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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations