Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/codeGenerators/orchestration/nodejs/toOrchestration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ export default function codeGenerator(node: any, options: any = {}): any {
}
if (node.expression.operator === '-='){
increments = codeGenerator(node.expression.rightHandSide);
return `\n${privateStateName}_newCommitmentValue = generalise(parseInt(${privateStateName}_newCommitmentValue.integer, 10) + (${increments}));\n`;
const incrementsWithParens = node.expression.rightHandSide.nodeType === 'BinaryOperation'
? `(${increments})`
: increments;
return `\n${privateStateName}_newCommitmentValue = generalise(parseInt(${privateStateName}_newCommitmentValue.integer, 10) - (${incrementsWithParens}));\n`;
}
if (node.expression.operator === '='){
increments = codeGenerator(node.expression.rightHandSide);
Expand Down Expand Up @@ -163,22 +166,30 @@ export default function codeGenerator(node: any, options: any = {}): any {
// To ensure the left hand side is always a general number, we generalise it here (excluding the initialisation in a for loop).
if (!node.isInitializationAssignment && node.rightHandSide.subType !== 'generalNumber'){
if (['+=', '-=', '*='].includes(node.operator)) {
const rightHandSideCode = codeGenerator(node.rightHandSide);
const rightHandSideWithParens = node.rightHandSide.nodeType === 'BinaryOperation'
? `(${rightHandSideCode})`
: rightHandSideCode;
return `${codeGenerator(node.leftHandSide, {
lhs: true,
})} = generalise(${codeGenerator(node.leftHandSide)} ${node.operator.charAt(
0,
)} ${codeGenerator(node.rightHandSide)})`;
)} ${rightHandSideWithParens})`;
}
return `${codeGenerator(node.leftHandSide, { lhs: true })} ${
node.operator
} generalise(${codeGenerator(node.rightHandSide)})`;
} else {
if (['+=', '-=', '*='].includes(node.operator)) {
const rightHandSideCode = codeGenerator(node.rightHandSide);
const rightHandSideWithParens = node.rightHandSide.nodeType === 'BinaryOperation'
? `(${rightHandSideCode})`
: rightHandSideCode;
return `${codeGenerator(node.leftHandSide, {
lhs: true,
})} = ${codeGenerator(node.leftHandSide)} ${node.operator.charAt(
0,
)} ${codeGenerator(node.rightHandSide)}`;
)} ${rightHandSideWithParens}`;
}
return `${codeGenerator(node.leftHandSide, { lhs: true })} ${
node.operator
Expand Down