[PATCH] D20819: [find-all-symbols] remove dots in SymbolInfo file paths.

Eric Liu via cfe-commits cfe-commits at lists.llvm.org
Tue May 31 10:44:06 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL271302: [find-all-symbols] remove dots in SymbolInfo file paths. (authored by ioeric).

Changed prior to commit:
  http://reviews.llvm.org/D20819?vs=59075&id=59091#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20819

Files:
  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/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp

Index: clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
===================================================================
--- clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
+++ clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
@@ -90,13 +90,28 @@
     InMemoryFileSystem->addFile(HeaderName, 0,
                                 llvm::MemoryBuffer::getMemBuffer(Code));
 
+    // Test path cleaning for both decls and macros.
+    const std::string DirtyHeader = "./internal/../internal/./a/b.h";
+    const std::string CleanHeader = "internal/a/b.h";
+    const std::string DirtyHeaderContent =
+        "#define INTERNAL 1\nclass ExtraInternal {};";
+    InMemoryFileSystem->addFile(
+        DirtyHeader, 0, llvm::MemoryBuffer::getMemBuffer(DirtyHeaderContent));
+    SymbolInfo DirtyMacro("INTERNAL", SymbolInfo::SymbolKind::Macro,
+                          CleanHeader, 1, {});
+    SymbolInfo DirtySymbol("ExtraInternal", SymbolInfo::SymbolKind::Class,
+                           CleanHeader, 2, {});
+
     std::string Content = "#include\"" + std::string(HeaderName) +
                           "\"\n"
-                          "#include \"internal/internal.h\"";
+                          "#include \"internal/internal.h\"\n"
+                          "#include \"" + DirtyHeader + "\"";
     InMemoryFileSystem->addFile(FileName, 0,
                                 llvm::MemoryBuffer::getMemBuffer(Content));
     Invocation.run();
     EXPECT_TRUE(hasSymbol(InternalSymbol));
+    EXPECT_TRUE(hasSymbol(DirtySymbol));
+    EXPECT_TRUE(hasSymbol(DirtyMacro));
     return true;
   }
 
Index: clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp
===================================================================
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp
@@ -99,7 +99,10 @@
   // If Collector is not nullptr, check pragma remapping header.
   FilePath = Collector ? Collector->getMappedHeader(FilePath) : FilePath;
 
-  return SymbolInfo(ND->getNameAsString(), Type, FilePath.str(),
+  SmallString<256> CleanedFilePath = FilePath;
+  llvm::sys::path::remove_dots(CleanedFilePath, /*remove_dot_dot=*/true);
+
+  return SymbolInfo(ND->getNameAsString(), Type, CleanedFilePath,
                     SM.getExpansionLineNumber(Loc), GetContexts(ND));
 }
 
Index: clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllMacros.cpp
===================================================================
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllMacros.cpp
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllMacros.cpp
@@ -13,6 +13,7 @@
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Token.h"
+#include "llvm/Support/Path.h"
 
 namespace clang {
 namespace find_all_symbols {
@@ -30,8 +31,11 @@
   // If Collector is not nullptr, check pragma remapping header.
   FilePath = Collector ? Collector->getMappedHeader(FilePath) : FilePath;
 
+  SmallString<256> CleanedFilePath = FilePath;
+  llvm::sys::path::remove_dots(CleanedFilePath, /*remove_dot_dot=*/true);
+
   SymbolInfo Symbol(MacroNameTok.getIdentifierInfo()->getName(),
-                    SymbolInfo::SymbolKind::Macro, FilePath.str(),
+                    SymbolInfo::SymbolKind::Macro, CleanedFilePath,
                     SM->getSpellingLineNumber(Loc), {});
 
   Reporter->reportSymbol(SM->getFileEntryForID(SM->getMainFileID())->getName(),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20819.59091.patch
Type: text/x-patch
Size: 3671 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160531/694a8f4a/attachment-0001.bin>


More information about the cfe-commits mailing list