For an Obj-C message expression [o m], the adding matcher will match the declaration of the method m. This matcher is the Obj-C counterpart of the existing callee ASTMatcher which matches function/method declarations for C/C++ calls. So I think this matcher is general enough to be added to the ASTMatcher.h.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang/include/clang/ASTMatchers/ASTMatchers.h | ||
---|---|---|
3841 | Nitpick carryover: needs capital letter and . |
clang/include/clang/ASTMatchers/ASTMatchers.h | ||
---|---|---|
3853 | This is a good question! callee has already been overloaded to accept both Matcher<Decl> and Matcher<Stmt> as the parameter. In my case, I will need callee to be polymorphic in returning both Matcher<CallExpr> and Matcher<ObjCMessageExpr> types. So that will end up in 4 definitions of callee, one of which has different return type and parameter type from one of the others. Is this achievable? I know I can overload parameters or make return types polymorphic, but can I mix them together? |
clang/include/clang/ASTMatchers/ASTMatchers.h | ||
---|---|---|
3853 | I figured it out. I will soon update this patch to simply overload callee |
Taking @aaron.ballman 's advice to overload callee instead of creating a new matcher. Avoid to bloat ASTMatchers.h.
Sorry to the reviewers that have to review this patch again.
Thank you, this is looking really promising!
Can you also add a test to unittests/ASTMatchers/Dynamic/RegistryTest.cpp to the TEST_F(RegistryTest, OverloadedMatchers) test which tests the behavior of callee() to make sure it works from dynamic matchers? If that test fails, I think you may need to update lib/ASTMatchers/Dynamic/Registry.cpp to add a REGISTER_OVERLOADED_3 that is used by both callee and equals.
clang/include/clang/ASTMatchers/ASTMatchers.h | ||
---|---|---|
3871 | This way you get an assert if someone adds another type and forgets to update the rest of the body. |
Added a test to unittests/ASTMatchers/Dynamic/RegistryTest.cpp and confirms that the overloaded callee still works with dynamic matchers
Nitpick carryover: needs capital letter and .