Commit 3b413f50 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Clean up some dead code from the cfg changes

And make BST_arguments a bit safer by removing misleading fields.
parent 763cc656
...@@ -340,16 +340,7 @@ public: ...@@ -340,16 +340,7 @@ public:
return true; return true;
} }
virtual bool visit_arguments(BST_arguments* node) { virtual bool visit_arguments(BST_arguments* node) { RELEASE_ASSERT(0, "this shouldn't get hit"); }
if (node->kwarg)
_doSet(node->kwarg);
if (node->vararg)
_doSet(node->vararg);
for (int i = 0; i < node->args.size(); i++) {
_doSet(node->args[i]);
}
return true;
}
virtual bool visit_exec(BST_Exec* node) { return true; } virtual bool visit_exec(BST_Exec* node) { return true; }
......
...@@ -61,11 +61,6 @@ void BST_arguments::accept(BSTVisitor* v) { ...@@ -61,11 +61,6 @@ void BST_arguments::accept(BSTVisitor* v) {
return; return;
visitVector(defaults, v); visitVector(defaults, v);
visitVector(args, v);
if (kwarg)
kwarg->accept(v);
if (vararg)
vararg->accept(v);
} }
void BST_Assert::accept(BSTVisitor* v) { void BST_Assert::accept(BSTVisitor* v) {
...@@ -883,17 +878,13 @@ bool PrintVisitor::visit_alias(BST_alias* node) { ...@@ -883,17 +878,13 @@ bool PrintVisitor::visit_alias(BST_alias* node) {
} }
bool PrintVisitor::visit_arguments(BST_arguments* node) { bool PrintVisitor::visit_arguments(BST_arguments* node) {
int nargs = node->args.size();
int ndefault = node->defaults.size(); int ndefault = node->defaults.size();
for (int i = 0; i < nargs; i++) { for (int i = 0; i < ndefault; i++) {
if (i > 0) if (i > 0)
stream << ", "; stream << ", ";
node->args[i]->accept(this); stream << "<default " << i << ">=";
if (i >= nargs - ndefault) { node->defaults[i]->accept(this);
stream << "=";
node->defaults[i - (nargs - ndefault)]->accept(this);
}
} }
return true; return true;
} }
......
...@@ -232,9 +232,7 @@ class BST_Name; ...@@ -232,9 +232,7 @@ class BST_Name;
class BST_arguments : public BST { class BST_arguments : public BST {
public: public:
// no lineno, col_offset attributes // no lineno, col_offset attributes
std::vector<BST_expr*> args, defaults; std::vector<BST_expr*> defaults;
BST_Name* kwarg = NULL, * vararg = NULL;
virtual void accept(BSTVisitor* v); virtual void accept(BSTVisitor* v);
......
...@@ -150,42 +150,6 @@ static int getLastLineno(llvm::ArrayRef<AST_stmt*> body, int default_lineno) { ...@@ -150,42 +150,6 @@ static int getLastLineno(llvm::ArrayRef<AST_stmt*> body, int default_lineno) {
return default_lineno; return default_lineno;
return getLastLinenoSub(body.back()); return getLastLinenoSub(body.back());
} }
#if 0
int getLastLineno(AST* ast) {
switch (ast->type) {
case AST_TYPE::Lambda: {
auto lambda = ast_cast<AST_Lambda>(ast);
return getLastLinenoSub(lambda->body);
}
case AST_TYPE::Expression: {
auto expr = ast_cast<AST_Expression>(ast);
return getLastLinenoSub(expr->body);
}
case AST_TYPE::ClassDef: {
auto classdef = ast_cast<AST_ClassDef>(ast);
if (classdef->body.size() == 0)
return classdef->lineno;
return getLastLinenoSub(classdef->body.back());
}
case AST_TYPE::Module: {
auto module = ast_cast<AST_Module>(ast);
if (module->body.size() == 0) {
assert(module->lineno == 0);
return 1;
}
return getLastLinenoSub(module->body.back());
}
case AST_TYPE::FunctionDef: {
auto funcdef = ast_cast<AST_FunctionDef>(ast);
if (funcdef->body.size() == 0)
return funcdef->lineno;
return getLastLinenoSub(funcdef->body.back());
}
default:
RELEASE_ASSERT(0, "%d", ast->type);
}
}
#endif
void CFGBlock::connectTo(CFGBlock* successor, bool allow_backedge) { void CFGBlock::connectTo(CFGBlock* successor, bool allow_backedge) {
assert(successors.size() <= 1); assert(successors.size() <= 1);
...@@ -846,7 +810,6 @@ private: ...@@ -846,7 +810,6 @@ private:
return subscript; return subscript;
} }
// void pushAssign(BST_expr* target, BST_expr* val);
// We need this both on asts (ex assigning to the element name in a for loop), and // We need this both on asts (ex assigning to the element name in a for loop), and
// for bsts (desugaring an augassign) // for bsts (desugaring an augassign)
// TODO: we should get rid of this bst one, or at least not call it the same thing? // TODO: we should get rid of this bst one, or at least not call it the same thing?
...@@ -1259,25 +1222,6 @@ private: ...@@ -1259,25 +1222,6 @@ private:
return rtn; return rtn;
} }
// This is a helper function used for generators expressions and comprehensions.
//
// Generates a FunctionDef which produces scope for `node'. The function produced is empty, so you'd better fill it.
// `node' had better be a kind of node that scoping_analysis thinks can carry scope (see the switch (node->type)
// block in ScopingAnalysis::processNameUsages in analysis/scoping_analysis.cpp); e.g. a Lambda or GeneratorExp.
AST_MakeFunction* makeFunctionForScope(AST* node) {
AST_FunctionDef* func = new AST_FunctionDef();
func->lineno = node->lineno;
func->col_offset = node->col_offset;
// TODO this should be set off the type of the comprehension (ie <setcomp> or <dictcomp> or <genexpr>)
InternedString func_name = internString("<comprehension>");
func->name = func_name;
func->args = new AST_arguments();
func->args->vararg = NULL;
func->args->kwarg = NULL;
RELEASE_ASSERT(0, "should this just be the bare functiondef?");
return new AST_MakeFunction(func);
}
// This is a helper function used for generator expressions and comprehensions. // This is a helper function used for generator expressions and comprehensions.
// TODO(rntz): use this to handle unscoped (i.e. list) comprehensions as well? // TODO(rntz): use this to handle unscoped (i.e. list) comprehensions as well?
void emitComprehensionLoops(int lineno, std::vector<AST_stmt*>* insert_point, void emitComprehensionLoops(int lineno, std::vector<AST_stmt*>* insert_point,
...@@ -1308,7 +1252,7 @@ private: ...@@ -1308,7 +1252,7 @@ private:
} }
do_yield(insert_point); do_yield(insert_point);
// RELEASE_ASSERT(0, "have to delete these new ast nodes"); // TODO: have to delete these new ast nodes
} }
BST_expr* remapGeneratorExp(AST_GeneratorExp* node) { BST_expr* remapGeneratorExp(AST_GeneratorExp* node) {
...@@ -1449,12 +1393,7 @@ private: ...@@ -1449,12 +1393,7 @@ private:
} }
BST_arguments* remapArguments(AST_arguments* args) { BST_arguments* remapArguments(AST_arguments* args) {
// TODO: once in BST we don't need the arguments struct except for evaluating defaults.
auto rtn = new BST_arguments(); auto rtn = new BST_arguments();
// for (auto a : args->args)
// rtn->args.push_back(remapExpr(a));
// rtn->kwarg = remapName(args->kwarg);
// rtn->vararg = remapName(args->vararg);
for (auto expr : args->defaults) for (auto expr : args->defaults)
rtn->defaults.push_back(remapExpr(expr)); rtn->defaults.push_back(remapExpr(expr));
return rtn; return rtn;
...@@ -1470,7 +1409,6 @@ private: ...@@ -1470,7 +1409,6 @@ private:
auto bdef = new BST_FunctionDef(); auto bdef = new BST_FunctionDef();
bdef->lineno = node->lineno; bdef->lineno = node->lineno;
bdef->col_offset = node->col_offset; bdef->col_offset = node->col_offset;
// bdef->name = name;
bdef->args = remapArguments(node->args); bdef->args = remapArguments(node->args);
...@@ -1605,8 +1543,6 @@ private: ...@@ -1605,8 +1543,6 @@ private:
rtn = remapExtSlice(ast_cast<AST_ExtSlice>(node)); rtn = remapExtSlice(ast_cast<AST_ExtSlice>(node));
break; break;
case AST_TYPE::Index: case AST_TYPE::Index:
// if (ast_cast<AST_Index>(node)->value->type == AST_TYPE::Num)
// return node;
rtn = remapIndex(ast_cast<AST_Index>(node)); rtn = remapIndex(ast_cast<AST_Index>(node));
break; break;
case AST_TYPE::Slice: case AST_TYPE::Slice:
......
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