summaryrefslogtreecommitdiffstats
path: root/clang/lib/ASTMatchers/ASTMatchFinder.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Speed up clang-tidy when profiling in on.Samuel Benzaquen2014-10-271-15/+31
| | | | | | | | | | | | | | | | Summary: Speed up clang-tidy when profiling in on. It makes profiling runs twice as fast by reusing the time samples between the different actions. It also joins together the sampling of different matchers of the same check. Reviewers: alexfh Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D5972 llvm-svn: 220682
* Add support for profiling the matchers used.Samuel Benzaquen2014-10-221-7/+52
| | | | | | | | | | | | | | | Summary: Add support for profiling the matchers used. This will be connected with clang-tidy to generate a report to determine and debug slow checks. Reviewers: alexfh Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D5911 llvm-svn: 220418
* Return a reference instead of vector copy for parentmap queries.Benjamin Kramer2014-10-041-26/+24
| | | | | | | The map is immutable until the whole ASTContext dies. While there movify a couple of copies in ASTMatchFinder away. NFC. llvm-svn: 219062
* Refactor Matcher<T> and DynTypedMatcher to reduce overhead of casts.Samuel Benzaquen2014-10-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This change introduces DynMatcherInterface and changes the internal representation of DynTypedMatcher and Matcher<T> to use a generic interface instead. It removes unnecessary indirections and virtual function calls when converting matchers by implicit and dynamic casts. DynTypedMatcher now remembers the stricter type in the chain of casts and checks it before calling into DynMatcherInterface. This change improves our clang-tidy related benchmark by ~14%. Also, it opens the door for more optimizations of this kind that are coming in future changes. As a side effect of removing these template instantiations, it also speeds up compilation of Dynamic/Registry.cpp by ~17% and reduces the number of symbols generated by ~30%. Reviewers: klimek Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D5542 llvm-svn: 218769
* Revert r218616, "Refactor Matcher<T> and DynTypedMatcher to reduce overhead ↵NAKAMURA Takumi2014-09-291-1/+1
| | | | | | | | | | | | of casts." MSC17, aka VS2012, cannot compile it. clang/include/clang/ASTMatchers/ASTMatchersInternal.h(387) : error C4519: default template arguments are only allowed on a class template clang/include/clang/ASTMatchers/ASTMatchersInternal.h(443) : see reference to class template instantiation 'clang::ast_matchers::internal::Matcher<T>' being compiled llvm-svn: 218648
* Refactor Matcher<T> and DynTypedMatcher to reduce overhead of casts.Samuel Benzaquen2014-09-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This change introduces DynMatcherInterface and changes the internal representation of DynTypedMatcher and Matcher<T> to use a generic interface instead. It removes unnecessary indirections and virtual function calls when converting matchers by implicit and dynamic casts. DynTypedMatcher now remembers the stricter type in the chain of casts and checks it before calling into DynMatcherInterface. This change improves our clang-tidy related benchmark by ~14%. Also, it opens the door for more optimizations of this kind that are coming in future changes. As a side effect of removing these template instantiations, it also speeds up compilation of Dynamic/Registry.cpp by ~17% and reduces the number of symbols generated by ~30%. Reviewers: klimek Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D5485 llvm-svn: 218616
* Separate the matchers by type and statically dispatch to the right list.Samuel Benzaquen2014-09-051-40/+72
| | | | | | | | | | | | | | | | | Summary: Separate the matchers by type and statically dispatch to the right list. For any node type that we support, it reduces the number of matchers we run it through. For node types we do not support, it makes match() a noop. This change improves our clang-tidy related benchmark by ~30%. Reviewers: klimek Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D5197 llvm-svn: 217274
* Don't create a null reference to NestedNameSpecifier.Alexey Samsonov2014-08-281-1/+2
| | | | | | This bug was reported by UBSan. llvm-svn: 216691
* Recommit 213307: unique_ptr-ify ownership of ASTConsumers (reverted in r213325)David Blaikie2014-08-101-2/+2
| | | | | | | | After post-commit review and community discussion, this seems like a reasonable direction to continue, making ownership semantics explicit in the source using the type system. llvm-svn: 215323
* Prevent assert in ASTMatchFinder.Daniel Jasper2014-07-231-1/+1
| | | | | | | | | | | | If nodes without memoization data (e.g. TypeLocs) are bound to specific names, that effectively prevents memoization as those elements cannot be compared effectively. If it is tried anyway, this can lead to an assert as demonstrated in the new test. In the long term, the better solution will be to enable DynTypedNodes without memoization data. For now, simply skip memoization instead. llvm-svn: 213751
* Revert "unique_ptr-ify ownership of ASTConsumers"David Blaikie2014-07-171-2/+2
| | | | | | | | | This reverts commit r213307. Reverting to have some on-list discussion/confirmation about the ongoing direction of smart pointer usage in the LLVM project. llvm-svn: 213325
* unique_ptr-ify ownership of ASTConsumersDavid Blaikie2014-07-171-2/+2
| | | | | | | | | (after fixing a bug in MultiplexConsumer I noticed the ownership of the nested consumers was implemented with raw pointers - so this fixes that... and follows the source back to its origin pushing unique_ptr ownership up through there too) llvm-svn: 213307
* [C++11] Use 'nullptr'. ASTMatchers edition.Craig Topper2014-05-171-17/+17
| | | | llvm-svn: 209070
* Remove unused typedef as pointed out by a GCC warning.Benjamin Kramer2014-03-141-1/+0
| | | | | | Yay for auto. llvm-svn: 203912
* [C++11] Replacing CXXRecordDecl iterators bases_begin() and bases_end() with ↵Aaron Ballman2014-03-131-4/+2
| | | | | | iterator_range bases(). Updating all of the usages of the iterators with range-based for loops. llvm-svn: 203803
* [C++11] Add 'override' keyword to virtual methods that override their base ↵Craig Topper2014-03-131-19/+19
| | | | | | class. llvm-svn: 203769
* [C++11] Simplify compare operators with std::tie.Benjamin Kramer2014-03-031-5/+2
| | | | | | No functionality change. llvm-svn: 202755
* [C++11] ASTMatchers: Use standard static_assert and type traits.Benjamin Kramer2014-03-021-2/+2
| | | | llvm-svn: 202653
* Introduce MatchFinder::matchAST.Peter Collingbourne2013-11-071-12/+14
| | | | | | Differential Revision: http://llvm-reviews.chandlerc.com/D2115 llvm-svn: 194223
* Re-introduce MatchFinder::addDynamicMatcher.Peter Collingbourne2013-11-071-0/+24
| | | | | | Differential Revision: http://llvm-reviews.chandlerc.com/D2114 llvm-svn: 194222
* Resubmit "Refactor DynTypedMatcher into a value type class, just like ↵Samuel Benzaquen2013-10-291-42/+30
| | | | | | | | | | | | | | Matcher<T>." Summary: This resubmits r193100, plus a fix for a breakage with MSVC. Reviewers: klimek, rnk CC: cfe-commits, revane Differential Revision: http://llvm-reviews.chandlerc.com/D2005 llvm-svn: 193613
* Revert "Refactor DynTypedMatcher into a value type class, just like Matcher<T>."Reid Kleckner2013-10-211-30/+42
| | | | | | | | | This reverts commit r193100. It was failing to compile with MSVC 2012 while instantiating llvm::Optional<DynTypedMatcher>. llvm-svn: 193123
* Refactor DynTypedMatcher into a value type class, just like Matcher<T>.Samuel Benzaquen2013-10-211-42/+30
| | | | | | | | | | | | | | | | Summary: Refactor DynTypedMatcher into a value type class, just like Matcher<T>. This simplifies its usage and removes the virtual hierarchy from Matcher<T>. It also enables planned changes to replace MatcherInteface<T>. Too many instantiaions of this class hierarchy has been causing Registry.cpp.o to bloat in size and number of symbols. Reviewers: klimek CC: cfe-commits, revane Differential Revision: http://llvm-reviews.chandlerc.com/D1661 llvm-svn: 193100
* Fix crash when encountering alias templates in isDerivedFrom matches.Manuel Klimek2013-08-021-43/+51
| | | | | | | | | - pull out function to drill to the CXXRecordDecl from the type, to allow recursive resolution - make the analysis more robust by rather skipping values we don't understand llvm-svn: 187676
* Use memoization for has()-matcher.Daniel Jasper2013-07-251-2/+4
| | | | | | | | | | | In TUs with large classes, a matcher like methodDecl(ofClass(recordDecl(has(varDecl())))) (finding all member functions of classes with static variables) becomes unbearably slow otherwise. llvm-svn: 187115
* 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
* 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
* Enhancements for the DynTypedMatcher system.Samuel Benzaquen2013-06-201-8/+0
| | | | | | | | | - 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-191-42/+91
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Add an overridable MatchCallback::onEndOfTranslationUnit() function.Peter Collingbourne2013-05-281-0/+10
| | | | | | Differential Revision: http://llvm-reviews.chandlerc.com/D745 llvm-svn: 182798
* First revision of the dynamic ASTMatcher library.Manuel Klimek2013-05-141-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* 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
* 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
OpenPOWER on IntegriCloud