Commit Graph

357 Commits

Author SHA1 Message Date
Daniel Jasper 206df73417 Prefer not to break after assignments.
This addresses llvm.org/PR14830.

Before:
unsigned Cost =
    TTI.getMemoryOpCost(I->getOpcode(), VectorTy, SI->getAlignment(),
                        SI->getPointerAddressSpace());
CharSourceRange LineRange =
    CharSourceRange::getTokenRange(TheLine.Tokens.front().Tok.getLocation(),
                                   TheLine.Tokens.back().Tok.getLocation());

After:
unsigned Cost = TTI.getMemoryOpCost(I->getOpcode(), VectorTy,
                                    SI->getAlignment(),
                                    SI->getPointerAddressSpace());
CharSourceRange LineRange = CharSourceRange::getTokenRange(
                                TheLine.Tokens.front().Tok.getLocation(),
                                TheLine.Tokens.back().Tok.getLocation());

This required rudimentary changes to static initializer lists, but we
are not yet formatting them in a reasonable way. That will be done in a
subsequent patch.

llvm-svn: 171731
2013-01-07 13:08:40 +00:00
Daniel Jasper 5ad1e1992a Add style option for number of spaces before trailing comments.
In LLVM style, a single space should be enough. In Google style, two
spaces are required.

llvm-svn: 171725
2013-01-07 11:09:06 +00:00
Daniel Jasper da16db3f9a Do not break before "0" in pure virtual function declarations.
Before:
virtual void write(ELFWriter *writer, OwningPtr<FileOutputBuffer> &buffer) =
    0

After:
virtual void write(ELFWriter *writerrr,
                   OwningPtr<FileOutputBuffer> &buffer) = 0;

This addresses llvm.org/PR14815.

To implement this I introduced a line type during parsing and moved the
definition of TokenType out of the struct for increased readability.
Should have done the latter in a separate patch, but it would be hard to
pull apart now.

llvm-svn: 171724
2013-01-07 10:48:50 +00:00
Manuel Klimek 7872571fc5 Fix incorrect FIXME.
The case that we wanted to write a test for cannot happen, as the
UnwrappedLineParser already protects against it. Added an assert to
prevent regressions of that assumption.

llvm-svn: 171720
2013-01-07 10:03:37 +00:00
Manuel Klimek 38ba11e492 Do not ever allow using the full line in preprocessor directives.
We would format:
  #define A \
    int f(a); int i;
as
  #define A \
    int f(a);\
    int i

The fix will break up macro definitions that could fit a line, but hit
the last column; fixing that is more involved, though, as it requires
looking at the following line.

llvm-svn: 171715
2013-01-07 09:24:17 +00:00
Manuel Klimek c74d292229 Fix layouting of single-line-comments preceded by an escaped newline.
Previously, we'd format
  int i;\
  // comment
as
  int i; // comment

The problem is that the escaped newline is part of the next token, and
thus the raw token text of the comment doesn't start with "//".

llvm-svn: 171713
2013-01-07 08:54:53 +00:00
Manuel Klimek ef92069940 Fix layouting of tokens with a leading escaped newline.
If a token follows directly on an escaped newline, the escaped newline
is stored with the token. Since we re-layout escaped newlines, we need
to treat them just like normal whitespace - thus, we need to increase
the whitespace-length of the token, while decreasing the token length
(otherwise the token length contains the length of the escaped newline
and we double-count it while indenting).

llvm-svn: 171706
2013-01-07 07:56:50 +00:00
Daniel Jasper c7345ccc2c Put a higher penalty on breaking before "." or "->".
This fixes llvm.org/PR14823.

Before:
    local_state->SetString(prefs::kApplicationLocale, parent_local_state
                                ->GetString(prefs::kApplicationLocale));
After:
    local_state->SetString(
        prefs::kApplicationLocale,
        parent_local_state->GetString(prefs::kApplicationLocale));

llvm-svn: 171705
2013-01-07 07:13:20 +00:00
Manuel Klimek 1058d987f9 Fixes handling of unbalances braces.
If we find an unexpected closing brace, we must not stop parsing, as
we'd otherwise not layout anything beyond that point.

If we find a structural error on the highest level we'll not re-indent
anyway, but we'll still want to format within unwrapped lines.

Needed to introduce a differentiation between an expected and unexpected
closing brace.

