[clang-tools-extra] r270566 - [find-all-symbols] Added hardcode header mapping from header postfix to header name for STL symbols.

Eric Liu via cfe-commits cfe-commits at lists.llvm.org
Tue May 24 08:11:00 PDT 2016


Author: ioeric
Date: Tue May 24 10:10:58 2016
New Revision: 270566

URL: http://llvm.org/viewvc/llvm-project?rev=270566&view=rev
Log:
[find-all-symbols] Added hardcode header mapping from header postfix to header name for STL symbols.

Summary: [find-all-symbols] Added hardcode header mapping from header postfix to header name for STL symbols.

Reviewers: klimek, bkramer

Subscribers: cfe-commits, hokein

Differential Revision: http://reviews.llvm.org/D20566

Added:
    clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbolsAction.cpp
    clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbolsAction.h
    clang-tools-extra/trunk/include-fixer/find-all-symbols/HeaderMapCollector.cpp
    clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/STLPostfixHeaderMap.cpp
    clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/STLPostfixHeaderMap.h
Modified:
    clang-tools-extra/trunk/include-fixer/find-all-symbols/CMakeLists.txt
    clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllMacros.cpp
    clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp
    clang-tools-extra/trunk/include-fixer/find-all-symbols/HeaderMapCollector.h
    clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/CMakeLists.txt
    clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
    clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp

