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