aboutsummaryrefslogtreecommitdiff
path: root/clang/docs/LibASTMatchersReference.html
AgeCommit message (Collapse)AuthorFilesLines
2025-03-12[AstMatcher]`templateArgumentCountIs` support `FunctionDecl` (#130416)Congcong Cai1-2/+48
`hasTemplateArgument` and `templateArgumentCountIs` are always used together. It is more convenient to make then support `FunctionDecl`.
2025-03-11[AstMatcher][NFC]fix doc gen for ast matchers (#130726)Congcong Cai1-59/+134
1. dump-ast-matchers.py does not depend on pwd 2. fix some warning in python3
2025-01-09[Clang][ASTMatcher] Extend `hasDependentName` to match DependentNameType ↵Amr Hesham1-0/+15
name (#121975) Extend `hasDependentName` to be a polymorphic matcher that matches the name of either `DependentNameType` or `DependentScopeDeclRefExpr`
2025-01-05[Clang][ASTMatcher] Add a matcher for the name of a ↵Amr Hesham1-0/+13
DependentScopeDeclRefExpr (#121656) Add the `hasDependentName` matcher to match the name of `DependentScopeDeclRefExpr` Fixes https://github.com/llvm/llvm-project/issues/121610
2025-01-03[Clang][ASTMatcher] Add `dependentTemplateSpecializationType` matcher (#121435)kefan cao1-0/+11
Fixes https://github.com/llvm/llvm-project/issues/121307
2024-12-29[Clang][ASTMatcher] Add `dependentNameType` AST matcher (#121263)Amr Hesham1-0/+9
Fixes: https://github.com/llvm/llvm-project/issues/121240
2024-12-27[Clang][ASTMatcher] Add `dependentScopeDeclRefExpr` matcher (#120996)Amr Hesham1-0/+6
Fixes https://github.com/llvm/llvm-project/issues/120937
2024-12-02[clang-tidy][use-internal-linkage]fix false positives for ExportDecl (#117901)Congcong Cai1-0/+11
Fixed: #97190
2024-11-16Revert "Reland: [clang][test] add testing for the AST matcher reference" ↵Julian Schmidt1-5670/+2263
(#116477) Reverts llvm/llvm-project#112168
2024-11-15Reland: [clang][test] add testing for the AST matcher reference (#112168)Julian Schmidt1-2263/+5670
## Problem Statement Previously, the examples in the AST matcher reference, which gets generated by the Doxygen comments in `ASTMatchers.h`, were untested and best effort. Some of the matchers had no or wrong examples of how to use the matcher. ## Solution This patch introduces a simple DSL around Doxygen commands to enable testing the AST matcher documentation in a way that should be relatively easy to use. In `ASTMatchers.h`, most matchers are documented with a Doxygen comment. Most of these also have a code example that aims to show what the matcher will match, given a matcher somewhere in the documentation text. The way that the documentation is tested, is by using Doxygen's alias feature to declare custom aliases. These aliases forward to `<tt>text</tt>` (which is what Doxygen's `\c` does, but for multiple words). Using the Doxygen aliases is the obvious choice, because there are (now) four consumers: - people reading the header/using signature help - the Doxygen generated documentation - the generated HTML AST matcher reference - (new) the generated matcher tests This patch rewrites/extends the documentation such that all matchers have a documented example. The new `generate_ast_matcher_doc_tests.py` script will warn on any undocumented matchers (but not on matchers without a Doxygen comment) and provides diagnostics and statistics about the matchers. The current statistics emitted by the parser are: ```text Statistics: doxygen_blocks : 519 missing_tests : 10 skipped_objc : 42 code_snippets : 503 matches : 820 matchers : 580 tested_matchers : 574 none_type_matchers : 6 ``` The tests are generated during building, and the script will only print something if it found an issue with the specified tests (e.g., missing tests). ## Description DSL for generating the tests from documentation. TLDR: ``` \header{a.h} \endheader <- zero or more header \code int a = 42; \endcode \compile_args{-std=c++,c23-or-later} <- optional, the std flag supports std ranges and whole languages \matcher{expr()} <- one or more matchers in succession \match{42} <- one or more matches in succession \matcher{varDecl()} <- new matcher resets the context, the above \match will not count for this new matcher(-group) \match{int a = 42} <- only applies to the previous matcher (not to the previous case) ``` The above block can be repeated inside a Doxygen command for multiple code examples for a single matcher. The test generation script will only look for these annotations and ignore anything else like `\c` or the sentences where these annotations are embedded into: `The matcher \matcher{expr()} matches the number \match{42}.`. ### Language Grammar [] denotes an optional, and <> denotes user-input ``` compile_args j:= \compile_args{[<compile_arg>;]<compile_arg>} matcher_tag_key ::= type match_tag_key ::= type || std || count || sub matcher_tags ::= [matcher_tag_key=<value>;]matcher_tag_key=<value> match_tags ::= [match_tag_key=<value>;]match_tag_key=<value> matcher ::= \matcher{[matcher_tags$]<matcher>} matchers ::= [matcher] matcher match ::= \match{[match_tags$]<match>} matches ::= [match] match case ::= matchers matches cases ::= [case] case header-block ::= \header{<name>} <code> \endheader code-block ::= \code <code> \endcode testcase ::= code-block [compile_args] cases ``` ### Language Standard Versions The 'std' tag and '\compile_args' support specifying a specific language version, a whole language and all of its versions, and thresholds (implies ranges). Multiple arguments are passed with a ',' separator. For a language and version to execute a tested matcher, it has to match the specified '\compile_args' for the code, and the 'std' tag for the matcher. Predicates for the 'std' compiler flag are used with disjunction between languages (e.g. 'c || c++') and conjunction for all predicates specific to each language (e.g. 'c++11-or-later && c++23-or-earlier'). Examples: - `c` all available versions of C - `c++11` only C++11 - `c++11-or-later` C++11 or later - `c++11-or-earlier` C++11 or earlier - `c++11-or-later,c++23-or-earlier,c` all of C and C++ between 11 and 23 (inclusive) - `c++11-23,c` same as above ### Tags #### `type`: **Match types** are used to select where the string that is used to check if a node matches comes from. Available: `code`, `name`, `typestr`, `typeofstr`. The default is `code`. - `code`: Forwards to `tooling::fixit::getText(...)` and should be the preferred way to show what matches. - `name`: Casts the match to a `NamedDecl` and returns the result of `getNameAsString`. Useful when the matched AST node is not easy to spell out (`code` type), e.g., namespaces or classes with many members. - `typestr`: Returns the result of `QualType::getAsString` for the type derived from `Type` (otherwise, if it is derived from `Decl`, recurses with `Node->getTypeForDecl()`) **Matcher types** are used to mark matchers as sub-matcher with 'sub' or as deactivated using 'none'. Testing sub-matcher is not implemented. #### `count`: Specifying a 'count=n' on a match will result in a test that requires that the specified match will be matched n times. Default is 1. #### `std`: A match allows specifying if it matches only in specific language versions. This may be needed when the AST differs between language versions. #### `sub`: The `sub` tag on a `\match` will indicate that the match is for a node of a bound sub-matcher. E.g., `\matcher{expr(expr().bind("inner"))}` has a sub-matcher that binds to `inner`, which is the value for the `sub` tag of the expected match for the sub-matcher `\match{sub=inner$...}`. Currently, sub-matchers are not tested in any way. ### What if ...? #### ... I want to add a matcher? Add a Doxygen comment to the matcher with a code example, corresponding matchers and matches, that shows what the matcher is supposed to do. Specify the compile arguments/supported languages if required, and run `ninja check-clang-unit` to test the documentation. #### ... the example I wrote is wrong? The test-failure output of the generated test file will provide information about - where the generated test file is located - which line in `ASTMatcher.h` the example is from - which matches were: found, not-(yet)-found, expected - in case of an unexpected match: what the node looks like using the different `type`s - the language version and if the test ran with a windows `-target` flag (also in failure summary) #### ... I don't adhere to the required order of the syntax? The script will diagnose any found issues, such as `matcher is missing an example` with a `file:line:` prefix, which should provide enough information about the issue. #### ... the script diagnoses a false-positive issue with a Doxygen comment? It hopefully shouldn't, but if you, e.g., added some non-matcher code and documented it with Doxygen, then the script will consider that as a matcher documentation. As a result, the script will print that it detected a mismatch between the actual and the expected number of failures. If the diagnostic truly is a false-positive, change the `expected_failure_statistics` at the top of the `generate_ast_matcher_doc_tests.py` file. Fixes #57607 Fixes #63748
2024-10-17Different info in docs in AST methods (#112190)Mikhnenko Sasha1-2/+2
[Here](https://github.com/llvm/llvm-project/blob/6a98c4a1602591c942f01dceb3aa29ffd4cf1e5b/clang/include/clang/ASTMatchers/ASTMatchers.h#L4188-L4203) and [here](https://github.com/llvm/llvm-project/blob/6a98c4a1602591c942f01dceb3aa29ffd4cf1e5b/clang/include/clang/ASTMatchers/ASTMatchers.h#L3679-L3695) we can see similar code samples and same examples: ``` cxxMemberCallExpr(on(callExpr())) ``` In the first case, it is [written](https://github.com/llvm/llvm-project/blob/6a98c4a1602591c942f01dceb3aa29ffd4cf1e5b/clang/include/clang/ASTMatchers/ASTMatchers.h#L4201) that the object must not be matched: ``` /// cxxMemberCallExpr(on(callExpr())) /// does not match `(g()).m()`, because the parens are not ignored. ``` In the second case, it is [written](https://github.com/llvm/llvm-project/blob/6a98c4a1602591c942f01dceb3aa29ffd4cf1e5b/clang/include/clang/ASTMatchers/ASTMatchers.h#L3693) that the object must be matched: ``` /// cxxMemberCallExpr(on(callExpr())) /// matches `(g()).m()`. ``` I think that parens are ignored
2024-09-28Revert "[clang][test] add testing for the AST matcher reference" (#110354)Julian Schmidt1-5673/+2266
Reverts llvm/llvm-project#110258 The commit caused a timeout for clang-arm64-windows-msvc: https://lab.llvm.org/buildbot/#/builders/161/builds/2385 and it looks like my commit is at fault.
2024-09-27[clang][test] add testing for the AST matcher reference (#110258)Julian Schmidt1-2266/+5673
## Problem Statement Previously, the examples in the AST matcher reference, which gets generated by the Doxygen comments in `ASTMatchers.h`, were untested and best effort. Some of the matchers had no or wrong examples of how to use the matcher. ## Solution This patch introduces a simple DSL around Doxygen commands to enable testing the AST matcher documentation in a way that should be relatively easy to use. In `ASTMatchers.h`, most matchers are documented with a Doxygen comment. Most of these also have a code example that aims to show what the matcher will match, given a matcher somewhere in the documentation text. The way that the documentation is tested, is by using Doxygen's alias feature to declare custom aliases. These aliases forward to `<tt>text</tt>` (which is what Doxygen's `\c` does, but for multiple words). Using the Doxygen aliases is the obvious choice, because there are (now) four consumers: - people reading the header/using signature help - the Doxygen generated documentation - the generated HTML AST matcher reference - (new) the generated matcher tests This patch rewrites/extends the documentation such that all matchers have a documented example. The new `generate_ast_matcher_doc_tests.py` script will warn on any undocumented matchers (but not on matchers without a Doxygen comment) and provides diagnostics and statistics about the matchers. The current statistics emitted by the parser are: ```text Statistics: doxygen_blocks : 519 missing_tests : 10 skipped_objc : 42 code_snippets : 503 matches : 820 matchers : 580 tested_matchers : 574 none_type_matchers : 6 ``` The tests are generated during building, and the script will only print something if it found an issue with the specified tests (e.g., missing tests). ## Description DSL for generating the tests from documentation. TLDR: ``` \header{a.h} \endheader <- zero or more header \code int a = 42; \endcode \compile_args{-std=c++,c23-or-later} <- optional, the std flag supports std ranges and whole languages \matcher{expr()} <- one or more matchers in succession \match{42} <- one or more matches in succession \matcher{varDecl()} <- new matcher resets the context, the above \match will not count for this new matcher(-group) \match{int a = 42} <- only applies to the previous matcher (not to the previous case) ``` The above block can be repeated inside a Doxygen command for multiple code examples for a single matcher. The test generation script will only look for these annotations and ignore anything else like `\c` or the sentences where these annotations are embedded into: `The matcher \matcher{expr()} matches the number \match{42}.`. ### Language Grammar [] denotes an optional, and <> denotes user-input ``` compile_args j:= \compile_args{[<compile_arg>;]<compile_arg>} matcher_tag_key ::= type match_tag_key ::= type || std || count || sub matcher_tags ::= [matcher_tag_key=<value>;]matcher_tag_key=<value> match_tags ::= [match_tag_key=<value>;]match_tag_key=<value> matcher ::= \matcher{[matcher_tags$]<matcher>} matchers ::= [matcher] matcher match ::= \match{[match_tags$]<match>} matches ::= [match] match case ::= matchers matches cases ::= [case] case header-block ::= \header{<name>} <code> \endheader code-block ::= \code <code> \endcode testcase ::= code-block [compile_args] cases ``` ### Language Standard Versions The 'std' tag and '\compile_args' support specifying a specific language version, a whole language and all of its versions, and thresholds (implies ranges). Multiple arguments are passed with a ',' separator. For a language and version to execute a tested matcher, it has to match the specified '\compile_args' for the code, and the 'std' tag for the matcher. Predicates for the 'std' compiler flag are used with disjunction between languages (e.g. 'c || c++') and conjunction for all predicates specific to each language (e.g. 'c++11-or-later && c++23-or-earlier'). Examples: - `c` all available versions of C - `c++11` only C++11 - `c++11-or-later` C++11 or later - `c++11-or-earlier` C++11 or earlier - `c++11-or-later,c++23-or-earlier,c` all of C and C++ between 11 and 23 (inclusive) - `c++11-23,c` same as above ### Tags #### `type`: **Match types** are used to select where the string that is used to check if a node matches comes from. Available: `code`, `name`, `typestr`, `typeofstr`. The default is `code`. - `code`: Forwards to `tooling::fixit::getText(...)` and should be the preferred way to show what matches. - `name`: Casts the match to a `NamedDecl` and returns the result of `getNameAsString`. Useful when the matched AST node is not easy to spell out (`code` type), e.g., namespaces or classes with many members. - `typestr`: Returns the result of `QualType::getAsString` for the type derived from `Type` (otherwise, if it is derived from `Decl`, recurses with `Node->getTypeForDecl()`) **Matcher types** are used to mark matchers as sub-matcher with 'sub' or as deactivated using 'none'. Testing sub-matcher is not implemented. #### `count`: Specifying a 'count=n' on a match will result in a test that requires that the specified match will be matched n times. Default is 1. #### `std`: A match allows specifying if it matches only in specific language versions. This may be needed when the AST differs between language versions. #### `sub`: The `sub` tag on a `\match` will indicate that the match is for a node of a bound sub-matcher. E.g., `\matcher{expr(expr().bind("inner"))}` has a sub-matcher that binds to `inner`, which is the value for the `sub` tag of the expected match for the sub-matcher `\match{sub=inner$...}`. Currently, sub-matchers are not tested in any way. ### What if ...? #### ... I want to add a matcher? Add a Doxygen comment to the matcher with a code example, corresponding matchers and matches, that shows what the matcher is supposed to do. Specify the compile arguments/supported languages if required, and run `ninja check-clang-unit` to test the documentation. #### ... the example I wrote is wrong? The test-failure output of the generated test file will provide information about - where the generated test file is located - which line in `ASTMatcher.h` the example is from - which matches were: found, not-(yet)-found, expected - in case of an unexpected match: what the node looks like using the different `type`s - the language version and if the test ran with a windows `-target` flag (also in failure summary) #### ... I don't adhere to the required order of the syntax? The script will diagnose any found issues, such as `matcher is missing an example` with a `file:line:` prefix, which should provide enough information about the issue. #### ... the script diagnoses a false-positive issue with a Doxygen comment? It hopefully shouldn't, but if you, e.g., added some non-matcher code and documented it with Doxygen, then the script will consider that as a matcher documentation. As a result, the script will print that it detected a mismatch between the actual and the expected number of failures. If the diagnostic truly is a false-positive, change the `expected_failure_statistics` at the top of the `generate_ast_matcher_doc_tests.py` file. Fixes #57607 Fixes #63748
2024-09-27Revert "[clang][test] add testing for the AST matcher reference (#94248)"Julian Schmidt1-5673/+2266
This reverts commit 097ada2fcb607be09da94a0d11f627a3759a10de.
2024-09-27[clang][test] add testing for the AST matcher reference (#94248)Julian Schmidt1-2266/+5673
## Problem Statement Previously, the examples in the AST matcher reference, which gets generated by the doxygen comments in `ASTMatchers.h`, were untested and best effort. Some of the matchers had no or wrong examples of how to use the matcher. ## Solution This patch introduces a simple DSL around doxygen commands to enable testing the AST matcher documentation in a way that should be relatively easy to use. In `ASTMatchers.h`, most matchers are documented with a doxygen comment. Most of these also have a code example that aims to show what the matcher will match, given a matcher somewhere in the documentation text. The way that the documentation is tested, is by using doxygen's alias feature to declare custom aliases. These aliases forward to `<tt>text</tt>` (which is what doxygen's `\c` does, but for multiple words). Using the doxygen aliases is the obvious choice, because there are (now) four consumers: - people reading the header/using signature help - the doxygen generated documentation - the generated html AST matcher reference - (new) the generated matcher tests This patch rewrites/extends the documentation such that all matchers have a documented example. The new `generate_ast_matcher_doc_tests.py` script will warn on any undocumented matchers (but not on matchers without a doxygen comment) and provides diagnostics and statistics about the matchers. The current statistics emitted by the parser are: ```text Statistics: doxygen_blocks : 519 missing_tests : 10 skipped_objc : 42 code_snippets : 503 matches : 820 matchers : 580 tested_matchers : 574 none_type_matchers : 6 ``` The tests are generated during building and the script will only print something if it found an issue (compile failure, parsing issues, the expected and actual number of failures differs). ## Description DSL for generating the tests from documentation. TLDR: ``` \header{a.h} \endheader <- zero or more header \code int a = 42; \endcode \compile_args{-std=c++,c23-or-later} <- optional, the std flag supports std ranges and whole languages \matcher{expr()} <- one or more matchers in succession \match{42} <- one or more matches in succession \matcher{varDecl()} <- new matcher resets the context, the above \match will not count for this new matcher(-group) \match{int a = 42} <- only applies to the previous matcher (not to the previous case) ``` The above block can be repeated inside a doxygen command for multiple code examples for a single matcher. The test generation script will only look for these annotations and ignore anything else like `\c` or the sentences where these annotations are embedded into: `The matcher \matcher{expr()} matches the number \match{42}.`. ### Language Grammar [] denotes an optional, and <> denotes user-input ``` compile_args j:= \compile_args{[<compile_arg>;]<compile_arg>} matcher_tag_key ::= type match_tag_key ::= type || std || count || sub matcher_tags ::= [matcher_tag_key=<value>;]matcher_tag_key=<value> match_tags ::= [match_tag_key=<value>;]match_tag_key=<value> matcher ::= \matcher{[matcher_tags$]<matcher>} matchers ::= [matcher] matcher match ::= \match{[match_tags$]<match>} matches ::= [match] match case ::= matchers matches cases ::= [case] case header-block ::= \header{<name>} <code> \endheader code-block ::= \code <code> \endcode testcase ::= code-block [compile_args] cases ``` ### Language Standard Versions The 'std' tag and '\compile_args' support specifying a specific language version, a whole language and all of its versions, and thresholds (implies ranges). Multiple arguments are passed with a ',' separator. For a language and version to execute a tested matcher, it has to match the specified '\compile_args' for the code, and the 'std' tag for the matcher. Predicates for the 'std' compiler flag are used with disjunction between languages (e.g. 'c || c++') and conjunction for all predicates specific to each language (e.g. 'c++11-or-later && c++23-or-earlier'). Examples: - `c` all available versions of C - `c++11` only C++11 - `c++11-or-later` C++11 or later - `c++11-or-earlier` C++11 or earlier - `c++11-or-later,c++23-or-earlier,c` all of C and C++ between 11 and 23 (inclusive) - `c++11-23,c` same as above ### Tags #### `type`: **Match types** are used to select where the string that is used to check if a node matches comes from. Available: `code`, `name`, `typestr`, `typeofstr`. The default is `code`. - `code`: Forwards to `tooling::fixit::getText(...)` and should be the preferred way to show what matches. - `name`: Casts the match to a `NamedDecl` and returns the result of `getNameAsString`. Useful when the matched AST node is not easy to spell out (`code` type), e.g., namespaces or classes with many members. - `typestr`: Returns the result of `QualType::getAsString` for the type derived from `Type` (otherwise, if it is derived from `Decl`, recurses with `Node->getTypeForDecl()`) **Matcher types** are used to mark matchers as sub-matcher with 'sub' or as deactivated using 'none'. Testing sub-matcher is not implemented. #### `count`: Specifying a 'count=n' on a match will result in a test that requires that the specified match will be matched n times. Default is 1. #### `std`: A match allows specifying if it matches only in specific language versions. This may be needed when the AST differs between language versions. #### `sub`: The `sub` tag on a `\match` will indicate that the match is for a node of a bound sub-matcher. E.g., `\matcher{expr(expr().bind("inner"))}` has a sub-matcher that binds to `inner`, which is the value for the `sub` tag of the expected match for the sub-matcher `\match{sub=inner$...}`. Currently, sub-matchers are not tested in any way. ### What if ...? #### ... I want to add a matcher? Add a doxygen comment to the matcher with a code example, corresponding matchers and matches, that shows what the matcher is supposed to do. Specify the compile arguments/supported languages if required, and run `ninja check-clang-unit` to test the documentation. #### ... the example I wrote is wrong? The test-generation script will try to compile your example code before it continues. This makes finding issues with your example code easier because the test-failures are much more verbose. The test-failure output of the generated test file will provide information about - where the generated test file is located - which line in `ASTMatcher.h` the example is from - which matches were: found, not-(yet)-found, expected - in case of an unexpected match: what the node looks like using the different `type`s - the language version and if the test ran with a windows `-target` flag (also in failure summary) #### ... I don't adhere to the required order of the syntax? The script will diagnose any found issues, such as `matcher is missing an example` with a `file:line:` prefix, which should provide enough information about the issue. #### ... the script diagnoses a false-positive issue with a doxygen comment? It hopefully shouldn't, but if you, e.g., added some non-matcher code and documented it with doxygen, then the script will consider that as a matcher documentation. As a result, the script will print that it detected a mismatch between the actual and the expected number of failures. If the diagnostic truly is a false-positive, change the `expected_failure_statistics` at the top of the `generate_ast_matcher_doc_tests.py` file. Fixes #57607 Fixes #63748
2024-05-14Reapply "[Clang] Unify interface for accessing template arguments as written ↵Krystian Stasiowski1-103/+261
for class/variable template specializations (#81642)" (#91393) Reapplies #81642, fixing the crash which occurs when running the lldb test suite.
2024-05-07Revert "[Clang] Unify interface for accessing template arguments as written ↵Adrian Prantl1-261/+103
for class/variable template specializations (#81642)" This reverts commit 7115ed0fff027b65fa76fdfae215ed1382ed1473. This commit broke several LLDB tests. https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/3480/
2024-05-07[Clang] Unify interface for accessing template arguments as written for ↵Krystian Stasiowski1-103/+261
class/variable template specializations (#81642) Our current method of storing the template arguments as written for `(Class/Var)Template(Partial)SpecializationDecl` suffers from a number of flaws: - We use `TypeSourceInfo` to store `TemplateArgumentLocs` for class template/variable template partial/explicit specializations. For variable template specializations, this is a rather unintuitive hack (as we store a non-type specialization as a type). Moreover, we don't ever *need* the type as written -- in almost all cases, we only want the template arguments (e.g. in tooling use-cases). - The template arguments as written are stored in a number of redundant data members. For example, `(Class/Var)TemplatePartialSpecialization` have their own `ArgsAsWritten` member that stores an `ASTTemplateArgumentListInfo` (the template arguments). `VarTemplateSpecializationDecl` has yet _another_ redundant member "`TemplateArgsInfo`" that also stores an `ASTTemplateArgumentListInfo`. This patch eliminates all `(Class/Var)Template(Partial)SpecializationDecl` members which store the template arguments as written, and turns the `ExplicitInfo` member into a `llvm::PointerUnion<const ASTTemplateArgumentListInfo*, ExplicitInstantiationInfo*>` (to avoid unnecessary allocations when the declaration isn't an explicit instantiation). The template arguments as written are now accessed via `getTemplateArgsWritten` in all cases. The "most breaking" change is to AST Matchers, insofar that `hasTypeLoc` will no longer match class template specializations (since they no longer store the type as written).
2024-03-08[clang][ASTMatcher] Add matchers for isExplicitObjectMemberFunction() (#84446)Balazs Benics1-0/+15
Note that this patch will be necessary to fix `forEachArgumentWithParam()` and `forEachArgumentWithParamType()` matchers for deducing "this"; which is my true motivation. There the bug is that with explicit obj params, one should not adjust the number of arguments in presence of `CXXMethodDecls`, and this causes a mismatch there mapping the argument to the wrong param. But, I'll come back there once we have this matcher.
2024-02-28[clang] remove (clang::)ast_matchers:: namespace from AST matcher args for ↵Julian Schmidt1-7/+7
docs (#81437) When parsing the ASTMatchers.h file, a matcher could specify an argument that is a matcher using the not needed namespace `(clang::)ast_matchers::`. Change the argument parsing in dump_ast_matchers.py to remove those namespaces such that when parameters with these namespaces slip through, the namespaces will be not be shown in the matchers reference, like it is done with the `internal` namespace. Additionally, remove the not needed namespaces from arguments in ASTMatchers.h.
2024-01-16[clang][ASTMatcher] Add matchers for CXXFoldExpr (#71245)Julian Schmidt1-23/+271
Adds support for the following matchers related to `CXXFoldExpr`: `cxxFoldExpr`, `callee`, `hasInit`, `hasPattern`, `isRightFold`, `isLeftFold`, `isUnaryFold`, `isBinaryFold`, `hasOperator`, `hasLHS`, `hasRHS`.
2023-09-04[ASTMatchers] Bring comments & docs back in syncSam McCall1-1/+2
415d9e8ca39c0b42f351cc532ccfb48b6ac97f7f edited the generated html directly without updating the source of truth.
2023-08-16[clang][ASTMatcher] Add matcher for 'MacroQualifiedType'dingfei1-0/+12
Add matcher for 'MacroQualifiedType' Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D157777
2023-08-12[ASTMatcher] Fix typos in LibASTMatchersReference.htmldingfei1-3/+3
2023-08-07[clang][ASTMatcher] Add Matcher 'convertVectorExpr'dingfei1-0/+5
Add Matcher convertVectorExpr. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D157248
2023-08-07[clang][ASTMatcher] Add Matcher 'dependentSizedExtVectorType'dingfei1-0/+13
Add Matcher dependentSizedExtVectorType for DependentSizedExtVectorType. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D157237
2023-07-20[clang] adds `conceptDecl` as an ASTMatcherChristopher Di Bella1-0/+9
Closes #63934 Differential Revision: https://reviews.llvm.org/D155549
2023-07-20[WIP][-Wunsafe-buffer-usage] Handle lambda expressions within a method.Rashmi Mudduluru1-0/+37
Differential Revision: https://reviews.llvm.org/D150386
2023-07-18[clang][docs] Update LibASTMatchersReference.htmlRashmi Mudduluru1-27/+70
Differential Revision: https://reviews.llvm.org/D155304
2023-06-25[ASTMatchers] Add argumentCountAtLeast narrowing matcherMike Crowe1-0/+48
This will be used by the modernize-use-std-print clang-tidy check and related checks later. Reviewed By: PiotrZSL Differential Revision: https://reviews.llvm.org/D153716
2023-01-20Correct documentation for the refersToType AST matcherAaron Ballman1-3/+3
The docs used a nonexisting matcher that caused some confusion. It has now been replaced with the correct syntax. Fixes #58044
2023-01-10Remove a stale FIXME comment; NFCAaron Ballman1-2/+0
Also regenerates the AST matcher documentation. This matcher is tested in TEST(HasImplicitDestinationType, MatchesSimpleCase) and TEST(HasImplicitDestinationType, DoesNotMatchIncorrectly) in ASTMatchersTraversalTest.cpp.
2023-01-10Fix the documentation for the hasBody AST matcherAaron Ballman1-5/+100
The problem was whitespace between the comment and the code for the matcher. Rather than fix the script, I went the easier route and removed the offending newline. If this problem comes up again though, we should consider making the script less fragile.
2023-01-10Update dump_ast_matchers.py to Python 3Aaron Ballman1-20/+23
Also regenerates the documentation and fixed a validation diagnostic about use of 'is' vs '=='.
2022-12-23[ASTMatchers] Add isInAnonymousNamespace narrowing matcherCarlos Galvez1-0/+19
Used in a couple clang-tidy checks so it could be extracted out as its own matcher. Differential Revision: https://reviews.llvm.org/D140328
2022-10-18[doc] Fix invalid reference to `hasReturnArgument` matcher.Clement Courbet1-1/+1
The matcher is called `hasReturnValue`.
2022-07-21[ASTMatchers] Adding a new matcher for callee declarations of Obj-CZiqing Luo1-3/+34
message expressions For an Obj-C message expression `[o m]`, the adding matcher will match the declaration of the method `m`. This commit overloads the existing `callee` ASTMatcher, which originally was only for C/C++ nodes but also applies to Obj-C messages now. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D129398
2022-06-30Adds AST matcher for ObjCStringLiteralRashmi Mudduluru1-47/+52
Differential Revision: https://reviews.llvm.org/D128103
2022-05-19[Clang][[OpenMP5.1] Initial parser/sema for default(private) clauseJennifer Yu1-2/+22
This implements the default(private) clause as defined in OMP5.1 Differential Revision: https://reviews.llvm.org/D125912
2022-05-13[ASTMatchers][clang-tidy][NFC] Hoist `forEachTemplateArgument` matcher into ↵Whisperity1-0/+79
the core library Fixes the `FIXME:` related to adding `forEachTemplateArgument` to the core AST Matchers library. Reviewed By: aaron.ballman Differential Revision: http://reviews.llvm.org/D125383
2022-05-11[ASTMatchers][NFC] Fix name of matcher in docs and add a missing testWhisperity1-1/+1
2022-02-23[ASTMatchers] Expand isInline matcher to VarDeclNathan James1-2/+23
Add support to the `isInline` matcher for C++17's inline variables. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D118900
2022-02-03[clang][docs] Regenerate ASTMatchers documentationNathan James1-17/+68
2022-01-24Add `isConstinit` matcherEvgeny Shulgin1-0/+13
Support C++20 constinit variables for AST Matchers.
2022-01-20Add `isConsteval` matcherEvgeny Shulgin1-0/+32
Support C++20 consteval functions and C++2b if consteval for AST Matchers.
2021-12-02Fix documentation for `forEachLambdaCapture` and `hasAnyCapture`James King1-29/+29
Updates the return types of these matchers' definitions to use `internal::Matcher<LambdaCapture>` instead of `LambdaCaptureMatcher`. This ensures that they are categorized as traversal matchers, instead of narrowing matchers. Reviewed By: ymandel, tdl-g, aaron.ballman Differential Revision: https://reviews.llvm.org/D114809
2021-11-15Add `isInitCapture` and `forEachLambdaCapture` matchers.James King1-1/+35
This contributes follow-up work from https://reviews.llvm.org/D112491, which allows for increased control over the matching of lambda captures. This also updates the documentation for the `lambdaCapture` matcher. Reviewed By: ymandel, aaron.ballman Differential Revision: https://reviews.llvm.org/D113575
2021-11-08Add `LambdaCapture`-related matchers.James King1-18/+48
This provides better support for `LambdaCapture`s by making them first- class and allowing them to be bindable. In addition, this implements several `LambdaCapture`-related matchers. This does not update how lambdas are traversed. As a result, something like trying to match `lambdaCapture()` by itself will not work - it must be used as an inner matcher. Reviewed By: aaron.ballman, sammccall Differential Revision: https://reviews.llvm.org/D112491
2021-10-08Add `TypeLoc`-related matchers.James King1-22/+193
Contributes several matchers that involve `TypeLoc`s. These matchers are (in alphabetical order): - elaboratedTypeLoc - hasAnyTemplateArgumentLoc - hasNamedTypeLoc - hasPointeeLoc - hasReferentLoc - hasReturnTypeLoc - hasTemplateArgumentLoc - hasUnqualifiedLoc - pointerTypeLoc - qualifiedTypeLoc - referenceTypeLoc - templateSpecializationTypeLoc Reviewed By: ymandel, aaron.ballman Differential Revision: https://reviews.llvm.org/D111242
2021-09-04[clang] NFC: Fix trivial typo in comments and documentKazuaki Ishizaki1-1/+1
`the the` -> `the` Reviewed By: xgupta Differential Revision: https://reviews.llvm.org/D77470