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) {
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -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