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 class
BaseExpression.SymbolHashMap
-
Field Summary
Fields Modifier and Type Field Description private Env
compileEnv
private java.lang.String
expression
private java.util.List<java.lang.String>
filteredFunctionNames
static java.lang.String
FUNC_PARAMS_VAR
private java.util.Map<java.lang.Integer,java.util.List<FunctionArgument>>
funcsArgs
private java.util.List<java.lang.String>
functionNames
protected AviatorEvaluatorInstance
instance
protected java.util.Map<java.lang.String,LambdaFunctionBootstrap>
lambdaBootstraps
private static long
serialVersionUID
protected java.lang.String
sourceFile
private java.util.concurrent.ConcurrentHashMap<java.lang.String,java.util.concurrent.FutureTask<AviatorEvaluatorInstance.StringSegments>>
stringSegs
protected SymbolTable
symbolTable
protected java.util.List<java.lang.String>
varFullNames
protected java.util.List<java.lang.String>
varNames
private 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.String
addSymbol(java.lang.String name)
Adds the specified symbol to the symbol table and returns a reference to the unique symbol.protected void
afterPopulateFullNames(java.util.Map<java.lang.String,VariableMeta> fullNames, java.util.Set<java.lang.String> parentVars)
void
customReadObject(java.io.ObjectInputStream input)
void
customWriteObject(java.io.ObjectOutputStream output)
java.lang.Object
execute()
Execute an expression with an empty environment, returns the result.java.lang.Object
execute(java.util.Map<java.lang.String,java.lang.Object> map)
Execute an expression with an environment, returns the result.protected java.lang.Object
execute(java.util.Map<java.lang.String,java.lang.Object> map, boolean checkExecutionTimeout)
abstract java.lang.Object
executeDirectly(java.util.Map<java.lang.String,java.lang.Object> env)
protected Env
genTopEnv(java.util.Map<java.lang.String,java.lang.Object> map, boolean checkExecutionTimeout)
Env
getCompileEnv()
private long
getExecutionStartNs(boolean checkExecutionTimeout)
java.lang.String
getExpression()
Returns the expression string when turn onOptions.TRACE_EVAL
option, 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.String
getSourceFile()
Returns the source file name.AviatorEvaluatorInstance.StringSegments
getStringSegements(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 Env
newEnv(java.util.Map<java.lang.String,java.lang.Object> map)
protected Env
newEnv(java.util.Map<java.lang.String,java.lang.Object> map, boolean direct, boolean checkExecutionTimeout)
LambdaFunction
newLambda(Env env, java.lang.String name)
private void
populateFilteredFuncNames()
private void
populateFullNames()
private void
populateNames()
protected void
setCompileEnv(Env compileEnv)
protected void
setExpression(java.lang.String expression)
protected void
setFuncsArgs(java.util.Map<java.lang.Integer,java.util.List<FunctionArgument>> funcsArgs)
protected void
setFunctionNames(java.util.List<java.lang.String> functionNames)
protected void
setInstance(AviatorEvaluatorInstance instance)
protected void
setLambdaBootstraps(java.util.Map<java.lang.String,LambdaFunctionBootstrap> lambdaBootstraps)
protected void
setSourceFile(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:Expression
Returns the source file name.- Specified by:
getSourceFile
in 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:Expression
Created a faster env map(compare variable names by reference).The arguments should be a sequence of pair. - Specified by:
newEnv
in 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:Expression
Execute an expression with an environment, returns the result.- Specified by:
execute
in 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_EVAL
option, 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:Expression
Adds 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:
addSymbol
in interfaceExpression
- Parameters:
name
- The symbol name.
-
execute
public java.lang.Object execute()
Description copied from interface:Expression
Execute an expression with an empty environment, returns the result.- Specified by:
execute
in interfaceExpression
- Returns:
- the result of execution
-
getVariableFullNames
public java.util.List<java.lang.String> getVariableFullNames()
Description copied from interface:Expression
Returns 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:
getVariableFullNames
in interfaceExpression
- Returns:
-
getVars
public java.util.List<VariableMeta> getVars()
-
getVariableNames
public java.util.List<java.lang.String> getVariableNames()
Description copied from interface:Expression
Returns this expression's all uninitialized global variable names in order when using AviatorEvaluator.EVAL mode, otherwise returns an empty list.- Specified by:
getVariableNames
in 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:Expression
Returns the function names in the expression when using AviatorEvaluator.EVAL mode, otherwise returns an empty list.- Specified by:
getFunctionNames
in 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.ClassNotFoundException
java.io.IOException
-
customWriteObject
public void customWriteObject(java.io.ObjectOutputStream output) throws java.io.IOException
- Throws:
java.io.IOException
-
-