/**
* Returns true if the given expression represents constant value.
* This value can be a boolean or integer.
* @param e the expression to test
* @return true if the given expression represents constant value
*/
private boolean isConstant(Expression e) {
if(e instanceof IntegerExpression)
return true;
if(e instanceof VnameExpression) {
VnameExpression vname = (VnameExpression)e;
if(vname.V instanceof SimpleVname)
if(((SimpleVname)vname.V).I.spelling.equals(StdEnvironment.trueDecl.I.spelling)
|| ((SimpleVname)vname.V).I.spelling.equals(StdEnvironment.falseDecl.I.spelling))
return true;
}
return false;
}
/**
* Returns the boolean value of the given expression that represents a boolean value.
* @param e a boolean value
* @return the boolean value of the given expression that represents a boolean value
*/
private boolean parseBoolean(Expression e) {
if(e instanceof VnameExpression) {
VnameExpression vname = (VnameExpression)e;
if(vname.V instanceof SimpleVname)
if(((SimpleVname)vname.V).I.spelling.equals(StdEnvironment.trueDecl.I.spelling))
return true;
if(((SimpleVname)vname.V).I.spelling.equals(StdEnvironment.falseDecl.I.spelling))
return false;
}
throw new RuntimeException();
}
/**
* Returns an expression representing the given boolean value.
* @param val the boolean value that will be represented by the returned expression
* @return an expression representing the given boolean value
*/
private Expression createBoolean(boolean val) {
Identifier iAST = new Identifier(val ? "true" : "false", new SourcePosition());
iAST.decl = val ? StdEnvironment.trueDecl : StdEnvironment.falseDecl;
SimpleVname vAST = new SimpleVname(iAST, new SourcePosition());
vAST.type = StdEnvironment.booleanType;
VnameExpression boolExpression = new VnameExpression(vAST, new SourcePosition());
return boolExpression;
}