use of org.wso2.ballerinalang.compiler.tree.statements.BLangLock in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
public void visit(BLangLock lockNode) {
if (lockNode.lockVariables.isEmpty()) {
this.genNode(lockNode.body, this.env);
return;
}
Operand gotoLockEndAddr = getOperand(-1);
Instruction instructGotoLockEnd = InstructionFactory.get(InstructionCodes.GOTO, gotoLockEndAddr);
Operand[] operands = getOperands(lockNode);
ErrorTableAttributeInfo errorTable = createErrorTableIfAbsent(currentPkgInfo);
int fromIP = nextIP();
emit((InstructionCodes.LOCK), operands);
this.genNode(lockNode.body, this.env);
int toIP = nextIP() - 1;
emit((InstructionCodes.UNLOCK), operands);
emit(instructGotoLockEnd);
ErrorTableEntry errorTableEntry = new ErrorTableEntry(fromIP, toIP, nextIP(), 0, -1);
errorTable.addErrorTableEntry(errorTableEntry);
emit((InstructionCodes.UNLOCK), operands);
emit(InstructionFactory.get(InstructionCodes.THROW, getOperand(-1)));
gotoLockEndAddr.value = nextIP();
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangLock in project ballerina by ballerina-lang.
the class CodeGenerator method getOperands.
private Operand[] getOperands(BLangLock lockNode) {
Operand[] operands = new Operand[(lockNode.lockVariables.size() * 2) + 1];
int i = 0;
operands[i++] = new Operand(lockNode.lockVariables.size());
for (BVarSymbol varSymbol : lockNode.lockVariables) {
int typeSigCPIndex = addUTF8CPEntry(currentPkgInfo, varSymbol.getType().getDesc());
TypeRefCPEntry typeRefCPEntry = new TypeRefCPEntry(typeSigCPIndex);
operands[i++] = getOperand(currentPkgInfo.addCPEntry(typeRefCPEntry));
operands[i++] = varSymbol.varIndex;
}
return operands;
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangLock 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.BLangLock in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addLockStmt.
public void addLockStmt(DiagnosticPos pos, Set<Whitespace> ws) {
BLangLock lockNode = (BLangLock) TreeBuilder.createLockNode();
lockNode.pos = pos;
lockNode.addWS(ws);
BLangBlockStmt lockBlock = (BLangBlockStmt) this.blockNodeStack.pop();
lockBlock.pos = pos;
lockNode.setBody(lockBlock);
addStmtToCurrentBlock(lockNode);
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangLock in project ballerina by ballerina-lang.
the class Desugar method visit.
@Override
public void visit(BLangLock lockNode) {
enclLocks.push(lockNode);
lockNode.body = rewrite(lockNode.body, env);
enclLocks.pop();
lockNode.lockVariables = lockNode.lockVariables.stream().sorted((v1, v2) -> {
String o1FullName = String.join(":", v1.pkgID.getName().getValue(), v1.name.getValue());
String o2FullName = String.join(":", v2.pkgID.getName().getValue(), v2.name.getValue());
return o1FullName.compareTo(o2FullName);
}).collect(Collectors.toSet());
result = lockNode;
}
Aggregations