Commit Graph

170 Commits

Author SHA1 Message Date
Daniel Jasper a6bc1f6d35 Create initial support for matching and binding NestedNameSpecifier(Loc)s.
Review: http://llvm-reviews.chandlerc.com/D39
llvm-svn: 163794
2012-09-13 13:11:25 +00:00
Daniel Jasper d6b82cba05 Rename isA to isSameOrDerivedFrom.
There are two evils we can choose from:
- Name overlap between isA-matcher and llvm::isa<>()
- Bad name for what the isA-matcher currently does

After some discussion we have agreed to go with the latter evil.

Review: http://llvm-reviews.chandlerc.com/D40
llvm-svn: 163740
2012-09-12 21:14:15 +00:00
Dmitri Gribenko 7acbf00f96 Comment AST: TableGen'ize all command lists in CommentCommandTraits.cpp.
Now we have a list of all commands.  This is a good thing in itself, but it
also enables us to easily implement typo correction for command names.

With this change we have objects that contain information about each command,
so it makes sense to resolve command name just once during lexing (currently we
store command names as strings and do a linear search every time some property
value is needed).  Thus comment token and AST nodes were changed to contain a
command ID -- index into a tables of builtin and registered commands.  Unknown
commands are registered during parsing and thus are also uniformly assigned an
ID.  Using an ID instead of a StringRef is also a nice memory optimization
since ID is a small integer that fits into a common bitfield in Comment class.

This change implies that to get any information about a command (even a command
name) we need a CommandTraits object to resolve the command ID to CommandInfo*.
Currently a fresh temporary CommandTraits object is created whenever it is
needed since it does not have any state.  But with this change it has state --
new commands can be registered, so a CommandTraits object was added to
ASTContext.

Also, in libclang CXComment has to be expanded to include a CXTranslationUnit
so that all functions working on comment AST nodes can get a CommandTraits
object.  This breaks binary compatibility of CXComment APIs.

Now clang_FullComment_getAsXML(CXTranslationUnit TU, CXComment CXC) doesn't
need TU parameter anymore, so it was removed.  This is a source-incompatible
change for this C API.

llvm-svn: 163540
2012-09-10 20:32:42 +00:00
Daniel Jasper f49d1e0070 Change the behavior of the isDerivedFrom-matcher to not match on the
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
2012-09-07 12:48:17 +00:00
Manuel Klimek 3ca12c5b54 Implements hasAncestor.
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
2012-09-07 09:26:10 +00:00
Manuel Klimek eb958ded72 Introduces DynTypedMatcher as a new concept that replaces the 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
2012-09-05 12:12:07 +00:00
Ted Kremenek cdf814900d Split library clangRewrite into clangRewriteCore and clangRewriteFrontend.
This is similar to how we divide up the StaticAnalyzer libraries to separate
core functionality to what is clearly associated with Frontend actions.

llvm-svn: 163050
2012-09-01 05:09:24 +00:00
Dmitri Gribenko 6bab9113b0 Remove the useless CommentOptions class.
llvm-svn: 162986
2012-08-31 10:35:30 +00:00
Dmitri Gribenko 454a43cf30 DeclPrinter tests: simplify the code by using the new runToolOnCodeWithArgs
function from Tooling.

llvm-svn: 162976
2012-08-31 03:23:26 +00:00
Dmitri Gribenko bda79e5cc2 DeclPrinter tests: since now some platforms use C++11 by default, make it
explicitly visible in test cases which language variant is used.

llvm-svn: 162974
2012-08-31 03:05:44 +00:00
Manuel Klimek fdf98763ac Fixes a bug for binding memoized match results.
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
2012-08-30 19:41:06 +00:00
Nico Weber 723b4f02a7 Reland r160052: Default to -std=c++11 on Windows.
Also update the tests that rely on c++98 to explicitly mention that.

llvm-svn: 162890
2012-08-30 02:08:31 +00:00
Nico Weber 077a53e5ab Tooling: Add a runToolOnCodeWithArgs() function that allows
passing additional parameters to a tool.

Use this to fix a FIXME in testing code.

llvm-svn: 162889
2012-08-30 02:02:19 +00:00
NAKAMURA Takumi 6ab80a0872 ASTTests: Suppress TestCXXConstructorDecl11 on msvc for now. It seems incompatible.
llvm-svn: 162631
2012-08-25 00:05:56 +00:00
Sam Panzer 68a35af312 New matcher for MaterializeTemporaryExpr
llvm-svn: 162609
2012-08-24 22:04:44 +00:00
James Dennett 75c100b8e5 Allow RecursiveASTVisitor to visit CXXCtorInitializer objects for which
isWritten() returns false, if shouldVisitImplicitCode() returns true.
Previously those CXXCtorInitializers were always skipped.

