Skip to content

Commit

Permalink
Fix assignment for costant node
Browse files Browse the repository at this point in the history
  • Loading branch information
boozec committed Jul 14, 2024
1 parent 67687d9 commit 41f618c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/ast/Python3VisitorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ public Node visitAssignment(AssignmentContext ctx) {

R.put(((ExprNode) ((ExprListNode) lhr).getElem(0)).getId(), ctx.getStart().getLine());

// rewriter.insertAfter(assignmentNode.getRhrIndex(), "\n");

return assignmentNode;
}

Expand Down Expand Up @@ -431,11 +429,14 @@ private void optimizeBlock(BlockNode block, int lineStart, int lineStop, int ind
// int lastToken = ctx.expr().expr(counter).getStop().getTokenIndex();
// int firstToken = ctx.expr().expr(counter).getStart().getTokenIndex();
// rewriter.replace(firstToken, lastToken, newVar);
System.out.println("1 " + assignment.toPrint(""));
} else {

rewriter.insertBefore(assignment.getLhrIndex(), "\t");
}
} else {
String newVar = Label.newVar();
rewriter.insertBefore(index, newVar + "=" + rhr.toPrint("") + "\n");
rewriter.replace(assignment.getLhrIndex(), assignment.getRhrIndex(),
"\t" + lhr.toPrint("") + "=" + newVar + "\n");
}
}
}
Expand Down
1 change: 1 addition & 0 deletions test/2a.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
m = m * tmp
tmp = 2 * x
n = n - 1

print(m + tmp)

0 comments on commit 41f618c

Please sign in to comment.