Commit Graph

131 Commits

Author SHA1 Message Date
Peter Collingbourne 00cba4f6dd Split registry matcher resolution into a lookup phase and a construction phase.
The looked-up matchers will be used during code completion.

Differential Revision: http://llvm-reviews.chandlerc.com/D2207

llvm-svn: 195534
2013-11-23 01:13:16 +00:00
Samuel Benzaquen ef77f3cca7 Make the negative test more specific.
Summary:
Make the negative test more specific.
Otherwise it can accidentally match injected code.

Reviewers: aaron.ballman

CC: klimek, cfe-commits, revane

Differential Revision: http://llvm-reviews.chandlerc.com/D2257

llvm-svn: 195512
2013-11-22 23:05:57 +00:00
Samuel Benzaquen 4d05874ba2 Add support for the 'unless' matcher in the dynamic layer.
Summary: Add support for the 'unless' matcher in the dynamic layer.

Reviewers: klimek

CC: cfe-commits, revane, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D2247

llvm-svn: 195466
2013-11-22 14:41:48 +00:00
Samuel Benzaquen 464c1cbc3f Add partial support for the hasDeclaration() matcher in the dynamic layer.
Summary:
Add partial support for the hasDeclaration() matcher in the dynamic layer.
This matcher has some special logic to allow any type that has a getDecl() method.  We do not support this right now.

Reviewers: klimek

CC: cfe-commits, revane

Differential Revision: http://llvm-reviews.chandlerc.com/D1889

llvm-svn: 195013
2013-11-18 14:53:42 +00:00
Peter Collingbourne a2334162cf Introduce MatchFinder::matchAST.
Differential Revision: http://llvm-reviews.chandlerc.com/D2115

llvm-svn: 194223
2013-11-07 22:30:36 +00:00
Peter Collingbourne 2b94713053 Re-introduce MatchFinder::addDynamicMatcher.
Differential Revision: http://llvm-reviews.chandlerc.com/D2114

llvm-svn: 194222
2013-11-07 22:30:32 +00:00
Peter Collingbourne 093a729e03 Introduce BoundNodes::getMap.
The purpose of this function is to allow clients of the dynamic AST matcher
to enumerate each binding.

Differential Revision: http://llvm-reviews.chandlerc.com/D2095

llvm-svn: 194112
2013-11-06 00:27:07 +00:00
Samuel Benzaquen f34ac3ed2c Resubmit "Refactor DynTypedMatcher into a value type class, just like 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
2013-10-29 14:37:15 +00:00
Reid Kleckner 9171f02528 Revert "Refactor DynTypedMatcher into a value type class, just like Matcher<T>."
This reverts commit r193100.

It was failing to compile with MSVC 2012 while instantiating
llvm::Optional<DynTypedMatcher>.

llvm-svn: 193123
2013-10-21 22:26:36 +00:00
Samuel Benzaquen f46e5f1c9a Refactor DynTypedMatcher into a value type class, just like Matcher<T>.
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
2013-10-21 18:40:51 +00:00
Michael Han c90d12d1df Teach RAV to visit parameter variable declarations of implicit functions. Fixes PR16182.
Normally RAV visits parameter variable declarations of a function by traversing the TypeLoc of
the parameter declarations. However, for implicit functions, their parameters don't have any
TypeLoc, because they are implicit.

So for implicit functions, we visit their parameter variable declarations by traversing them through
the function declaration, and visit them accordingly.

Reviewed by Richard Smith and Manuel Klimek.

llvm-svn: 190528
2013-09-11 15:53:29 +00:00
Samuel Benzaquen 998cda23b9 Reduce the number of symbols by changing how templates are instantiated per function bound in the registry.
Summary:
Reduce the number of symbols by changing how templates are instantiated per function bound in the registry.
This change reduces the number of sections in Registry.cpp.o by a little over 10%.

Reviewers: klimek

CC: cfe-commits, revane

Differential Revision: http://llvm-reviews.chandlerc.com/D1557

llvm-svn: 189676
2013-08-30 15:09:52 +00:00
Samuel Benzaquen 68cd396f82 Fix tests to be more specific.
The environments can inject some declaration in every translation unit,
which can match very generic matchers, thus failing the tests.

Summary:
Fix tests to be more specific.
The environments can inject some declaration in every translation unit,
which can match very generic matchers, thus failing the tests.

Reviewers: aaron.ballman

CC: klimek, cfe-commits, revane

Differential Revision: http://llvm-reviews.chandlerc.com/D1541

llvm-svn: 189587
2013-08-29 15:39:26 +00:00
Samuel Benzaquen 4adca6262e Add support for eachOf/allOf/anyOf variadic matchers in the dynamic layer.
Summary:
Add support for eachOf/allOf/anyOf variadic matchers in the dynamic layer.
These function require some late binding behavior for the type conversions, thus changes in VariadicValue's MatcherList.
Second try. This time with a fix for C++11 builds.

