Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for LOAD_CLASSDEREF #458

Merged
merged 2 commits into from
Feb 26, 2024
Merged
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
10 changes: 8 additions & 2 deletions ASTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,12 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
break;
case Pyc::BUILD_TUPLE_A:
{
// if class is a closure code, ignore this tuple
PycRef<ASTNode> tos = stack.top();
if (tos->type() == ASTNode::NODE_LOADBUILDCLASS) {
break;
}

ASTTuple::value_t values;
values.resize(operand);
for (int i=0; i<operand; i++) {
Expand Down Expand Up @@ -1501,6 +1507,7 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
}
break;
case Pyc::LOAD_DEREF_A:
case Pyc::LOAD_CLASSDEREF_A:
stack.push(new ASTName(code->getCellVar(mod, operand)));
break;
case Pyc::LOAD_FAST_A:
Expand Down Expand Up @@ -3358,8 +3365,7 @@ void decompyle(PycRef<PycCode> code, PycModule* mod, std::ostream& pyc_output)
PycRef<ASTObject> src = store->src().cast<ASTObject>();
PycRef<PycString> srcString = src->object().try_cast<PycString>();
PycRef<ASTName> dest = store->dest().cast<ASTName>();
if (srcString != nullptr && srcString->isEqual(code->name().cast<PycObject>())
&& dest->name()->isEqual("__qualname__")) {
if (dest->name()->isEqual("__qualname__")) {
// __qualname__ = '<Class Name>'
// Automatically added by Python 3.3 and later
clean->removeFirst();
Expand Down
Binary file added tests/compiled/load_classderef.3.4.pyc
Binary file not shown.
4 changes: 4 additions & 0 deletions tests/input/load_classderef.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def func():
x = 1
class my_class:
y = x
6 changes: 6 additions & 0 deletions tests/tokenized/load_classderef.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def func ( ) : <EOL>
<INDENT>
x = 1 <EOL>
class my_class : <EOL>
<INDENT>
y = x <EOL>
Loading