use of org.wso2.ballerinalang.compiler.tree.statements.BLangTransaction in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
public void visit(BLangTransaction transactionNode) {
++transactionIndex;
Operand transactionIndexOperand = getOperand(transactionIndex);
Operand retryCountRegIndex = new RegIndex(-1, TypeTags.INT);
if (transactionNode.retryCount != null) {
this.genNode(transactionNode.retryCount, this.env);
retryCountRegIndex = transactionNode.retryCount.regIndex;
}
Operand committedFuncRegIndex = new RegIndex(-1, TypeTags.INVOKABLE);
if (transactionNode.onCommitFunction != null) {
committedFuncRegIndex.value = getFuncRefCPIndex((BInvokableSymbol) ((BLangFunctionVarRef) transactionNode.onCommitFunction).symbol);
}
Operand abortedFuncRegIndex = new RegIndex(-1, TypeTags.INVOKABLE);
if (transactionNode.onAbortFunction != null) {
abortedFuncRegIndex.value = getFuncRefCPIndex((BInvokableSymbol) ((BLangFunctionVarRef) transactionNode.onAbortFunction).symbol);
}
ErrorTableAttributeInfo errorTable = createErrorTableIfAbsent(currentPkgInfo);
Operand transStmtEndAddr = getOperand(-1);
Operand transStmtAbortEndAddr = getOperand(-1);
Operand transStmtFailEndAddr = getOperand(-1);
Instruction gotoAbortTransBlockEnd = InstructionFactory.get(InstructionCodes.GOTO, transStmtAbortEndAddr);
Instruction gotoFailTransBlockEnd = InstructionFactory.get(InstructionCodes.GOTO, transStmtFailEndAddr);
abortInstructions.push(gotoAbortTransBlockEnd);
failInstructions.push(gotoFailTransBlockEnd);
// start transaction
this.emit(InstructionCodes.TR_BEGIN, transactionIndexOperand, retryCountRegIndex, committedFuncRegIndex, abortedFuncRegIndex);
Operand transBlockStartAddr = getOperand(nextIP());
// retry transaction;
Operand retryEndWithThrowAddr = getOperand(-1);
Operand retryEndWithNoThrowAddr = getOperand(-1);
this.emit(InstructionCodes.TR_RETRY, transactionIndexOperand, retryEndWithThrowAddr, retryEndWithNoThrowAddr);
// process transaction statements
this.genNode(transactionNode.transactionBody, this.env);
// end the transaction
int transBlockEndAddr = nextIP();
this.emit(InstructionCodes.TR_END, transactionIndexOperand, getOperand(TransactionStatus.SUCCESS.value()));
abortInstructions.pop();
failInstructions.pop();
emit(InstructionCodes.GOTO, transStmtEndAddr);
// CodeGen for error handling.
int errorTargetIP = nextIP();
transStmtFailEndAddr.value = errorTargetIP;
emit(InstructionCodes.TR_END, transactionIndexOperand, getOperand(TransactionStatus.FAILED.value()));
if (transactionNode.onRetryBody != null) {
this.genNode(transactionNode.onRetryBody, this.env);
}
emit(InstructionCodes.GOTO, transBlockStartAddr);
retryEndWithThrowAddr.value = nextIP();
emit(InstructionCodes.TR_END, transactionIndexOperand, getOperand(TransactionStatus.END.value()));
emit(InstructionCodes.THROW, getOperand(-1));
ErrorTableEntry errorTableEntry = new ErrorTableEntry(transBlockStartAddr.value, transBlockEndAddr, errorTargetIP, 0, -1);
errorTable.addErrorTableEntry(errorTableEntry);
transStmtAbortEndAddr.value = nextIP();
emit(InstructionCodes.TR_END, transactionIndexOperand, getOperand(TransactionStatus.ABORTED.value()));
int transactionEndIp = nextIP();
transStmtEndAddr.value = transactionEndIp;
retryEndWithNoThrowAddr.value = transactionEndIp;
emit(InstructionCodes.TR_END, transactionIndexOperand, getOperand(TransactionStatus.END.value()));
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangTransaction in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addRetryCountExpression.
public void addRetryCountExpression() {
BLangTransaction transaction = (BLangTransaction) transactionNodeStack.peek();
transaction.retryCount = (BLangExpression) exprNodeStack.pop();
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangTransaction in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addAbortedBlock.
public void addAbortedBlock() {
BLangTransaction transaction = (BLangTransaction) transactionNodeStack.peek();
transaction.onAbortFunction = (BLangExpression) exprNodeStack.pop();
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangTransaction in project ballerina by ballerina-lang.
the class BLangPackageBuilder method endTransactionStmt.
public void endTransactionStmt(DiagnosticPos pos, Set<Whitespace> ws, boolean distributedTransactionEnabled) {
BLangTransaction transaction = (BLangTransaction) transactionNodeStack.pop();
transaction.pos = pos;
transaction.addWS(ws);
addStmtToCurrentBlock(transaction);
if (distributedTransactionEnabled) {
// TODO This is a temporary workaround to flag coordinator service start
String value = compilerOptions.get(CompilerOptionName.TRANSACTION_EXISTS);
if (value != null) {
return;
}
compilerOptions.put(CompilerOptionName.TRANSACTION_EXISTS, "true");
List<String> nameComps = getPackageNameComps(Names.TRANSACTION_PACKAGE.value);
addImportPackageDeclaration(pos, null, Names.TRANSACTION_ORG.value, nameComps, Names.DEFAULT_VERSION.value, Names.DOT.value + nameComps.get(nameComps.size() - 1));
}
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangTransaction in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addCommittedBlock.
public void addCommittedBlock() {
BLangTransaction transaction = (BLangTransaction) transactionNodeStack.peek();
transaction.onCommitFunction = (BLangExpression) exprNodeStack.pop();
}
Aggregations