[PATCH] D120956: [clang][AST matchers] new AST matcher argumentsGivenCountIs(n) that checks the actual number of arguments given in a function call

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 16 06:25:24 PDT 2022


aaron.ballman added a comment.

In D120956#3384416 <https://reviews.llvm.org/D120956#3384416>, @ajohnson-uoregon wrote:

> When we're doing matcher generation, we aren't able to look up the FunctionDecl and see if there are defaults (because the function name itself might be a parameter for us), and even if we could, adding `cxxDefaultArgExpr()` for all of the missing ones is a lot of work that we'd rather not do.

Thanks, this is pretty compelling rationale for why this is a generally useful matcher.

Be sure to also add test coverage for the matcher, as well as regenerate the documentation from `docs/tools/dump_ast_matchers.py`.



================
Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:4452
+/// \endcode
+AST_POLYMORPHIC_MATCHER_P(argumentsGivenCountIs,
+                          AST_POLYMORPHIC_SUPPORTED_TYPES(
----------------
ajohnson-uoregon wrote:
> aaron.ballman wrote:
> > I have a preference for `argumentCountAsWrittenIs()` -- we often use "as written" to distinguish syntax from semantics, and in the case of default arguments, the semantics are that the default arguments are treated as if they were given at the call site, so I would expect `argumentsGivenCountIs(2)` to match both calls to `f()`.
> Ah that's a good point, and I like that name much better, I will update that.
I'm not 100% sold on the new name being `argumentsGivenCountIs` -- I get where it's coming from, but it feels less grammatical than `argumentCountAsWrittenIs()`. Also, we have an `AsWritten` matcher already (`isVirtualAsWritten()`), but none with `Given`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120956/new/

https://reviews.llvm.org/D120956



More information about the cfe-commits mailing list