In order to make this change easier to test, this patch also extends the
test class template ExpectedLocationVisitor to support arbitrary numbers
of expected matches and disallowed matches.

llvm-svn: 162544
2012-08-24 06:59:51 +00:00
Daniel Jasper 6ed1f85c24 Use LLVM's plugin registry to enable registering new compilation
databases. Move JSONCompilationDatabase.h to its own files and
register it as plugin.

llvm-svn: 162541
2012-08-24 05:50:27 +00:00
Daniel Jasper bd3d76d90c Rename the ASTMatchers to better match AST nodes. Now, all
ASTMatchers have the same name as the corresponding AST nodes
but are lower case. The only exceptions are the "CXX" prefixes
which are not copied over to the matcher names as the goal is to
actually remove these prefixes from the AST node names.

llvm-svn: 162536
2012-08-24 05:12:34 +00:00
Dmitri Gribenko def829ee86 DeclPrinter tests: mark test case we get wrong currently with WRONG.
llvm-svn: 162512
2012-08-24 00:27:50 +00:00
Dmitri Gribenko 340c0f6776 DeclPrinter tests: add two more tests.
llvm-svn: 162511
2012-08-24 00:26:25 +00:00
Richard Smith 802c4b7015 Fix undefined behavior: member function calls where 'this' is a null pointer.
llvm-svn: 162430
2012-08-23 06:16:52 +00:00
Dmitri Gribenko 107618a6cb Comment parsing: parse "<blah" as an HTML tag only if "blah" is a known tag
name.  This should reduce the amount of warning false positives about bad HTML
in comments when the comment author intended to put a reference to a template.
This change will also enable us parse the comment as intended in these cases.

Fixes part 1 of PR13374.

llvm-svn: 162407
2012-08-22 22:56:08 +00:00
Dmitri Gribenko a9a2af7893 DeclPrinter, terse mode: don't print function bodies
llvm-svn: 162294
2012-08-21 17:47:24 +00:00
Dmitri Gribenko a93a7e8d5e Rename PrintingPolicy::DontRecurseInDeclContext to PrintingPolicy::TerseOutput
to reflect the intention, not the implementation.

llvm-svn: 162293
2012-08-21 17:36:32 +00:00
Dmitri Gribenko 309856ae9f DeclPrinter: add terse output mode and lots of tests
Add a flag PrintingPolicy::DontRecurseInDeclContext to provide "terse" output
from DeclPrinter.  The motivation is to use DeclPrinter to print declarations
in user-friendly format, without overwhelming user with inner detail of the
declaration being printed.

Also add many tests for DeclPrinter.  There are quite a few things that we
print incorrectly: search for WRONG in DeclPrinterTest.cpp -- and these tests
check our output against incorrect output, so that we can fix/refactor/rewrite
the DeclPrinter later.

llvm-svn: 162245
2012-08-20 23:39:06 +00:00
Dmitri Gribenko edee47891c AST Matchers tests: test that member() matches member allocation functions:
declare size_t in system-independent way.

llvm-svn: 162158
2012-08-18 00:41:04 +00:00
Dmitri Gribenko 0696304a61 AST Matchers tests: test that member() matches member allocation functions.
llvm-svn: 162153
2012-08-18 00:29:27 +00:00
Richard Smith 87deab3e6c Part of PR13618: visit the TypeLoc when RecursiveASTVisitor visits a CompoundLiteralExpr.
llvm-svn: 162133
2012-08-17 21:23:17 +00:00
Dmitri Gribenko d394c8a83e AST Matchers: introduce functionTemplate(), classTemplate() and
isExplicitTemplateSpecialization() matchers which do what their name says.

llvm-svn: 162115
2012-08-17 18:42:47 +00:00
Richard Smith 034b94a557 Don't forget to apply #pragma pack to partial and explicit specializations of
class templates. This fixes misalignment issues in llvm/Support/Endian.h when
built by Clang.

