aboutsummaryrefslogtreecommitdiff
path: root/lib/ASTMatchers
AgeCommit message (Collapse)Author
2013-03-14Implements memoization for ancestor matching.Manuel Klimek
This yields a log(#ast_nodes) worst-case improvement with matchers like stmt(unless(hasAncestor(...))). Also made the order of visitation for ancestor matches BFS, as the most common use cases (for example finding the closest enclosing function definition) rely on that. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177081 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-28First step towards adding a parent map to the ASTContext.Manuel Klimek
This does not yet implement the LimitNode approach discussed. The impact of this is an O(n) in the number of nodes in the AST reduction of complexity for certain kinds of matchers (as otherwise the parent map gets recreated for every new MatchFinder). See FIXMEs in the comments for the direction of future work. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176251 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-01Re-design the convenience interfaces on MatchFinder.Manuel Klimek
First, this implements a match() method on MatchFinder; this allows us to get rid of the findAll implementation, as findAll is really a special case of recursive matchers on match. Instead of findAll, provide a convenience function match() that lets users iterate easily over the results instead of needing to implement callbacks. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174172 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-12Remove useless 'llvm::' qualifier from names like StringRef and others that areDmitri Gribenko
brought into 'clang' namespace by clang/Basic/LLVM.h git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172323 91177308-0d34-0410-b5e6-96231b3b80d8
2012-12-06Implements multiple parents in the parent map.Manuel Klimek
Previously we would match the last visited parent, which in the case of template instantiations was the last instantiated template. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169508 91177308-0d34-0410-b5e6-96231b3b80d8
2012-12-04Fixes crash in isDerivedFrom for recursive templates.Manuel Klimek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169262 91177308-0d34-0410-b5e6-96231b3b80d8
2012-11-30Allow matchers to access the ASTContext.Manuel Klimek
Patch by Edwin Vane. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169000 91177308-0d34-0410-b5e6-96231b3b80d8
2012-11-16Fix partial-match-bind-behavior with forEachDescendant() matchers.Daniel Jasper
The problem is that a partial match of an (explicit or implicit) allOf matcher binds results, i.e. recordDecl(decl().bind("x"), hasName("A")) can very well bind a record that is not named "A". With this fix, the common cases of stumbling over this bug are fixed by the BoundNodesMap overwriting the results of a partial match. An error can still be created with a weird combination of anyOf and allOf (see inactive test). We need to decide whether this is worth fixing, as the fix will have performance impact. Review: http://llvm-reviews.chandlerc.com/D124 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168177 91177308-0d34-0410-b5e6-96231b3b80d8
2012-11-16Make libASTMatchers link its dependencies. libRewriteFrontend depends on ↵Benjamin Kramer
libRewriteCore. LLVM_USED_LIBS does nothing here. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168172 91177308-0d34-0410-b5e6-96231b3b80d8
2012-11-15Do not use data recursion in ASTMatchFinder.Daniel Jasper
The matchers rely on the complete AST being traversed as shown by the new test cases. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168022 91177308-0d34-0410-b5e6-96231b3b80d8
2012-11-13Fix AST-matcher descendant visiting for Types, TypeLocs and ↵Daniel Jasper
NestedNamespecifierLocs. The RecursiveASTVisitor assumes that any given Traverse-method can be called with a NULL-node. So the subclass needs to handle these appropriately. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167850 91177308-0d34-0410-b5e6-96231b3b80d8
2012-11-11Fix binding of nodes in case of forEach..() matchers.Daniel Jasper
When recursively visiting the generated matches, the aggregated bindings need to be copied during the recursion. Otherwise, we they might not be properly overwritten (which is shown by the test), or there might be bound nodes present that were bound on a different matching branch. Review: http://llvm-reviews.chandlerc.com/D112 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167695 91177308-0d34-0410-b5e6-96231b3b80d8
2012-11-02Insert interception point onStartOfTranslationUnit.Manuel Klimek
Often users of the ASTMatchers want to add tasks that are done once per translation unit, for example, cleaning up caches. Combined with the interception point for the end of source file one can add to the factory creation, this covers the cases we've seen users need. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167271 91177308-0d34-0410-b5e6-96231b3b80d8
2012-10-30Implement descendant matchers for NestedNamespecifiersDaniel Jasper
This implements has(), hasDescendant(), forEach() and forEachDescendant() for NestedNameSpecifier and NestedNameSpecifierLoc matchers. Review: http://llvm-reviews.chandlerc.com/D86 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167017 91177308-0d34-0410-b5e6-96231b3b80d8
2012-10-29Implement has(), hasDescendant(), forEach() and forEachDescendant() forDaniel Jasper
Types, QualTypes and TypeLocs. Review: http://llvm-reviews.chandlerc.com/D83 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166917 91177308-0d34-0410-b5e6-96231b3b80d8
2012-10-24Adds the possibility to run ASTMatchFinder over arbitrary AST nodes.Manuel Klimek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166567 91177308-0d34-0410-b5e6-96231b3b80d8
2012-10-22Implement hasParent()-matcher.Daniel Jasper
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166421 91177308-0d34-0410-b5e6-96231b3b80d8
2012-10-17First version of matchers for Types and TypeLocs.Daniel Jasper
Review: http://llvm-reviews.chandlerc.com/D47 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166094 91177308-0d34-0410-b5e6-96231b3b80d8
2012-09-18Fix isDerivedFrom matcher.Daniel Jasper
Without this patch, the isDerivedFrom matcher asserts in the "assert(ClassDecl != NULL);" in the new test, as a DependentTemplateSpecilizationType is not a sub-type of TemplateSpecializationType and also does not offer getAsCXXRecordDecl(). I am not sure why this did not cause problems before. It is now (after the changed implementation of isDerivedFrom) easier to write a matcher that actually gets into this branch of the code. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164127 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-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-28Modifes BoundNodes to store void* and allow casting themManuel Klimek
into the correct types when pulling them out in the result callback in a type safe way. This is also the base change for multiple things that will allow handling things more generally and thus supporting more of the AST, especially handling Type nodes. Patch contributed by Michael Diamond. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162804 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-17Move RefactoringCallbacks to Tooling to avoid dependency fromDaniel Jasper
ASTMatchers (lower level abstraction) to Tooling (higher level abstraction). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160351 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-16Add refactoring callbacks to make common kinds of refactorings easy.Daniel Jasper
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160255 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-09[CMake] Get rid of unconditional dependency to ClangDiagnosticCommon. Only ↵NAKAMURA Takumi
clangBasic and clangASTMatchers need it. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159931 91177308-0d34-0410-b5e6-96231b3b80d8
2012-07-07ASTMatchers/CMakeLists.txt: Add dependencies to generated headers, or "make ↵NAKAMURA Takumi
clean; make ASTMatchers" would fail. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159906 91177308-0d34-0410-b5e6-96231b3b80d8
2012-07-06Build-fix: Remove non-existent directories from Makefiles.Manuel Klimek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159807 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