aboutsummaryrefslogtreecommitdiff
path: root/unittests/ASTMatchers/ASTMatchersTest.cpp
AgeCommit message (Collapse)Author
2012-09-18Add missing matcher for C-style cast expressions.Daniel Jasper
Patch by Gábor Horváth. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164123 91177308-0d34-0410-b5e6-96231b3b80d8
2012-09-18Make all VariadicDynCast-Expr-matchers StatementMatchersDaniel Jasper
Having Expr-subclass-matchers being VariadicDynCast-Expr-matchers does not provide additional type safety and just makes using them harder. In the clang AST, expressions are always statements and an expression matcher can be used anywhere, a statement matcher is expected. Any given matcher definition still has at least one noun. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164121 91177308-0d34-0410-b5e6-96231b3b80d8
2012-09-13Create initial support for matching and binding NestedNameSpecifier(Loc)s.Daniel Jasper
Review: http://llvm-reviews.chandlerc.com/D39 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163794 91177308-0d34-0410-b5e6-96231b3b80d8
2012-09-12Rename isA to isSameOrDerivedFrom.Daniel Jasper
There are two evils we can choose from: - Name overlap between isA-matcher and llvm::isa<>() - Bad name for what the isA-matcher currently does After some discussion we have agreed to go with the latter evil. Review: http://llvm-reviews.chandlerc.com/D40 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163740 91177308-0d34-0410-b5e6-96231b3b80d8
2012-09-07Change the behavior of the isDerivedFrom-matcher to not match on theDaniel Jasper
class itself. This caused some confusion (intuitively, a class is not derived from itself) and makes it hard to write certain matchers, e.g. "match and bind any pair of base and subclass". The original behavior can be achieved with a new isA-matcher. Similar to all other matchers, this matcher has the same behavior and name as the corresponding AST-entity - in this case the isa<>() function. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163385 91177308-0d34-0410-b5e6-96231b3b80d8
2012-09-07Implements hasAncestor.Manuel Klimek
Implements the hasAncestor matcher. This builds on the previous patch that introduced DynTypedNode to build up a parent map for an additional degree of freedom in the AST traversal. The map is only built once we hit an hasAncestor matcher, in order to not slow down matching for cases where this is not needed. We could implement some speed-ups for special cases, like building up the parent map as we go and only building up the full map if we break out of the already visited part of the tree, but that is probably not going to be worth it, and would make the code significantly more complex. Major TODOs are: - implement hasParent - implement type traversal - implement memoization in hasAncestor git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163382 91177308-0d34-0410-b5e6-96231b3b80d8
2012-09-05Introduces DynTypedMatcher as a new concept that replaces the ↵Manuel Klimek
UntypedBaseMatcher and TypedMatcher. Due to DynTypedNode the basic dynamically typed matcher interface can now be simplified. Also switches the traversal interfaces to use DynTypedNode; this is in preperation for the hasAncestor implementation, and also allows us to need fewer changes when we want to add new nodes to traverse, thus making the code a little more decoupled. Main design concerns: I went back towards the original design of getNodeAs to return a pointer, and switched DynTypedNode::get to always return a pointer (in case of value types like QualType the pointer points into the storage of DynTypedNode, thus allowing us to treat all the nodes the same from the point of view of a user of the DynTypedNodes. Adding the QualType implementation for DynTypedNode was needed for the recursive traversal interface changes. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163212 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-30Fixes a bug for binding memoized match results.Manuel Klimek
Intorduces an abstraction for DynTypedNode which makes is impossible to create in ways that introduced the bug; also hides the implementation details of the template magic away from the user and prepares the code for adding QualType and TypeLoc bindings, as well as using DynTypedNode instead of overloads for child and ancestor matching. getNodeAs<T> was changed towards a non-pointer type, as we'll want QualType and TypeLoc nodes to be returned by value (the alternative would be to create new storage which is prohibitively costly if we want to use it for child / ancestor matching). DynTypedNode is moved into a new header ASTTypeTraits.h, as it is completely independent of the rest of the matcher infrastructure - if the need comes up, we can move it to a more common place. The interface for users before the introduction of the common storage change remains the same, minus the introduced bug, for which a regression test was added. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162936 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-24New matcher for MaterializeTemporaryExprSam Panzer
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162609 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-24Rename the ASTMatchers to better match AST nodes. Now, allDaniel Jasper
ASTMatchers have the same name as the corresponding AST nodes but are lower case. The only exceptions are the "CXX" prefixes which are not copied over to the matcher names as the goal is to actually remove these prefixes from the AST node names. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162536 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-18AST Matchers tests: test that member() matches member allocation functions:Dmitri Gribenko
declare size_t in system-independent way. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162158 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-18AST Matchers tests: test that member() matches member allocation functions.Dmitri Gribenko
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162153 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-17AST Matchers: introduce functionTemplate(), classTemplate() andDmitri Gribenko
isExplicitTemplateSpecialization() matchers which do what their name says. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162115 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-16Matchers related to DeclStmt for matching the count of declarations, a ↵Sam Panzer
particular declaration within the statement, and single-Decl DeclStmts. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162027 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-16Matchers which correspond to CastExpr, IgnoreImpCasts, IgnoreParenCasts, and ↵Sam Panzer
IgnoreParenImpCasts git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162025 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-15Add ASTMatcher for matching extern "C" function declarations.Daniel Jasper
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161974 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-01Add missing tests for class template specialization and templateDaniel Jasper
argument matchers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161102 91177308-0d34-0410-b5e6-96231b3b80d8
2012-07-30Fix for ASTMatchFinder to visit a functions parameter declarations.Daniel Jasper
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160947 91177308-0d34-0410-b5e6-96231b3b80d8
2012-07-25Introduces the 'decl' matcher which was missing for a whileManuel Klimek
and became necessary with the change to require BindableMatchers for binding. Also fixes PR 13445: "hasSourceExpression only works for implicit casts". git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160716 91177308-0d34-0410-b5e6-96231b3b80d8
2012-07-24Introduces a new concept for binding results to matchersManuel Klimek
as per Chandler's request: - introduces a new matcher base type BindableMatcher that provides the bind() call - makes all dynamic-cast matcher creation functions return BindableMatchers; the special case about dynamic-cast matchers is that the node they match on and the node their child matchers match on are the same node, just casted to a different type; thus, there is no ambiguity on what bind() matches on; additionally, those are the matchers that we name with nouns in the matcher language, so it's easy for users to intuitively know which matchers are bindable To make this change possible, we got rid of a non-orthogonal implementation of thisPointerType, which had an implicit dynamic-cast matcher from CallExpr to CXXMemberCallExpr; as alternative, we now provide a memberCall dynamic-cast matcher and thisPointerType is a predicate on CXXMemberCallExpr. Last, the ArgumentAdaptingMatcher is actually not required for the implementation of makeDynCastAllOfComposite - this simplification makes it more obvious where the bind() call can be used based on the matcher creation function types. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160673 91177308-0d34-0410-b5e6-96231b3b80d8
2012-07-17Make the isDerivedFrom matcher more generic.Daniel Jasper
It now accepts an arbitrary inner matcher but is fully backwards compatible. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160348 91177308-0d34-0410-b5e6-96231b3b80d8
2012-07-15Fix spelling of anyOf matcher and add missing test.Daniel Jasper
Patch by Sam Panzer! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160233 91177308-0d34-0410-b5e6-96231b3b80d8
2012-07-12This commit combines three patches to the ASTMatchers.Daniel Jasper
One adds matchers for the various parts of a for loop (initializer, condition, increment), as well as extending the hasBody matcher to work for while and do-while loops. The second patch adds an isInteger matcher for types. The third patch fixes a bug in allOf, where a few of the name chages (AllOf --> allOf) had been missed. All matchers come with unit tests. Patches by Sam Panzer! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160115 91177308-0d34-0410-b5e6-96231b3b80d8
2012-07-10 Add more matchers and do cleanups.Daniel Jasper
Reviewers: klimek Differential Revision: http://ec2-50-18-127-156.us-west-1.compute.amazonaws.com/D2 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160013 91177308-0d34-0410-b5e6-96231b3b80d8
2012-07-10Disable death tests on platforms which don't support them.Benjamin Kramer
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160000 91177308-0d34-0410-b5e6-96231b3b80d8
2012-07-10Fixes the MSVC build.Manuel Klimek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159992 91177308-0d34-0410-b5e6-96231b3b80d8
2012-07-06Adds the AST Matcher library, which provides a in-C++ DSL to expressManuel Klimek
matches on interesting parts of the AST, and callback mechanisms to act on them. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159805 91177308-0d34-0410-b5e6-96231b3b80d8