Commit Graph

248 Commits

Author SHA1 Message Date
Daniel Jasper 88de3d7284 Add some overloads so that floating point literals can be AST matched properly.
I am not entirely sure whether the implemented sematics are ideal. In
particular, should floatLiteral(equals(0.5)) match "0.5f" and should
floatLiteral(equals(0.5f)) match "0.5". With the overloads in this
patch, the answer to both questions is yes, but I am happy to change
that.

llvm-svn: 227892
2015-02-02 23:04:00 +00:00
Samuel Benzaquen b405c08bdb Add voidType() matcher.
Summary: Add voidType() matcher.

Reviewers: klimek

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D6656

llvm-svn: 224250
2014-12-15 15:09:22 +00:00
Manuel Klimek d3aa1f4a63 Re-apply r222646 (was reverted in r222667). Adding 4 ASTMatchers: typedefDecl, isInMainFile, isInSystemFile, isInFileMatchingName
Change to original: ifndef out tests in Windows due to /-separated
paths.

Summary:
Often one is only interested in matches within the main-file or matches
that are not within a system-header, for which this patch adds
isInMainFile and isInSystemFile. They take no arguments and narrow down
the matches.

The isInFileMatchingName is mainly thought for interactive
clang-query-sessions, to make a matcher more specific without restarting
the session with the files you are interested in for that moment. It
takes a string that will be used as regular-expression to match the
filename of where the matched node is expanded.

Patch by Hendrik von Prince.

llvm-svn: 222765
2014-11-25 17:01:06 +00:00
Aaron Ballman 6265102c17 Reverting r222646; the tests do not pass on Windows. Also reverts r222664, which was required for r222646 to compile with Visual Studio 2012.
llvm-svn: 222667
2014-11-24 17:39:44 +00:00
Aaron Ballman 54891e047f Unbreaking the MSVC 2012 build; however, these tests still fail on Windows.
llvm-svn: 222664
2014-11-24 17:22:32 +00:00
Manuel Klimek da50ff8e4a Adding 4 ASTMatchers: typedefDecl, isInMainFile, isInSystemFile, isInFileMatchingName
Summary:
Often one is only interested in matches within the main-file or matches
that are not within a system-header, for which this patch adds
isInMainFile and isInSystemFile. They take no arguments and narrow down
the matches.

The isInFileMatchingName is mainly thought for interactive
clang-query-sessions, to make a matcher more specific without restarting
the session with the files you are interested in for that moment. It
takes a string that will be used as regular-expression to match the
filename of where the matched node is expanded.

Patch by Hendrik von Prince.

llvm-svn: 222646
2014-11-24 09:10:56 +00:00
Samuel Benzaquen c640ef5634 Add valueDecl() matcher.
Summary: Add valueDecl() matcher.

Reviewers: klimek

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D6005

llvm-svn: 220776
2014-10-28 13:33:58 +00:00
Samuel Benzaquen d93fcc1b28 Fix segfault in hasDeclContext for nodes that have no decl context.
Summary:
Some declarations do not have a declaration context, like TranslationUnitDecl.
Fix hasDeclContext() to not segfault on these nodes.

Reviewers: klimek

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D6003

llvm-svn: 220719
2014-10-27 20:58:44 +00:00
Samuel Benzaquen 43dcf2172a Add support for profiling the matchers used.
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
2014-10-22 20:31:05 +00:00
Samuel Benzaquen 2009960ea3 Fix bug in DynTypedMatcher::constructVariadic() that would cause false negatives.
Summary:
Change r219118 fixed the bug for anyOf and eachOf, but it is still
present for unless.
The variadic wrapper doesn't have enough information to know how to
restrict the type. Different operators handle restrict failures in
different ways.

Reviewers: klimek

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D5731

llvm-svn: 219622
2014-10-13 17:38:12 +00:00
Samuel Benzaquen b63c251894 Fix completion logic to allow for heterogeneous argument types in matcher overloads.
Summary:
There was an assumption that there were no matchers that were overloaded
on matchers and other types of arguments.
This assumption was broken recently with the addition of new matcher
overloads.

