Save file IDs of IWYU private headers and report them as private.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
| clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h | ||
|---|---|---|
| 76 | I think this function should return true if the given file is marked with the IWYU private mapping pragma, because conceptually these file are also private. | |
| 95 | It should collect files with mapping IWYU private pragmas. and I think the last sentence can be removed (the intention of using UniqueID is clear from other comments). | |
| clang-tools-extra/include-cleaner/lib/Record.cpp | ||
| 270 | I'd suggest moving this to the above line 236 where we handle the private mapping. | |
| clang-tools-extra/include-cleaner/unittests/RecordTest.cpp | ||
| 350 | no extra ; token needed for the #include. | |
| 371 | add EXPECT_TRUE(PI.isPrivate(PrivateFE.get())). | |
| clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h | ||
|---|---|---|
| 97 | i'd actually merge this with the previous map, and store empty verbatim spellings. semantics of getPublic is to return empty path when there are no mappings anyway. | |
| clang-tools-extra/include-cleaner/unittests/RecordTest.cpp | ||
| 361 | nit: no need for the declaration of Private here (nor in private.h). it's actually introducing a double definition error into TU now. | |
The formatting has introduced a bit of unrelated diff. It's not much, so I hope that's fine.
| clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h | ||
|---|---|---|
| 95 | I've followed Kadir's suggestion below now and merged the private pragmas with the IWYUPublic map. | |
| 97 | Sounds reasonable. I wasn't sure which of the options to pick in the first place. | |
| clang-tools-extra/include-cleaner/unittests/RecordTest.cpp | ||
| 361 | Out of curiosity: what's TU? | |
| clang-tools-extra/include-cleaner/lib/Record.cpp | ||
|---|---|---|
| 237 | nit: you can drop the braces here. LLVM convention is to not have braces when a condition/loop body has only a single statement. | |
| 240 | nit: you can also rewrite this as: StringRef PublicHeader;
if (Pragma->consume_front(", include ")) {
PublicHeader = save(Pragma->startswith("<") || Pragma->startswith("\"")
? (*Pragma)
: ("\"" + *Pragma + "\"").str());
}
Out->IWYUPublic.insert({FE->getLastRef().getUniqueID(), PublicHeader}); | |
| clang-tools-extra/include-cleaner/unittests/RecordTest.cpp | ||
| 361 | it means translation unit, it's the source file provided to the compiler after all preprocessor directives are processed. | |
Thanks, looks good from my side, a few nits on the test.
| clang-tools-extra/include-cleaner/unittests/RecordTest.cpp | ||
|---|---|---|
| 363–364 | nit: IIUC, we're using a blank line to separate the tests per FileEntry, this EXPECT_EQ statement should belong to the above group (which is PrivateFE), right? | |
| 367–372 | nit: add EXPECT_FALSE(PI.isPrivate(PublicFE.get())); | |
I think this function should return true if the given file is marked with the IWYU private mapping pragma, because conceptually these file are also private.