Package com.googlecode.aviator
Class BaseExpression
- java.lang.Object
-
- com.googlecode.aviator.BaseExpression
-
- All Implemented Interfaces:
Expression,java.io.Serializable
- Direct Known Subclasses:
ClassExpression,InterpretExpression,LiteralExpression
public abstract class BaseExpression extends java.lang.Object implements Expression
Base expression- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classBaseExpression.SymbolHashMap
-
Field Summary
Fields Modifier and Type Field Description private EnvcompileEnvprivate java.lang.Stringexpressionprivate java.util.List<java.lang.String>filteredFunctionNamesstatic java.lang.StringFUNC_PARAMS_VARprivate java.util.Map<java.lang.Integer,java.util.List<FunctionArgument>>funcsArgsprivate java.util.List<java.lang.String>functionNamesprotected AviatorEvaluatorInstanceinstanceprotected java.util.Map<java.lang.String,LambdaFunctionBootstrap>lambdaBootstrapsprivate static longserialVersionUIDprotected java.lang.StringsourceFileprivate java.util.concurrent.ConcurrentHashMap<java.lang.String,java.util.concurrent.FutureTask<AviatorEvaluatorInstance.StringSegments>>stringSegsprotected SymbolTablesymbolTableprotected java.util.List<java.lang.String>varFullNamesprotected java.util.List<java.lang.String>varNamesprivate java.util.List<VariableMeta>vars
-
Constructor Summary
Constructors Constructor Description BaseExpression(AviatorEvaluatorInstance instance, java.util.List<VariableMeta> vars, SymbolTable symbolTable)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.StringaddSymbol(java.lang.String name)Adds the specified symbol to the symbol table and returns a reference to the unique symbol.protected voidafterPopulateFullNames(java.util.Map<java.lang.String,VariableMeta> fullNames, java.util.Set<java.lang.String> parentVars)voidcustomReadObject(java.io.ObjectInputStream input)voidcustomWriteObject(java.io.ObjectOutputStream output)java.lang.Objectexecute()Execute an expression with an empty environment, returns the result.java.lang.Objectexecute(java.util.Map<java.lang.String,java.lang.Object> map)Execute an expression with an environment, returns the result.protected java.lang.Objectexecute(java.util.Map<java.lang.String,java.lang.Object> map, boolean checkExecutionTimeout)abstract java.lang.ObjectexecuteDirectly(java.util.Map<java.lang.String,java.lang.Object> env)protected EnvgenTopEnv(java.util.Map<java.lang.String,java.lang.Object> map, boolean checkExecutionTimeout)EnvgetCompileEnv()private longgetExecutionStartNs(boolean checkExecutionTimeout)java.lang.StringgetExpression()Returns the expression string when turn onOptions.TRACE_EVALoption, else returns null.java.util.Map<java.lang.String,VariableMeta>getFullNameMetas()java.util.List<java.lang.String>getFunctionNames()Returns the function names in the expression when using AviatorEvaluator.EVAL mode, otherwise returns an empty list.java.util.Map<java.lang.String,LambdaFunctionBootstrap>getLambdaBootstraps()java.lang.StringgetSourceFile()Returns the source file name.AviatorEvaluatorInstance.StringSegmentsgetStringSegements(java.lang.String lexeme, int lineNo)java.util.List<java.lang.String>getVariableFullNames()Returns this expression's all uninitialized global variable full names(contains dot) in order when using AviatorEvaluator.EVAL mode, otherwise returns an empty list.java.util.List<java.lang.String>getVariableNames()Returns this expression's all uninitialized global variable names in order when using AviatorEvaluator.EVAL mode, otherwise returns an empty list.java.util.List<VariableMeta>getVars()java.util.Map<java.lang.String,java.lang.Object>newEnv(java.lang.Object... args)Created a faster env map(compare variable names by reference).The arguments should be a sequence of pair. protected EnvnewEnv(java.util.Map<java.lang.String,java.lang.Object> map)protected EnvnewEnv(java.util.Map<java.lang.String,java.lang.Object> map, boolean direct, boolean checkExecutionTimeout)LambdaFunctionnewLambda(Env env, java.lang.String name)private voidpopulateFilteredFuncNames()private voidpopulateFullNames()private voidpopulateNames()protected voidsetCompileEnv(Env compileEnv)protected voidsetExpression(java.lang.String expression)protected voidsetFuncsArgs(java.util.Map<java.lang.Integer,java.util.List<FunctionArgument>> funcsArgs)protected voidsetFunctionNames(java.util.List<java.lang.String> functionNames)protected voidsetInstance(AviatorEvaluatorInstance instance)protected voidsetLambdaBootstraps(java.util.Map<java.lang.String,LambdaFunctionBootstrap> lambdaBootstraps)protected voidsetSourceFile(java.lang.String sourceFile)
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
FUNC_PARAMS_VAR
public static final java.lang.String FUNC_PARAMS_VAR
- See Also:
- Constant Field Values
-
varNames
protected transient java.util.List<java.lang.String> varNames
-
varFullNames
protected transient java.util.List<java.lang.String> varFullNames
-
vars
private java.util.List<VariableMeta> vars
-
expression
private java.lang.String expression
-
instance
protected transient AviatorEvaluatorInstance instance
-
compileEnv
private Env compileEnv
-
funcsArgs
private java.util.Map<java.lang.Integer,java.util.List<FunctionArgument>> funcsArgs
-
symbolTable
protected SymbolTable symbolTable
-
stringSegs
private transient java.util.concurrent.ConcurrentHashMap<java.lang.String,java.util.concurrent.FutureTask<AviatorEvaluatorInstance.StringSegments>> stringSegs
-
functionNames
private java.util.List<java.lang.String> functionNames
-
filteredFunctionNames
private transient java.util.List<java.lang.String> filteredFunctionNames
-
sourceFile
protected java.lang.String sourceFile
-
lambdaBootstraps
protected java.util.Map<java.lang.String,LambdaFunctionBootstrap> lambdaBootstraps
-
-
Constructor Detail
-
BaseExpression
public BaseExpression(AviatorEvaluatorInstance instance, java.util.List<VariableMeta> vars, SymbolTable symbolTable)
-
-
Method Detail
-
getSourceFile
public java.lang.String getSourceFile()
Description copied from interface:ExpressionReturns the source file name.- Specified by:
getSourceFilein interfaceExpression- Returns:
- the source file name
-
setSourceFile
protected void setSourceFile(java.lang.String sourceFile)
-
setInstance
protected void setInstance(AviatorEvaluatorInstance instance)
-
populateNames
private void populateNames()
-
afterPopulateFullNames
protected void afterPopulateFullNames(java.util.Map<java.lang.String,VariableMeta> fullNames, java.util.Set<java.lang.String> parentVars)
-
populateFullNames
private void populateFullNames()
-
getFullNameMetas
public java.util.Map<java.lang.String,VariableMeta> getFullNameMetas()
-
getStringSegements
public AviatorEvaluatorInstance.StringSegments getStringSegements(java.lang.String lexeme, int lineNo)
-
newEnv
public java.util.Map<java.lang.String,java.lang.Object> newEnv(java.lang.Object... args)
Description copied from interface:ExpressionCreated a faster env map(compare variable names by reference).The arguments should be a sequence of pair. - Specified by:
newEnvin interfaceExpression- Returns:
- an env map
-
executeDirectly
public abstract java.lang.Object executeDirectly(java.util.Map<java.lang.String,java.lang.Object> env)
-
execute
public java.lang.Object execute(java.util.Map<java.lang.String,java.lang.Object> map)
Description copied from interface:ExpressionExecute an expression with an environment, returns the result.- Specified by:
executein interfaceExpression- Parameters:
map- Binding variable environment- Returns:
- the result of execution
-
execute
protected java.lang.Object execute(java.util.Map<java.lang.String,java.lang.Object> map, boolean checkExecutionTimeout)
-
setFuncsArgs
protected void setFuncsArgs(java.util.Map<java.lang.Integer,java.util.List<FunctionArgument>> funcsArgs)
-
getCompileEnv
public Env getCompileEnv()
-
setCompileEnv
protected void setCompileEnv(Env compileEnv)
-
getExpression
public java.lang.String getExpression()
Returns the expression string when turn onOptions.TRACE_EVALoption, else returns null.- Returns:
- expression in string.
-
setExpression
protected void setExpression(java.lang.String expression)
-
addSymbol
public java.lang.String addSymbol(java.lang.String name)
Description copied from interface:ExpressionAdds the specified symbol to the symbol table and returns a reference to the unique symbol. If the symbol already exists, the previous symbol reference is returned instead, in order guarantee that symbol references remain unique.- Specified by:
addSymbolin interfaceExpression- Parameters:
name- The symbol name.
-
execute
public java.lang.Object execute()
Description copied from interface:ExpressionExecute an expression with an empty environment, returns the result.- Specified by:
executein interfaceExpression- Returns:
- the result of execution
-
getVariableFullNames
public java.util.List<java.lang.String> getVariableFullNames()
Description copied from interface:ExpressionReturns this expression's all uninitialized global variable full names(contains dot) in order when using AviatorEvaluator.EVAL mode, otherwise returns an empty list.- Specified by:
getVariableFullNamesin interfaceExpression- Returns:
-
getVars
public java.util.List<VariableMeta> getVars()
-
getVariableNames
public java.util.List<java.lang.String> getVariableNames()
Description copied from interface:ExpressionReturns this expression's all uninitialized global variable names in order when using AviatorEvaluator.EVAL mode, otherwise returns an empty list.- Specified by:
getVariableNamesin interfaceExpression- Returns:
- See Also:
AviatorEvaluator.EVAL
-
newEnv
protected Env newEnv(java.util.Map<java.lang.String,java.lang.Object> map, boolean direct, boolean checkExecutionTimeout)
-
genTopEnv
protected Env genTopEnv(java.util.Map<java.lang.String,java.lang.Object> map, boolean checkExecutionTimeout)
-
getExecutionStartNs
private long getExecutionStartNs(boolean checkExecutionTimeout)
-
newEnv
protected Env newEnv(java.util.Map<java.lang.String,java.lang.Object> map)
-
getFunctionNames
public java.util.List<java.lang.String> getFunctionNames()
Description copied from interface:ExpressionReturns the function names in the expression when using AviatorEvaluator.EVAL mode, otherwise returns an empty list.- Specified by:
getFunctionNamesin interfaceExpression- Returns:
- the function name list
-
populateFilteredFuncNames
private void populateFilteredFuncNames()
-
setFunctionNames
protected void setFunctionNames(java.util.List<java.lang.String> functionNames)
-
getLambdaBootstraps
public java.util.Map<java.lang.String,LambdaFunctionBootstrap> getLambdaBootstraps()
-
setLambdaBootstraps
protected void setLambdaBootstraps(java.util.Map<java.lang.String,LambdaFunctionBootstrap> lambdaBootstraps)
-
newLambda
public LambdaFunction newLambda(Env env, java.lang.String name)
-
customReadObject
public void customReadObject(java.io.ObjectInputStream input) throws java.lang.ClassNotFoundException, java.io.IOException- Throws:
java.lang.ClassNotFoundExceptionjava.io.IOException
-
customWriteObject
public void customWriteObject(java.io.ObjectOutputStream output) throws java.io.IOException- Throws:
java.io.IOException
-
-