Fixes http://llvm.org/PR21226

Reviewers: pcc

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D5711

llvm-svn: 219450
2014-10-09 22:08:52 +00:00
Samuel Benzaquen 96039d727b Special case 0 and 1 matcher in makeAllOfComposite().
Summary:
Remove unnecessary wrapping for the 0 and 1 matcher cases of
makeAllOfComposite(). We don't need a variadic wrapper for those cases.
Refactor TrueMatcher to take advandage of the new conversions between
DynTypedMatcher and Matcher<T>. Also, make it a singleton.
This change improves our clang-tidy related benchmarks by ~12%.

Reviewers: klimek

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D5675

llvm-svn: 219431
2014-10-09 19:28:18 +00:00
Manuel Klimek 7735e40a87 Implement various matchers around template argument handling.
llvm-svn: 219408
2014-10-09 13:06:22 +00:00
Samuel Benzaquen a117002d93 Fix bug in DynTypedMatcher::constructVariadic() that would cause false negatives.
Summary:
DynTypedMatcher::constructVariadic() where the restrict kind of the
different matchers are not related causes the matcher to have a "None"
restrict kind. This causes false negatives for anyOf and eachOf.
Change the logic to get a common ancestor if there is one.
Also added regression tests that fail without the fix.

Reviewers: klimek

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D5580

llvm-svn: 219118
2014-10-06 13:14:30 +00:00
Fariborz Jahanian 5afc869f96 Adds 'override' to overriding methods. NFC.
These were uncoveredby my yet undelivered patch.

llvm-svn: 218774
2014-10-01 16:56:40 +00:00
Samuel Benzaquen f28d997083 Refactor Matcher<T> and DynTypedMatcher to reduce overhead of casts.
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
2014-10-01 15:08:07 +00:00
NAKAMURA Takumi 13f0aeb6ee Revert r218616, "Refactor Matcher<T> and DynTypedMatcher to reduce overhead 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
2014-09-29 23:56:21 +00:00
Samuel Benzaquen ee110341fb Refactor Matcher<T> and DynTypedMatcher to reduce overhead of casts.
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
2014-09-29 18:43:20 +00:00
Manuel Klimek 94ad0bf10d Add matcher for linkage specification
Patch by Jacques Pienaar.

llvm-svn: 217135
2014-09-04 08:51:06 +00:00
Benjamin Kramer 7ab8476c15 ASTMatchers: Add a matcher to detect whether a decl or stmt is inside a template instantiation.
This is hoisted from clang-tidy where it's used everywhere. The implementation
is not particularly efficient right now, but there is no easy fix for that.

Differential Revision: http://reviews.llvm.org/D5085

llvm-svn: 217029
2014-09-03 12:08:14 +00:00
Manuel Klimek 3fe8a38110 Add hasAttr matcher for declarations.
Delete special-case CUDA attribute matchers.

Patch by Jacques Pienaar.

llvm-svn: 216379
2014-08-25 11:23:50 +00:00
Samuel Benzaquen 8e7f99647d Add isDeleted() matcher for FunctionDecl nodes.
Reviewers: klimek

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D4911

llvm-svn: 215714
2014-08-15 14:20:59 +00:00
Benjamin Kramer 2f5db8b3db Header guard canonicalization, clang part.
Modifications made by clang-tidy with minor tweaks.

llvm-svn: 215557
2014-08-13 16:25:19 +00:00
Samuel Benzaquen 646f23b809 Support named values in the autocomplete feature.
Summary:
This includes:
 - Passing a Sema to completeExpression to allow for named values in the
   expression.
 - Passing a map of names to values to the parser.
 - Update the Sema interface to include completion for matchers.
 - Change the parser to use the Sema for completion, instead of going
   directly to Registry.

Reviewers: pcc

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D3509

llvm-svn: 215472
2014-08-12 21:11:37 +00:00
NAKAMURA Takumi 360927923f ASTMatchersTests/matchesConditionallyWithCuda: Add -fno-ms-extensions, and get rid of initializer list.
I am not sure whether -xcuda might imply -fno-ms-extensions.

