use of org.wso2.ballerinalang.compiler.tree.statements.BLangStatement in project ballerina by ballerina-lang.
the class SymbolEnter method defineObjectInitFunction.
private void defineObjectInitFunction(BLangObject object, SymbolEnv conEnv) {
BLangFunction initFunction = object.initFunction;
if (initFunction == null) {
initFunction = createInitFunction(object.pos, "", Names.OBJECT_INIT_SUFFIX);
}
initFunction.attachedFunction = true;
// Set cached receiver to the init function
initFunction.receiver = object.receiver;
initFunction.flagSet.add(Flag.ATTACHED);
// Add object level variables to the init function
BLangFunction finalInitFunction = initFunction;
object.fields.stream().filter(f -> f.expr != null).forEachOrdered(v -> finalInitFunction.initFunctionStmts.put(v.symbol, (BLangStatement) createAssignmentStmt(v)));
object.initFunction = initFunction;
defineNode(object.initFunction, conEnv);
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangStatement in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
public void visit(BLangBlockStmt blockNode) {
SymbolEnv blockEnv = SymbolEnv.createBlockEnv(blockNode, this.env);
for (BLangStatement stmt : blockNode.stmts) {
if (stmt.getKind() != NodeKind.TRY && stmt.getKind() != NodeKind.CATCH && stmt.getKind() != NodeKind.IF) {
addLineNumberInfo(stmt.pos);
}
genNode(stmt, blockEnv);
// Update the maxRegIndexes structure
setMaxRegIndexes(regIndexes, maxRegIndexes);
// Reset the regIndexes structure for every statement
regIndexes = new VariableIndex(REG);
}
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangStatement in project ballerina by ballerina-lang.
the class CodeGenerator method generateFinallyInstructions.
private void generateFinallyInstructions(BLangStatement statement, NodeKind... expectedParentKinds) {
BLangStatement current = statement;
while (current != null && current.statementLink.parent != null) {
BLangStatement parent = current.statementLink.parent.statement;
for (NodeKind expected : expectedParentKinds) {
if (expected == parent.getKind()) {
return;
}
}
if (NodeKind.TRY == parent.getKind()) {
BLangTryCatchFinally tryCatchFinally = (BLangTryCatchFinally) parent;
if (tryCatchFinally.finallyBody != null && current != tryCatchFinally.finallyBody) {
genNode(tryCatchFinally.finallyBody, env);
}
} else if (NodeKind.LOCK == parent.getKind()) {
BLangLock lockNode = (BLangLock) parent;
if (!lockNode.lockVariables.isEmpty()) {
Operand[] operands = getOperands(lockNode);
emit((InstructionCodes.UNLOCK), operands);
}
}
current = parent;
}
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangStatement in project ballerina by ballerina-lang.
the class ASTBuilderUtil method createBlockStmt.
static BLangBlockStmt createBlockStmt(DiagnosticPos pos, List<BLangStatement> stmts) {
final BLangBlockStmt blockNode = (BLangBlockStmt) TreeBuilder.createBlockNode();
blockNode.pos = pos;
blockNode.stmts = stmts;
return blockNode;
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangStatement 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;
}
Aggregations