summaryrefslogtreecommitdiffstats
path: root/clang/lib/ASTMatchers
Commit message (Collapse)AuthorAgeFilesLines
...
* [AST] Allow limiting the scope of common AST traversals (getParents, RAV).Sam McCall2018-11-141-6/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The goal is to allow analyses such as clang-tidy checks to run on a subset of the AST, e.g. "only on main-file decls" for interactive tools. Today, these become "problematically global" by running RecursiveASTVisitors rooted at the TUDecl, or by navigating up via ASTContext::getParent(). The scope is restricted using a set of top-level-decls that RecursiveASTVisitors should be rooted at. This also applies to the visitor that populates the parent map, and so the top-level-decls are considered to have no parents. This patch makes the traversal scope a mutable property of ASTContext. The more obvious way to do this is to pass the top-level decls to relevant functions directly, but this has some problems: - it's error-prone: accidentally mixing restricted and unrestricted scopes is a performance trap. Interleaving multiple analyses is common (many clang-tidy checks run matchers or RAVs from matcher callbacks) - it doesn't map well to the actual use cases, where we really do want *all* traversals to be restricted. - it involves a lot of plumbing in parts of the code that don't care about traversals. This approach was tried out in D54259 and D54261, I wanted to like it but it feels pretty awful in practice. Caveats: to get scope-limiting behavior of RecursiveASTVisitors, callers have to call the new TraverseAST(Ctx) function instead of TraverseDecl(TU). I think this is an improvement to the API regardless. Reviewers: klimek, ioeric Subscribers: mgorny, cfe-commits Differential Revision: https://reviews.llvm.org/D54309 llvm-svn: 346847
* [ASTMatchers] overload ignoringParens for ExprJonas Toth2018-11-091-1/+1
| | | | | | | | | | | | | | | | Summary: This patch allows fixing PR39583. Reviewers: aaron.ballman, sbenza, klimek Reviewed By: aaron.ballman Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D54307 llvm-svn: 346554
* Compound literals, enums, et al require const exprBill Wendling2018-11-092-0/+2
| | | | | | | | | | | | | | | | | | Summary: Compound literals, enums, file-scoped arrays, etc. require their initializers and size specifiers to be constant. Wrap the initializer expressions in a ConstantExpr so that we can easily check for this later on. Reviewers: rsmith, shafik Reviewed By: rsmith Subscribers: cfe-commits, jyknight, nickdesaulniers Differential Revision: https://reviews.llvm.org/D53921 llvm-svn: 346455
* Add the isStaticLocal() AST matcher for matching on local static variables.Aaron Ballman2018-10-291-0/+1
| | | | | | Patch by Joe Ranieri. llvm-svn: 345502
* Use llvm::{all,any,none}_of instead std::{all,any,none}_of. NFCFangrui Song2018-10-201-5/+5
| | | | llvm-svn: 344859
* [ASTMatcher] Add missing imaginaryLiteralStephen Kelly2018-10-091-0/+1
| | | | llvm-svn: 344026
* Add matchers missing from dynamic AST registryStephen Kelly2018-10-031-0/+7
| | | | llvm-svn: 343717
* Sort list of matchersStephen Kelly2018-10-031-14/+14
| | | | llvm-svn: 343716
* Allow comments with '#' in dynamic AST MatchersStephen Kelly2018-10-031-0/+4
| | | | | | | | | | | | | | Summary: This is necessary for clang-query to be able to handle comments. Reviewers: aaron.ballman Reviewed By: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D52751 llvm-svn: 343665
* Use the container form llvm::sort(C, ...)Fangrui Song2018-09-301-5/+5
| | | | | | | | | There are a few leftovers of rC343147 that are not (\w+)\.begin but in the form of ([-[:alnum:]>.]+)\.begin or spanning two lines. Change them to use the container form in this commit. The 12 occurrences have been inspected manually for safety. llvm-svn: 343425
* [ASTMatchers] add three matchers for dependent expressionsJonas Toth2018-09-111-0/+3
| | | | | | | | | | | | | | | | | | | Summary: The new matchers can be used to check if an expression is type-, value- or instantiation-dependent in a templated context. These matchers are used in a clang-tidy check and generally useful as the problem of unresolved templates occurs more often in clang-tidy and they provide an easy way to check for this issue. Reviewers: aaron.ballman, alexfh, klimek Reviewed By: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D51880 llvm-svn: 341958
* Allow binding to NamedValue resulting from let expressionStephen Kelly2018-08-301-2/+21
| | | | | | | | Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D51259 llvm-svn: 341142
* Extract parseBindID methodStephen Kelly2018-08-301-31/+38
| | | | | | | | Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D51258 llvm-svn: 341141
* Fix import of class templates partial specializationGabor Marton2018-08-221-0/+3
| | | | | | | | | | | | | | | | | | | Summary: Currently there are several issues with the import of class template specializations. (1) Different TUs may have class template specializations with the same template arguments, but with different set of instantiated MethodDecls and FieldDecls. In this patch we provide a fix to merge these methods and fields. (2) Currently, we search the partial template specializations in the set of simple specializations and we add partial specializations as simple specializations. This is bad, this patch fixes it. Reviewers: a_sidorin, xazax.hun, r.stahl Subscribers: rnkovacs, dkrupp, cfe-commits Differential Revision: https://reviews.llvm.org/D50451 llvm-svn: 340402
* [ASTMatchers] Add matchers unresolvedMemberExpr, cxxDependentScopeMemberExprShuai Wang2018-08-122-0/+6
| | | | | | | | Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D50606 llvm-svn: 339522
* Add support for importing imaginary literalsGabor Marton2018-08-091-0/+1
| | | | | | | | | | Reviewers: a_sidorin, r.stahl, xazax.hun Subscribers: rnkovacs, dkrupp, cfe-commits Differential Revision: https://reviews.llvm.org/D50428 llvm-svn: 339334
* [ASTMatchers] Introduce a matcher for `ObjCIvarExpr`, support getting it's ↵George Karpenkov2018-07-272-0/+2
| | | | | | | | | | | | | declaration. ObjCIvarExpr is *not* a subclass of MemberExpr, and a separate matcher is required to support it. Adding a hasDeclaration support as well, as it's not very useful without it. Differential Revision: https://reviews.llvm.org/D49701 llvm-svn: 338137
* [ASTMatchers] Add an isMain() matcherGeorge Karpenkov2018-07-231-0/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D49615 llvm-svn: 337761
* [ASTMatchers] add matcher for decltypeType and its underlyingTypeJonas Toth2018-07-232-0/+2
| | | | | | | | | | | | | | | | Summary: This patch introduces a new matcher for `DecltypeType` and its underlying type in order to fix a bug in clang-tidy, see https://reviews.llvm.org/D48717 for more. Reviewers: aaron.ballman, alexfh, NoQ, dcoughlin Reviewed By: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D48759 llvm-svn: 337703
* [ASTMatchers] Introduce Objective-C matchers `hasReceiver` and ↵George Karpenkov2018-07-161-0/+2
| | | | | | | | `isInstanceMessage` for ObjCMessageExpr Differential Revision: https://reviews.llvm.org/D49333 llvm-svn: 337209
* [ASTMatchers] A matcher for Objective-C @autoreleasepoolGeorge Karpenkov2018-07-062-0/+3
| | | | | | Differential Revision: https://reviews.llvm.org/D48910 llvm-svn: 336468
* [ASTMatchers] Introduce a blockDecl matcher for matching block declarationsGeorge Karpenkov2018-05-162-0/+3
| | | | | | | | Blocks can be matched just as well as functions or Objective-C methods. Differential Revision: https://reviews.llvm.org/D46980 llvm-svn: 332545
* Remove \brief commands from doxygen comments.Adrian Prantl2018-05-096-47/+47
| | | | | | | | | | | | | | | | | | | This is similar to the LLVM change https://reviews.llvm.org/D46290. We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\@brief'); do perl -pi -e 's/\@brief //g' $i & done for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done Differential Revision: https://reviews.llvm.org/D46320 llvm-svn: 331834
* Fix typos in clangAlexander Kornienko2018-04-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Found via codespell -q 3 -I ../clang-whitelist.txt Where whitelist consists of: archtype cas classs checkk compres definit frome iff inteval ith lod methode nd optin ot pres statics te thru Patch by luzpaz! (This is a subset of D44188 that applies cleanly with a few files that have dubious fixes reverted.) Differential revision: https://reviews.llvm.org/D44188 llvm-svn: 329399
* [astmatchers] Fix linking issueGeorge Karpenkov2018-03-291-0/+3
| | | | llvm-svn: 328754
* [astmatchers] Move a matcher out of internal namespace: blind debugging of ↵George Karpenkov2018-03-291-9/+10
| | | | | | MSVC issues llvm-svn: 328750
* [ASTMatchers] Introduce a matcher for matching any given Objective-C selectorGeorge Karpenkov2018-03-292-4/+25
| | | | | | | | Incudes a tiny related refactoring. Differential Revision: https://reviews.llvm.org/D44858 llvm-svn: 328747
* [clang] Change std::sort to llvm::sort in response to r327219Mandeep Singh Grang2018-03-271-2/+2
| | | | | | | | | | | r327219 added wrappers to std::sort which randomly shuffle the container before sorting. This will help in uncovering non-determinism caused due to undefined sorting order of objects having the same key. To make use of that infrastructure we need to invoke llvm::sort instead of std::sort. llvm-svn: 328636
* [ASTMatchers] Add isAssignmentOperator matcherPeter Szecsi2018-03-271-0/+1
| | | | | | | | | | | Adding a matcher for BinaryOperator and cxxOperatorCallExpr to be able to decide whether it is any kind of assignment operator or not. This would be useful since allows us to easily detect assignments via matchers for static analysis (Tidy, SA) purposes. Differential Revision: https://reviews.llvm.org/D44893 llvm-svn: 328618
* PR36581: Support data recursion over Stmts in AST matchers.Richard Smith2018-03-021-11/+16
| | | | llvm-svn: 326624
* Add hasTrailingReturn AST matcherJulie Hockett2018-01-221-0/+1
| | | | | | | | Adds AST matcher for a FunctionDecl that has a trailing return type. Differential Revision: https://reviews.llvm.org/D42273 llvm-svn: 323158
* [ASTMatcher] Add isScoped matcher for enumDecl.Haojian Wu2018-01-181-0/+1
| | | | | | | | | | | | Summary: Reviewers: bkramer, aaron.ballman Subscribers: aaron.ballman, cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D42185 llvm-svn: 322826
* [ASTMatchers] Add isNoReturn() match narrower for FunctionDeclarationsRoman Lebedev2018-01-171-0/+1
| | | | | | | | | | | | | | Reviewers: aaron.ballman Reviewed By: aaron.ballman Subscribers: dblaikie, klimek, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D41455 llvm-svn: 322746
* Remove creation of out-of-bounds value of enumeration type (resulting in UB).Richard Smith2017-12-081-12/+10
| | | | | | | Also remove unnecessary initialization of out-parameters with this value, so that MSan is able to catch errors appropriately. llvm-svn: 320212
* Add the hasDefinition() AST matcher to match class declarations that also ↵Aaron Ballman2017-11-291-0/+1
| | | | | | | | have a definition. Patch by Julie Hockett. llvm-svn: 319360
* [ASTMatchers] Matchers for new[] operatorsAdam Balogh2017-11-231-0/+2
| | | | | | | | Two new matchers for `CXXNewExpr` are added which may be useful e.g. in `clang-tidy` checkers. One of them is `isArray` which matches `new[]` but not plain `new`. The other one, `hasArraySize` matches `new[]` for a given size. llvm-svn: 318909
* Add an AST matcher for hasDefaultArgument() to match on parameter ↵Aaron Ballman2017-11-211-0/+1
| | | | | | | | declarations that have a default value. Patch by Julie Hockett. llvm-svn: 318794
* ASTMatchers{,Macros}.h: Add some extra macros to use for decl/def of matchersDavid Blaikie2017-11-211-0/+9
| | | | | | | Fix ODR violations caused by using internal linkage variables in non-internal inline functions. (also removes duplicate definitions, etc) llvm-svn: 318720
* ASTMatchers.h: Fix ODR violations by avoiding internal linkage variables in ↵David Blaikie2017-11-151-0/+268
| | | | | | | | | | | | | | headers Internal linkage variables ODR referenced from inline functions create ODR violations (the same inline function ends up having different definitions in each TU, since it references different variables - rather than one definition). This also happens to break modular code generation - so this is the last fix to allow clang to compile with modular code generation. llvm-svn: 318304
* Add ObjC exception statement AST matchersDave Lee2017-11-111-0/+4
| | | | | | | | | | | | | | Summary: Add AST matchers for Objective-C @throw, @try, @catch and @finally. Reviewers: aaron.ballman, malcolm.parsons, alexshap, compnerd Reviewed By: aaron.ballman Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D39940 llvm-svn: 317992
* [ASTMatchers] Fix some Clang-tidy modernize and Include What You Use ↵Eugene Zelenko2017-11-014-83/+162
| | | | | | warnings; other minor fixes (NFC). llvm-svn: 317137
* Add objcCategoryImplDecl matcherDave Lee2017-10-261-0/+1
| | | | | | | | | | | | | | | | | Summary: Add `objcCategoryImplDecl` which matches ObjC category definitions (`@implementation`). This matcher complements `objcCategoryDecl` (`@interface`) which was added in D30854. Reviewers: aaron.ballman, malcolm.parsons, alexshap Reviewed By: aaron.ballman Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D39293 llvm-svn: 316670
* [ASTMatchers] Expose forEachOverriden in dynamic AST matchers.Benjamin Kramer2017-10-231-0/+1
| | | | llvm-svn: 316344
* [ASTMatchers] Don't create a copy of a std::set when iterating over it.Benjamin Kramer2017-10-101-1/+4
| | | | | | | This is a bit awkward because lookup returns a copy instead of a reference. No functionality change intended. llvm-svn: 315276
* Add objcImplementationDecl matcherDave Lee2017-09-101-0/+1
| | | | | | | | | | | | | | | | | | | | | Summary: Add the `objcImplementationDecl` matcher. See related: D30854 Tested with: ``` ./tools/clang/unittests/ASTMatchers/ASTMatchersTests ``` Reviewers: aaron.ballman, compnerd, alexshap Reviewed By: aaron.ballman Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D37643 llvm-svn: 312889
* Register linkageSpecDecl matcherDave Lee2017-08-311-0/+1
| | | | | | | | | | | | | | | | | Summary: This allows `linkageSpecDecl` to be used from `clang-query`. See also D31869 which similary adds `isStaticStorageClass`. Reviewers: aaron.ballman Reviewed By: aaron.ballman Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D37346 llvm-svn: 312283
* [ASTMatchers] Fix use after free.Benjamin Kramer2017-06-091-1/+2
| | | | | | Found by asan. llvm-svn: 305094
* [ASTMatchers] Add clang-query support for equals matcherPeter Wu2017-06-081-9/+19
| | | | | | | | | | | | | Summary: This allows the clang-query tool to use matchers like "integerLiteral(equals(32))". For this to work, an overloaded function is added for each possible parameter type. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D33094 llvm-svn: 305022
* [ASTMatchers] Add support for floatLiteralsPeter Wu2017-06-084-15/+81
| | | | | | | | | | | | | Summary: Needed to support something like "floatLiteral(equals(1.0))". The parser for floating point numbers is kept simple, so instead of ".1" you have to use "0.1". Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D33135 llvm-svn: 305021
* [ASTMatchers] Add support for boolean literalsPeter Wu2017-06-083-2/+52
| | | | | | | | | | | | | Summary: Recognize boolean literals for future extensions ("equals(true)"). Note that a specific VariantValue constructor is added to resolve ambiguity (like "Value = 5") between unsigned and bool. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D33093 llvm-svn: 305020
OpenPOWER on IntegriCloud