llvm-svn: 162074
2012-08-17 03:20:55 +00:00
Sam Panzer d624bfb5f0 Matchers related to DeclStmt for matching the count of declarations, a particular declaration within the statement, and single-Decl DeclStmts.
llvm-svn: 162027
2012-08-16 17:20:59 +00:00
Sam Panzer 80c13773e3 Matchers which correspond to CastExpr, IgnoreImpCasts, IgnoreParenCasts, and IgnoreParenImpCasts
llvm-svn: 162025
2012-08-16 16:58:10 +00:00
Daniel Jasper faaffe373e Add ASTMatcher for matching extern "C" function declarations.
llvm-svn: 161974
2012-08-15 18:52:19 +00:00
Chad Rosier bf40d6b6a5 [ms-inline asm] Add various MC components to clang build to support MS-style inline assembly.
llvm-svn: 161594
2012-08-09 17:17:01 +00:00
Dmitri Gribenko ca7f80ada0 Comment parsing: extract TableGen'able pieces into new CommandTraits class.
llvm-svn: 161548
2012-08-09 00:03:17 +00:00
Chad Rosier 4577cd3036 Add various MC components to clang build to support MS-style inline assembly.
llvm-svn: 161498
2012-08-08 16:27:29 +00:00
Dmitri Gribenko 6297fa8a14 Comment parsing: fix crash on \tparam followed immediately by another block
command, for example: \tparam\brief.

llvm-svn: 161361
2012-08-06 23:48:44 +00:00
Dmitri Gribenko 6087ba7dc8 Comment parser tests: test that we allow placing no whitespace between \param
and [direction].

llvm-svn: 161146
2012-08-01 23:49:32 +00:00
Daniel Jasper 8bd14aab3a Add missing tests for class template specialization and template
argument matchers.

llvm-svn: 161102
2012-08-01 08:40:24 +00:00
Dmitri Gribenko 34df220410 Comment parsing: add support for \tparam command on all levels.
The only caveat is renumbering CXCommentKind enum for aesthetic reasons -- this
breaks libclang binary compatibility, but should not be a problem since API is
so new.

This also fixes PR13372 as a side-effect.

llvm-svn: 161087
2012-07-31 22:37:06 +00:00
Dmitri Gribenko dfe14f7848 Comment parser: add one more test
llvm-svn: 160965
2012-07-30 16:52:51 +00:00
Daniel Jasper 3cb72b476d Fix for ASTMatchFinder to visit a functions parameter declarations.
llvm-svn: 160947
2012-07-30 05:03:25 +00:00
Dmitri Gribenko 4586df765e Implement resolving of HTML character references (named: &amp;, decimal: &#42;,
hex: &#x1a;) during comment parsing.

Now internal representation of plain text in comment AST does not contain
character references, but the characters themselves.

llvm-svn: 160891
2012-07-27 20:37:06 +00:00
Manuel Klimek e923569b1b Introduces the 'decl' matcher which was missing for a while
and became necessary with the change to require BindableMatchers
for binding.

Also fixes PR 13445: "hasSourceExpression only works for implicit casts".

llvm-svn: 160716
2012-07-25 10:02:02 +00:00
Dmitri Gribenko 35b0c09b6c Comment parsing: allow newlines between \param, direction specification (e.g.,
[in]), parameter name and description paragraph.

llvm-svn: 160682
2012-07-24 18:23:31 +00:00
Dmitri Gribenko 1c85d5b17d Comment parsing: retokenized text tokens are now pushed back in correct (not
reverse) order

llvm-svn: 160675
2012-07-24 16:10:47 +00:00
Manuel Klimek 86f8bbced4 Introduces a new concept for binding results to matchers
as per Chandler's request:
- introduces a new matcher base type BindableMatcher that
  provides the bind() call
- makes all dynamic-cast matcher creation functions return
  BindableMatchers; the special case about dynamic-cast
  matchers is that the node they match on and the node
  their child matchers match on are the same node, just
  casted to a different type; thus, there is no ambiguity
  on what bind() matches on; additionally, those are the
  matchers that we name with nouns in the matcher language,
  so it's easy for users to intuitively know which matchers
  are bindable

To make this change possible, we got rid of a non-orthogonal
implementation of thisPointerType, which had an implicit
dynamic-cast matcher from CallExpr to CXXMemberCallExpr; as
alternative, we now provide a memberCall dynamic-cast matcher
and thisPointerType is a predicate on CXXMemberCallExpr.

Last, the ArgumentAdaptingMatcher is actually not required
for the implementation of makeDynCastAllOfComposite - this
simplification makes it more obvious where the bind() call
can be used based on the matcher creation function types.

llvm-svn: 160673
2012-07-24 13:37:29 +00:00
Dmitri Gribenko 47f622d414 Comment parser unit tests: split a huge test case
llvm-svn: 160649
2012-07-23 23:37:11 +00:00
Dmitri Gribenko 89630bce27 Comment parser unit tests: reduce code duplication
llvm-svn: 160647
2012-07-23 23:09:32 +00:00
Dmitri Gribenko e3942ef9a4 add AST unittests to CMake build system
llvm-svn: 160640
2012-07-23 20:11:34 +00:00