Search in sources :

Example 21 with BLangVariableReference

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addTupleDestructuringStatement.

public void addTupleDestructuringStatement(DiagnosticPos pos, Set<Whitespace> ws, boolean isVarsExist, boolean varDeclaration) {
    BLangTupleDestructure stmt = (BLangTupleDestructure) TreeBuilder.createTupleDestructureStatementNode();
    stmt.pos = pos;
    stmt.addWS(ws);
    if (isVarsExist) {
        stmt.setDeclaredWithVar(varDeclaration);
        stmt.expr = (BLangExpression) exprNodeStack.pop();
        List<ExpressionNode> lExprList = exprNodeListStack.pop();
        lExprList.forEach(expressionNode -> stmt.varRefs.add((BLangVariableReference) expressionNode));
    }
    // TODO: handle ParamList Destructue.
    addStmtToCurrentBlock(stmt);
}
Also used : ExpressionNode(org.ballerinalang.model.tree.expressions.ExpressionNode) SelectExpressionNode(org.ballerinalang.model.tree.clauses.SelectExpressionNode) BLangVariableReference(org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference) BLangTupleDestructure(org.wso2.ballerinalang.compiler.tree.statements.BLangTupleDestructure)

Example 22 with BLangVariableReference

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addCompoundAssignmentStatement.

public void addCompoundAssignmentStatement(DiagnosticPos pos, Set<Whitespace> ws, String operator) {
    BLangCompoundAssignment assignmentNode = (BLangCompoundAssignment) TreeBuilder.createCompoundAssignmentNode();
    assignmentNode.setExpression(exprNodeStack.pop());
    assignmentNode.setVariable((BLangVariableReference) exprNodeStack.pop());
    assignmentNode.pos = pos;
    assignmentNode.addWS(ws);
    assignmentNode.opKind = OperatorKind.valueFrom(operator);
    addStmtToCurrentBlock(assignmentNode);
}
Also used : BLangCompoundAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangCompoundAssignment)

Example 23 with BLangVariableReference

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference in project ballerina by ballerina-lang.

the class BLangPackageBuilder method createXmlAttributesRefExpr.

public void createXmlAttributesRefExpr(DiagnosticPos pos, Set<Whitespace> ws, boolean singleAttribute) {
    BLangXMLAttributeAccess xmlAttributeAccess = (BLangXMLAttributeAccess) TreeBuilder.createXMLAttributeAccessNode();
    xmlAttributeAccess.pos = pos;
    xmlAttributeAccess.addWS(ws);
    if (singleAttribute) {
        xmlAttributeAccess.indexExpr = (BLangExpression) exprNodeStack.pop();
    }
    xmlAttributeAccess.expr = (BLangVariableReference) exprNodeStack.pop();
    addExpressionNode(xmlAttributeAccess);
}
Also used : BLangXMLAttributeAccess(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttributeAccess)

Example 24 with BLangVariableReference

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addForeachStatement.

public void addForeachStatement(DiagnosticPos pos, Set<Whitespace> ws) {
    BLangForeach foreach = (BLangForeach) TreeBuilder.createForeachNode();
    foreach.addWS(ws);
    foreach.pos = pos;
    foreach.setCollection(exprNodeStack.pop());
    foreach.addWS(commaWsStack.pop());
    List<ExpressionNode> lExprList = exprNodeListStack.pop();
    lExprList.forEach(expressionNode -> foreach.addVariable((BLangVariableReference) expressionNode));
    BLangBlockStmt foreachBlock = (BLangBlockStmt) this.blockNodeStack.pop();
    foreachBlock.pos = pos;
    foreach.setBody(foreachBlock);
    addStmtToCurrentBlock(foreach);
}
Also used : BLangForeach(org.wso2.ballerinalang.compiler.tree.statements.BLangForeach) BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) ExpressionNode(org.ballerinalang.model.tree.expressions.ExpressionNode) SelectExpressionNode(org.ballerinalang.model.tree.clauses.SelectExpressionNode) BLangVariableReference(org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference)

Example 25 with BLangVariableReference

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference in project ballerina by ballerina-lang.

the class BLangPackageBuilder method createInvocationNode.

public void createInvocationNode(DiagnosticPos pos, Set<Whitespace> ws, String invocation, boolean argsAvailable) {
    BLangInvocation invocationNode = (BLangInvocation) TreeBuilder.createInvocationNode();
    invocationNode.pos = pos;
    invocationNode.addWS(ws);
    invocationNode.addWS(invocationWsStack.pop());
    if (argsAvailable) {
        List<ExpressionNode> exprNodes = exprNodeListStack.pop();
        exprNodes.forEach(exprNode -> invocationNode.argExprs.add((BLangExpression) exprNode));
        invocationNode.addWS(commaWsStack.pop());
    }
    invocationNode.expr = (BLangVariableReference) exprNodeStack.pop();
    invocationNode.name = (BLangIdentifier) createIdentifier(invocation);
    invocationNode.pkgAlias = (BLangIdentifier) createIdentifier(null);
    addExpressionNode(invocationNode);
}
Also used : ExpressionNode(org.ballerinalang.model.tree.expressions.ExpressionNode) SelectExpressionNode(org.ballerinalang.model.tree.clauses.SelectExpressionNode) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Aggregations

BLangVariableReference (org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference)16 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)8 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)8 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)7 ArrayList (java.util.ArrayList)6 BLangFieldBasedAccess (org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess)6 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)6 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)5 SelectExpressionNode (org.ballerinalang.model.tree.clauses.SelectExpressionNode)4 ExpressionNode (org.ballerinalang.model.tree.expressions.ExpressionNode)4 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)4 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)4 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)4 Arrays (java.util.Arrays)3 List (java.util.List)3 Map (java.util.Map)3 Stack (java.util.Stack)3 Collectors (java.util.stream.Collectors)3 CompilerPhase (org.ballerinalang.compiler.CompilerPhase)3 TreeBuilder (org.ballerinalang.model.TreeBuilder)3