use of org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral in project ballerina by ballerina-lang.
the class Desugar method visit.
@Override
public void visit(BLangFieldBasedAccess fieldAccessExpr) {
BLangVariableReference targetVarRef = fieldAccessExpr;
if (fieldAccessExpr.expr.type.tag == TypeTags.ENUM) {
targetVarRef = new BLangEnumeratorAccessExpr(fieldAccessExpr.pos, fieldAccessExpr.field, fieldAccessExpr.symbol);
} else {
fieldAccessExpr.expr = rewriteExpr(fieldAccessExpr.expr);
BType varRefType = fieldAccessExpr.expr.type;
if (varRefType.tag == TypeTags.STRUCT) {
targetVarRef = new BLangStructFieldAccessExpr(fieldAccessExpr.pos, fieldAccessExpr.expr, fieldAccessExpr.symbol);
} else if (varRefType.tag == TypeTags.MAP) {
BLangLiteral stringLit = createStringLiteral(fieldAccessExpr.pos, fieldAccessExpr.field.value);
targetVarRef = new BLangMapAccessExpr(fieldAccessExpr.pos, fieldAccessExpr.expr, stringLit);
} else if (varRefType.tag == TypeTags.JSON) {
BLangLiteral stringLit = createStringLiteral(fieldAccessExpr.pos, fieldAccessExpr.field.value);
targetVarRef = new BLangJSONAccessExpr(fieldAccessExpr.pos, fieldAccessExpr.expr, stringLit);
} else if (varRefType.tag == TypeTags.XML) {
BLangLiteral stringLit = createStringLiteral(fieldAccessExpr.pos, fieldAccessExpr.field.value);
targetVarRef = new BLangXMLAccessExpr(fieldAccessExpr.pos, fieldAccessExpr.expr, stringLit, fieldAccessExpr.fieldType);
}
}
targetVarRef.lhsVar = fieldAccessExpr.lhsVar;
targetVarRef.type = fieldAccessExpr.type;
result = targetVarRef;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral in project ballerina by ballerina-lang.
the class Desugar method visit.
@Override
public void visit(BLangTupleDestructure stmt) {
// var (a, b) = (tuple)
//
// desugar once
// any[] x = (tuple);
// a = x[0];
final BLangBlockStmt blockStmt = ASTBuilderUtil.createBlockStmt(stmt.pos);
BType runTimeType = new BArrayType(symTable.anyType);
final BLangVariable tuple = ASTBuilderUtil.createVariable(stmt.pos, "", runTimeType, null, new BVarSymbol(0, names.fromString("tuple"), this.env.scope.owner.pkgID, runTimeType, this.env.scope.owner));
tuple.expr = stmt.expr;
final BLangVariableDef variableDef = ASTBuilderUtil.createVariableDefStmt(stmt.pos, blockStmt);
variableDef.var = tuple;
for (int index = 0; index < stmt.varRefs.size(); index++) {
BLangExpression varRef = stmt.varRefs.get(index);
BLangLiteral indexExpr = ASTBuilderUtil.createLiteral(stmt.pos, symTable.intType, (long) index);
BLangIndexBasedAccess arrayAccess = ASTBuilderUtil.createIndexBasesAccessExpr(stmt.pos, symTable.anyType, tuple.symbol, indexExpr);
final BLangExpression assignmentExpr;
if (types.isValueType(varRef.type)) {
BLangTypeConversionExpr castExpr = (BLangTypeConversionExpr) TreeBuilder.createTypeConversionNode();
castExpr.expr = arrayAccess;
castExpr.conversionSymbol = Symbols.createUnboxValueTypeOpSymbol(symTable.anyType, varRef.type);
castExpr.type = varRef.type;
assignmentExpr = castExpr;
} else {
assignmentExpr = arrayAccess;
}
final BLangAssignment assignmentStmt = ASTBuilderUtil.createAssignmentStmt(stmt.pos, blockStmt);
assignmentStmt.declaredWithVar = stmt.declaredWithVar;
assignmentStmt.varRefs = Lists.of(varRef);
assignmentStmt.expr = assignmentExpr;
}
result = rewrite(blockStmt, env);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral in project ballerina by ballerina-lang.
the class Desugar method createInvocationForForeverBlock.
private BLangInvocation createInvocationForForeverBlock(BLangForever forever) {
List<BLangExpression> args = new ArrayList<>();
List<BType> retTypes = new ArrayList<>();
retTypes.add(symTable.noType);
BLangLiteral streamingQueryLiteral = ASTBuilderUtil.createLiteral(forever.pos, symTable.stringType, forever.getSiddhiQuery());
args.add(streamingQueryLiteral);
addReferenceVariablesToArgs(args, siddhiQueryBuilder.getInStreamRefs());
addReferenceVariablesToArgs(args, siddhiQueryBuilder.getInTableRefs());
addReferenceVariablesToArgs(args, siddhiQueryBuilder.getOutStreamRefs());
addReferenceVariablesToArgs(args, siddhiQueryBuilder.getOutTableRefs());
addFunctionPointersToArgs(args, forever.gettreamingQueryStatements());
return createInvocationNode(CREATE_FOREVER, args, retTypes);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addLiteralValue.
public void addLiteralValue(DiagnosticPos pos, Set<Whitespace> ws, int typeTag, Object value) {
BLangLiteral litExpr = (BLangLiteral) TreeBuilder.createLiteralExpression();
litExpr.addWS(ws);
litExpr.pos = pos;
litExpr.typeTag = typeTag;
litExpr.value = value;
addExpressionNode(litExpr);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral in project ballerina by ballerina-lang.
the class BLangPackageBuilder method createXMLPILiteral.
public void createXMLPILiteral(DiagnosticPos pos, Set<Whitespace> ws, String targetQName, Stack<String> precedingTextFragments, String endingText) {
List<BLangExpression> dataExprs = getExpressionsInTemplate(pos, ws, precedingTextFragments, endingText, NodeKind.LITERAL);
addLiteralValue(pos, ws, TypeTags.STRING, targetQName);
BLangXMLProcInsLiteral xmlProcInsLiteral = (BLangXMLProcInsLiteral) TreeBuilder.createXMLProcessingIntsructionLiteralNode();
xmlProcInsLiteral.pos = pos;
xmlProcInsLiteral.dataFragments = dataExprs;
xmlProcInsLiteral.target = (BLangLiteral) exprNodeStack.pop();
;
addExpressionNode(xmlProcInsLiteral);
}
Aggregations