summaryrefslogtreecommitdiffstats
path: root/clang/unittests/ASTMatchers
Commit message (Collapse)AuthorAgeFilesLines
...
* Make isNoThrow and hasDynamicExceptionSpec polymorphic so they can be used ↵Aaron Ballman2016-06-071-0/+21
| | | | | | | | with both functionDecl and functionPrototype matchers. Patch by Don Hinton. llvm-svn: 272028
* Adding an AST matcher to ignore parenthesis in *types* (rather than ↵Aaron Ballman2016-06-061-0/+7
| | | | | | expressions). This is required for traversing certain types (like function pointer types). llvm-svn: 271927
* [ASTMatchers] Breaking change of `has` matcherPiotr Padlewski2016-05-311-2/+2
| | | | | | | | has matcher can now match to implicit and paren casts http://reviews.llvm.org/D20801 llvm-svn: 271288
* [ASTMatchers] Add support of hasCondition for SwitchStmt.Etienne Bergeron2016-05-301-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The switch statement could be added to the hasCondition matcher. Example: ``` clang-query> match switchStmt(hasCondition(ignoringImpCasts(declRefExpr()))) ``` Output: ``` Match #1: Binding for "root": SwitchStmt 0x2f9b528 </usr/local/google/home/etienneb/examples/enum.cc:35:3, line:38:3> |-<<<NULL>>> |-ImplicitCastExpr 0x2f9b510 <line:35:11> 'int' <IntegralCast> | `-ImplicitCastExpr 0x2f9b4f8 <col:11> 'enum Color' <LValueToRValue> | `-DeclRefExpr 0x2f9b4d0 <col:11> 'enum Color' lvalue Var 0x2f9a118 'C' 'enum Color' `-CompoundStmt 0x2f9b610 <col:14, line:38:3> |-CaseStmt 0x2f9b578 <line:36:3, col:22> | |-ImplicitCastExpr 0x2f9b638 <col:8> 'int' <IntegralCast> | | `-DeclRefExpr 0x2f9b550 <col:8> 'enum Size' EnumConstant 0x2f99e40 'Small' 'enum Size' | |-<<<NULL>>> | `-ReturnStmt 0x2f9b5d0 <col:15, col:22> | `-IntegerLiteral 0x2f9b5b0 <col:22> 'int' 1 `-DefaultStmt 0x2f9b5f0 <line:37:3, col:12> `-BreakStmt 0x2f9b5e8 <col:12> 1 match. ``` Reviewers: aaron.ballman, sbenza, klimek Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D20767 llvm-svn: 271208
* [ASTMacther] A follow-up on unresolvedLookupExpr test fixing.Haojian Wu2016-05-181-1/+4
| | | | llvm-svn: 269957
* [ASTMatcher] Fix a ASTMatcher test failure on Windows.Haojian Wu2016-05-181-7/+8
| | | | | | | | | | Reviewers: alexfh, aaron.ballman Subscribers: thakis, cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D20369 llvm-svn: 269936
* [ASTMatcher] Add a node matcher for UnresolvedLookupExpr.Haojian Wu2016-05-181-0/+9
| | | | | | | | | | Reviewers: alexfh, aaron.ballman Subscribers: aaron.ballman, klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D20360 llvm-svn: 269916
* Dividied ASTMatcherTests into 4 filesPiotr Padlewski2016-05-177-5650/+5703
| | | | | | | fix for long compilation [20061] http://reviews.llvm.org/D20210 llvm-svn: 269802
* Add the hasDynamicExceptionSpec() AST matcher to match function declarations ↵Aaron Ballman2016-05-161-0/+16
| | | | | | | | that have a dynamic exception specification. Patch by Don Hinton. llvm-svn: 269662
* Add an AST matcher for CastExpr kindEtienne Bergeron2016-05-131-0/+9
| | | | | | | | | | | | | | Summary: This AST matcher will match a given CastExpr kind. It's an narrowing matcher on CastExpr. Reviewers: klimek, alexfh, sbenza, aaron.ballman Subscribers: Prazek, jroelofs, aaron.ballman, klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D19871 llvm-svn: 269460
* Add an AST matcher for string-literal lengthEtienne Bergeron2016-05-121-1/+11
| | | | | | | | | | | | | | | | Summary: This patch is adding support for a matcher to check string literal length. This matcher is used in clang-tidy checkers and is part of this refactoring: see: http://reviews.llvm.org/D19841 Reviewers: sbenza, klimek, aaron.ballman Subscribers: alexfh, klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D19876 llvm-svn: 269274
* [ASTMatchers] New matcher forFunctionGabor Horvath2016-05-041-0/+35
| | | | | | | | | | | | Summary: Matcher proposed in the review of checker misc-assign-operator (name pending). Its goal is to find the direct enclosing function declaration of a statement and run the inner matcher on it. Two version is attached in this patch (thus it will not compile), to be decided which approach to take. The second one always chooses one single parent while the first one does a depth-first search upwards (thus a height-first search) and returns the first positive match of the inner matcher (thus it always returns zero or one matches, not more). Further questions: is it enough to implement it in-place, or ASTMatchersInternals or maybe ASTMatchFinder should be involved? Reviewers: sbenza Subscribers: aaron.ballman, klimek, o.gyorgy, xazax.hun, cfe-commits Differential Revision: http://reviews.llvm.org/D19357 llvm-svn: 268490
* Clarify memory ownership semantics; NFC.Aaron Ballman2016-04-212-93/+96
| | | | | | Patch by Clement Courbet llvm-svn: 266986
* [ASTMatchers] Do not try to memoize nodes we can't compare.Samuel Benzaquen2016-04-191-0/+13
| | | | | | | | | | | | | | | | Summary: Prevent hasAncestor from comparing nodes that are not supported. hasDescendant was fixed some time ago to avoid this problem. I'm applying the same fix to hasAncestor: if any object in the Builder map is not comparable, skip the cache. Reviewers: alexfh Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D19231 llvm-svn: 266748
* Add typedefNameDecl() and typeAliasDecl() to the AST matchers; improves ↵Aaron Ballman2016-04-141-1/+27
| | | | | | | | hasType() to match on TypedefNameDecl nodes. Patch by Clement Courbet. llvm-svn: 266331
* Reorder ASTNodeKind::AllKindInfo to match NodeKindId.Alexander Kornienko2016-04-142-10/+9
| | | | | | | | | | | | | | Summary: AllKindInfo is being indexed by NodeKindId, so the order must match. Extended ASTTypeTraits tests to cover this. Reviewers: sbenza Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D19059 llvm-svn: 266268
* Add AST Matchers for CXXConstructorDecl::isDelegatingConstructor and ↵Alexander Kornienko2016-04-131-0/+26
| | | | | | | | | | | | | | | | CXXMethodDecl::isUserProvided. Summary: Added two AST matchers: isDelegatingConstructor for CXXConstructorDecl::IsDelegatingConstructor; and isUserProvided corresponding to CXXMethodDecl::isUserProvided. Reviewers: aaron.ballman, alexfh Subscribers: klimek, cfe-commits Patch by Michael Miller! Differential Revision: http://reviews.llvm.org/D19038 llvm-svn: 266189
* [ASTMatchers]: fix crash in hasReturnValueMatthias Gehre2016-04-121-0/+1
| | | | | | | | | | | | | | | Summary: The crash was reproduced by the included test case. It was initially found through a crash of clang-tidy's misc-misplaced-widening-cast check. Reviewers: klimek, alexfh Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D18991 llvm-svn: 266043
* [ASTMatchers] Existing matcher hasAnyArgument fixedGabor Horvath2016-03-301-1/+6
| | | | | | | | | | | | Summary: A checker (will be uploaded after this patch) needs to check implicit casts. The checker needs matcher hasAnyArgument but it ignores implicit casts and parenthesized expressions which disables checking of implicit casts for arguments in the checker. However the documentation of the matcher contains a FIXME that this should be removed once separate matchers for ignoring implicit casts and parenthesized expressions are ready. Since these matchers were already there the fix could be executed. Only one Clang checker was affected which was also fixed (ignoreParenImpCasts added) and is separately uploaded. Third party checkers (not in the Clang repository) may be affected by this fix so the fix must be emphasized in the release notes. Reviewers: klimek, sbenza, alexfh Subscribers: alexfh, klimek, xazax.hun, cfe-commits Differential Revision: http://reviews.llvm.org/D18243 llvm-svn: 264855
* [ASTMatchers] Add own version of VariadicFunction.Samuel Benzaquen2016-03-251-0/+3
| | | | | | | | | | | | | | | | Summary: llvm::VariadicFunction is only being used by ASTMatchers. Having our own copy here allows us to remove the other one from llvm/ADT. Also, we can extend the API to meet our needs without modifying the common implementation. Reviewers: alexfh Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D18275 llvm-svn: 264417
* [ASTMatchers] New matcher hasReturnValue addedAlexander Kornienko2016-03-221-0/+6
| | | | | | | | | | | | | | Summary: A checker (will be uploaded after this patch) needs to check implicit casts. Existing generic matcher "has" ignores implicit casts and parenthesized expressions and no specific matcher for matching return value expression preexisted. The patch adds such a matcher (hasReturnValue). Reviewers: klimek, sbenza Subscribers: xazax.hun, klimek, cfe-commits Patch by Ádám Balogh! Differential Revision: http://reviews.llvm.org/D17986 llvm-svn: 264037
* Use an explicit instantiation to work around delayed template parsing for ↵Aaron Ballman2016-03-091-3/+3
| | | | | | MSVC-built bots. llvm-svn: 263041
* Adding new AST matchers for: addrLabelExpr, atomicExpr, ↵Aaron Ballman2016-03-092-1/+111
| | | | | | | | binaryConditionalOperator, designatedInitExpr, designatorCountIs, hasSyntacticForm, implicitValueInitExpr, labelDecl, opaqueValueExpr, parenListExpr, predefinedExpr, requiresZeroInitialization, and stmtExpr. Patch by Aleksei Sidorin. llvm-svn: 263027
* Turning on the /bigobj flag for two more files that will not link with MSVC ↵Aaron Ballman2016-03-081-0/+6
| | | | | | 2015 Win64 Debug due to the section limit. llvm-svn: 262938
* [ASTMatchers] Document that isAnyPointer() matcher also matches Objective-C ↵Felix Berger2016-03-061-0/+5
| | | | | | | | | | | | | | object pointers. Summary: Add test for Objective-C object pointer matching. Reviewers: aaron.ballman Subscribers: klimek Differential Revision: http://reviews.llvm.org/D17489 llvm-svn: 262806
* [ASTMatchers] Add matcher hasAnyName.Samuel Benzaquen2016-02-221-0/+13
| | | | | | | | | | | | Summary: Add matcher hasAnyName as an optimization over anyOf(hasName(),...) Reviewers: alexfh Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D17163 llvm-svn: 261574
* Add an AST matcher for real floating-point types. e.g., float, double, long ↵Aaron Ballman2016-02-181-0/+9
| | | | | | double, but not complex. llvm-svn: 261221
* Missing semicolons are kind of important. Who knew?Aaron Ballman2016-02-161-1/+1
| | | | llvm-svn: 261009
* Add a nullPointerConstant() AST matcher to handle variations of null pointer ↵Aaron Ballman2016-02-161-0/+10
| | | | | | constants in one matcher. llvm-svn: 261008
* Add isAnyPointer() matchers. Register missing matchers.Felix Berger2016-02-151-0/+8
| | | | | | | | | | | | | Summary: The isAnyPointer() matcher is useful for http://reviews.llvm.org/D15623. Reviewers: alexfh, klimek Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D15819 llvm-svn: 260872
* Make ParentMap work with explicit specializations of function templates.Nico Weber2016-02-081-0/+7
| | | | | | | | | | | | | | | | | For an explicit specialization, we first build a FunctionDecl, and then we call SubstDecl() on it to build a second FunctionDecl, which has the first FunctionDecl as canonical decl. The address of an explicit specialization of function template used to be the canonical decl of the FunctionDecl. This is different from all the other DeduceTemplateArguments() calls in SemaOverload, and since the canonical decl isn't visited by ParentMap while the redecl is, it also made ParentMap assert when computing the parent of a address-of-explicit-specialization-fun-template. To fix, remove the getCanonicalDecl() call. No behavior difference for clang, but it fixes an assert in ParentMap (which is e.g. used by libTooling). llvm-svn: 260159
* [ASTMatchers] Allow hasName() to look through inline namespacesSamuel Benzaquen2016-02-051-0/+46
| | | | | | | | | | | | | | | | | Summary: Allow hasName() to look through inline namespaces. This will fix the interaction between some clang-tidy checks and libc++. libc++ defines names in an inline namespace named std::<version_#>. When we try to match a name using hasName("std::xxx") it fails to match and the clang-tidy check does not work. Reviewers: klimek Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D15506 llvm-svn: 259898
* Provide match function to look over an entire TU again.Daniel Jasper2016-02-031-1/+9
| | | | llvm-svn: 259648
* Always build a new TypeSourceInfo for function templates with parametersNico Weber2016-02-011-0/+11
| | | | | | | | | | | | | | | | | | | | | RecursiveASTVisitor::TraverseFunctionHelper() traverses a function's ParmVarDecls by going to the function's getTypeSourceInfo if it exists, and `DEF_TRAVERSE_TYPELOC(FunctionProtoType` then goes to the function's ParmVarDecls. For a function template that doesn't have parameters that explicitly depend on the template parameter, we used to be clever and not build a new TypeSourceInfo. That meant that when an instantiation of such a template is visited, its TypeSourceInfo would point to the ParmVarDecls of the template, not of the instantiation, which then confused clients of RecursiveASTVisitor. So don't be clever for function templates that have parameters, even if none of the parameters depend on the type. Fixes PR26257. http://reviews.llvm.org/D16478 llvm-svn: 259428
* Reapply r259210 with a fix for RegistryTest.cpp.Aaron Ballman2016-02-012-2/+26
| | | | | | Patch by Richard Thomson. llvm-svn: 259359
* Revert r259210 "Extend hasType narrowing matcher for TypedefDecls, add ↵Hans Wennborg2016-01-291-25/+1
| | | | | | | | functionProtoType matcher for FunctionProtoType nodes, extend parameterCountIs to FunctionProtoType nodes." It didn't pass check-clang. llvm-svn: 259218
* Extend hasType narrowing matcher for TypedefDecls, add functionProtoType ↵Aaron Ballman2016-01-291-1/+25
| | | | | | | | matcher for FunctionProtoType nodes, extend parameterCountIs to FunctionProtoType nodes. Patch by Richard Thomson llvm-svn: 259210
* Add an optional ToolName argument to ↵Benjamin Kramer2016-01-291-3/+3
| | | | | | | | | | runToolOnCodeWithArgs/buildASTFromCodeWithArgs. This can be used as a way to modify argv[0] for a clang tool. Differential Revision: http://reviews.llvm.org/D16718 llvm-svn: 259187
* Include RecordDecls from anonymous unions in the AST.Nico Weber2016-01-281-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For void f() { union { int i; }; } clang used to omit the RecordDecl from the anonymous union from the AST. That's because the code creating it only called PushOnScopeChains(), which adds it to the current DeclContext, which here is the function's DeclContext. But RecursiveASTVisitor doesn't descent into all decls in a FunctionDecl. Instead, for DeclContexts that contain statements, return the RecordDecl so that it can be included in the DeclStmt containing the VarDecl for the union. Interesting bits from the AST before this change: |-FunctionDecl | `-CompoundStmt | |-DeclStmt | | `-VarDecl 0x589cd60 <col:3> col:3 implicit used 'union (anonymous at test.cc:3:3)' callinit After this change: -FunctionDecl | `-CompoundStmt | |-DeclStmt | | |-CXXRecordDecl 0x4612e48 <col:3, col:18> col:3 union definition | | | |-FieldDecl 0x4612f70 <col:11, col:15> col:15 referenced i 'int' | | `-VarDecl 0x4613010 <col:3> col:3 implicit used 'union (anonymous at test.cc:3:3)' callinit This is now closer to how anonymous struct and unions are represented as members of structs. It also enabled deleting some one-off code in the template instantiation code. Finally, it fixes a crash with ASTMatchers, see the included test case (this fixes http://crbug.com/580749). llvm-svn: 259079
* Remove autoconf supportChris Bieneman2016-01-262-44/+0
| | | | | | | | | | | | | | | | | Summary: This patch is provided in preparation for removing autoconf on 1/26. The proposal to remove autoconf on 1/26 was discussed on the llvm-dev thread here: http://lists.llvm.org/pipermail/llvm-dev/2016-January/093875.html "This is the way [autoconf] ends Not with a bang but a whimper." -T.S. Eliot Reviewers: chandlerc, grosbach, bob.wilson, echristo Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D16472 llvm-svn: 258862
* Add am AST matcher for isMoveAssignmentOperator.Aaron Ballman2016-01-221-0/+15
| | | | | | Patch by Jonathan Coe. llvm-svn: 258573
* Let RecursiveASTVisitor visit array index VarDeclsNico Weber2016-01-221-0/+8
| | | | | | | | | | | | An implicit copy ctor creates loop VarDecls that hang off CXXCtorInitializer. RecursiveASTVisitor used to not visit them, so that they didn't show up in the parent map used by ASTMatchers, causing asserts() when the implicit DeclRefExpr() in a CXXCtorInitializer referred to one of these VarDecls. Fixes PR26227. http://reviews.llvm.org/D16413 llvm-svn: 258503
* Add an isVirtualAsWritten AST matcher.Nico Weber2016-01-211-0/+10
| | | | | | http://reviews.llvm.org/D16394 llvm-svn: 258415
* Add AST matcher support for FunctionDecls with the hasBody matcher.Aaron Ballman2016-01-202-1/+5
| | | | | | Patch by Aleksei Sidorin. llvm-svn: 258322
* Add AST matcher for paren expressions.Aaron Ballman2016-01-202-0/+14
| | | | | | Patch by Adrian Zgorzałek. llvm-svn: 258321
* The destructor name should be matched to ~Foo instead of Foo.Aaron Ballman2016-01-181-3/+3
| | | | llvm-svn: 258077
* Add an AST matcher for checking whether a function is defaulted.Aaron Ballman2016-01-181-0/+7
| | | | | | Patch by Jonathan Coe. llvm-svn: 258072
* Augments r258042; changes the AST matcher tests to use matchesNot and ↵Aaron Ballman2016-01-181-2/+14
| | | | | | EXPECT_TRUE instead of EXPECT_FALSE. Adds a matcher test to ensure that static member functions are properly handled. Generates the documentation from the matcher. llvm-svn: 258070
* Add forEachArgumentWithParam AST matcher.Manuel Klimek2016-01-181-0/+85
| | | | | | | | | | | | The new matcher allows users to provide a matcher for both the argument of a CallExpr/CxxConstructExpr a well as the ParmVarDecl of the argument. Patch by Felix Berger. Differential Revision: http://reviews.llvm.org/D13845 llvm-svn: 258042
* [ASTMatchers] Add booleanType() matcher.Samuel Benzaquen2015-12-221-0/+7
| | | | llvm-svn: 256278
OpenPOWER on IntegriCloud