Reviewers: klimek

CC: cfe-commits, revane

Differential Revision: http://llvm-reviews.chandlerc.com/D1536

llvm-svn: 189500
2013-08-28 18:42:04 +00:00
Samuel Benzaquen 46e59b05eb Revert "Add support for eachOf/allOf/anyOf variadic matchers in the dynamic layer."
Summary:
This reverts commit 3b082a3c72324aa3363b5184731740534c6b9a2b.

It breaks the build in c++11 mode.

Reviewers: klimek

CC: cfe-commits, revane

Differential Revision: http://llvm-reviews.chandlerc.com/D1533

llvm-svn: 189368
2013-08-27 16:55:22 +00:00
Samuel Benzaquen fe48aaf1a4 Add support for eachOf/allOf/anyOf variadic matchers in the dynamic layer.
Summary:
Add support for eachOf/allOf/anyOf variadic matchers in the dynamic layer.
These function require some late binding behavior for the type conversions, thus changes in VariadicValue's MatcherList.

Reviewers: klimek

CC: cfe-commits, revane

Differential Revision: http://llvm-reviews.chandlerc.com/D1531

llvm-svn: 189362
2013-08-27 16:04:53 +00:00
Samuel Benzaquen 0239b69167 Refactor "MatcherList" into "VariantMatcher" and abstract the notion of a list of matchers for the polymorphic case.
Summary:
Refactor "MatcherList" into "VariantMatcher" and abstract the notion of a list of matchers for the polymorphic case.
This work is to support future changes needed for eachOf/allOf/anyOf matchers. We will add a new type on VariantMatcher.

Reviewers: klimek

CC: cfe-commits, revane

Differential Revision: http://llvm-reviews.chandlerc.com/D1365

llvm-svn: 188272
2013-08-13 14:54:51 +00:00
Manuel Klimek 1863e505ce Fix crash when encountering alias templates in isDerivedFrom matches.
- 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
2013-08-02 21:24:09 +00:00
Daniel Jasper 91f1c8ca27 Add matcher for float literals.
Patch by Chris Gray! Thanks!

llvm-svn: 187232
2013-07-26 18:52:58 +00:00
Samuel Benzaquen 7f8a5b140a Add support for Adaptative matchers on the dynamic registry.
Summary:
Add support for Adaptative matchers on the dynamic registry.
Each adaptative matcher is created with a function template. We instantiate the function N times, one for each possible From type and apply the techniques used on argument overloaded and polymorphic matchers to add them to the registry.

Reviewers: klimek

CC: cfe-commits, revane

Differential Revision: http://llvm-reviews.chandlerc.com/D1201

llvm-svn: 187044
2013-07-24 14:48:01 +00:00
Samuel Benzaquen e0b2c8e478 Add support for overloaded matchers. ie different matcher function signatures with the same name.
Summary:
Add support for overloaded matchers.
This composes with other features, like supporting polymorphic matchers.

Reviewers: klimek

CC: cfe-commits, revane

Differential Revision: http://llvm-reviews.chandlerc.com/D1188

llvm-svn: 186836
2013-07-22 16:13:57 +00:00
Samuel Benzaquen b837248ad4 Add support for raw_ostream on the printing methods of Diagnostics.
Summary:
Add printToStream*(llvm::raw_ostream&) methods to Diagnostics, and reimplement everything based on streams instead of concatenating strings.
Also, fix some functions to start with lowercase to match the style guide.

Reviewers: klimek

CC: cfe-commits, revane

Differential Revision: http://llvm-reviews.chandlerc.com/D1187

llvm-svn: 186715
2013-07-19 20:02:35 +00:00
Manuel Klimek ba46fc01a8 Adds ctorInitializer and forEachConstructorInitializer matchers.
llvm-svn: 186668
2013-07-19 11:50:54 +00:00
Samuel Benzaquen 21b3da0f93 Add TemplateArgument related matchers to the registry.
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
2013-07-17 15:11:30 +00:00
Samuel Benzaquen 06e056c4d8 Add CXXCtorInitializer related matchers to the dynamic matcher registry.
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
2013-07-17 14:28:00 +00:00
Samuel Benzaquen 79656e19c8 Add support for type traversal matchers.
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
2013-07-15 19:25:06 +00:00
NAKAMURA Takumi 1d7bdb171a clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp: Suppress unexpected failures on MS hosts.
FIXME: A couple of tests have been suppressed.
I know it'd be bad with _MSC_VER here, though.

llvm-svn: 184727
2013-06-24 13:19:26 +00:00
Samuel Benzaquen c6f2c9b566 Add support for polymorphic matchers. Use runtime type checking to determine the right polymorphic overload to use.
llvm-svn: 184558
2013-06-21 15:51:31 +00:00
Reid Kleckner f9794c15e7 Disable an assertion death test when using MSVC's assert()
MSVC's debug runtime prints assertion failures in wide characters, which
gtest doesn't understand.