llvm-svn: 171666
2013-01-06 20:07:31 +00:00
Manuel Klimek 52d0fd8961 Fixes parsing of hash tokens in the middle of a line.
To parse # correctly, we need to know whether it is the first token in a
line - we can deduct this either from the whitespace or seeing that the
token is the first in the file - we already calculate this information.
This patch moves the identification of the first token into the
getNextToken method and stores it inside the FormatToken, so the
UnwrappedLineParser can stay independent of the SourceManager.

llvm-svn: 171640
2013-01-05 22:56:06 +00:00
Manuel Klimek ef2cfb110d Fixes PR14801 - preprocessor directives shouldn't be indented
Uses indent 0 for macros for now and resets the indent state to the
level prior to the preprocessor directive.

llvm-svn: 171639
2013-01-05 22:14:16 +00:00
Manuel Klimek 09e0797953 Fixes PR14811: Crash when formatting some macros
A preprocessor directive cannot be started while we're parsing one.

llvm-svn: 171635
2013-01-05 21:34:55 +00:00
Manuel Klimek 1abf789c7a Various fixes to clang-format's macro handling.
Some of this is still pretty rough (note the load of FIXMEs), but it is
strictly an improvement and fixes various bugs that were related to
macro processing but are also imporant in non-macro use cases.

Specific fixes:
- correctly puts espaced newlines at the end of the line
- fixes counting of white space before a token when escaped newlines are
  present
- fixes parsing of "trailing" tokens when eof() is hit
- puts macro parsing orthogonal to parsing other structure
- general support for parsing of macro definitions

Due to the fix to format trailing tokens, this change also includes a
bunch of fixes to the c-index tests.

llvm-svn: 171556
2013-01-04 23:34:14 +00:00
Daniel Jasper 3c2557d0dd Correctly format dereference and address of in array parameters.
Before: InvalidRegions[ &R] = 0;
After:  InvalidRegions[&R] = 0;

This fixes llvm.org/PR14793

llvm-svn: 171522
2013-01-04 20:46:38 +00:00
Daniel Jasper c0880a904b Let the formatter ignore UnwrappedLines containing errors.
This prevents code like:

