Commit f1817d4f authored by Vinzenz Feenstra's avatar Vinzenz Feenstra

Implementation for parsing 'exec'

parent 4c7b796a
...@@ -352,6 +352,18 @@ AST_ExceptHandler* read_excepthandler(BufferedReader* reader) { ...@@ -352,6 +352,18 @@ AST_ExceptHandler* read_excepthandler(BufferedReader* reader) {
return rtn; return rtn;
} }
AST_Exec* read_exec(BufferedReader* reader) {
AST_Exec* rtn = new AST_Exec();
rtn->expr = 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* read_expr(BufferedReader* reader) {
AST_Expr* rtn = new AST_Expr(); AST_Expr* rtn = new AST_Expr();
...@@ -813,6 +825,8 @@ AST_stmt* readASTStmt(BufferedReader* reader) { ...@@ -813,6 +825,8 @@ AST_stmt* readASTStmt(BufferedReader* reader) {
return read_continue(reader); return read_continue(reader);
case AST_TYPE::Delete: case AST_TYPE::Delete:
return read_delete(reader); return read_delete(reader);
case AST_TYPE::Exec:
return read_exec(reader);
case AST_TYPE::Expr: case AST_TYPE::Expr:
return read_expr(reader); return read_expr(reader);
case AST_TYPE::For: case AST_TYPE::For:
......
...@@ -440,6 +440,14 @@ struct expr_dispatcher { ...@@ -440,6 +440,14 @@ struct expr_dispatcher {
return ptr; return ptr;
} }
ResultPtr read(pypa::AstSetComp& l) {
AST_SetComp* ptr = new AST_SetComp();
location(ptr, l);
readVector(ptr->generators, l.generators);
ptr->elt = readItem(l.element);
return ptr;
}
ResultPtr read(pypa::AstName& a) { ResultPtr read(pypa::AstName& a) {
AST_Name* ptr = new AST_Name(); AST_Name* ptr = new AST_Name();
location(ptr, a); location(ptr, a);
...@@ -613,6 +621,17 @@ struct stmt_dispatcher { ...@@ -613,6 +621,17 @@ struct stmt_dispatcher {
return ptr; return ptr;
} }
ResultPtr read(pypa::AstExec& e) {
AST_Exec* ptr = new AST_Exec();
location(ptr, e);
ptr->expr = 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) { ResultPtr read(pypa::AstExpressionStatement& e) {
AST_Expr* ptr = new AST_Expr(); AST_Expr* ptr = new AST_Expr();
location(ptr, e); location(ptr, e);
......
...@@ -445,6 +445,19 @@ void AST_ExceptHandler::accept(ASTVisitor* v) { ...@@ -445,6 +445,19 @@ void AST_ExceptHandler::accept(ASTVisitor* v) {
visitVector(body, v); visitVector(body, v);
} }
void AST_Exec::accept(ASTVisitor* v) {
bool skip = v->visit_exec(this);
if (skip)
return;
if (expr)
expr->accept(v);
}
void AST_Exec::accept_stmt(StmtVisitor* v) {
v->visit_exec(this);
}
void AST_Expr::accept(ASTVisitor* v) { void AST_Expr::accept(ASTVisitor* v) {
bool skip = v->visit_expr(this); bool skip = v->visit_expr(this);
if (skip) if (skip)
...@@ -1245,6 +1258,23 @@ bool PrintVisitor::visit_excepthandler(AST_ExceptHandler* node) { ...@@ -1245,6 +1258,23 @@ bool PrintVisitor::visit_excepthandler(AST_ExceptHandler* node) {
return true; return true;
} }
bool PrintVisitor::visit_exec(AST_Exec* node) {
printf("exec ");
node->expr->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) { bool PrintVisitor::visit_expr(AST_Expr* node) {
return false; return false;
} }
...@@ -1853,6 +1883,10 @@ public: ...@@ -1853,6 +1883,10 @@ public:
output->push_back(node); output->push_back(node);
return false; return false;
} }
virtual bool visit_exec(AST_Exec* node) {
output->push_back(node);
return false;
}
virtual bool visit_expr(AST_Expr* node) { virtual bool visit_expr(AST_Expr* node) {
output->push_back(node); output->push_back(node);
return false; return false;
......
...@@ -435,6 +435,19 @@ public: ...@@ -435,6 +435,19 @@ public:
static const AST_TYPE::AST_TYPE TYPE = AST_TYPE::ExceptHandler; static const AST_TYPE::AST_TYPE TYPE = AST_TYPE::ExceptHandler;
}; };
class AST_Exec : public AST_stmt {
public:
AST_expr* expr;
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 { class AST_ExtSlice : public AST_expr {
public: public:
...@@ -1007,6 +1020,7 @@ public: ...@@ -1007,6 +1020,7 @@ public:
virtual bool visit_dictcomp(AST_DictComp* node) { RELEASE_ASSERT(0, ""); } virtual bool visit_dictcomp(AST_DictComp* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_ellipsis(AST_Ellipsis* 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_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_expr(AST_Expr* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_extslice(AST_ExtSlice* node) { RELEASE_ASSERT(0, ""); } virtual bool visit_extslice(AST_ExtSlice* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_for(AST_For* node) { RELEASE_ASSERT(0, ""); } virtual bool visit_for(AST_For* node) { RELEASE_ASSERT(0, ""); }
...@@ -1075,6 +1089,7 @@ public: ...@@ -1075,6 +1089,7 @@ public:
virtual bool visit_dictcomp(AST_DictComp* node) { return false; } virtual bool visit_dictcomp(AST_DictComp* node) { return false; }
virtual bool visit_ellipsis(AST_Ellipsis* node) { return false; } virtual bool visit_ellipsis(AST_Ellipsis* node) { return false; }
virtual bool visit_excepthandler(AST_ExceptHandler* 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_expr(AST_Expr* node) { return false; }
virtual bool visit_extslice(AST_ExtSlice* node) { return false; } virtual bool visit_extslice(AST_ExtSlice* node) { return false; }
virtual bool visit_for(AST_For* node) { return false; } virtual bool visit_for(AST_For* node) { return false; }
...@@ -1164,6 +1179,7 @@ public: ...@@ -1164,6 +1179,7 @@ public:
virtual void visit_classdef(AST_ClassDef* node) { RELEASE_ASSERT(0, ""); } virtual void visit_classdef(AST_ClassDef* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_delete(AST_Delete* 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_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_expr(AST_Expr* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_for(AST_For* node) { RELEASE_ASSERT(0, ""); } virtual void visit_for(AST_For* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_functiondef(AST_FunctionDef* node) { RELEASE_ASSERT(0, ""); } virtual void visit_functiondef(AST_FunctionDef* node) { RELEASE_ASSERT(0, ""); }
...@@ -1217,6 +1233,7 @@ public: ...@@ -1217,6 +1233,7 @@ public:
virtual bool visit_dictcomp(AST_DictComp* node); virtual bool visit_dictcomp(AST_DictComp* node);
virtual bool visit_ellipsis(AST_Ellipsis* node); virtual bool visit_ellipsis(AST_Ellipsis* node);
virtual bool visit_excepthandler(AST_ExceptHandler* 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_expr(AST_Expr* node);
virtual bool visit_extslice(AST_ExtSlice* node); virtual bool visit_extslice(AST_ExtSlice* node);
virtual bool visit_for(AST_For* node); virtual bool visit_for(AST_For* node);
......
...@@ -1568,6 +1568,8 @@ public: ...@@ -1568,6 +1568,8 @@ public:
return true; return true;
} }
bool visit_exec(AST_Exec* node) override { raiseExcHelper(SyntaxError, "'exec' currently not supported"); }
bool visit_while(AST_While* node) override { bool visit_while(AST_While* node) override {
if (!curblock) if (!curblock)
return true; 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