use of org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression in project ballerina by ballerina-lang.
the class Desugar method createPatternMatchBinaryExpr.
private BLangExpression createPatternMatchBinaryExpr(DiagnosticPos pos, BVarSymbol varSymbol, BType patternType) {
if (patternType == symTable.nullType) {
BLangSimpleVarRef varRef = ASTBuilderUtil.createVariableRef(pos, varSymbol);
BLangLiteral bLangLiteral = ASTBuilderUtil.createLiteral(pos, symTable.nullType, null);
return ASTBuilderUtil.createBinaryExpr(pos, varRef, bLangLiteral, symTable.booleanType, OperatorKind.EQUAL, (BOperatorSymbol) symResolver.resolveBinaryOperator(OperatorKind.EQUAL, symTable.anyType, symTable.nullType));
} else {
return createIsAssignableExpression(pos, varSymbol, patternType);
}
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression in project ballerina by ballerina-lang.
the class Desugar method createTypeConversionExpr.
private BLangExpression createTypeConversionExpr(BLangExpression expr, BType sourceType, BType targetType) {
BConversionOperatorSymbol symbol = (BConversionOperatorSymbol) symResolver.resolveConversionOperator(sourceType, targetType);
BLangTypeConversionExpr conversionExpr = (BLangTypeConversionExpr) TreeBuilder.createTypeConversionNode();
conversionExpr.pos = expr.pos;
conversionExpr.expr = expr;
conversionExpr.type = targetType;
conversionExpr.conversionSymbol = symbol;
return conversionExpr;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression in project ballerina by ballerina-lang.
the class Desugar method visit.
@Override
public void visit(BLangTupleDestructure stmt) {
// var (a, b) = (tuple)
//
// desugar once
// any[] x = (tuple);
// a = x[0];
final BLangBlockStmt blockStmt = ASTBuilderUtil.createBlockStmt(stmt.pos);
BType runTimeType = new BArrayType(symTable.anyType);
final BLangVariable tuple = ASTBuilderUtil.createVariable(stmt.pos, "", runTimeType, null, new BVarSymbol(0, names.fromString("tuple"), this.env.scope.owner.pkgID, runTimeType, this.env.scope.owner));
tuple.expr = stmt.expr;
final BLangVariableDef variableDef = ASTBuilderUtil.createVariableDefStmt(stmt.pos, blockStmt);
variableDef.var = tuple;
for (int index = 0; index < stmt.varRefs.size(); index++) {
BLangExpression varRef = stmt.varRefs.get(index);
BLangLiteral indexExpr = ASTBuilderUtil.createLiteral(stmt.pos, symTable.intType, (long) index);
BLangIndexBasedAccess arrayAccess = ASTBuilderUtil.createIndexBasesAccessExpr(stmt.pos, symTable.anyType, tuple.symbol, indexExpr);
final BLangExpression assignmentExpr;
if (types.isValueType(varRef.type)) {
BLangTypeConversionExpr castExpr = (BLangTypeConversionExpr) TreeBuilder.createTypeConversionNode();
castExpr.expr = arrayAccess;
castExpr.conversionSymbol = Symbols.createUnboxValueTypeOpSymbol(symTable.anyType, varRef.type);
castExpr.type = varRef.type;
assignmentExpr = castExpr;
} else {
assignmentExpr = arrayAccess;
}
final BLangAssignment assignmentStmt = ASTBuilderUtil.createAssignmentStmt(stmt.pos, blockStmt);
assignmentStmt.declaredWithVar = stmt.declaredWithVar;
assignmentStmt.varRefs = Lists.of(varRef);
assignmentStmt.expr = assignmentExpr;
}
result = rewrite(blockStmt, env);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression in project ballerina by ballerina-lang.
the class Desugar method addReferenceVariablesToArgs.
private void addReferenceVariablesToArgs(List<BLangExpression> args, List<BLangExpression> varRefs) {
BLangArrayLiteral localRefs = createArrayLiteralExprNode();
varRefs.forEach(varRef -> localRefs.exprs.add(rewrite(varRef, env)));
args.add(localRefs);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression in project ballerina by ballerina-lang.
the class Desugar method reorderNamedArgs.
private void reorderNamedArgs(BLangInvocation iExpr, BInvokableSymbol invocableSymbol) {
Map<String, BLangExpression> namedArgs = new HashMap<>();
iExpr.namedArgs.forEach(expr -> namedArgs.put(((NamedArgNode) expr).getName().value, expr));
// Re-order the named arguments
List<BLangExpression> args = new ArrayList<>();
for (BVarSymbol param : invocableSymbol.defaultableParams) {
args.add(namedArgs.get(param.name.value));
}
iExpr.namedArgs = args;
}
Aggregations