Use expansion locations for target symbol decls when finding headers for macros.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
The implementation looks good. Some comments around the test.
clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp | ||
---|---|---|
162 | these 3 newly-added tests are similar, instead of duplicating them, we can use a table-gen style test, see an example | |
168 | nit: use guard(R"cpp(...)cpp) for the normal header code. | |
187 | The intention of the test is to test the function findHeaders, we're testing it in an implicit way (findHeaders is hidden inside the walkUsed), there is no code here explicitly calling this function. We can make it clearer (no need to use walkUsed):
for 1, we can just write a simple RecursiveASTVisitor, and capture a NamedDecl which called Foo, something like: struct Visitor : RecursiveASTVisitor<Visitor> { const NamedDecl *Out = nullptr; bool VisitNamedDecl(const NamedDecl *ND) { if (ND->getName() == "Foo") { EXPECT_TRUE(Out == nullptr); Out = ND; } return true; } }; |
thanks, the test looks better now, a few more suggestions.
clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp | ||
---|---|---|
162 | Move the definition to the TEST_F body. | |
174 | I think if (ND->getName() == "FLAG_foo" || ND->getName() == "Foo") should just work (without the VisitCXXRecordDecl method)? | |
190 | I think the Foo foo; is not really needed for the test (#include "declare.h" is the key part of the main file) as we only want the location of the CXXRecordDecl. The same for the following testcases. So I think we can simplify it further: TestCases has two members (DeclareHeader, MacroHeader). The main file content is always #include "declare.h", we can construct the main code in the for-loop body. | |
227 | nit: Annotations is not needed as we don't use any annotation here. | |
233 | Visitor.TraverseDecl(AST->context().getTranslationUnitDecl()); | |
241 | this is not needed -- the following EXPECT_THAT already covers it. |
Thanks!
clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp | ||
---|---|---|
176 | nit: it feels more natural to declare MacroHeader first then DeclareHeader, as the DeclareHeader already includes the macro.h | |
177 | The clang-format's indentation seems odd to me, I think if you put a trailing , on the last element }, };, its format is better. | |
178 | nit: I'd add /*DeclareHeader=*/, /*MacroHeader=*/, which improves the code readability. | |
212 | nit: /*PragmaIncludes=*/nullptr |
these 3 newly-added tests are similar, instead of duplicating them, we can use a table-gen style test, see an example