summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-10-27 10:15:33 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-10-27 10:31:42 +0200
commit8a39134d5c177ea9735424a8e9f40bfd8986a1c6 (patch)
treeed05d6fcc5589325304abe2d6d86937bb5dfdd64 /compilerplugins
parent5585bc2fbbe8b6072cfdd5cdaaf326f5124632ce (diff)
no need to build the parent tree twice
lets just use the built in parents stuff Change-Id: I7bb705acfcd6c8c18168676b0cdb13c26ba5b95a
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/plugin.cxx27
-rw-r--r--compilerplugins/clang/plugin.hxx2
2 files changed, 8 insertions, 21 deletions
diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx
index d7ab4ad3e63e..e512cc399d16 100644
--- a/compilerplugins/clang/plugin.cxx
+++ b/compilerplugins/clang/plugin.cxx
@@ -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());
diff --git a/compilerplugins/clang/plugin.hxx b/compilerplugins/clang/plugin.hxx
index 39c1c18b14d1..1f57dfeb0ffa 100644
--- a/compilerplugins/clang/plugin.hxx
+++ b/compilerplugins/clang/plugin.hxx
@@ -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 );
};
/**