llvm-svn: 184544
2013-06-21 12:58:12 +00:00
Samuel Benzaquen 81ef929b8f Enhancements for the DynTypedMatcher system.
- 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
2013-06-20 14:28:32 +00:00
Manuel Klimek bbb758577f Adds the equalsBoundNode matcher.
Most of the tests contributed by Edwin Vane.

llvm-svn: 184427
2013-06-20 14:06:32 +00:00
Manuel Klimek c16c652ca5 Implements declaratorDecl, parmVarDecl and hassTypeLoc matchers.
llvm-svn: 184419
2013-06-20 13:08:29 +00:00
Manuel Klimek a0c025f5d2 Completely revamp node binding for AST matchers.
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
2013-06-19 15:42:45 +00:00
Reid Kleckner 898229ab4b [Driver] Refactor clang driver to use LLVM's Option library
The big changes are:
- Deleting Driver/(Arg|Opt)*
- Rewriting includes to llvm/Option/ and re-sorting
- 'using namespace llvm::opt' in clang::driver
- Fixing the autoconf build by adding option everywhere

As discussed in the review, this change includes using directives in
header files.  I'll make follow up changes to remove those in favor of
name specifiers.

Reviewers: espindola

Differential Revision: http://llvm-reviews.chandlerc.com/D975

llvm-svn: 183989
2013-06-14 17:17:23 +00:00
Samuel Benzaquen c31b3524cb Parser/Registry argument enhancements.
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
2013-06-04 15:46:22 +00:00
Samuel Benzaquen 31edb51a4f Add support for .bind("foo") expressions on the dynamic matchers.
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
2013-06-03 19:31:08 +00:00
Peter Collingbourne 6a55bb2307 Add an overridable MatchCallback::onEndOfTranslationUnit() function.
Differential Revision: http://llvm-reviews.chandlerc.com/D745

llvm-svn: 182798
2013-05-28 19:21:51 +00:00
Benjamin Kramer 324bf7a159 Take a stab at trying to unbreak the makefile build.
There is no clangRewrite.a.

llvm-svn: 181781
2013-05-14 12:21:21 +00:00
Manuel Klimek cf0a230477 Hopefully fix configure build.
llvm-svn: 181780
2013-05-14 11:59:20 +00:00
Manuel Klimek 24db0f0afd First revision of the dynamic ASTMatcher library.
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
2013-05-14 09:13:00 +00:00
Peter Collingbourne 3154a10bcb Add caseStmt(), defaultStmt(), eachCase() and hasCaseConstant() matchers.
Differential Revision: http://llvm-reviews.chandlerc.com/D744

llvm-svn: 181588
2013-05-10 11:52:02 +00:00
Edwin Vane fc4f7dc0a6 Adding isConst() ASTMatcher for CXXMethodDecl nodes
Updated reference and unit tests.

llvm-svn: 181522
2013-05-09 17:00:17 +00:00
Richard Smith 061f1e21be When deducing an 'auto' type, don't modify the type-as-written.
llvm-svn: 180808
2013-04-30 21:23:01 +00:00
Edwin Vane 37ee1d7b80 Adding new AST Matchers isVirtual and isOverride
isVirtual - matches CXXMethodDecl nodes for virtual methods
isOverride - matches CXXMethodDecl nodes for methods that override virtual methods from a base class.

Author: Philip Dunstan <phil@philipdunstan.com>
llvm-svn: 179126
2013-04-09 20:46:36 +00:00
Daniel Jasper 9fcdc461ed Add matcher for NamespaceDecls.
llvm-svn: 179027
2013-04-08 16:44:05 +00:00
Edwin Vane 119d3dfcba Adding a hasLocalQualifiers() AST Matcher.
Updated tests and docs.

llvm-svn: 178556
2013-04-02 18:15:55 +00:00
Edwin Vane ec0748068e Adding parenType() and innerType() AST Matchers
Updated docs and tests.

llvm-svn: 178487
2013-04-01 18:33:34 +00:00
Manuel Klimek b64d6b7fee Implements memoization for ancestor matching.
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
2013-03-14 16:33:21 +00:00
Edwin Vane 2a760d02f7 Adding lvalue and rvalue reference type matchers
Updated docs and tests.
    
Reviewers: klimek, gribozavr

llvm-svn: 176630
2013-03-07 15:44:40 +00:00
Edwin Vane 0a4836ed0e New ASTMatchers and enhancement to hasOverloadedOperatorName
Added two new narrowing matchers:
* hasMethod: aplies a matcher to a CXXRecordDecl's methods until a match is made
  or there are no more methods.
* hasCanonicalType: applies a matcher to a QualType's canonicalType.

Enhanced hasOverloadedOperatorName to work on CXXMethodDecl as well as
CXXOperatorCallExpr.

Updated tests and docs.

Reviewers: klimek, gribozavr
llvm-svn: 176556
2013-03-06 17:02:57 +00:00