use of org.wso2.siddhi.query.api.expression.Expression in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
public void visit(BLangTernaryExpr ternaryExpr) {
// Determine the reg index of the ternary expression and this reg index will be used by both then and else
// expressions to store their result
RegIndex ternaryExprRegIndex = calcAndGetExprRegIndex(ternaryExpr);
// Generate code for the condition
this.genNode(ternaryExpr.expr, this.env);
Operand ifFalseJumpAddr = getOperand(-1);
this.emit(InstructionCodes.BR_FALSE, ternaryExpr.expr.regIndex, ifFalseJumpAddr);
// Generate code for the then expression
ternaryExpr.thenExpr.regIndex = createLHSRegIndex(ternaryExprRegIndex);
this.genNode(ternaryExpr.thenExpr, this.env);
Operand endJumpAddr = getOperand(-1);
this.emit(InstructionCodes.GOTO, endJumpAddr);
ifFalseJumpAddr.value = nextIP();
// Generate code for the then expression
ternaryExpr.elseExpr.regIndex = createLHSRegIndex(ternaryExprRegIndex);
this.genNode(ternaryExpr.elseExpr, this.env);
endJumpAddr.value = nextIP();
}
use of org.wso2.siddhi.query.api.expression.Expression in project ballerina by ballerina-lang.
the class CodeGenerator method visitOrExpression.
private void visitOrExpression(BLangBinaryExpr binaryExpr) {
// short-circuit evaluation
// Code address to jump if the lhs expression gets evaluated to 'true'.
Operand lExprTrueJumpAddr = getOperand(-1);
// Code address to jump if the rhs expression gets evaluated to 'false'.
Operand rExprFalseJumpAddr = getOperand(-1);
// Generate code for the left hand side
genNode(binaryExpr.lhsExpr, this.env);
emit(InstructionCodes.BR_TRUE, binaryExpr.lhsExpr.regIndex, lExprTrueJumpAddr);
// Generate code for the right hand side
genNode(binaryExpr.rhsExpr, this.env);
emit(InstructionCodes.BR_FALSE, binaryExpr.rhsExpr.regIndex, rExprFalseJumpAddr);
lExprTrueJumpAddr.value = nextIP();
RegIndex exprRegIndex = calcAndGetExprRegIndex(binaryExpr);
emit(InstructionCodes.BCONST_1, exprRegIndex);
Operand gotoAddr = getOperand(-1);
emit(InstructionCodes.GOTO, gotoAddr);
rExprFalseJumpAddr.value = nextIP();
// Load 'false' if the both conditions are false;
emit(InstructionCodes.BCONST_0, exprRegIndex);
gotoAddr.value = nextIP();
}
use of org.wso2.siddhi.query.api.expression.Expression in project ballerina by ballerina-lang.
the class CodeGenerator method createStringLiteral.
/**
* Creates a string literal expression, generate the code and returns the registry index.
*
* @param value String value to generate the string literal
* @param regIndex String literal expression's reg index
* @param env Environment
* @return String registry index of the generated string
*/
private RegIndex createStringLiteral(String value, RegIndex regIndex, SymbolEnv env) {
BLangLiteral prefixLiteral = (BLangLiteral) TreeBuilder.createLiteralExpression();
prefixLiteral.value = value;
prefixLiteral.typeTag = TypeTags.STRING;
prefixLiteral.type = symTable.stringType;
prefixLiteral.regIndex = regIndex;
genNode(prefixLiteral, env);
return prefixLiteral.regIndex;
}
use of org.wso2.siddhi.query.api.expression.Expression in project ballerina by ballerina-lang.
the class AnnotationDesugar method initAnnotation.
private void initAnnotation(BLangAnnotationAttachment attachment, BLangVariable annotationMapEntryVar, BLangBlockStmt target, BSymbol parentSymbol, int index) {
BLangVariable annotationVar = null;
if (attachment.annotationSymbol.attachedType != null) {
// create: AttachedType annotationVar = { annotation-expression }
annotationVar = ASTBuilderUtil.createVariable(attachment.pos, attachment.annotationName.value, attachment.annotationSymbol.attachedType.type);
annotationVar.expr = attachment.expr;
ASTBuilderUtil.defineVariable(annotationVar, parentSymbol, names);
ASTBuilderUtil.createVariableDefStmt(attachment.pos, target).var = annotationVar;
}
// create: annotationMapEntryVar["name$index"] = annotationVar;
BLangAssignment assignmentStmt = ASTBuilderUtil.createAssignmentStmt(target.pos, target);
if (annotationVar != null) {
assignmentStmt.expr = ASTBuilderUtil.createVariableRef(target.pos, annotationVar.symbol);
} else {
assignmentStmt.expr = ASTBuilderUtil.createLiteral(target.pos, symTable.nullType, null);
}
BLangIndexBasedAccess indexAccessNode = (BLangIndexBasedAccess) TreeBuilder.createIndexBasedAccessNode();
indexAccessNode.pos = target.pos;
indexAccessNode.indexExpr = ASTBuilderUtil.createLiteral(target.pos, symTable.stringType, attachment.annotationSymbol.bvmAlias() + "$" + index);
indexAccessNode.expr = ASTBuilderUtil.createVariableRef(target.pos, annotationMapEntryVar.symbol);
indexAccessNode.type = annotationMapEntryVar.symbol.type;
assignmentStmt.varRefs.add(indexAccessNode);
}
use of org.wso2.siddhi.query.api.expression.Expression in project ballerina by ballerina-lang.
the class Desugar method getSQLPreparedStatement.
private BLangLiteral getSQLPreparedStatement(BLangTableQueryExpression tableQueryExpression) {
// create a literal to represent the sql query.
BLangLiteral sqlQueryLiteral = (BLangLiteral) TreeBuilder.createLiteralExpression();
sqlQueryLiteral.typeTag = TypeTags.STRING;
// assign the sql query from table expression to the literal.
sqlQueryLiteral.value = tableQueryExpression.getSqlQuery();
sqlQueryLiteral.type = symTable.getTypeFromTag(sqlQueryLiteral.typeTag);
return sqlQueryLiteral;
}
Aggregations