Search in sources :

Example 16 with ExpressionNode

use of org.ballerinalang.model.tree.expressions.ExpressionNode in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addAssignmentStatement.

public void addAssignmentStatement(DiagnosticPos pos, Set<Whitespace> ws, boolean isVarDeclaration, boolean safeAssignment) {
    ExpressionNode rExprNode = exprNodeStack.pop();
    ExpressionNode lExprNode = exprNodeStack.pop();
    BLangAssignment assignmentNode = (BLangAssignment) TreeBuilder.createAssignmentNode();
    assignmentNode.setExpression(rExprNode);
    assignmentNode.setDeclaredWithVar(isVarDeclaration);
    assignmentNode.pos = pos;
    assignmentNode.addWS(ws);
    assignmentNode.safeAssignment = safeAssignment;
    assignmentNode.addVariable((BLangVariableReference) lExprNode);
    addStmtToCurrentBlock(assignmentNode);
}
Also used : ExpressionNode(org.ballerinalang.model.tree.expressions.ExpressionNode) SelectExpressionNode(org.ballerinalang.model.tree.clauses.SelectExpressionNode) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)

Example 17 with ExpressionNode

use of org.ballerinalang.model.tree.expressions.ExpressionNode in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addExprToExprNodeList.

private void addExprToExprNodeList(List<ExpressionNode> exprList, int n) {
    if (exprNodeStack.empty()) {
        throw new IllegalStateException("Expression stack cannot be empty in processing an ExpressionList");
    }
    ExpressionNode expr = exprNodeStack.pop();
    if (n > 1) {
        addExprToExprNodeList(exprList, n - 1);
    }
    exprList.add(expr);
}
Also used : ExpressionNode(org.ballerinalang.model.tree.expressions.ExpressionNode) SelectExpressionNode(org.ballerinalang.model.tree.clauses.SelectExpressionNode)

Example 18 with ExpressionNode

use of org.ballerinalang.model.tree.expressions.ExpressionNode in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addTypeInitExpression.

public void addTypeInitExpression(DiagnosticPos pos, Set<Whitespace> ws, String initName, boolean typeAvailable, boolean exprAvailable) {
    BLangTypeInit objectInitNode = (BLangTypeInit) TreeBuilder.createObjectInitNode();
    objectInitNode.pos = pos;
    objectInitNode.addWS(ws);
    if (typeAvailable) {
        objectInitNode.userDefinedType = (BLangUserDefinedType) typeNodeStack.pop();
    }
    BLangInvocation invocationNode = (BLangInvocation) TreeBuilder.createInvocationNode();
    invocationNode.pos = pos;
    invocationNode.addWS(ws);
    if (exprAvailable) {
        List<ExpressionNode> exprNodes = exprNodeListStack.pop();
        Set<Whitespace> cws = commaWsStack.pop();
        exprNodes.forEach(exprNode -> {
            invocationNode.argExprs.add((BLangExpression) exprNode);
            objectInitNode.argsExpr.add((BLangExpression) exprNode);
        });
        invocationNode.addWS(cws);
        objectInitNode.addWS(cws);
    }
    // TODO check whether pkgName can be be empty
    IdentifierNode pkgNameNode = TreeBuilder.createIdentifierNode();
    IdentifierNode nameNode = createIdentifier(initName);
    BLangNameReference nameReference = new BLangNameReference(pos, ws, pkgNameNode, nameNode);
    invocationNode.name = (BLangIdentifier) nameReference.name;
    invocationNode.addWS(nameReference.ws);
    invocationNode.pkgAlias = (BLangIdentifier) nameReference.pkgAlias;
    objectInitNode.objectInitInvocation = invocationNode;
    this.addExpressionNode(objectInitNode);
}
Also used : BLangTypeInit(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeInit) BLangNameReference(org.wso2.ballerinalang.compiler.tree.BLangNameReference) ExpressionNode(org.ballerinalang.model.tree.expressions.ExpressionNode) SelectExpressionNode(org.ballerinalang.model.tree.clauses.SelectExpressionNode) IdentifierNode(org.ballerinalang.model.tree.IdentifierNode) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) Whitespace(org.ballerinalang.model.Whitespace)

Aggregations

SelectExpressionNode (org.ballerinalang.model.tree.clauses.SelectExpressionNode)18 ExpressionNode (org.ballerinalang.model.tree.expressions.ExpressionNode)18 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)9 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)3 BLangNameReference (org.wso2.ballerinalang.compiler.tree.BLangNameReference)2 BLangVariableReference (org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference)2 Whitespace (org.ballerinalang.model.Whitespace)1 IdentifierNode (org.ballerinalang.model.tree.IdentifierNode)1 OperatorKind (org.ballerinalang.model.tree.OperatorKind)1 JoinStreamingInput (org.ballerinalang.model.tree.clauses.JoinStreamingInput)1 StreamingInput (org.ballerinalang.model.tree.clauses.StreamingInput)1 WhereNode (org.ballerinalang.model.tree.clauses.WhereNode)1 BLangJoinStreamingInput (org.wso2.ballerinalang.compiler.tree.clauses.BLangJoinStreamingInput)1 BLangPatternStreamingInput (org.wso2.ballerinalang.compiler.tree.clauses.BLangPatternStreamingInput)1 BLangStreamingInput (org.wso2.ballerinalang.compiler.tree.clauses.BLangStreamingInput)1 BLangWhere (org.wso2.ballerinalang.compiler.tree.clauses.BLangWhere)1 BLangArrayLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral)1 BLangTypeInit (org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeInit)1 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)1 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)1