Commit 47d6b1e6 authored by Marius Wachtler's avatar Marius Wachtler

make ScopingAnalysis a shared_ptr

parent 49502e91
...@@ -91,7 +91,8 @@ void FunctionMetadata::addVersion(CompiledFunction* compiled) { ...@@ -91,7 +91,8 @@ void FunctionMetadata::addVersion(CompiledFunction* compiled) {
} }
} }
SourceInfo::SourceInfo(BoxedModule* m, ScopingAnalysis* scoping, FutureFlags future_flags, AST* ast, BoxedString* fn) SourceInfo::SourceInfo(BoxedModule* m, std::shared_ptr<ScopingAnalysis> scoping, FutureFlags future_flags, AST* ast,
BoxedString* fn)
: parent_module(m), : parent_module(m),
scoping(scoping), scoping(scoping),
scope_info(scoping->getScopeInfoForNode(ast)), scope_info(scoping->getScopeInfoForNode(ast)),
......
...@@ -369,11 +369,11 @@ void compileAndRunModule(AST_Module* m, BoxedModule* bm) { ...@@ -369,11 +369,11 @@ void compileAndRunModule(AST_Module* m, BoxedModule* bm) {
RELEASE_ASSERT(fn, ""); RELEASE_ASSERT(fn, "");
FutureFlags future_flags = getFutureFlags(m->body, fn); FutureFlags future_flags = getFutureFlags(m->body, fn);
ScopingAnalysis* scoping = new ScopingAnalysis(m, true); std::shared_ptr<ScopingAnalysis> scoping = std::make_shared<ScopingAnalysis>(m, true);
auto fn_str = boxString(fn); auto fn_str = boxString(fn);
AUTO_DECREF(fn_str); AUTO_DECREF(fn_str);
std::unique_ptr<SourceInfo> si(new SourceInfo(bm, scoping, future_flags, m, fn_str)); std::unique_ptr<SourceInfo> si(new SourceInfo(bm, std::move(scoping), future_flags, m, fn_str));
static BoxedString* doc_str = getStaticString("__doc__"); static BoxedString* doc_str = getStaticString("__doc__");
bm->setattr(doc_str, autoDecref(si->getDocString()), NULL); bm->setattr(doc_str, autoDecref(si->getDocString()), NULL);
...@@ -415,7 +415,7 @@ static FunctionMetadata* compileForEvalOrExec(AST* source, llvm::ArrayRef<AST_st ...@@ -415,7 +415,7 @@ static FunctionMetadata* compileForEvalOrExec(AST* source, llvm::ArrayRef<AST_st
PyCompilerFlags* flags) { PyCompilerFlags* flags) {
Timer _t("for evalOrExec()"); Timer _t("for evalOrExec()");
ScopingAnalysis* scoping = new ScopingAnalysis(source, false); auto scoping = std::make_shared<ScopingAnalysis>(source, false);
// `my_future_flags` are the future flags enabled in the exec's code. // `my_future_flags` are the future flags enabled in the exec's code.
// `caller_future_flags` are the future flags of the source that the exec statement is in. // `caller_future_flags` are the future flags of the source that the exec statement is in.
...@@ -428,10 +428,9 @@ static FunctionMetadata* compileForEvalOrExec(AST* source, llvm::ArrayRef<AST_st ...@@ -428,10 +428,9 @@ static FunctionMetadata* compileForEvalOrExec(AST* source, llvm::ArrayRef<AST_st
flags->cf_flags = future_flags; flags->cf_flags = future_flags;
} }
std::unique_ptr<SourceInfo> si(new SourceInfo(getCurrentModule(), scoping, future_flags, source, fn)); std::unique_ptr<SourceInfo> si(new SourceInfo(getCurrentModule(), std::move(scoping), future_flags, source, fn));
FunctionMetadata* md = new FunctionMetadata(0, false, false, std::move(si)); return new FunctionMetadata(0, false, false, std::move(si));
return md;
} }
static FunctionMetadata* compileExec(AST_Module* parsedModule, BoxedString* fn, PyCompilerFlags* flags) { static FunctionMetadata* compileExec(AST_Module* parsedModule, BoxedString* fn, PyCompilerFlags* flags) {
......
...@@ -247,7 +247,7 @@ private: ...@@ -247,7 +247,7 @@ private:
FutureFlags future_flags; FutureFlags future_flags;
CFG* cfg; CFG* cfg;
CFGBlock* curblock; CFGBlock* curblock;
ScopingAnalysis* scoping_analysis; ScopingAnalysis& scoping_analysis;
std::vector<ContInfo> continuations; std::vector<ContInfo> continuations;
std::vector<ExcBlockInfo> exc_handlers; std::vector<ExcBlockInfo> exc_handlers;
...@@ -257,7 +257,7 @@ private: ...@@ -257,7 +257,7 @@ private:
public: public:
CFGVisitor(SourceInfo* source, AST_TYPE::AST_TYPE root_type, FutureFlags future_flags, CFGVisitor(SourceInfo* source, AST_TYPE::AST_TYPE root_type, FutureFlags future_flags,
ScopingAnalysis* scoping_analysis, CFG* cfg) ScopingAnalysis& scoping_analysis, CFG* cfg)
: source(source), : source(source),
root_type(root_type), root_type(root_type),
future_flags(future_flags), future_flags(future_flags),
...@@ -1039,7 +1039,7 @@ private: ...@@ -1039,7 +1039,7 @@ private:
func->args = new AST_arguments(); func->args = new AST_arguments();
func->args->vararg = NULL; func->args->vararg = NULL;
func->args->kwarg = NULL; func->args->kwarg = NULL;
scoping_analysis->registerScopeReplacement(node, func); // critical bit scoping_analysis.registerScopeReplacement(node, func); // critical bit
return new AST_MakeFunction(func); return new AST_MakeFunction(func);
} }
...@@ -1212,7 +1212,7 @@ private: ...@@ -1212,7 +1212,7 @@ private:
def->body = { stmt }; def->body = { stmt };
def->args = remapArguments(node->args); def->args = remapArguments(node->args);
scoping_analysis->registerScopeReplacement(node, def); scoping_analysis.registerScopeReplacement(node, def);
auto tmp = nodeName(); auto tmp = nodeName();
pushAssign(tmp, new AST_MakeFunction(def)); pushAssign(tmp, new AST_MakeFunction(def));
...@@ -1651,7 +1651,7 @@ public: ...@@ -1651,7 +1651,7 @@ public:
for (auto expr : node->bases) for (auto expr : node->bases)
def->bases.push_back(remapExpr(expr)); def->bases.push_back(remapExpr(expr));
scoping_analysis->registerScopeReplacement(node, def); scoping_analysis.registerScopeReplacement(node, def);
auto tmp = nodeName(); auto tmp = nodeName();
pushAssign(tmp, new AST_MakeClass(def)); pushAssign(tmp, new AST_MakeClass(def));
...@@ -1672,7 +1672,7 @@ public: ...@@ -1672,7 +1672,7 @@ public:
def->decorator_list.push_back(remapExpr(expr)); def->decorator_list.push_back(remapExpr(expr));
def->args = remapArguments(node->args); def->args = remapArguments(node->args);
scoping_analysis->registerScopeReplacement(node, def); scoping_analysis.registerScopeReplacement(node, def);
auto tmp = nodeName(); auto tmp = nodeName();
pushAssign(tmp, new AST_MakeFunction(def)); pushAssign(tmp, new AST_MakeFunction(def));
...@@ -2854,9 +2854,7 @@ CFG* computeCFG(SourceInfo* source, const ParamNames& param_names) { ...@@ -2854,9 +2854,7 @@ CFG* computeCFG(SourceInfo* source, const ParamNames& param_names) {
CFG* rtn = new CFG(); CFG* rtn = new CFG();
ScopingAnalysis* scoping_analysis = source->scoping; CFGVisitor visitor(source, source->ast->type, source->future_flags, *source->scoping, rtn);
CFGVisitor visitor(source, source->ast->type, source->future_flags, scoping_analysis, rtn);
bool skip_first = false; bool skip_first = false;
......
...@@ -442,7 +442,7 @@ private: ...@@ -442,7 +442,7 @@ private:
public: public:
BoxedModule* parent_module; BoxedModule* parent_module;
ScopingAnalysis* scoping; std::shared_ptr<ScopingAnalysis> scoping;
std::unique_ptr<ScopeInfo> scope_info; std::unique_ptr<ScopeInfo> scope_info;
AST* ast; AST* ast;
CFG* cfg; CFG* cfg;
...@@ -464,7 +464,8 @@ public: ...@@ -464,7 +464,8 @@ public:
Box* getDocString(); Box* getDocString();
SourceInfo(BoxedModule* m, ScopingAnalysis* scoping, FutureFlags future_flags, AST* ast, BoxedString* fn); SourceInfo(BoxedModule* m, std::shared_ptr<ScopingAnalysis> scoping, FutureFlags future_flags, AST* ast,
BoxedString* fn);
~SourceInfo(); ~SourceInfo();
}; };
......
...@@ -31,7 +31,7 @@ TEST_F(AnalysisTest, augassign) { ...@@ -31,7 +31,7 @@ TEST_F(AnalysisTest, augassign) {
AST_Module* module = caching_parse_file(fn.c_str(), 0); AST_Module* module = caching_parse_file(fn.c_str(), 0);
assert(module); assert(module);
ScopingAnalysis *scoping = new ScopingAnalysis(module, true); auto scoping = std::make_shared<ScopingAnalysis>(module, true);
assert(module->body[0]->type == AST_TYPE::FunctionDef); assert(module->body[0]->type == AST_TYPE::FunctionDef);
AST_FunctionDef* func = static_cast<AST_FunctionDef*>(module->body[0]); AST_FunctionDef* func = static_cast<AST_FunctionDef*>(module->body[0]);
...@@ -65,7 +65,7 @@ void doOsrTest(bool is_osr, bool i_maybe_undefined) { ...@@ -65,7 +65,7 @@ void doOsrTest(bool is_osr, bool i_maybe_undefined) {
AST_Module* module = caching_parse_file(fn.c_str(), 0); AST_Module* module = caching_parse_file(fn.c_str(), 0);
assert(module); assert(module);
ScopingAnalysis *scoping = new ScopingAnalysis(module, true); auto scoping = std::make_shared<ScopingAnalysis>(module, true);
assert(module->body[0]->type == AST_TYPE::FunctionDef); assert(module->body[0]->type == AST_TYPE::FunctionDef);
AST_FunctionDef* func = static_cast<AST_FunctionDef*>(module->body[0]); AST_FunctionDef* func = static_cast<AST_FunctionDef*>(module->body[0]);
......
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