Skip to content

Commit

Permalink
Add support for printing ASTNode::NODE_CLASS
Browse files Browse the repository at this point in the history
  • Loading branch information
greenozon committed Dec 5, 2023
1 parent 795ad18 commit 7d81581
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions ASTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3290,6 +3290,33 @@ void print_src(PycRef<ASTNode> node, PycModule* mod, std::ostream& pyc_output)
//pyc_output << ")";
}
break;
case ASTNode::NODE_CLASS:
{
pyc_output << "\n";
start_line(cur_indent, pyc_output);
pyc_output << "class ";

PycRef<ASTTuple> bases = node.cast<ASTClass>()->bases().cast<ASTTuple>();
if (bases->values().size() > 0) {
pyc_output << "(";
bool first = true;
for (const auto& val : bases->values()) {
if (!first)
pyc_output << ", ";
print_src(val, mod, pyc_output);
first = false;
}
pyc_output << "):\n";
}
else {
pyc_output << ":\n";
}
printClassDocstring = true;
PycRef<ASTNode> code = node.cast<ASTClass>()->code().cast<ASTCall>()
->func().cast<ASTFunction>()->code();
print_src(code, mod, pyc_output);
}
break;
default:
pyc_output << "<NODE:" << node->type() << ">";
fprintf(stderr, "Unsupported Node type: %d\n", node->type());
Expand Down

0 comments on commit 7d81581

Please sign in to comment.