Kaydet (Commit) 8a39134d authored tarafından Noel Grandin's avatar Noel Grandin

no need to build the parent tree twice

lets just use the built in parents stuff

Change-Id: I7bb705acfcd6c8c18168676b0cdb13c26ba5b95a
üst 5585bc2f
......@@ -116,23 +116,20 @@ void Plugin::registerPlugin( Plugin* (*create)( const InstantiationData& ), cons
PluginHandler::registerPlugin( create, optionName, isPPCallback, byDefault );
}
std::unordered_map< const Stmt*, const Stmt* > Plugin::parents;
const Stmt* Plugin::getParentStmt( const Stmt* stmt )
{
if( parents.empty())
buildParents( compiler );
//if(parents.count(stmt)!=1)stmt->dump();
//assert( parents.count( stmt ) == 1 );
return parents[ stmt ];
auto parentsRange = compiler.getASTContext().getParents(*stmt);
if ( parentsRange.begin() == parentsRange.end())
return nullptr;
return parentsRange.begin()->get<Stmt>();
}
Stmt* Plugin::getParentStmt( Stmt* stmt )
{
if( parents.empty())
buildParents( compiler );
//assert( parents.count( stmt ) == 1 );
return const_cast< Stmt* >( parents[ stmt ] );
auto parentsRange = compiler.getASTContext().getParents(*stmt);
if ( parentsRange.begin() == parentsRange.end())
return nullptr;
return const_cast<Stmt*>(parentsRange.begin()->get<Stmt>());
}
static const Decl* getDeclContext(ASTContext& context, const Stmt* stmt)
......@@ -256,14 +253,6 @@ void ParentBuilder::walk( const Stmt* stmt )
} // namespace
void Plugin::buildParents( CompilerInstance& compiler )
{
assert( parents.empty());
ParentBuilder builder;
builder.parents = &parents;
builder.TraverseDecl( compiler.getASTContext().getTranslationUnitDecl());
}
SourceLocation Plugin::locationAfterToken( SourceLocation location )
{
return Lexer::getLocForEndOfToken( location, 0, compiler.getSourceManager(), compiler.getLangOpts());
......
......@@ -88,8 +88,6 @@ private:
template< typename T > static Plugin* createHelper( const InstantiationData& data );
enum { isRewriter = false };
const char* name;
static std::unordered_map< const Stmt*, const Stmt* > parents;
static void buildParents( CompilerInstance& compiler );
};
/**
......
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