Merge pull request #458 from TiZCrocodile/support-for-LOAD_CLASSDEREF

Added support for `LOAD_CLASSDEREF`
This commit is contained in:
Michael Hansen
2024-02-26 14:27:51 -08:00
committed by GitHub
4 changed files with 18 additions and 2 deletions

View File

@@ -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++) {
@@ -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:
@@ -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();

Binary file not shown.

View File

@@ -0,0 +1,4 @@
def func():
x = 1
class my_class:
y = x

View File

@@ -0,0 +1,6 @@
def func ( ) : <EOL>
<INDENT>
x = 1 <EOL>
class my_class : <EOL>
<INDENT>
y = x <EOL>