use of org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef in project ballerina by ballerina-lang.
the class SemanticAnalyzer method createVarDef.
private BLangVariableDef createVarDef(BLangVariable var) {
BLangVariableDef varDefNode = new BLangVariableDef();
varDefNode.var = var;
varDefNode.pos = var.pos;
return varDefNode;
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef in project ballerina by ballerina-lang.
the class CodeGenerator method addParameterDefaultValues.
private void addParameterDefaultValues(BLangInvokableNode invokableNode, CallableUnitInfo callableUnitInfo) {
int paramDefaultsAttrNameIndex = addUTF8CPEntry(currentPkgInfo, AttributeInfo.Kind.PARAMETER_DEFAULTS_ATTRIBUTE.value());
ParamDefaultValueAttributeInfo paramDefaulValAttrInfo = new ParamDefaultValueAttributeInfo(paramDefaultsAttrNameIndex);
// Only named parameters can have default values.
for (BLangVariableDef param : invokableNode.defaultableParams) {
DefaultValue defaultVal = getDefaultValue((BLangLiteral) param.var.expr);
paramDefaulValAttrInfo.addParamDefaultValueInfo(defaultVal);
}
callableUnitInfo.addAttributeInfo(AttributeInfo.Kind.PARAMETER_DEFAULTS_ATTRIBUTE, paramDefaulValAttrInfo);
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef in project ballerina by ballerina-lang.
the class ASTBuilderUtil method createVariableDef.
static BLangVariableDef createVariableDef(DiagnosticPos pos) {
final BLangVariableDef variableDef = (BLangVariableDef) TreeBuilder.createVariableDefinitionNode();
variableDef.pos = pos;
return variableDef;
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef in project ballerina by ballerina-lang.
the class ASTBuilderUtil method createVariableDef.
static BLangVariableDef createVariableDef(DiagnosticPos pos, BLangVariable variable) {
final BLangVariableDef variableDef = (BLangVariableDef) TreeBuilder.createVariableDefinitionNode();
variableDef.pos = pos;
variableDef.var = variable;
return variableDef;
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef 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);
}
Aggregations