Search in sources :

Example 16 with BLangLiteral

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;
}
Also used : BLangStructFieldAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess.BLangStructFieldAccessExpr) BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) BLangEnumeratorAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess.BLangEnumeratorAccessExpr) BLangVariableReference(org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BLangMapAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangMapAccessExpr) BLangXMLAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangXMLAccessExpr) BLangJSONAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangJSONAccessExpr)

Example 17 with BLangLiteral

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);
}
Also used : BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) BLangIndexBasedAccess(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess) BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) BArrayType(org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType) BLangTypeConversionExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeConversionExpr) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 18 with BLangLiteral

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);
}
Also used : BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) ArrayList(java.util.ArrayList) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 19 with BLangLiteral

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);
}
Also used : BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)

Example 20 with BLangLiteral

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);
}
Also used : BLangXMLProcInsLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLProcInsLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Aggregations

BLangLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)23 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)15 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)11 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)8 HashMap (java.util.HashMap)4 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)4 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)4 ArrayList (java.util.ArrayList)3 AnnotationAttachmentNode (org.ballerinalang.model.tree.AnnotationAttachmentNode)3 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)3 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)3 Operand (org.wso2.ballerinalang.programfile.Instruction.Operand)3 Path (java.nio.file.Path)2 NodeKind (org.ballerinalang.model.tree.NodeKind)2 BStructSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)2 BXMLNSSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol)2 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)2 DefaultValue (org.wso2.ballerinalang.programfile.DefaultValue)2 ParamDefaultValueAttributeInfo (org.wso2.ballerinalang.programfile.attributes.ParamDefaultValueAttributeInfo)2 FloatCPEntry (org.wso2.ballerinalang.programfile.cpentries.FloatCPEntry)2