llvm-svn: 214876
2014-08-05 15:54:43 +00:00
Manuel Klimek d52a3b8897 Adds AST matchers for matching CUDA declarations.
Patch by Jacques Pienaar.

llvm-svn: 214852
2014-08-05 09:45:53 +00:00
Daniel Jasper 3dfa09bbbc Prevent assert in ASTMatchFinder.
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
2014-07-23 13:17:47 +00:00
Benjamin Kramer 7664558efc ASTMatchers: Bound node results are always const, make selectFirst's template argument implicitly const.
This avoids adding const to every user of selectFirst and also allows it to
match TypeLocs which BoundNodes doesn't use magic const removal specializations
for. No functionality change.

llvm-svn: 213737
2014-07-23 11:41:44 +00:00
Alp Toker 0621cb2e7d Make clang's rewrite engine a core feature
The rewrite facility's footprint is small so it's not worth going to these
lengths to support disabling at configure time, particularly since key compiler
features now depend on it.

Meanwhile the Objective-C rewriters have been moved under the
ENABLE_CLANG_ARCMT umbrella for now as they're comparatively heavy and still
potentially worth excluding from lightweight builds.

Tests are now passing with any combination of feature flags. The flags
historically haven't been tested by LLVM's build servers so caveat emptor.

llvm-svn: 213171
2014-07-16 16:48:33 +00:00
Benjamin Kramer 73ef216c73 [ASTMatchers] Add a usingDirectiveDecl matcher.
This matches 'using namespace' declarations.

Differential Revision: http://reviews.llvm.org/D4517

llvm-svn: 213152
2014-07-16 14:14:51 +00:00
Benjamin Kramer 09514492cc [ASTMatchers] Make hasOverloadedOperatorName also match freestanding overloads.
Freestanding overloads are represented as FunctionDecls in the AST, make
the matcher also match them.

Differential Revision: http://reviews.llvm.org/D4493

llvm-svn: 212940
2014-07-14 14:05:02 +00:00
Alexander Kornienko 9e41b5cc12 Add a matcher for SubstNonTypeTemplateParmExpr.
Reviewers: klimek, djasper

Reviewed By: djasper

Subscribers: klimek, aemerson, cfe-commits

Differential Revision: http://reviews.llvm.org/D4327

llvm-svn: 212001
2014-06-29 22:18:53 +00:00
Craig Topper 00bbdcf9b3 Remove llvm:: from uses of ArrayRef.
llvm-svn: 211987
2014-06-28 23:22:23 +00:00
Samuel Benzaquen 3ca0a7b404 Do not store duplicate parents when memoization data is available.
Summary:
Do not store duplicate parents when memoization data is available.
This does not solve the duplication problem, but ameliorates it.

Reviewers: klimek

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D4124

llvm-svn: 210902
2014-06-13 13:31:40 +00:00
Craig Topper 416fa34b87 [C++11] Use 'nullptr'. Unittests edition.
llvm-svn: 210423
2014-06-08 08:38:12 +00:00
Samuel Benzaquen f56a29924f Add hasLocalStorage/hasGlobalStorage matchers.
Summary:
Add hasLocalStorage/hasGlobalStorage matchers for VarDecl nodes.
Update the doc. Also add them to the dynamic registry.

Reviewers: klimek

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D4034

llvm-svn: 210278
2014-06-05 18:22:14 +00:00
Manuel Klimek a2c2a4faa0 Make equalsNode work with pointers to subtypes.
llvm-svn: 209652
2014-05-27 12:31:10 +00:00
Manuel Klimek 909b5c94c0 Adds child traversal matchers for IfStmt's then and else branches.
llvm-svn: 209649
2014-05-27 10:04:12 +00:00
Manuel Klimek 2af0a91cc4 Allow hasBody on CXXForRangeStmt nodes and update the docs.
llvm-svn: 209647
2014-05-27 07:45:18 +00:00
Manuel Klimek 8651081bbe Add the hasRangeInit() matcher for range-based for loop.
llvm-svn: 209533
2014-05-23 17:49:03 +00:00
Joey Gouly 0d9a2b2205 [ASTMatchers] Move the 'isImplicit' matcher from CXXConstructorDecl to Decl.
llvm-svn: 209006
2014-05-16 19:31:08 +00:00
Nico Weber 7c3ccb032e Fix 3 test-only leaks found by LSan.
llvm-svn: 207068
2014-04-24 03:30:22 +00:00
Samuel Benzaquen f434c4fa3f Add support for named values in the parser.
Summary: Add support for named values in the parser.