namespace {
class Foo {
  Foo(
  };
}  // comment

from causing segfaults (see llvm.org/PR14774).

llvm-svn: 171495
2013-01-04 18:52:56 +00:00
Manuel Klimek b69e3c6201 Fixes multiple formatting bugs.
Fixes:
- incorrect handling of multiple consecutive preprocessor directives
- crash when trying to right align the escpaed newline for a line that
  is longer than the column limit
- using only ColumnLimit-1 columns when layouting with escaped newlines
  inside preprocessor directives

llvm-svn: 171401
2013-01-02 18:33:23 +00:00
Daniel Jasper 90e51fdbab Don't allow line breaks after template parameters.
This fixes llvm.org/PR14786.

We will need to split there as a last resort, but that should be done
consistently independent of whether the type is a template type or not.

Before:
template <typename T>
aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaa<T>
                    ::aaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

After:
template <typename T>
aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaa,
                    aaaaaaaaaaaaaaaaaaaaaaaaaa<T>::aaaaaaaaaa,
                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

llvm-svn: 171400
2013-01-02 18:30:06 +00:00
Daniel Jasper 3c0431c887 Format */& as binary operator if followed by a unary operator.
This fixes llvm.org/PR14687.
Also fixes segfault for lines starting with * or &.

Before:
a *~b;
*a = 1;  // <- this segfaulted

After:
a * ~b;
*a = 1;  // no segfault :-)

llvm-svn: 171396
2013-01-02 17:21:36 +00:00
Manuel Klimek a71e5d8115 Fixes use of unescaped newlines when formatting preprocessor directives.
This is the first step towards handling preprocessor directives. This
patch only fixes the most pressing issue, namely correctly escaping
newlines for tokens within a sequence of a preprocessor directive.

The next step will be to fix incorrect format decisions on #define
directives.

llvm-svn: 171393
2013-01-02 16:30:12 +00:00
Daniel Jasper 542de16e50 Correctly format pointers and references in casts.
This fixes llvm.org/PR14747.

Before: Type *A = (Type * ) P;
After:  Type *A = (Type *) P;
llvm-svn: 171390
2013-01-02 15:46:59 +00:00
Daniel Jasper da1c68ab71 Understand unary operators after "return" and "case".
This fixes llvm.org/PR14746.

Before: return - 1;
After:  return -1;
llvm-svn: 171389
2013-01-02 15:26:16 +00:00
Daniel Jasper ac5c1c286c Prefer splitting after "template <...>" and fix indentation.
This addresses llvm.org/PR14699

Before:
template <typename T>
    void looooooooooooooooooooooongFunction(int Param1, int Param2);
template <typename T> void looooooooooooooooooooongFunction(
    int Paaaaaaaaaaaaaaaaaaaaram1, int Paaaaaaaaaaaaaaaaaaaaram2);

After:
template <typename T>
void looooooooooooooooooooooongFunction(int Param1, int Param2);
template <typename T>
void looooooooooooooooooooongFunction(int Paaaaaaaaaaaaaaaaaaaaram1,
                                      int Paaaaaaaaaaaaaaaaaaaaram2);

llvm-svn: 171388
2013-01-02 15:08:56 +00:00
Daniel Jasper 3d0c75cc96 Prefer to break after operators over breaking after "(".
Before:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

After:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
                                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

llvm-svn: 171386
2013-01-02 14:40:02 +00:00
Daniel Jasper 22bcf8a8eb Understand * and & in ternary expressions.
Before: "int a = b ? *c : * d;"
After: "int a = b ? *c : *d;
llvm-svn: 171358
2013-01-02 08:57:10 +00:00
Daniel Jasper d1926a3758 Don't break after pointer or reference specifier.
This fixes llvm.org/PR14717.
Buggy format:
TypeSpecDecl *
    TypeSpecDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
                         IdentifierInfo *II, Type *T) {

Now changed to:
TypeSpecDecl *TypeSpecDecl::Create(ASTContext &C, DeclContext *DC,
                                   SourceLocation L, IdentifierInfo *II,
                                   Type *T) {

llvm-svn: 171357
2013-01-02 08:44:14 +00:00
Dmitri Gribenko 58d64e2bb1 Formatter: parse and format inline namespaces like regular namespaces
This changes formatting from:

inline namespace X {
  class A {
  };
}

to:

inline namespace X {
class A {
};
}

llvm-svn: 171266
2012-12-30 21:27:25 +00:00
Daniel Jasper 6d822720f0 Penalize tokens with a lower parenthesis level than the start of the line.
This prevents formattings like this (assuming "parameter" doesn't fit the line):
  bool f = someFunction() && someFunctionWithParam(
      parameter) && someOtherFunction();

Here, "parameter" - the start of line 2 - has a parenthesis level of 2, but
there are subsequent tokens ("&&" and "someOtherFunction") with a lower level.
This is bad for readability as "parameter" hides "someOtherFunction". With this
patch, this changes to:
  bool f = someFunction() &&
           someFunctionWithParam(parameter) &&
           someOtherFunction();

llvm-svn: 171038
2012-12-24 16:43:00 +00:00
Daniel Jasper 2eda23e78a Align RHS after assignments and return statements.
This changes:
  int Result = a +  // force break
      b;
  return Result +  // force break
      5;

To:
  int Result = a +  // force break
               b;
  return Result +  // force break
         5;

llvm-svn: 171032
2012-12-24 13:43:52 +00:00
Daniel Jasper 537a29638d Fix formatting over overloaded operators.
This fixes llvm.org/pr14686.

We used to add too many spaces for different versions of overloaded operator
function declarations/definitions. This patch changes, e.g.

  operator *() {}
  operator >() {}
  operator () () {}

to

  operator*() {}
  operator>() {}
  operator()() {}

llvm-svn: 171028
2012-12-24 10:56:04 +00:00
Daniel Jasper de5c20792d Take operator precedence into account when splitting lines.
With this patch, splitting after binary operators has a panelty corresponding
to the operator's precedence. We used to ignore this and eagerly format like:

  if (aaaaaaaaaaaaaaaaaaaaaaaaa || bbbbbbbbbbbbbbbbbbbbbbbbb &&
      ccccccccccccccccccccccccc) { .. }

With this patch, this becomes:

  if (aaaaaaaaaaaaaaaaaaaaaaaaa ||
      bbbbbbbbbbbbbbbbbbbbbbbbb && ccccccccccccccccccccccccc) { .. }

llvm-svn: 171007
2012-12-24 00:13:23 +00:00
Nico Weber 6f372e6533 libFormat: Teach the *& usage heuristic that "return" starts a rhs too.
"return a*b;" was formatted as "return a *b;" and is now formatted as "return a * b;".

Fixes PR14687 partially.

llvm-svn: 170993
2012-12-23 01:07:46 +00:00
Fariborz Jahanian 9017ec3a62 Adding to FormatTest.cpp test for a very long ObjC method
declaration requiring formatting of wrap-arounds.

llvm-svn: 170946
2012-12-21 22:51:18 +00:00
Nico Weber 8f83ee46ba format: Handle #import as include directive too.
llvm-svn: 170914
2012-12-21 18:21:56 +00:00
Daniel Jasper 050948a5a5 clang-format: No spaces around directory specifiers
This fixes PR14683. We used to format like this:
  #include <a / b>

And this patch changes this to:
  #include <a/b>

llvm-svn: 170910
2012-12-21 17:58:39 +00:00
Daniel Jasper fbde69e266 Basic support for formatting for-loops.
We used to not really format them. Now we do:

  for (MachineBasicBlock::succ_iterator SI = BB->succ_begin(),
                                        SE = BB->succ_end();
       SI != SE; ++SI) {

This is just one example and I am sure we still mess some of them up, but it
is a step forward.

llvm-svn: 170899
2012-12-21 14:37:20 +00:00
Daniel Jasper 8dd404737b Formatting fixes for PR14680
Also, some (automated) formatting fixes and slight cleanups.

llvm-svn: 170873
2012-12-21 09:41:31 +00:00
Fariborz Jahanian 68a542aea7 Add objective-C style formatting to clang format and
use it to format xml declaration tags. 
// rdar://12378714

llvm-svn: 170727
2012-12-20 19:54:13 +00:00
Fariborz Jahanian 4419449391 Provide couple of DeclPrint tests for my last patch.
llvm-svn: 170635
2012-12-20 02:20:09 +00:00
Fariborz Jahanian 0389e528ab Audit DeclPrinter with -ast-dump on Cocoa.h and
fix any bad objectiveC syntax coming out of
DeclPrinter. This is on going. Also, introduce a new
PrintPolicy and use it as needed when declaration tag
is to be produced via DeclPrinter.

llvm-svn: 170606
2012-12-19 23:36:00 +00:00
Fariborz Jahanian 9b7ab87738 This is the libclang patch providing minimal API to
use clang's formatter. Currently, formatter is used 
to format declaration tags for xml comments. Since formatter
is in flux and its change will break several of the clang comment
tests, only a single tests is formatted using this facility.
Doug has reviewed and approved it for check-in. 

llvm-svn: 170467
2012-12-18 23:02:59 +00:00
Daniel Jasper 2af6bbe7e0 Better support for constructor initializers.
We used to format initializers like this (with a sort of hacky implementation):
Constructor()
    : Val1(A),
      Val2(B) {

and now format like this (with a somewhat better solution):
Constructor()
    : Val1(A), Val2(B) {

assuming this would not fit on a single line. Also added tests.

As a side effect we now first analyze whether an UnwrappedLine needs to be
split at all. If not, not splitting it is the best solution by definition. As
this should be a very common case in normal code, not exploring the entire
solution space can provide significant speedup.

llvm-svn: 170457
2012-12-18 21:05:13 +00:00
Daniel Jasper 3f69a1b860 Make the format scrambler understand line comments.
This allows for writing tests including line comments easier and more readable.
We will need more of those tests in the future and also line comments are
useful to force line breaks in tests.

llvm-svn: 170446
2012-12-18 19:56:56 +00:00
Daniel Jasper 5485d0cd67 Add basic support for splitting before function calls if it can't be
avoided.

This required a minor modification of the memoization as now the
"CurrentPenalty" depends on whether or not we break before the current
token. Therefore, the CurrentPenalty should not be memoized but added
after retrieving a value from memory. This should not affect the runtime
behavior.

llvm-svn: 170337
2012-12-17 14:34:14 +00:00
Daniel Jasper e25509f857 Fix several formatting problems.
More specifically:
- Improve formatting of static initializers.
- Fix formatting of lines comments in enums.
- Fix formmating of trailing line comments.

llvm-svn: 170316
2012-12-17 11:29:41 +00:00
Roman Divacky d93c8c008e Dont use/link ARCMT, StaticAnalyzer and Rewriter to clang when the user
specifies not to. Dont build ASTMatchers with Rewriter disabled and
StaticAnalyzer when it's disabled.

Without all those three, the clang binary shrinks (x86_64) from ~36MB
to ~32MB (unstripped).

llvm-svn: 170135
2012-12-13 16:09:42 +00:00
Argyrios Kyrtzidis 3b7793797f Extend stat query APIs to explicitly specify if the query is for
a file or directory, allowing just a stat call if a file descriptor
is not needed.

Doing just 'stat' is faster than 'open/fstat/close'.
This has the effect of cutting down system time for validating the input files of a PCH.

llvm-svn: 169831
2012-12-11 07:48:23 +00:00
Richard Smith bd3051272c PR14558: Compute triviality of special members (etc) at the end of the class
definition, rather than at the end of the definition of the set of nested
classes. We still defer checking of the user-specified exception specification
to the end of the nesting -- we can't check that until we've parsed the
in-class initializers for non-static data members.

llvm-svn: 169805
2012-12-11 01:14:52 +00:00
Daniel Jasper a4396865d0 Addi formatting tests for pointer template parameters.
Fix spacing before ",".

llvm-svn: 169746
2012-12-10 18:59:13 +00:00
Alexander Kornienko 2ca766f32a Clang-format: error recovery for access specifiers
Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits

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

llvm-svn: 169738
2012-12-10 16:34:48 +00:00
Manuel Klimek e792efd7ba Adding tests since when I was asked whether this works I wasn't
100% sure.

llvm-svn: 169725
2012-12-10 07:08:53 +00:00
Daniel Jasper 2723403f9e Small tweaks to clang-format.
Now not joining keywords with '::' and not putting a space between
a pointer pointer.

llvm-svn: 169594
2012-12-07 09:52:15 +00:00
Fariborz Jahanian 19cd502a1d Fixes Makefile for Format unit tests.
llvm-svn: 169554
2012-12-06 22:29:01 +00:00
Alexander Kornienko 578fdd8968 Clang-format: IndentCaseLabels option, proper namespace handling
Summary: + tests arranged in groups, as their number is already quite large.

Reviewers: djasper, klimek

Reviewed By: djasper

CC: cfe-commits

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

llvm-svn: 169520
2012-12-06 18:03:27 +00:00
Alexander Kornienko ecdc7507ab Clang-format: detect unbalanced braces.
Reviewers: klimek, djasper

Reviewed By: klimek

CC: cfe-commits, silvas

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

llvm-svn: 169518
2012-12-06 17:49:17 +00:00
Manuel Klimek c844a46e77 Implements multiple parents in the parent map.
Previously we would match the last visited parent, which in the
case of template instantiations was the last instantiated template.

llvm-svn: 169508
2012-12-06 14:42:48 +00:00
Daniel Jasper 26333c3b6b Improve clang-format's handling of unary operators.
llvm-svn: 169500
2012-12-06 13:16:39 +00:00
Daniel Jasper e9de260418 "<<" alignment for clang-format.
Also, small fix for handling the first token correctly.

Review: http://llvm-reviews.chandlerc.com/D177
llvm-svn: 169488
2012-12-06 09:56:08 +00:00
Fariborz Jahanian de872af437 In DeclPrint add printing of '= default'
in constructors.

llvm-svn: 169440
2012-12-05 22:53:06 +00:00
Fariborz Jahanian 69c403c5c9 In DeclPrint add printing of 'explicit'
constructors.

llvm-svn: 169435
2012-12-05 22:19:06 +00:00
Fariborz Jahanian ae638b3f91 fix comment.
llvm-svn: 169413
2012-12-05 20:10:11 +00:00
Fariborz Jahanian 14ef4790d1 Testing C++ declarations embedded in
<declaration> tag of Comment XML.
Added DeclPrint support for constructors
and fix tests accordingly.
This is wip. // rdar://12378714

llvm-svn: 169412
2012-12-05 19:54:11 +00:00
Alexander Kornienko 37d6c94e28 Clang-format: parse for and while loops
Summary: Adds support for formatting for and while loops.

Reviewers: djasper, klimek

Reviewed By: klimek

CC: cfe-commits

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

llvm-svn: 169387
2012-12-05 15:06:06 +00:00
Daniel Jasper aa1c920db8 Indentation fixes for clang-format.
- Fix behavior of memoization together with optimization
- Correctly attribute the PenaltyIndentLevel (breaking directly after "(" did
  not count towards the inner level)
- Recognize more tokens as assignments

Review: http://llvm-reviews.chandlerc.com/D172
llvm-svn: 169384
2012-12-05 14:57:28 +00:00
Daniel Jasper 426702dcd0 Small tweaks to automatic formatting.
Recognize '!=' as a binary operator and assume that there are no
type definitions on the RHS of an assignment.

llvm-svn: 169363
2012-12-05 07:51:39 +00:00
Alexander Kornienko 870f9eb9cc Error recovery part 2
Summary: Adds recovery for structural errors in clang-format.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, silvas

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

llvm-svn: 169286
2012-12-04 17:27:50 +00:00
Alexander Kornienko 0ea8e107fc Clang-format error recovery part 1
Reviewers: klimek

CC: cfe-commits

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

llvm-svn: 169278
2012-12-04 15:40:36 +00:00
Alexander Kornienko b7076a2308 Enum formatting implementation
Reviewers: djasper, klimek

Reviewed By: klimek

CC: cfe-commits

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

llvm-svn: 169272
2012-12-04 14:46:19 +00:00
Manuel Klimek 6137942d09 Fix spelling I ran over while proof-reading tests.
llvm-svn: 169271
2012-12-04 14:42:08 +00:00
Manuel Klimek 5472a52c20 Fixes crash in isDerivedFrom for recursive templates.
llvm-svn: 169262
2012-12-04 13:40:29 +00:00
Daniel Jasper 8b5297117b Small fixes to unary operator recognition and handling of include
directives.

llvm-svn: 169261
2012-12-04 13:02:32 +00:00
Daniel Jasper 9f501295bd Add parameterCountIs() matcher.
llvm-svn: 169257
2012-12-04 11:54:27 +00:00
Daniel Jasper 9b155475a8 Replace workarounds with correct fixes.
Also fix header guard.

http://llvm-reviews.chandlerc.com/D159

llvm-svn: 169254
2012-12-04 10:50:12 +00:00
Chandler Carruth fa0b3bb7ec Really sort the #include lines in unittests/...
I forgot to re-sort after fixing main module headers.

llvm-svn: 169244
2012-12-04 09:53:37 +00:00
Chandler Carruth 320d9666ee Sort the #include lines for unittests/...
I've tried to place sensible headers at the top as main-module headers.

llvm-svn: 169243
2012-12-04 09:45:34 +00:00
NAKAMURA Takumi 1f58e8e194 ASTTests, ASTMatchersTests: Move clangEdit before clangAst in USEDLIB.
llvm-svn: 169236
2012-12-04 08:20:41 +00:00
NAKAMURA Takumi b25f3f7dcb Untabify (in USEDLIBS, Makefile(s)).
llvm-svn: 169235
2012-12-04 08:20:35 +00:00
NAKAMURA Takumi 0e0c3aa560 clang/Lex: [CMake] Update CMakefiles since r169229.
llvm-svn: 169233
2012-12-04 07:40:33 +00:00
Argyrios Kyrtzidis f3d587ea7c Refactor recording the preprocessor conditional directive regions out of
PreprocessingRecord and into its own class, PPConditionalDirectiveRecord.

Decoupling allows a client to use the functionality of PPConditionalDirectiveRecord
without needing a PreprocessingRecord.

llvm-svn: 169229
2012-12-04 07:27:05 +00:00
Argyrios Kyrtzidis 251ad5e06b Introduce CompilationDatabase::getAllCompileCommands() that returns all
compile commands of the database and expose it via the libclang API.

llvm-svn: 169226
2012-12-04 07:26:44 +00:00
Daniel Jasper f793511579 Initial version of formatting library.
This formatting library will be used by a stand-alone clang-format tool
and can also be used when writing other refactorings.

Manuel's original design document:
https://docs.google.com/a/google.com/document/d/1gpckL2U_6QuU9YW2L1ABsc4Fcogn5UngKk7fE5dDOoA/edit

The library can already successfully format itself.

Review: http://llvm-reviews.chandlerc.com/D80
llvm-svn: 169137
2012-12-03 18:12:45 +00:00
Daniel Jasper 856194d00c Make hasDeclaration work for enums.
llvm-svn: 169129
2012-12-03 15:43:25 +00:00
Benjamin Kramer e5015e57c2 Update unit tests not to rely on transitive includes.
llvm-svn: 169096
2012-12-01 17:22:05 +00:00
Douglas Gregor 8c05893746 Fix unit tests for ModuleLoader change in r168961.
llvm-svn: 168962
2012-11-30 00:01:57 +00:00
Richard Smith f41d237bf6 Remove out-of-date comment.
llvm-svn: 168957
2012-11-29 23:09:57 +00:00
NAKAMURA Takumi c2b2b75bd5 ASTTests/StmtPrinterTest/StmtPrinter.TestMSIntegerLiteral: Remove i128 stuff. Conditioning-out in macro argument was not accepted on MS cl.exe.
llvm-svn: 168867
2012-11-29 10:22:40 +00:00
NAKAMURA Takumi b2df62570e ASTTests/StmtPrinterTest/StmtPrinter.TestMSIntegerLiteral: Suppress i128 according to r168856, for now.
I think "i128", that I conditioned out, could be completely removed.
MS Compiler doesn't accept i128. We can assume no one would use i128.

llvm-svn: 168865
2012-11-29 09:57:11 +00:00
Richard Smith 9219d1b764 Allow an ASTConsumer to selectively skip function bodies while parsing. Patch
by Olivier Goffart!

llvm-svn: 168726
2012-11-27 21:31:01 +00:00
Daniel Jasper 94a56856d2 Fix partial-match-bind-behavior with forEachDescendant() matchers.
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
2012-11-16 18:39:22 +00:00
NAKAMURA Takumi fe40a35075 clang/unittests: Fixup corresponding to Doug's r168136.
llvm-svn: 168137
2012-11-16 04:40:11 +00:00
Daniel Jasper 0f9f019ff8 Do not use data recursion in ASTMatchFinder.
The matchers rely on the complete AST being traversed as shown by the new test cases.

llvm-svn: 168022
2012-11-15 03:29:05 +00:00
Daniel Jasper 33806cdefc Fix binding of nodes in case of forEach..() matchers.
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
2012-11-11 22:14:55 +00:00
David Blaikie 3a0de21233 Fix a source range regression in C++ new expressions with call initializers.
Introduced in r167507, discovered in review by Abramo Bagnara.

llvm-svn: 167597
2012-11-08 22:53:48 +00:00
Abramo Bagnara 341ab737e9 Fixed converted ConstantArrayTypeLoc range. Added a missing testcase for ConstructorDecl source range.
llvm-svn: 167583
2012-11-08 14:44:42 +00:00
Abramo Bagnara 9b836fb019 Fixed range of implicit MemberExpr.
llvm-svn: 167581
2012-11-08 13:52:58 +00:00
David Blaikie b9db60fbce Test for source location range of new expressions fixed in r167507.
Patch by Philip Craig.

llvm-svn: 167538
2012-11-07 17:17:07 +00:00
Manuel Klimek e6de22d3dc Add unit tests for source locations of AST nodes.
Patch by Philip Craig.

llvm-svn: 167470
2012-11-06 17:31:40 +00:00
Benjamin Kramer f9db130715 Escape trigraphs in unittest.
llvm-svn: 167359
2012-11-03 20:58:26 +00:00
Manuel Klimek bd0e2b7111 Insert interception point onStartOfTranslationUnit.
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
2012-11-02 01:31:03 +00:00
Argyrios Kyrtzidis 2edbc86809 Make the FilenameRange of the InclusionDirective callback more accurate,
preserve the macro location of the range end if the filename came from a macro.

Patch by Kim Gräsman!

llvm-svn: 167239
2012-11-01 17:52:58 +00:00
Daniel Jasper 6fc3433b15 Implement descendant matchers for NestedNamespecifiers
This implements has(), hasDescendant(), forEach() and
forEachDescendant() for NestedNameSpecifier and NestedNameSpecifierLoc
matchers.

Review: http://llvm-reviews.chandlerc.com/D86
llvm-svn: 167017
2012-10-30 15:42:00 +00:00