Search in sources :

Example 66 with BLangExpression

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

the class BLangPackageBuilder method getExpressionsInTemplate.

// Private methods
private List<BLangExpression> getExpressionsInTemplate(DiagnosticPos pos, Set<Whitespace> ws, Stack<String> precedingTextFragments, String endingText, NodeKind targetStrExprKind) {
    List<BLangExpression> expressions = new ArrayList<>();
    endingText = endingText == null ? "" : StringEscapeUtils.unescapeJava(endingText);
    addLiteralValue(pos, ws, TypeTags.STRING, endingText);
    expressions.add((BLangExpression) exprNodeStack.pop());
    while (!precedingTextFragments.empty()) {
        expressions.add((BLangExpression) exprNodeStack.pop());
        String textFragment = precedingTextFragments.pop();
        textFragment = textFragment == null ? "" : StringEscapeUtils.unescapeJava(textFragment);
        addLiteralValue(pos, ws, TypeTags.STRING, textFragment);
        expressions.add((BLangExpression) exprNodeStack.pop());
    }
    Collections.reverse(expressions);
    return expressions;
}
Also used : ArrayList(java.util.ArrayList) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 67 with BLangExpression

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

the class BLangPackageBuilder method addThrowStmt.

public void addThrowStmt(DiagnosticPos poc, Set<Whitespace> ws) {
    ExpressionNode throwExpr = this.exprNodeStack.pop();
    BLangThrow throwNode = (BLangThrow) TreeBuilder.createThrowNode();
    throwNode.pos = poc;
    throwNode.addWS(ws);
    throwNode.expr = (BLangExpression) throwExpr;
    addStmtToCurrentBlock(throwNode);
}
Also used : BLangThrow(org.wso2.ballerinalang.compiler.tree.statements.BLangThrow) ExpressionNode(org.ballerinalang.model.tree.expressions.ExpressionNode) SelectExpressionNode(org.ballerinalang.model.tree.clauses.SelectExpressionNode)

Example 68 with BLangExpression

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

the class BLangPackageBuilder method addExpressionStmt.

public void addExpressionStmt(DiagnosticPos pos, Set<Whitespace> ws) {
    BLangExpressionStmt exprStmt = (BLangExpressionStmt) TreeBuilder.createExpressionStatementNode();
    exprStmt.pos = pos;
    exprStmt.addWS(ws);
    exprStmt.expr = (BLangExpression) exprNodeStack.pop();
    addStmtToCurrentBlock(exprStmt);
}
Also used : BLangExpressionStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt)

Example 69 with BLangExpression

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

the class BLangPackageBuilder method addRetryCountExpression.

public void addRetryCountExpression() {
    BLangTransaction transaction = (BLangTransaction) transactionNodeStack.peek();
    transaction.retryCount = (BLangExpression) exprNodeStack.pop();
}
Also used : BLangTransaction(org.wso2.ballerinalang.compiler.tree.statements.BLangTransaction)

Example 70 with BLangExpression

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

the class BLangPackageBuilder method createTernaryExpr.

public void createTernaryExpr(DiagnosticPos pos, Set<Whitespace> ws) {
    BLangTernaryExpr ternaryExpr = (BLangTernaryExpr) TreeBuilder.createTernaryExpressionNode();
    ternaryExpr.pos = pos;
    ternaryExpr.addWS(ws);
    ternaryExpr.elseExpr = (BLangExpression) exprNodeStack.pop();
    ternaryExpr.thenExpr = (BLangExpression) exprNodeStack.pop();
    ternaryExpr.expr = (BLangExpression) exprNodeStack.pop();
    if (ternaryExpr.expr.getKind() == NodeKind.TERNARY_EXPR) {
        // Re-organizing ternary expression tree if there nested ternary expressions.
        BLangTernaryExpr root = (BLangTernaryExpr) ternaryExpr.expr;
        BLangTernaryExpr parent = root;
        while (parent.elseExpr.getKind() == NodeKind.TERNARY_EXPR) {
            parent = (BLangTernaryExpr) parent.elseExpr;
        }
        ternaryExpr.expr = parent.elseExpr;
        parent.elseExpr = ternaryExpr;
        ternaryExpr = root;
    }
    addExpressionNode(ternaryExpr);
}
Also used : BLangTernaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTernaryExpr)

Aggregations

BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)101 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)27 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)26 ArrayList (java.util.ArrayList)22 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)19 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)15 BLangLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)15 SelectExpressionNode (org.ballerinalang.model.tree.clauses.SelectExpressionNode)14 ExpressionNode (org.ballerinalang.model.tree.expressions.ExpressionNode)14 RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)14 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)13 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)11 BLangArrayLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral)11 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)11 BLangTypeConversionExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeConversionExpr)11 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)10 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)10 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)10 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)10 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)10