Modified: clang-tools-extra/trunk/include-fixer/find-all-symbols/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/find-all-symbols/CMakeLists.txt?rev=270566&r1=270565&r2=270566&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/CMakeLists.txt Tue May 24 10:10:58 2016
@@ -4,7 +4,9 @@ set(LLVM_LINK_COMPONENTS
 
 add_clang_library(findAllSymbols
   FindAllSymbols.cpp
+  FindAllSymbolsAction.cpp
   FindAllMacros.cpp
+  HeaderMapCollector.cpp
   PragmaCommentHandler.cpp
   SymbolInfo.cpp
 

Modified: clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllMacros.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllMacros.cpp?rev=270566&r1=270565&r2=270566&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllMacros.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllMacros.cpp Tue May 24 10:10:58 2016
@@ -28,11 +28,7 @@ void FindAllMacros::MacroDefined(const T
     return;
 
   // If Collector is not nullptr, check pragma remapping header.
-  if (Collector) {
-    auto Iter = Collector->getHeaderMappingTable().find(FilePath);
-    if (Iter != Collector->getHeaderMappingTable().end())
-      FilePath = Iter->second;
-  }
+  FilePath = Collector ? Collector->getMappedHeader(FilePath) : FilePath;
 
   SymbolInfo Symbol(MacroNameTok.getIdentifierInfo()->getName(),
                     SymbolInfo::SymbolKind::Macro, FilePath.str(),

Modified: clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp?rev=270566&r1=270565&r2=270566&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp Tue May 24 10:10:58 2016
@@ -97,11 +97,7 @@ CreateSymbolInfo(const NamedDecl *ND, co
     return llvm::None;
 
   // If Collector is not nullptr, check pragma remapping header.
-  if (Collector) {
-    auto Iter = Collector->getHeaderMappingTable().find(FilePath);
-    if (Iter != Collector->getHeaderMappingTable().end())
-      FilePath = Iter->second;
-  }
+  FilePath = Collector ? Collector->getMappedHeader(FilePath) : FilePath;
 
   return SymbolInfo(ND->getNameAsString(), Type, FilePath.str(),
                     SM.getExpansionLineNumber(Loc), GetContexts(ND));

Added: clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbolsAction.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbolsAction.cpp?rev=270566&view=auto
==============================================================================
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbolsAction.cpp (added)
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbolsAction.cpp Tue May 24 10:10:58 2016
@@ -0,0 +1,32 @@
+//===-- FindAllSymbolsAction.cpp - find all symbols action --------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "FindAllSymbolsAction.h"
+
+namespace clang {
+namespace find_all_symbols {
+
+FindAllSymbolsAction::FindAllSymbolsAction(
+    SymbolReporter *Reporter, const HeaderMapCollector::HeaderMap *PostfixMap)
+    : Reporter(Reporter), Collector(PostfixMap), Handler(&Collector),
+      Matcher(Reporter, &Collector) {
+  Matcher.registerMatchers(&MatchFinder);
+}
+
+std::unique_ptr<clang::ASTConsumer>
+FindAllSymbolsAction::CreateASTConsumer(clang::CompilerInstance &Compiler,
+                                        StringRef InFile) {
+  Compiler.getPreprocessor().addCommentHandler(&Handler);
+  Compiler.getPreprocessor().addPPCallbacks(llvm::make_unique<FindAllMacros>(
+      Reporter, &Compiler.getSourceManager(), &Collector));
+  return MatchFinder.newASTConsumer();
+}
+
+} // namespace find_all_symbols
+} // namespace clang

Added: clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbolsAction.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbolsAction.h?rev=270566&view=auto
==============================================================================
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbolsAction.h (added)
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbolsAction.h Tue May 24 10:10:58 2016
@@ -0,0 +1,61 @@
+//===-- FindAllSymbolsAction.h - find all symbols action --------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_FIND_ALL_SYMBOLS_ACTION_H
+#define LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_FIND_ALL_SYMBOLS_ACTION_H
+
+#include "FindAllMacros.h"
+#include "FindAllSymbols.h"
+#include "HeaderMapCollector.h"
+#include "PragmaCommentHandler.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Tooling/Tooling.h"
+
+namespace clang {
+namespace find_all_symbols {
+
+class FindAllSymbolsAction : public clang::ASTFrontendAction {
+public:
+  explicit FindAllSymbolsAction(
+      SymbolReporter *Reporter,
+      const HeaderMapCollector::HeaderMap *PostfixMap = nullptr);
+
+  std::unique_ptr<clang::ASTConsumer>
+  CreateASTConsumer(clang::CompilerInstance &Compiler,
+                    StringRef InFile) override;
+
+private:
+  SymbolReporter *const Reporter;
+  clang::ast_matchers::MatchFinder MatchFinder;
+  HeaderMapCollector Collector;
+  PragmaCommentHandler Handler;
+  FindAllSymbols Matcher;
+};
+
+class FindAllSymbolsActionFactory : public tooling::FrontendActionFactory {
+public:
+  FindAllSymbolsActionFactory(
+      SymbolReporter *Reporter,
+      const HeaderMapCollector::HeaderMap *PostfixMap = nullptr)
+      : Reporter(Reporter), PostfixMap(PostfixMap) {}
+
+  virtual clang::FrontendAction *create() override {
+    return new FindAllSymbolsAction(Reporter, PostfixMap);
+  }
+
+private:
+  SymbolReporter *const Reporter;
+  const HeaderMapCollector::HeaderMap *const PostfixMap;
+};
+
+} // namespace find_all_symbols
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_FIND_ALL_SYMBOLS_ACTION_H

Added: clang-tools-extra/trunk/include-fixer/find-all-symbols/HeaderMapCollector.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/find-all-symbols/HeaderMapCollector.cpp?rev=270566&view=auto
==============================================================================
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/HeaderMapCollector.cpp (added)
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/HeaderMapCollector.cpp Tue May 24 10:10:58 2016
@@ -0,0 +1,34 @@
+//===-- HeaderMapCoolector.h - find all symbols------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "HeaderMapCollector.h"
+
+namespace clang {
+namespace find_all_symbols {
+
+llvm::StringRef
+HeaderMapCollector::getMappedHeader(llvm::StringRef Header) const {
+  auto Iter = HeaderMappingTable.find(Header);
+  if (Iter != HeaderMappingTable.end())
+    return Iter->second;
+  // If there is no complete header name mapping for this header, check the
+  // postfix mapping.
+  // FIXME: this is not very efficient. Change PostfixMappingTable to use
+  // postfix tree if necessary.
+  if (PostfixMappingTable) {
+    for (const auto &Entry : *PostfixMappingTable) {
+      if (Header.endswith(Entry.first()))
+        return Entry.second;
+    }
+  }
+  return Header;
+}
+
+} // namespace find_all_symbols
+} // namespace clang

Modified: clang-tools-extra/trunk/include-fixer/find-all-symbols/HeaderMapCollector.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/find-all-symbols/HeaderMapCollector.h?rev=270566&r1=270565&r2=270566&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/HeaderMapCollector.h (original)
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/HeaderMapCollector.h Tue May 24 10:10:58 2016
@@ -16,20 +16,36 @@
 namespace clang {
 namespace find_all_symbols {
 
-/// \brief HeaderMappCollector collects all remapping header files.
+/// \brief HeaderMappCollector collects all remapping header files. This maps
+/// complete header names or postfixes of header names to header names.
 class HeaderMapCollector {
 public:
   typedef llvm::StringMap<std::string> HeaderMap;
 
+  HeaderMapCollector() : PostfixMappingTable(nullptr) {}
+
+  explicit HeaderMapCollector(const HeaderMap *PostfixMap)
+      : PostfixMappingTable(PostfixMap) {}
+
   void addHeaderMapping(llvm::StringRef OrignalHeaderPath,
                         llvm::StringRef MappingHeaderPath) {
     HeaderMappingTable[OrignalHeaderPath] = MappingHeaderPath;
   };
-  const HeaderMap &getHeaderMappingTable() const { return HeaderMappingTable; };
+
+  /// Check if there is a mapping from \p Header or its postfix to another
+  /// header name.
+  /// \param Header A header name.
+  /// \return \p Header itself if there is no mapping for it; otherwise, return
+  /// a mapped header name.
+  llvm::StringRef getMappedHeader(llvm::StringRef Header) const;
 
 private:
   /// A string-to-string map saving the mapping relationship.
   HeaderMap HeaderMappingTable;
+
+  // A postfix-to-header name map.
+  // This is a reference to a hard-coded map.
+  const HeaderMap *const PostfixMappingTable;
 };
 
 } // namespace find_all_symbols

Modified: clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/CMakeLists.txt?rev=270566&r1=270565&r2=270566&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/CMakeLists.txt Tue May 24 10:10:58 2016
@@ -1,6 +1,9 @@
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
 
-add_clang_executable(find-all-symbols FindAllSymbolsMain.cpp)
+add_clang_executable(find-all-symbols
+    FindAllSymbolsMain.cpp
+    STLPostfixHeaderMap.cpp
+    )
 target_link_libraries(find-all-symbols
 
   clangAST

Modified: clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp?rev=270566&r1=270565&r2=270566&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp Tue May 24 10:10:58 2016
@@ -7,10 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "FindAllMacros.h"
-#include "FindAllSymbols.h"
-#include "HeaderMapCollector.h"
-#include "PragmaCommentHandler.h"
+#include "FindAllSymbolsAction.h"
+#include "STLPostfixHeaderMap.h"
 #include "SymbolInfo.h"
 #include "SymbolReporter.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -61,60 +59,32 @@ static cl::opt<std::string> MergeDir("me
 The directory for merging symbols.)"),
                                      cl::init(""),
                                      cl::cat(FindAllSymbolsCategory));
-
 namespace clang {
 namespace find_all_symbols {
 
 class YamlReporter : public clang::find_all_symbols::SymbolReporter {
 public:
-  ~YamlReporter() override {}
-
-  void reportSymbol(StringRef FileName, const SymbolInfo &Symbol) override {
-    Symbols[FileName].insert(Symbol);
-  }
-
-  void Write(const std::string &Dir) {
+  ~YamlReporter() override {
     for (const auto &Symbol : Symbols) {
       int FD;
       SmallString<128> ResultPath;
       llvm::sys::fs::createUniqueFile(
-          Dir + "/" + llvm::sys::path::filename(Symbol.first) + "-%%%%%%.yaml",
+          OutputDir + "/" + llvm::sys::path::filename(Symbol.first) +
+              "-%%%%%%.yaml",
           FD, ResultPath);
       llvm::raw_fd_ostream OS(FD, /*shouldClose=*/true);
       WriteSymbolInfosToStream(OS, Symbol.second);
     }
   }
 
-private:
-  std::map<std::string, std::set<SymbolInfo>> Symbols;
-};
-
-// FIXME: Move this out from the main file, make it reusable in unittest.
-class FindAllSymbolsAction : public clang::ASTFrontendAction {
-public:
-  FindAllSymbolsAction()
-      : Reporter(), MatchFinder(), Collector(), Handler(&Collector),
-        Matcher(&Reporter, &Collector) {
-    Matcher.registerMatchers(&MatchFinder);
-  }
-
-  std::unique_ptr<clang::ASTConsumer>
-  CreateASTConsumer(clang::CompilerInstance &Compiler,
-                    StringRef InFile) override {
-    Compiler.getPreprocessor().addCommentHandler(&Handler);
-    Compiler.getPreprocessor().addPPCallbacks(llvm::make_unique<FindAllMacros>(
-        &Reporter, &Compiler.getSourceManager(), &Collector));
-    return MatchFinder.newASTConsumer();
+  void reportSymbol(StringRef FileName, const SymbolInfo &Symbol) override {
+    Symbols[FileName].insert(Symbol);
   }
 
-  void EndSourceFileAction() override { Reporter.Write(OutputDir); }
-
 private:
-  YamlReporter Reporter;
-  clang::ast_matchers::MatchFinder MatchFinder;
-  HeaderMapCollector Collector;
-  PragmaCommentHandler Handler;
-  FindAllSymbols Matcher;
+  // Directory to write yaml files to.
+  const std::string Directory;
+  std::map<std::string, std::set<SymbolInfo>> Symbols;
 };
 
 bool Merge(llvm::StringRef MergeDir, llvm::StringRef OutputFile) {
@@ -176,8 +146,12 @@ int main(int argc, const char **argv) {
     clang::find_all_symbols::Merge(MergeDir, sources[0]);
     return 0;
   }
-  Tool.run(
-      newFrontendActionFactory<clang::find_all_symbols::FindAllSymbolsAction>()
-          .get());
+
+  clang::find_all_symbols::YamlReporter Reporter;
+
+  auto Factory =
+      llvm::make_unique<clang::find_all_symbols::FindAllSymbolsActionFactory>(
+          &Reporter, &clang::find_all_symbols::STLPostfixHeaderMap);
+  Tool.run(Factory.get());
   return 0;
 }

Added: clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/STLPostfixHeaderMap.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/STLPostfixHeaderMap.cpp?rev=270566&view=auto
==============================================================================
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/STLPostfixHeaderMap.cpp (added)
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/STLPostfixHeaderMap.cpp Tue May 24 10:10:58 2016
@@ -0,0 +1,358 @@
+//===-- STLPostfixHeaderMap.h - hardcoded STL header map --------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "STLPostfixHeaderMap.h"
+
+namespace clang {
+namespace find_all_symbols {
+
+const HeaderMapCollector::HeaderMap STLPostfixHeaderMap = {
+    {"include/__stddef_max_align_t.h", "<cstddef>"},
+    {"include/__wmmintrin_aes.h", "<wmmintrin.h>"},
+    {"include/__wmmintrin_pclmul.h", "<wmmintrin.h>"},
+    {"include/adxintrin.h", "<immintrin.h>"},
+    {"include/ammintrin.h", "<ammintrin.h>"},
+    {"include/avx2intrin.h", "<immintrin.h>"},
+    {"include/avx512bwintrin.h", "<immintrin.h>"},
+    {"include/avx512cdintrin.h", "<immintrin.h>"},
+    {"include/avx512dqintrin.h", "<immintrin.h>"},
+    {"include/avx512erintrin.h", "<immintrin.h>"},
+    {"include/avx512fintrin.h", "<immintrin.h>"},
+    {"include/avx512ifmaintrin.h", "<immintrin.h>"},
+    {"include/avx512ifmavlintrin.h", "<immintrin.h>"},
+    {"include/avx512pfintrin.h", "<immintrin.h>"},
+    {"include/avx512vbmiintrin.h", "<immintrin.h>"},
+    {"include/avx512vbmivlintrin.h", "<immintrin.h>"},
+    {"include/avx512vlbwintrin.h", "<immintrin.h>"},
+    {"include/avx512vlcdintrin.h", "<immintrin.h>"},
+    {"include/avx512vldqintrin.h", "<immintrin.h>"},
+    {"include/avx512vlintrin.h", "<immintrin.h>"},
+    {"include/avxintrin.h", "<immintrin.h>"},
+    {"include/bmi2intrin.h", "<x86intrin.h>"},
+    {"include/bmiintrin.h", "<x86intrin.h>"},
+    {"include/emmintrin.h", "<emmintrin.h>"},
+    {"include/f16cintrin.h", "<emmintrin.h>"},
+    {"include/float.h", "<cfloat>"},
+    {"include/fma4intrin.h", "<x86intrin.h>"},
+    {"include/fmaintrin.h", "<immintrin.h>"},
+    {"include/fxsrintrin.h", "<immintrin.h>"},
+    {"include/ia32intrin.h", "<x86intrin.h>"},
+    {"include/immintrin.h", "<immintrin.h>"},
+    {"include/inttypes.h", "<cinttypes>"},
+    {"include/limits.h", "<climits>"},
+    {"include/lzcntintrin.h", "<x86intrin.h>"},
+    {"include/mm3dnow.h", "<mm3dnow.h>"},
+    {"include/mm_malloc.h", "<mm_malloc.h>"},
+    {"include/mmintrin.h", "<mmintrin>"},
+    {"include/mwaitxintrin.h", "<x86intrin.h>"},
+    {"include/pkuintrin.h", "<immintrin.h>"},
+    {"include/pmmintrin.h", "<pmmintrin.h>"},
+    {"include/popcntintrin.h", "<popcntintrin.h>"},
+    {"include/prfchwintrin.h", "<x86intrin.h>"},
+    {"include/rdseedintrin.h", "<x86intrin.h>"},
+    {"include/rtmintrin.h", "<immintrin.h>"},
+    {"include/shaintrin.h", "<immintrin.h>"},
+    {"include/smmintrin.h", "<smmintrin>"},
+    {"include/stdalign.h", "<cstdalign>"},
+    {"include/stdarg.h", "<cstdarg>"},
+    {"include/stdbool.h", "<cstdbool>"},
+    {"include/stddef.h", "<cwchar>"},
+    {"include/stdint.h", "<cstdint>"},
+    {"include/tbmintrin.h", "<x86intrin.h>"},
+    {"include/tmmintrin.h", "<tmmintrin.h>"},
+    {"include/wmmintrin.h", "<wmmintrin.h>"},
+    {"include/x86intrin.h", "<x86intrin.h>"},
+    {"include/xmmintrin.h", "<xmmintrin.h>"},
+    {"include/xopintrin.h", "<x86intrin.h>"},
+    {"include/xsavecintrin.h", "<immintrin.h>"},
+    {"include/xsaveintrin.h", "<immintrin.h>"},
+    {"include/xsaveoptintrin.h", "<immintrin.h>"},
+    {"include/xsavesintrin.h", "<immintrin.h>"},
+    {"include/xtestintrin.h", "<immintrin.h>"},
+    {"include/_G_config.h", "<cstdio>"},
+    {"include/alloca.h", "<cstdlib>"},
+    {"include/asm-generic/errno-base.h", "<cerrno>"},
+    {"include/asm-generic/errno.h", "<cerrno>"},
+    {"include/assert.h", "<cassert>"},
+    {"algorithm", "<algorithm>"},
+    {"array", "<array>"},
+    {"atomic", "<atomic>"},
+    {"backward/auto_ptr.h", "<memory>"},
+    {"backward/binders.h", "<string>"},
+    {"bits/algorithmfwd.h", "<algorithm>"},
+    {"bits/alloc_traits.h", "<unordered_set>"},
+    {"bits/allocator.h", "<string>"},
+    {"bits/atomic_base.h", "<atomic>"},
+    {"bits/atomic_lockfree_defines.h", "<exception>"},
+    {"bits/basic_ios.h", "<ios>"},
+    {"bits/basic_ios.tcc", "<ios>"},
+    {"bits/basic_string.h", "<string>"},
+    {"bits/basic_string.tcc", "<string>"},
+    {"bits/char_traits.h", "<string>"},
+    {"bits/codecvt.h", "<fstream>"},
+    {"bits/concept_check.h", "<numeric>"},
+    {"bits/cpp_type_traits.h", "<cmath>"},
+    {"bits/cxxabi_forced.h", "<cxxabi.h>"},
+    {"bits/deque.tcc", "<deque>"},
+    {"bits/exception_defines.h", "<exception>"},
+    {"bits/exception_ptr.h", "<exception>"},
+    {"bits/forward_list.h", "<forward_list>"},
+    {"bits/forward_list.tcc", "<forward_list>"},
+    {"bits/fstream.tcc", "<fstream>"},
+    {"bits/functexcept.h", "<list>"},
+    {"bits/functional_hash.h", "<string>"},
+    {"bits/gslice.h", "<valarray>"},
+    {"bits/gslice_array.h", "<valarray>"},
+    {"bits/hash_bytes.h", "<typeinfo>"},
+    {"bits/hashtable.h", "<unordered_set>"},
+    {"bits/hashtable_policy.h", "<unordered_set>"},
+    {"bits/indirect_array.h", "<valarray>"},
+    {"bits/ios_base.h", "<streambuf>"},
+    {"bits/istream.tcc", "<istream>"},
+    {"bits/list.tcc", "<list>"},
+    {"bits/locale_classes.h", "<locale>"},
+    {"bits/locale_classes.tcc", "<locale>"},
+    {"bits/locale_facets.h", "<locale>"},
+    {"bits/locale_facets.tcc", "<locale>"},
+    {"bits/locale_facets_nonio.h", "<locale>"},
+    {"bits/locale_facets_nonio.tcc", "<locale>"},
+    {"bits/localefwd.h", "<string>"},
+    {"bits/mask_array.h", "<valarray>"},
+    {"bits/memoryfwd.h", "<string>"},
+    {"bits/move.h", "<utility>"},
+    {"bits/nested_exception.h", "<exception>"},
+    {"bits/ostream.tcc", "<ostream>"},
+    {"bits/ostream_insert.h", "<string>"},
+    {"bits/postypes.h", "<iosfwd>"},
+    {"bits/ptr_traits.h", "<unordered_set>"},
+    {"bits/random.h", "<random>"},
+    {"bits/random.tcc", "<random>"},
+    {"bits/range_access.h", "<string>"},
+    {"bits/regex.h", "<regex>"},
+    {"bits/regex_compiler.h", "<regex>"},
+    {"bits/regex_constants.h", "<regex>"},
+    {"bits/regex_cursor.h", "<regex>"},
+    {"bits/regex_error.h", "<regex>"},
+    {"bits/regex_grep_matcher.h", "<regex>"},
+    {"bits/regex_grep_matcher.tcc", "<regex>"},
+    {"bits/regex_nfa.h", "<regex>"},
+    {"bits/shared_ptr.h", "<memory>"},
+    {"bits/shared_ptr_base.h", "<memory>"},
+    {"bits/slice_array.h", "<valarray>"},
+    {"bits/sstream.tcc", "<sstream>"},
+    {"bits/stl_algo.h", "<algorithm>"},
+    {"bits/stl_algobase.h", "<list>"},
+    {"bits/stl_bvector.h", "<vector>"},
+    {"bits/stl_construct.h", "<deque>"},
+    {"bits/stl_deque.h", "<deque>"},
+    {"bits/stl_function.h", "<string>"},
+    {"bits/stl_heap.h", "<queue>"},
+    {"bits/stl_iterator.h", "<iterator>"},
+    {"bits/stl_iterator_base_funcs.h", "<iterator>"},
+    {"bits/stl_iterator_base_types.h", "<numeric>"},
+    {"bits/stl_list.h", "<list>"},
+    {"bits/stl_map.h", "<map>"},
+    {"bits/stl_multimap.h", "<map>"},
+    {"bits/stl_multiset.h", "<set>"},
+    {"bits/stl_numeric.h", "<numeric>"},
+    {"bits/stl_pair.h", "<utility>"},
+    {"bits/stl_queue.h", "<queue>"},
+    {"bits/stl_raw_storage_iter.h", "<memory>"},
+    {"bits/stl_relops.h", "<utility>"},
+    {"bits/stl_set.h", "<set>"},
+    {"bits/stl_stack.h", "<stack>"},
+    {"bits/stl_tempbuf.h", "<memory>"},
+    {"bits/stl_tree.h", "<map>"},
+    {"bits/stl_uninitialized.h", "<deque>"},
+    {"bits/stl_vector.h", "<vector>"},
+    {"bits/stream_iterator.h", "<iterator>"},
+    {"bits/streambuf.tcc", "<streambuf>"},
+    {"bits/streambuf_iterator.h", "<locale>"},
+    {"bits/stringfwd.h", "<string>"},
+    {"bits/unique_ptr.h", "<memory>"},
+    {"bits/unordered_map.h", "<unordered_map>"},
+    {"bits/unordered_set.h", "<unordered_set>"},
+    {"bits/uses_allocator.h", "<tuple>"},
+    {"bits/valarray_after.h", "<valarray>"},
+    {"bits/valarray_array.h", "<valarray>"},
+    {"bits/valarray_array.tcc", "<valarray>"},
+    {"bits/valarray_before.h", "<valarray>"},
+    {"bits/vector.tcc", "<vector>"},
+    {"bitset", "<bitset>"},
+    {"ccomplex", "<ccomplex>"},
+    {"cctype", "<cctype>"},
+    {"cerrno", "<cerrno>"},
+    {"cfenv", "<cfenv>"},
+    {"cfloat", "<cfloat>"},
+    {"chrono", "<chrono>"},
+    {"cinttypes", "<cinttypes>"},
+    {"climits", "<climits>"},
+    {"clocale", "<clocale>"},
+    {"cmath", "<cmath>"},
+    {"complex", "<complex>"},
+    {"complex.h", "<complex.h>"},
+    {"condition_variable", "<condition_variable>"},
+    {"csetjmp", "<csetjmp>"},
+    {"csignal", "<csignal>"},
+    {"cstdalign", "<cstdalign>"},
+    {"cstdarg", "<cstdarg>"},
+    {"cstdbool", "<cstdbool>"},
+    {"cstdint", "<cstdint>"},
+    {"cstdio", "<cstdio>"},
+    {"cstdlib", "<cstdlib>"},
+    {"cstring", "<cstring>"},
+    {"ctgmath", "<ctgmath>"},
+    {"ctime", "<ctime>"},
+    {"cwchar", "<cwchar>"},
+    {"cwctype", "<cwctype>"},
+    {"cxxabi.h", "<cxxabi.h>"},
+    {"debug/debug.h", "<numeric>"},
+    {"deque", "<deque>"},
+    {"exception", "<exception>"},
+    {"ext/alloc_traits.h", "<deque>"},
+    {"ext/atomicity.h", "<memory>"},
+    {"ext/concurrence.h", "<memory>"},
+    {"ext/new_allocator.h", "<string>"},
+    {"ext/numeric_traits.h", "<list>"},
+    {"ext/string_conversions.h", "<string>"},
+    {"ext/type_traits.h", "<cmath>"},
+    {"fenv.h", "<fenv.h>"},
+    {"forward_list", "<forward_list>"},
+    {"fstream", "<fstream>"},
+    {"functional", "<functional>"},
+    {"future", "<future>"},
+    {"initializer_list", "<initializer_list>"},
+    {"iomanip", "<iomanip>"},
+    {"ios", "<ios>"},
+    {"iosfwd", "<iosfwd>"},
+    {"iostream", "<iostream>"},
+    {"istream", "<istream>"},
+    {"iterator", "<iterator>"},
+    {"limits", "<limits>"},
+    {"list", "<list>"},
+    {"locale", "<locale>"},
+    {"map", "<map>"},
+    {"memory", "<memory>"},
+    {"mutex", "<mutex>"},
+    {"new", "<new>"},
+    {"numeric", "<numeric>"},
+    {"ostream", "<ostream>"},
+    {"queue", "<queue>"},
+    {"random", "<random>"},
+    {"ratio", "<ratio>"},
+    {"regex", "<regex>"},
+    {"scoped_allocator", "<scoped_allocator>"},
+    {"set", "<set>"},
+    {"sstream", "<sstream>"},
+    {"stack", "<stack>"},
+    {"stdexcept", "<stdexcept>"},
+    {"streambuf", "<streambuf>"},
+    {"string", "<string>"},
+    {"system_error", "<system_error>"},
+    {"tgmath.h", "<tgmath.h>"},
+    {"thread", "<thread>"},
+    {"tuple", "<tuple>"},
+    {"type_traits", "<type_traits>"},
+    {"typeindex", "<typeindex>"},
+    {"typeinfo", "<typeinfo>"},
+    {"unordered_map", "<unordered_map>"},
+    {"unordered_set", "<unordered_set>"},
+    {"utility", "<utility>"},
+    {"valarray", "<valarray>"},
+    {"vector", "<vector>"},
+    {"include/complex.h", "<complex.h>"},
+    {"include/ctype.h", "<cctype>"},
+    {"include/endian.h", "<cctype>"},
+    {"include/errno.h", "<cerrno>"},
+    {"include/features.h", "<cerrno>"},
+    {"include/fenv.h", "<fenv.h>"},
+    {"include/inttypes.h", "<cinttypes>"},
+    {"include/libintl.h", "<locale>"},
+    {"include/libio.h", "<cstdio>"},
+    {"include/limits.h", "<climits>"},
+    {"include/linux/limits.h", "<climits>"},
+    {"include/locale.h", "<clocale>"},
+    {"include/math.h", "<cmath>"},
+    {"include/pthread.h", "<memory>"},
+    {"include/sched.h", "<memory>"},
+    {"include/setjmp.h", "<csetjmp>"},
+    {"include/signal.h", "<csignal>"},
+    {"include/stdc-predef.h", "<cerrno>"},
+    {"include/stdint.h", "<cstdint>"},
+    {"include/stdio.h", "<cstdio>"},
+    {"include/stdlib.h", "<cstdlib>"},
+    {"include/string.h", "<cstring>"},
+    {"include/time.h", "<ctime>"},
+    {"include/wchar.h", "<cwchar>"},
+    {"include/wctype.h", "<cwctype>"},
+    {"bits/byteswap-16.h", "<cctype>"},
+    {"bits/byteswap.h", "<cctype>"},
+    {"bits/cmathcalls.h", "<complex.h>"},
+    {"bits/endian.h", "<cctype>"},
+    {"bits/errno.h", "<cerrno>"},
+    {"bits/fenv.h", "<fenv.h>"},
+    {"bits/huge_val.h", "<cmath>"},
+    {"bits/huge_valf.h", "<cmath>"},
+    {"bits/huge_vall.h", "<cmath>"},
+    {"bits/inf.h", "<cmath>"},
+    {"bits/local_lim.h", "<climits>"},
+    {"bits/locale.h", "<clocale>"},
+    {"bits/mathcalls.h", "<math.h>"},
+    {"bits/mathdef.h", "<cmath>"},
+    {"bits/nan.h", "<cmath>"},
+    {"bits/posix1_lim.h", "<climits>"},
+    {"bits/posix2_lim.h", "<climits>"},
+    {"bits/pthreadtypes.h", "<csignal>"},
+    {"bits/sched.h", "<memory>"},
+    {"bits/select.h", "<cstdlib>"},
+    {"bits/setjmp.h", "<csetjmp>"},
+    {"bits/sigaction.h", "<csignal>"},
+    {"bits/sigcontext.h", "<csignal>"},
+    {"bits/siginfo.h", "<csignal>"},
+    {"bits/signum.h", "<csignal>"},
+    {"bits/sigset.h", "<csignal>"},
+    {"bits/sigstack.h", "<csignal>"},
+    {"bits/sigthread.h", "<csignal>"},
+    {"bits/stdio_lim.h", "<cstdio>"},
+    {"bits/sys_errlist.h", "<cstdio>"},
+    {"bits/time.h", "<ctime>"},
+    {"bits/timex.h", "<ctime>"},
+    {"bits/types.h", "<cstdio>"},
+    {"bits/typesizes.h", "<cstdio>"},
+    {"bits/waitflags.h", "<cstdlib>"},
+    {"bits/waitstatus.h", "<cstdlib>"},
+    {"bits/wchar.h", "<cwchar>"},
+    {"bits/wordsize.h", "<csetjmp>"},
+    {"bits/xopen_lim.h", "<climits>"},
+    {"gnu/stubs-64.h", "<cerrno>"},
+    {"sys/cdefs.h", "<cerrno>"},
+    {"sys/select.h", "<cstdlib>"},
+    {"sys/sysmacros.h", "<cstdlib>"},
+    {"sys/types.h", "<cstdlib>"},
+    {"sys/ucontext.h", "<csignal>"},
+    {"/usr/include/xlocale.h", "<cstring>"},
+    {"bits/atomic_word.h", "<memory>"},
+    {"bits/basic_file.h", "<fstream>"},
+    {"bits/c++allocator.h", "<string>"},
+    {"bits/c++config.h", "<iosfwd>"},
+    {"bits/c++io.h", "<fstream>"},
+    {"bits/c++locale.h", "<string>"},
+    {"bits/cpu_defines.h", "<iosfwd>"},
+    {"bits/ctype_base.h", "<locale>"},
+    {"bits/cxxabi_tweaks.h", "<cxxabi.h>"},
+    {"bits/error_constants.h", "<system_error>"},
+    {"bits/gthr-default.h", "<memory>"},
+    {"bits/gthr.h", "<memory>"},
+    {"bits/opt_random.h", "<random>"},
+    {"bits/os_defines.h", "<iosfwd>"},
+};
+
+} // namespace find_all_symbols
+} // namespace clang
+

Added: clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/STLPostfixHeaderMap.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/STLPostfixHeaderMap.h?rev=270566&view=auto
==============================================================================
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/STLPostfixHeaderMap.h (added)
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/STLPostfixHeaderMap.h Tue May 24 10:10:58 2016
@@ -0,0 +1,23 @@
+//===-- STLPostfixHeaderMap.h - hardcoded header map for STL ----*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_TOOL_STL_POSTFIX_HEADER_MAP_H
+#define LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_TOOL_STL_POSTFIX_HEADER_MAP_H
+
+#include <HeaderMapCollector.h>
+
+namespace clang {
+namespace find_all_symbols {
+
+extern const HeaderMapCollector::HeaderMap STLPostfixHeaderMap;
+
+} // namespace find_all_symbols
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_TOOL_STL_POSTFIX_HEADER_MAP_H

Modified: clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp?rev=270566&r1=270565&r2=270566&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp Tue May 24 10:10:58 2016
@@ -7,10 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "FindAllMacros.h"
-#include "FindAllSymbols.h"
+#include "FindAllSymbolsAction.h"
 #include "HeaderMapCollector.h"
-#include "PragmaCommentHandler.h"
 #include "SymbolInfo.h"
 #include "SymbolReporter.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -54,44 +52,6 @@ private:
   std::vector<SymbolInfo> Symbols;
 };
 
-class TestFindAllSymbolsAction : public clang::ASTFrontendAction {
-public:
-  TestFindAllSymbolsAction(SymbolReporter *Reporter)
-      : Reporter(Reporter), MatchFinder(), Collector(), Handler(&Collector),
-        Matcher(Reporter, &Collector) {
-    Matcher.registerMatchers(&MatchFinder);
-  }
-
-  std::unique_ptr<clang::ASTConsumer>
-  CreateASTConsumer(clang::CompilerInstance &Compiler,
-                    StringRef InFile) override {
-    Compiler.getPreprocessor().addCommentHandler(&Handler);
-    Compiler.getPreprocessor().addPPCallbacks(llvm::make_unique<FindAllMacros>(
-        Reporter, &Compiler.getSourceManager(), &Collector));
-    return MatchFinder.newASTConsumer();
-  }
-
-private:
-  SymbolReporter *const Reporter;
-  ast_matchers::MatchFinder MatchFinder;
-  HeaderMapCollector Collector;
-  PragmaCommentHandler Handler;
-  FindAllSymbols Matcher;
-};
-
-class TestFindAllSymbolsActionFactory
-    : public clang::tooling::FrontendActionFactory {
-public:
-  TestFindAllSymbolsActionFactory(TestSymbolReporter *Reporter)
-      : Reporter(Reporter) {}
-  clang::FrontendAction *create() override {
-    return new TestFindAllSymbolsAction(Reporter);
-  }
-
-private:
-  TestSymbolReporter *const Reporter;
-};
-
 class FindAllSymbolsTest : public ::testing::Test {
 public:
   bool hasSymbol(const SymbolInfo &Symbol) {
@@ -106,8 +66,20 @@ public:
 
     std::string FileName = "symbol.cc";
 
+    const std::string InternalHeader = "internal/internal.h";
+    const std::string TopHeader = "<top>";
+    HeaderMapCollector::HeaderMap PostfixMap = {
+        {"internal.h", TopHeader},
+    };
+
+    std::string InternalCode = "class Internal {};";
+    SymbolInfo InternalSymbol("Internal", SymbolInfo::SymbolKind::Class,
+                              TopHeader, 1, {});
+    InMemoryFileSystem->addFile(InternalHeader, 0,
+                                llvm::MemoryBuffer::getMemBuffer(InternalCode));
+
     std::unique_ptr<clang::tooling::FrontendActionFactory> Factory(
-        new TestFindAllSymbolsActionFactory(&Reporter));
+        new FindAllSymbolsActionFactory(&Reporter, &PostfixMap));
 
     tooling::ToolInvocation Invocation(
         {std::string("find_all_symbols"), std::string("-fsyntax-only"),
@@ -118,10 +90,13 @@ public:
     InMemoryFileSystem->addFile(HeaderName, 0,
                                 llvm::MemoryBuffer::getMemBuffer(Code));
 
-    std::string Content = "#include\"" + std::string(HeaderName) + "\"";
+    std::string Content = "#include\"" + std::string(HeaderName) +
+                          "\"\n"
+                          "#include \"internal/internal.h\"";
     InMemoryFileSystem->addFile(FileName, 0,
                                 llvm::MemoryBuffer::getMemBuffer(Content));
     Invocation.run();
+    EXPECT_TRUE(hasSymbol(InternalSymbol));
     return true;
   }
 




More information about the cfe-commits mailing list