From 8a39134d5c177ea9735424a8e9f40bfd8986a1c6 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 27 Oct 2017 10:15:33 +0200 Subject: no need to build the parent tree twice lets just use the built in parents stuff Change-Id: I7bb705acfcd6c8c18168676b0cdb13c26ba5b95a --- compilerplugins/clang/plugin.cxx | 27 ++++++++------------------- compilerplugins/clang/plugin.hxx | 2 -- 2 files changed, 8 insertions(+), 21 deletions(-) (limited to 'compilerplugins') 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* 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(parentsRange.begin()->get()); } 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 ); }; /** -- cgit