Reviewers: pcc

CC: cfe-commits, klimek

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

llvm-svn: 206176
2014-04-14 13:51:21 +00:00
Samuel Benzaquen 5548eadb1c Revert "Add support for named values in the parser."
This was submitted before it was ready.

This reverts commit 62060a01e095cf35eb9ca42a333752d12714f35c.

llvm-svn: 205533
2014-04-03 12:50:47 +00:00
Samuel Benzaquen f10662923a Add matcher for ExprWithCleanups.
Summary: Add matcher for ExprWithCleanups.

Reviewers: klimek

CC: cfe-commits, klimek

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

llvm-svn: 205420
2014-04-02 13:12:14 +00:00
Samuel Benzaquen 2019cea863 Add support for named values in the parser.
Summary:
Add support for named values in the parser.
This allows injection of arbitrary constants using a custom Sema object.
Completions are not supported right now.

Will be used by clang_query to support the 'let' command.
Usage example:
  clang_query> let unique_ptr recordDecl(hasName("unique_ptr"))
  clang_query> match varDecl(hasType(unique_ptr))

Reviewers: klimek, pcc

CC: cfe-commits, klimek

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

llvm-svn: 205419
2014-04-02 13:11:45 +00:00
David Blaikie abe1a398e3 Render anonymous entities as '(anonymous <thing>)' (and lambdas as '(lambda at ... )')
For namespaces, this is consistent with mangling and GCC's debug info
behavior. For structs, GCC uses <anonymous struct> but we prefer
consistency between all anonymous entities but don't want to confuse
them with template arguments, etc, so we'll just go with parens in all
cases.

llvm-svn: 205398
2014-04-02 05:58:29 +00:00
Saleem Abdulrasool 377066a5f5 Use the new Windows environment for target detection
This follows the LLVM change to canonicalise the Windows target triple
spellings.  Rather than treating each Windows environment as a single entity,
the environments are now modelled properly as an environment.  This is a
mechanical change to convert the triple use to reflect that change.

llvm-svn: 204978
2014-03-27 22:50:18 +00:00
Manuel Klimek ce68f7714a Fixes a bug in DynTypedNode.
Two DynTypedNodes can be equal if they do not have the same node type,
because DynTypedNodes for the same underlying object might have been
created from different types (for example, Decl vs VarDecl).

llvm-svn: 204722
2014-03-25 14:39:26 +00:00
Samuel Benzaquen a083935d0a Add loc() to the dynamic registry.
Summary:
Add loc() to the dynamic registry.
Other fixes:
 - Fix the polymorphic variant value to accept an exact match, even if
   there are other possible conversions.
 - Fix specifiesTypeLoc() to not crash on an empty
   NestedNameSpecifierLoc.

Reviewers: klimek

CC: cfe-commits, klimek

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

llvm-svn: 203467
2014-03-10 15:40:23 +00:00
Ahmed Charles b89843299a Replace OwningPtr with std::unique_ptr.
This compiles cleanly with lldb/lld/clang-tools-extra/llvm.

llvm-svn: 203279
2014-03-07 20:03:18 +00:00
David Majnemer 197e2103a2 Speculatively fix MSVC buildbots
llvm-svn: 202938
2014-03-05 06:32:38 +00:00
Craig Topper a798a9db93 Switch all uses of LLVM_OVERRIDE to just use 'override' directly.
llvm-svn: 202625
2014-03-02 09:32:10 +00:00
Dmitri Gribenko 51c1b55bc2 ASTMatchers: added CXXMethodDecl matcher isPure()
The isPure() CXXMethodDecl matcher matches pure method declaration like "A::x"
in this example:

