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) {
}
}
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),
scoping(scoping),
scope_info(scoping->getScopeInfoForNode(ast)),
......
......@@ -369,11 +369,11 @@ void compileAndRunModule(AST_Module* m, BoxedModule* bm) {
RELEASE_ASSERT(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_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__");
bm->setattr(doc_str, autoDecref(si->getDocString()), NULL);
......@@ -415,7 +415,7 @@ static FunctionMetadata* compileForEvalOrExec(AST* source, llvm::ArrayRef<AST_st
PyCompilerFlags* flags) {
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.
// `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
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 md;
return new FunctionMetadata(0, false, false, std::move(si));
}
static FunctionMetadata* compileExec(AST_Module* parsedModule, BoxedString* fn, PyCompilerFlags* flags) {
......
......@@ -247,7 +247,7 @@ private:
FutureFlags future_flags;
CFG* cfg;
CFGBlock* curblock;
ScopingAnalysis* scoping_analysis;
ScopingAnalysis& scoping_analysis;
std::vector<ContInfo> continuations;
std::vector<ExcBlockInfo> exc_handlers;
......@@ -257,7 +257,7 @@ private:
public:
CFGVisitor(SourceInfo* source, AST_TYPE::AST_TYPE root_type, FutureFlags future_flags,
ScopingAnalysis* scoping_analysis, CFG* cfg)
ScopingAnalysis& scoping_analysis, CFG* cfg)
: source(source),
root_type(root_type),
future_flags(future_flags),
......@@ -1039,7 +1039,7 @@ private:
func->args = new AST_arguments();
func->args->vararg = NULL;
func->args->kwarg = NULL;
scoping_analysis->registerScopeReplacement(node, func); // critical bit
scoping_analysis.registerScopeReplacement(node, func); // critical bit
return new AST_MakeFunction(func);
}
......@@ -1212,7 +1212,7 @@ private:
def->body = { stmt };
def->args = remapArguments(node->args);
scoping_analysis->registerScopeReplacement(node, def);
scoping_analysis.registerScopeReplacement(node, def);
auto tmp = nodeName();
pushAssign(tmp, new AST_MakeFunction(def));
......@@ -1651,7 +1651,7 @@ public:
for (auto expr : node->bases)
def->bases.push_back(remapExpr(expr));
scoping_analysis->registerScopeReplacement(node, def);
scoping_analysis.registerScopeReplacement(node, def);
auto tmp = nodeName();
pushAssign(tmp, new AST_MakeClass(def));
......@@ -1672,7 +1672,7 @@ public:
def->decorator_list.push_back(remapExpr(expr));
def->args = remapArguments(node->args);
scoping_analysis->registerScopeReplacement(node, def);
scoping_analysis.registerScopeReplacement(node, def);
auto tmp = nodeName();
pushAssign(tmp, new AST_MakeFunction(def));
......@@ -2854,9 +2854,7 @@ CFG* computeCFG(SourceInfo* source, const ParamNames& param_names) {
CFG* rtn = new CFG();
ScopingAnalysis* scoping_analysis = source->scoping;
CFGVisitor visitor(source, source->ast->type, source->future_flags, scoping_analysis, rtn);
CFGVisitor visitor(source, source->ast->type, source->future_flags, *source->scoping, rtn);
bool skip_first = false;
......
......@@ -442,7 +442,7 @@ private:
public:
BoxedModule* parent_module;
ScopingAnalysis* scoping;
std::shared_ptr<ScopingAnalysis> scoping;
std::unique_ptr<ScopeInfo> scope_info;
AST* ast;
CFG* cfg;
......@@ -464,7 +464,8 @@ public:
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();
};
......
......@@ -31,7 +31,7 @@ TEST_F(AnalysisTest, augassign) {
AST_Module* module = caching_parse_file(fn.c_str(), 0);
assert(module);
ScopingAnalysis *scoping = new ScopingAnalysis(module, true);
auto scoping = std::make_shared<ScopingAnalysis>(module, true);
assert(module->body[0]->type == AST_TYPE::FunctionDef);
AST_FunctionDef* func = static_cast<AST_FunctionDef*>(module->body[0]);
......@@ -65,7 +65,7 @@ void doOsrTest(bool is_osr, bool i_maybe_undefined) {
AST_Module* module = caching_parse_file(fn.c_str(), 0);
assert(module);
ScopingAnalysis *scoping = new ScopingAnalysis(module, true);
auto scoping = std::make_shared<ScopingAnalysis>(module, true);
assert(module->body[0]->type == AST_TYPE::FunctionDef);
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