Correct output for in-place operators.

This commit is contained in:
Darryl Pogue
2011-09-18 11:59:02 -07:00
parent f907dc76ad
commit 84b8cba005
2 changed files with 43 additions and 4 deletions

View File

@@ -105,6 +105,7 @@ public:
PycRef<ASTNode> left() const { return m_left; }
PycRef<ASTNode> right() const { return m_right; }
int op() const { return m_op; }
bool is_inplace() const { return m_op >= BIN_IP_ADD; }
virtual const char* op_str() const;
protected:

View File

@@ -507,8 +507,7 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
stack.pop();
PycRef<ASTNode> src = stack.top();
stack.pop();
/* This is a problem, so fake it with a = a + b syntax */
stack.push(new ASTBinary(src, right, ASTBinary::BIN_ADD));
stack.push(new ASTBinary(src, right, ASTBinary::BIN_IP_ADD));
}
break;
case Pyc::INPLACE_SUBTRACT:
@@ -517,8 +516,25 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
stack.pop();
PycRef<ASTNode> src = stack.top();
stack.pop();
/* This is a problem, so fake it with a = a - b syntax */
stack.push(new ASTBinary(src, right, ASTBinary::BIN_SUBTRACT));
stack.push(new ASTBinary(src, right, ASTBinary::BIN_IP_SUBTRACT));
}
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;
case Pyc::INPLACE_DIVIDE:
{
PycRef<ASTNode> right = stack.top();
stack.pop();
PycRef<ASTNode> src = stack.top();
stack.pop();
stack.push(new ASTBinary(src, right, ASTBinary::BIN_IP_DIVIDE));
}
break;
case Pyc::JUMP_IF_FALSE_A:
@@ -839,6 +855,22 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
stack.push(two);
}
break;
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;
case Pyc::SET_LINENO_A:
// Ignore
break;
@@ -1574,6 +1606,12 @@ void print_src(PycRef<ASTNode> node, PycModule* mod)
print_src(import->name(), mod);
}
} else {
if (src->type() == ASTNode::NODE_BINARY &&
src.cast<ASTBinary>()->is_inplace() == true) {
print_src(src, mod);
break;
}
if (dest->type() == ASTNode::NODE_NAME &&
dest.cast<ASTName>()->name()->isEqual("__doc__")) {
if (src->type() == ASTNode::NODE_OBJECT) {