class A {
  virtual void x() = 0;
}

Patch by Konrad Kleine.

llvm-svn: 202012
2014-02-24 09:27:46 +00:00
Peter Collingbourne 564597fd26 Add TemplateSpecializationType polymorphism for hasTemplateArgument and
hasAnyTemplateArgument, and (out of necessity) an isExpr matcher.

Also updates the TemplateArgument doxygen to reflect reality for
non-canonical template arguments.

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

llvm-svn: 201804
2014-02-20 19:18:03 +00:00
NAKAMURA Takumi 7d2da0b2ae clang/unittests/AST,ASTMatchers: Remove _MSC_VER.
llvm-svn: 201485
2014-02-16 10:16:09 +00:00
David Blaikie 8972f4e966 Consistently print anonymous namespace names as "<anonymous namespace>"
For some reason we have two bits of code handling this printing:

lib/AST/Decl.cpp:        OS << "<anonymous namespace>";
lib/AST/TypePrinter.cpp:      OS << "<anonymous namespace>::";

it would be nice if we only had one...

llvm-svn: 201437
2014-02-14 22:12:54 +00:00
Peter Collingbourne 1fec3dfe43 Add isListInitialization matcher.
Differential Revision: http://llvm-reviews.chandlerc.com/D2708

llvm-svn: 200949
2014-02-06 21:52:24 +00:00
Richard Smith 3d584b0ced PR18128: a lambda capture-default is not permitted for a non-local lambda
expression.

llvm-svn: 200948
2014-02-06 21:49:08 +00:00
Alexander Kornienko 9b539e1dd9 Added the hasLoopVariable sub-matcher for forRangeStmt.
Summary:
This sub-matcher makes it possible to access directly the range-based for
loop variable: forRangeStmt(hasLoopVariable(anything()).bind(...)).
I've tried to re-generate the docs, but the diffs seem to include much more than
this change could cause, so I'd better leave docs update to someone who knows
the intended changes in the contents better.

Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits, klimek

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

llvm-svn: 200850
2014-02-05 16:35:08 +00:00
Peter Collingbourne 252444a777 Introduce Parser::completeExpression.
This function returns a list of completions for a given expression and
completion position.

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

llvm-svn: 200497
2014-01-30 22:38:41 +00:00
Peter Collingbourne d32e28c87a Introduce Registry::getCompletions.
This returns a list of valid (and useful) completions for a context (a list
of outer matchers), ordered by decreasing relevance then alphabetically. It
will be used by the matcher parser to implement completion.

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

llvm-svn: 199950
2014-01-23 22:48:38 +00:00
Ismail Pazarbasi 1121de36c2 Fix string-literal to char* conversion in overload resolution for C++11
String literal to char* conversion is deprecated in C++03, and is removed in
C++11. We still accept this conversion in C++11 mode as an extension, if we find
it in the best viable function.

llvm-svn: 199513
2014-01-17 21:08:52 +00:00
NAKAMURA Takumi 9b435fec0d DynamicASTMatchers/VariantValueTest.cpp: It works with msvcrt since setmode(stderr, O_BINARY) were removed.
llvm-svn: 199059
2014-01-12 17:49:26 +00:00
Chandler Carruth 5553d0d4ca Sort all the #include lines with LLVM's utils/sort_includes.py which
encodes the canonical rules for LLVM's style. I noticed this had drifted
quite a bit when cleaning up LLVM, so wanted to clean up Clang as well.

llvm-svn: 198686
2014-01-07 11:51:46 +00:00
Alp Toker 8db6e7a972 Fix 'declartion' typos
llvm-svn: 198549
2014-01-05 06:38:57 +00:00
NAKAMURA Takumi ac85179219 [CMake] Update target_link_libraries() and LLVM_LINK_COMPONENTS for each CMakeLists.txt.
llvm-svn: 196916
2013-12-10 12:40:37 +00:00
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