Search in sources :

Example 41 with BLangExpression

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

the class ASTBuilderUtil method generateConversionExpr.

static BLangExpression generateConversionExpr(BLangExpression varRef, BType target, SymbolResolver symResolver) {
    if (varRef.type.tag == target.tag || varRef.type.tag > TypeTags.TYPEDESC) {
        return varRef;
    }
    // Box value using cast expression.
    final BLangTypeConversionExpr conversion = (BLangTypeConversionExpr) TreeBuilder.createTypeConversionNode();
    conversion.pos = varRef.pos;
    conversion.expr = varRef;
    conversion.type = target;
    conversion.targetType = target;
    conversion.conversionSymbol = (BConversionOperatorSymbol) symResolver.resolveConversionOperator(varRef.type, target);
    return conversion;
}
Also used : BLangTypeConversionExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeConversionExpr)

Example 42 with BLangExpression

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

the class ASTBuilderUtil method createIfElseStmt.

static BLangIf createIfElseStmt(DiagnosticPos pos, BLangExpression conditionExpr, BLangBlockStmt thenBody, BLangStatement elseStmt) {
    final BLangIf ifNode = (BLangIf) TreeBuilder.createIfElseStatementNode();
    ifNode.pos = pos;
    ifNode.expr = conditionExpr;
    ifNode.body = thenBody;
    ifNode.elseStmt = elseStmt;
    return ifNode;
}
Also used : BLangIf(org.wso2.ballerinalang.compiler.tree.statements.BLangIf)

Example 43 with BLangExpression

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

the class ASTBuilderUtil method createVariable.

static BLangVariable createVariable(DiagnosticPos pos, String name, BType type, BLangExpression expr, BVarSymbol varSymbol) {
    final BLangVariable varNode = (BLangVariable) TreeBuilder.createVariableNode();
    varNode.pos = pos;
    varNode.name = createIdentifier(pos, name);
    varNode.type = type;
    varNode.expr = expr;
    varNode.symbol = varSymbol;
    return varNode;
}
Also used : BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 44 with BLangExpression

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

the class ASTBuilderUtil method createUnaryExpr.

static BLangUnaryExpr createUnaryExpr(DiagnosticPos pos, BLangExpression expr, BType type, OperatorKind kind, BOperatorSymbol symbol) {
    final BLangUnaryExpr unaryExpr = (BLangUnaryExpr) TreeBuilder.createUnaryExpressionNode();
    unaryExpr.pos = pos;
    unaryExpr.expr = expr;
    unaryExpr.type = type;
    unaryExpr.operator = kind;
    unaryExpr.opSymbol = symbol;
    return unaryExpr;
}
Also used : BLangUnaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangUnaryExpr)

Example 45 with BLangExpression

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

the class ASTBuilderUtil method generateArgExprs.

static List<BLangExpression> generateArgExprs(DiagnosticPos pos, List<BLangVariable> args, List<BVarSymbol> formalParams, SymbolResolver symResolver) {
    List<BLangExpression> argsExpr = new ArrayList<>();
    final List<BLangSimpleVarRef> variableRefList = createVariableRefList(pos, args);
    for (int i = 0; i < variableRefList.size(); i++) {
        BLangSimpleVarRef varRef = variableRefList.get(i);
        BType target = formalParams.get(i).type;
        BType source = varRef.symbol.type;
        if (source != target) {
            argsExpr.add(generateConversionExpr(varRef, target, symResolver));
            continue;
        }
        argsExpr.add(varRef);
    }
    return argsExpr;
}
Also used : BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) ArrayList(java.util.ArrayList) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

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