use of org.wso2.ballerinalang.compiler.semantics.model.types.BType 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.semantics.model.types.BType in project ballerina by ballerina-lang.
the class Desugar method getInitExpr.
private BLangExpression getInitExpr(BType type) {
// Don't need to create an empty init expressions if the type allows null.
if (type.isNullable()) {
return null;
}
switch(type.tag) {
case TypeTags.INT:
case TypeTags.FLOAT:
case TypeTags.BOOLEAN:
case TypeTags.STRING:
case TypeTags.BLOB:
// Int, float, boolean, string, blob types will get default values from VM side.
break;
case TypeTags.JSON:
return new BLangJSONLiteral(new ArrayList<>(), type);
case TypeTags.XML:
return new BLangXMLSequenceLiteral(type);
case TypeTags.TABLE:
return new BLangTableLiteral(type);
case TypeTags.STREAM:
return new BLangStreamLiteral(type, null);
case TypeTags.MAP:
return new BLangMapLiteral(new ArrayList<>(), type);
case TypeTags.STRUCT:
if (((BStructSymbol) type.tsymbol).isObject) {
return new BLangTypeInit();
}
return new BLangStructLiteral(new ArrayList<>(), type);
case TypeTags.ARRAY:
BLangArrayLiteral array = new BLangArrayLiteral();
array.exprs = new ArrayList<>();
array.type = type;
return rewriteExpr(array);
default:
break;
}
return null;
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.
the class Desugar method createInvocationForForeverBlock.
private BLangInvocation createInvocationForForeverBlock(BLangForever forever) {
List<BLangExpression> args = new ArrayList<>();
List<BType> retTypes = new ArrayList<>();
retTypes.add(symTable.noType);
BLangLiteral streamingQueryLiteral = ASTBuilderUtil.createLiteral(forever.pos, symTable.stringType, forever.getSiddhiQuery());
args.add(streamingQueryLiteral);
addReferenceVariablesToArgs(args, siddhiQueryBuilder.getInStreamRefs());
addReferenceVariablesToArgs(args, siddhiQueryBuilder.getInTableRefs());
addReferenceVariablesToArgs(args, siddhiQueryBuilder.getOutStreamRefs());
addReferenceVariablesToArgs(args, siddhiQueryBuilder.getOutTableRefs());
addFunctionPointersToArgs(args, forever.gettreamingQueryStatements());
return createInvocationNode(CREATE_FOREVER, args, retTypes);
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.
the class Desugar method createPatternIfCondition.
private BLangExpression createPatternIfCondition(BLangMatchStmtPatternClause patternClause, BVarSymbol varSymbol) {
BLangExpression binaryExpr;
BType patternType = patternClause.variable.type;
BType[] memberTypes;
if (patternType.tag == TypeTags.UNION) {
BUnionType unionType = (BUnionType) patternType;
memberTypes = unionType.memberTypes.toArray(new BType[0]);
} else {
memberTypes = new BType[1];
memberTypes[0] = patternType;
}
if (memberTypes.length == 1) {
binaryExpr = createPatternMatchBinaryExpr(patternClause.pos, varSymbol, memberTypes[0]);
} else {
BLangExpression lhsExpr = createPatternMatchBinaryExpr(patternClause.pos, varSymbol, memberTypes[0]);
BLangExpression rhsExpr = createPatternMatchBinaryExpr(patternClause.pos, varSymbol, memberTypes[1]);
binaryExpr = ASTBuilderUtil.createBinaryExpr(patternClause.pos, lhsExpr, rhsExpr, symTable.booleanType, OperatorKind.OR, (BOperatorSymbol) symResolver.resolveBinaryOperator(OperatorKind.OR, lhsExpr.type, rhsExpr.type));
for (int i = 2; i < memberTypes.length; i++) {
lhsExpr = createPatternMatchBinaryExpr(patternClause.pos, varSymbol, memberTypes[i]);
rhsExpr = binaryExpr;
binaryExpr = ASTBuilderUtil.createBinaryExpr(patternClause.pos, lhsExpr, rhsExpr, symTable.booleanType, OperatorKind.OR, (BOperatorSymbol) symResolver.resolveBinaryOperator(OperatorKind.OR, lhsExpr.type, rhsExpr.type));
}
}
return binaryExpr;
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.
the class EndpointDesugar method getTypeAccessExpression.
private BLangTypeofExpr getTypeAccessExpression(DiagnosticPos pos, BType serviceType) {
BLangTypeofExpr typeAccessExpr = (BLangTypeofExpr) TreeBuilder.createTypeAccessNode();
typeAccessExpr.pos = pos;
typeAccessExpr.resolvedType = serviceType;
typeAccessExpr.type = symTable.typeDesc;
return typeAccessExpr;
}
Aggregations