2013-06-28 23:22:25 -07:00
|
|
|
#include <cstring>
|
2009-07-26 10:07:13 +00:00
|
|
|
#include "ASTree.h"
|
|
|
|
#include "FastStack.h"
|
2011-10-23 17:48:10 -07:00
|
|
|
#include "pyc_numeric.h"
|
2009-07-26 10:07:13 +00:00
|
|
|
#include "bytecode.h"
|
|
|
|
|
2009-07-27 00:30:31 +00:00
|
|
|
/* Use this to determine if an error occurred (and therefore, if we should
|
|
|
|
* avoid cleaning the output tree) */
|
|
|
|
static bool cleanBuild;
|
|
|
|
|
2011-10-22 14:06:14 -07:00
|
|
|
/* Use this to prevent printing return keywords and newlines in lambdas. */
|
|
|
|
static bool inLambda = false;
|
|
|
|
|
2015-01-28 14:35:18 -05:00
|
|
|
/* Use this to keep track of whether we need to print out any docstring and
|
|
|
|
* the list of global variables that we are using (such as inside a function). */
|
|
|
|
static bool printDocstringAndGlobals = false;
|
2011-10-09 23:42:34 -07:00
|
|
|
|
2015-01-28 13:35:17 -05:00
|
|
|
/* Use this to keep track of whether we need to print a class or module docstring */
|
|
|
|
static bool printClassDocstring = true;
|
2011-10-09 23:42:34 -07:00
|
|
|
|
2009-07-26 10:07:13 +00:00
|
|
|
PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
|
|
|
|
{
|
|
|
|
PycBuffer source(code->code()->value(), code->code()->length());
|
|
|
|
|
|
|
|
FastStack stack((mod->majorVer() == 1) ? 20 : code->stackSize());
|
|
|
|
stackhist_t stack_hist;
|
|
|
|
|
2010-12-21 23:41:56 -08:00
|
|
|
std::stack<PycRef<ASTBlock> > blocks;
|
|
|
|
PycRef<ASTBlock> defblock = new ASTBlock(ASTBlock::BLK_MAIN);
|
2011-01-02 02:51:23 -08:00
|
|
|
defblock->init();
|
2015-08-16 14:34:54 +03:00
|
|
|
PycRef<ASTBlock> curblock = defblock;
|
2010-12-21 23:41:56 -08:00
|
|
|
blocks.push(defblock);
|
|
|
|
|
2009-07-26 10:07:13 +00:00
|
|
|
int opcode, operand;
|
2011-10-09 15:32:14 -07:00
|
|
|
int curpos = 0;
|
2009-07-26 10:07:13 +00:00
|
|
|
int pos = 0;
|
2011-01-08 16:19:38 -08:00
|
|
|
int unpack = 0;
|
2010-12-31 21:45:06 -08:00
|
|
|
bool else_pop = false;
|
2011-10-01 21:56:48 -07:00
|
|
|
bool need_try = false;
|
2009-07-26 10:07:13 +00:00
|
|
|
|
|
|
|
while (!source.atEof()) {
|
2011-10-09 01:47:20 -07:00
|
|
|
#if defined(BLOCK_DEBUG) || defined(STACK_DEBUG)
|
|
|
|
fprintf(stderr, "%-7d", pos);
|
|
|
|
#ifdef STACK_DEBUG
|
|
|
|
fprintf(stderr, "%-5d", (unsigned int)stack_hist.size() + 1);
|
|
|
|
#endif
|
|
|
|
#ifdef BLOCK_DEBUG
|
2011-10-02 10:40:05 -07:00
|
|
|
for (unsigned int i = 0; i < blocks.size(); i++)
|
|
|
|
fprintf(stderr, " ");
|
2011-10-10 19:09:31 -07:00
|
|
|
fprintf(stderr, "%s (%d)", curblock->type_str(), curblock->end());
|
2011-10-09 01:47:20 -07:00
|
|
|
#endif
|
|
|
|
fprintf(stderr, "\n");
|
2011-10-01 19:40:34 -07:00
|
|
|
#endif
|
|
|
|
|
2011-10-09 15:32:14 -07:00
|
|
|
curpos = pos;
|
2009-07-26 10:07:13 +00:00
|
|
|
bc_next(source, mod, opcode, operand, pos);
|
|
|
|
|
2011-10-01 21:56:48 -07:00
|
|
|
if (need_try && opcode != Pyc::SETUP_EXCEPT_A) {
|
|
|
|
need_try = false;
|
|
|
|
|
|
|
|
/* Store the current stack for the except/finally statement(s) */
|
|
|
|
stack_hist.push(stack);
|
2011-10-16 18:55:34 -07:00
|
|
|
PycRef<ASTBlock> tryblock = new ASTBlock(ASTBlock::BLK_TRY, curblock->end(), true);
|
2018-01-28 14:33:26 -08:00
|
|
|
blocks.push(tryblock);
|
2011-10-01 21:56:48 -07:00
|
|
|
curblock = blocks.top();
|
2011-10-02 18:57:42 -07:00
|
|
|
} else if (else_pop
|
|
|
|
&& opcode != Pyc::JUMP_FORWARD_A
|
2011-10-09 15:05:01 -07:00
|
|
|
&& opcode != Pyc::JUMP_IF_FALSE_A
|
|
|
|
&& opcode != Pyc::JUMP_IF_FALSE_OR_POP_A
|
|
|
|
&& opcode != Pyc::POP_JUMP_IF_FALSE_A
|
|
|
|
&& opcode != Pyc::JUMP_IF_TRUE_A
|
|
|
|
&& opcode != Pyc::JUMP_IF_TRUE_OR_POP_A
|
|
|
|
&& opcode != Pyc::POP_JUMP_IF_TRUE_A
|
2011-10-02 18:57:42 -07:00
|
|
|
&& opcode != Pyc::POP_BLOCK) {
|
2010-12-31 21:45:06 -08:00
|
|
|
else_pop = false;
|
|
|
|
|
|
|
|
PycRef<ASTBlock> prev = curblock;
|
2011-10-02 18:57:42 -07:00
|
|
|
while (prev->end() < pos
|
|
|
|
&& prev->blktype() != ASTBlock::BLK_MAIN) {
|
2011-10-09 01:47:20 -07:00
|
|
|
if (prev->blktype() != ASTBlock::BLK_CONTAINER) {
|
2011-10-10 19:09:31 -07:00
|
|
|
if (prev->end() == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-10-10 01:06:18 -07:00
|
|
|
/* We want to keep the stack the same, but we need to pop
|
|
|
|
* a level off the history. */
|
|
|
|
//stack = stack_hist.top();
|
2013-07-22 16:11:59 -04:00
|
|
|
if (!stack_hist.empty())
|
|
|
|
stack_hist.pop();
|
2011-10-09 01:47:20 -07:00
|
|
|
}
|
2011-01-05 13:05:01 -08:00
|
|
|
blocks.pop();
|
2013-07-22 22:23:45 -04:00
|
|
|
|
2013-07-22 16:11:59 -04:00
|
|
|
if (blocks.empty())
|
|
|
|
break;
|
|
|
|
|
2011-01-05 13:05:01 -08:00
|
|
|
curblock = blocks.top();
|
|
|
|
curblock->append(prev.cast<ASTNode>());
|
|
|
|
|
|
|
|
prev = curblock;
|
|
|
|
}
|
2010-12-31 21:45:06 -08:00
|
|
|
}
|
|
|
|
|
2009-07-26 10:07:13 +00:00
|
|
|
switch (opcode) {
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::BINARY_ADD:
|
2009-07-27 08:42:59 +00:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> left = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTBinary(left, right, ASTBinary::BIN_ADD));
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::BINARY_AND:
|
2009-07-26 10:07:13 +00:00
|
|
|
{
|
2009-07-27 00:23:49 +00:00
|
|
|
PycRef<ASTNode> right = stack.top();
|
2009-07-26 10:07:13 +00:00
|
|
|
stack.pop();
|
2009-07-27 00:23:49 +00:00
|
|
|
PycRef<ASTNode> left = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTBinary(left, right, ASTBinary::BIN_AND));
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::BINARY_DIVIDE:
|
2009-07-27 08:42:59 +00:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> left = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTBinary(left, right, ASTBinary::BIN_DIVIDE));
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::BINARY_FLOOR_DIVIDE:
|
2009-07-27 08:42:59 +00:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> left = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTBinary(left, right, ASTBinary::BIN_FLOOR));
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::BINARY_LSHIFT:
|
2009-07-27 08:42:59 +00:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> left = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTBinary(left, right, ASTBinary::BIN_LSHIFT));
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::BINARY_MODULO:
|
2009-07-27 08:42:59 +00:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> left = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTBinary(left, right, ASTBinary::BIN_MODULO));
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::BINARY_MULTIPLY:
|
2009-07-27 08:42:59 +00:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> left = stack.top();
|
|
|
|
stack.pop();
|
2010-09-07 21:32:34 -07:00
|
|
|
stack.push(new ASTBinary(left, right, ASTBinary::BIN_MULTIPLY));
|
2009-07-27 08:42:59 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::BINARY_OR:
|
2009-07-27 08:42:59 +00:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> left = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTBinary(left, right, ASTBinary::BIN_OR));
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::BINARY_POWER:
|
2009-07-27 08:42:59 +00:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> left = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTBinary(left, right, ASTBinary::BIN_POWER));
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::BINARY_RSHIFT:
|
2009-07-27 08:42:59 +00:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> left = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTBinary(left, right, ASTBinary::BIN_RSHIFT));
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::BINARY_SUBSCR:
|
2010-08-31 23:17:38 -07:00
|
|
|
{
|
2010-09-03 21:50:35 -07:00
|
|
|
PycRef<ASTNode> subscr = stack.top();
|
2010-08-31 23:17:38 -07:00
|
|
|
stack.pop();
|
2010-09-03 21:50:35 -07:00
|
|
|
PycRef<ASTNode> src = stack.top();
|
2010-08-31 23:17:38 -07:00
|
|
|
stack.pop();
|
2010-09-03 21:50:35 -07:00
|
|
|
stack.push(new ASTSubscr(src, subscr));
|
2010-08-31 23:17:38 -07:00
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::BINARY_SUBTRACT:
|
2009-07-27 08:42:59 +00:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> left = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTBinary(left, right, ASTBinary::BIN_SUBTRACT));
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::BINARY_TRUE_DIVIDE:
|
2009-07-27 08:42:59 +00:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> left = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTBinary(left, right, ASTBinary::BIN_DIVIDE));
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::BINARY_XOR:
|
2009-07-27 08:42:59 +00:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> left = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTBinary(left, right, ASTBinary::BIN_XOR));
|
|
|
|
}
|
|
|
|
break;
|
2015-10-01 17:01:02 -07:00
|
|
|
case Pyc::BINARY_MATRIX_MULTIPLY:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> left = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTBinary(left, right, ASTBinary::BIN_MAT_MULTIPLY));
|
|
|
|
}
|
2017-07-05 16:10:59 -07:00
|
|
|
break;
|
2011-01-01 02:31:31 -08:00
|
|
|
case Pyc::BREAK_LOOP:
|
2011-09-18 22:31:43 -07:00
|
|
|
curblock->append(new ASTKeyword(ASTKeyword::KW_BREAK));
|
2011-01-01 02:31:31 -08:00
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::BUILD_CLASS:
|
2009-07-27 03:00:55 +00:00
|
|
|
{
|
2019-10-04 16:16:10 -07:00
|
|
|
PycRef<ASTNode> class_code = stack.top();
|
2009-07-27 03:00:55 +00:00
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> bases = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> name = stack.top();
|
|
|
|
stack.pop();
|
2019-10-04 16:16:10 -07:00
|
|
|
stack.push(new ASTClass(class_code, bases, name));
|
2009-07-27 03:00:55 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::BUILD_FUNCTION:
|
2009-07-27 00:23:49 +00:00
|
|
|
{
|
2019-10-04 16:16:10 -07:00
|
|
|
PycRef<ASTNode> fun_code = stack.top();
|
2009-07-27 00:23:49 +00:00
|
|
|
stack.pop();
|
2019-10-08 11:36:12 -07:00
|
|
|
stack.push(new ASTFunction(fun_code, {}, {}));
|
2009-07-27 00:23:49 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::BUILD_LIST_A:
|
2009-07-27 08:42:59 +00:00
|
|
|
{
|
|
|
|
ASTList::value_t values;
|
|
|
|
for (int i=0; i<operand; i++) {
|
|
|
|
values.push_front(stack.top());
|
|
|
|
stack.pop();
|
|
|
|
}
|
|
|
|
stack.push(new ASTList(values));
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::BUILD_MAP_A:
|
2019-10-04 16:35:58 -07:00
|
|
|
if (mod->verCompare(3, 5) >= 0) {
|
2019-10-03 15:48:44 -07:00
|
|
|
auto map = new ASTMap;
|
|
|
|
for (int i=0; i<operand; ++i) {
|
|
|
|
PycRef<ASTNode> value = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> key = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
map->add(key, value);
|
|
|
|
}
|
|
|
|
stack.push(map);
|
|
|
|
} else {
|
|
|
|
stack.push(new ASTMap());
|
|
|
|
}
|
2009-07-27 08:42:59 +00:00
|
|
|
break;
|
2012-06-02 02:38:59 -07:00
|
|
|
case Pyc::STORE_MAP:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> key = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> value = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTMap> map = stack.top().cast<ASTMap>();
|
|
|
|
map->add(key, value);
|
|
|
|
}
|
|
|
|
break;
|
2011-01-06 10:56:10 -08:00
|
|
|
case Pyc::BUILD_SLICE_A:
|
|
|
|
{
|
|
|
|
if (operand == 2) {
|
|
|
|
PycRef<ASTNode> end = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> start = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
2017-07-05 16:36:04 -07:00
|
|
|
if (start.type() == ASTNode::NODE_OBJECT
|
2011-01-06 10:56:10 -08:00
|
|
|
&& start.cast<ASTObject>()->object() == Pyc_None) {
|
2017-07-05 16:36:04 -07:00
|
|
|
start = NULL;
|
2011-01-06 10:56:10 -08:00
|
|
|
}
|
|
|
|
|
2017-07-05 16:36:04 -07:00
|
|
|
if (end.type() == ASTNode::NODE_OBJECT
|
2011-01-06 10:56:10 -08:00
|
|
|
&& end.cast<ASTObject>()->object() == Pyc_None) {
|
2017-07-05 16:36:04 -07:00
|
|
|
end = NULL;
|
2011-01-06 10:56:10 -08:00
|
|
|
}
|
|
|
|
|
2017-07-05 16:36:04 -07:00
|
|
|
if (start == NULL && end == NULL) {
|
2011-01-06 10:56:10 -08:00
|
|
|
stack.push(new ASTSlice(ASTSlice::SLICE0));
|
2017-07-05 16:36:04 -07:00
|
|
|
} else if (start == NULL) {
|
2011-01-06 10:56:10 -08:00
|
|
|
stack.push(new ASTSlice(ASTSlice::SLICE2, start, end));
|
2017-07-05 16:36:04 -07:00
|
|
|
} else if (end == NULL) {
|
2011-01-06 10:56:10 -08:00
|
|
|
stack.push(new ASTSlice(ASTSlice::SLICE1, start, end));
|
|
|
|
} else {
|
|
|
|
stack.push(new ASTSlice(ASTSlice::SLICE3, start, end));
|
|
|
|
}
|
|
|
|
} else if (operand == 3) {
|
|
|
|
PycRef<ASTNode> step = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> end = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> start = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
2017-07-05 16:36:04 -07:00
|
|
|
if (start.type() == ASTNode::NODE_OBJECT
|
2011-01-06 10:56:10 -08:00
|
|
|
&& start.cast<ASTObject>()->object() == Pyc_None) {
|
2017-07-05 16:36:04 -07:00
|
|
|
start = NULL;
|
2011-01-06 10:56:10 -08:00
|
|
|
}
|
|
|
|
|
2017-07-05 16:36:04 -07:00
|
|
|
if (end.type() == ASTNode::NODE_OBJECT
|
2011-01-06 10:56:10 -08:00
|
|
|
&& end.cast<ASTObject>()->object() == Pyc_None) {
|
2017-07-05 16:36:04 -07:00
|
|
|
end = NULL;
|
2011-01-06 10:56:10 -08:00
|
|
|
}
|
|
|
|
|
2017-07-05 16:36:04 -07:00
|
|
|
if (step.type() == ASTNode::NODE_OBJECT
|
2011-01-06 10:56:10 -08:00
|
|
|
&& step.cast<ASTObject>()->object() == Pyc_None) {
|
2017-07-05 16:36:04 -07:00
|
|
|
step = NULL;
|
2011-01-06 10:56:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We have to do this as a slice where one side is another slice */
|
|
|
|
/* [[a:b]:c] */
|
|
|
|
|
2017-07-05 16:36:04 -07:00
|
|
|
if (start == NULL && end == NULL) {
|
2011-01-06 10:56:10 -08:00
|
|
|
stack.push(new ASTSlice(ASTSlice::SLICE0));
|
2017-07-05 16:36:04 -07:00
|
|
|
} else if (start == NULL) {
|
2011-01-06 10:56:10 -08:00
|
|
|
stack.push(new ASTSlice(ASTSlice::SLICE2, start, end));
|
2017-07-05 16:36:04 -07:00
|
|
|
} else if (end == NULL) {
|
2011-01-06 10:56:10 -08:00
|
|
|
stack.push(new ASTSlice(ASTSlice::SLICE1, start, end));
|
|
|
|
} else {
|
|
|
|
stack.push(new ASTSlice(ASTSlice::SLICE3, start, end));
|
|
|
|
}
|
|
|
|
|
|
|
|
PycRef<ASTNode> lhs = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
2017-07-05 16:36:04 -07:00
|
|
|
if (step == NULL) {
|
2011-01-06 10:56:10 -08:00
|
|
|
stack.push(new ASTSlice(ASTSlice::SLICE1, lhs, step));
|
|
|
|
} else {
|
|
|
|
stack.push(new ASTSlice(ASTSlice::SLICE3, lhs, step));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::BUILD_TUPLE_A:
|
2009-07-27 03:00:55 +00:00
|
|
|
{
|
2009-07-27 08:42:59 +00:00
|
|
|
ASTTuple::value_t values;
|
|
|
|
values.resize(operand);
|
2009-07-27 03:00:55 +00:00
|
|
|
for (int i=0; i<operand; i++) {
|
2009-07-27 08:42:59 +00:00
|
|
|
values[operand-i-1] = stack.top();
|
2009-07-27 03:00:55 +00:00
|
|
|
stack.pop();
|
|
|
|
}
|
2009-07-27 08:42:59 +00:00
|
|
|
stack.push(new ASTTuple(values));
|
2009-07-27 03:00:55 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::CALL_FUNCTION_A:
|
2009-07-27 00:23:49 +00:00
|
|
|
{
|
|
|
|
int kwparams = (operand & 0xFF00) >> 8;
|
|
|
|
int pparams = (operand & 0xFF);
|
|
|
|
ASTCall::kwparam_t kwparamList;
|
|
|
|
ASTCall::pparam_t pparamList;
|
2015-04-20 17:38:36 -04:00
|
|
|
|
|
|
|
/* Test for the load build class function */
|
|
|
|
stack_hist.push(stack);
|
|
|
|
int basecnt = 0;
|
|
|
|
ASTTuple::value_t bases;
|
|
|
|
bases.resize(basecnt);
|
|
|
|
PycRef<ASTNode> TOS = stack.top();
|
2017-07-05 16:36:04 -07:00
|
|
|
int TOS_type = TOS.type();
|
2015-04-20 17:38:36 -04:00
|
|
|
// bases are NODE_NAME at TOS
|
|
|
|
while (TOS_type == ASTNode::NODE_NAME) {
|
|
|
|
bases.resize(basecnt + 1);
|
|
|
|
bases[basecnt] = TOS;
|
|
|
|
basecnt++;
|
|
|
|
stack.pop();
|
|
|
|
TOS = stack.top();
|
2017-07-05 16:36:04 -07:00
|
|
|
TOS_type = TOS.type();
|
2015-04-20 17:38:36 -04:00
|
|
|
}
|
|
|
|
// qualified name is PycString at TOS
|
|
|
|
PycRef<ASTNode> name = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> function = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> loadbuild = stack.top();
|
|
|
|
stack.pop();
|
2017-07-05 16:36:04 -07:00
|
|
|
int loadbuild_type = loadbuild.type();
|
2015-04-20 17:38:36 -04:00
|
|
|
if (loadbuild_type == ASTNode::NODE_LOADBUILDCLASS) {
|
|
|
|
PycRef<ASTNode> call = new ASTCall(function, pparamList, kwparamList);
|
|
|
|
stack.push(new ASTClass(call, new ASTTuple(bases), name));
|
|
|
|
stack_hist.pop();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stack = stack_hist.top();
|
|
|
|
stack_hist.pop();
|
|
|
|
}
|
|
|
|
|
2009-07-27 00:23:49 +00:00
|
|
|
for (int i=0; i<kwparams; i++) {
|
|
|
|
PycRef<ASTNode> val = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> key = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
kwparamList.push_front(std::make_pair(key, val));
|
|
|
|
}
|
|
|
|
for (int i=0; i<pparams; i++) {
|
2012-06-10 00:26:28 -07:00
|
|
|
PycRef<ASTNode> param = stack.top();
|
2009-07-27 00:23:49 +00:00
|
|
|
stack.pop();
|
2017-07-05 16:36:04 -07:00
|
|
|
if (param.type() == ASTNode::NODE_FUNCTION) {
|
2019-10-04 16:16:10 -07:00
|
|
|
PycRef<ASTNode> fun_code = param.cast<ASTFunction>()->code();
|
|
|
|
PycRef<PycCode> code_src = fun_code.cast<ASTObject>()->object().cast<PycCode>();
|
2012-06-10 00:26:28 -07:00
|
|
|
PycRef<PycString> function_name = code_src->name();
|
|
|
|
if (function_name->isEqual("<lambda>")) {
|
|
|
|
pparamList.push_front(param);
|
|
|
|
} else {
|
|
|
|
// Decorator used
|
2019-10-04 16:16:10 -07:00
|
|
|
PycRef<ASTNode> decor_name = new ASTName(function_name);
|
|
|
|
curblock->append(new ASTStore(param, decor_name));
|
2012-06-10 00:26:28 -07:00
|
|
|
|
2019-10-04 16:16:10 -07:00
|
|
|
pparamList.push_front(decor_name);
|
2012-06-10 00:26:28 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pparamList.push_front(param);
|
|
|
|
}
|
2009-07-27 00:23:49 +00:00
|
|
|
}
|
|
|
|
PycRef<ASTNode> func = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTCall(func, pparamList, kwparamList));
|
|
|
|
}
|
|
|
|
break;
|
2011-10-09 22:38:18 -07:00
|
|
|
case Pyc::CALL_FUNCTION_VAR_A:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> var = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
int kwparams = (operand & 0xFF00) >> 8;
|
|
|
|
int pparams = (operand & 0xFF);
|
|
|
|
ASTCall::kwparam_t kwparamList;
|
|
|
|
ASTCall::pparam_t pparamList;
|
|
|
|
for (int i=0; i<kwparams; i++) {
|
|
|
|
PycRef<ASTNode> val = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> key = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
kwparamList.push_front(std::make_pair(key, val));
|
|
|
|
}
|
|
|
|
for (int i=0; i<pparams; i++) {
|
|
|
|
pparamList.push_front(stack.top());
|
|
|
|
stack.pop();
|
|
|
|
}
|
|
|
|
PycRef<ASTNode> func = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
|
|
|
PycRef<ASTNode> call = new ASTCall(func, pparamList, kwparamList);
|
|
|
|
call.cast<ASTCall>()->setVar(var);
|
|
|
|
stack.push(call);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Pyc::CALL_FUNCTION_KW_A:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> kw = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
int kwparams = (operand & 0xFF00) >> 8;
|
|
|
|
int pparams = (operand & 0xFF);
|
|
|
|
ASTCall::kwparam_t kwparamList;
|
|
|
|
ASTCall::pparam_t pparamList;
|
|
|
|
for (int i=0; i<kwparams; i++) {
|
|
|
|
PycRef<ASTNode> val = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> key = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
kwparamList.push_front(std::make_pair(key, val));
|
|
|
|
}
|
|
|
|
for (int i=0; i<pparams; i++) {
|
|
|
|
pparamList.push_front(stack.top());
|
|
|
|
stack.pop();
|
|
|
|
}
|
|
|
|
PycRef<ASTNode> func = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
|
|
|
PycRef<ASTNode> call = new ASTCall(func, pparamList, kwparamList);
|
|
|
|
call.cast<ASTCall>()->setKW(kw);
|
|
|
|
stack.push(call);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Pyc::CALL_FUNCTION_VAR_KW_A:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> kw = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> var = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
int kwparams = (operand & 0xFF00) >> 8;
|
|
|
|
int pparams = (operand & 0xFF);
|
|
|
|
ASTCall::kwparam_t kwparamList;
|
|
|
|
ASTCall::pparam_t pparamList;
|
|
|
|
for (int i=0; i<kwparams; i++) {
|
|
|
|
PycRef<ASTNode> val = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> key = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
kwparamList.push_front(std::make_pair(key, val));
|
|
|
|
}
|
|
|
|
for (int i=0; i<pparams; i++) {
|
|
|
|
pparamList.push_front(stack.top());
|
|
|
|
stack.pop();
|
|
|
|
}
|
|
|
|
PycRef<ASTNode> func = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
|
|
|
PycRef<ASTNode> call = new ASTCall(func, pparamList, kwparamList);
|
|
|
|
call.cast<ASTCall>()->setKW(kw);
|
|
|
|
call.cast<ASTCall>()->setVar(var);
|
|
|
|
stack.push(call);
|
|
|
|
}
|
|
|
|
break;
|
2011-01-01 02:31:31 -08:00
|
|
|
case Pyc::CONTINUE_LOOP_A:
|
2011-09-18 22:31:43 -07:00
|
|
|
curblock->append(new ASTKeyword(ASTKeyword::KW_CONTINUE));
|
2011-01-01 02:31:31 -08:00
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::COMPARE_OP_A:
|
2009-07-27 00:23:49 +00:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> left = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTCompare(left, right, operand));
|
2009-07-26 10:07:13 +00:00
|
|
|
}
|
|
|
|
break;
|
2011-01-05 13:05:01 -08:00
|
|
|
case Pyc::DELETE_ATTR_A:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> name = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
curblock->append(new ASTDelete(new ASTBinary(name, new ASTName(code->getName(operand)), ASTBinary::BIN_ATTR)));
|
|
|
|
}
|
|
|
|
break;
|
2011-01-05 10:52:57 -08:00
|
|
|
case Pyc::DELETE_GLOBAL_A:
|
2011-10-25 21:40:05 -07:00
|
|
|
code->markGlobal(code->getName(operand));
|
|
|
|
/* Fall through */
|
2011-01-05 10:52:57 -08:00
|
|
|
case Pyc::DELETE_NAME_A:
|
|
|
|
{
|
2011-10-10 15:57:20 -07:00
|
|
|
PycRef<PycString> varname = code->getName(operand);
|
|
|
|
|
2018-01-28 14:33:26 -08:00
|
|
|
if (varname->length() >= 2 && varname->value()[0] == '_'
|
|
|
|
&& varname->value()[1] == '[') {
|
2011-10-10 15:57:20 -07:00
|
|
|
/* Don't show deletes that are a result of list comps. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
PycRef<ASTNode> name = new ASTName(varname);
|
2011-01-05 10:52:57 -08:00
|
|
|
curblock->append(new ASTDelete(name));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Pyc::DELETE_FAST_A:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> name;
|
|
|
|
|
2012-05-26 14:03:10 -07:00
|
|
|
if (mod->verCompare(1, 3) < 0)
|
2011-01-05 10:52:57 -08:00
|
|
|
name = new ASTName(code->getName(operand));
|
|
|
|
else
|
|
|
|
name = new ASTName(code->getVarName(operand));
|
|
|
|
|
2011-10-16 18:17:48 -07:00
|
|
|
if (name.cast<ASTName>()->name()->value()[0] == '_'
|
|
|
|
&& name.cast<ASTName>()->name()->value()[1] == '[') {
|
|
|
|
/* Don't show deletes that are a result of list comps. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-01-05 10:52:57 -08:00
|
|
|
curblock->append(new ASTDelete(name));
|
|
|
|
}
|
|
|
|
break;
|
2011-01-06 10:56:10 -08:00
|
|
|
case Pyc::DELETE_SLICE_0:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> name = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
|
|
|
curblock->append(new ASTDelete(new ASTSubscr(name, new ASTSlice(ASTSlice::SLICE0))));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Pyc::DELETE_SLICE_1:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> upper = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> name = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
|
|
|
curblock->append(new ASTDelete(new ASTSubscr(name, new ASTSlice(ASTSlice::SLICE1, upper))));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Pyc::DELETE_SLICE_2:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> lower = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> name = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
2017-07-05 16:36:04 -07:00
|
|
|
curblock->append(new ASTDelete(new ASTSubscr(name, new ASTSlice(ASTSlice::SLICE2, NULL, lower))));
|
2011-01-06 10:56:10 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Pyc::DELETE_SLICE_3:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> lower = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> upper = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> name = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
|
|
|
curblock->append(new ASTDelete(new ASTSubscr(name, new ASTSlice(ASTSlice::SLICE3, upper, lower))));
|
|
|
|
}
|
|
|
|
break;
|
2011-01-05 22:14:24 -08:00
|
|
|
case Pyc::DELETE_SUBSCR:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> key = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> name = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
|
|
|
curblock->append(new ASTDelete(new ASTSubscr(name, key)));
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::DUP_TOP:
|
2009-07-27 08:42:59 +00:00
|
|
|
stack.push(stack.top());
|
|
|
|
break;
|
2011-09-19 22:31:58 -07:00
|
|
|
case Pyc::DUP_TOP_TWO:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> first = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> second = stack.top();
|
|
|
|
|
|
|
|
stack.push(first);
|
|
|
|
stack.push(second);
|
|
|
|
stack.push(first);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Pyc::DUP_TOPX_A:
|
|
|
|
{
|
|
|
|
std::stack<PycRef<ASTNode> > first;
|
|
|
|
std::stack<PycRef<ASTNode> > second;
|
|
|
|
|
|
|
|
for (int i = 0; i < operand; i++) {
|
|
|
|
PycRef<ASTNode> node = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
first.push(node);
|
|
|
|
second.push(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (first.size()) {
|
|
|
|
stack.push(first.top());
|
|
|
|
first.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
while (second.size()) {
|
|
|
|
stack.push(second.top());
|
|
|
|
second.pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2010-12-21 23:41:56 -08:00
|
|
|
case Pyc::END_FINALLY:
|
|
|
|
{
|
2011-10-01 19:40:34 -07:00
|
|
|
bool isFinally = false;
|
|
|
|
if (curblock->blktype() == ASTBlock::BLK_FINALLY) {
|
|
|
|
PycRef<ASTBlock> final = curblock;
|
|
|
|
blocks.pop();
|
|
|
|
|
2011-10-09 01:47:20 -07:00
|
|
|
stack = stack_hist.top();
|
|
|
|
stack_hist.pop();
|
|
|
|
|
2011-10-01 19:40:34 -07:00
|
|
|
curblock = blocks.top();
|
|
|
|
curblock->append(final.cast<ASTNode>());
|
|
|
|
isFinally = true;
|
2011-10-02 18:57:42 -07:00
|
|
|
} else if (curblock->blktype() == ASTBlock::BLK_EXCEPT) {
|
|
|
|
/* Turn it into an else statement. */
|
|
|
|
blocks.pop();
|
2011-10-10 21:51:29 -07:00
|
|
|
PycRef<ASTBlock> prev = curblock;
|
2011-10-10 21:22:02 -07:00
|
|
|
if (curblock->size() != 0) {
|
|
|
|
blocks.top()->append(curblock.cast<ASTNode>());
|
|
|
|
}
|
2011-10-01 19:40:34 -07:00
|
|
|
curblock = blocks.top();
|
2011-10-10 21:51:29 -07:00
|
|
|
|
|
|
|
if (curblock->end() != pos || curblock.cast<ASTContainerBlock>()->hasFinally()) {
|
|
|
|
PycRef<ASTBlock> elseblk = new ASTBlock(ASTBlock::BLK_ELSE, prev->end());
|
|
|
|
elseblk->init();
|
|
|
|
blocks.push(elseblk);
|
|
|
|
curblock = blocks.top();
|
|
|
|
} else {
|
|
|
|
stack = stack_hist.top();
|
|
|
|
stack_hist.pop();
|
|
|
|
}
|
2011-10-01 19:40:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (curblock->blktype() == ASTBlock::BLK_CONTAINER) {
|
|
|
|
/* This marks the end of the except block(s). */
|
|
|
|
PycRef<ASTContainerBlock> cont = curblock.cast<ASTContainerBlock>();
|
|
|
|
if (!cont->hasFinally() || isFinally) {
|
|
|
|
/* If there's no finally block, pop the container. */
|
|
|
|
blocks.pop();
|
|
|
|
curblock = blocks.top();
|
|
|
|
curblock->append(cont.cast<ASTNode>());
|
|
|
|
}
|
|
|
|
}
|
2010-12-21 23:41:56 -08:00
|
|
|
}
|
|
|
|
break;
|
2011-01-10 13:15:56 -08:00
|
|
|
case Pyc::EXEC_STMT:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> loc = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> glob = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> stmt = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
|
|
|
curblock->append(new ASTExec(stmt, glob, loc));
|
|
|
|
}
|
|
|
|
break;
|
2011-01-04 14:39:19 -08:00
|
|
|
case Pyc::FOR_ITER_A:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> iter = stack.top(); // Iterable
|
2011-10-10 15:57:20 -07:00
|
|
|
stack.pop();
|
2011-01-04 14:39:19 -08:00
|
|
|
/* Pop it? Don't pop it? */
|
|
|
|
|
2011-10-10 15:57:20 -07:00
|
|
|
bool comprehension = false;
|
2011-01-04 14:39:19 -08:00
|
|
|
PycRef<ASTBlock> top = blocks.top();
|
2011-10-10 15:57:20 -07:00
|
|
|
if (top->blktype() == ASTBlock::BLK_WHILE) {
|
|
|
|
blocks.pop();
|
|
|
|
} else {
|
|
|
|
comprehension = true;
|
|
|
|
}
|
2011-10-16 18:17:48 -07:00
|
|
|
PycRef<ASTIterBlock> forblk = new ASTIterBlock(ASTBlock::BLK_FOR, top->end(), iter);
|
2011-10-10 15:57:20 -07:00
|
|
|
forblk->setComprehension(comprehension);
|
2011-01-04 14:39:19 -08:00
|
|
|
blocks.push(forblk.cast<ASTBlock>());
|
|
|
|
curblock = blocks.top();
|
|
|
|
|
2017-07-05 16:36:04 -07:00
|
|
|
stack.push(NULL);
|
2011-01-04 14:39:19 -08:00
|
|
|
}
|
|
|
|
break;
|
2011-01-01 02:31:31 -08:00
|
|
|
case Pyc::FOR_LOOP_A:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> curidx = stack.top(); // Current index
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> iter = stack.top(); // Iterable
|
|
|
|
stack.pop();
|
|
|
|
|
2011-10-16 18:17:48 -07:00
|
|
|
bool comprehension = false;
|
2011-01-01 02:31:31 -08:00
|
|
|
PycRef<ASTBlock> top = blocks.top();
|
2011-10-16 18:17:48 -07:00
|
|
|
if (top->blktype() == ASTBlock::BLK_WHILE) {
|
|
|
|
blocks.pop();
|
|
|
|
} else {
|
|
|
|
comprehension = true;
|
|
|
|
}
|
|
|
|
PycRef<ASTIterBlock> forblk = new ASTIterBlock(ASTBlock::BLK_FOR, top->end(), iter);
|
|
|
|
forblk->setComprehension(comprehension);
|
2011-01-01 02:31:31 -08:00
|
|
|
blocks.push(forblk.cast<ASTBlock>());
|
|
|
|
curblock = blocks.top();
|
|
|
|
|
|
|
|
/* Python Docs say:
|
|
|
|
"push the sequence, the incremented counter,
|
|
|
|
and the current item onto the stack." */
|
|
|
|
stack.push(iter);
|
|
|
|
stack.push(curidx);
|
2017-07-05 16:36:04 -07:00
|
|
|
stack.push(NULL); // We can totally hack this >_>
|
2011-01-01 02:31:31 -08:00
|
|
|
}
|
|
|
|
break;
|
2011-01-04 14:39:19 -08:00
|
|
|
case Pyc::GET_ITER:
|
|
|
|
/* We just entirely ignore this */
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::IMPORT_NAME_A:
|
|
|
|
if (mod->majorVer() == 1) {
|
2017-07-05 16:36:04 -07:00
|
|
|
stack.push(new ASTImport(new ASTName(code->getName(operand)), NULL));
|
2010-09-04 01:20:41 -07:00
|
|
|
} else {
|
2009-07-27 03:00:55 +00:00
|
|
|
PycRef<ASTNode> fromlist = stack.top();
|
|
|
|
stack.pop();
|
2012-05-26 14:03:10 -07:00
|
|
|
if (mod->verCompare(2, 5) >= 0)
|
2009-07-27 03:00:55 +00:00
|
|
|
stack.pop(); // Level -- we don't care
|
|
|
|
stack.push(new ASTImport(new ASTName(code->getName(operand)), fromlist));
|
|
|
|
}
|
|
|
|
break;
|
2010-12-18 22:18:32 -08:00
|
|
|
case Pyc::IMPORT_FROM_A:
|
2011-09-20 22:36:15 -07:00
|
|
|
stack.push(new ASTName(code->getName(operand)));
|
2010-12-18 22:18:32 -08:00
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::IMPORT_STAR:
|
2009-07-27 03:23:56 +00:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> import = stack.top();
|
|
|
|
stack.pop();
|
2017-07-05 16:36:04 -07:00
|
|
|
curblock->append(new ASTStore(import, NULL));
|
2009-07-27 03:23:56 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::INPLACE_ADD:
|
2010-08-31 23:17:38 -07:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> src = stack.top();
|
|
|
|
stack.pop();
|
2011-09-18 11:59:02 -07:00
|
|
|
stack.push(new ASTBinary(src, right, ASTBinary::BIN_IP_ADD));
|
2010-08-31 23:17:38 -07:00
|
|
|
}
|
|
|
|
break;
|
2011-09-18 21:01:43 -07:00
|
|
|
case Pyc::INPLACE_AND:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> left = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTBinary(left, right, ASTBinary::BIN_IP_AND));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Pyc::INPLACE_DIVIDE:
|
2010-08-31 23:17:38 -07:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> src = stack.top();
|
|
|
|
stack.pop();
|
2011-09-18 21:01:43 -07:00
|
|
|
stack.push(new ASTBinary(src, right, ASTBinary::BIN_IP_DIVIDE));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Pyc::INPLACE_FLOOR_DIVIDE:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> left = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTBinary(left, right, ASTBinary::BIN_IP_FLOOR));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Pyc::INPLACE_LSHIFT:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> left = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTBinary(left, right, ASTBinary::BIN_IP_LSHIFT));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Pyc::INPLACE_MODULO:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> left = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTBinary(left, right, ASTBinary::BIN_IP_MODULO));
|
2011-09-18 11:59:02 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Pyc::INPLACE_MULTIPLY:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> src = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTBinary(src, right, ASTBinary::BIN_IP_MULTIPLY));
|
|
|
|
}
|
|
|
|
break;
|
2011-09-18 21:01:43 -07:00
|
|
|
case Pyc::INPLACE_OR:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> left = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTBinary(left, right, ASTBinary::BIN_IP_OR));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Pyc::INPLACE_POWER:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> left = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTBinary(left, right, ASTBinary::BIN_IP_POWER));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Pyc::INPLACE_RSHIFT:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> left = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTBinary(left, right, ASTBinary::BIN_IP_RSHIFT));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Pyc::INPLACE_SUBTRACT:
|
2011-09-18 11:59:02 -07:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> src = stack.top();
|
|
|
|
stack.pop();
|
2011-09-18 21:01:43 -07:00
|
|
|
stack.push(new ASTBinary(src, right, ASTBinary::BIN_IP_SUBTRACT));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Pyc::INPLACE_TRUE_DIVIDE:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> left = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTBinary(left, right, ASTBinary::BIN_IP_DIVIDE));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Pyc::INPLACE_XOR:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> left = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTBinary(left, right, ASTBinary::BIN_IP_XOR));
|
2010-08-31 23:17:38 -07:00
|
|
|
}
|
|
|
|
break;
|
2015-10-01 17:01:02 -07:00
|
|
|
case Pyc::INPLACE_MATRIX_MULTIPLY:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> right = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> left = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTBinary(left, right, ASTBinary::BIN_IP_MAT_MULTIPLY));
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::JUMP_IF_FALSE_A:
|
2010-12-31 22:40:13 -08:00
|
|
|
case Pyc::JUMP_IF_TRUE_A:
|
|
|
|
case Pyc::JUMP_IF_FALSE_OR_POP_A:
|
|
|
|
case Pyc::JUMP_IF_TRUE_OR_POP_A:
|
|
|
|
case Pyc::POP_JUMP_IF_FALSE_A:
|
|
|
|
case Pyc::POP_JUMP_IF_TRUE_A:
|
2010-08-31 23:20:40 -07:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> cond = stack.top();
|
2011-01-01 02:31:31 -08:00
|
|
|
PycRef<ASTCondBlock> ifblk;
|
2011-01-02 02:51:23 -08:00
|
|
|
int popped = ASTCondBlock::UNINITED;
|
2010-12-24 20:25:55 -08:00
|
|
|
|
2010-12-31 22:40:13 -08:00
|
|
|
if (opcode == Pyc::POP_JUMP_IF_FALSE_A
|
|
|
|
|| opcode == Pyc::POP_JUMP_IF_TRUE_A) {
|
|
|
|
/* Pop condition before the jump */
|
|
|
|
stack.pop();
|
2011-01-02 02:51:23 -08:00
|
|
|
popped = ASTCondBlock::PRE_POPPED;
|
2010-12-24 20:25:55 -08:00
|
|
|
}
|
2011-10-09 01:47:20 -07:00
|
|
|
|
2010-12-31 22:40:13 -08:00
|
|
|
/* Store the current stack for the else statement(s) */
|
2010-12-24 20:25:55 -08:00
|
|
|
stack_hist.push(stack);
|
2011-10-09 01:47:20 -07:00
|
|
|
|
2010-12-31 22:40:13 -08:00
|
|
|
if (opcode == Pyc::JUMP_IF_FALSE_OR_POP_A
|
|
|
|
|| opcode == Pyc::JUMP_IF_TRUE_OR_POP_A) {
|
|
|
|
/* Pop condition only if condition is met */
|
|
|
|
stack.pop();
|
2011-01-02 02:51:23 -08:00
|
|
|
popped = ASTCondBlock::POPPED;
|
2010-12-31 22:40:13 -08:00
|
|
|
}
|
2010-12-24 20:25:55 -08:00
|
|
|
|
2010-12-31 22:40:13 -08:00
|
|
|
/* "Jump if true" means "Jump if not false" */
|
|
|
|
bool neg = opcode == Pyc::JUMP_IF_TRUE_A
|
|
|
|
|| opcode == Pyc::JUMP_IF_TRUE_OR_POP_A
|
|
|
|
|| opcode == Pyc::POP_JUMP_IF_TRUE_A;
|
|
|
|
|
|
|
|
int offs = operand;
|
|
|
|
if (opcode == Pyc::JUMP_IF_FALSE_A
|
|
|
|
|| opcode == Pyc::JUMP_IF_TRUE_A) {
|
|
|
|
/* Offset is relative in these cases */
|
|
|
|
offs = pos + operand;
|
|
|
|
}
|
2010-12-24 20:25:55 -08:00
|
|
|
|
2017-07-05 16:36:04 -07:00
|
|
|
if (cond.type() == ASTNode::NODE_COMPARE
|
2011-10-10 19:09:31 -07:00
|
|
|
&& cond.cast<ASTCompare>()->op() == ASTCompare::CMP_EXCEPTION) {
|
2011-10-09 01:47:20 -07:00
|
|
|
if (curblock->blktype() == ASTBlock::BLK_EXCEPT
|
2017-07-05 16:36:04 -07:00
|
|
|
&& curblock.cast<ASTCondBlock>()->cond() == NULL) {
|
2011-10-01 21:05:33 -07:00
|
|
|
blocks.pop();
|
|
|
|
curblock = blocks.top();
|
|
|
|
|
|
|
|
stack_hist.pop();
|
|
|
|
}
|
2011-01-04 13:52:15 -08:00
|
|
|
ifblk = new ASTCondBlock(ASTBlock::BLK_EXCEPT, offs, cond.cast<ASTCompare>()->right(), false);
|
2011-09-18 23:55:27 -07:00
|
|
|
} else if (curblock->blktype() == ASTBlock::BLK_ELSE
|
|
|
|
&& curblock->size() == 0) {
|
2010-12-31 22:40:13 -08:00
|
|
|
/* Collapse into elif statement */
|
2010-12-24 20:25:55 -08:00
|
|
|
blocks.pop();
|
2011-10-09 01:47:20 -07:00
|
|
|
stack = stack_hist.top();
|
|
|
|
stack_hist.pop();
|
2010-12-31 22:40:13 -08:00
|
|
|
ifblk = new ASTCondBlock(ASTBlock::BLK_ELIF, offs, cond, neg);
|
2011-09-18 23:55:27 -07:00
|
|
|
} else if (curblock->size() == 0 && !curblock->inited()
|
|
|
|
&& curblock->blktype() == ASTBlock::BLK_WHILE) {
|
2011-01-04 15:25:25 -08:00
|
|
|
/* The condition for a while loop */
|
2010-12-31 02:42:58 -08:00
|
|
|
PycRef<ASTBlock> top = blocks.top();
|
|
|
|
blocks.pop();
|
2010-12-31 22:40:13 -08:00
|
|
|
ifblk = new ASTCondBlock(top->blktype(), offs, cond, neg);
|
2011-01-04 15:25:25 -08:00
|
|
|
|
|
|
|
/* We don't store the stack for loops! Pop it! */
|
|
|
|
stack_hist.pop();
|
2011-09-18 23:55:27 -07:00
|
|
|
} else if (curblock->size() == 0 && curblock->end() <= offs
|
|
|
|
&& (curblock->blktype() == ASTBlock::BLK_IF
|
2011-10-09 21:42:18 -07:00
|
|
|
|| curblock->blktype() == ASTBlock::BLK_ELIF
|
|
|
|
|| curblock->blktype() == ASTBlock::BLK_WHILE)) {
|
2011-01-02 04:24:32 -08:00
|
|
|
PycRef<ASTNode> newcond;
|
2011-01-02 02:51:23 -08:00
|
|
|
PycRef<ASTCondBlock> top = curblock.cast<ASTCondBlock>();
|
|
|
|
PycRef<ASTNode> cond1 = top->cond();
|
|
|
|
blocks.pop();
|
|
|
|
|
2011-10-10 19:09:31 -07:00
|
|
|
if (curblock->blktype() == ASTBlock::BLK_WHILE) {
|
|
|
|
stack_hist.pop();
|
|
|
|
} else {
|
|
|
|
FastStack s_top = stack_hist.top();
|
|
|
|
stack_hist.pop();
|
|
|
|
stack_hist.pop();
|
|
|
|
stack_hist.push(s_top);
|
|
|
|
}
|
2011-01-02 02:51:23 -08:00
|
|
|
|
2011-10-09 15:32:14 -07:00
|
|
|
if (curblock->end() == offs
|
|
|
|
|| (curblock->end() == curpos && !top->negative())) {
|
2011-01-02 04:24:32 -08:00
|
|
|
/* if blah and blah */
|
|
|
|
newcond = new ASTBinary(cond1, cond, ASTBinary::BIN_LOG_AND);
|
|
|
|
} else {
|
|
|
|
/* if blah or blah */
|
|
|
|
newcond = new ASTBinary(cond1, cond, ASTBinary::BIN_LOG_OR);
|
|
|
|
}
|
|
|
|
ifblk = new ASTCondBlock(top->blktype(), offs, newcond, neg);
|
2019-10-04 16:35:58 -07:00
|
|
|
} else if (curblock->blktype() == ASTBlock::BLK_FOR
|
|
|
|
&& curblock.cast<ASTIterBlock>()->isComprehension()
|
|
|
|
&& mod->verCompare(2, 7) >= 0) {
|
|
|
|
/* Comprehension condition */
|
|
|
|
curblock.cast<ASTIterBlock>()->setCondition(cond);
|
|
|
|
stack_hist.pop();
|
|
|
|
// TODO: Handle older python versions, where condition
|
|
|
|
// is laid out a little differently.
|
|
|
|
break;
|
2010-12-24 20:25:55 -08:00
|
|
|
} else {
|
2010-12-31 22:40:13 -08:00
|
|
|
/* Plain old if statement */
|
|
|
|
ifblk = new ASTCondBlock(ASTBlock::BLK_IF, offs, cond, neg);
|
2010-12-24 20:25:55 -08:00
|
|
|
}
|
2011-01-01 02:31:31 -08:00
|
|
|
|
|
|
|
if (popped)
|
2011-01-02 02:51:23 -08:00
|
|
|
ifblk->init(popped);
|
2011-01-01 02:31:31 -08:00
|
|
|
|
2010-12-24 20:25:55 -08:00
|
|
|
blocks.push(ifblk.cast<ASTBlock>());
|
|
|
|
curblock = blocks.top();
|
2010-08-31 23:20:40 -07:00
|
|
|
}
|
|
|
|
break;
|
2010-12-31 02:42:58 -08:00
|
|
|
case Pyc::JUMP_ABSOLUTE_A:
|
|
|
|
{
|
2011-01-04 15:25:25 -08:00
|
|
|
if (operand < pos) {
|
2011-10-16 18:17:48 -07:00
|
|
|
if (curblock->blktype() == ASTBlock::BLK_FOR
|
|
|
|
&& curblock.cast<ASTIterBlock>()->isComprehension()) {
|
2011-10-10 15:57:20 -07:00
|
|
|
PycRef<ASTNode> top = stack.top();
|
|
|
|
|
2017-07-05 16:36:04 -07:00
|
|
|
if (top.type() == ASTNode::NODE_COMPREHENSION) {
|
2011-10-10 15:57:20 -07:00
|
|
|
PycRef<ASTComprehension> comp = top.cast<ASTComprehension>();
|
|
|
|
|
|
|
|
comp->addGenerator(curblock.cast<ASTIterBlock>());
|
|
|
|
}
|
|
|
|
|
|
|
|
blocks.pop();
|
|
|
|
curblock = blocks.top();
|
2019-10-04 16:35:58 -07:00
|
|
|
} else if (curblock->blktype() == ASTBlock::BLK_ELSE) {
|
2011-10-22 22:47:09 -07:00
|
|
|
stack = stack_hist.top();
|
|
|
|
stack_hist.pop();
|
|
|
|
|
|
|
|
blocks.pop();
|
|
|
|
blocks.top()->append(curblock.cast<ASTNode>());
|
|
|
|
curblock = blocks.top();
|
|
|
|
|
|
|
|
if (curblock->blktype() == ASTBlock::BLK_CONTAINER
|
|
|
|
&& !curblock.cast<ASTContainerBlock>()->hasFinally()) {
|
|
|
|
blocks.pop();
|
|
|
|
blocks.top()->append(curblock.cast<ASTNode>());
|
|
|
|
curblock = blocks.top();
|
|
|
|
}
|
2011-10-16 18:17:48 -07:00
|
|
|
} else {
|
|
|
|
curblock->append(new ASTKeyword(ASTKeyword::KW_CONTINUE));
|
2011-10-10 15:57:20 -07:00
|
|
|
}
|
2011-09-18 22:31:43 -07:00
|
|
|
|
2011-01-04 15:25:25 -08:00
|
|
|
/* We're in a loop, this jumps back to the start */
|
|
|
|
/* I think we'll just ignore this case... */
|
|
|
|
break; // Bad idea? Probably!
|
|
|
|
}
|
|
|
|
|
2011-10-09 01:47:20 -07:00
|
|
|
if (curblock->blktype() == ASTBlock::BLK_CONTAINER) {
|
|
|
|
PycRef<ASTContainerBlock> cont = curblock.cast<ASTContainerBlock>();
|
|
|
|
if (cont->hasExcept() && pos < cont->except()) {
|
2017-07-05 16:36:04 -07:00
|
|
|
PycRef<ASTBlock> except = new ASTCondBlock(ASTBlock::BLK_EXCEPT, 0, NULL, false);
|
2011-10-09 01:47:20 -07:00
|
|
|
except->init();
|
|
|
|
blocks.push(except);
|
|
|
|
curblock = blocks.top();
|
|
|
|
}
|
2011-01-04 14:39:19 -08:00
|
|
|
break;
|
2011-10-09 01:47:20 -07:00
|
|
|
}
|
2011-01-04 14:39:19 -08:00
|
|
|
|
2010-12-31 21:45:06 -08:00
|
|
|
stack = stack_hist.top();
|
2010-12-31 02:42:58 -08:00
|
|
|
stack_hist.pop();
|
|
|
|
|
2010-12-31 21:45:06 -08:00
|
|
|
PycRef<ASTBlock> prev = curblock;
|
2011-10-09 01:47:20 -07:00
|
|
|
PycRef<ASTBlock> nil;
|
|
|
|
bool push = true;
|
|
|
|
|
|
|
|
do {
|
|
|
|
blocks.pop();
|
|
|
|
|
|
|
|
blocks.top()->append(prev.cast<ASTNode>());
|
|
|
|
|
|
|
|
if (prev->blktype() == ASTBlock::BLK_IF
|
|
|
|
|| prev->blktype() == ASTBlock::BLK_ELIF) {
|
|
|
|
if (push) {
|
|
|
|
stack_hist.push(stack);
|
|
|
|
}
|
|
|
|
PycRef<ASTBlock> next = new ASTBlock(ASTBlock::BLK_ELSE, blocks.top()->end());
|
|
|
|
if (prev->inited() == ASTCondBlock::PRE_POPPED) {
|
|
|
|
next->init(ASTCondBlock::PRE_POPPED);
|
|
|
|
}
|
|
|
|
|
|
|
|
blocks.push(next.cast<ASTBlock>());
|
|
|
|
prev = nil;
|
|
|
|
} else if (prev->blktype() == ASTBlock::BLK_EXCEPT) {
|
|
|
|
if (push) {
|
|
|
|
stack_hist.push(stack);
|
|
|
|
}
|
2017-07-05 16:36:04 -07:00
|
|
|
PycRef<ASTBlock> next = new ASTCondBlock(ASTBlock::BLK_EXCEPT, blocks.top()->end(), NULL, false);
|
2011-10-09 01:47:20 -07:00
|
|
|
next->init();
|
|
|
|
|
|
|
|
blocks.push(next.cast<ASTBlock>());
|
|
|
|
prev = nil;
|
|
|
|
} else if (prev->blktype() == ASTBlock::BLK_ELSE) {
|
|
|
|
/* Special case */
|
|
|
|
prev = blocks.top();
|
2011-10-09 15:05:01 -07:00
|
|
|
if (!push) {
|
|
|
|
stack = stack_hist.top();
|
|
|
|
stack_hist.pop();
|
|
|
|
}
|
2011-10-09 01:47:20 -07:00
|
|
|
push = false;
|
|
|
|
} else {
|
|
|
|
prev = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (prev != nil);
|
2010-12-31 21:45:06 -08:00
|
|
|
|
|
|
|
curblock = blocks.top();
|
2010-12-31 02:42:58 -08:00
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::JUMP_FORWARD_A:
|
2010-08-31 23:20:40 -07:00
|
|
|
{
|
2011-10-01 19:40:34 -07:00
|
|
|
if (curblock->blktype() == ASTBlock::BLK_CONTAINER) {
|
2011-10-01 21:05:33 -07:00
|
|
|
PycRef<ASTContainerBlock> cont = curblock.cast<ASTContainerBlock>();
|
|
|
|
if (cont->hasExcept()) {
|
|
|
|
stack_hist.push(stack);
|
|
|
|
|
2011-10-10 21:51:29 -07:00
|
|
|
curblock->setEnd(pos+operand);
|
2017-07-05 16:36:04 -07:00
|
|
|
PycRef<ASTBlock> except = new ASTCondBlock(ASTBlock::BLK_EXCEPT, pos+operand, NULL, false);
|
2011-10-01 21:17:22 -07:00
|
|
|
except->init();
|
2011-10-01 21:05:33 -07:00
|
|
|
blocks.push(except);
|
|
|
|
curblock = blocks.top();
|
|
|
|
}
|
2011-10-01 19:40:34 -07:00
|
|
|
break;
|
2012-06-02 02:38:59 -07:00
|
|
|
}
|
2011-10-09 01:47:20 -07:00
|
|
|
|
2011-10-22 01:33:18 -07:00
|
|
|
if ((curblock->blktype() == ASTBlock::BLK_WHILE
|
|
|
|
&& !curblock->inited())
|
|
|
|
|| (curblock->blktype() == ASTBlock::BLK_IF
|
|
|
|
&& curblock->size() == 0)) {
|
2011-10-16 18:17:48 -07:00
|
|
|
PycRef<PycObject> fakeint = new PycInt(1);
|
|
|
|
PycRef<ASTNode> truthy = new ASTObject(fakeint);
|
|
|
|
|
|
|
|
stack.push(truthy);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-07-22 16:11:59 -04:00
|
|
|
if (!stack_hist.empty()) {
|
|
|
|
stack = stack_hist.top();
|
|
|
|
stack_hist.pop();
|
|
|
|
}
|
2011-10-01 19:40:34 -07:00
|
|
|
|
2010-12-24 20:25:55 -08:00
|
|
|
PycRef<ASTBlock> prev = curblock;
|
2010-12-31 21:45:06 -08:00
|
|
|
PycRef<ASTBlock> nil;
|
2011-10-09 01:47:20 -07:00
|
|
|
bool push = true;
|
2010-12-24 20:25:55 -08:00
|
|
|
|
2010-12-31 21:45:06 -08:00
|
|
|
do {
|
|
|
|
blocks.pop();
|
|
|
|
|
2013-07-22 16:11:59 -04:00
|
|
|
if (!blocks.empty())
|
|
|
|
blocks.top()->append(prev.cast<ASTNode>());
|
2010-12-31 21:45:06 -08:00
|
|
|
|
2011-01-10 12:54:17 -08:00
|
|
|
if (prev->blktype() == ASTBlock::BLK_IF
|
|
|
|
|| prev->blktype() == ASTBlock::BLK_ELIF) {
|
2011-10-09 01:47:20 -07:00
|
|
|
if (operand == 0) {
|
|
|
|
prev = nil;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (push) {
|
|
|
|
stack_hist.push(stack);
|
|
|
|
}
|
2010-12-31 21:45:06 -08:00
|
|
|
PycRef<ASTBlock> next = new ASTBlock(ASTBlock::BLK_ELSE, pos+operand);
|
2011-01-02 02:51:23 -08:00
|
|
|
if (prev->inited() == ASTCondBlock::PRE_POPPED) {
|
|
|
|
next->init(ASTCondBlock::PRE_POPPED);
|
|
|
|
}
|
|
|
|
|
2011-10-02 18:57:42 -07:00
|
|
|
blocks.push(next.cast<ASTBlock>());
|
|
|
|
prev = nil;
|
|
|
|
} else if (prev->blktype() == ASTBlock::BLK_EXCEPT) {
|
2011-10-09 01:47:20 -07:00
|
|
|
if (operand == 0) {
|
|
|
|
prev = nil;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (push) {
|
|
|
|
stack_hist.push(stack);
|
|
|
|
}
|
2017-07-05 16:36:04 -07:00
|
|
|
PycRef<ASTBlock> next = new ASTCondBlock(ASTBlock::BLK_EXCEPT, pos+operand, NULL, false);
|
2011-10-02 18:57:42 -07:00
|
|
|
next->init();
|
|
|
|
|
2010-12-31 21:45:06 -08:00
|
|
|
blocks.push(next.cast<ASTBlock>());
|
|
|
|
prev = nil;
|
2011-09-18 23:55:27 -07:00
|
|
|
} else if (prev->blktype() == ASTBlock::BLK_ELSE) {
|
2010-12-31 21:45:06 -08:00
|
|
|
/* Special case */
|
|
|
|
prev = blocks.top();
|
2011-10-09 15:05:01 -07:00
|
|
|
if (!push) {
|
|
|
|
stack = stack_hist.top();
|
|
|
|
stack_hist.pop();
|
|
|
|
}
|
2011-10-09 01:47:20 -07:00
|
|
|
push = false;
|
2011-10-22 01:33:18 -07:00
|
|
|
|
|
|
|
if (prev->blktype() == ASTBlock::BLK_MAIN) {
|
|
|
|
/* Something went out of control! */
|
|
|
|
prev = nil;
|
|
|
|
}
|
2011-10-22 00:42:22 -07:00
|
|
|
} else if (prev->blktype() == ASTBlock::BLK_TRY
|
|
|
|
&& prev->end() < pos+operand) {
|
|
|
|
/* Need to add an except/finally block */
|
|
|
|
stack = stack_hist.top();
|
|
|
|
stack.pop();
|
|
|
|
|
|
|
|
if (blocks.top()->blktype() == ASTBlock::BLK_CONTAINER) {
|
|
|
|
PycRef<ASTContainerBlock> cont = blocks.top().cast<ASTContainerBlock>();
|
|
|
|
if (cont->hasExcept()) {
|
|
|
|
if (push) {
|
|
|
|
stack_hist.push(stack);
|
|
|
|
}
|
|
|
|
|
2017-07-05 16:36:04 -07:00
|
|
|
PycRef<ASTBlock> except = new ASTCondBlock(ASTBlock::BLK_EXCEPT, pos+operand, NULL, false);
|
2011-10-22 00:42:22 -07:00
|
|
|
except->init();
|
|
|
|
blocks.push(except);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Something TERRIBLE happened!!\n");
|
|
|
|
}
|
|
|
|
prev = nil;
|
2010-12-31 21:45:06 -08:00
|
|
|
} else {
|
|
|
|
prev = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (prev != nil);
|
2010-12-24 20:25:55 -08:00
|
|
|
|
|
|
|
curblock = blocks.top();
|
2011-10-10 21:22:02 -07:00
|
|
|
|
|
|
|
if (curblock->blktype() == ASTBlock::BLK_EXCEPT) {
|
|
|
|
curblock->setEnd(pos+operand);
|
|
|
|
}
|
2010-08-31 23:20:40 -07:00
|
|
|
}
|
|
|
|
break;
|
2011-10-10 15:57:20 -07:00
|
|
|
case Pyc::LIST_APPEND:
|
|
|
|
case Pyc::LIST_APPEND_A:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> value = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
|
|
|
PycRef<ASTNode> list = stack.top();
|
|
|
|
|
|
|
|
|
|
|
|
if (curblock->blktype() == ASTBlock::BLK_FOR
|
|
|
|
&& curblock.cast<ASTIterBlock>()->isComprehension()) {
|
2019-10-04 16:35:58 -07:00
|
|
|
stack.pop();
|
2011-10-10 15:57:20 -07:00
|
|
|
stack.push(new ASTComprehension(value));
|
|
|
|
} else {
|
|
|
|
stack.push(new ASTSubscr(list, value)); /* Total hack */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::LOAD_ATTR_A:
|
2009-07-27 03:00:55 +00:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> name = stack.top();
|
2017-07-05 16:36:04 -07:00
|
|
|
if (name.type() != ASTNode::NODE_IMPORT) {
|
2011-09-20 22:36:15 -07:00
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTBinary(name, new ASTName(code->getName(operand)), ASTBinary::BIN_ATTR));
|
|
|
|
}
|
2009-07-27 03:00:55 +00:00
|
|
|
}
|
|
|
|
break;
|
2019-10-08 08:53:53 -07:00
|
|
|
case Pyc::LOAD_BUILD_CLASS:
|
|
|
|
stack.push(new ASTLoadBuildClass(new PycObject()));
|
|
|
|
break;
|
2011-10-16 22:46:17 -07:00
|
|
|
case Pyc::LOAD_CLOSURE_A:
|
|
|
|
/* Ignore this */
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::LOAD_CONST_A:
|
2010-12-18 22:18:32 -08:00
|
|
|
{
|
|
|
|
PycRef<ASTObject> t_ob = new ASTObject(code->getConst(operand));
|
|
|
|
|
2017-07-05 16:36:04 -07:00
|
|
|
if ((t_ob->object().type() == PycObject::TYPE_TUPLE ||
|
|
|
|
t_ob->object().type() == PycObject::TYPE_SMALL_TUPLE) &&
|
2010-12-18 22:18:32 -08:00
|
|
|
!t_ob->object().cast<PycTuple>()->values().size()) {
|
|
|
|
ASTTuple::value_t values;
|
|
|
|
stack.push(new ASTTuple(values));
|
2017-07-05 16:36:04 -07:00
|
|
|
} else if (t_ob->object().type() == PycObject::TYPE_NONE) {
|
|
|
|
stack.push(NULL);
|
2010-12-18 22:18:32 -08:00
|
|
|
} else {
|
|
|
|
stack.push(t_ob.cast<ASTNode>());
|
|
|
|
}
|
|
|
|
}
|
2009-07-26 10:07:13 +00:00
|
|
|
break;
|
2011-10-16 22:46:17 -07:00
|
|
|
case Pyc::LOAD_DEREF_A:
|
2018-01-28 14:33:26 -08:00
|
|
|
stack.push(new ASTName(code->getCellVar(operand)));
|
2011-10-16 22:46:17 -07:00
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::LOAD_FAST_A:
|
2012-05-26 14:03:10 -07:00
|
|
|
if (mod->verCompare(1, 3) < 0)
|
2009-07-27 00:23:49 +00:00
|
|
|
stack.push(new ASTName(code->getName(operand)));
|
|
|
|
else
|
|
|
|
stack.push(new ASTName(code->getVarName(operand)));
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::LOAD_GLOBAL_A:
|
2009-07-27 03:00:55 +00:00
|
|
|
stack.push(new ASTName(code->getName(operand)));
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::LOAD_LOCALS:
|
2009-07-27 03:00:55 +00:00
|
|
|
stack.push(new ASTNode(ASTNode::NODE_LOCALS));
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::LOAD_NAME_A:
|
2009-07-27 00:23:49 +00:00
|
|
|
stack.push(new ASTName(code->getName(operand)));
|
|
|
|
break;
|
2011-10-16 22:46:17 -07:00
|
|
|
case Pyc::MAKE_CLOSURE_A:
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::MAKE_FUNCTION_A:
|
2009-07-27 00:23:49 +00:00
|
|
|
{
|
2019-10-04 16:16:10 -07:00
|
|
|
PycRef<ASTNode> fun_code = stack.top();
|
2009-07-27 00:23:49 +00:00
|
|
|
stack.pop();
|
2015-04-17 09:51:00 -04:00
|
|
|
|
|
|
|
/* Test for the qualified name of the function (at TOS) */
|
2019-10-04 16:16:10 -07:00
|
|
|
int tos_type = fun_code.cast<ASTObject>()->object().type();
|
2015-04-17 09:51:00 -04:00
|
|
|
if (tos_type != PycObject::TYPE_CODE &&
|
2015-04-17 18:37:37 -07:00
|
|
|
tos_type != PycObject::TYPE_CODE2) {
|
2019-10-04 16:16:10 -07:00
|
|
|
fun_code = stack.top();
|
2015-04-17 09:51:00 -04:00
|
|
|
stack.pop();
|
|
|
|
}
|
|
|
|
|
2019-10-08 11:36:12 -07:00
|
|
|
ASTFunction::defarg_t defArgs, kwDefArgs;
|
|
|
|
const int defCount = operand & 0xFF;
|
|
|
|
const int kwDefCount = (operand >> 8) & 0xFF;
|
|
|
|
for (int i = 0; i < defCount; ++i) {
|
2009-07-27 00:23:49 +00:00
|
|
|
defArgs.push_front(stack.top());
|
|
|
|
stack.pop();
|
|
|
|
}
|
2019-10-08 11:36:12 -07:00
|
|
|
for (int i = 0; i < kwDefCount; ++i) {
|
|
|
|
kwDefArgs.push_front(stack.top());
|
|
|
|
stack.pop();
|
|
|
|
}
|
|
|
|
stack.push(new ASTFunction(fun_code, defArgs, kwDefArgs));
|
2009-07-27 00:23:49 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-10-24 09:44:06 -07:00
|
|
|
case Pyc::NOP:
|
|
|
|
break;
|
2010-12-31 02:42:58 -08:00
|
|
|
case Pyc::POP_BLOCK:
|
2010-12-21 23:41:56 -08:00
|
|
|
{
|
2011-10-01 19:40:34 -07:00
|
|
|
if (curblock->blktype() == ASTBlock::BLK_CONTAINER ||
|
|
|
|
curblock->blktype() == ASTBlock::BLK_FINALLY) {
|
|
|
|
/* These should only be popped by an END_FINALLY */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-06-09 16:45:37 -07:00
|
|
|
if (curblock->blktype() == ASTBlock::BLK_WITH) {
|
|
|
|
// This should only be popped by a WITH_CLEANUP
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-09-18 22:31:43 -07:00
|
|
|
PycRef<ASTBlock> tmp;
|
|
|
|
|
2011-10-01 21:05:33 -07:00
|
|
|
if (curblock->nodes().size() &&
|
2017-07-05 16:36:04 -07:00
|
|
|
curblock->nodes().back().type() == ASTNode::NODE_KEYWORD) {
|
2011-09-18 22:31:43 -07:00
|
|
|
curblock->removeLast();
|
|
|
|
}
|
|
|
|
|
2011-10-09 01:47:20 -07:00
|
|
|
if (curblock->blktype() == ASTBlock::BLK_IF
|
|
|
|
|| curblock->blktype() == ASTBlock::BLK_ELIF
|
|
|
|
|| curblock->blktype() == ASTBlock::BLK_ELSE
|
|
|
|
|| curblock->blktype() == ASTBlock::BLK_TRY
|
|
|
|
|| curblock->blktype() == ASTBlock::BLK_EXCEPT
|
|
|
|
|| curblock->blktype() == ASTBlock::BLK_FINALLY) {
|
|
|
|
stack = stack_hist.top();
|
|
|
|
stack_hist.pop();
|
|
|
|
}
|
|
|
|
|
2011-09-18 22:31:43 -07:00
|
|
|
tmp = curblock;
|
2010-12-21 23:41:56 -08:00
|
|
|
blocks.pop();
|
2013-07-23 13:16:49 -04:00
|
|
|
|
2013-07-22 22:23:45 -04:00
|
|
|
if (!blocks.empty())
|
2013-07-22 16:11:59 -04:00
|
|
|
curblock = blocks.top();
|
2011-10-02 18:57:42 -07:00
|
|
|
|
|
|
|
if (!(tmp->blktype() == ASTBlock::BLK_ELSE
|
|
|
|
&& tmp->nodes().size() == 0)) {
|
|
|
|
curblock->append(tmp.cast<ASTNode>());
|
|
|
|
}
|
|
|
|
|
2013-07-22 16:11:59 -04:00
|
|
|
if (tmp->blktype() == ASTBlock::BLK_FOR && tmp->end() >= pos) {
|
2011-10-16 18:17:48 -07:00
|
|
|
stack_hist.push(stack);
|
|
|
|
|
|
|
|
PycRef<ASTBlock> blkelse = new ASTBlock(ASTBlock::BLK_ELSE, tmp->end());
|
|
|
|
blocks.push(blkelse);
|
|
|
|
curblock = blocks.top();
|
|
|
|
}
|
|
|
|
|
2011-10-10 01:41:57 -07:00
|
|
|
if (curblock->blktype() == ASTBlock::BLK_TRY
|
|
|
|
&& tmp->blktype() != ASTBlock::BLK_FOR
|
|
|
|
&& tmp->blktype() != ASTBlock::BLK_WHILE) {
|
|
|
|
stack = stack_hist.top();
|
|
|
|
stack_hist.pop();
|
|
|
|
|
|
|
|
tmp = curblock;
|
|
|
|
blocks.pop();
|
|
|
|
curblock = blocks.top();
|
|
|
|
|
|
|
|
if (!(tmp->blktype() == ASTBlock::BLK_ELSE
|
|
|
|
&& tmp->nodes().size() == 0)) {
|
|
|
|
curblock->append(tmp.cast<ASTNode>());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-02 18:57:42 -07:00
|
|
|
if (curblock->blktype() == ASTBlock::BLK_CONTAINER) {
|
|
|
|
PycRef<ASTContainerBlock> cont = curblock.cast<ASTContainerBlock>();
|
|
|
|
|
|
|
|
if (tmp->blktype() == ASTBlock::BLK_ELSE && !cont->hasFinally()) {
|
|
|
|
|
|
|
|
/* Pop the container */
|
|
|
|
blocks.pop();
|
|
|
|
curblock = blocks.top();
|
|
|
|
curblock->append(cont.cast<ASTNode>());
|
|
|
|
|
2011-10-09 01:47:20 -07:00
|
|
|
} else if ((tmp->blktype() == ASTBlock::BLK_ELSE && cont->hasFinally())
|
|
|
|
|| (tmp->blktype() == ASTBlock::BLK_TRY && !cont->hasExcept())) {
|
2011-10-02 18:57:42 -07:00
|
|
|
|
|
|
|
/* Add the finally block */
|
2011-10-09 01:47:20 -07:00
|
|
|
stack_hist.push(stack);
|
2011-10-02 18:57:42 -07:00
|
|
|
|
|
|
|
PycRef<ASTBlock> final = new ASTBlock(ASTBlock::BLK_FINALLY, 0, true);
|
|
|
|
blocks.push(final);
|
|
|
|
curblock = blocks.top();
|
|
|
|
}
|
|
|
|
}
|
2011-10-16 21:22:08 -07:00
|
|
|
|
|
|
|
if (curblock->blktype() == ASTBlock::BLK_FOR
|
|
|
|
&& curblock->end() == pos) {
|
|
|
|
blocks.pop();
|
|
|
|
blocks.top()->append(curblock.cast<ASTNode>());
|
|
|
|
curblock = blocks.top();
|
|
|
|
}
|
2010-12-21 23:41:56 -08:00
|
|
|
}
|
2010-12-31 02:42:58 -08:00
|
|
|
break;
|
2011-10-01 21:50:24 -07:00
|
|
|
case Pyc::POP_EXCEPT:
|
|
|
|
/* Do nothing. */
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::POP_TOP:
|
2009-07-27 03:23:56 +00:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> value = stack.top();
|
|
|
|
stack.pop();
|
2011-01-10 12:54:17 -08:00
|
|
|
if (!curblock->inited()) {
|
2012-06-03 20:39:45 -07:00
|
|
|
if (curblock->blktype() == ASTBlock::BLK_WITH) {
|
|
|
|
curblock.cast<ASTWithBlock>()->setExpr(value);
|
|
|
|
} else {
|
2018-01-28 14:33:26 -08:00
|
|
|
curblock->init();
|
2012-06-03 20:39:45 -07:00
|
|
|
}
|
2011-01-01 02:31:31 -08:00
|
|
|
break;
|
2019-10-10 10:26:19 -07:00
|
|
|
} else if (value == nullptr
|
|
|
|
|| value.type() == ASTNode::NODE_INVALID
|
2017-07-05 16:36:04 -07:00
|
|
|
|| value.type() == ASTNode::NODE_BINARY
|
2019-10-10 10:26:19 -07:00
|
|
|
|| value.type() == ASTNode::NODE_NAME
|
|
|
|
|| (value.type() == ASTNode::NODE_COMPARE
|
|
|
|
&& value.cast<ASTCompare>()->op() == ASTCompare::CMP_EXCEPTION)) {
|
2011-10-01 23:00:12 -07:00
|
|
|
break;
|
2011-01-01 02:31:31 -08:00
|
|
|
}
|
|
|
|
|
2011-01-08 16:19:38 -08:00
|
|
|
curblock->append(value);
|
2011-10-10 15:57:20 -07:00
|
|
|
|
|
|
|
if (curblock->blktype() == ASTBlock::BLK_FOR
|
|
|
|
&& curblock.cast<ASTIterBlock>()->isComprehension()) {
|
|
|
|
/* This relies on some really uncertain logic...
|
|
|
|
* If it's a comprehension, the only POP_TOP should be
|
|
|
|
* a call to append the iter to the list.
|
|
|
|
*/
|
2017-07-05 16:36:04 -07:00
|
|
|
if (value.type() == ASTNode::NODE_CALL) {
|
2011-10-10 15:57:20 -07:00
|
|
|
PycRef<ASTNode> res = value.cast<ASTCall>()->pparams().front();
|
|
|
|
|
|
|
|
stack.push(new ASTComprehension(res));
|
|
|
|
}
|
|
|
|
}
|
2009-07-27 03:23:56 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::PRINT_ITEM:
|
2019-10-09 14:20:46 -07:00
|
|
|
{
|
|
|
|
PycRef<ASTPrint> printNode;
|
|
|
|
if (curblock->size() > 0 && curblock->nodes().back().type() == ASTNode::NODE_PRINT)
|
|
|
|
printNode = curblock->nodes().back().cast<ASTPrint>();
|
|
|
|
if (printNode && printNode->stream() == nullptr && !printNode->eol())
|
|
|
|
printNode->add(stack.top());
|
|
|
|
else
|
|
|
|
curblock->append(new ASTPrint(stack.top()));
|
|
|
|
stack.pop();
|
|
|
|
}
|
2009-08-03 23:13:50 +00:00
|
|
|
break;
|
2011-09-18 00:35:28 -07:00
|
|
|
case Pyc::PRINT_ITEM_TO:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> stream = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
2019-10-09 14:20:46 -07:00
|
|
|
PycRef<ASTPrint> printNode;
|
|
|
|
if (curblock->size() > 0 && curblock->nodes().back().type() == ASTNode::NODE_PRINT)
|
|
|
|
printNode = curblock->nodes().back().cast<ASTPrint>();
|
|
|
|
if (printNode && printNode->stream() == stream && !printNode->eol())
|
|
|
|
printNode->add(stack.top());
|
|
|
|
else
|
|
|
|
curblock->append(new ASTPrint(stack.top(), stream));
|
2011-09-18 00:35:28 -07:00
|
|
|
stack.pop();
|
|
|
|
}
|
2019-10-09 14:20:46 -07:00
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::PRINT_NEWLINE:
|
2019-10-09 14:20:46 -07:00
|
|
|
{
|
|
|
|
PycRef<ASTPrint> printNode;
|
|
|
|
if (curblock->size() > 0 && curblock->nodes().back().type() == ASTNode::NODE_PRINT)
|
|
|
|
printNode = curblock->nodes().back().cast<ASTPrint>();
|
|
|
|
if (printNode && printNode->stream() == nullptr && !printNode->eol())
|
|
|
|
printNode->setEol(true);
|
|
|
|
else
|
|
|
|
curblock->append(new ASTPrint(nullptr));
|
|
|
|
stack.pop();
|
|
|
|
}
|
2009-08-03 23:13:50 +00:00
|
|
|
break;
|
2011-09-18 00:35:28 -07:00
|
|
|
case Pyc::PRINT_NEWLINE_TO:
|
2019-10-09 14:20:46 -07:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> stream = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
|
|
|
PycRef<ASTPrint> printNode;
|
|
|
|
if (curblock->size() > 0 && curblock->nodes().back().type() == ASTNode::NODE_PRINT)
|
|
|
|
printNode = curblock->nodes().back().cast<ASTPrint>();
|
|
|
|
if (printNode && printNode->stream() == stream && !printNode->eol())
|
|
|
|
printNode->setEol(true);
|
|
|
|
else
|
|
|
|
curblock->append(new ASTPrint(nullptr, stream));
|
|
|
|
stack.pop();
|
|
|
|
}
|
2011-09-18 00:35:28 -07:00
|
|
|
break;
|
2011-01-01 02:31:31 -08:00
|
|
|
case Pyc::RAISE_VARARGS_A:
|
|
|
|
{
|
|
|
|
ASTRaise::param_t paramList;
|
|
|
|
for (int i = 0; i < operand; i++) {
|
|
|
|
paramList.push_front(stack.top());
|
|
|
|
stack.pop();
|
|
|
|
}
|
|
|
|
curblock->append(new ASTRaise(paramList));
|
2011-10-01 21:44:57 -07:00
|
|
|
|
2011-10-10 19:49:33 -07:00
|
|
|
if ((curblock->blktype() == ASTBlock::BLK_IF
|
|
|
|
|| curblock->blktype() == ASTBlock::BLK_ELSE)
|
|
|
|
&& stack_hist.size()
|
2012-05-26 14:03:10 -07:00
|
|
|
&& (mod->verCompare(2, 6) >= 0)) {
|
2011-10-01 21:44:57 -07:00
|
|
|
stack = stack_hist.top();
|
|
|
|
stack_hist.pop();
|
|
|
|
|
|
|
|
PycRef<ASTBlock> prev = curblock;
|
|
|
|
blocks.pop();
|
|
|
|
curblock = blocks.top();
|
|
|
|
curblock->append(prev.cast<ASTNode>());
|
|
|
|
|
|
|
|
bc_next(source, mod, opcode, operand, pos);
|
|
|
|
}
|
2011-01-01 02:31:31 -08:00
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::RETURN_VALUE:
|
2009-07-27 00:23:49 +00:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> value = stack.top();
|
|
|
|
stack.pop();
|
2010-12-21 23:41:56 -08:00
|
|
|
curblock->append(new ASTReturn(value));
|
2011-01-02 02:51:23 -08:00
|
|
|
|
2011-01-10 12:54:17 -08:00
|
|
|
if ((curblock->blktype() == ASTBlock::BLK_IF
|
2011-01-08 16:19:38 -08:00
|
|
|
|| curblock->blktype() == ASTBlock::BLK_ELSE)
|
2011-10-09 01:47:20 -07:00
|
|
|
&& stack_hist.size()
|
2012-05-26 14:03:10 -07:00
|
|
|
&& (mod->verCompare(2, 6) >= 0)) {
|
2011-01-08 16:19:38 -08:00
|
|
|
stack = stack_hist.top();
|
|
|
|
stack_hist.pop();
|
2011-01-02 02:51:23 -08:00
|
|
|
|
|
|
|
PycRef<ASTBlock> prev = curblock;
|
|
|
|
blocks.pop();
|
|
|
|
curblock = blocks.top();
|
|
|
|
curblock->append(prev.cast<ASTNode>());
|
2011-01-10 12:54:17 -08:00
|
|
|
|
|
|
|
bc_next(source, mod, opcode, operand, pos);
|
2011-01-08 16:19:38 -08:00
|
|
|
}
|
2009-07-27 00:23:49 +00:00
|
|
|
}
|
|
|
|
break;
|
2011-01-05 22:15:22 -08:00
|
|
|
case Pyc::ROT_TWO:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> one = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> two = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
|
|
|
stack.push(one);
|
|
|
|
stack.push(two);
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::ROT_THREE:
|
2009-07-27 08:42:59 +00:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> one = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> two = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> three = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(one);
|
|
|
|
stack.push(three);
|
|
|
|
stack.push(two);
|
|
|
|
}
|
|
|
|
break;
|
2011-09-18 11:59:02 -07:00
|
|
|
case Pyc::ROT_FOUR:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> one = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> two = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> three = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> four = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(one);
|
|
|
|
stack.push(four);
|
|
|
|
stack.push(three);
|
|
|
|
stack.push(two);
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::SET_LINENO_A:
|
2009-08-03 23:13:50 +00:00
|
|
|
// Ignore
|
|
|
|
break;
|
2012-06-03 20:39:45 -07:00
|
|
|
case Pyc::SETUP_WITH_A:
|
|
|
|
{
|
|
|
|
PycRef<ASTBlock> withblock = new ASTWithBlock(pos+operand);
|
|
|
|
blocks.push(withblock);
|
|
|
|
curblock = blocks.top();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Pyc::WITH_CLEANUP:
|
|
|
|
{
|
2012-06-09 16:45:37 -07:00
|
|
|
// Stack top should be a None. Ignore it.
|
2012-06-03 20:39:45 -07:00
|
|
|
PycRef<ASTNode> none = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
2017-07-05 16:36:04 -07:00
|
|
|
if (none != NULL) {
|
2012-06-03 20:39:45 -07:00
|
|
|
fprintf(stderr, "Something TERRIBLE happened!\n");
|
2012-06-09 16:45:37 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (curblock->blktype() == ASTBlock::BLK_WITH
|
|
|
|
&& curblock->end() == curpos) {
|
|
|
|
PycRef<ASTBlock> with = curblock;
|
|
|
|
blocks.pop();
|
|
|
|
curblock = blocks.top();
|
|
|
|
curblock->append(with.cast<ASTNode>());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "Something TERRIBLE happened! No matching with block found for WITH_CLEANUP at %d\n", curpos);
|
2012-06-03 20:39:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2011-10-01 17:43:30 -07:00
|
|
|
case Pyc::SETUP_EXCEPT_A:
|
2010-12-21 23:41:56 -08:00
|
|
|
{
|
2011-10-01 19:40:34 -07:00
|
|
|
if (curblock->blktype() == ASTBlock::BLK_CONTAINER) {
|
2011-10-02 18:57:42 -07:00
|
|
|
curblock.cast<ASTContainerBlock>()->setExcept(pos+operand);
|
2011-10-01 19:40:34 -07:00
|
|
|
} else {
|
2011-10-02 18:57:42 -07:00
|
|
|
PycRef<ASTBlock> next = new ASTContainerBlock(0, pos+operand);
|
2011-10-01 19:40:34 -07:00
|
|
|
blocks.push(next.cast<ASTBlock>());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store the current stack for the except/finally statement(s) */
|
|
|
|
stack_hist.push(stack);
|
2011-10-01 21:17:22 -07:00
|
|
|
PycRef<ASTBlock> tryblock = new ASTBlock(ASTBlock::BLK_TRY, pos+operand, true);
|
2011-10-01 19:40:34 -07:00
|
|
|
blocks.push(tryblock.cast<ASTBlock>());
|
|
|
|
curblock = blocks.top();
|
2011-10-01 21:56:48 -07:00
|
|
|
|
|
|
|
need_try = false;
|
2010-12-21 23:41:56 -08:00
|
|
|
}
|
2011-10-01 17:43:30 -07:00
|
|
|
break;
|
|
|
|
case Pyc::SETUP_FINALLY_A:
|
2010-12-21 23:41:56 -08:00
|
|
|
{
|
2011-10-02 18:57:42 -07:00
|
|
|
PycRef<ASTBlock> next = new ASTContainerBlock(pos+operand);
|
2011-10-01 19:40:34 -07:00
|
|
|
blocks.push(next.cast<ASTBlock>());
|
|
|
|
curblock = blocks.top();
|
2011-10-01 21:56:48 -07:00
|
|
|
|
|
|
|
need_try = true;
|
2010-12-21 23:41:56 -08:00
|
|
|
}
|
2011-10-01 17:43:30 -07:00
|
|
|
break;
|
2010-12-31 02:42:58 -08:00
|
|
|
case Pyc::SETUP_LOOP_A:
|
|
|
|
{
|
2017-07-05 16:36:04 -07:00
|
|
|
PycRef<ASTBlock> next = new ASTCondBlock(ASTBlock::BLK_WHILE, pos+operand, NULL, false);
|
2010-12-31 02:42:58 -08:00
|
|
|
blocks.push(next.cast<ASTBlock>());
|
|
|
|
curblock = blocks.top();
|
|
|
|
}
|
|
|
|
break;
|
2011-01-04 13:52:15 -08:00
|
|
|
case Pyc::SLICE_0:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> name = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
|
|
|
PycRef<ASTNode> slice = new ASTSlice(ASTSlice::SLICE0);
|
|
|
|
stack.push(new ASTSubscr(name, slice));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Pyc::SLICE_1:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> lower = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> name = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
|
|
|
PycRef<ASTNode> slice = new ASTSlice(ASTSlice::SLICE1, lower);
|
|
|
|
stack.push(new ASTSubscr(name, slice));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Pyc::SLICE_2:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> upper = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> name = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
2017-07-05 16:36:04 -07:00
|
|
|
PycRef<ASTNode> slice = new ASTSlice(ASTSlice::SLICE2, NULL, upper);
|
2011-01-04 13:52:15 -08:00
|
|
|
stack.push(new ASTSubscr(name, slice));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Pyc::SLICE_3:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> upper = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> lower = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> name = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
|
|
|
PycRef<ASTNode> slice = new ASTSlice(ASTSlice::SLICE3, lower, upper);
|
|
|
|
stack.push(new ASTSubscr(name, slice));
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::STORE_ATTR_A:
|
2009-07-27 03:23:56 +00:00
|
|
|
{
|
2011-10-16 21:21:48 -07:00
|
|
|
if (unpack) {
|
|
|
|
PycRef<ASTNode> name = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> attr = new ASTBinary(name, new ASTName(code->getName(operand)), ASTBinary::BIN_ATTR);
|
|
|
|
|
|
|
|
PycRef<ASTNode> tup = stack.top();
|
2019-10-04 16:16:10 -07:00
|
|
|
if (tup.type() == ASTNode::NODE_TUPLE)
|
|
|
|
tup.cast<ASTTuple>()->add(attr);
|
|
|
|
else
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("Something TERRIBLE happened!\n", stderr);
|
2011-10-16 21:21:48 -07:00
|
|
|
|
|
|
|
if (--unpack <= 0) {
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> seq = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
|
|
|
curblock->append(new ASTStore(seq, tup));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
PycRef<ASTNode> name = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> value = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> attr = new ASTBinary(name, new ASTName(code->getName(operand)), ASTBinary::BIN_ATTR);
|
|
|
|
|
|
|
|
curblock->append(new ASTStore(value, attr));
|
|
|
|
}
|
2009-07-27 03:23:56 +00:00
|
|
|
}
|
|
|
|
break;
|
2011-10-16 22:46:17 -07:00
|
|
|
case Pyc::STORE_DEREF_A:
|
|
|
|
{
|
|
|
|
if (unpack) {
|
2018-01-28 14:33:26 -08:00
|
|
|
PycRef<ASTNode> name = new ASTName(code->getCellVar(operand));
|
2011-10-16 22:46:17 -07:00
|
|
|
|
|
|
|
PycRef<ASTNode> tup = stack.top();
|
2019-10-04 16:16:10 -07:00
|
|
|
if (tup.type() == ASTNode::NODE_TUPLE)
|
|
|
|
tup.cast<ASTTuple>()->add(name);
|
|
|
|
else
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("Something TERRIBLE happened!\n", stderr);
|
2011-10-16 22:46:17 -07:00
|
|
|
|
|
|
|
if (--unpack <= 0) {
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> seq = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
|
|
|
curblock->append(new ASTStore(seq, tup));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
PycRef<ASTNode> value = stack.top();
|
|
|
|
stack.pop();
|
2018-01-28 14:33:26 -08:00
|
|
|
PycRef<ASTNode> name = new ASTName(code->getCellVar(operand));
|
2011-10-16 22:46:17 -07:00
|
|
|
curblock->append(new ASTStore(value, name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::STORE_FAST_A:
|
2009-07-27 00:23:49 +00:00
|
|
|
{
|
2011-01-08 16:19:38 -08:00
|
|
|
if (unpack) {
|
|
|
|
PycRef<ASTNode> name;
|
2011-01-01 02:31:31 -08:00
|
|
|
|
2012-05-26 14:03:10 -07:00
|
|
|
if (mod->verCompare(1, 3) < 0)
|
2011-01-08 16:19:38 -08:00
|
|
|
name = new ASTName(code->getName(operand));
|
|
|
|
else
|
|
|
|
name = new ASTName(code->getVarName(operand));
|
2011-01-01 02:31:31 -08:00
|
|
|
|
2011-01-08 16:19:38 -08:00
|
|
|
PycRef<ASTNode> tup = stack.top();
|
2019-10-04 16:16:10 -07:00
|
|
|
if (tup.type() == ASTNode::NODE_TUPLE)
|
|
|
|
tup.cast<ASTTuple>()->add(name);
|
|
|
|
else
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("Something TERRIBLE happened!\n", stderr);
|
2011-01-08 16:19:38 -08:00
|
|
|
|
|
|
|
if (--unpack <= 0) {
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> seq = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
2013-06-28 16:30:05 +02:00
|
|
|
if (curblock->blktype() == ASTBlock::BLK_FOR
|
|
|
|
&& !curblock->inited()) {
|
2019-10-04 14:08:47 -07:00
|
|
|
PycRef<ASTTuple> tuple = tup.cast<ASTTuple>();
|
|
|
|
if (tuple != NULL)
|
|
|
|
tuple->setRequireParens(false);
|
2013-06-28 16:30:05 +02:00
|
|
|
curblock.cast<ASTIterBlock>()->setIndex(tup);
|
|
|
|
} else {
|
|
|
|
curblock->append(new ASTStore(seq, tup));
|
|
|
|
}
|
2011-01-08 16:19:38 -08:00
|
|
|
}
|
2011-01-01 02:31:31 -08:00
|
|
|
} else {
|
2011-01-08 16:19:38 -08:00
|
|
|
PycRef<ASTNode> value = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> name;
|
|
|
|
|
2012-05-26 14:03:10 -07:00
|
|
|
if (mod->verCompare(1, 3) < 0)
|
2011-01-08 16:19:38 -08:00
|
|
|
name = new ASTName(code->getName(operand));
|
|
|
|
else
|
|
|
|
name = new ASTName(code->getVarName(operand));
|
|
|
|
|
2011-10-16 18:17:48 -07:00
|
|
|
if (name.cast<ASTName>()->name()->value()[0] == '_'
|
|
|
|
&& name.cast<ASTName>()->name()->value()[1] == '[') {
|
|
|
|
/* Don't show stores of list comp append objects. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-01-08 16:19:38 -08:00
|
|
|
if (curblock->blktype() == ASTBlock::BLK_FOR
|
2011-09-18 23:55:27 -07:00
|
|
|
&& !curblock->inited()) {
|
2011-01-08 16:19:38 -08:00
|
|
|
curblock.cast<ASTIterBlock>()->setIndex(name);
|
2012-06-09 16:45:37 -07:00
|
|
|
} else if (curblock->blktype() == ASTBlock::BLK_WITH
|
|
|
|
&& !curblock->inited()) {
|
2012-06-03 20:39:45 -07:00
|
|
|
curblock.cast<ASTWithBlock>()->setExpr(value);
|
|
|
|
curblock.cast<ASTWithBlock>()->setVar(name);
|
2011-01-08 16:19:38 -08:00
|
|
|
} else {
|
|
|
|
curblock->append(new ASTStore(value, name));
|
|
|
|
}
|
2011-01-01 02:31:31 -08:00
|
|
|
}
|
2009-07-27 08:42:59 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::STORE_GLOBAL_A:
|
2009-07-27 03:23:56 +00:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> name = new ASTName(code->getName(operand));
|
2011-10-16 22:46:17 -07:00
|
|
|
|
|
|
|
if (unpack) {
|
|
|
|
PycRef<ASTNode> tup = stack.top();
|
2019-10-04 16:16:10 -07:00
|
|
|
if (tup.type() == ASTNode::NODE_TUPLE)
|
|
|
|
tup.cast<ASTTuple>()->add(name);
|
|
|
|
else
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("Something TERRIBLE happened!\n", stderr);
|
2011-10-16 22:46:17 -07:00
|
|
|
|
|
|
|
if (--unpack <= 0) {
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> seq = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
|
|
|
if (curblock->blktype() == ASTBlock::BLK_FOR
|
|
|
|
&& !curblock->inited()) {
|
2019-10-04 14:08:47 -07:00
|
|
|
PycRef<ASTTuple> tuple = tup.cast<ASTTuple>();
|
|
|
|
if (tuple != NULL)
|
|
|
|
tuple->setRequireParens(false);
|
2011-10-16 22:46:17 -07:00
|
|
|
curblock.cast<ASTIterBlock>()->setIndex(tup);
|
|
|
|
} else {
|
|
|
|
curblock->append(new ASTStore(seq, tup));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
PycRef<ASTNode> value = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
curblock->append(new ASTStore(value, name));
|
|
|
|
}
|
2011-10-09 23:42:34 -07:00
|
|
|
|
|
|
|
/* Mark the global as used */
|
|
|
|
code->markGlobal(name.cast<ASTName>()->name());
|
2009-07-27 03:23:56 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::STORE_NAME_A:
|
2009-07-27 08:42:59 +00:00
|
|
|
{
|
2011-01-08 16:19:38 -08:00
|
|
|
if (unpack) {
|
|
|
|
PycRef<ASTNode> name = new ASTName(code->getName(operand));
|
|
|
|
|
|
|
|
PycRef<ASTNode> tup = stack.top();
|
2019-10-04 16:16:10 -07:00
|
|
|
if (tup.type() == ASTNode::NODE_TUPLE)
|
|
|
|
tup.cast<ASTTuple>()->add(name);
|
|
|
|
else
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("Something TERRIBLE happened!\n", stderr);
|
2011-01-08 16:19:38 -08:00
|
|
|
|
|
|
|
if (--unpack <= 0) {
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> seq = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
2011-09-22 22:08:18 -07:00
|
|
|
if (curblock->blktype() == ASTBlock::BLK_FOR
|
|
|
|
&& !curblock->inited()) {
|
2019-10-04 14:08:47 -07:00
|
|
|
PycRef<ASTTuple> tuple = tup.cast<ASTTuple>();
|
|
|
|
if (tuple != NULL)
|
|
|
|
tuple->setRequireParens(false);
|
2011-09-22 22:08:18 -07:00
|
|
|
curblock.cast<ASTIterBlock>()->setIndex(tup);
|
|
|
|
} else {
|
|
|
|
curblock->append(new ASTStore(seq, tup));
|
|
|
|
}
|
2011-01-08 16:19:38 -08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
PycRef<ASTNode> value = stack.top();
|
|
|
|
stack.pop();
|
2011-01-10 12:54:17 -08:00
|
|
|
|
2011-10-10 15:57:20 -07:00
|
|
|
PycRef<PycString> varname = code->getName(operand);
|
2018-01-28 14:33:26 -08:00
|
|
|
if (varname->length() >= 2 && varname->value()[0] == '_'
|
|
|
|
&& varname->value()[1] == '[') {
|
2011-10-10 15:57:20 -07:00
|
|
|
/* Don't show stores of list comp append objects. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
PycRef<ASTNode> name = new ASTName(varname);
|
2011-09-18 22:30:27 -07:00
|
|
|
|
|
|
|
if (curblock->blktype() == ASTBlock::BLK_FOR
|
2011-09-18 23:55:27 -07:00
|
|
|
&& !curblock->inited()) {
|
2011-09-18 22:30:27 -07:00
|
|
|
curblock.cast<ASTIterBlock>()->setIndex(name);
|
2017-07-05 16:36:04 -07:00
|
|
|
} else if (stack.top().type() == ASTNode::NODE_IMPORT) {
|
2011-09-20 22:36:15 -07:00
|
|
|
PycRef<ASTImport> import = stack.top().cast<ASTImport>();
|
|
|
|
|
|
|
|
import->add_store(new ASTStore(value, name));
|
2012-06-03 20:39:45 -07:00
|
|
|
} else if (curblock->blktype() == ASTBlock::BLK_WITH
|
|
|
|
&& !curblock->inited()) {
|
|
|
|
curblock.cast<ASTWithBlock>()->setExpr(value);
|
|
|
|
curblock.cast<ASTWithBlock>()->setVar(name);
|
2011-09-18 22:30:27 -07:00
|
|
|
} else {
|
|
|
|
curblock->append(new ASTStore(value, name));
|
|
|
|
|
2017-07-05 16:36:04 -07:00
|
|
|
if (value.type() == ASTNode::NODE_INVALID)
|
2011-09-18 22:30:27 -07:00
|
|
|
break;
|
|
|
|
}
|
2011-01-08 16:19:38 -08:00
|
|
|
}
|
2009-07-27 08:42:59 +00:00
|
|
|
}
|
|
|
|
break;
|
2011-01-05 22:15:22 -08:00
|
|
|
case Pyc::STORE_SLICE_0:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> dest = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> value = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
|
|
|
curblock->append(new ASTStore(value, new ASTSubscr(dest, new ASTSlice(ASTSlice::SLICE0))));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Pyc::STORE_SLICE_1:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> upper = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> dest = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> value = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
|
|
|
curblock->append(new ASTStore(value, new ASTSubscr(dest, new ASTSlice(ASTSlice::SLICE1, upper))));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Pyc::STORE_SLICE_2:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> lower = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> dest = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> value = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
2017-07-05 16:36:04 -07:00
|
|
|
curblock->append(new ASTStore(value, new ASTSubscr(dest, new ASTSlice(ASTSlice::SLICE2, NULL, lower))));
|
2011-01-05 22:15:22 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Pyc::STORE_SLICE_3:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> lower = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> upper = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> dest = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> value = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
|
|
|
curblock->append(new ASTStore(value, new ASTSubscr(dest, new ASTSlice(ASTSlice::SLICE3, upper, lower))));
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::STORE_SUBSCR:
|
2009-07-27 08:42:59 +00:00
|
|
|
{
|
2011-10-16 21:21:48 -07:00
|
|
|
if (unpack) {
|
|
|
|
PycRef<ASTNode> subscr = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> dest = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
|
|
|
PycRef<ASTNode> save = new ASTSubscr(dest, subscr);
|
|
|
|
|
|
|
|
PycRef<ASTNode> tup = stack.top();
|
2019-10-04 16:16:10 -07:00
|
|
|
if (tup.type() == ASTNode::NODE_TUPLE)
|
|
|
|
tup.cast<ASTTuple>()->add(save);
|
|
|
|
else
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("Something TERRIBLE happened!\n", stderr);
|
2011-10-16 21:21:48 -07:00
|
|
|
|
|
|
|
if (--unpack <= 0) {
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> seq = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
|
|
|
curblock->append(new ASTStore(seq, tup));
|
|
|
|
}
|
2009-07-27 08:42:59 +00:00
|
|
|
} else {
|
2011-10-16 21:21:48 -07:00
|
|
|
PycRef<ASTNode> subscr = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> dest = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
PycRef<ASTNode> src = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
|
2017-07-05 16:36:04 -07:00
|
|
|
if (dest.type() == ASTNode::NODE_MAP) {
|
2011-10-16 21:21:48 -07:00
|
|
|
dest.cast<ASTMap>()->add(subscr, src);
|
|
|
|
} else {
|
|
|
|
curblock->append(new ASTStore(src, new ASTSubscr(dest, subscr)));
|
|
|
|
}
|
2009-07-27 08:42:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::UNARY_CALL:
|
2010-09-03 21:50:35 -07:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> func = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTCall(func, ASTCall::pparam_t(), ASTCall::kwparam_t()));
|
|
|
|
}
|
|
|
|
break;
|
2011-01-01 02:31:31 -08:00
|
|
|
case Pyc::UNARY_CONVERT:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> name = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTConvert(name));
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::UNARY_INVERT:
|
2009-08-03 23:13:50 +00:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> arg = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTUnary(arg, ASTUnary::UN_INVERT));
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::UNARY_NEGATIVE:
|
2009-08-03 23:13:50 +00:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> arg = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTUnary(arg, ASTUnary::UN_NEGATIVE));
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::UNARY_NOT:
|
2009-08-03 23:13:50 +00:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> arg = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTUnary(arg, ASTUnary::UN_NOT));
|
|
|
|
}
|
|
|
|
break;
|
2010-09-04 01:20:41 -07:00
|
|
|
case Pyc::UNARY_POSITIVE:
|
2009-08-03 23:13:50 +00:00
|
|
|
{
|
|
|
|
PycRef<ASTNode> arg = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
stack.push(new ASTUnary(arg, ASTUnary::UN_POSITIVE));
|
|
|
|
}
|
|
|
|
break;
|
2011-01-10 12:54:17 -08:00
|
|
|
case Pyc::UNPACK_LIST_A:
|
|
|
|
case Pyc::UNPACK_TUPLE_A:
|
2011-01-08 16:19:38 -08:00
|
|
|
case Pyc::UNPACK_SEQUENCE_A:
|
|
|
|
{
|
|
|
|
unpack = operand;
|
|
|
|
|
|
|
|
ASTTuple::value_t vals;
|
|
|
|
|
|
|
|
stack.push(new ASTTuple(vals));
|
|
|
|
}
|
|
|
|
break;
|
2011-09-18 22:31:09 -07:00
|
|
|
case Pyc::YIELD_VALUE:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> value = stack.top();
|
|
|
|
stack.pop();
|
|
|
|
curblock->append(new ASTReturn(value, ASTReturn::YIELD));
|
|
|
|
}
|
|
|
|
break;
|
2009-07-26 10:07:13 +00:00
|
|
|
default:
|
2010-09-07 21:32:34 -07:00
|
|
|
fprintf(stderr, "Unsupported opcode: %s\n", Pyc::OpcodeName(opcode & 0xFF));
|
2009-07-27 00:30:31 +00:00
|
|
|
cleanBuild = false;
|
2010-12-21 23:41:56 -08:00
|
|
|
return new ASTNodeList(defblock->nodes());
|
2009-07-26 10:07:13 +00:00
|
|
|
}
|
2010-09-04 23:51:22 -07:00
|
|
|
|
2011-10-10 00:15:25 -07:00
|
|
|
else_pop = ( (curblock->blktype() == ASTBlock::BLK_ELSE)
|
|
|
|
|| (curblock->blktype() == ASTBlock::BLK_IF)
|
|
|
|
|| (curblock->blktype() == ASTBlock::BLK_ELIF) )
|
|
|
|
&& (curblock->end() == pos);
|
2010-12-30 16:48:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (stack_hist.size()) {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("Warning: Stack history is not empty!\n", stderr);
|
2010-12-30 16:48:59 -08:00
|
|
|
|
|
|
|
while (stack_hist.size()) {
|
|
|
|
stack_hist.pop();
|
|
|
|
}
|
2009-07-26 10:07:13 +00:00
|
|
|
}
|
|
|
|
|
2010-12-31 21:45:06 -08:00
|
|
|
if (blocks.size() > 1) {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("Warning: block stack is not empty!\n", stderr);
|
2010-12-31 21:45:06 -08:00
|
|
|
|
|
|
|
while (blocks.size() > 1) {
|
|
|
|
PycRef<ASTBlock> tmp = blocks.top();
|
|
|
|
blocks.pop();
|
|
|
|
|
|
|
|
blocks.top()->append(tmp.cast<ASTNode>());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-27 00:30:31 +00:00
|
|
|
cleanBuild = true;
|
2010-12-21 23:41:56 -08:00
|
|
|
return new ASTNodeList(defblock->nodes());
|
2009-07-26 10:07:13 +00:00
|
|
|
}
|
|
|
|
|
2009-08-03 23:13:50 +00:00
|
|
|
static int cmp_prec(PycRef<ASTNode> parent, PycRef<ASTNode> child)
|
2009-07-26 10:07:13 +00:00
|
|
|
{
|
2009-08-03 23:13:50 +00:00
|
|
|
/* Determine whether the parent has higher precedence than therefore
|
|
|
|
child, so we don't flood the source code with extraneous parens.
|
|
|
|
Else we'd have expressions like (((a + b) + c) + d) when therefore
|
|
|
|
equivalent, a + b + c + d would suffice. */
|
|
|
|
|
2017-07-05 16:36:04 -07:00
|
|
|
if (parent.type() == ASTNode::NODE_UNARY && parent.cast<ASTUnary>()->op() == ASTUnary::UN_NOT)
|
2009-08-03 23:13:50 +00:00
|
|
|
return 1; // Always parenthesize not(x)
|
2017-07-05 16:36:04 -07:00
|
|
|
if (child.type() == ASTNode::NODE_BINARY) {
|
2009-08-03 23:13:50 +00:00
|
|
|
PycRef<ASTBinary> binChild = child.cast<ASTBinary>();
|
2017-07-05 16:36:04 -07:00
|
|
|
if (parent.type() == ASTNode::NODE_BINARY)
|
2009-08-03 23:13:50 +00:00
|
|
|
return binChild->op() - parent.cast<ASTBinary>()->op();
|
2017-07-05 16:36:04 -07:00
|
|
|
else if (parent.type() == ASTNode::NODE_COMPARE)
|
2009-08-03 23:13:50 +00:00
|
|
|
return (binChild->op() == ASTBinary::BIN_LOG_AND ||
|
|
|
|
binChild->op() == ASTBinary::BIN_LOG_OR) ? 1 : -1;
|
2017-07-05 16:36:04 -07:00
|
|
|
else if (parent.type() == ASTNode::NODE_UNARY)
|
2009-08-03 23:13:50 +00:00
|
|
|
return (binChild->op() == ASTBinary::BIN_POWER) ? -1 : 1;
|
2017-07-05 16:36:04 -07:00
|
|
|
} else if (child.type() == ASTNode::NODE_UNARY) {
|
2009-08-03 23:13:50 +00:00
|
|
|
PycRef<ASTUnary> unChild = child.cast<ASTUnary>();
|
2017-07-05 16:36:04 -07:00
|
|
|
if (parent.type() == ASTNode::NODE_BINARY) {
|
2009-08-03 23:13:50 +00:00
|
|
|
PycRef<ASTBinary> binParent = parent.cast<ASTBinary>();
|
|
|
|
if (binParent->op() == ASTBinary::BIN_LOG_AND ||
|
|
|
|
binParent->op() == ASTBinary::BIN_LOG_OR)
|
|
|
|
return -1;
|
|
|
|
else if (unChild->op() == ASTUnary::UN_NOT)
|
|
|
|
return 1;
|
|
|
|
else if (binParent->op() == ASTBinary::BIN_POWER)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return -1;
|
2017-07-05 16:36:04 -07:00
|
|
|
} else if (parent.type() == ASTNode::NODE_COMPARE) {
|
2009-08-03 23:13:50 +00:00
|
|
|
return (unChild->op() == ASTUnary::UN_NOT) ? 1 : -1;
|
2017-07-05 16:36:04 -07:00
|
|
|
} else if (parent.type() == ASTNode::NODE_UNARY) {
|
2009-08-03 23:13:50 +00:00
|
|
|
return unChild->op() - parent.cast<ASTUnary>()->op();
|
|
|
|
}
|
2017-07-05 16:36:04 -07:00
|
|
|
} else if (child.type() == ASTNode::NODE_COMPARE) {
|
2009-08-03 23:13:50 +00:00
|
|
|
PycRef<ASTCompare> cmpChild = child.cast<ASTCompare>();
|
2017-07-05 16:36:04 -07:00
|
|
|
if (parent.type() == ASTNode::NODE_BINARY)
|
2009-08-03 23:13:50 +00:00
|
|
|
return (parent.cast<ASTBinary>()->op() == ASTBinary::BIN_LOG_AND ||
|
|
|
|
parent.cast<ASTBinary>()->op() == ASTBinary::BIN_LOG_OR) ? -1 : 1;
|
2017-07-05 16:36:04 -07:00
|
|
|
else if (parent.type() == ASTNode::NODE_COMPARE)
|
2009-08-03 23:13:50 +00:00
|
|
|
return cmpChild->op() - parent.cast<ASTCompare>()->op();
|
2017-07-05 16:36:04 -07:00
|
|
|
else if (parent.type() == ASTNode::NODE_UNARY)
|
2009-08-03 23:13:50 +00:00
|
|
|
return (parent.cast<ASTUnary>()->op() == ASTUnary::UN_NOT) ? -1 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* For normal nodes, don't parenthesize anything */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_ordered(PycRef<ASTNode> parent, PycRef<ASTNode> child,
|
2010-09-07 21:32:34 -07:00
|
|
|
PycModule* mod)
|
2009-08-03 23:13:50 +00:00
|
|
|
{
|
2017-07-05 16:36:04 -07:00
|
|
|
if (child.type() == ASTNode::NODE_BINARY ||
|
|
|
|
child.type() == ASTNode::NODE_COMPARE) {
|
2009-08-03 23:13:50 +00:00
|
|
|
if (cmp_prec(parent, child) > 0) {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("(", pyc_output);
|
2010-09-07 21:32:34 -07:00
|
|
|
print_src(child, mod);
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(")", pyc_output);
|
2009-08-03 23:13:50 +00:00
|
|
|
} else {
|
2010-09-07 21:32:34 -07:00
|
|
|
print_src(child, mod);
|
2009-08-03 23:13:50 +00:00
|
|
|
}
|
2017-07-05 16:36:04 -07:00
|
|
|
} else if (child.type() == ASTNode::NODE_UNARY) {
|
2009-08-03 23:13:50 +00:00
|
|
|
if (cmp_prec(parent, child) > 0) {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("(", pyc_output);
|
2010-09-07 21:32:34 -07:00
|
|
|
print_src(child, mod);
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(")", pyc_output);
|
2009-08-03 23:13:50 +00:00
|
|
|
} else {
|
2010-09-07 21:32:34 -07:00
|
|
|
print_src(child, mod);
|
2009-08-03 23:13:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
2010-09-07 21:32:34 -07:00
|
|
|
print_src(child, mod);
|
2009-08-03 23:13:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void start_line(int indent)
|
|
|
|
{
|
2019-10-09 14:20:46 -07:00
|
|
|
if (inLambda)
|
2011-09-18 23:55:27 -07:00
|
|
|
return;
|
2009-07-26 10:07:13 +00:00
|
|
|
for (int i=0; i<indent; i++)
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(" ", pyc_output);
|
2009-07-26 10:07:13 +00:00
|
|
|
}
|
|
|
|
|
2009-08-03 23:13:50 +00:00
|
|
|
static void end_line()
|
|
|
|
{
|
2019-10-09 14:20:46 -07:00
|
|
|
if (inLambda)
|
2011-09-18 23:55:27 -07:00
|
|
|
return;
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("\n", pyc_output);
|
2009-08-03 23:13:50 +00:00
|
|
|
}
|
|
|
|
|
2010-09-07 21:32:34 -07:00
|
|
|
int cur_indent = -1;
|
2011-10-01 21:45:20 -07:00
|
|
|
static void print_block(PycRef<ASTBlock> blk, PycModule* mod) {
|
|
|
|
ASTBlock::list_t lines = blk->nodes();
|
|
|
|
|
|
|
|
if (lines.size() == 0) {
|
2019-10-08 13:12:31 -07:00
|
|
|
PycRef<ASTNode> pass = new ASTKeyword(ASTKeyword::KW_PASS);
|
2011-10-01 21:45:20 -07:00
|
|
|
start_line(cur_indent);
|
|
|
|
print_src(pass, mod);
|
|
|
|
}
|
|
|
|
|
2019-10-04 15:56:24 -07:00
|
|
|
for (auto ln = lines.cbegin(); ln != lines.cend();) {
|
2017-07-05 16:36:04 -07:00
|
|
|
if ((*ln).cast<ASTNode>().type() != ASTNode::NODE_NODELIST) {
|
2011-10-01 21:45:20 -07:00
|
|
|
start_line(cur_indent);
|
|
|
|
}
|
|
|
|
print_src(*ln, mod);
|
|
|
|
if (++ln != lines.end()) {
|
|
|
|
end_line();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-07 21:32:34 -07:00
|
|
|
void print_src(PycRef<ASTNode> node, PycModule* mod)
|
2009-07-26 10:07:13 +00:00
|
|
|
{
|
2017-07-05 16:36:04 -07:00
|
|
|
if (node == NULL) {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("None", pyc_output);
|
2011-09-22 22:38:43 -07:00
|
|
|
cleanBuild = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-07-26 10:07:13 +00:00
|
|
|
switch (node->type()) {
|
2009-07-27 00:23:49 +00:00
|
|
|
case ASTNode::NODE_BINARY:
|
|
|
|
case ASTNode::NODE_COMPARE:
|
|
|
|
{
|
|
|
|
PycRef<ASTBinary> bin = node.cast<ASTBinary>();
|
2010-09-07 21:32:34 -07:00
|
|
|
print_ordered(node, bin->left(), mod);
|
2011-10-23 19:04:06 -07:00
|
|
|
fprintf(pyc_output, "%s", bin->op_str());
|
2010-09-07 21:32:34 -07:00
|
|
|
print_ordered(node, bin->right(), mod);
|
2010-08-31 23:17:38 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ASTNode::NODE_UNARY:
|
|
|
|
{
|
|
|
|
PycRef<ASTUnary> un = node.cast<ASTUnary>();
|
2011-10-23 19:04:06 -07:00
|
|
|
fprintf(pyc_output, "%s", un->op_str());
|
2010-09-07 21:32:34 -07:00
|
|
|
print_ordered(node, un->operand(), mod);
|
2009-07-27 00:23:49 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ASTNode::NODE_CALL:
|
|
|
|
{
|
|
|
|
PycRef<ASTCall> call = node.cast<ASTCall>();
|
2010-09-07 21:32:34 -07:00
|
|
|
print_src(call->func(), mod);
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("(", pyc_output);
|
2009-07-27 00:23:49 +00:00
|
|
|
bool first = true;
|
2019-10-04 15:56:24 -07:00
|
|
|
for (const auto& param : call->pparams()) {
|
2011-09-18 23:55:27 -07:00
|
|
|
if (!first)
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(", ", pyc_output);
|
2019-10-04 15:56:24 -07:00
|
|
|
print_src(param, mod);
|
2009-07-27 00:23:49 +00:00
|
|
|
first = false;
|
|
|
|
}
|
2019-10-04 15:56:24 -07:00
|
|
|
for (const auto& param : call->kwparams()) {
|
2011-09-18 23:55:27 -07:00
|
|
|
if (!first)
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(", ", pyc_output);
|
2019-10-04 15:56:24 -07:00
|
|
|
if (param.first.type() == ASTNode::NODE_NAME) {
|
|
|
|
fprintf(pyc_output, "%s = ", param.first.cast<ASTName>()->name()->value());
|
2018-01-28 14:33:26 -08:00
|
|
|
} else {
|
2019-10-04 15:56:24 -07:00
|
|
|
PycRef<PycString> str_name = param.first.cast<ASTObject>()->object().require_cast<PycString>();
|
2018-01-28 14:33:26 -08:00
|
|
|
fprintf(pyc_output, "%s = ", str_name->value());
|
|
|
|
}
|
2019-10-04 15:56:24 -07:00
|
|
|
print_src(param.second, mod);
|
2009-07-27 00:23:49 +00:00
|
|
|
first = false;
|
|
|
|
}
|
2011-10-09 22:38:18 -07:00
|
|
|
if (call->hasVar()) {
|
|
|
|
if (!first)
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(", ", pyc_output);
|
|
|
|
fputs("*", pyc_output);
|
2011-10-09 22:38:18 -07:00
|
|
|
print_src(call->var(), mod);
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
if (call->hasKW()) {
|
|
|
|
if (!first)
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(", ", pyc_output);
|
|
|
|
fputs("**", pyc_output);
|
2019-10-08 11:44:52 -07:00
|
|
|
print_src(call->kw(), mod);
|
2011-10-09 22:38:18 -07:00
|
|
|
first = false;
|
|
|
|
}
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(")", pyc_output);
|
2009-07-27 00:23:49 +00:00
|
|
|
}
|
|
|
|
break;
|
2011-01-05 10:52:57 -08:00
|
|
|
case ASTNode::NODE_DELETE:
|
|
|
|
{
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("del ", pyc_output);
|
2011-01-05 10:52:57 -08:00
|
|
|
print_src(node.cast<ASTDelete>()->value(), mod);
|
|
|
|
}
|
|
|
|
break;
|
2011-01-10 13:15:56 -08:00
|
|
|
case ASTNode::NODE_EXEC:
|
|
|
|
{
|
|
|
|
PycRef<ASTExec> exec = node.cast<ASTExec>();
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("exec ", pyc_output);
|
2011-01-10 13:15:56 -08:00
|
|
|
print_src(exec->statement(), mod);
|
|
|
|
|
2017-07-05 16:36:04 -07:00
|
|
|
if (exec->globals() != NULL) {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(" in ", pyc_output);
|
2011-01-10 13:15:56 -08:00
|
|
|
print_src(exec->globals(), mod);
|
|
|
|
|
2017-07-05 16:36:04 -07:00
|
|
|
if (exec->locals() != NULL
|
2011-09-18 23:55:27 -07:00
|
|
|
&& exec->globals() != exec->locals()) {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(", ", pyc_output);
|
2011-01-10 13:15:56 -08:00
|
|
|
print_src(exec->locals(), mod);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2011-01-01 02:31:31 -08:00
|
|
|
case ASTNode::NODE_KEYWORD:
|
2011-10-23 19:04:06 -07:00
|
|
|
fprintf(pyc_output, "%s", node.cast<ASTKeyword>()->word_str());
|
2011-01-01 02:31:31 -08:00
|
|
|
break;
|
2009-07-26 10:07:13 +00:00
|
|
|
case ASTNode::NODE_LIST:
|
2009-07-27 08:42:59 +00:00
|
|
|
{
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("[", pyc_output);
|
2009-07-27 08:42:59 +00:00
|
|
|
bool first = true;
|
2010-09-07 21:32:34 -07:00
|
|
|
cur_indent++;
|
2019-10-04 15:56:24 -07:00
|
|
|
for (const auto& val : node.cast<ASTList>()->values()) {
|
2011-09-18 23:55:27 -07:00
|
|
|
if (first)
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("\n", pyc_output);
|
2011-09-18 23:55:27 -07:00
|
|
|
else
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(",\n", pyc_output);
|
2010-09-07 21:32:34 -07:00
|
|
|
start_line(cur_indent);
|
2019-10-04 15:56:24 -07:00
|
|
|
print_src(val, mod);
|
2009-07-27 08:42:59 +00:00
|
|
|
first = false;
|
|
|
|
}
|
2010-09-07 21:32:34 -07:00
|
|
|
cur_indent--;
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("]", pyc_output);
|
2009-07-27 08:42:59 +00:00
|
|
|
}
|
|
|
|
break;
|
2011-10-10 15:57:20 -07:00
|
|
|
case ASTNode::NODE_COMPREHENSION:
|
|
|
|
{
|
|
|
|
PycRef<ASTComprehension> comp = node.cast<ASTComprehension>();
|
|
|
|
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("[ ", pyc_output);
|
2011-10-10 15:57:20 -07:00
|
|
|
print_src(comp->result(), mod);
|
|
|
|
|
2019-10-04 15:56:24 -07:00
|
|
|
for (const auto& gen : comp->generators()) {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(" for ", pyc_output);
|
2019-10-04 15:56:24 -07:00
|
|
|
print_src(gen->index(), mod);
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(" in ", pyc_output);
|
2019-10-04 15:56:24 -07:00
|
|
|
print_src(gen->iter(), mod);
|
2019-10-04 16:35:58 -07:00
|
|
|
if (gen->condition()) {
|
|
|
|
fprintf(pyc_output, " if ");
|
|
|
|
print_src(gen->condition(), mod);
|
|
|
|
}
|
2011-10-10 15:57:20 -07:00
|
|
|
}
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(" ]", pyc_output);
|
2011-10-10 15:57:20 -07:00
|
|
|
}
|
|
|
|
break;
|
2009-07-27 08:42:59 +00:00
|
|
|
case ASTNode::NODE_MAP:
|
|
|
|
{
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("{", pyc_output);
|
2009-07-27 08:42:59 +00:00
|
|
|
bool first = true;
|
2010-09-07 21:32:34 -07:00
|
|
|
cur_indent++;
|
2019-10-04 15:56:24 -07:00
|
|
|
for (const auto& val : node.cast<ASTMap>()->values()) {
|
2011-09-18 23:55:27 -07:00
|
|
|
if (first)
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("\n", pyc_output);
|
2011-09-18 23:55:27 -07:00
|
|
|
else
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(",\n", pyc_output);
|
2010-09-07 21:32:34 -07:00
|
|
|
start_line(cur_indent);
|
2019-10-04 15:56:24 -07:00
|
|
|
print_src(val.first, mod);
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(": ", pyc_output);
|
2019-10-04 15:56:24 -07:00
|
|
|
print_src(val.second, mod);
|
2009-07-27 08:42:59 +00:00
|
|
|
first = false;
|
|
|
|
}
|
2010-09-07 21:32:34 -07:00
|
|
|
cur_indent--;
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(" }", pyc_output);
|
2009-07-27 08:42:59 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ASTNode::NODE_NAME:
|
2011-10-23 19:04:06 -07:00
|
|
|
fprintf(pyc_output, "%s", node.cast<ASTName>()->name()->value());
|
2009-07-27 08:42:59 +00:00
|
|
|
break;
|
|
|
|
case ASTNode::NODE_NODELIST:
|
2009-07-26 10:07:13 +00:00
|
|
|
{
|
2010-09-07 21:32:34 -07:00
|
|
|
cur_indent++;
|
2019-10-04 15:56:24 -07:00
|
|
|
for (const auto& ln : node.cast<ASTNodeList>()->nodes()) {
|
|
|
|
if (ln.cast<ASTNode>().type() != ASTNode::NODE_NODELIST) {
|
2010-09-07 21:32:34 -07:00
|
|
|
start_line(cur_indent);
|
|
|
|
}
|
2019-10-04 15:56:24 -07:00
|
|
|
print_src(ln, mod);
|
2010-12-21 23:41:56 -08:00
|
|
|
end_line();
|
|
|
|
}
|
|
|
|
cur_indent--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ASTNode::NODE_BLOCK:
|
|
|
|
{
|
2011-01-04 15:40:00 -08:00
|
|
|
if (node.cast<ASTBlock>()->blktype() == ASTBlock::BLK_ELSE
|
|
|
|
&& node.cast<ASTBlock>()->size() == 0)
|
|
|
|
break;
|
|
|
|
|
2011-10-01 19:40:34 -07:00
|
|
|
if (node.cast<ASTBlock>()->blktype() == ASTBlock::BLK_CONTAINER) {
|
|
|
|
end_line();
|
|
|
|
PycRef<ASTBlock> blk = node.cast<ASTBlock>();
|
2011-10-01 21:45:20 -07:00
|
|
|
print_block(blk, mod);
|
2011-10-01 19:40:34 -07:00
|
|
|
end_line();
|
|
|
|
break;
|
|
|
|
}
|
2011-09-18 22:32:00 -07:00
|
|
|
|
2011-10-23 19:04:06 -07:00
|
|
|
fprintf(pyc_output, "%s", node.cast<ASTBlock>()->type_str());
|
2010-12-31 02:42:58 -08:00
|
|
|
PycRef<ASTBlock> blk = node.cast<ASTBlock>();
|
|
|
|
if (blk->blktype() == ASTBlock::BLK_IF
|
|
|
|
|| blk->blktype() == ASTBlock::BLK_ELIF
|
2011-09-18 23:55:27 -07:00
|
|
|
|| blk->blktype() == ASTBlock::BLK_WHILE) {
|
2010-12-31 02:42:58 -08:00
|
|
|
if (blk.cast<ASTCondBlock>()->negative())
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(" not ", pyc_output);
|
2010-12-24 20:25:55 -08:00
|
|
|
else
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(" ", pyc_output);
|
2010-12-24 20:25:55 -08:00
|
|
|
|
2010-12-31 02:42:58 -08:00
|
|
|
print_src(blk.cast<ASTCondBlock>()->cond(), mod);
|
2011-09-18 23:55:27 -07:00
|
|
|
} else if (blk->blktype() == ASTBlock::BLK_FOR) {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(" ", pyc_output);
|
2011-01-02 04:24:32 -08:00
|
|
|
print_src(blk.cast<ASTIterBlock>()->index(), mod);
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(" in ", pyc_output);
|
2011-01-02 04:24:32 -08:00
|
|
|
print_src(blk.cast<ASTIterBlock>()->iter(), mod);
|
2011-10-01 21:05:33 -07:00
|
|
|
} else if (blk->blktype() == ASTBlock::BLK_EXCEPT &&
|
2017-07-05 16:36:04 -07:00
|
|
|
blk.cast<ASTCondBlock>()->cond() != NULL) {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(" ", pyc_output);
|
2011-01-04 13:52:15 -08:00
|
|
|
print_src(blk.cast<ASTCondBlock>()->cond(), mod);
|
2012-06-03 20:39:45 -07:00
|
|
|
} else if (blk->blktype() == ASTBlock::BLK_WITH) {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(" ", pyc_output);
|
2012-06-03 20:39:45 -07:00
|
|
|
print_src(blk.cast<ASTWithBlock>()->expr(), mod);
|
|
|
|
PycRef<ASTNode> var = blk.cast<ASTWithBlock>()->var();
|
2017-07-05 16:36:04 -07:00
|
|
|
if (var != NULL) {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(" as ", pyc_output);
|
2012-06-03 20:39:45 -07:00
|
|
|
print_src(var, mod);
|
|
|
|
}
|
2011-01-04 13:52:15 -08:00
|
|
|
}
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(":\n", pyc_output);
|
2010-12-24 20:25:55 -08:00
|
|
|
|
2010-12-21 23:41:56 -08:00
|
|
|
cur_indent++;
|
2011-10-01 21:45:20 -07:00
|
|
|
print_block(blk, mod);
|
2010-09-07 21:32:34 -07:00
|
|
|
cur_indent--;
|
2009-07-26 10:07:13 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-07-27 08:42:59 +00:00
|
|
|
case ASTNode::NODE_OBJECT:
|
|
|
|
{
|
|
|
|
PycRef<PycObject> obj = node.cast<ASTObject>()->object();
|
2017-07-05 16:36:04 -07:00
|
|
|
if (obj.type() == PycObject::TYPE_CODE) {
|
2011-10-09 23:42:34 -07:00
|
|
|
PycRef<PycCode> code = obj.cast<PycCode>();
|
|
|
|
decompyle(code, mod);
|
|
|
|
} else {
|
2009-07-27 08:42:59 +00:00
|
|
|
print_const(obj, mod);
|
2011-10-09 23:42:34 -07:00
|
|
|
}
|
2009-07-27 08:42:59 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-08-03 23:13:50 +00:00
|
|
|
case ASTNode::NODE_PRINT:
|
2019-10-09 14:20:46 -07:00
|
|
|
{
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("print ", pyc_output);
|
2019-10-09 14:20:46 -07:00
|
|
|
bool first = true;
|
|
|
|
if (node.cast<ASTPrint>()->stream() != nullptr) {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(">>", pyc_output);
|
2011-09-18 00:35:28 -07:00
|
|
|
print_src(node.cast<ASTPrint>()->stream(), mod);
|
2019-10-09 14:20:46 -07:00
|
|
|
first = false;
|
2011-09-18 00:35:28 -07:00
|
|
|
}
|
2019-10-09 14:20:46 -07:00
|
|
|
|
|
|
|
for (const auto& val : node.cast<ASTPrint>()->values()) {
|
|
|
|
if (!first)
|
|
|
|
fputs(", ", pyc_output);
|
|
|
|
print_src(val, mod);
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
if (!node.cast<ASTPrint>()->eol())
|
|
|
|
fputs(",", pyc_output);
|
2009-08-03 23:13:50 +00:00
|
|
|
}
|
|
|
|
break;
|
2011-01-01 02:31:31 -08:00
|
|
|
case ASTNode::NODE_RAISE:
|
|
|
|
{
|
|
|
|
PycRef<ASTRaise> raise = node.cast<ASTRaise>();
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("raise ", pyc_output);
|
2011-01-01 02:31:31 -08:00
|
|
|
bool first = true;
|
2019-10-04 15:56:24 -07:00
|
|
|
for (const auto& param : raise->params()) {
|
2011-09-18 23:55:27 -07:00
|
|
|
if (!first)
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(", ", pyc_output);
|
2019-10-04 15:56:24 -07:00
|
|
|
print_src(param, mod);
|
2011-01-01 02:31:31 -08:00
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-07-27 08:42:59 +00:00
|
|
|
case ASTNode::NODE_RETURN:
|
2011-09-18 22:31:09 -07:00
|
|
|
{
|
|
|
|
PycRef<ASTReturn> ret = node.cast<ASTReturn>();
|
2011-10-22 14:06:14 -07:00
|
|
|
if (!inLambda) {
|
|
|
|
switch (ret->rettype()) {
|
|
|
|
case ASTReturn::RETURN:
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("return ", pyc_output);
|
2011-10-22 14:06:14 -07:00
|
|
|
break;
|
|
|
|
case ASTReturn::YIELD:
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("yield ", pyc_output);
|
2011-10-22 14:06:14 -07:00
|
|
|
break;
|
|
|
|
}
|
2011-09-18 22:31:09 -07:00
|
|
|
}
|
|
|
|
print_src(ret->value(), mod);
|
|
|
|
}
|
2009-07-27 08:42:59 +00:00
|
|
|
break;
|
2011-01-04 13:52:15 -08:00
|
|
|
case ASTNode::NODE_SLICE:
|
|
|
|
{
|
|
|
|
PycRef<ASTSlice> slice = node.cast<ASTSlice>();
|
|
|
|
|
|
|
|
if (slice->op() & ASTSlice::SLICE1) {
|
|
|
|
print_src(slice->left(), mod);
|
|
|
|
}
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(":", pyc_output);
|
2011-01-04 13:52:15 -08:00
|
|
|
if (slice->op() & ASTSlice::SLICE2) {
|
|
|
|
print_src(slice->right(), mod);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2011-09-20 22:36:15 -07:00
|
|
|
case ASTNode::NODE_IMPORT:
|
|
|
|
{
|
|
|
|
PycRef<ASTImport> import = node.cast<ASTImport>();
|
|
|
|
if (import->stores().size()) {
|
|
|
|
ASTImport::list_t stores = import->stores();
|
|
|
|
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("from ", pyc_output);
|
2017-07-05 16:36:04 -07:00
|
|
|
if (import->name().type() == ASTNode::NODE_IMPORT)
|
2011-09-20 22:36:15 -07:00
|
|
|
print_src(import->name().cast<ASTImport>()->name(), mod);
|
|
|
|
else
|
|
|
|
print_src(import->name(), mod);
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(" import ", pyc_output);
|
2011-09-20 22:36:15 -07:00
|
|
|
|
|
|
|
if (stores.size() == 1) {
|
2019-10-04 15:56:24 -07:00
|
|
|
auto src = stores.front()->src();
|
|
|
|
auto dest = stores.front()->dest();
|
|
|
|
print_src(src, mod);
|
2011-09-20 22:36:15 -07:00
|
|
|
|
2019-10-04 15:56:24 -07:00
|
|
|
if (src.cast<ASTName>()->name()->value() != dest.cast<ASTName>()->name()->value()) {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(" as ", pyc_output);
|
2019-10-04 15:56:24 -07:00
|
|
|
print_src(dest, mod);
|
2011-09-20 22:36:15 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bool first = true;
|
2019-10-04 15:56:24 -07:00
|
|
|
for (const auto& st : stores) {
|
2011-09-20 22:36:15 -07:00
|
|
|
if (!first)
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(", ", pyc_output);
|
2019-10-04 15:56:24 -07:00
|
|
|
print_src(st->src(), mod);
|
2011-09-20 22:36:15 -07:00
|
|
|
first = false;
|
|
|
|
|
2019-10-04 15:56:24 -07:00
|
|
|
if (st->src().cast<ASTName>()->name()->value() != st->dest().cast<ASTName>()->name()->value()) {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(" as ", pyc_output);
|
2019-10-04 15:56:24 -07:00
|
|
|
print_src(st->dest(), mod);
|
2011-09-20 22:36:15 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("import ", pyc_output);
|
2011-09-20 22:36:15 -07:00
|
|
|
print_src(import->name(), mod);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2011-09-18 00:37:33 -07:00
|
|
|
case ASTNode::NODE_FUNCTION:
|
|
|
|
{
|
|
|
|
/* Actual named functions are NODE_STORE with a name */
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("(lambda ", pyc_output);
|
2011-09-18 00:37:33 -07:00
|
|
|
PycRef<ASTNode> code = node.cast<ASTFunction>()->code();
|
|
|
|
PycRef<PycCode> code_src = code.cast<ASTObject>()->object().cast<PycCode>();
|
|
|
|
ASTFunction::defarg_t defargs = node.cast<ASTFunction>()->defargs();
|
2019-10-08 11:36:12 -07:00
|
|
|
ASTFunction::defarg_t kwdefargs = node.cast<ASTFunction>()->kwdefargs();
|
2019-10-04 15:56:24 -07:00
|
|
|
auto da = defargs.cbegin();
|
2019-10-08 11:36:12 -07:00
|
|
|
int narg = 0;
|
2011-09-18 00:37:33 -07:00
|
|
|
for (int i=0; i<code_src->argCount(); i++) {
|
2019-10-08 11:36:12 -07:00
|
|
|
if (narg)
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(", ", pyc_output);
|
2019-10-08 11:36:12 -07:00
|
|
|
fprintf(pyc_output, "%s", code_src->getVarName(narg++)->value());
|
2011-09-18 00:37:33 -07:00
|
|
|
if ((code_src->argCount() - i) <= (int)defargs.size()) {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(" = ", pyc_output);
|
2011-09-18 00:37:33 -07:00
|
|
|
print_src(*da++, mod);
|
|
|
|
}
|
|
|
|
}
|
2019-10-08 11:36:12 -07:00
|
|
|
da = kwdefargs.cbegin();
|
|
|
|
if (code_src->kwOnlyArgCount() != 0) {
|
|
|
|
fputs(narg == 0 ? "*" : ", *", pyc_output);
|
|
|
|
for (int i = 0; i < code_src->argCount(); i++) {
|
|
|
|
fputs(", ", pyc_output);
|
|
|
|
fprintf(pyc_output, "%s", code_src->getVarName(narg++)->value());
|
|
|
|
if ((code_src->kwOnlyArgCount() - i) <= (int)kwdefargs.size()) {
|
|
|
|
fputs(" = ", pyc_output);
|
|
|
|
print_src(*da++, mod);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(": ", pyc_output);
|
2011-10-22 14:06:14 -07:00
|
|
|
|
|
|
|
inLambda = true;
|
2011-09-18 00:37:33 -07:00
|
|
|
print_src(code, mod);
|
2011-10-22 14:06:14 -07:00
|
|
|
inLambda = false;
|
2016-07-09 15:20:39 +00:00
|
|
|
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(")", pyc_output);
|
2011-09-18 00:37:33 -07:00
|
|
|
}
|
|
|
|
break;
|
2009-07-26 10:07:13 +00:00
|
|
|
case ASTNode::NODE_STORE:
|
|
|
|
{
|
|
|
|
PycRef<ASTNode> src = node.cast<ASTStore>()->src();
|
|
|
|
PycRef<ASTNode> dest = node.cast<ASTStore>()->dest();
|
2017-07-05 16:36:04 -07:00
|
|
|
if (src.type() == ASTNode::NODE_FUNCTION) {
|
2009-07-27 00:23:49 +00:00
|
|
|
PycRef<ASTNode> code = src.cast<ASTFunction>()->code();
|
|
|
|
PycRef<PycCode> code_src = code.cast<ASTObject>()->object().cast<PycCode>();
|
2013-06-28 23:22:25 -07:00
|
|
|
bool isLambda = false;
|
|
|
|
|
2013-06-29 00:22:59 -07:00
|
|
|
if (strcmp(code_src->name()->value(), "<lambda>") == 0) {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("\n", pyc_output);
|
2013-06-28 23:22:25 -07:00
|
|
|
start_line(cur_indent);
|
|
|
|
print_src(dest, mod);
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(" = lambda ", pyc_output);
|
2013-06-28 23:22:25 -07:00
|
|
|
isLambda = true;
|
|
|
|
} else {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("\n", pyc_output);
|
2013-06-28 23:22:25 -07:00
|
|
|
start_line(cur_indent);
|
2015-11-13 15:22:19 -08:00
|
|
|
if (code_src->flags() & PycCode::CO_COROUTINE)
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("async ", pyc_output);
|
|
|
|
fputs("def ", pyc_output);
|
2013-06-28 23:22:25 -07:00
|
|
|
print_src(dest, mod);
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("(", pyc_output);
|
2013-06-28 23:22:25 -07:00
|
|
|
}
|
|
|
|
|
2009-07-27 08:42:59 +00:00
|
|
|
ASTFunction::defarg_t defargs = src.cast<ASTFunction>()->defargs();
|
2019-10-08 11:36:12 -07:00
|
|
|
ASTFunction::defarg_t kwdefargs = src.cast<ASTFunction>()->kwdefargs();
|
2019-10-04 15:56:24 -07:00
|
|
|
auto da = defargs.cbegin();
|
2019-10-08 11:36:12 -07:00
|
|
|
int narg = 0;
|
|
|
|
for (int i = 0; i < code_src->argCount(); ++i) {
|
|
|
|
if (narg)
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(", ", pyc_output);
|
2019-10-08 11:36:12 -07:00
|
|
|
fprintf(pyc_output, "%s", code_src->getVarName(narg++)->value());
|
2009-07-27 08:42:59 +00:00
|
|
|
if ((code_src->argCount() - i) <= (int)defargs.size()) {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(" = ", pyc_output);
|
2010-09-07 21:32:34 -07:00
|
|
|
print_src(*da++, mod);
|
2009-07-27 08:42:59 +00:00
|
|
|
}
|
2019-10-08 11:36:12 -07:00
|
|
|
}
|
|
|
|
da = kwdefargs.cbegin();
|
|
|
|
if (code_src->kwOnlyArgCount() != 0) {
|
|
|
|
fputs(narg == 0 ? "*" : ", *", pyc_output);
|
|
|
|
for (int i = 0; i < code_src->kwOnlyArgCount(); ++i) {
|
|
|
|
fputs(", ", pyc_output);
|
|
|
|
fprintf(pyc_output, "%s", code_src->getVarName(narg++)->value());
|
|
|
|
if ((code_src->kwOnlyArgCount() - i) <= (int)kwdefargs.size()) {
|
|
|
|
fputs(" = ", pyc_output);
|
|
|
|
print_src(*da++, mod);
|
|
|
|
}
|
|
|
|
}
|
2011-10-09 22:38:18 -07:00
|
|
|
}
|
|
|
|
if (code_src->flags() & PycCode::CO_VARARGS) {
|
2019-10-08 11:36:12 -07:00
|
|
|
if (narg)
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(", ", pyc_output);
|
2019-10-08 11:36:12 -07:00
|
|
|
fprintf(pyc_output, "*%s", code_src->getVarName(narg++)->value());
|
2011-10-09 22:38:18 -07:00
|
|
|
}
|
|
|
|
if (code_src->flags() & PycCode::CO_VARKEYWORDS) {
|
2019-10-08 11:36:12 -07:00
|
|
|
if (narg)
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(", ", pyc_output);
|
2011-10-09 22:38:18 -07:00
|
|
|
|
|
|
|
int idx = code_src->argCount();
|
|
|
|
if (code_src->flags() & PycCode::CO_VARARGS) {
|
|
|
|
idx++;
|
|
|
|
}
|
2019-10-08 11:36:12 -07:00
|
|
|
fprintf(pyc_output, "**%s", code_src->getVarName(narg++)->value());
|
2009-07-27 00:23:49 +00:00
|
|
|
}
|
2013-06-28 23:22:25 -07:00
|
|
|
|
|
|
|
if (isLambda) {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(": ", pyc_output);
|
2013-06-28 23:22:25 -07:00
|
|
|
} else {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("):\n", pyc_output);
|
2015-01-28 14:35:18 -05:00
|
|
|
printDocstringAndGlobals = true;
|
2013-06-28 23:22:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool preLambda = inLambda;
|
|
|
|
inLambda |= isLambda;
|
|
|
|
|
2010-09-07 21:32:34 -07:00
|
|
|
print_src(code, mod);
|
2013-06-28 23:22:25 -07:00
|
|
|
|
|
|
|
inLambda = preLambda;
|
2017-07-05 16:36:04 -07:00
|
|
|
} else if (src.type() == ASTNode::NODE_CLASS) {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("\n", pyc_output);
|
2010-09-07 21:32:34 -07:00
|
|
|
start_line(cur_indent);
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("class ", pyc_output);
|
2010-09-07 21:32:34 -07:00
|
|
|
print_src(dest, mod);
|
2009-07-27 03:00:55 +00:00
|
|
|
PycRef<ASTTuple> bases = src.cast<ASTClass>()->bases().cast<ASTTuple>();
|
2009-08-03 23:13:50 +00:00
|
|
|
if (bases->values().size() > 0) {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("(", pyc_output);
|
2009-08-03 23:13:50 +00:00
|
|
|
bool first = true;
|
2019-10-04 15:56:24 -07:00
|
|
|
for (const auto& val : bases->values()) {
|
2011-09-18 23:55:27 -07:00
|
|
|
if (!first)
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(", ", pyc_output);
|
2019-10-04 15:56:24 -07:00
|
|
|
print_src(val, mod);
|
2009-08-03 23:13:50 +00:00
|
|
|
first = false;
|
|
|
|
}
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("):\n", pyc_output);
|
2009-08-03 23:13:50 +00:00
|
|
|
} else {
|
|
|
|
// Don't put parens if there are no base classes
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(":\n", pyc_output);
|
2009-07-27 03:00:55 +00:00
|
|
|
}
|
2015-01-28 13:35:17 -05:00
|
|
|
printClassDocstring = true;
|
2009-07-27 03:00:55 +00:00
|
|
|
PycRef<ASTNode> code = src.cast<ASTClass>()->code().cast<ASTCall>()
|
|
|
|
->func().cast<ASTFunction>()->code();
|
2010-09-07 21:32:34 -07:00
|
|
|
print_src(code, mod);
|
2017-07-05 16:36:04 -07:00
|
|
|
} else if (src.type() == ASTNode::NODE_IMPORT) {
|
2009-07-27 03:00:55 +00:00
|
|
|
PycRef<ASTImport> import = src.cast<ASTImport>();
|
2017-07-05 16:36:04 -07:00
|
|
|
if (import->fromlist() != NULL) {
|
2010-09-03 21:50:35 -07:00
|
|
|
PycRef<PycObject> fromlist = import->fromlist().cast<ASTObject>()->object();
|
|
|
|
if (fromlist != Pyc_None) {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("from ", pyc_output);
|
2017-07-05 16:36:04 -07:00
|
|
|
if (import->name().type() == ASTNode::NODE_IMPORT)
|
2010-09-07 21:32:34 -07:00
|
|
|
print_src(import->name().cast<ASTImport>()->name(), mod);
|
2010-09-03 21:50:35 -07:00
|
|
|
else
|
2010-09-07 21:32:34 -07:00
|
|
|
print_src(import->name(), mod);
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(" import ", pyc_output);
|
2017-07-05 16:36:04 -07:00
|
|
|
if (fromlist.type() == PycObject::TYPE_TUPLE ||
|
|
|
|
fromlist.type() == PycObject::TYPE_SMALL_TUPLE) {
|
2010-09-03 21:50:35 -07:00
|
|
|
bool first = true;
|
2019-10-04 15:56:24 -07:00
|
|
|
for (const auto& val : fromlist.cast<PycTuple>()->values()) {
|
2010-09-03 21:50:35 -07:00
|
|
|
if (!first)
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(", ", pyc_output);
|
2019-10-04 15:56:24 -07:00
|
|
|
fprintf(pyc_output, "%s", val.cast<PycString>()->value());
|
2010-09-03 21:50:35 -07:00
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
} else {
|
2011-10-23 19:04:06 -07:00
|
|
|
fprintf(pyc_output, "%s", fromlist.cast<PycString>()->value());
|
2009-07-27 03:00:55 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("import ", pyc_output);
|
2010-09-07 21:32:34 -07:00
|
|
|
print_src(import->name(), mod);
|
2009-07-27 03:00:55 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("import ", pyc_output);
|
2012-06-10 02:57:28 -07:00
|
|
|
PycRef<ASTNode> import_name = import->name();
|
|
|
|
print_src(import_name, mod);
|
|
|
|
if (!dest.cast<ASTName>()->name()->isEqual(import_name.cast<ASTName>()->name().cast<PycObject>())) {
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(" as ", pyc_output);
|
2012-06-10 02:57:28 -07:00
|
|
|
print_src(dest, mod);
|
|
|
|
}
|
2009-07-27 03:00:55 +00:00
|
|
|
}
|
2017-07-05 16:36:04 -07:00
|
|
|
} else if (src.type() == ASTNode::NODE_BINARY &&
|
2015-01-28 13:35:17 -05:00
|
|
|
src.cast<ASTBinary>()->is_inplace() == true) {
|
|
|
|
print_src(src, mod);
|
2009-07-27 00:23:49 +00:00
|
|
|
} else {
|
2015-01-28 13:35:17 -05:00
|
|
|
print_src(dest, mod);
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(" = ", pyc_output);
|
2015-01-28 13:35:17 -05:00
|
|
|
print_src(src, mod);
|
2009-07-27 00:23:49 +00:00
|
|
|
}
|
2009-07-26 10:07:13 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-07-27 08:42:59 +00:00
|
|
|
case ASTNode::NODE_SUBSCR:
|
2010-09-04 23:51:22 -07:00
|
|
|
{
|
2010-09-07 21:32:34 -07:00
|
|
|
print_src(node.cast<ASTSubscr>()->name(), mod);
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("[", pyc_output);
|
2010-09-07 21:32:34 -07:00
|
|
|
print_src(node.cast<ASTSubscr>()->key(), mod);
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("]", pyc_output);
|
2010-09-04 23:51:22 -07:00
|
|
|
}
|
2009-07-27 00:23:49 +00:00
|
|
|
break;
|
2011-01-01 02:31:31 -08:00
|
|
|
case ASTNode::NODE_CONVERT:
|
|
|
|
{
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("`", pyc_output);
|
2011-01-01 02:31:31 -08:00
|
|
|
print_src(node.cast<ASTConvert>()->name(), mod);
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("`", pyc_output);
|
2011-01-01 02:31:31 -08:00
|
|
|
}
|
|
|
|
break;
|
2009-07-27 03:00:55 +00:00
|
|
|
case ASTNode::NODE_TUPLE:
|
|
|
|
{
|
2019-10-04 14:08:47 -07:00
|
|
|
PycRef<ASTTuple> tuple = node.cast<ASTTuple>();
|
|
|
|
ASTTuple::value_t values = tuple->values();
|
|
|
|
if (tuple->requireParens())
|
|
|
|
fputc('(', pyc_output);
|
2009-07-27 03:00:55 +00:00
|
|
|
bool first = true;
|
2019-10-04 15:56:24 -07:00
|
|
|
for (const auto& val : values) {
|
2011-09-18 23:55:27 -07:00
|
|
|
if (!first)
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(", ", pyc_output);
|
2019-10-04 15:56:24 -07:00
|
|
|
print_src(val, mod);
|
2009-07-27 03:00:55 +00:00
|
|
|
first = false;
|
|
|
|
}
|
2009-07-27 08:42:59 +00:00
|
|
|
if (values.size() == 1)
|
2019-10-04 14:08:47 -07:00
|
|
|
fputc(',', pyc_output);
|
|
|
|
if (tuple->requireParens())
|
|
|
|
fputc(')', pyc_output);
|
2009-07-27 03:00:55 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-07-26 10:07:13 +00:00
|
|
|
default:
|
2011-10-23 19:04:06 -07:00
|
|
|
fprintf(pyc_output, "<NODE:%d>", node->type());
|
2009-07-27 00:23:49 +00:00
|
|
|
fprintf(stderr, "Unsupported Node type: %d\n", node->type());
|
2009-07-27 03:23:56 +00:00
|
|
|
cleanBuild = false;
|
|
|
|
return;
|
2009-07-26 10:07:13 +00:00
|
|
|
}
|
2009-07-27 03:23:56 +00:00
|
|
|
|
|
|
|
cleanBuild = true;
|
2009-07-26 10:07:13 +00:00
|
|
|
}
|
|
|
|
|
2015-01-28 14:35:18 -05:00
|
|
|
bool print_docstring(PycRef<PycObject> obj, int indent, PycModule* mod)
|
|
|
|
{
|
|
|
|
// docstrings are translated from the bytecode __doc__ = 'string' to simply '''string'''
|
2015-04-17 19:52:35 -07:00
|
|
|
signed char prefix = -1;
|
2019-10-06 14:34:24 -07:00
|
|
|
switch (obj.type()) {
|
|
|
|
case PycObject::TYPE_STRING:
|
|
|
|
prefix = mod->strIsUnicode() ? 'b' : 0;
|
|
|
|
break;
|
|
|
|
case PycObject::TYPE_UNICODE:
|
|
|
|
prefix = mod->strIsUnicode() ? 0 : 'u';
|
|
|
|
break;
|
|
|
|
case PycObject::TYPE_STRINGREF:
|
|
|
|
case PycObject::TYPE_INTERNED:
|
|
|
|
case PycObject::TYPE_ASCII:
|
|
|
|
case PycObject::TYPE_ASCII_INTERNED:
|
|
|
|
case PycObject::TYPE_SHORT_ASCII:
|
|
|
|
case PycObject::TYPE_SHORT_ASCII_INTERNED:
|
|
|
|
if (mod->majorVer() >= 3)
|
|
|
|
prefix = 0;
|
|
|
|
else
|
|
|
|
prefix = mod->strIsUnicode() ? 'b' : 0;
|
|
|
|
break;
|
|
|
|
}
|
2015-01-28 14:35:18 -05:00
|
|
|
if (prefix != -1) {
|
|
|
|
start_line(indent);
|
|
|
|
OutputString(obj.cast<PycString>(), prefix, true);
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("\n", pyc_output);
|
2015-01-28 14:35:18 -05:00
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-07 21:32:34 -07:00
|
|
|
void decompyle(PycRef<PycCode> code, PycModule* mod)
|
2009-07-26 10:07:13 +00:00
|
|
|
{
|
2009-07-27 00:23:49 +00:00
|
|
|
PycRef<ASTNode> source = BuildFromCode(code, mod);
|
|
|
|
|
2009-08-03 23:13:50 +00:00
|
|
|
PycRef<ASTNodeList> clean = source.cast<ASTNodeList>();
|
2009-07-27 00:30:31 +00:00
|
|
|
if (cleanBuild) {
|
|
|
|
// The Python compiler adds some stuff that we don't really care
|
|
|
|
// about, and would add extra code for re-compilation anyway.
|
|
|
|
// We strip these lines out here, and then add a "pass" statement
|
|
|
|
// if the cleaned up code is empty
|
2017-07-05 16:36:04 -07:00
|
|
|
if (clean->nodes().front().type() == ASTNode::NODE_STORE) {
|
2009-07-27 00:30:31 +00:00
|
|
|
PycRef<ASTStore> store = clean->nodes().front().cast<ASTStore>();
|
2019-10-08 08:53:53 -07:00
|
|
|
if (store->src().type() == ASTNode::NODE_NAME
|
|
|
|
&& store->dest().type() == ASTNode::NODE_NAME) {
|
2009-07-27 00:30:31 +00:00
|
|
|
PycRef<ASTName> src = store->src().cast<ASTName>();
|
|
|
|
PycRef<ASTName> dest = store->dest().cast<ASTName>();
|
2019-10-08 08:53:53 -07:00
|
|
|
if (src->name()->isEqual("__name__")
|
|
|
|
&& dest->name()->isEqual("__module__")) {
|
2009-07-27 00:30:31 +00:00
|
|
|
// __module__ = __name__
|
2016-09-07 18:21:51 -07:00
|
|
|
// Automatically added by Python 2.2.1 and later
|
2009-07-27 00:30:31 +00:00
|
|
|
clean->removeFirst();
|
|
|
|
}
|
2009-07-27 00:23:49 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-08 08:53:53 -07:00
|
|
|
if (clean->nodes().front().type() == ASTNode::NODE_STORE) {
|
|
|
|
PycRef<ASTStore> store = clean->nodes().front().cast<ASTStore>();
|
|
|
|
if (store->src().type() == ASTNode::NODE_OBJECT
|
|
|
|
&& store->dest().type() == ASTNode::NODE_NAME) {
|
|
|
|
PycRef<ASTObject> src = store->src().cast<ASTObject>();
|
|
|
|
PycRef<PycString> srcString = src->object().cast<PycString>();
|
|
|
|
PycRef<ASTName> dest = store->dest().cast<ASTName>();
|
|
|
|
if (srcString != nullptr && srcString->isEqual(code->name().cast<PycObject>())
|
|
|
|
&& dest->name()->isEqual("__qualname__")) {
|
|
|
|
// __qualname__ = '<Class Name>'
|
|
|
|
// Automatically added by Python 3.3 and later
|
|
|
|
clean->removeFirst();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 14:35:18 -05:00
|
|
|
// Class and module docstrings may only appear at the beginning of their source
|
2017-07-05 16:36:04 -07:00
|
|
|
if (printClassDocstring && clean->nodes().front().type() == ASTNode::NODE_STORE) {
|
2015-01-28 13:35:17 -05:00
|
|
|
PycRef<ASTStore> store = clean->nodes().front().cast<ASTStore>();
|
2017-07-05 16:36:04 -07:00
|
|
|
if (store->dest().type() == ASTNode::NODE_NAME &&
|
2015-01-28 13:35:17 -05:00
|
|
|
store->dest().cast<ASTName>()->name()->isEqual("__doc__") &&
|
2017-07-05 16:36:04 -07:00
|
|
|
store->src().type() == ASTNode::NODE_OBJECT) {
|
2015-01-28 14:35:18 -05:00
|
|
|
if (print_docstring(store->src().cast<ASTObject>()->object(),
|
|
|
|
cur_indent + (code->name()->isEqual("<module>") ? 0 : 1), mod))
|
2015-01-28 13:35:17 -05:00
|
|
|
clean->removeFirst();
|
|
|
|
}
|
|
|
|
}
|
2017-07-05 16:36:04 -07:00
|
|
|
if (clean->nodes().back().type() == ASTNode::NODE_RETURN) {
|
2011-10-09 01:47:20 -07:00
|
|
|
PycRef<ASTReturn> ret = clean->nodes().back().cast<ASTReturn>();
|
|
|
|
|
2017-07-05 16:36:04 -07:00
|
|
|
if (ret->value() == NULL || ret->value().type() == ASTNode::NODE_LOCALS) {
|
2011-10-09 01:47:20 -07:00
|
|
|
clean->removeLast(); // Always an extraneous return statement
|
|
|
|
}
|
|
|
|
}
|
2009-07-27 00:30:31 +00:00
|
|
|
}
|
2015-01-28 13:35:17 -05:00
|
|
|
if (printClassDocstring)
|
|
|
|
printClassDocstring = false;
|
2009-08-03 23:13:50 +00:00
|
|
|
// This is outside the clean check so a source block will always
|
|
|
|
// be compilable, even if decompylation failed.
|
2019-10-08 09:04:41 -07:00
|
|
|
if (clean->nodes().size() == 0 && !code.isIdent(mod->code()))
|
2019-10-08 13:12:31 -07:00
|
|
|
clean->append(new ASTKeyword(ASTKeyword::KW_PASS));
|
2009-07-27 00:23:49 +00:00
|
|
|
|
2009-07-27 03:23:56 +00:00
|
|
|
bool part1clean = cleanBuild;
|
2011-10-09 23:42:34 -07:00
|
|
|
|
2015-01-28 14:35:18 -05:00
|
|
|
if (printDocstringAndGlobals) {
|
|
|
|
if (code->consts()->size())
|
|
|
|
print_docstring(code->getConst(0), cur_indent + 1, mod);
|
|
|
|
|
|
|
|
PycCode::globals_t globs = code->getGlobals();
|
|
|
|
if (globs.size()) {
|
|
|
|
start_line(cur_indent + 1);
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("global ", pyc_output);
|
2015-01-28 14:35:18 -05:00
|
|
|
bool first = true;
|
2019-10-04 15:56:24 -07:00
|
|
|
for (const auto& glob : globs) {
|
2015-01-28 14:35:18 -05:00
|
|
|
if (!first)
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs(", ", pyc_output);
|
2019-10-04 15:56:24 -07:00
|
|
|
fprintf(pyc_output, "%s", glob->value());
|
2015-01-28 14:35:18 -05:00
|
|
|
first = false;
|
|
|
|
}
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("\n", pyc_output);
|
2011-10-09 23:42:34 -07:00
|
|
|
}
|
2015-01-28 14:35:18 -05:00
|
|
|
printDocstringAndGlobals = false;
|
2011-10-09 23:42:34 -07:00
|
|
|
}
|
|
|
|
|
2010-09-07 21:32:34 -07:00
|
|
|
print_src(source, mod);
|
2009-07-27 03:23:56 +00:00
|
|
|
|
|
|
|
if (!cleanBuild || !part1clean) {
|
2010-09-07 21:32:34 -07:00
|
|
|
start_line(cur_indent);
|
2018-01-28 10:32:44 -08:00
|
|
|
fputs("# WARNING: Decompyle incomplete\n", pyc_output);
|
2009-07-27 03:23:56 +00:00
|
|
|
}
|
2009-07-26 10:07:13 +00:00
|
|
|
}
|