summaryrefslogtreecommitdiffstats
path: root/clang/lib/ASTMatchers
Commit message (Collapse)AuthorAgeFilesLines
...
* Separate the notion of 'context' when recursing down in the parser and ↵Samuel Benzaquen2013-07-184-59/+98
| | | | | | | | | | | | | | | | | actual errors. Summary: Change how error messages are constructed and stored in Diagnostics. Separate the notion of 'context' when recursing down in the parser and actual errors. This will simplify adding some new features, like argument overloading and error recovery. Reviewers: klimek CC: cfe-commits, revane Differential Revision: http://llvm-reviews.chandlerc.com/D1168 llvm-svn: 186602
* Add TemplateArgument related matchers to the registry.Samuel Benzaquen2013-07-171-4/+2
| | | | | | | | | | | | | | Summary: Continue adding more matchers to the dynamic registry. This time, we add TemplateArgument matchers. Reviewers: klimek CC: cfe-commits, revane Differential Revision: http://llvm-reviews.chandlerc.com/D1166 llvm-svn: 186514
* Add CXXCtorInitializer related matchers to the dynamic matcher registry.Samuel Benzaquen2013-07-171-6/+4
| | | | | | | | | | | | Summary: Now that CXXCtorInitializer is already supported in ASTNodeKind, add CXXCtorInitializer matchers to the dynamic matcher registry. Reviewers: klimek CC: cfe-commits, revane Differential Revision: http://llvm-reviews.chandlerc.com/D1158 llvm-svn: 186508
* Remove unnecessary assignment.Manuel Klimek2013-07-161-1/+0
| | | | llvm-svn: 186412
* Fixes another hard to test problem with iterator invalidation.Manuel Klimek2013-07-161-60/+69
| | | | | | | | | | As every match call can recursively call back into the memoized match via a nested traversal matcher (for example: stmt(hasAncestor(stmt(hasDescendant(stmt(hasDescendant(stmt()))))))), and every memoization step might clear the cache, we must not store iterators into the result cache when calling match on a submatcher. llvm-svn: 186411
* Add support for type traversal matchers.Samuel Benzaquen2013-07-152-30/+20
| | | | | | | | | | | | | | | Summary: Fixup the type traversal macros/matchers to specify the supported types. Make the marshallers a little more generic to support any variadic function. Update the doc script. Reviewers: klimek CC: cfe-commits, revane Differential Revision: http://llvm-reviews.chandlerc.com/D1023 llvm-svn: 186340
* Fix use of invalidated iterator bug in AST match finder.Manuel Klimek2013-07-081-4/+6
| | | | | | | | Pulled out the cache clearing in the case of descendant matching, too, for consistency, also it is not technically needed there. FIXME: Make cache size configurable and add unit test. llvm-svn: 185820
* Add support for polymorphic matchers. Use runtime type checking to determine ↵Samuel Benzaquen2013-06-215-106/+190
| | | | | | the right polymorphic overload to use. llvm-svn: 184558
* Enhancements for the DynTypedMatcher system.Samuel Benzaquen2013-06-204-16/+34
| | | | | | | | | - Added conversion routines and checks in Matcher<T> that take a DynTypedMatcher. - Added type information on the error messages for the marshallers. - Allows future work on Polymorphic/overloaded matchers. We should be able to disambiguate at runtime and choose the appropriate overload. llvm-svn: 184429
* Completely revamp node binding for AST matchers.Manuel Klimek2013-06-192-100/+99
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is in preparation for the backwards references to bound nodes, which will expose a lot more about how matches occur. Main changes: - instead of building the tree of bound nodes, we build a "set" of bound nodes and explode all possible match combinations while running through the matchers; this will allow us to also implement matchers that filter down the current set of matches, like "equalsBoundNode" - take the set of bound nodes at the start of the match into consideration when doing memoization; as part of that, reevaluated that memoization gives us benefits that are large enough (it still does - the effect on common match patterns is up to an order of magnitude) - reset the bound nodes when a node does not match, thus never leaking information from partial sub-matcher matches for failing matchers Effects: - we can now correctly "explode" combinatorial matches, for example: allOf(forEachDescendant(...bind("a")), forEachDescendant(...bind("b"))) will now trigger matches for all combinations of matching "a" and "b"s. - we now never expose bound nodes from partial matches in matchers that did not match in the end - this fixes a long-standing issue FIXMEs: - rename BoundNodesTreeBuilder to BoundNodesBuilder or BoundNodesSetBuilder, as we don't build a tree any more; this is out of scope for this change, though - we're seeing some performance regressions (around 10%), but I expect some performance tuning will get that back, and it's easily worth the increase in expressiveness for now llvm-svn: 184313
* Reduce the number of symbols on the object file.Samuel Benzaquen2013-06-111-43/+80
| | | | | | | | | | | | | | | | | Summary: Some compilers where failing with this file because the number of symbols was above 2**15. - Replace std::list<> and std::vector<> with plain arrays. - Change VariadicMatcherCreateCallback to be a function template, and a single class that wraps the instantiations. - Remove some more unnecessary template arguments and function calls. Reviewers: klimek CC: cfe-commits, revane Differential Revision: http://llvm-reviews.chandlerc.com/D948 llvm-svn: 183768
* Parser/Registry argument enhancements.Samuel Benzaquen2013-06-045-18/+264
| | | | | | | | | | | | | | | Summary: Parser/Registry argument enhancements. - 2 argument support. - unsigned values support. Reviewers: klimek CC: cfe-commits, revane Differential Revision: http://llvm-reviews.chandlerc.com/D915 llvm-svn: 183231
* Add support for .bind("foo") expressions on the dynamic matchers.Samuel Benzaquen2013-06-034-8/+91
| | | | | | | | | | | | Summary: Add support on the parser, registry, and DynTypedMatcher for binding IDs dynamically. Reviewers: klimek CC: cfe-commits, revane Differential Revision: http://llvm-reviews.chandlerc.com/D911 llvm-svn: 183144
* Add an overridable MatchCallback::onEndOfTranslationUnit() function.Peter Collingbourne2013-05-281-0/+10
| | | | | | Differential Revision: http://llvm-reviews.chandlerc.com/D745 llvm-svn: 182798
* Move documentation to the constructor. Fixes a -Wdocumentation warningDmitri Gribenko2013-05-171-4/+3
| | | | llvm-svn: 182134
* Test commitSamuel Benzaquen2013-05-151-3/+3
| | | | llvm-svn: 181915
* Link dynamic ast matchers with the ast matchers library. Unbreaks shared ↵Benjamin Kramer2013-05-141-0/+4
| | | | | | cmake build. llvm-svn: 181783
* First revision of the dynamic ASTMatcher library.Manuel Klimek2013-05-1410-0/+963
| | | | | | | | | | | | | | | | | | | | | | | | | | | This library supports all the features of the compile-time based ASTMatcher library, but allows the user to specify and construct the matchers at runtime. It contains the following modules: - A variant type, to be used by the matcher factory. - A registry, where the matchers are indexed by name and have a factory method with a generic signature. - A simple matcher expression parser, that can be used to convert a matcher expression string into actual matchers that can be used with the AST at runtime. Many features where omitted from this first revision to simplify this code review. The main ideas are still represented in this change and it already has support working use cases. Things that are missing: - Support for polymorphic matchers. These requires supporting code in the registry, the marshallers and the variant type. - Support for numbers, char and bool arguments to the matchers. This requires supporting code in the parser and the variant type. - A command line program putting everything together and providing an already functional tool. Patch by Samuel Benzaquen. llvm-svn: 181768
* Implements memoization for ancestor matching.Manuel Klimek2013-03-141-17/+65
| | | | | | | | | | | 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. llvm-svn: 177081
* First step towards adding a parent map to the ASTContext.Manuel Klimek2013-02-281-85/+6
| | | | | | | | | | | | 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. llvm-svn: 176251
* Re-design the convenience interfaces on MatchFinder.Manuel Klimek2013-02-011-26/+23
| | | | | | | | | | | | 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. llvm-svn: 174172
* Remove useless 'llvm::' qualifier from names like StringRef and others that areDmitri Gribenko2013-01-121-4/+4
| | | | | | brought into 'clang' namespace by clang/Basic/LLVM.h llvm-svn: 172323
* Implements multiple parents in the parent map.Manuel Klimek2012-12-061-23/+48
| | | | | | | Previously we would match the last visited parent, which in the case of template instantiations was the last instantiated template. llvm-svn: 169508
* Fixes crash in isDerivedFrom for recursive templates.Manuel Klimek2012-12-041-1/+6
| | | | llvm-svn: 169262
* Allow matchers to access the ASTContext.Manuel Klimek2012-11-301-0/+3
| | | | | | Patch by Edwin Vane. llvm-svn: 169000
* Fix partial-match-bind-behavior with forEachDescendant() matchers.Daniel Jasper2012-11-161-2/+5
| | | | | | | | | | | | | | | | 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 llvm-svn: 168177
* Make libASTMatchers link its dependencies. libRewriteFrontend depends on ↵Benjamin Kramer2012-11-161-1/+5
| | | | | | | | libRewriteCore. LLVM_USED_LIBS does nothing here. llvm-svn: 168172
* Do not use data recursion in ASTMatchFinder.Daniel Jasper2012-11-151-0/+9
| | | | | | The matchers rely on the complete AST being traversed as shown by the new test cases. llvm-svn: 168022
* Fix AST-matcher descendant visiting for Types, TypeLocs and ↵Daniel Jasper2012-11-131-1/+7
| | | | | | | | NestedNamespecifierLocs. The RecursiveASTVisitor assumes that any given Traverse-method can be called with a NULL-node. So the subclass needs to handle these appropriately. llvm-svn: 167850
* Fix binding of nodes in case of forEach..() matchers.Daniel Jasper2012-11-111-5/+6
| | | | | | | | | | 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 llvm-svn: 167695
* Insert interception point onStartOfTranslationUnit.Manuel Klimek2012-11-021-0/+10
| | | | | | | | | 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. llvm-svn: 167271
* Implement descendant matchers for NestedNamespecifiersDaniel Jasper2012-10-301-0/+23
| | | | | | | | | This implements has(), hasDescendant(), forEach() and forEachDescendant() for NestedNameSpecifier and NestedNameSpecifierLoc matchers. Review: http://llvm-reviews.chandlerc.com/D86 llvm-svn: 167017
* Implement has(), hasDescendant(), forEach() and forEachDescendant() forDaniel Jasper2012-10-291-28/+57
| | | | | | | Types, QualTypes and TypeLocs. Review: http://llvm-reviews.chandlerc.com/D83 llvm-svn: 166917
* Adds the possibility to run ASTMatchFinder over arbitrary AST nodes.Manuel Klimek2012-10-241-0/+12
| | | | llvm-svn: 166567
* Implement hasParent()-matcher.Daniel Jasper2012-10-221-3/+6
| | | | llvm-svn: 166421
* First version of matchers for Types and TypeLocs.Daniel Jasper2012-10-171-4/+15
| | | | | Review: http://llvm-reviews.chandlerc.com/D47 llvm-svn: 166094
* Fix isDerivedFrom matcher.Daniel Jasper2012-09-181-0/+1
| | | | | | | | | | | | | 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. llvm-svn: 164127
* Create initial support for matching and binding NestedNameSpecifier(Loc)s.Daniel Jasper2012-09-131-0/+29
| | | | | Review: http://llvm-reviews.chandlerc.com/D39 llvm-svn: 163794
* Change the behavior of the isDerivedFrom-matcher to not match on theDaniel Jasper2012-09-071-6/+6
| | | | | | | | | | | | 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. llvm-svn: 163385
* Implements hasAncestor.Manuel Klimek2012-09-071-0/+87
| | | | | | | | | | | | | | | | | | | | | | 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 llvm-svn: 163382
* Introduces DynTypedMatcher as a new concept that replaces the ↵Manuel Klimek2012-09-051-67/+65
| | | | | | | | | | | | | | | | | | | | | | | 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. llvm-svn: 163212
* Fixes a bug for binding memoized match results.Manuel Klimek2012-08-301-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | 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. llvm-svn: 162936
* Modifes BoundNodes to store void* and allow casting themManuel Klimek2012-08-281-42/+24
| | | | | | | | | | | | | 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. llvm-svn: 162804
* Fix for ASTMatchFinder to visit a functions parameter declarations.Daniel Jasper2012-07-301-1/+2
| | | | llvm-svn: 160947
* Move RefactoringCallbacks to Tooling to avoid dependency fromDaniel Jasper2012-07-172-79/+0
| | | | | | | ASTMatchers (lower level abstraction) to Tooling (higher level abstraction). llvm-svn: 160351
* Make the isDerivedFrom matcher more generic.Daniel Jasper2012-07-171-37/+27
| | | | | | | It now accepts an arbitrary inner matcher but is fully backwards compatible. llvm-svn: 160348
* Add refactoring callbacks to make common kinds of refactorings easy.Daniel Jasper2012-07-162-0/+79
| | | | llvm-svn: 160255
* Add more matchers and do cleanups.Daniel Jasper2012-07-102-73/+73
| | | | | | | | Reviewers: klimek Differential Revision: http://ec2-50-18-127-156.us-west-1.compute.amazonaws.com/D2 llvm-svn: 160013
* [CMake] Get rid of unconditional dependency to ClangDiagnosticCommon. Only ↵NAKAMURA Takumi2012-07-091-0/+1
| | | | | | clangBasic and clangASTMatchers need it. llvm-svn: 159931
* ASTMatchers/CMakeLists.txt: Add dependencies to generated headers, or "make ↵NAKAMURA Takumi2012-07-071-0/+9
| | | | | | clean; make ASTMatchers" would fail. llvm-svn: 159906
OpenPOWER on IntegriCloud