use of org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment in project ballerina by ballerina-lang.
the class Desugar method createAssignmentStmt.
// TODO: Same function is used in symbol enter. Refactor this to reuse the same function.
private StatementNode createAssignmentStmt(BLangVariable variable) {
BLangSimpleVarRef varRef = (BLangSimpleVarRef) TreeBuilder.createSimpleVariableReferenceNode();
varRef.pos = variable.pos;
varRef.variableName = variable.name;
varRef.symbol = variable.symbol;
varRef.type = variable.type;
varRef.pkgAlias = (BLangIdentifier) TreeBuilder.createIdentifierNode();
BLangAssignment assignmentStmt = (BLangAssignment) TreeBuilder.createAssignmentNode();
assignmentStmt.expr = variable.expr;
assignmentStmt.pos = variable.pos;
assignmentStmt.addVariable(varRef);
return assignmentStmt;
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment in project ballerina by ballerina-lang.
the class Desugar method getSafeAssignSuccessPattern.
private BLangMatchStmtPatternClause getSafeAssignSuccessPattern(DiagnosticPos pos, BType lhsType, boolean isVarDef, BVarSymbol varSymbol, BLangExpression lhsExpr) {
// File _$_f1 => f = _$_f1;
// 1) Create the pattern variable
String patternSuccessCaseVarName = GEN_VAR_PREFIX.value + "t_match";
BLangVariable patternSuccessCaseVar = ASTBuilderUtil.createVariable(pos, patternSuccessCaseVarName, lhsType, null, new BVarSymbol(0, names.fromString(patternSuccessCaseVarName), this.env.scope.owner.pkgID, lhsType, this.env.scope.owner));
// 2) Create the pattern body
BLangExpression varRefExpr;
if (isVarDef) {
varRefExpr = ASTBuilderUtil.createVariableRef(pos, varSymbol);
} else {
varRefExpr = lhsExpr;
}
BLangVariableReference patternSuccessCaseVarRef = ASTBuilderUtil.createVariableRef(pos, patternSuccessCaseVar.symbol);
BLangAssignment assignmentStmtSuccessCase = ASTBuilderUtil.createAssignmentStmt(pos, new ArrayList<BLangExpression>() {
{
add(varRefExpr);
}
}, patternSuccessCaseVarRef, false);
BLangBlockStmt patternBlockSuccessCase = ASTBuilderUtil.createBlockStmt(pos, new ArrayList<BLangStatement>() {
{
add(assignmentStmtSuccessCase);
}
});
return ASTBuilderUtil.createMatchStatementPattern(pos, patternSuccessCaseVar, patternBlockSuccessCase);
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment in project ballerina by ballerina-lang.
the class Desugar method addArgInitExpr.
private void addArgInitExpr(BLangTransformer transformerNode, BLangVariable var) {
BLangSimpleVarRef varRef = new BLangLocalVarRef(var.symbol);
varRef.lhsVar = true;
varRef.pos = var.pos;
varRef.type = var.type;
BLangExpression initExpr = null;
switch(var.type.tag) {
case TypeTags.MAP:
initExpr = new BLangMapLiteral(new ArrayList<>(), var.type);
break;
case TypeTags.JSON:
initExpr = new BLangJSONLiteral(new ArrayList<>(), var.type);
break;
case TypeTags.STRUCT:
initExpr = new BLangStructLiteral(new ArrayList<>(), var.type);
break;
case TypeTags.INT:
case TypeTags.FLOAT:
case TypeTags.STRING:
case TypeTags.BOOLEAN:
case TypeTags.BLOB:
case TypeTags.XML:
return;
case TypeTags.TABLE:
case TypeTags.STREAM:
// TODO: add this once the able initializing is supported.
return;
default:
return;
}
initExpr.pos = var.pos;
BLangAssignment assignStmt = (BLangAssignment) TreeBuilder.createAssignmentNode();
assignStmt.pos = var.pos;
assignStmt.addVariable(varRef);
assignStmt.expr = initExpr;
transformerNode.body.stmts.add(0, assignStmt);
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment in project ballerina by ballerina-lang.
the class Desugar method visit.
@Override
public void visit(BLangBind bindNode) {
bindNode.varRef = rewriteExpr(bindNode.varRef);
bindNode.expr = rewriteExpr(bindNode.expr);
result = new BLangAssignment(bindNode.pos, Arrays.asList(bindNode.varRef), bindNode.expr, false);
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment in project ballerina by ballerina-lang.
the class IterableCodeDesugar method generateMap.
/**
* Generates statements for Map/Select operation. Select operation is similar to Map except that Select returns
* a Table where as Map returns an Array.
*
* v3,v4 = lambda(v1,v2);
*
* @param blockStmt target
* @param operation operation instance
*/
private void generateMap(BLangBlockStmt blockStmt, Operation operation) {
final DiagnosticPos pos = operation.pos;
final BLangAssignment assignment = ASTBuilderUtil.createAssignmentStmt(pos, blockStmt);
assignment.varRefs.add(ASTBuilderUtil.createVariableRef(operation.pos, operation.retVar.symbol));
assignment.expr = ASTBuilderUtil.createInvocationExpr(pos, operation.lambdaSymbol, Lists.of(operation.argVar), symResolver);
}
Aggregations