Author: ioeric Date: Tue May 31 12:37:38 2016 New Revision: 271302 URL: http://llvm.org/viewvc/llvm-project?rev=271302&view=rev Log: [find-all-symbols] remove dots in SymbolInfo file paths.
Summary: remove dots in SymbolInfo file paths. Reviewers: bkramer, klimek Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D20819 Modified: 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 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=271302&r1=271301&r2=271302&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 31 12:37:38 2016 @@ -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 @@ void FindAllMacros::MacroDefined(const T // 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(), 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=271302&r1=271301&r2=271302&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 31 12:37:38 2016 @@ -99,7 +99,10 @@ CreateSymbolInfo(const NamedDecl *ND, co // 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)); } 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=271302&r1=271301&r2=271302&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 31 12:37:38 2016 @@ -90,13 +90,28 @@ public: 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; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits