Commit 2707c2e2 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge #213

With some changes
- renamed AST_Exec::expr -> body (to match CPython)
- removed references to AST_SetComp
parents cf1f0e20 60146462
......@@ -352,6 +352,18 @@ AST_ExceptHandler* read_excepthandler(BufferedReader* reader) {
return rtn;
}
AST_Exec* read_exec(BufferedReader* reader) {
AST_Exec* rtn = new AST_Exec();
rtn->body = readASTExpr(reader);
rtn->col_offset = readColOffset(reader);
rtn->globals = readASTExpr(reader);
rtn->lineno = reader->readULL();
rtn->locals = readASTExpr(reader);
return rtn;
}
AST_Expr* read_expr(BufferedReader* reader) {
AST_Expr* rtn = new AST_Expr();
......@@ -813,6 +825,8 @@ AST_stmt* readASTStmt(BufferedReader* reader) {
return read_continue(reader);
case AST_TYPE::Delete:
return read_delete(reader);
case AST_TYPE::Exec:
return read_exec(reader);
case AST_TYPE::Expr:
return read_expr(reader);
case AST_TYPE::For:
......
......@@ -613,6 +613,17 @@ struct stmt_dispatcher {
return ptr;
}
ResultPtr read(pypa::AstExec& e) {
AST_Exec* ptr = new AST_Exec();
location(ptr, e);
ptr->body = readItem(e.body);
if (e.globals)
ptr->globals = readItem(e.globals);
if (e.locals)
ptr->locals = readItem(e.locals);
return ptr;
}
ResultPtr read(pypa::AstExpressionStatement& e) {
AST_Expr* ptr = new AST_Expr();
location(ptr, e);
......
......@@ -445,6 +445,19 @@ void AST_ExceptHandler::accept(ASTVisitor* v) {
visitVector(body, v);
}
void AST_Exec::accept(ASTVisitor* v) {
bool skip = v->visit_exec(this);
if (skip)
return;
if (body)
body->accept(v);
}
void AST_Exec::accept_stmt(StmtVisitor* v) {
v->visit_exec(this);
}
void AST_Expr::accept(ASTVisitor* v) {
bool skip = v->visit_expr(this);
if (skip)
......@@ -1245,6 +1258,23 @@ bool PrintVisitor::visit_excepthandler(AST_ExceptHandler* node) {
return true;
}
bool PrintVisitor::visit_exec(AST_Exec* node) {
printf("exec ");
node->body->accept(this);
if (node->globals) {
printf(" in ");
node->globals->accept(this);
if (node->locals) {
printf(", ");
node->locals->accept(this);
}
}
printf("\n");
return true;
}
bool PrintVisitor::visit_expr(AST_Expr* node) {
return false;
}
......@@ -1853,6 +1883,10 @@ public:
output->push_back(node);
return false;
}
virtual bool visit_exec(AST_Exec* node) {
output->push_back(node);
return false;
}
virtual bool visit_expr(AST_Expr* node) {
output->push_back(node);
return false;
......
......@@ -435,6 +435,19 @@ public:
static const AST_TYPE::AST_TYPE TYPE = AST_TYPE::ExceptHandler;
};
class AST_Exec : public AST_stmt {
public:
AST_expr* body;
AST_expr* globals;
AST_expr* locals;
virtual void accept(ASTVisitor* v);
virtual void accept_stmt(StmtVisitor* v);
AST_Exec() : AST_stmt(AST_TYPE::Exec) {}
static const AST_TYPE::AST_TYPE TYPE = AST_TYPE::Exec;
};
class AST_ExtSlice : public AST_expr {
public:
......@@ -1007,6 +1020,7 @@ public:
virtual bool visit_dictcomp(AST_DictComp* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_ellipsis(AST_Ellipsis* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_excepthandler(AST_ExceptHandler* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_exec(AST_Exec* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_expr(AST_Expr* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_extslice(AST_ExtSlice* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_for(AST_For* node) { RELEASE_ASSERT(0, ""); }
......@@ -1075,6 +1089,7 @@ public:
virtual bool visit_dictcomp(AST_DictComp* node) { return false; }
virtual bool visit_ellipsis(AST_Ellipsis* node) { return false; }
virtual bool visit_excepthandler(AST_ExceptHandler* node) { return false; }
virtual bool visit_exec(AST_Exec* node) { return false; }
virtual bool visit_expr(AST_Expr* node) { return false; }
virtual bool visit_extslice(AST_ExtSlice* node) { return false; }
virtual bool visit_for(AST_For* node) { return false; }
......@@ -1164,6 +1179,7 @@ public:
virtual void visit_classdef(AST_ClassDef* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_delete(AST_Delete* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_continue(AST_Continue* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_exec(AST_Exec* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_expr(AST_Expr* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_for(AST_For* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_functiondef(AST_FunctionDef* node) { RELEASE_ASSERT(0, ""); }
......@@ -1217,6 +1233,7 @@ public:
virtual bool visit_dictcomp(AST_DictComp* node);
virtual bool visit_ellipsis(AST_Ellipsis* node);
virtual bool visit_excepthandler(AST_ExceptHandler* node);
virtual bool visit_exec(AST_Exec* node);
virtual bool visit_expr(AST_Expr* node);
virtual bool visit_extslice(AST_ExtSlice* node);
virtual bool visit_for(AST_For* node);
......
......@@ -1574,6 +1574,8 @@ public:
return true;
}
bool visit_exec(AST_Exec* node) override { raiseExcHelper(SyntaxError, "'exec' currently not supported"); }
bool visit_while(AST_While* node) override {
if (!curblock)
return true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment