This revision was automatically updated to reflect the committed changes. Closed by commit rG9961fa1653a2: [include-cleaner] Record whether includes are spelled with <angle> quotes (authored by sammccall).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D139018/new/ https://reviews.llvm.org/D139018 Files: clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h clang-tools-extra/include-cleaner/lib/HTMLReport.cpp clang-tools-extra/include-cleaner/lib/Record.cpp clang-tools-extra/include-cleaner/lib/Types.cpp clang-tools-extra/include-cleaner/unittests/RecordTest.cpp Index: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp =================================================================== --- clang-tools-extra/include-cleaner/unittests/RecordTest.cpp +++ clang-tools-extra/include-cleaner/unittests/RecordTest.cpp @@ -134,7 +134,7 @@ TEST_F(RecordPPTest, CapturesIncludes) { llvm::Annotations MainFile(R"cpp( $H^#include "./header.h" - $M^#include "missing.h" + $M^#include <missing.h> )cpp"); Inputs.Code = MainFile.code(); Inputs.ExtraFiles["header.h"] = ""; @@ -151,6 +151,7 @@ AST.sourceManager().getComposedLoc( AST.sourceManager().getMainFileID(), MainFile.point("H"))); EXPECT_EQ(H.Resolved, AST.fileManager().getFile("header.h").get()); + EXPECT_FALSE(H.Angled); auto &M = Recorded.Includes.all().back(); EXPECT_EQ(M.Line, 3u); @@ -158,6 +159,7 @@ AST.sourceManager().getComposedLoc( AST.sourceManager().getMainFileID(), MainFile.point("M"))); EXPECT_EQ(M.Resolved, nullptr); + EXPECT_TRUE(M.Angled); } TEST_F(RecordPPTest, CapturesMacroRefs) { Index: clang-tools-extra/include-cleaner/lib/Types.cpp =================================================================== --- clang-tools-extra/include-cleaner/lib/Types.cpp +++ clang-tools-extra/include-cleaner/lib/Types.cpp @@ -39,7 +39,7 @@ } llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Include &I) { - return OS << I.Line << ": " << I.Spelled << " => " + return OS << I.Line << ": " << I.quote() << " => " << (I.Resolved ? I.Resolved->getName() : "<missing>"); } @@ -64,4 +64,9 @@ llvm_unreachable("Unexpected RefType"); } +std::string Include::quote() const { + return (llvm::StringRef(Angled ? "<" : "\"") + Spelled + + (Angled ? ">" : "\"")) + .str(); +} } // namespace clang::include_cleaner Index: clang-tools-extra/include-cleaner/lib/Record.cpp =================================================================== --- clang-tools-extra/include-cleaner/lib/Record.cpp +++ clang-tools-extra/include-cleaner/lib/Record.cpp @@ -46,6 +46,7 @@ I.Resolved = File ? &File->getFileEntry() : nullptr; I.Line = SM.getSpellingLineNumber(Hash); I.Spelled = SpelledFilename; + I.Angled = IsAngled; Recorded.Includes.add(I); } Index: clang-tools-extra/include-cleaner/lib/HTMLReport.cpp =================================================================== --- clang-tools-extra/include-cleaner/lib/HTMLReport.cpp +++ clang-tools-extra/include-cleaner/lib/HTMLReport.cpp @@ -416,7 +416,7 @@ for (const auto *I : R.Includes) { OS << "<tr><th>Included</th><td>"; - escapeString(I->Spelled); + escapeString(I->quote()); OS << ", <a href='#line" << I->Line << "'>line " << I->Line << "</a>"; OS << "</td></tr>"; } Index: clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h =================================================================== --- clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h +++ clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h @@ -133,6 +133,8 @@ // nullptr if the header was not found SourceLocation HashLocation; // of hash in #include <vector> unsigned Line = 0; // 1-based line number for #include + bool Angled = false; // True if spelled with <angle> quotes. + std::string quote() const; // e.g. <vector> }; llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Include &);
Index: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp =================================================================== --- clang-tools-extra/include-cleaner/unittests/RecordTest.cpp +++ clang-tools-extra/include-cleaner/unittests/RecordTest.cpp @@ -134,7 +134,7 @@ TEST_F(RecordPPTest, CapturesIncludes) { llvm::Annotations MainFile(R"cpp( $H^#include "./header.h" - $M^#include "missing.h" + $M^#include <missing.h> )cpp"); Inputs.Code = MainFile.code(); Inputs.ExtraFiles["header.h"] = ""; @@ -151,6 +151,7 @@ AST.sourceManager().getComposedLoc( AST.sourceManager().getMainFileID(), MainFile.point("H"))); EXPECT_EQ(H.Resolved, AST.fileManager().getFile("header.h").get()); + EXPECT_FALSE(H.Angled); auto &M = Recorded.Includes.all().back(); EXPECT_EQ(M.Line, 3u); @@ -158,6 +159,7 @@ AST.sourceManager().getComposedLoc( AST.sourceManager().getMainFileID(), MainFile.point("M"))); EXPECT_EQ(M.Resolved, nullptr); + EXPECT_TRUE(M.Angled); } TEST_F(RecordPPTest, CapturesMacroRefs) { Index: clang-tools-extra/include-cleaner/lib/Types.cpp =================================================================== --- clang-tools-extra/include-cleaner/lib/Types.cpp +++ clang-tools-extra/include-cleaner/lib/Types.cpp @@ -39,7 +39,7 @@ } llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Include &I) { - return OS << I.Line << ": " << I.Spelled << " => " + return OS << I.Line << ": " << I.quote() << " => " << (I.Resolved ? I.Resolved->getName() : "<missing>"); } @@ -64,4 +64,9 @@ llvm_unreachable("Unexpected RefType"); } +std::string Include::quote() const { + return (llvm::StringRef(Angled ? "<" : "\"") + Spelled + + (Angled ? ">" : "\"")) + .str(); +} } // namespace clang::include_cleaner Index: clang-tools-extra/include-cleaner/lib/Record.cpp =================================================================== --- clang-tools-extra/include-cleaner/lib/Record.cpp +++ clang-tools-extra/include-cleaner/lib/Record.cpp @@ -46,6 +46,7 @@ I.Resolved = File ? &File->getFileEntry() : nullptr; I.Line = SM.getSpellingLineNumber(Hash); I.Spelled = SpelledFilename; + I.Angled = IsAngled; Recorded.Includes.add(I); } Index: clang-tools-extra/include-cleaner/lib/HTMLReport.cpp =================================================================== --- clang-tools-extra/include-cleaner/lib/HTMLReport.cpp +++ clang-tools-extra/include-cleaner/lib/HTMLReport.cpp @@ -416,7 +416,7 @@ for (const auto *I : R.Includes) { OS << "<tr><th>Included</th><td>"; - escapeString(I->Spelled); + escapeString(I->quote()); OS << ", <a href='#line" << I->Line << "'>line " << I->Line << "</a>"; OS << "</td></tr>"; } Index: clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h =================================================================== --- clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h +++ clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h @@ -133,6 +133,8 @@ // nullptr if the header was not found SourceLocation HashLocation; // of hash in #include <vector> unsigned Line = 0; // 1-based line number for #include + bool Angled = false; // True if spelled with <angle> quotes. + std::string quote() const; // e.g. <vector> }; llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Include &);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits