Implement support for begin_keep/end_keep pragmas.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
| clang-tools-extra/include-cleaner/lib/Record.cpp | ||
|---|---|---|
| 219 | nit: remove the brace for the if, the same below. | |
| clang-tools-extra/include-cleaner/unittests/RecordTest.cpp | ||
| 354 | with more tests being added, these line-number-inlined tests now are hard to follow, even with the line comment in the example. I think we can polish these tests by using the annotation point ^, something like. llvm::Annotation Code = R"cpp(
$keep1^#include "keep1.h" // IWYU pragma: keep
$normal^%include "normal.h"
)cpp";
EXPECT_TRUE(PI.shouldKeep(offsetToLine(Code.point("keep1"))));
EXPECT_FALSE(PI.shouldKeep(offsetToLine(Code.point("normal"))));We need to implement an offsetToLine function, it should be trivial to add (basically calculate the number of \ns to the offset point). | |
| clang-tools-extra/include-cleaner/unittests/RecordTest.cpp | ||
|---|---|---|
| 354 | Ok, thanks. Have a look now please. | |
| clang-tools-extra/include-cleaner/unittests/RecordTest.cpp | ||
|---|---|---|
| 312 | this is only used in IWYUKeep test, I'd make it as a local lambda (with MainFile captured) in the test: auto OffsetToLineNum = [&MainFile](size_t Offset) { ... }; | |
| 349 | I think we can also do similar thing on $begin_keep_pragma^// IWYU pragma... | |
| 351 | keep4.h can be removed to simplify the testcode. | |
| 358 | keep7.h can be removed. | |
| 365 | no need to repeatly test the begin_keep and end_keep pragmas. | |
Address review comments.
| clang-tools-extra/include-cleaner/unittests/RecordTest.cpp | ||
|---|---|---|
| 312 | Nice idea, thanks. | |
thanks, looks good.
| clang-tools-extra/include-cleaner/unittests/RecordTest.cpp | ||
|---|---|---|
| 312 | this method can be removed. | |
| clang-tools-extra/include-cleaner/unittests/RecordTest.cpp | ||
|---|---|---|
| 312 | Oops, sorry. | |
nit: remove the brace for the if, the same below.