Salvaging some of the work we've already done in now deprecated patch https://reviews.llvm.org/D78165
Details
Diff Detail
Event Timeline
Can you run clang-format over this patch please.
Personally I'm also in favour of removing the Base from the access modifiers i.e. isPublicBase to isPublic.
As you are adding matchers you need to do a few small other jobs:
- Add these matchers to clang/lib/ASTMatchers/Dynamic/Registry.cpp. Make sure you keep it in alphabetical order.
- Regenerate the docs by running clang/docs/tools/dump_ast_matchers.py.
clang/include/clang/ASTMatchers/ASTMatchers.h | ||
---|---|---|
2895 | s/public/private | |
2903 | NIT: remove the empty comment line, same goes below. | |
clang/lib/ASTMatchers/ASTMatchFinder.cpp | ||
947 | Why are you casting away const, setOrigin takes a const CXXRecordDecl *? Think of the kittens life :) |
clang/lib/ASTMatchers/ASTMatchFinder.cpp | ||
---|---|---|
947 | Haha :D |
- Changed matchers to polymorphic instead of using Base suffix.
- Registered one new matcher (the rest has been already existing and is now just polymorphic).
- Regenerated the docs.
- Some doc comments tweaking.
- Saved a kitten!
A few more nits, you'll need to re-run the python script after addressing them.
clang/include/clang/ASTMatchers/ASTMatchers.h | ||
---|---|---|
561 | I'm struggling to see the value of this matcher. I don't think its possible to use it as a match query e.g. | |
2878–2887 | Gonna hazard a guess you forgot to remove this. | |
3517 | Could you update the comment to say Usable as ... Matcher<CXXBaseSpecifier> and maybe a use case in the example. | |
5191–5202 | Again add a use case in the example. |
clang/lib/ASTMatchers/ASTMatchersInternal.cpp | ||
---|---|---|
670 ↗ | (On Diff #264752) | As you have removed the decl in ASTMatchers.h this no longer needs to be here |
clang/lib/ASTMatchers/ASTMatchersInternal.cpp | ||
---|---|---|
670 ↗ | (On Diff #264752) | True! |
You really don't need to modify the MatchASTVisitor for this.
I just put this in ASTMatchersInternal.cpp with a decl in ASTMatchersInternal.h
bool matchesAnyBase(const CXXRecordDecl &Node, const Matcher<CXXBaseSpecifier> &BaseSpecMatcher, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder) { if (!Node.hasDefinition()) return false; CXXBasePaths Paths; Paths.setOrigin(&Node); const auto basePredicate = [Finder, Builder, &BaseSpecMatcher](const CXXBaseSpecifier *BaseSpec, CXXBasePath &IgnoredParam) { BoundNodesTreeBuilder Result(*Builder); if (BaseSpecMatcher.matches(*BaseSpec, Finder, Builder)) { *Builder = std::move(Result); return true; } return false; }; return Node.lookupInBases(basePredicate, Paths, /*LookupInDependent =*/true); }
Then your matcher code goes to
AST_MATCHER_P(CXXRecordDecl, hasAnyBase, internal::Matcher<CXXBaseSpecifier>, BaseSpecMatcher) { return internal::matchesAnyBase(Node, BaseSpecMatcher, Finder, Builder); }
Theres also a file clang-tidy/misc/NonPrivateMemberVariablesInClassesCheck.cpp that has a compile error due to the changes in isProtected and isPrivate that needs fixing.
LGTM but I'm not the gatekeeper, see what Manuel says first.
clang/lib/ASTMatchers/ASTMatchFinder.cpp | ||
---|---|---|
21 | Nit, this can be removed, its the only change to this file |
I'm adding couple other potential reviewers. @njames93 if you feel comfortable doing that I think you can approve yourself too.
LGTM aside from a nit.
clang/include/clang/ASTMatchers/ASTMatchers.h | ||
---|---|---|
2863 | The example doesn't include hasAnyBase? |
I'm struggling to see the value of this matcher. I don't think its possible to use it as a match query e.g.
match cxxBaseSpecifier() The only possible use case I can think of is maybe to try to bind to it, though I'm not even sure that would work.