Skip to content
Open
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions ASTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1053,9 +1053,21 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
case Pyc::POP_JUMP_IF_TRUE_A:
case Pyc::POP_JUMP_FORWARD_IF_FALSE_A:
case Pyc::POP_JUMP_FORWARD_IF_TRUE_A:
case Pyc::POP_JUMP_FORWARD_IF_NONE_A:
case Pyc::POP_JUMP_FORWARD_IF_NOT_NONE_A:
case Pyc::INSTRUMENTED_POP_JUMP_IF_FALSE_A:
case Pyc::INSTRUMENTED_POP_JUMP_IF_TRUE_A:
{
// if POP_JUMP_FORWARD_IF_NONE_A or ...NOT_NONE -
// then first push to the stack the ASTCompare to simulate like a IS_OP with a None were existed before this opcode
if (opcode == Pyc::POP_JUMP_FORWARD_IF_NONE_A
|| opcode == Pyc::POP_JUMP_FORWARD_IF_NOT_NONE_A) {
PycRef<ASTNode> left = stack.top();
stack.pop();
stack.push(new ASTCompare(left, nullptr, (opcode == Pyc::POP_JUMP_FORWARD_IF_NOT_NONE_A
? ASTCompare::CMP_IS : ASTCompare::CMP_IS_NOT)));
}

PycRef<ASTNode> cond = stack.top();
PycRef<ASTCondBlock> ifblk;
int popped = ASTCondBlock::UNINITED;
Expand All @@ -1064,6 +1076,8 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
|| opcode == Pyc::POP_JUMP_IF_TRUE_A
|| opcode == Pyc::POP_JUMP_FORWARD_IF_FALSE_A
|| opcode == Pyc::POP_JUMP_FORWARD_IF_TRUE_A
|| opcode == Pyc::POP_JUMP_FORWARD_IF_NONE_A
|| opcode == Pyc::POP_JUMP_FORWARD_IF_NOT_NONE_A
|| opcode == Pyc::INSTRUMENTED_POP_JUMP_IF_FALSE_A
|| opcode == Pyc::INSTRUMENTED_POP_JUMP_IF_TRUE_A) {
/* Pop condition before the jump */
Expand Down Expand Up @@ -1094,6 +1108,8 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
if (mod->verCompare(3, 12) >= 0
|| opcode == Pyc::JUMP_IF_FALSE_A
|| opcode == Pyc::JUMP_IF_TRUE_A
|| opcode == Pyc::POP_JUMP_FORWARD_IF_NONE_A
|| opcode == Pyc::POP_JUMP_FORWARD_IF_NOT_NONE_A
|| opcode == Pyc::POP_JUMP_FORWARD_IF_TRUE_A
|| opcode == Pyc::POP_JUMP_FORWARD_IF_FALSE_A) {
/* Offset is relative in these cases */
Expand Down
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/input/test_pop_jump_forward_if_none&not_none.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def func():
a = 1
if a is None:
print('a is None')
if a is not None:
print('a is not None')
return None
11 changes: 11 additions & 0 deletions tests/tokenized/test_pop_jump_forward_if_none&not_none.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def func ( ) : <EOL>
<INDENT>
a = 1 <EOL>
if a is None : <EOL>
<INDENT>
print ( 'a is None' ) <EOL>
<OUTDENT>
if a is not None : <EOL>
<INDENT>
print ( 'a is not None' ) <EOL>
return None <EOL>