Commit 0dea31b9 authored by Marius Wachtler's avatar Marius Wachtler Committed by GitHub

Merge pull request #1360 from undingen/astbst_cleanup

AST & BST: remove unnecessary nodes and fields + little less memory usage
parents aba408b8 1228d981
......@@ -78,8 +78,6 @@ public:
bool isKilledAt(BST_Name* node, bool is_live_at_end) { return node->is_kill; }
bool visit_import(BST_Import* node) { RELEASE_ASSERT(0, "these should all get removed by the cfg"); }
bool visit_classdef(BST_ClassDef* node) {
for (auto e : node->bases)
e->accept(this);
......@@ -118,8 +116,6 @@ public:
}
return true;
}
bool visit_alias(BST_alias* node) { RELEASE_ASSERT(0, "these should be removed by the cfg"); }
};
LivenessAnalysis::LivenessAnalysis(CFG* cfg) : cfg(cfg), result_cache(cfg->getVRegInfo().getTotalNumOfVRegs()) {
......@@ -282,16 +278,14 @@ public:
virtual bool visit_assert(BST_Assert* node) { return true; }
virtual bool visit_branch(BST_Branch* node) { return true; }
virtual bool visit_expr(BST_Expr* node) { return true; }
virtual bool visit_global(BST_Global* node) { return true; }
virtual bool visit_invoke(BST_Invoke* node) { return false; }
virtual bool visit_jump(BST_Jump* node) { return true; }
virtual bool visit_pass(BST_Pass* node) { return true; }
virtual bool visit_print(BST_Print* node) { return true; }
virtual bool visit_raise(BST_Raise* node) { return true; }
virtual bool visit_return(BST_Return* node) { return true; }
virtual bool visit_delete(BST_Delete* node) {
for (auto t : node->targets) {
auto t = node->target;
if (t->type == BST_TYPE::Name) {
BST_Name* name = bst_cast<BST_Name>(t);
if (name->lookup_type != ScopeInfo::VarScopeType::GLOBAL
......@@ -306,7 +300,6 @@ public:
// and look for BST_Name's with a ctx of Del
assert(t->type == BST_TYPE::Attribute || t->type == BST_TYPE::Subscript);
}
}
return true;
}
......@@ -322,21 +315,8 @@ public:
return true;
}
virtual bool visit_alias(BST_alias* node) {
int vreg = node->name_vreg;
if (node->asname.s().size())
vreg = node->asname_vreg;
_doSet(vreg);
return true;
}
virtual bool visit_import(BST_Import* node) { return false; }
virtual bool visit_importfrom(BST_ImportFrom* node) { return false; }
virtual bool visit_assign(BST_Assign* node) {
for (int i = 0; i < node->targets.size(); i++) {
_doSet(node->targets[i]);
}
_doSet(node->target);
return true;
}
......
......@@ -606,8 +606,6 @@ public:
bool visit_while(AST_While* node) override { return false; }
bool visit_with(AST_With* node) override { return false; }
bool visit_yield(AST_Yield* node) override { return false; }
bool visit_branch(AST_Branch* node) override { return false; }
bool visit_jump(AST_Jump* node) override { return false; }
bool visit_delete(AST_Delete* node) override { return false; }
bool visit_global(AST_Global* node) override {
......
......@@ -65,7 +65,7 @@ public:
// import dis
// print dis.dis(g)
enum class VarScopeType {
enum class VarScopeType : unsigned char {
FAST,
GLOBAL,
CLOSURE,
......
......@@ -219,8 +219,7 @@ private:
}
if (VERBOSITY() >= 2 && rtn == UNDEF) {
printf("Think %s.%s is undefined, at %d:%d\n", t->debugName().c_str(), node->attr.c_str(), node->lineno,
node->col_offset);
printf("Think %s.%s is undefined, at %d\n", t->debugName().c_str(), node->attr.c_str(), node->lineno);
print_bst(node);
printf("\n");
}
......@@ -231,8 +230,7 @@ private:
CompilerType* t = getType(node->value);
CompilerType* rtn = t->getattrType(node->attr, true);
if (VERBOSITY() >= 2 && rtn == UNDEF) {
printf("Think %s.%s is undefined, at %d:%d\n", t->debugName().c_str(), node->attr.c_str(), node->lineno,
node->col_offset);
printf("Think %s.%s is undefined, at %d\n", t->debugName().c_str(), node->attr.c_str(), node->lineno);
print_bst(node);
printf("\n");
}
......@@ -297,21 +295,6 @@ private:
return rtn;
}
void* visit_boolop(BST_BoolOp* node) override {
int n = node->values.size();
CompilerType* rtn = NULL;
for (int i = 0; i < n; i++) {
CompilerType* t = getType(node->values[i]);
if (rtn == NULL)
rtn = t;
else if (rtn != t)
rtn = UNKNOWN;
}
return rtn;
}
void* visit_call(BST_Call* node) override {
CompilerType* func = getType(node->func);
......@@ -349,18 +332,16 @@ private:
}
void* visit_compare(BST_Compare* node) override {
if (node->ops.size() == 1) {
CompilerType* left = getType(node->left);
CompilerType* right = getType(node->comparators[0]);
CompilerType* right = getType(node->comparator);
AST_TYPE::AST_TYPE op_type = node->ops[0];
AST_TYPE::AST_TYPE op_type = node->op;
if (op_type == AST_TYPE::Is || op_type == AST_TYPE::IsNot || op_type == AST_TYPE::In
|| op_type == AST_TYPE::NotIn) {
assert(node->ops.size() == 1 && "I don't think this should happen");
return BOOL;
}
BoxedString* name = getOpName(node->ops[0]);
BoxedString* name = getOpName(node->op);
CompilerType* attr_type = left->getattrType(name, true);
if (attr_type == UNDEF)
......@@ -369,9 +350,6 @@ private:
std::vector<CompilerType*> arg_types;
arg_types.push_back(right);
return attr_type->callType(ArgPassSpec(2), arg_types, NULL);
} else {
return UNKNOWN;
}
}
void* visit_dict(BST_Dict* node) override {
......@@ -541,9 +519,7 @@ private:
void visit_assign(BST_Assign* node) override {
CompilerType* t = getType(node->value);
for (int i = 0; i < node->targets.size(); i++) {
_doSet(node->targets[i], t);
}
_doSet(node->target, t);
}
void visit_branch(BST_Branch* node) override {
......@@ -569,7 +545,7 @@ private:
}
void visit_delete(BST_Delete* node) override {
for (BST_expr* target : node->targets) {
BST_expr* target = node->target;
switch (target->type) {
case BST_TYPE::Subscript:
getType(bst_cast<BST_Subscript>(target)->value);
......@@ -591,7 +567,6 @@ private:
RELEASE_ASSERT(0, "%d", target->type);
}
}
}
void visit_expr(BST_Expr* node) override {
if (EXPAND_UNNEEDED) {
......@@ -617,12 +592,6 @@ private:
return t;
}
void visit_global(BST_Global* node) override {}
void visit_import(BST_Import* node) override { assert(0 && "this should get removed by cfg"); }
void visit_importfrom(BST_ImportFrom* node) override { assert(0 && "this should get removed by cfg"); }
void visit_exec(BST_Exec* node) override {
getType(node->body);
if (node->globals)
......@@ -634,17 +603,13 @@ private:
void visit_invoke(BST_Invoke* node) override { node->stmt->accept_stmt(this); }
void visit_jump(BST_Jump* node) override {}
void visit_pass(BST_Pass* node) override {}
void visit_print(BST_Print* node) override {
if (node->dest)
getType(node->dest);
if (EXPAND_UNNEEDED) {
for (int i = 0; i < node->values.size(); i++) {
getType(node->values[i]);
}
}
if (EXPAND_UNNEEDED && node->value)
getType(node->value);
}
void visit_raise(BST_Raise* node) override {
......
......@@ -88,8 +88,6 @@ private:
Value visit_compare(BST_Compare* node);
Value visit_delete(BST_Delete* node);
Value visit_exec(BST_Exec* node);
Value visit_global(BST_Global* node);
Value visit_module(BST_Module* node);
Value visit_print(BST_Print* node);
Value visit_raise(BST_Raise* node);
Value visit_return(BST_Return* node);
......@@ -1055,10 +1053,6 @@ Value ASTInterpreter::visit_stmt(BST_stmt* node) {
throw e;
}
return rtn;
case BST_TYPE::Global:
rtn = visit_global((BST_Global*)node);
ASTInterpreterJitInterface::pendingCallsCheckHelper();
break;
// pseudo
case BST_TYPE::Branch:
......@@ -1308,17 +1302,8 @@ Value ASTInterpreter::visit_assert(BST_Assert* node) {
return Value();
}
Value ASTInterpreter::visit_global(BST_Global* node) {
#ifndef NDEBUG
for (auto name : node->names) {
assert(!getSymVRegMap().count(name));
}
#endif
return Value();
}
Value ASTInterpreter::visit_delete(BST_Delete* node) {
for (BST_expr* target_ : node->targets) {
BST_expr* target_ = node->target;
switch (target_->type) {
case BST_TYPE::Subscript: {
BST_Subscript* sub = (BST_Subscript*)target_;
......@@ -1365,7 +1350,7 @@ Value ASTInterpreter::visit_delete(BST_Delete* node) {
if (jit)
jit->emitDelGlobal(target->id.getBox());
delGlobal(frame_info.globals, target->id.getBox());
continue;
break;
} else if (vst == ScopeInfo::VarScopeType::NAME) {
if (jit)
jit->emitDelName(target->id);
......@@ -1397,22 +1382,18 @@ Value ASTInterpreter::visit_delete(BST_Delete* node) {
ASSERT(0, "Unsupported del target: %d", target_->type);
abort();
}
}
return Value();
}
Value ASTInterpreter::visit_assign(BST_Assign* node) {
assert(node->targets.size() == 1 && "cfg should have lowered it to a single target");
Value v = visit_expr(node->value);
doStore(node->targets[0], v);
doStore(node->target, v);
return Value();
}
Value ASTInterpreter::visit_print(BST_Print* node) {
assert(node->values.size() <= 1 && "cfg should have lowered it to 0 or 1 values");
Value dest = node->dest ? visit_expr(node->dest) : Value();
Value var = node->values.size() ? visit_expr(node->values[0]) : Value();
Value var = node->value ? visit_expr(node->value) : Value();
if (jit)
jit->emitPrint(dest, var, node->nl);
......@@ -1442,12 +1423,11 @@ Value ASTInterpreter::visit_exec(BST_Exec* node) {
}
Value ASTInterpreter::visit_compare(BST_Compare* node) {
RELEASE_ASSERT(node->comparators.size() == 1, "not implemented");
Value left = visit_expr(node->left);
AUTO_DECREF(left.o);
Value right = visit_expr(node->comparators[0]);
Value right = visit_expr(node->comparator);
AUTO_DECREF(right.o);
return doBinOp(node, left, right, node->ops[0], BinExpType::Compare);
return doBinOp(node, left, right, node->op, BinExpType::Compare);
}
Value ASTInterpreter::visit_expr(BST_expr* node) {
......@@ -2127,9 +2107,8 @@ extern "C" Box* astInterpretDeoptFromASM(BoxedCode* code, BST_expr* after_expr,
if (enclosing_stmt->type == BST_TYPE::Assign) {
auto asgn = bst_cast<BST_Assign>(enclosing_stmt);
RELEASE_ASSERT(asgn->value == after_expr, "%p %p", asgn->value, after_expr);
assert(asgn->targets.size() == 1);
assert(asgn->targets[0]->type == BST_TYPE::Name);
auto name = bst_cast<BST_Name>(asgn->targets[0]);
assert(asgn->target->type == BST_TYPE::Name);
auto name = bst_cast<BST_Name>(asgn->target);
assert(name->id.s()[0] == '#');
interpreter.addSymbol(name->vreg, expr_val, true);
break;
......
......@@ -727,13 +727,12 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc
if (stmt->type == BST_TYPE::Assign) {
auto asgn = bst_cast<BST_Assign>(stmt);
assert(asgn->targets.size() == 1);
if (asgn->targets[0]->type == BST_TYPE::Name) {
auto asname = bst_cast<BST_Name>(asgn->targets[0]);
if (asgn->target->type == BST_TYPE::Name) {
auto asname = bst_cast<BST_Name>(asgn->target);
assert(asname->lookup_type != ScopeInfo::VarScopeType::UNKNOWN);
InternedString name = asname->id;
int vreg = bst_cast<BST_Name>(asgn->targets[0])->vreg;
int vreg = bst_cast<BST_Name>(asgn->target)->vreg;
assert(name.c_str()[0] == '#'); // it must be a temporary
// You might think I need to check whether `name' is being assigned globally or locally,
// since a global assign doesn't affect the symbol table. However, the CFG pass only
......
......@@ -1137,19 +1137,16 @@ private:
}
CompilerVariable* evalCompare(BST_Compare* node, const UnwindInfo& unw_info) {
RELEASE_ASSERT(node->ops.size() == 1, "");
CompilerVariable* left = evalExpr(node->left, unw_info);
CompilerVariable* right = evalExpr(node->comparators[0], unw_info);
CompilerVariable* right = evalExpr(node->comparator, unw_info);
assert(left);
assert(right);
if (node->ops[0] == AST_TYPE::Is || node->ops[0] == AST_TYPE::IsNot) {
return doIs(emitter, left, right, node->ops[0] == AST_TYPE::IsNot);
}
if (node->op == AST_TYPE::Is || node->op == AST_TYPE::IsNot)
return doIs(emitter, left, right, node->op == AST_TYPE::IsNot);
CompilerVariable* rtn = _evalBinExp(node, left, right, node->ops[0], Compare, unw_info);
CompilerVariable* rtn = _evalBinExp(node, left, right, node->op, Compare, unw_info);
return rtn;
}
......@@ -2084,13 +2081,11 @@ private:
void doAssign(BST_Assign* node, const UnwindInfo& unw_info) {
CompilerVariable* val = evalExpr(node->value, unw_info);
for (int i = 0; i < node->targets.size(); i++) {
_doSet(node->targets[i], val, unw_info);
}
_doSet(node->target, val, unw_info);
}
void doDelete(BST_Delete* node, const UnwindInfo& unw_info) {
for (BST_expr* target : node->targets) {
BST_expr* target = node->target;
switch (target->type) {
case BST_TYPE::Subscript:
_doDelitem(static_cast<BST_Subscript*>(target), unw_info);
......@@ -2106,7 +2101,6 @@ private:
abort();
}
}
}
// invoke delitem in objmodel.cpp, which will invoke the listDelitem of list
void _doDelitem(BST_Subscript* target, const UnwindInfo& unw_info) {
......@@ -2237,11 +2231,10 @@ private:
}
assert(dest);
assert(node->values.size() <= 1);
ConcreteCompilerVariable* converted;
if (node->values.size() == 1) {
CompilerVariable* var = evalExpr(node->values[0], unw_info);
if (node->value) {
CompilerVariable* var = evalExpr(node->value, unw_info);
converted = var->makeConverted(emitter, var->getBoxType());
} else {
converted = new ConcreteCompilerVariable(UNKNOWN, getNullPtr(g.llvm_value_type_ptr));
......@@ -2561,15 +2554,6 @@ private:
if ((((BST_Expr*)node)->value)->type != BST_TYPE::Str)
doExpr(bst_cast<BST_Expr>(node), unw_info);
break;
// case BST_TYPE::If:
// doIf(bst_cast<BST_If>(node));
// break;
// case BST_TYPE::Import:
// doImport(bst_cast<BST_Import>(node), unw_info);
// break;
// case BST_TYPE::ImportFrom:
// doImportFrom(bst_cast<BST_ImportFrom>(node), unw_info);
// break;
case BST_TYPE::Global:
// Should have been handled already
break;
......
......@@ -490,7 +490,7 @@ static const LineInfo lineInfoForFrameInfo(FrameInfo* frame_info) {
auto* code = frame_info->code;
assert(code);
return LineInfo(current_stmt->lineno, current_stmt->col_offset, code->filename, code->name);
return LineInfo(current_stmt->lineno, code->filename, code->name);
}
// A class that converts a C stack trace to a Python stack trace.
......
......@@ -887,28 +887,6 @@ void AST_Yield::accept(ASTVisitor* v) {
value->accept(v);
}
void AST_Branch::accept(ASTVisitor* v) {
bool skip = v->visit_branch(this);
if (skip)
return;
test->accept(v);
}
void AST_Branch::accept_stmt(ASTStmtVisitor* v) {
v->visit_branch(this);
}
void AST_Jump::accept(ASTVisitor* v) {
bool skip = v->visit_jump(this);
if (skip)
return;
}
void AST_Jump::accept_stmt(ASTStmtVisitor* v) {
v->visit_jump(this);
}
void AST_ClsAttribute::accept(ASTVisitor* v) {
bool skip = v->visit_clsattribute(this);
if (skip)
......@@ -917,22 +895,6 @@ void AST_ClsAttribute::accept(ASTVisitor* v) {
value->accept(v);
}
void AST_MakeFunction::accept(ASTVisitor* v) {
bool skip = v->visit_makefunction(this);
if (skip)
return;
function_def->accept(v);
}
void AST_MakeClass::accept(ASTVisitor* v) {
bool skip = v->visit_makeclass(this);
if (skip)
return;
class_def->accept(v);
}
void print_ast(AST* ast) {
ASTPrintVisitor v;
ast->accept(&v);
......@@ -1827,18 +1789,6 @@ bool ASTPrintVisitor::visit_yield(AST_Yield* node) {
return true;
}
bool ASTPrintVisitor::visit_branch(AST_Branch* node) {
stream << "if ";
node->test->accept(this);
stream << " goto " << node->iftrue->idx << " else goto " << node->iffalse->idx;
return true;
}
bool ASTPrintVisitor::visit_jump(AST_Jump* node) {
stream << "goto " << node->target->idx;
return true;
}
bool ASTPrintVisitor::visit_clsattribute(AST_ClsAttribute* node) {
// printf("getclsattr(");
// node->value->accept(this);
......@@ -1848,16 +1798,7 @@ bool ASTPrintVisitor::visit_clsattribute(AST_ClsAttribute* node) {
return true;
}
bool ASTPrintVisitor::visit_makefunction(AST_MakeFunction* node) {
stream << "make_";
return false;
}
bool ASTPrintVisitor::visit_makeclass(AST_MakeClass* node) {
stream << "make_";
return false;
}
namespace {
class FlattenVisitor : public ASTVisitor {
private:
std::vector<AST*>* output;
......@@ -2101,30 +2042,14 @@ public:
return false;
}
virtual bool visit_branch(AST_Branch* node) {
output->push_back(node);
return false;
}
virtual bool visit_jump(AST_Jump* node) {
output->push_back(node);
return false;
}
virtual bool visit_clsattribute(AST_ClsAttribute* node) {
output->push_back(node);
return false;
}
virtual bool visit_makeclass(AST_MakeClass* node) {
output->push_back(node);
return false;
}
virtual bool visit_makefunction(AST_MakeFunction* node) {
output->push_back(node);
return false;
}
};
}
void flatten(const llvm::SmallVector<AST_stmt*, 4>& roots, std::vector<AST*>& output, bool expand_scopes) {
void flatten(llvm::ArrayRef<AST_stmt*> roots, std::vector<AST*>& output, bool expand_scopes) {
FlattenVisitor visitor(&output, expand_scopes);
for (int i = 0; i < roots.size(); i++) {
......
......@@ -146,7 +146,7 @@ namespace AST_TYPE {
#define GENERATE_ENUM(ENUM, N) ENUM = N,
#define GENERATE_STRING(STRING, N) m[N] = #STRING;
enum AST_TYPE { FOREACH_TYPE(GENERATE_ENUM) };
enum AST_TYPE : unsigned char { FOREACH_TYPE(GENERATE_ENUM) };
static const char* stringify(int n) {
static std::map<int, const char*> m;
......@@ -206,8 +206,6 @@ class AST_stmt : public AST {
public:
virtual void accept_stmt(ASTStmtVisitor* v) = 0;
int cxx_exception_count = 0;
AST_stmt(AST_TYPE::AST_TYPE type) : AST(type) {}
};
......@@ -220,7 +218,6 @@ public:
class AST_alias : public AST {
public:
InternedString name, asname;
int name_vreg = -1, asname_vreg = -1;
virtual void accept(ASTVisitor* v);
......@@ -352,9 +349,6 @@ public:
std::vector<AST_expr*> args;
std::vector<AST_keyword*> keywords;
// used during execution stores all keyword names
std::unique_ptr<std::vector<BoxedString*>> keywords_names;
virtual void accept(ASTVisitor* v);
AST_Call() : AST_expr(AST_TYPE::Call) {}
......@@ -723,32 +717,20 @@ public:
// different bytecodes.
ScopeInfo::VarScopeType lookup_type;
// These are only valid for lookup_type == FAST or CLOSURE
// The interpreter and baseline JIT store variables with FAST and CLOSURE scopes in an array (vregs) this specifies
// the zero based index of this variable inside the vregs array. If uninitialized it's value is -1.
int vreg;
bool is_kill = false;
// Only valid for lookup_type == DEREF:
DerefInfo deref_info = DerefInfo({ INT_MAX, INT_MAX });
// Only valid for lookup_type == CLOSURE:
int closure_offset = -1;
virtual void accept(ASTVisitor* v);
AST_Name(InternedString id, AST_TYPE::AST_TYPE ctx_type, int lineno, int col_offset = 0)
: AST_expr(AST_TYPE::Name, lineno, col_offset),
ctx_type(ctx_type),
id(id),
lookup_type(ScopeInfo::VarScopeType::UNKNOWN),
vreg(-1) {}
lookup_type(ScopeInfo::VarScopeType::UNKNOWN) {}
static const AST_TYPE::AST_TYPE TYPE = AST_TYPE::Name;
};
class AST_Num : public AST_expr {
public:
enum NumType {
enum NumType : unsigned char {
// These values must correspond to the values in parse_ast.py
INT = 0x10,
FLOAT = 0x20,
......@@ -870,7 +852,7 @@ public:
class AST_Str : public AST_expr {
public:
enum StrType {
enum StrType : unsigned char {
UNSET = 0x00,
STR = 0x10,
UNICODE = 0x20,
......@@ -987,60 +969,12 @@ public:
static const AST_TYPE::AST_TYPE TYPE = AST_TYPE::Yield;
};
class AST_MakeFunction : public AST_expr {
public:
AST_FunctionDef* function_def;
virtual void accept(ASTVisitor* v);
AST_MakeFunction(AST_FunctionDef* fd)
: AST_expr(AST_TYPE::MakeFunction, fd->lineno, fd->col_offset), function_def(fd) {}
static const AST_TYPE::AST_TYPE TYPE = AST_TYPE::MakeFunction;
};
class AST_MakeClass : public AST_expr {
public:
AST_ClassDef* class_def;
virtual void accept(ASTVisitor* v);
AST_MakeClass(AST_ClassDef* cd) : AST_expr(AST_TYPE::MakeClass, cd->lineno, cd->col_offset), class_def(cd) {}
static const AST_TYPE::AST_TYPE TYPE = AST_TYPE::MakeClass;
};
// AST pseudo-nodes that will get added during CFG-construction. These don't exist in the input AST, but adding them in
// lets us avoid creating a completely new IR for this phase
class CFGBlock;
class AST_Branch : public AST_stmt {
public:
AST_expr* test;
CFGBlock* iftrue, *iffalse;
virtual void accept(ASTVisitor* v);
virtual void accept_stmt(ASTStmtVisitor* v);
AST_Branch() : AST_stmt(AST_TYPE::Branch) {}
static const AST_TYPE::AST_TYPE TYPE = AST_TYPE::Branch;
};
class AST_Jump : public AST_stmt {
public:
CFGBlock* target;
virtual void accept(ASTVisitor* v);
virtual void accept_stmt(ASTStmtVisitor* v);
AST_Jump() : AST_stmt(AST_TYPE::Jump) {}
static const AST_TYPE::AST_TYPE TYPE = AST_TYPE::Jump;
};
class AST_ClsAttribute : public AST_expr {
public:
AST_expr* value;
......@@ -1073,7 +1007,7 @@ public:
// These are basically bytecodes, framed as pseudo-AST-nodes.
class AST_LangPrimitive : public AST_expr {
public:
enum Opcodes {
enum Opcodes : unsigned char {
LANDINGPAD, // grabs the info about the last raised exception
LOCALS,
GET_ITER,
......@@ -1102,8 +1036,6 @@ template <typename T> T* ast_cast(AST* node) {
return static_cast<T*>(node);
}
class ASTVisitor {
protected:
public:
......@@ -1170,11 +1102,6 @@ public:
virtual bool visit_while(AST_While* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_with(AST_With* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_yield(AST_Yield* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_makeclass(AST_MakeClass* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_makefunction(AST_MakeFunction* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_branch(AST_Branch* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_jump(AST_Jump* node) { RELEASE_ASSERT(0, ""); }
};
class NoopASTVisitor : public ASTVisitor {
......@@ -1243,11 +1170,6 @@ public:
virtual bool visit_while(AST_While* node) { return false; }
virtual bool visit_with(AST_With* node) { return false; }
virtual bool visit_yield(AST_Yield* node) { return false; }
virtual bool visit_branch(AST_Branch* node) { return false; }
virtual bool visit_jump(AST_Jump* node) { return false; }
virtual bool visit_makeclass(AST_MakeClass* node) { return false; }
virtual bool visit_makefunction(AST_MakeFunction* node) { return false; }
};
class ASTStmtVisitor {
......@@ -1279,9 +1201,6 @@ public:
virtual void visit_tryfinally(AST_TryFinally* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_while(AST_While* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_with(AST_With* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_branch(AST_Branch* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_jump(AST_Jump* node) { RELEASE_ASSERT(0, ""); }
};
void print_ast(AST* ast);
......@@ -1358,17 +1277,12 @@ public:
virtual bool visit_while(AST_While* node);
virtual bool visit_with(AST_With* node);
virtual bool visit_yield(AST_Yield* node);
virtual bool visit_branch(AST_Branch* node);
virtual bool visit_jump(AST_Jump* node);
virtual bool visit_makefunction(AST_MakeFunction* node);
virtual bool visit_makeclass(AST_MakeClass* node);
};
// Given an AST node, return a vector of the node plus all its descendents.
// This is useful for analyses that care more about the constituent nodes than the
// exact tree structure; ex, finding all "global" directives.
void flatten(const llvm::SmallVector<AST_stmt*, 4>& roots, std::vector<AST*>& output, bool expand_scopes);
void flatten(llvm::ArrayRef<AST_stmt*> roots, std::vector<AST*>& output, bool expand_scopes);
void flatten(AST_expr* root, std::vector<AST*>& output, bool expand_scopes);
// Similar to the flatten() function, but filters for a specific type of ast nodes:
template <class T, class R> void findNodes(const R& roots, std::vector<T*>& output, bool expand_scopes) {
......
......@@ -49,12 +49,6 @@ static void visitCFG(CFG* cfg, BSTVisitor* v) {
e->accept(v);
}
void BST_alias::accept(BSTVisitor* v) {
bool skip = v->visit_alias(this);
if (skip)
return;
}
void BST_arguments::accept(BSTVisitor* v) {
bool skip = v->visit_arguments(this);
if (skip)
......@@ -83,32 +77,13 @@ void BST_Assign::accept(BSTVisitor* v) {
return;
value->accept(v);
for (int i = 0; i < targets.size(); i++) {
// Targets are assigned to left-to-right, so this is valid:
// x = x.a = object()
// but this is not:
// x.a = x = object()
targets[i]->accept(v);
}
target->accept(v);
}
void BST_Assign::accept_stmt(StmtVisitor* v) {
v->visit_assign(this);
}
void BST_AugAssign::accept(BSTVisitor* v) {
bool skip = v->visit_augassign(this);
if (skip)
return;
value->accept(v);
target->accept(v);
}
void BST_AugAssign::accept_stmt(StmtVisitor* v) {
v->visit_augassign(this);
}
void BST_AugBinOp::accept(BSTVisitor* v) {
bool skip = v->visit_augbinop(this);
if (skip)
......@@ -147,28 +122,6 @@ void* BST_BinOp::accept_expr(ExprVisitor* v) {
return v->visit_binop(this);
}
void BST_BoolOp::accept(BSTVisitor* v) {
bool skip = v->visit_boolop(this);
if (skip)
return;
visitVector(values, v);
}
void* BST_BoolOp::accept_expr(ExprVisitor* v) {
return v->visit_boolop(this);
}
void BST_Break::accept(BSTVisitor* v) {
bool skip = v->visit_break(this);
if (skip)
return;
}
void BST_Break::accept_stmt(StmtVisitor* v) {
v->visit_break(this);
}
void BST_Call::accept(BSTVisitor* v) {
bool skip = v->visit_call(this);
if (skip)
......@@ -193,25 +146,13 @@ void BST_Compare::accept(BSTVisitor* v) {
return;
left->accept(v);
visitVector(comparators, v);
comparator->accept(v);
}
void* BST_Compare::accept_expr(ExprVisitor* v) {
return v->visit_compare(this);
}
void BST_comprehension::accept(BSTVisitor* v) {
bool skip = v->visit_comprehension(this);
if (skip)
return;
target->accept(v);
iter->accept(v);
for (auto if_ : ifs) {
if_->accept(v);
}
}
void BST_ClassDef::accept(BSTVisitor* v) {
bool skip = v->visit_classdef(this);
if (skip)
......@@ -226,22 +167,12 @@ void BST_ClassDef::accept_stmt(StmtVisitor* v) {
v->visit_classdef(this);
}
void BST_Continue::accept(BSTVisitor* v) {
bool skip = v->visit_continue(this);
if (skip)
return;
}
void BST_Continue::accept_stmt(StmtVisitor* v) {
v->visit_continue(this);
}
void BST_Delete::accept(BSTVisitor* v) {
bool skip = v->visit_delete(this);
if (skip)
return;
visitVector(this->targets, v);
target->accept(v);
}
void BST_Delete::accept_stmt(StmtVisitor* v) {
......@@ -263,23 +194,6 @@ void* BST_Dict::accept_expr(ExprVisitor* v) {
return v->visit_dict(this);
}
void BST_DictComp::accept(BSTVisitor* v) {
bool skip = v->visit_dictcomp(this);
if (skip)
return;
for (auto c : generators) {
c->accept(v);
}
value->accept(v);
key->accept(v);
}
void* BST_DictComp::accept_expr(ExprVisitor* v) {
return v->visit_dictcomp(this);
}
void BST_Ellipsis::accept(BSTVisitor* v) {
bool skip = v->visit_ellipsis(this);
if (skip)
......@@ -290,18 +204,6 @@ void* BST_Ellipsis::accept_slice(SliceVisitor* v) {
return v->visit_ellipsis(this);
}
void BST_ExceptHandler::accept(BSTVisitor* v) {
bool skip = v->visit_excepthandler(this);
if (skip)
return;
if (type)
type->accept(v);
if (name)
name->accept(v);
visitVector(body, v);
}
void BST_Exec::accept(BSTVisitor* v) {
bool skip = v->visit_exec(this);
if (skip)
......@@ -343,21 +245,6 @@ void* BST_ExtSlice::accept_slice(SliceVisitor* v) {
return v->visit_extslice(this);
}
void BST_For::accept(BSTVisitor* v) {
bool skip = v->visit_for(this);
if (skip)
return;
iter->accept(v);
target->accept(v);
visitVector(body, v);
visitVector(orelse, v);
}
void BST_For::accept_stmt(StmtVisitor* v) {
v->visit_for(this);
}
void BST_FunctionDef::accept(BSTVisitor* v) {
bool skip = v->visit_functiondef(this);
if (skip)
......@@ -372,84 +259,6 @@ void BST_FunctionDef::accept_stmt(StmtVisitor* v) {
v->visit_functiondef(this);
}
void BST_GeneratorExp::accept(BSTVisitor* v) {
bool skip = v->visit_generatorexp(this);
if (skip)
return;
for (auto c : generators) {
c->accept(v);
}
elt->accept(v);
}
void* BST_GeneratorExp::accept_expr(ExprVisitor* v) {
return v->visit_generatorexp(this);
}
void BST_Global::accept(BSTVisitor* v) {
bool skip = v->visit_global(this);
if (skip)
return;
}
void BST_Global::accept_stmt(StmtVisitor* v) {
v->visit_global(this);
}
void BST_If::accept(BSTVisitor* v) {
bool skip = v->visit_if(this);
if (skip)
return;
test->accept(v);
visitVector(body, v);
visitVector(orelse, v);
}
void BST_If::accept_stmt(StmtVisitor* v) {
v->visit_if(this);
}
void BST_IfExp::accept(BSTVisitor* v) {
bool skip = v->visit_ifexp(this);
if (skip)
return;
this->test->accept(v);
this->body->accept(v);
this->orelse->accept(v);
}
void* BST_IfExp::accept_expr(ExprVisitor* v) {
return v->visit_ifexp(this);
}
void BST_Import::accept(BSTVisitor* v) {
bool skip = v->visit_import(this);
if (skip)
return;
visitVector(names, v);
}
void BST_Import::accept_stmt(StmtVisitor* v) {
v->visit_import(this);
}
void BST_ImportFrom::accept(BSTVisitor* v) {
bool skip = v->visit_importfrom(this);
if (skip)
return;
visitVector(names, v);
}
void BST_ImportFrom::accept_stmt(StmtVisitor* v) {
v->visit_importfrom(this);
}
void BST_Index::accept(BSTVisitor* v) {
bool skip = v->visit_index(this);
if (skip)
......@@ -482,19 +291,6 @@ void BST_keyword::accept(BSTVisitor* v) {
value->accept(v);
}
void BST_Lambda::accept(BSTVisitor* v) {
bool skip = v->visit_lambda(this);
if (skip)
return;
args->accept(v);
body->accept(v);
}
void* BST_Lambda::accept_expr(ExprVisitor* v) {
return v->visit_lambda(this);
}
void BST_LangPrimitive::accept(BSTVisitor* v) {
bool skip = v->visit_langprimitive(this);
if (skip)
......@@ -519,46 +315,6 @@ void* BST_List::accept_expr(ExprVisitor* v) {
return v->visit_list(this);
}
void BST_ListComp::accept(BSTVisitor* v) {
bool skip = v->visit_listcomp(this);
if (skip)
return;
for (auto c : generators) {
c->accept(v);
}
elt->accept(v);
}
void* BST_ListComp::accept_expr(ExprVisitor* v) {
return v->visit_listcomp(this);
}
void BST_Module::accept(BSTVisitor* v) {
bool skip = v->visit_module(this);
if (skip)
return;
visitVector(body, v);
}
void BST_Expression::accept(BSTVisitor* v) {
bool skip = v->visit_expression(this);
if (skip)
return;
body->accept(v);
}
void BST_Suite::accept(BSTVisitor* v) {
bool skip = v->visit_suite(this);
if (skip)
return;
visitVector(body, v);
}
void BST_Name::accept(BSTVisitor* v) {
bool skip = v->visit_name(this);
}
......@@ -575,14 +331,6 @@ void* BST_Num::accept_expr(ExprVisitor* v) {
return v->visit_num(this);
}
void BST_Pass::accept(BSTVisitor* v) {
bool skip = v->visit_pass(this);
}
void BST_Pass::accept_stmt(StmtVisitor* v) {
v->visit_pass(this);
}
void BST_Print::accept(BSTVisitor* v) {
bool skip = v->visit_print(this);
if (skip)
......@@ -590,7 +338,9 @@ void BST_Print::accept(BSTVisitor* v) {
if (dest)
dest->accept(v);
visitVector(values, v);
if (value)
value->accept(v);
}
void BST_Print::accept_stmt(StmtVisitor* v) {
......@@ -651,22 +401,6 @@ void* BST_Set::accept_expr(ExprVisitor* v) {
return v->visit_set(this);
}
void BST_SetComp::accept(BSTVisitor* v) {
bool skip = v->visit_setcomp(this);
if (skip)
return;
for (auto c : generators) {
c->accept(v);
}
elt->accept(v);
}
void* BST_SetComp::accept_expr(ExprVisitor* v) {
return v->visit_setcomp(this);
}
void BST_Slice::accept(BSTVisitor* v) {
bool skip = v->visit_slice(this);
if (skip)
......@@ -707,33 +441,6 @@ void* BST_Subscript::accept_expr(ExprVisitor* v) {
return v->visit_subscript(this);
}
void BST_TryExcept::accept(BSTVisitor* v) {
bool skip = v->visit_tryexcept(this);
if (skip)
return;
visitVector(body, v);
visitVector(orelse, v);
visitVector(handlers, v);
}
void BST_TryExcept::accept_stmt(StmtVisitor* v) {
v->visit_tryexcept(this);
}
void BST_TryFinally::accept(BSTVisitor* v) {
bool skip = v->visit_tryfinally(this);
if (skip)
return;
visitVector(body, v);
visitVector(finalbody, v);
}
void BST_TryFinally::accept_stmt(StmtVisitor* v) {
v->visit_tryfinally(this);
}
void BST_Tuple::accept(BSTVisitor* v) {
bool skip = v->visit_tuple(this);
if (skip)
......@@ -758,35 +465,6 @@ void* BST_UnaryOp::accept_expr(ExprVisitor* v) {
return v->visit_unaryop(this);
}
void BST_While::accept(BSTVisitor* v) {
bool skip = v->visit_while(this);
if (skip)
return;
test->accept(v);
visitVector(body, v);
visitVector(orelse, v);
}
void BST_While::accept_stmt(StmtVisitor* v) {
v->visit_while(this);
}
void BST_With::accept(BSTVisitor* v) {
bool skip = v->visit_with(this);
if (skip)
return;
context_expr->accept(v);
if (optional_vars)
optional_vars->accept(v);
visitVector(body, v);
}
void BST_With::accept_stmt(StmtVisitor* v) {
v->visit_with(this);
}
void BST_Yield::accept(BSTVisitor* v) {
bool skip = v->visit_yield(this);
if (skip)
......@@ -870,13 +548,6 @@ void PrintVisitor::printIndent() {
}
}
bool PrintVisitor::visit_alias(BST_alias* node) {
stream << node->name.s();
if (node->asname.s().size())
stream << " as " << node->asname.s();
return true;
}
bool PrintVisitor::visit_arguments(BST_arguments* node) {
int ndefault = node->defaults.size();
for (int i = 0; i < ndefault; i++) {
......@@ -900,10 +571,8 @@ bool PrintVisitor::visit_assert(BST_Assert* node) {
}
bool PrintVisitor::visit_assign(BST_Assign* node) {
for (int i = 0; i < node->targets.size(); i++) {
node->targets[i]->accept(this);
node->target->accept(this);
stream << " = ";
}
node->value->accept(this);
return true;
}
......@@ -949,14 +618,6 @@ void PrintVisitor::printOp(AST_TYPE::AST_TYPE op_type) {
}
}
bool PrintVisitor::visit_augassign(BST_AugAssign* node) {
node->target->accept(this);
printOp(node->op_type);
stream << '=';
node->value->accept(this);
return true;
}
bool PrintVisitor::visit_augbinop(BST_AugBinOp* node) {
node->left->accept(this);
stream << '=';
......@@ -979,32 +640,6 @@ bool PrintVisitor::visit_binop(BST_BinOp* node) {
return true;
}
bool PrintVisitor::visit_boolop(BST_BoolOp* node) {
for (int i = 0; i < node->values.size(); i++) {
node->values[i]->accept(this);
if (i == node->values.size() - 1)
continue;
switch (node->op_type) {
case BST_TYPE::And:
stream << " and ";
break;
case BST_TYPE::Or:
stream << " or ";
break;
default:
ASSERT(0, "%d", node->op_type);
break;
}
}
return true;
}
bool PrintVisitor::visit_break(BST_Break* node) {
stream << "break";
return true;
}
bool PrintVisitor::visit_call(BST_Call* node) {
node->func->accept(this);
stream << "(";
......@@ -1040,27 +675,8 @@ bool PrintVisitor::visit_call(BST_Call* node) {
bool PrintVisitor::visit_compare(BST_Compare* node) {
node->left->accept(this);
for (int i = 0; i < node->ops.size(); i++) {
std::string symbol = getOpSymbol(node->ops[i]);
stream << " " << symbol << " ";
node->comparators[i]->accept(this);
}
return true;
}
bool PrintVisitor::visit_comprehension(BST_comprehension* node) {
stream << "for ";
node->target->accept(this);
stream << " in ";
node->iter->accept(this);
for (BST_expr* i : node->ifs) {
stream << " if ";
i->accept(this);
}
stream << " " << getOpSymbol(node->op) << " ";
node->comparator->accept(this);
return true;
}
......@@ -1096,18 +712,9 @@ bool PrintVisitor::visit_classdef(BST_ClassDef* node) {
return true;
}
bool PrintVisitor::visit_continue(BST_Continue* node) {
stream << "continue";
return true;
}
bool PrintVisitor::visit_delete(BST_Delete* node) {
stream << "del ";
for (int i = 0; i < node->targets.size(); i++) {
if (i > 0)
stream << ", ";
node->targets[i]->accept(this);
}
node->target->accept(this);
return true;
}
......@@ -1124,46 +731,11 @@ bool PrintVisitor::visit_dict(BST_Dict* node) {
return true;
}
bool PrintVisitor::visit_dictcomp(BST_DictComp* node) {
stream << "{";
node->key->accept(this);
stream << ":";
node->value->accept(this);
for (auto c : node->generators) {
stream << " ";
c->accept(this);
}
stream << "}";
return true;
}
bool PrintVisitor::visit_ellipsis(BST_Ellipsis*) {
stream << "...";
return true;
}
bool PrintVisitor::visit_excepthandler(BST_ExceptHandler* node) {
stream << "except";
if (node->type) {
stream << " ";
node->type->accept(this);
}
if (node->name) {
stream << " as ";
node->name->accept(this);
}
stream << ":\n";
indent += 4;
for (BST* subnode : node->body) {
printIndent();
subnode->accept(this);
stream << "\n";
}
indent -= 4;
return true;
}
bool PrintVisitor::visit_exec(BST_Exec* node) {
stream << "exec ";
......@@ -1194,11 +766,6 @@ bool PrintVisitor::visit_extslice(BST_ExtSlice* node) {
return true;
}
bool PrintVisitor::visit_for(BST_For* node) {
stream << "<for loop>\n";
return true;
}
bool PrintVisitor::visit_functiondef(BST_FunctionDef* node) {
for (auto d : node->decorator_list) {
stream << "@";
......@@ -1231,94 +798,6 @@ bool PrintVisitor::visit_functiondef(BST_FunctionDef* node) {
return true;
}
bool PrintVisitor::visit_generatorexp(BST_GeneratorExp* node) {
stream << "[";
node->elt->accept(this);
for (auto c : node->generators) {
stream << " ";
c->accept(this);
}
stream << "]";
return true;
}
bool PrintVisitor::visit_global(BST_Global* node) {
stream << "global ";
for (int i = 0; i < node->names.size(); i++) {
if (i > 0)
stream << ", ";
stream << node->names[i].s();
}
return true;
}
bool PrintVisitor::visit_if(BST_If* node) {
stream << "if ";
node->test->accept(this);
stream << ":\n";
indent += 4;
for (int i = 0; i < node->body.size(); i++) {
printIndent();
node->body[i]->accept(this);
stream << "\n";
}
indent -= 4;
if (node->orelse.size()) {
printIndent();
bool elif = false;
if (node->orelse.size() == 1 && node->orelse[0]->type == BST_TYPE::If)
elif = true;
if (elif) {
stream << "el";
} else {
stream << "else:\n";
indent += 4;
}
for (int i = 0; i < node->orelse.size(); i++) {
if (i)
stream << "\n";
printIndent();
node->orelse[i]->accept(this);
}
if (!elif)
indent -= 4;
}
return true;
}
bool PrintVisitor::visit_ifexp(BST_IfExp* node) {
node->body->accept(this);
stream << " if ";
node->test->accept(this);
stream << " else ";
node->orelse->accept(this);
return true;
}
bool PrintVisitor::visit_import(BST_Import* node) {
stream << "import ";
for (int i = 0; i < node->names.size(); i++) {
if (i > 0)
stream << ", ";
node->names[i]->accept(this);
}
return true;
}
bool PrintVisitor::visit_importfrom(BST_ImportFrom* node) {
stream << "from " << node->module.s() << " import ";
for (int i = 0; i < node->names.size(); i++) {
if (i > 0)
stream << ", ";
node->names[i]->accept(this);
}
return true;
}
bool PrintVisitor::visit_index(BST_Index* node) {
return false;
}
......@@ -1329,14 +808,6 @@ bool PrintVisitor::visit_invoke(BST_Invoke* node) {
return true;
}
bool PrintVisitor::visit_lambda(BST_Lambda* node) {
stream << "lambda ";
node->args->accept(this);
stream << ": ";
node->body->accept(this);
return true;
}
bool PrintVisitor::visit_langprimitive(BST_LangPrimitive* node) {
stream << ":";
switch (node->opcode) {
......@@ -1403,47 +874,12 @@ bool PrintVisitor::visit_list(BST_List* node) {
return true;
}
bool PrintVisitor::visit_listcomp(BST_ListComp* node) {
stream << "[";
node->elt->accept(this);
for (auto c : node->generators) {
stream << " ";
c->accept(this);
}
stream << "]";
return true;
}
bool PrintVisitor::visit_keyword(BST_keyword* node) {
stream << node->arg.s() << "=";
node->value->accept(this);
return true;
}
bool PrintVisitor::visit_module(BST_Module* node) {
// stream << "<module>\n";
for (int i = 0; i < node->body.size(); i++) {
node->body[i]->accept(this);
stream << "\n";
}
return true;
}
bool PrintVisitor::visit_expression(BST_Expression* node) {
node->body->accept(this);
stream << "\n";
return true;
}
bool PrintVisitor::visit_suite(BST_Suite* node) {
for (int i = 0; i < node->body.size(); i++) {
printIndent();
node->body[i]->accept(this);
stream << "\n";
}
return true;
}
bool PrintVisitor::visit_name(BST_Name* node) {
stream << node->id.s();
#if 0
......@@ -1482,11 +918,6 @@ bool PrintVisitor::visit_num(BST_Num* node) {
return false;
}
bool PrintVisitor::visit_pass(BST_Pass* node) {
stream << "pass";
return true;
}
bool PrintVisitor::visit_print(BST_Print* node) {
stream << "print ";
if (node->dest) {
......@@ -1494,11 +925,8 @@ bool PrintVisitor::visit_print(BST_Print* node) {
node->dest->accept(this);
stream << ", ";
}
for (int i = 0; i < node->values.size(); i++) {
if (i > 0)
stream << ", ";
node->values[i]->accept(this);
}
if (node->value)
node->value->accept(this);
if (!node->nl)
stream << ",";
return true;
......@@ -1555,17 +983,6 @@ bool PrintVisitor::visit_set(BST_Set* node) {
return true;
}
bool PrintVisitor::visit_setcomp(BST_SetComp* node) {
stream << "{";
node->elt->accept(this);
for (auto c : node->generators) {
stream << " ";
c->accept(this);
}
stream << "}";
return true;
}
bool PrintVisitor::visit_slice(BST_Slice* node) {
stream << "<slice>(";
if (node->lower)
......@@ -1601,70 +1018,6 @@ bool PrintVisitor::visit_subscript(BST_Subscript* node) {
return true;
}
bool PrintVisitor::visit_tryexcept(BST_TryExcept* node) {
stream << "try:\n";
indent += 4;
for (BST* subnode : node->body) {
printIndent();
subnode->accept(this);
stream << "\n";
}
indent -= 4;
for (BST_ExceptHandler* handler : node->handlers) {
printIndent();
handler->accept(this);
}
if (node->orelse.size()) {
printIndent();
stream << "else:\n";
indent += 4;
for (BST* subnode : node->orelse) {
printIndent();
subnode->accept(this);
stream << "\n";
}
indent -= 4;
}
return true;
}
bool PrintVisitor::visit_tryfinally(BST_TryFinally* node) {
if (node->body.size() == 1 && node->body[0]->type == BST_TYPE::TryExcept) {
node->body[0]->accept(this);
printIndent();
stream << "finally:\n";
indent += 4;
for (BST* subnode : node->finalbody) {
printIndent();
subnode->accept(this);
stream << "\n";
}
indent -= 4;
} else {
stream << "try:\n";
indent += 4;
for (BST* subnode : node->body) {
printIndent();
subnode->accept(this);
stream << "\n";
}
indent -= 4;
printIndent();
stream << "finally:\n";
indent += 4;
for (BST* subnode : node->finalbody) {
printIndent();
subnode->accept(this);
stream << "\n";
}
indent -= 4;
}
return true;
}
bool PrintVisitor::visit_tuple(BST_Tuple* node) {
stream << "(";
int n = node->elts.size();
......@@ -1703,54 +1056,6 @@ bool PrintVisitor::visit_unaryop(BST_UnaryOp* node) {
return true;
}
bool PrintVisitor::visit_while(BST_While* node) {
stream << "while ";
node->test->accept(this);
stream << "\n";
indent += 4;
for (int i = 0; i < node->body.size(); i++) {
printIndent();
node->body[i]->accept(this);
stream << "\n";
}
indent -= 4;
if (node->orelse.size()) {
printIndent();
stream << "else\n";
indent += 4;
for (int i = 0; i < node->orelse.size(); i++) {
printIndent();
node->orelse[i]->accept(this);
stream << "\n";
}
indent -= 4;
}
return true;
}
bool PrintVisitor::visit_with(BST_With* node) {
stream << "with ";
node->context_expr->accept(this);
if (node->optional_vars) {
stream << " as ";
node->optional_vars->accept(this);
stream << ":\n";
}
indent += 4;
for (int i = 0; i < node->body.size(); i++) {
if (i > 0)
stream << "\n";
printIndent();
node->body[i]->accept(this);
}
indent -= 4;
return true;
}
bool PrintVisitor::visit_yield(BST_Yield* node) {
stream << "yield ";
if (node->value)
......@@ -1789,6 +1094,7 @@ bool PrintVisitor::visit_makeclass(BST_MakeClass* node) {
return false;
}
namespace {
class FlattenVisitor : public BSTVisitor {
private:
std::vector<BST*>* output;
......@@ -1799,10 +1105,6 @@ public:
assert(expand_scopes && "not sure if this works properly");
}
virtual bool visit_alias(BST_alias* node) {
output->push_back(node);
return false;
}
virtual bool visit_arguments(BST_arguments* node) {
output->push_back(node);
return false;
......@@ -1815,10 +1117,6 @@ public:
output->push_back(node);
return false;
}
virtual bool visit_augassign(BST_AugAssign* node) {
output->push_back(node);
return false;
}
virtual bool visit_augbinop(BST_AugBinOp* node) {
output->push_back(node);
return false;
......@@ -1831,14 +1129,6 @@ public:
output->push_back(node);
return false;
}
virtual bool visit_boolop(BST_BoolOp* node) {
output->push_back(node);
return false;
}
virtual bool visit_break(BST_Break* node) {
output->push_back(node);
return false;
}
virtual bool visit_call(BST_Call* node) {
output->push_back(node);
return false;
......@@ -1851,14 +1141,6 @@ public:
output->push_back(node);
return false;
}
virtual bool visit_comprehension(BST_comprehension* node) {
output->push_back(node);
return false;
}
virtual bool visit_continue(BST_Continue* node) {
output->push_back(node);
return false;
}
virtual bool visit_delete(BST_Delete* node) {
output->push_back(node);
return false;
......@@ -1867,18 +1149,10 @@ public:
output->push_back(node);
return false;
}
virtual bool visit_dictcomp(BST_DictComp* node) {
output->push_back(node);
return false;
}
virtual bool visit_ellipsis(BST_Ellipsis* node) {
output->push_back(node);
return false;
}
virtual bool visit_excepthandler(BST_ExceptHandler* node) {
output->push_back(node);
return false;
}
virtual bool visit_exec(BST_Exec* node) {
output->push_back(node);
return false;
......@@ -1891,38 +1165,10 @@ public:
output->push_back(node);
return false;
}
virtual bool visit_for(BST_For* node) {
output->push_back(node);
return !expand_scopes;
}
virtual bool visit_functiondef(BST_FunctionDef* node) {
output->push_back(node);
return !expand_scopes;
}
virtual bool visit_generatorexp(BST_GeneratorExp* node) {
output->push_back(node);
return !expand_scopes;
}
virtual bool visit_global(BST_Global* node) {
output->push_back(node);
return false;
}
virtual bool visit_if(BST_If* node) {
output->push_back(node);
return false;
}
virtual bool visit_ifexp(BST_IfExp* node) {
output->push_back(node);
return false;
}
virtual bool visit_import(BST_Import* node) {
output->push_back(node);
return false;
}
virtual bool visit_importfrom(BST_ImportFrom* node) {
output->push_back(node);
return false;
}
virtual bool visit_index(BST_Index* node) {
output->push_back(node);
return false;
......@@ -1935,10 +1181,6 @@ public:
output->push_back(node);
return false;
}
virtual bool visit_lambda(BST_Lambda* node) {
output->push_back(node);
return !expand_scopes;
}
virtual bool visit_langprimitive(BST_LangPrimitive* node) {
output->push_back(node);
return false;
......@@ -1947,14 +1189,6 @@ public:
output->push_back(node);
return false;
}
virtual bool visit_listcomp(BST_ListComp* node) {
output->push_back(node);
return false;
}
virtual bool visit_module(BST_Module* node) {
output->push_back(node);
return !expand_scopes;
}
virtual bool visit_name(BST_Name* node) {
output->push_back(node);
return false;
......@@ -1963,10 +1197,6 @@ public:
output->push_back(node);
return false;
}
virtual bool visit_pass(BST_Pass* node) {
output->push_back(node);
return false;
}
virtual bool visit_print(BST_Print* node) {
output->push_back(node);
return false;
......@@ -1987,10 +1217,6 @@ public:
output->push_back(node);
return false;
}
virtual bool visit_setcomp(BST_SetComp* node) {
output->push_back(node);
return false;
}
virtual bool visit_slice(BST_Slice* node) {
output->push_back(node);
return false;
......@@ -2003,14 +1229,6 @@ public:
output->push_back(node);
return false;
}
virtual bool visit_tryexcept(BST_TryExcept* node) {
output->push_back(node);
return false;
}
virtual bool visit_tryfinally(BST_TryFinally* node) {
output->push_back(node);
return false;
}
virtual bool visit_tuple(BST_Tuple* node) {
output->push_back(node);
return false;
......@@ -2019,14 +1237,6 @@ public:
output->push_back(node);
return false;
}
virtual bool visit_while(BST_While* node) {
output->push_back(node);
return false;
}
virtual bool visit_with(BST_With* node) {
output->push_back(node);
return false;
}
virtual bool visit_yield(BST_Yield* node) {
output->push_back(node);
return false;
......@@ -2054,8 +1264,9 @@ public:
return false;
}
};
}
void flatten(const llvm::SmallVector<BST_stmt*, 4>& roots, std::vector<BST*>& output, bool expand_scopes) {
void flatten(llvm::ArrayRef<BST_stmt*> roots, std::vector<BST*>& output, bool expand_scopes) {
FlattenVisitor visitor(&output, expand_scopes);
for (int i = 0; i < roots.size(); i++) {
......
......@@ -147,7 +147,7 @@ namespace BST_TYPE {
#define GENERATE_ENUM(ENUM, N) ENUM = N,
#define GENERATE_STRING(STRING, N) m[N] = #STRING;
enum BST_TYPE { FOREACH_TYPE(GENERATE_ENUM) };
enum BST_TYPE : unsigned char { FOREACH_TYPE(GENERATE_ENUM) };
static const char* stringify(int n) {
static std::map<int, const char*> m;
......@@ -171,7 +171,7 @@ public:
virtual ~BST() {}
const BST_TYPE::BST_TYPE type;
uint32_t lineno, col_offset;
uint32_t lineno;
virtual void accept(BSTVisitor* v) = 0;
......@@ -185,10 +185,9 @@ private:
public:
BST(BST_TYPE::BST_TYPE type);
#else
BST(BST_TYPE::BST_TYPE type) : type(type), lineno(0), col_offset(0) {}
BST(BST_TYPE::BST_TYPE type) : type(type), lineno(0) {}
#endif
BST(BST_TYPE::BST_TYPE type, uint32_t lineno, uint32_t col_offset = 0)
: type(type), lineno(lineno), col_offset(col_offset) {}
BST(BST_TYPE::BST_TYPE type, uint32_t lineno) : type(type), lineno(lineno) {}
};
class BST_expr : public BST {
......@@ -196,7 +195,7 @@ public:
virtual void* accept_expr(ExprVisitor* v) = 0;
BST_expr(BST_TYPE::BST_TYPE type) : BST(type) {}
BST_expr(BST_TYPE::BST_TYPE type, uint32_t lineno, uint32_t col_offset = 0) : BST(type, lineno, col_offset) {}
BST_expr(BST_TYPE::BST_TYPE type, uint32_t lineno) : BST(type, lineno) {}
};
class BST_stmt : public BST {
......@@ -212,26 +211,14 @@ class BST_slice : public BST {
public:
virtual void* accept_slice(SliceVisitor* s) = 0;
BST_slice(BST_TYPE::BST_TYPE type) : BST(type) {}
BST_slice(BST_TYPE::BST_TYPE type, uint32_t lineno, uint32_t col_offset = 0) : BST(type, lineno, col_offset) {}
};
class BST_alias : public BST {
public:
InternedString name, asname;
int name_vreg = -1, asname_vreg = -1;
virtual void accept(BSTVisitor* v);
BST_alias(InternedString name, InternedString asname) : BST(BST_TYPE::alias), name(name), asname(asname) {}
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::alias;
BST_slice(BST_TYPE::BST_TYPE type, uint32_t lineno) : BST(type, lineno) {}
};
class BST_Name;
class BST_arguments : public BST {
public:
// no lineno, col_offset attributes
// no lineno attributes
std::vector<BST_expr*> defaults;
virtual void accept(BSTVisitor* v);
......@@ -255,7 +242,7 @@ public:
class BST_Assign : public BST_stmt {
public:
std::vector<BST_expr*> targets;
BST_expr* target;
BST_expr* value;
virtual void accept(BSTVisitor* v);
......@@ -266,20 +253,6 @@ public:
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::Assign;
};
class BST_AugAssign : public BST_stmt {
public:
BST_expr* value;
BST_expr* target;
AST_TYPE::AST_TYPE op_type;
virtual void accept(BSTVisitor* v);
virtual void accept_stmt(StmtVisitor* v);
BST_AugAssign() : BST_stmt(BST_TYPE::AugAssign) {}
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::AugAssign;
};
class BST_AugBinOp : public BST_expr {
public:
AST_TYPE::AST_TYPE op_type;
......@@ -323,29 +296,6 @@ public:
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::BinOp;
};
class BST_BoolOp : public BST_expr {
public:
AST_TYPE::AST_TYPE op_type;
std::vector<BST_expr*> values;
virtual void accept(BSTVisitor* v);
virtual void* accept_expr(ExprVisitor* v);
BST_BoolOp() : BST_expr(BST_TYPE::BoolOp) {}
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::BoolOp;
};
class BST_Break : public BST_stmt {
public:
virtual void accept(BSTVisitor* v);
virtual void accept_stmt(StmtVisitor* v);
BST_Break() : BST_stmt(BST_TYPE::Break) {}
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::Break;
};
class BST_Call : public BST_expr {
public:
BST_expr* starargs, *kwargs, *func;
......@@ -365,8 +315,8 @@ public:
class BST_Compare : public BST_expr {
public:
std::vector<AST_TYPE::AST_TYPE> ops;
std::vector<BST_expr*> comparators;
AST_TYPE::AST_TYPE op;
BST_expr* comparator;
BST_expr* left;
virtual void accept(BSTVisitor* v);
......@@ -377,19 +327,6 @@ public:
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::Compare;
};
class BST_comprehension : public BST {
public:
BST_expr* target;
BST_expr* iter;
std::vector<BST_expr*> ifs;
virtual void accept(BSTVisitor* v);
BST_comprehension() : BST(BST_TYPE::comprehension) {}
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::comprehension;
};
class BST_ClassDef : public BST_stmt {
public:
virtual void accept(BSTVisitor* v);
......@@ -405,16 +342,6 @@ public:
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::ClassDef;
};
class BST_Continue : public BST_stmt {
public:
virtual void accept(BSTVisitor* v);
virtual void accept_stmt(StmtVisitor* v);
BST_Continue() : BST_stmt(BST_TYPE::Continue) {}
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::Continue;
};
class BST_Dict : public BST_expr {
public:
std::vector<BST_expr*> keys, values;
......@@ -427,22 +354,9 @@ public:
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::Dict;
};
class BST_DictComp : public BST_expr {
public:
std::vector<BST_comprehension*> generators;
BST_expr* key, *value;
virtual void accept(BSTVisitor* v);
virtual void* accept_expr(ExprVisitor* v);
BST_DictComp() : BST_expr(BST_TYPE::DictComp) {}
const static BST_TYPE::BST_TYPE TYPE = BST_TYPE::DictComp;
};
class BST_Delete : public BST_stmt {
public:
std::vector<BST_expr*> targets;
BST_expr* target;
virtual void accept(BSTVisitor* v);
virtual void accept_stmt(StmtVisitor* v);
......@@ -474,19 +388,6 @@ public:
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::Expr;
};
class BST_ExceptHandler : public BST {
public:
std::vector<BST_stmt*> body;
BST_expr* type; // can be NULL for a bare "except:" clause
BST_expr* name; // can be NULL if the exception doesn't get a name
virtual void accept(BSTVisitor* v);
BST_ExceptHandler() : BST(BST_TYPE::ExceptHandler) {}
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::ExceptHandler;
};
class BST_Exec : public BST_stmt {
public:
BST_expr* body;
......@@ -501,22 +402,6 @@ public:
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::Exec;
};
// (Alternative to BST_Module, used for, e.g., eval)
class BST_Expression : public BST {
public:
std::unique_ptr<InternedStringPool> interned_strings;
// this should be an expr but we convert it into a BST_Return(BST_expr) to make the code simpler
BST_stmt* body;
virtual void accept(BSTVisitor* v);
BST_Expression(std::unique_ptr<InternedStringPool> interned_strings)
: BST(BST_TYPE::Expression), interned_strings(std::move(interned_strings)) {}
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::Expression;
};
class BST_ExtSlice : public BST_slice {
public:
std::vector<BST_slice*> dims;
......@@ -529,19 +414,6 @@ public:
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::ExtSlice;
};
class BST_For : public BST_stmt {
public:
std::vector<BST_stmt*> body, orelse;
BST_expr* target, *iter;
virtual void accept(BSTVisitor* v);
virtual void accept_stmt(StmtVisitor* v);
BST_For() : BST_stmt(BST_TYPE::For) {}
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::For;
};
class BST_FunctionDef : public BST_stmt {
public:
std::vector<BST_expr*> decorator_list;
......@@ -558,82 +430,6 @@ public:
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::FunctionDef;
};
class BST_GeneratorExp : public BST_expr {
public:
std::vector<BST_comprehension*> generators;
BST_expr* elt;
virtual void accept(BSTVisitor* v);
virtual void* accept_expr(ExprVisitor* v);
BST_GeneratorExp() : BST_expr(BST_TYPE::GeneratorExp) {}
const static BST_TYPE::BST_TYPE TYPE = BST_TYPE::GeneratorExp;
};
class BST_Global : public BST_stmt {
public:
std::vector<InternedString> names;
virtual void accept(BSTVisitor* v);
virtual void accept_stmt(StmtVisitor* v);
BST_Global() : BST_stmt(BST_TYPE::Global) {}
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::Global;
};
class BST_If : public BST_stmt {
public:
std::vector<BST_stmt*> body, orelse;
BST_expr* test;
virtual void accept(BSTVisitor* v);
virtual void accept_stmt(StmtVisitor* v);
BST_If() : BST_stmt(BST_TYPE::If) {}
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::If;
};
class BST_IfExp : public BST_expr {
public:
BST_expr* body, *test, *orelse;
virtual void accept(BSTVisitor* v);
virtual void* accept_expr(ExprVisitor* v);
BST_IfExp() : BST_expr(BST_TYPE::IfExp) {}
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::IfExp;
};
class BST_Import : public BST_stmt {
public:
std::vector<BST_alias*> names;
virtual void accept(BSTVisitor* v);
virtual void accept_stmt(StmtVisitor* v);
BST_Import() : BST_stmt(BST_TYPE::Import) {}
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::Import;
};
class BST_ImportFrom : public BST_stmt {
public:
InternedString module;
std::vector<BST_alias*> names;
int level;
virtual void accept(BSTVisitor* v);
virtual void accept_stmt(StmtVisitor* v);
BST_ImportFrom() : BST_stmt(BST_TYPE::ImportFrom) {}
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::ImportFrom;
};
class BST_Index : public BST_slice {
public:
BST_expr* value;
......@@ -648,7 +444,7 @@ public:
class BST_keyword : public BST {
public:
// no lineno, col_offset attributes
// no lineno attributes
BST_expr* value;
InternedString arg;
......@@ -659,19 +455,6 @@ public:
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::keyword;
};
class BST_Lambda : public BST_expr {
public:
BST_arguments* args;
BST_expr* body;
virtual void accept(BSTVisitor* v);
virtual void* accept_expr(ExprVisitor* v);
BST_Lambda() : BST_expr(BST_TYPE::Lambda) {}
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::Lambda;
};
class BST_List : public BST_expr {
public:
std::vector<BST_expr*> elts;
......@@ -685,48 +468,6 @@ public:
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::List;
};
class BST_ListComp : public BST_expr {
public:
std::vector<BST_comprehension*> generators;
BST_expr* elt;
virtual void accept(BSTVisitor* v);
virtual void* accept_expr(ExprVisitor* v);
BST_ListComp() : BST_expr(BST_TYPE::ListComp) {}
const static BST_TYPE::BST_TYPE TYPE = BST_TYPE::ListComp;
};
class BST_Module : public BST {
public:
std::unique_ptr<InternedStringPool> interned_strings;
// no lineno, col_offset attributes
std::vector<BST_stmt*> body;
virtual void accept(BSTVisitor* v);
BST_Module(std::unique_ptr<InternedStringPool> interned_strings)
: BST(BST_TYPE::Module), interned_strings(std::move(interned_strings)) {}
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::Module;
};
class BST_Suite : public BST {
public:
std::unique_ptr<InternedStringPool> interned_strings;
std::vector<BST_stmt*> body;
virtual void accept(BSTVisitor* v);
BST_Suite(std::unique_ptr<InternedStringPool> interned_strings)
: BST(BST_TYPE::Suite), interned_strings(std::move(interned_strings)) {}
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::Suite;
};
class BST_Name : public BST_expr {
public:
AST_TYPE::AST_TYPE ctx_type;
......@@ -751,8 +492,8 @@ public:
virtual void accept(BSTVisitor* v);
virtual void* accept_expr(ExprVisitor* v);
BST_Name(InternedString id, AST_TYPE::AST_TYPE ctx_type, int lineno, int col_offset = 0)
: BST_expr(BST_TYPE::Name, lineno, col_offset),
BST_Name(InternedString id, AST_TYPE::AST_TYPE ctx_type, int lineno)
: BST_expr(BST_TYPE::Name, lineno),
ctx_type(ctx_type),
id(id),
lookup_type(ScopeInfo::VarScopeType::UNKNOWN),
......@@ -792,26 +533,16 @@ public:
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::Repr;
};
class BST_Pass : public BST_stmt {
public:
virtual void accept(BSTVisitor* v);
virtual void accept_stmt(StmtVisitor* v);
BST_Pass() : BST_stmt(BST_TYPE::Pass) {}
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::Pass;
};
class BST_Print : public BST_stmt {
public:
BST_expr* dest;
bool nl;
std::vector<BST_expr*> values;
BST_expr* value;
virtual void accept(BSTVisitor* v);
virtual void accept_stmt(StmtVisitor* v);
BST_Print() : BST_stmt(BST_TYPE::Print) {}
BST_Print() : BST_stmt(BST_TYPE::Print), value(NULL) {}
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::Print;
};
......@@ -856,19 +587,6 @@ public:
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::Set;
};
class BST_SetComp : public BST_expr {
public:
std::vector<BST_comprehension*> generators;
BST_expr* elt;
virtual void accept(BSTVisitor* v);
virtual void* accept_expr(ExprVisitor* v);
BST_SetComp() : BST_expr(BST_TYPE::SetComp) {}
const static BST_TYPE::BST_TYPE TYPE = BST_TYPE::SetComp;
};
class BST_Slice : public BST_slice {
public:
BST_expr* lower, *upper, *step;
......@@ -912,31 +630,6 @@ public:
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::Subscript;
};
class BST_TryExcept : public BST_stmt {
public:
std::vector<BST_stmt*> body, orelse;
std::vector<BST_ExceptHandler*> handlers;
virtual void accept(BSTVisitor* v);
virtual void accept_stmt(StmtVisitor* v);
BST_TryExcept() : BST_stmt(BST_TYPE::TryExcept) {}
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::TryExcept;
};
class BST_TryFinally : public BST_stmt {
public:
std::vector<BST_stmt*> body, finalbody;
virtual void accept(BSTVisitor* v);
virtual void accept_stmt(StmtVisitor* v);
BST_TryFinally() : BST_stmt(BST_TYPE::TryFinally) {}
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::TryFinally;
};
class BST_Tuple : public BST_expr {
public:
std::vector<BST_expr*> elts;
......@@ -963,32 +656,6 @@ public:
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::UnaryOp;
};
class BST_While : public BST_stmt {
public:
BST_expr* test;
std::vector<BST_stmt*> body, orelse;
virtual void accept(BSTVisitor* v);
virtual void accept_stmt(StmtVisitor* v);
BST_While() : BST_stmt(BST_TYPE::While) {}
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::While;
};
class BST_With : public BST_stmt {
public:
BST_expr* optional_vars, *context_expr;
std::vector<BST_stmt*> body;
virtual void accept(BSTVisitor* v);
virtual void accept_stmt(StmtVisitor* v);
BST_With() : BST_stmt(BST_TYPE::With) {}
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::With;
};
class BST_Yield : public BST_expr {
public:
BST_expr* value;
......@@ -1008,8 +675,7 @@ public:
virtual void accept(BSTVisitor* v);
virtual void* accept_expr(ExprVisitor* v);
BST_MakeFunction(BST_FunctionDef* fd)
: BST_expr(BST_TYPE::MakeFunction, fd->lineno, fd->col_offset), function_def(fd) {}
BST_MakeFunction(BST_FunctionDef* fd) : BST_expr(BST_TYPE::MakeFunction, fd->lineno), function_def(fd) {}
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::MakeFunction;
};
......@@ -1021,7 +687,7 @@ public:
virtual void accept(BSTVisitor* v);
virtual void* accept_expr(ExprVisitor* v);
BST_MakeClass(BST_ClassDef* cd) : BST_expr(BST_TYPE::MakeClass, cd->lineno, cd->col_offset), class_def(cd) {}
BST_MakeClass(BST_ClassDef* cd) : BST_expr(BST_TYPE::MakeClass, cd->lineno), class_def(cd) {}
static const BST_TYPE::BST_TYPE TYPE = BST_TYPE::MakeClass;
};
......@@ -1090,7 +756,7 @@ public:
// These are basically bytecodes, framed as pseudo-BST-nodes.
class BST_LangPrimitive : public BST_expr {
public:
enum Opcodes {
enum Opcodes : unsigned char {
LANDINGPAD, // grabs the info about the last raised exception
LOCALS,
GET_ITER,
......@@ -1127,66 +793,40 @@ protected:
public:
virtual ~BSTVisitor() {}
virtual bool visit_alias(BST_alias* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_arguments(BST_arguments* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_assert(BST_Assert* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_assign(BST_Assign* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_augassign(BST_AugAssign* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_augbinop(BST_AugBinOp* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_attribute(BST_Attribute* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_binop(BST_BinOp* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_boolop(BST_BoolOp* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_break(BST_Break* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_call(BST_Call* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_clsattribute(BST_ClsAttribute* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_compare(BST_Compare* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_comprehension(BST_comprehension* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_classdef(BST_ClassDef* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_continue(BST_Continue* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_delete(BST_Delete* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_dict(BST_Dict* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_dictcomp(BST_DictComp* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_ellipsis(BST_Ellipsis* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_excepthandler(BST_ExceptHandler* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_exec(BST_Exec* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_expr(BST_Expr* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_expression(BST_Expression* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_suite(BST_Suite* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_extslice(BST_ExtSlice* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_for(BST_For* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_functiondef(BST_FunctionDef* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_generatorexp(BST_GeneratorExp* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_global(BST_Global* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_if(BST_If* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_ifexp(BST_IfExp* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_import(BST_Import* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_importfrom(BST_ImportFrom* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_index(BST_Index* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_invoke(BST_Invoke* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_keyword(BST_keyword* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_lambda(BST_Lambda* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_langprimitive(BST_LangPrimitive* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_list(BST_List* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_listcomp(BST_ListComp* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_module(BST_Module* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_name(BST_Name* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_num(BST_Num* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_pass(BST_Pass* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_print(BST_Print* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_raise(BST_Raise* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_repr(BST_Repr* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_return(BST_Return* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_set(BST_Set* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_setcomp(BST_SetComp* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_slice(BST_Slice* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_str(BST_Str* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_subscript(BST_Subscript* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_tryexcept(BST_TryExcept* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_tryfinally(BST_TryFinally* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_tuple(BST_Tuple* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_unaryop(BST_UnaryOp* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_while(BST_While* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_with(BST_With* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_yield(BST_Yield* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_makeclass(BST_MakeClass* node) { RELEASE_ASSERT(0, ""); }
......@@ -1200,66 +840,40 @@ protected:
public:
virtual ~NoopBSTVisitor() {}
virtual bool visit_alias(BST_alias* node) { return false; }
virtual bool visit_arguments(BST_arguments* node) { return false; }
virtual bool visit_assert(BST_Assert* node) { return false; }
virtual bool visit_assign(BST_Assign* node) { return false; }
virtual bool visit_augassign(BST_AugAssign* node) { return false; }
virtual bool visit_augbinop(BST_AugBinOp* node) { return false; }
virtual bool visit_attribute(BST_Attribute* node) { return false; }
virtual bool visit_binop(BST_BinOp* node) { return false; }
virtual bool visit_boolop(BST_BoolOp* node) { return false; }
virtual bool visit_break(BST_Break* node) { return false; }
virtual bool visit_call(BST_Call* node) { return false; }
virtual bool visit_clsattribute(BST_ClsAttribute* node) { return false; }
virtual bool visit_compare(BST_Compare* node) { return false; }
virtual bool visit_comprehension(BST_comprehension* node) { return false; }
virtual bool visit_classdef(BST_ClassDef* node) { return false; }
virtual bool visit_continue(BST_Continue* node) { return false; }
virtual bool visit_delete(BST_Delete* node) { return false; }
virtual bool visit_dict(BST_Dict* node) { return false; }
virtual bool visit_dictcomp(BST_DictComp* node) { return false; }
virtual bool visit_ellipsis(BST_Ellipsis* node) { return false; }
virtual bool visit_excepthandler(BST_ExceptHandler* node) { return false; }
virtual bool visit_exec(BST_Exec* node) { return false; }
virtual bool visit_expr(BST_Expr* node) { return false; }
virtual bool visit_expression(BST_Expression* node) { return false; }
virtual bool visit_suite(BST_Suite* node) { return false; }
virtual bool visit_extslice(BST_ExtSlice* node) { return false; }
virtual bool visit_for(BST_For* node) { return false; }
virtual bool visit_functiondef(BST_FunctionDef* node) { return false; }
virtual bool visit_generatorexp(BST_GeneratorExp* node) { return false; }
virtual bool visit_global(BST_Global* node) { return false; }
virtual bool visit_if(BST_If* node) { return false; }
virtual bool visit_ifexp(BST_IfExp* node) { return false; }
virtual bool visit_import(BST_Import* node) { return false; }
virtual bool visit_importfrom(BST_ImportFrom* node) { return false; }
virtual bool visit_index(BST_Index* node) { return false; }
virtual bool visit_invoke(BST_Invoke* node) { return false; }
virtual bool visit_keyword(BST_keyword* node) { return false; }
virtual bool visit_lambda(BST_Lambda* node) { return false; }
virtual bool visit_langprimitive(BST_LangPrimitive* node) { return false; }
virtual bool visit_list(BST_List* node) { return false; }
virtual bool visit_listcomp(BST_ListComp* node) { return false; }
virtual bool visit_module(BST_Module* node) { return false; }
virtual bool visit_name(BST_Name* node) { return false; }
virtual bool visit_num(BST_Num* node) { return false; }
virtual bool visit_pass(BST_Pass* node) { return false; }
virtual bool visit_print(BST_Print* node) { return false; }
virtual bool visit_raise(BST_Raise* node) { return false; }
virtual bool visit_repr(BST_Repr* node) { return false; }
virtual bool visit_return(BST_Return* node) { return false; }
virtual bool visit_set(BST_Set* node) { return false; }
virtual bool visit_setcomp(BST_SetComp* node) { return false; }
virtual bool visit_slice(BST_Slice* node) { return false; }
virtual bool visit_str(BST_Str* node) { return false; }
virtual bool visit_subscript(BST_Subscript* node) { return false; }
virtual bool visit_tryexcept(BST_TryExcept* node) { return false; }
virtual bool visit_tryfinally(BST_TryFinally* node) { return false; }
virtual bool visit_tuple(BST_Tuple* node) { return false; }
virtual bool visit_unaryop(BST_UnaryOp* node) { return false; }
virtual bool visit_while(BST_While* node) { return false; }
virtual bool visit_with(BST_With* node) { return false; }
virtual bool visit_yield(BST_Yield* node) { return false; }
virtual bool visit_branch(BST_Branch* node) { return false; }
......@@ -1276,23 +890,16 @@ public:
virtual void* visit_augbinop(BST_AugBinOp* node) { RELEASE_ASSERT(0, ""); }
virtual void* visit_attribute(BST_Attribute* node) { RELEASE_ASSERT(0, ""); }
virtual void* visit_binop(BST_BinOp* node) { RELEASE_ASSERT(0, ""); }
virtual void* visit_boolop(BST_BoolOp* node) { RELEASE_ASSERT(0, ""); }
virtual void* visit_call(BST_Call* node) { RELEASE_ASSERT(0, ""); }
virtual void* visit_clsattribute(BST_ClsAttribute* node) { RELEASE_ASSERT(0, ""); }
virtual void* visit_compare(BST_Compare* node) { RELEASE_ASSERT(0, ""); }
virtual void* visit_dict(BST_Dict* node) { RELEASE_ASSERT(0, ""); }
virtual void* visit_dictcomp(BST_DictComp* node) { RELEASE_ASSERT(0, ""); }
virtual void* visit_generatorexp(BST_GeneratorExp* node) { RELEASE_ASSERT(0, ""); }
virtual void* visit_ifexp(BST_IfExp* node) { RELEASE_ASSERT(0, ""); }
virtual void* visit_lambda(BST_Lambda* node) { RELEASE_ASSERT(0, ""); }
virtual void* visit_langprimitive(BST_LangPrimitive* node) { RELEASE_ASSERT(0, ""); }
virtual void* visit_list(BST_List* node) { RELEASE_ASSERT(0, ""); }
virtual void* visit_listcomp(BST_ListComp* node) { RELEASE_ASSERT(0, ""); }
virtual void* visit_name(BST_Name* node) { RELEASE_ASSERT(0, ""); }
virtual void* visit_num(BST_Num* node) { RELEASE_ASSERT(0, ""); }
virtual void* visit_repr(BST_Repr* node) { RELEASE_ASSERT(0, ""); }
virtual void* visit_set(BST_Set* node) { RELEASE_ASSERT(0, ""); }
virtual void* visit_setcomp(BST_SetComp* node) { RELEASE_ASSERT(0, ""); }
virtual void* visit_str(BST_Str* node) { RELEASE_ASSERT(0, ""); }
virtual void* visit_subscript(BST_Subscript* node) { RELEASE_ASSERT(0, ""); }
virtual void* visit_tuple(BST_Tuple* node) { RELEASE_ASSERT(0, ""); }
......@@ -1309,28 +916,15 @@ public:
virtual void visit_assert(BST_Assert* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_assign(BST_Assign* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_augassign(BST_AugAssign* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_break(BST_Break* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_classdef(BST_ClassDef* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_delete(BST_Delete* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_continue(BST_Continue* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_exec(BST_Exec* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_expr(BST_Expr* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_for(BST_For* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_functiondef(BST_FunctionDef* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_global(BST_Global* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_if(BST_If* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_import(BST_Import* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_importfrom(BST_ImportFrom* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_invoke(BST_Invoke* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_pass(BST_Pass* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_print(BST_Print* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_raise(BST_Raise* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_return(BST_Return* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_tryexcept(BST_TryExcept* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_tryfinally(BST_TryFinally* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_while(BST_While* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_with(BST_With* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_branch(BST_Branch* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_jump(BST_Jump* node) { RELEASE_ASSERT(0, ""); }
......@@ -1358,66 +952,40 @@ public:
virtual ~PrintVisitor() {}
void flush() { stream.flush(); }
virtual bool visit_alias(BST_alias* node);
virtual bool visit_arguments(BST_arguments* node);
virtual bool visit_assert(BST_Assert* node);
virtual bool visit_assign(BST_Assign* node);
virtual bool visit_augassign(BST_AugAssign* node);
virtual bool visit_augbinop(BST_AugBinOp* node);
virtual bool visit_attribute(BST_Attribute* node);
virtual bool visit_binop(BST_BinOp* node);
virtual bool visit_boolop(BST_BoolOp* node);
virtual bool visit_break(BST_Break* node);
virtual bool visit_call(BST_Call* node);
virtual bool visit_compare(BST_Compare* node);
virtual bool visit_comprehension(BST_comprehension* node);
virtual bool visit_classdef(BST_ClassDef* node);
virtual bool visit_clsattribute(BST_ClsAttribute* node);
virtual bool visit_continue(BST_Continue* node);
virtual bool visit_delete(BST_Delete* node);
virtual bool visit_dict(BST_Dict* node);
virtual bool visit_dictcomp(BST_DictComp* node);
virtual bool visit_ellipsis(BST_Ellipsis* node);
virtual bool visit_excepthandler(BST_ExceptHandler* node);
virtual bool visit_exec(BST_Exec* node);
virtual bool visit_expr(BST_Expr* node);
virtual bool visit_expression(BST_Expression* node);
virtual bool visit_suite(BST_Suite* node);
virtual bool visit_extslice(BST_ExtSlice* node);
virtual bool visit_for(BST_For* node);
virtual bool visit_functiondef(BST_FunctionDef* node);
virtual bool visit_generatorexp(BST_GeneratorExp* node);
virtual bool visit_global(BST_Global* node);
virtual bool visit_if(BST_If* node);
virtual bool visit_ifexp(BST_IfExp* node);
virtual bool visit_import(BST_Import* node);
virtual bool visit_importfrom(BST_ImportFrom* node);
virtual bool visit_index(BST_Index* node);
virtual bool visit_invoke(BST_Invoke* node);
virtual bool visit_keyword(BST_keyword* node);
virtual bool visit_lambda(BST_Lambda* node);
virtual bool visit_langprimitive(BST_LangPrimitive* node);
virtual bool visit_list(BST_List* node);
virtual bool visit_listcomp(BST_ListComp* node);
virtual bool visit_module(BST_Module* node);
virtual bool visit_name(BST_Name* node);
virtual bool visit_num(BST_Num* node);
virtual bool visit_pass(BST_Pass* node);
virtual bool visit_print(BST_Print* node);
virtual bool visit_raise(BST_Raise* node);
virtual bool visit_repr(BST_Repr* node);
virtual bool visit_return(BST_Return* node);
virtual bool visit_set(BST_Set* node);
virtual bool visit_setcomp(BST_SetComp* node);
virtual bool visit_slice(BST_Slice* node);
virtual bool visit_str(BST_Str* node);
virtual bool visit_subscript(BST_Subscript* node);
virtual bool visit_tuple(BST_Tuple* node);
virtual bool visit_tryexcept(BST_TryExcept* node);
virtual bool visit_tryfinally(BST_TryFinally* node);
virtual bool visit_unaryop(BST_UnaryOp* node);
virtual bool visit_while(BST_While* node);
virtual bool visit_with(BST_With* node);
virtual bool visit_yield(BST_Yield* node);
virtual bool visit_branch(BST_Branch* node);
......@@ -1429,7 +997,7 @@ public:
// Given an BST node, return a vector of the node plus all its descendents.
// This is useful for analyses that care more about the constituent nodes than the
// exact tree structure; ex, finding all "global" directives.
void flatten(const llvm::SmallVector<BST_stmt*, 4>& roots, std::vector<BST*>& output, bool expand_scopes);
void flatten(llvm::ArrayRef<BST_stmt*> roots, std::vector<BST*>& output, bool expand_scopes);
void flatten(BST_expr* root, std::vector<BST*>& output, bool expand_scopes);
};
......
......@@ -54,11 +54,11 @@ ParamNames::ParamNames(AST_arguments* arguments, InternedStringPool& pool)
AST_expr* arg = arguments->args[i];
if (arg->type == AST_TYPE::Name) {
AST_Name* name = ast_cast<AST_Name>(arg);
BST_Name* new_name = new BST_Name(name->id, name->ctx_type, name->lineno, name->col_offset);
BST_Name* new_name = new BST_Name(name->id, name->ctx_type, name->lineno);
all_args.emplace_back(new_name);
} else {
InternedString dot_arg_name = pool.get("." + std::to_string(i));
auto new_name = new BST_Name(dot_arg_name, AST_TYPE::Param, arg->lineno, arg->col_offset);
auto new_name = new BST_Name(dot_arg_name, AST_TYPE::Param, arg->lineno);
new_name->lookup_type = ScopeInfo::VarScopeType::FAST;
all_args.emplace_back(new_name);
}
......@@ -67,16 +67,14 @@ ParamNames::ParamNames(AST_arguments* arguments, InternedStringPool& pool)
auto vararg_name = arguments->vararg;
if (vararg_name) {
has_vararg_name = 1;
BST_Name* new_name
= new BST_Name(vararg_name->id, vararg_name->ctx_type, vararg_name->lineno, vararg_name->col_offset);
BST_Name* new_name = new BST_Name(vararg_name->id, vararg_name->ctx_type, vararg_name->lineno);
all_args.emplace_back(new_name);
}
auto kwarg_name = arguments->kwarg;
if (kwarg_name) {
has_kwarg_name = 1;
BST_Name* new_name
= new BST_Name(kwarg_name->id, kwarg_name->ctx_type, kwarg_name->lineno, kwarg_name->col_offset);
BST_Name* new_name = new BST_Name(kwarg_name->id, kwarg_name->ctx_type, kwarg_name->lineno);
all_args.emplace_back(new_name);
}
}
......@@ -374,24 +372,23 @@ private:
return name;
}
BST_Name* makeName(InternedString id, AST_TYPE::AST_TYPE ctx_type, int lineno, int col_offset = 0,
bool is_kill = false) {
BST_Name* name = new BST_Name(id, ctx_type, lineno, col_offset);
BST_Name* makeName(InternedString id, AST_TYPE::AST_TYPE ctx_type, int lineno, bool is_kill = false) {
BST_Name* name = new BST_Name(id, ctx_type, lineno);
fillScopingInfo(name, scoping);
name->is_kill = is_kill;
return name;
}
BST_Name* makeLoad(InternedString id, AST* node, bool is_kill = false) {
return makeName(id, AST_TYPE::Load, node->lineno, 0, is_kill);
return makeName(id, AST_TYPE::Load, node->lineno, is_kill);
}
BST_Name* makeLoad(InternedString id, BST* node, bool is_kill = false) {
return makeName(id, AST_TYPE::Load, node->lineno, 0, is_kill);
return makeName(id, AST_TYPE::Load, node->lineno, is_kill);
}
BST_Name* makeLoad(InternedString id, int lineno, bool is_kill = false) {
return makeName(id, AST_TYPE::Load, lineno, 0, is_kill);
return makeName(id, AST_TYPE::Load, lineno, is_kill);
}
void pushLoopContinuation(CFGBlock* continue_dest, CFGBlock* break_dest) {
......@@ -425,7 +422,6 @@ private:
BST_Return* node = new BST_Return();
node->value = value;
node->col_offset = value->col_offset;
node->lineno = value->lineno;
push_back(node);
curblock = NULL;
......@@ -469,7 +465,6 @@ private:
BST_LangPrimitive* call = new BST_LangPrimitive(BST_LangPrimitive::NONZERO);
call->args.push_back(e);
call->lineno = e->lineno;
call->col_offset = e->col_offset;
// Simple optimization: allow the generation of nested nodes if there isn't a
// current exc handler.
......@@ -484,7 +479,7 @@ private:
BST_Name* remapName(AST_Name* name) {
if (!name)
return NULL;
BST_Name* rtn = new BST_Name(name->id, name->ctx_type, name->lineno, name->col_offset);
BST_Name* rtn = new BST_Name(name->id, name->ctx_type, name->lineno);
fillScopingInfo(rtn, scoping);
return rtn;
}
......@@ -492,7 +487,6 @@ private:
BST_Num* remapNum(AST_Num* num) {
auto r = new BST_Num();
r->lineno = num->lineno;
r->col_offset = num->col_offset;
r->num_type = num->num_type;
switch (r->num_type) {
case AST_Num::INT:
......@@ -514,7 +508,6 @@ private:
r->str_data = str->str_data;
r->str_type = str->str_type;
r->lineno = str->lineno;
r->col_offset = str->col_offset;
return r;
}
......@@ -568,7 +561,6 @@ private:
// printf("Body block for comp %d is %d\n", i, body_block->idx);
BST_Branch* br = new BST_Branch();
br->col_offset = node->col_offset;
br->lineno = node->lineno;
br->test = test;
br->iftrue = body_block;
......@@ -662,7 +654,6 @@ private:
BST_Branch* makeBranch(BST_expr* test) {
BST_Branch* rtn = new BST_Branch();
rtn->test = callNonzero(test);
rtn->col_offset = test->col_offset;
rtn->lineno = test->lineno;
return rtn;
}
......@@ -725,7 +716,6 @@ private:
attr->attr = name;
rtn = attr;
}
rtn->col_offset = base->col_offset;
rtn->lineno = base->lineno;
return rtn;
}
......@@ -758,7 +748,6 @@ private:
call->starargs = NULL;
call->kwargs = NULL;
call->func = func;
call->col_offset = func->col_offset;
call->lineno = func->lineno;
return call;
}
......@@ -786,9 +775,9 @@ private:
BST_Compare* makeCompare(AST_TYPE::AST_TYPE oper, BST_expr* left, BST_expr* right) {
auto compare = new BST_Compare();
compare->ops.push_back(oper);
compare->op = oper;
compare->left = left;
compare->comparators.push_back(right);
compare->comparator = right;
return compare;
}
......@@ -796,7 +785,6 @@ private:
auto index = new BST_Index();
index->value = value;
index->lineno = value->lineno;
index->col_offset = value->col_offset;
return index;
}
......@@ -806,7 +794,6 @@ private:
subscript->value = value;
subscript->slice = slice;
subscript->lineno = slice->lineno;
subscript->col_offset = slice->col_offset;
return subscript;
}
......@@ -816,20 +803,18 @@ private:
void pushAssign(BST_expr* target, BST_expr* val) {
BST_Assign* assign = new BST_Assign();
assign->value = val;
assign->col_offset = val->col_offset;
assign->lineno = val->lineno;
assign->targets.push_back(target);
assign->target = target;
push_back(assign);
}
void pushAssign(AST_expr* target, BST_expr* val) {
BST_Assign* assign = new BST_Assign();
assign->value = val;
assign->col_offset = val->col_offset;
assign->lineno = val->lineno;
if (target->type == AST_TYPE::Name) {
assign->targets.push_back(makeName(ast_cast<AST_Name>(target)->id, AST_TYPE::Store, val->lineno, 0));
assign->target = makeName(ast_cast<AST_Name>(target)->id, AST_TYPE::Store, val->lineno, 0);
push_back(assign);
} else if (target->type == AST_TYPE::Subscript) {
AST_Subscript* s = ast_cast<AST_Subscript>(target);
......@@ -839,10 +824,9 @@ private:
s_target->value = remapExpr(s->value);
s_target->slice = remapSlice(s->slice);
s_target->ctx_type = AST_TYPE::Store;
s_target->col_offset = s->col_offset;
s_target->lineno = s->lineno;
assign->targets.push_back(s_target);
assign->target = s_target;
push_back(assign);
} else if (target->type == AST_TYPE::Attribute) {
AST_Attribute* a = ast_cast<AST_Attribute>(target);
......@@ -852,10 +836,9 @@ private:
a_target->value = remapExpr(a->value);
a_target->attr = scoping->mangleName(a->attr);
a_target->ctx_type = AST_TYPE::Store;
a_target->col_offset = a->col_offset;
a_target->lineno = a->lineno;
assign->targets.push_back(a_target);
assign->target = a_target;
push_back(assign);
} else if (target->type == AST_TYPE::Tuple || target->type == AST_TYPE::List) {
std::vector<AST_expr*>* elts;
......@@ -872,11 +855,10 @@ private:
BST_Tuple* new_target = new BST_Tuple();
new_target->ctx_type = AST_TYPE::Store;
new_target->lineno = target->lineno;
new_target->col_offset = target->col_offset;
// A little hackery: push the assign, even though we're not done constructing it yet,
// so that we can iteratively push more stuff after it
assign->targets.push_back(new_target);
assign->target = new_target;
push_back(assign);
for (int i = 0; i < elts->size(); i++) {
......@@ -893,9 +875,8 @@ private:
void pushAssign(InternedString id, BST_expr* val) {
BST_Assign* assign = new BST_Assign();
assign->value = val;
assign->col_offset = val->col_offset;
assign->lineno = val->lineno;
assign->targets.push_back(makeName(id, AST_TYPE::Store, val->lineno, 0));
assign->target = makeName(id, AST_TYPE::Store, val->lineno, 0);
push_back(assign);
}
......@@ -911,7 +892,6 @@ private:
BST_Expr* stmt = new BST_Expr();
stmt->value = expr;
stmt->lineno = expr->lineno;
stmt->col_offset = expr->col_offset;
return stmt;
}
......@@ -926,7 +906,6 @@ private:
BST_expr* remapAttribute(AST_Attribute* node) {
BST_Attribute* rtn = new BST_Attribute();
rtn->col_offset = node->col_offset;
rtn->lineno = node->lineno;
rtn->ctx_type = node->ctx_type;
rtn->attr = scoping->mangleName(node->attr);
......@@ -937,7 +916,6 @@ private:
BST_expr* remapBinOp(AST_BinOp* node) {
BST_BinOp* rtn = new BST_BinOp();
rtn->lineno = node->lineno;
rtn->col_offset = node->col_offset;
rtn->op_type = remapBinOpType(node->op_type);
rtn->left = remapExpr(node->left);
rtn->right = remapExpr(node->right);
......@@ -950,13 +928,11 @@ private:
} else if (val->type == BST_TYPE::Ellipsis) {
BST_Ellipsis* orig = bst_cast<BST_Ellipsis>(val);
BST_Ellipsis* made = new BST_Ellipsis();
made->col_offset = orig->col_offset;
made->lineno = orig->lineno;
return made;
} else if (val->type == BST_TYPE::ExtSlice) {
BST_ExtSlice* orig = bst_cast<BST_ExtSlice>(val);
BST_ExtSlice* made = new BST_ExtSlice();
made->col_offset = orig->col_offset;
made->lineno = orig->lineno;
made->dims.reserve(orig->dims.size());
for (BST_slice* item : orig->dims) {
......@@ -967,13 +943,11 @@ private:
BST_Index* orig = bst_cast<BST_Index>(val);
BST_Index* made = new BST_Index();
made->value = _dup(orig->value);
made->col_offset = orig->col_offset;
made->lineno = orig->lineno;
return made;
} else if (val->type == BST_TYPE::Slice) {
BST_Slice* orig = bst_cast<BST_Slice>(val);
BST_Slice* made = new BST_Slice();
made->col_offset = orig->col_offset;
made->lineno = orig->lineno;
made->lower = _dup(orig->lower);
made->upper = _dup(orig->upper);
......@@ -996,7 +970,7 @@ private:
if (val->type == BST_TYPE::Name) {
BST_Name* orig = bst_cast<BST_Name>(val);
BST_Name* made = makeName(orig->id, orig->ctx_type, orig->lineno, orig->col_offset);
BST_Name* made = makeName(orig->id, orig->ctx_type, orig->lineno);
return made;
} else if (val->type == BST_TYPE::Num) {
BST_Num* orig = bst_cast<BST_Num>(val);
......@@ -1004,7 +978,6 @@ private:
made->num_type = orig->num_type;
made->n_int = orig->n_int;
made->n_long = orig->n_long;
made->col_offset = orig->col_offset;
made->lineno = orig->lineno;
return made;
} else if (val->type == BST_TYPE::Str) {
......@@ -1012,7 +985,6 @@ private:
BST_Str* made = new BST_Str();
made->str_type = orig->str_type;
made->str_data = orig->str_data;
made->col_offset = orig->col_offset;
made->lineno = orig->lineno;
return made;
} else {
......@@ -1072,7 +1044,6 @@ private:
BST_expr* remapCall(AST_Call* node) {
BST_Call* rtn = new BST_Call();
rtn->lineno = node->lineno;
rtn->col_offset = node->col_offset;
if (node->func->type == AST_TYPE::Attribute) {
// TODO this is a cludge to make sure that "callattrs" stick together.
......@@ -1106,7 +1077,6 @@ private:
BST_expr* remapClsAttribute(AST_ClsAttribute* node) {
BST_ClsAttribute* rtn = new BST_ClsAttribute();
rtn->col_offset = node->col_offset;
rtn->lineno = node->lineno;
rtn->attr = node->attr;
rtn->value = remapExpr(node->value);
......@@ -1120,14 +1090,12 @@ private:
if (node->ops.size() == 1) {
BST_Compare* rtn = new BST_Compare();
rtn->lineno = node->lineno;
rtn->col_offset = node->col_offset;
rtn->ops = node->ops;
rtn->op = node->ops[0];
rtn->left = remapExpr(node->left);
for (auto elt : node->comparators) {
rtn->comparators.push_back(remapExpr(elt));
}
assert(node->comparators.size() == 1);
rtn->comparator = remapExpr(node->comparators[0]);
return rtn;
} else {
InternedString name = nodeName();
......@@ -1142,14 +1110,13 @@ private:
BST_expr* right = remapExpr(node->comparators[i]);
BST_Compare* val = new BST_Compare;
val->col_offset = node->col_offset;
val->lineno = node->lineno;
val->left = left;
if (i < node->ops.size() - 1)
val->comparators.push_back(_dup(right));
val->comparator = _dup(right);
else
val->comparators.push_back(right);
val->ops.push_back(node->ops[i]);
val->comparator = right;
val->op = node->ops[i];
pushAssign(name, val);
......@@ -1189,7 +1156,6 @@ private:
BST_expr* remapDict(AST_Dict* node) {
BST_Dict* rtn = new BST_Dict();
rtn->lineno = node->lineno;
rtn->col_offset = node->col_offset;
InternedString dict_name = nodeName();
......@@ -1208,14 +1174,12 @@ private:
BST_slice* remapEllipsis(AST_Ellipsis* node) {
auto r = new BST_Ellipsis();
r->lineno = node->lineno;
r->col_offset = node->col_offset;
return r;
}
BST_slice* remapExtSlice(AST_ExtSlice* node) {
BST_ExtSlice* rtn = new BST_ExtSlice();
rtn->lineno = node->lineno;
rtn->col_offset = node->col_offset;
for (auto* e : node->dims)
rtn->dims.push_back(remapSlice(e));
......@@ -1387,7 +1351,6 @@ private:
BST_slice* remapIndex(AST_Index* node) {
BST_Index* rtn = new BST_Index();
rtn->lineno = node->lineno;
rtn->col_offset = node->col_offset;
rtn->value = remapExpr(node->value);
return rtn;
}
......@@ -1402,13 +1365,11 @@ private:
BST_expr* remapLambda(AST_Lambda* node) {
auto stmt = new AST_Return;
stmt->lineno = node->lineno;
stmt->col_offset = node->col_offset;
stmt->value = node->body; // don't remap now; will be CFG'ed later
auto bdef = new BST_FunctionDef();
bdef->lineno = node->lineno;
bdef->col_offset = node->col_offset;
bdef->args = remapArguments(node->args);
......@@ -1425,7 +1386,6 @@ private:
// AST_LangPrimitive can be PRINT_EXPR
assert(node->opcode == AST_LangPrimitive::PRINT_EXPR);
BST_LangPrimitive* rtn = new BST_LangPrimitive(BST_LangPrimitive::PRINT_EXPR);
rtn->col_offset = node->col_offset;
rtn->lineno = node->lineno;
for (AST_expr* arg : node->args) {
......@@ -1439,7 +1399,6 @@ private:
BST_List* rtn = new BST_List();
rtn->lineno = node->lineno;
rtn->col_offset = node->col_offset;
rtn->ctx_type = node->ctx_type;
for (auto elt : node->elts) {
......@@ -1451,7 +1410,6 @@ private:
BST_expr* remapRepr(AST_Repr* node) {
BST_Repr* rtn = new BST_Repr();
rtn->lineno = node->lineno;
rtn->col_offset = node->col_offset;
rtn->value = remapExpr(node->value);
return rtn;
}
......@@ -1459,7 +1417,6 @@ private:
BST_expr* remapSet(AST_Set* node) {
BST_Set* rtn = new BST_Set();
rtn->lineno = node->lineno;
rtn->col_offset = node->col_offset;
for (auto e : node->elts) {
rtn->elts.push_back(remapExpr(e));
......@@ -1471,7 +1428,6 @@ private:
BST_slice* remapSlice(AST_Slice* node) {
BST_Slice* rtn = new BST_Slice();
rtn->lineno = node->lineno;
rtn->col_offset = node->col_offset;
rtn->lower = remapExpr(node->lower);
rtn->upper = remapExpr(node->upper);
......@@ -1485,7 +1441,6 @@ private:
BST_Tuple* rtn = new BST_Tuple();
rtn->lineno = node->lineno;
rtn->col_offset = node->col_offset;
rtn->ctx_type = node->ctx_type;
for (auto elt : node->elts) {
......@@ -1497,7 +1452,6 @@ private:
BST_expr* remapSubscript(AST_Subscript* node) {
BST_Subscript* rtn = new BST_Subscript();
rtn->lineno = node->lineno;
rtn->col_offset = node->col_offset;
rtn->ctx_type = node->ctx_type;
rtn->value = remapExpr(node->value);
rtn->slice = remapSlice(node->slice);
......@@ -1507,7 +1461,6 @@ private:
BST_expr* remapUnaryOp(AST_UnaryOp* node) {
BST_UnaryOp* rtn = new BST_UnaryOp();
rtn->lineno = node->lineno;
rtn->col_offset = node->col_offset;
rtn->op_type = node->op_type;
rtn->operand = remapExpr(node->operand);
return rtn;
......@@ -1516,7 +1469,6 @@ private:
BST_expr* remapYield(AST_Yield* node) {
BST_Yield* rtn = new BST_Yield();
rtn->lineno = node->lineno;
rtn->col_offset = node->col_offset;
rtn->value = remapExpr(node->value);
InternedString node_name(nodeName());
......@@ -1754,9 +1706,8 @@ public:
if (node->type == BST_TYPE::Assign) {
BST_Assign* asgn = bst_cast<BST_Assign>(node);
assert(asgn->targets.size() == 1);
if (asgn->targets[0]->type == BST_TYPE::Name) {
BST_Name* target = bst_cast<BST_Name>(asgn->targets[0]);
if (asgn->target->type == BST_TYPE::Name) {
BST_Name* target = bst_cast<BST_Name>(asgn->target);
if (target->id.s()[0] != '#') {
// assigning to a non-temporary
#ifndef NDEBUG
......@@ -1789,9 +1740,8 @@ public:
// Deleting temporary names is safe, since we only use it to represent kills.
if (node->type == BST_TYPE::Delete) {
BST_Delete* del = bst_cast<BST_Delete>(node);
assert(del->targets.size() == 1);
if (del->targets[0]->type == BST_TYPE::Name) {
BST_Name* target = bst_cast<BST_Name>(del->targets[0]);
if (del->target->type == BST_TYPE::Name) {
BST_Name* target = bst_cast<BST_Name>(del->target);
if (target->id.s()[0] == '#') {
curblock->push_back(node);
return;
......@@ -1818,7 +1768,6 @@ public:
BST_Invoke* invoke = new BST_Invoke(node);
invoke->normal_dest = normal_dest;
invoke->exc_dest = exc_dest;
invoke->col_offset = node->col_offset;
invoke->lineno = node->lineno;
curblock->push_back(invoke);
......@@ -1836,7 +1785,7 @@ public:
target->elts.push_back(makeName(exc_info.exc_type_name, AST_TYPE::Store, node->lineno));
target->elts.push_back(makeName(exc_info.exc_value_name, AST_TYPE::Store, node->lineno));
target->elts.push_back(makeName(exc_info.exc_traceback_name, AST_TYPE::Store, node->lineno));
exc_asgn->targets.push_back(target);
exc_asgn->target = target;
exc_asgn->value = new BST_LangPrimitive(BST_LangPrimitive::LANDINGPAD);
curblock->push_back(exc_asgn);
......@@ -1852,7 +1801,6 @@ public:
bool visit_classdef(AST_ClassDef* node) override {
auto def = new BST_ClassDef();
def->lineno = node->lineno;
def->col_offset = node->col_offset;
def->name = node->name;
// Decorators are evaluated before bases:
......@@ -1868,7 +1816,7 @@ public:
auto tmp = nodeName();
pushAssign(tmp, new BST_MakeClass(def));
pushAssign(scoping->mangleName(def->name), makeName(tmp, AST_TYPE::Load, node->lineno, 0, true));
pushAssign(scoping->mangleName(def->name), makeName(tmp, AST_TYPE::Load, node->lineno, true));
return true;
}
......@@ -1876,7 +1824,6 @@ public:
bool visit_functiondef(AST_FunctionDef* node) override {
auto def = new BST_FunctionDef();
def->lineno = node->lineno;
def->col_offset = node->col_offset;
def->name = node->name;
// Decorators are evaluated before the defaults, so this *must* go before remapArguments().
......@@ -1892,15 +1839,13 @@ public:
auto tmp = nodeName();
pushAssign(tmp, new BST_MakeFunction(def));
pushAssign(scoping->mangleName(def->name), makeName(tmp, AST_TYPE::Load, node->lineno, node->col_offset, true));
pushAssign(scoping->mangleName(def->name), makeName(tmp, AST_TYPE::Load, node->lineno, true));
return true;
}
bool visit_global(AST_Global* node) override {
BST_Global* newnode = new BST_Global();
newnode->names = std::move(node->names);
push_back(newnode);
bool visit_global(AST_Global*) override {
// nothing todo only the scoping analysis cares about this node
return true;
}
......@@ -1917,7 +1862,6 @@ public:
for (AST_alias* a : node->names) {
BST_LangPrimitive* import = new BST_LangPrimitive(BST_LangPrimitive::IMPORT_NAME);
import->lineno = node->lineno;
import->col_offset = node->col_offset;
import->args.push_back(new BST_Num());
static_cast<BST_Num*>(import->args[0])->num_type = AST_Num::INT;
......@@ -1970,7 +1914,6 @@ public:
bool visit_importfrom(AST_ImportFrom* node) override {
BST_LangPrimitive* import = new BST_LangPrimitive(BST_LangPrimitive::IMPORT_NAME);
import->lineno = node->lineno;
import->col_offset = node->col_offset;
import->args.push_back(new BST_Num());
static_cast<BST_Num*>(import->args[0])->num_type = AST_Num::INT;
......@@ -2003,19 +1946,16 @@ public:
BST_LangPrimitive* import_star = new BST_LangPrimitive(BST_LangPrimitive::IMPORT_STAR);
import_star->lineno = node->lineno;
import_star->col_offset = node->col_offset;
import_star->args.push_back(makeLoad(tmp_module_name, node, is_kill));
BST_Expr* import_star_expr = new BST_Expr();
import_star_expr->value = import_star;
import_star_expr->lineno = node->lineno;
import_star_expr->col_offset = node->col_offset;
push_back(import_star_expr);
} else {
BST_LangPrimitive* import_from = new BST_LangPrimitive(BST_LangPrimitive::IMPORT_FROM);
import_from->lineno = node->lineno;
import_from->col_offset = node->col_offset;
import_from->args.push_back(makeLoad(tmp_module_name, node, is_kill));
import_from->args.push_back(new BST_Str(a->name.s()));
......@@ -2058,7 +1998,6 @@ public:
fake_test->n_int = 0;
remapped->test = fake_test;
remapped->lineno = node->lineno;
remapped->col_offset = node->col_offset;
push_back(remapped);
curblock = iftrue;
......@@ -2120,14 +2059,12 @@ public:
s_target->value = remapExpr(s->value);
s_target->slice = remapSlice(s->slice);
s_target->ctx_type = AST_TYPE::Store;
s_target->col_offset = s->col_offset;
s_target->lineno = s->lineno;
remapped_target = s_target;
BST_Subscript* s_lhs = new BST_Subscript();
s_lhs->value = _dup(s_target->value);
s_lhs->slice = _dup(s_target->slice);
s_lhs->col_offset = s->col_offset;
s_lhs->lineno = s->lineno;
s_lhs->ctx_type = AST_TYPE::Load;
remapped_lhs = wrap(s_lhs);
......@@ -2142,7 +2079,6 @@ public:
a_target->value = remapExpr(a->value);
a_target->attr = scoping->mangleName(a->attr);
a_target->ctx_type = AST_TYPE::Store;
a_target->col_offset = a->col_offset;
a_target->lineno = a->lineno;
remapped_target = a_target;
......@@ -2150,7 +2086,6 @@ public:
a_lhs->value = _dup(a_target->value);
a_lhs->attr = a_target->attr;
a_lhs->ctx_type = AST_TYPE::Load;
a_lhs->col_offset = a->col_offset;
a_lhs->lineno = a->lineno;
remapped_lhs = wrap(a_lhs);
......@@ -2164,7 +2099,6 @@ public:
binop->op_type = remapBinOpType(node->op_type);
binop->left = remapped_lhs;
binop->right = remapExpr(node->value);
binop->col_offset = node->col_offset;
binop->lineno = node->lineno;
InternedString node_name(nodeName());
......@@ -2183,9 +2117,6 @@ public:
bool visit_delete(AST_Delete* node) override {
for (auto t : node->targets) {
BST_Delete* astdel = new BST_Delete();
astdel->lineno = node->lineno;
astdel->col_offset = node->col_offset;
BST_expr* target = NULL;
switch (t->type) {
case AST_TYPE::Subscript: {
......@@ -2235,12 +2166,13 @@ public:
RELEASE_ASSERT(0, "Unsupported del target: %d", t->type);
}
if (target != NULL)
astdel->targets.push_back(target);
if (astdel->targets.size() > 0)
if (target != NULL) {
BST_Delete* astdel = new BST_Delete();
astdel->lineno = node->lineno;
astdel->target = target;
push_back(astdel);
}
}
return true;
}
......@@ -2248,7 +2180,6 @@ public:
bool visit_expr(AST_Expr* node) override {
BST_Expr* remapped = new BST_Expr();
remapped->lineno = node->lineno;
remapped->col_offset = node->col_offset;
remapped->value = remapExpr(node->value, false);
push_back(remapped);
return true;
......@@ -2260,7 +2191,6 @@ public:
int i = 0;
for (auto v : node->values) {
BST_Print* remapped = new BST_Print();
remapped->col_offset = node->col_offset;
remapped->lineno = node->lineno;
if (i < node->values.size() - 1) {
......@@ -2271,7 +2201,7 @@ public:
remapped->nl = node->nl;
}
remapped->values.push_back(remapExpr(v));
remapped->value = remapExpr(v);
push_back(remapped);
i++;
......@@ -2281,7 +2211,6 @@ public:
assert(node->nl);
BST_Print* final = new BST_Print();
final->col_offset = node->col_offset;
final->lineno = node->lineno;
// TODO not good to reuse 'dest' like this
final->dest = dest;
......@@ -2312,7 +2241,6 @@ public:
assert(curblock);
BST_Branch* br = new BST_Branch();
br->col_offset = node->col_offset;
br->lineno = node->lineno;
br->test = callNonzero(remapExpr(node->test));
push_back(br);
......@@ -2379,7 +2307,6 @@ public:
bool visit_exec(AST_Exec* node) override {
BST_Exec* astexec = new BST_Exec();
astexec->lineno = node->lineno;
astexec->col_offset = node->col_offset;
astexec->body = remapExpr(node->body);
astexec->globals = remapExpr(node->globals);
astexec->locals = remapExpr(node->locals);
......@@ -2447,7 +2374,7 @@ public:
BST_stmt* makeKill(InternedString name) {
// There might be a better way to represent this, maybe with a dedicated AST_Kill bytecode?
auto del = new BST_Delete();
del->targets.push_back(makeName(name, AST_TYPE::Del, 0, 0, false));
del->target = makeName(name, AST_TYPE::Del, 0, false);
return del;
}
......@@ -2559,7 +2486,6 @@ public:
assert(curblock);
BST_Raise* remapped = new BST_Raise();
remapped->col_offset = node->col_offset;
remapped->lineno = node->lineno;
if (node->arg0)
......@@ -2934,8 +2860,6 @@ public:
AssignVRegsVisitor() : current_block(0), next_vreg(0) {}
bool visit_alias(BST_alias* node) override { RELEASE_ASSERT(0, "these should be removed by the cfg"); }
bool visit_arguments(BST_arguments* node) override {
for (BST_expr* d : node->defaults)
d->accept(this);
......@@ -2957,12 +2881,6 @@ public:
return true;
}
bool visit_lambda(BST_Lambda* node) override {
node->args->accept(this);
return true;
}
bool isNameUsedInSingleBlock(InternedString id) {
assert(step != TrackBlockUsage);
assert(sym_blocks_map.count(id));
......@@ -3087,7 +3005,7 @@ static CFG* computeCFG(llvm::ArrayRef<AST_stmt*> body, AST_TYPE::AST_TYPE ast_ty
auto module_name_value = new BST_Name(stringpool.get("__name__"), AST_TYPE::Load, lineno);
fillScopingInfo(module_name_value, scoping);
module_assign->targets.push_back(module_name_target);
module_assign->target = module_name_target;
module_assign->value = module_name_value;
module_assign->lineno = lineno;
......@@ -3100,7 +3018,7 @@ static CFG* computeCFG(llvm::ArrayRef<AST_stmt*> body, AST_TYPE::AST_TYPE ast_ty
BST_Assign* doc_assign = new BST_Assign();
auto doc_target_name = new BST_Name(stringpool.get("__doc__"), AST_TYPE::Store, lineno);
fillScopingInfo(doc_target_name, scoping);
doc_assign->targets.push_back(doc_target_name);
doc_assign->target = doc_target_name;
auto doc_val = new BST_Str();
doc_val->str_data = ast_cast<AST_Str>(first_expr->value)->str_data;
doc_val->str_type = ast_cast<AST_Str>(first_expr->value)->str_type;
......@@ -3124,8 +3042,7 @@ static CFG* computeCFG(llvm::ArrayRef<AST_stmt*> body, AST_TYPE::AST_TYPE ast_ty
for (AST_expr* arg_expr : args->args) {
if (arg_expr->type == AST_TYPE::Tuple) {
InternedString arg_name = stringpool.get("." + std::to_string(counter));
BST_Name* arg_name_expr
= new BST_Name(arg_name, AST_TYPE::Load, arg_expr->lineno, arg_expr->col_offset);
BST_Name* arg_name_expr = new BST_Name(arg_name, AST_TYPE::Load, arg_expr->lineno);
assert(scoping->getScopeTypeOfName(arg_name) == ScopeInfo::VarScopeType::FAST);
arg_name_expr->lookup_type = ScopeInfo::VarScopeType::FAST;
visitor.pushAssign(arg_expr, arg_name_expr);
......@@ -3158,7 +3075,6 @@ static CFG* computeCFG(llvm::ArrayRef<AST_stmt*> body, AST_TYPE::AST_TYPE ast_ty
// having to support not having a return statement:
BST_Return* return_stmt = new BST_Return();
return_stmt->lineno = getLastLineno(body, lineno);
return_stmt->col_offset = 0;
return_stmt->value = NULL;
visitor.push_back(return_stmt);
}
......
......@@ -997,11 +997,10 @@ void raiseSyntaxErrorHelper(llvm::StringRef file, llvm::StringRef func, AST* nod
// A data structure used for storing information for tracebacks.
struct LineInfo {
public:
int line, column;
int line;
BoxedString* file, *func;
LineInfo(int line, int column, BoxedString* file, BoxedString* func)
: line(line), column(column), file(file), func(func) {}
LineInfo(int line, BoxedString* file, BoxedString* func) : line(line), file(file), func(func) {}
};
// A data structure to simplify passing around all the data about a thrown exception.
......
......@@ -361,7 +361,7 @@ static void print_frame(unw_cursor_t* cursor, const unw_proc_info_t* pip) {
if (frame_type == INTERPRETED && cf && cur_stmt) {
auto source = cf->code_obj->source.get();
// FIXME: dup'ed from lineInfoForFrame
LineInfo line(cur_stmt->lineno, cur_stmt->col_offset, cf->code_obj->filename, cf->code_obj->name);
LineInfo line(cur_stmt->lineno, cf->code_obj->filename, cf->code_obj->name);
printf(" File \"%s\", line %d, in %s\n", line.file->c_str(), line.line, line.func->c_str());
}
}
......
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