public class CodeBlock extends java.lang.Object implements Expression
Expression.
c=a+b;d=c*2;return d; will perform the following computations:
The following expression c=a+b;d=c*2; will have exactly the same result.
| Modifier and Type | Field and Description |
|---|---|
protected CodeBlock |
block |
STRUCT_ARRAY, STRUCT_SCALAR, STRUCT_STRUCTURE, TYPE_BOOL, TYPE_DYNAMIC, TYPE_FLOAT, TYPE_INTEGER, TYPE_NUMERIC, TYPE_STRING, TYPE_UNDEF| Constructor and Description |
|---|
CodeBlock(Expression root) |
| Modifier and Type | Method and Description |
|---|---|
void |
addExpression(Expression expr)
Add an expression to the block.
|
java.lang.Object |
clone() |
int |
countExpressions()
Return the number of expressions.
|
java.lang.Object |
eval()
Evaluate the expression.
|
boolean |
evalAsBoolean()
Evaluate the expression as a boolean.
|
float |
evalAsFloat()
Evaluate the expression as a float.
|
int |
evalAsInt()
Evaluate the expression as an int.
|
java.lang.String |
getExpressionName()
Return the expression name.
|
java.util.List<Expression> |
getExpressions()
Return the expressions.
|
ExprWHILE |
getExprWHILE() |
LocalVariable |
getLocalVariable(java.lang.String varName)
Return the internal variable of a specified name.
|
java.util.Map<java.lang.String,LocalVariable> |
getLocalVariables()
Return the internal variables of the block.
|
CodeBlock |
getParentBlock()
Return the parent expression block if the expression is one of several expressions separated by commas.
|
short |
getResultStructure()
Return the structure of the result for the expression.
|
short |
getResultType()
Return the type of the result for the expression.
|
Expression |
getRoot()
Return the root expression.
|
Variable |
getVariable(java.lang.String varName)
Return a variable declared by the expression.
|
Variable |
getVariable(java.lang.String varName,
boolean includeLocals)
Return a variable declared by the expression.
|
java.util.Map<java.lang.String,Variable> |
getVariables()
Return the variables used by this expression.
|
boolean |
hasVariable(java.lang.String varName,
boolean includeLocals)
Return true if there is a variable with a specified name.
|
Expression |
lastExpression()
Return the last expression.
|
boolean |
replaceLastExpression(Expression expr)
Replace the last expression of the block.
|
void |
setExpressions(java.util.List<Expression> expressions)
Set the expressions.
|
void |
setExprWHILE(ExprWHILE exprWHILE) |
void |
setLocalVariables(java.util.Map<java.lang.String,LocalVariable> internalVars)
Set the internal variables of the block.
|
void |
setParentBlock(CodeBlock block)
Set the parent expression block.
|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetExpression, getVariables, hasVariable, removeVariableprotected CodeBlock block
public CodeBlock(Expression root)
public Expression getRoot()
getRoot in interface Expressionpublic java.lang.Object clone()
throws java.lang.CloneNotSupportedException
clone in interface Expressionclone in class java.lang.Objectjava.lang.CloneNotSupportedExceptionpublic void setExprWHILE(ExprWHILE exprWHILE)
public ExprWHILE getExprWHILE()
public void setParentBlock(CodeBlock block)
ExpressionsetParentBlock in interface Expressionblock - the parent expression blockpublic CodeBlock getParentBlock()
Expressionb=a+2; return b, the two "b=a+2" and "return b" have "b=a+2; return b" as their
parent block.getParentBlock in interface Expressionpublic boolean replaceLastExpression(Expression expr)
expr - the expression to use for the replacementpublic Expression lastExpression()
public int countExpressions()
public void addExpression(Expression expr)
expr - the expressionpublic java.util.List<Expression> getExpressions()
public void setExpressions(java.util.List<Expression> expressions)
expressions - the expressionpublic java.lang.Object eval()
Expressioneval in interface Expressionpublic java.util.Map<java.lang.String,Variable> getVariables()
Expressionint c=a+b, only "a" and "b" will be returned.getVariables in interface Expressionpublic LocalVariable getLocalVariable(java.lang.String varName)
getLocalVariable in interface ExpressionvarName - the variable namepublic Variable getVariable(java.lang.String varName, boolean includeLocals)
getVariable in interface ExpressionvarName - the variable nameincludeLocals - true if local variables should be includedpublic boolean hasVariable(java.lang.String varName,
boolean includeLocals)
hasVariable in interface ExpressionvarName - the variable nameincludeLocals - true if local variables should be includedpublic void setLocalVariables(java.util.Map<java.lang.String,LocalVariable> internalVars)
internalVars - the internal variablespublic java.util.Map<java.lang.String,LocalVariable> getLocalVariables()
getLocalVariables in interface Expressionpublic java.lang.String getExpressionName()
ExpressiongetExpressionName in interface Expressionpublic Variable getVariable(java.lang.String varName)
ExpressiongetVariable in interface ExpressionvarName - the variable namepublic int evalAsInt()
ExpressionExpression.eval(), but the evaluation
engine will be able to optimize the computation by knwoing that the result is an int (primitive valeus are cached internally).evalAsInt in interface Expressionpublic float evalAsFloat()
ExpressionExpression.eval(), but the evaluation
engine will be able to optimize the computation by knwoing that the result is a float (primitive valeus are cached internally).evalAsFloat in interface Expressionpublic boolean evalAsBoolean()
ExpressionExpression.eval(), but the evaluation
engine will be able to optimize the computation by knwoing that the result is a boolean (primitive valeus are cached internally).evalAsBoolean in interface Expressionpublic short getResultType()
ExpressionExpressionType.TYPE_INTEGER: integerExpressionType.TYPE_FLOAT: floatExpressionType.TYPE_NUMERIC: integer or float value. The runtime actual type may depend on the expression argumentsExpressionType.TYPE_STRING: stringExpressionType.TYPE_DYNAMIC: dynamic type. The runtime actual type may depend on the expression argumentsExpressionType.TYPE_UNDEF: undefined type. The default type, characteristic of an error if entountered.getResultType in interface Expressionpublic short getResultStructure()
ExpressionExpressionType.STRUCT_SCALAR: a scalar valueExpressionType.STRUCT_ARRAY: an array valuegetResultStructure in interface ExpressionCopyright © 2018 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence