Commit Graph

664 Commits

Author SHA1 Message Date
Fariborz Jahanian 5b637078e1 [Doc parsing] Provide diagnostics for unknown documentation
commands. // rdar://12381408

llvm-svn: 181071
2013-05-03 23:15:20 +00:00
Argyrios Kyrtzidis 37e48ff547 [Preprocessor] For the MacroExpands preprocessor callback, also pass the MacroArgs object that provides information about
the argument tokens for a function macro.

llvm-svn: 181065
2013-05-03 22:31:32 +00:00
Daniel Jasper 72463d32e0 Add space between ; and (.
Before: for (int i = 0;(i < 10); ++i) {}
After:  for (int i = 0; (i < 10); ++i) {}
llvm-svn: 181020
2013-05-03 14:50:50 +00:00
Daniel Jasper c37de30219 Fix expression recognition in for-loops.
Before: for (; a&& b;) {}
After:  for (; a && b;) {}
llvm-svn: 181017
2013-05-03 14:41:24 +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
Daniel Jasper e3c0e0144e Improve clang-format's memoization behavior.
Deeply nested expressions basically break clang-format's memoization.
This patch slightly improves the situations and makes expressions like

  aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(
      aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(
          aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(
              aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(
                  aaaaa(aaaaa())))))))))))))))))))))))))))))))))))))));

work.

llvm-svn: 180264
2013-04-25 13:31:51 +00:00
Daniel Jasper 6fe2f009df Add option to align escaped newlines left.
This enables formattings like:

  #define A   \
    int aaaa; \
    int b;    \
    int ccc;  \
    int dddddddddd;

Enabling this for Google/Chromium styles only as I don't know whether it
is desired for Clang/LLVM.

llvm-svn: 180253
2013-04-25 08:56:26 +00:00
Daniel Jasper 770eb7c5f9 Fix comment alignment behavior.
In the following snippet, clang-format incorrectly aligned the
trailing comment, when only the last line was formatted:

  int aaaaaa; // comment
  int b;
  int c; // Formatting only this line moved this comment.

llvm-svn: 180173
2013-04-24 06:33:59 +00:00
Daniel Jasper 4431aa99ab Fix formatting of complex #if expressions.
Before:
  #if !defined(AAAAAAAAAAAAAAAA) && (defined CCCCCCCC ||                         \
                                     defined DDDDDDDD) && defined(BBBBBBBB)

After:
  #if !defined(AAAAAAAAAAAAAAAA) && (defined CCCCCCCC || defined DDDDDDDD) &&    \
      defined(BBBBBBBB)

This fixes llvm.org/PR15828.

llvm-svn: 180105
2013-04-23 13:54:04 +00:00
Daniel Jasper cc960fa645 Fix bin-packing behavior of constructor initialziers.
In Google style, constructor initializers need to be all on one line or
one initializer per line if that does not fit. Without this patch, this
non-bin-packing-behavior incorrectly extends to the parameters of the
initializers.

Before:
Constructor()
    : aaaaa(aaaaaaaaaaaaaaaaaaaaaa,
            aaaaaaaaaaaaaaaaaaaaaa,
            aaaaaaaaaaaaaaaaaaaaaa) {}

After:
Constructor()
    : aaaaa(aaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaa,
            aaaaaaaaaaaaaaaaaaaaaa) {}

llvm-svn: 180001
2013-04-22 07:59:53 +00:00
Alexander Kornienko 9e90b62e01 Unified token breaking logic: support for line comments.
Summary:
Added BreakableLineComment, moved common code from
BreakableBlockComment to newly added BreakableComment. As a side-effect of the
rewrite, found another problem with escaped newlines and had to change
code which removes trailing whitespace from line comments not to break after
this patch.

Reviewers: klimek, djasper

Reviewed By: klimek

CC: cfe-commits

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

llvm-svn: 179693
2013-04-17 17:34:05 +00:00
Daniel Jasper 1b8e76f14e Break after multiline parameters.
We do this in general, but missed a few cases.

Before:
void aaaaaaaaaaaaaaaaaaaaaaa(
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbb bbbb);

After:
void aaaaaaaaaaaaaaaaaaaaaaa(
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
    bbbb bbbb);

llvm-svn: 179570
2013-04-15 22:36:37 +00:00
Alexander Kornienko cb45bc1861 Unified token breaking logic for strings and block comments.
Summary:
Both strings and block comments are broken into lines in
breakProtrudingToken. Logic specific for strings or block comments is abstracted
in implementations of the BreakToken interface. Among other goodness, this
change fixes placement of backslashes after a block comment inside a
preprocessor directive (see removed FIXMEs in unit tests).

The code is far from being polished, and some parts of it will be changed for
line comments support.

Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits

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

llvm-svn: 179526
2013-04-15 14:28:00 +00:00
Manuel Klimek 1a18c40468 Revamps structural error detection / handling.
Previously we'd only detect structural errors on the very first level.
This leads to incorrectly balanced braces not being discovered, and thus
incorrect indentation.

This change fixes the problem by:
- changing the parser to use an error state that can be detected
  anywhere inside the productions, for example if we get an eof on
  SOME_MACRO({ some block <eof>
- previously we'd never break lines when we discovered a structural
  error; now we break even in the case of a structural error if there
  are two unwrapped lines within the same line; thus,
  void f() { while (true) { g(); y(); } }
  will still be re-formatted, even if there's missing braces somewhere
  in the file
- still exclude macro definitions from generating structural error;
  macro definitions are inbalanced snippets

llvm-svn: 179379
2013-04-12 14:13:36 +00:00
Daniel Jasper 6728fc11bc Change clang-format's affinity for breaking after return types.
Function declarations are now broken with the following preferences:
1) break amongst arguments.
2) break after return type.
3) break after (.
4) break before after nested name specifiers.

Options #2 or #3 are preferred over #1 only if a substantial number of
lines can be saved by that.

llvm-svn: 179287
2013-04-11 14:29:13 +00:00
Daniel Jasper 6e8f4edf2d Fix formatting of overloaded assignment operators.
Before: SomeType &operator=(const SomeType & S);
After:  SomeType &operator=(const SomeType &S);
llvm-svn: 179270
2013-04-11 08:48:20 +00:00
Manuel Klimek a3ff45ebed Fixes recovering from errors when parsing braced init lists.
Before we would build huge unwrapped lines which take a long time
to optimze.

llvm-svn: 179168
2013-04-10 09:52:05 +00:00
Daniel Jasper c04baae34a Fix labels with trailing comments and cleanup.
Before:
class A {
public : // test
};

After:
class A {
public: // test
};

Also remove duplicate methods calculating properties of AnnotatedTokens
and make them members of AnnotatedTokens so that they are in a common
place.

llvm-svn: 179167
2013-04-10 09:49:49 +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 b67cc423eb Fix comments before labels.
Before:
switch (...) {
  // a
  // b
// c
case first:
  break;
}

After:
switch (...) {
// a
// b
// c
case first:
  break;
}

llvm-svn: 179107
2013-04-09 17:46:55 +00:00
Alexander Kornienko a04e5e213b Again macros without trailing semicolons: don't care about declaration context.
Summary:
Some codebases use these kinds of macros in functions, e.g. Chromium's
IPC_BEGIN_MESSAGE_MAP, IPC_BEGIN_MESSAGE_HANDLER, etc.

Reviewers: djasper, klimek

Reviewed By: klimek

CC: cfe-commits

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

llvm-svn: 179099
2013-04-09 16:15:19 +00:00
Alexander Kornienko de64427ac6 Recognize function-like macro usages without semicolon in declaration context.
Summary:
Preserve line breaks after function-like macro usages without
semicolon, e.g.:

QQQ(xxx)
class X {
};

Reviewers: djasper, klimek

Reviewed By: djasper

CC: cfe-commits

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

llvm-svn: 179064
2013-04-08 22:16:06 +00:00
Daniel Jasper 6bee682fae Revamp indentation behavior for complex binary expressions.
The idea is to indent according to operator precedence and pretty much
identical to how stuff would be indented with parenthesis.

Before:
bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
             aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
             aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
             aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *
             bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb +
             bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb &&
             aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *
             aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
             ccccccccccccccccccccccccccccccccccccccccc;

After:
  bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
                       aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
                       aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
                   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *
                           bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb +
                       bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb &&
               aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *
                       aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
                   ccccccccccccccccccccccccccccccccccccccccc;

llvm-svn: 179049
2013-04-08 20:33:42 +00:00
Daniel Jasper 9fcdc461ed Add matcher for NamespaceDecls.
llvm-svn: 179027
2013-04-08 16:44:05 +00:00
Daniel Jasper e7de2a3013 Revert accidental commit r179015.
llvm-svn: 179016
2013-04-08 10:45:44 +00:00
Daniel Jasper bd16eea59f x
llvm-svn: 179015
2013-04-08 10:36:32 +00:00
Tanya Lattner 713eef4f7c Add an error to check that all program scope variables are in the constant address space in OpenCL.
llvm-svn: 178906
2013-04-05 20:14:50 +00:00
Daniel Jasper 8319360099 Allow breaking after 'class' for classes with looong names.
(Don't ask, this was a user request).

llvm-svn: 178888
2013-04-05 17:22:09 +00:00
Daniel Jasper 54ac820890 Fix bad formatting of overloaded operator definitions.
Before:
bool operator<
    (const aaaaaaaaaaaaaaaaaaaaa &left, const aaaaaaaaaaaaaaaaaaaaa &right) {
  return left.group < right.group;
}

After:
bool operator<(const aaaaaaaaaaaaaaaaaaaaa &left,
               const aaaaaaaaaaaaaaaaaaaaa &right) {
  return left.group < right.group;
}

llvm-svn: 178887
2013-04-05 17:21:59 +00:00
Daniel Jasper 31c96b9c7e Improve formatting of multi-variable DeclStmts.
This fixed llvm.org/PR15670

Before:
aaaaaaaaa a = aaaaaaaaaaaaaaaaaaaa, b = bbbbbbbbbbbbbbbbbbbb,
                                    c = cccccccccccccccccccc,
                                    d = dddddddddddddddddddd;
aaaaaaaaa *a = aaaaaaaaaaaaaaaaaaa, *b = bbbbbbbbbbbbbbbbbbb,
                                     *c = ccccccccccccccccccc,
                                      *d = ddddddddddddddddddd;

After:
aaaaaaaaa a = aaaaaaaaaaaaaaaaaaaa, b = bbbbbbbbbbbbbbbbbbbb,
          c = cccccccccccccccccccc, d = dddddddddddddddddddd;
aaaaaaaaa *a = aaaaaaaaaaaaaaaaaaa, *b = bbbbbbbbbbbbbbbbbbb,
          *c = ccccccccccccccccccc, *d = ddddddddddddddddddd;

llvm-svn: 178860
2013-04-05 09:38:50 +00:00
Daniel Jasper a628c98bd3 Improve formatting of for loops and multi-variable DeclStmts.
This combines several related changes:
a) Don't break before after the variable types in for loops with a
   single variable.
b) Better indent DeclStmts defining multiple variables.

Before:
bool aaaaaaaaaaaaaaaaaaaaaaaaa =
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaa),
     bbbbbbbbbbbbbbbbbbbbbbbbb =
         bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(bbbbbbbbbbbbbbbb);
for (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
         aaaaaaaaaaa = aaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaa;
     aaaaaaaaaaa != aaaaaaaaaaaaaaaaaaa; ++aaaaaaaaaaa) {
}

After:
bool aaaaaaaaaaaaaaaaaaaaaaaaa =
         aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaa),
     bbbbbbbbbbbbbbbbbbbbbbbbb =
         bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(bbbbbbbbbbbbbbbb);
for (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaa =
         aaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaa;
     aaaaaaaaaaa != aaaaaaaaaaaaaaaaaaa; ++aaaaaaaaaaa) {
}

llvm-svn: 178641
2013-04-03 13:36:17 +00:00
Alexander Kornienko b1be9d6e74 Even better way to handle comments adjacent to preprocessor directives.
Summary:
It turns out that we don't need to store CommentsBeforeNextToken in the
line state, but rather flush them before we start parsing preprocessor
directives. This fixes wrong comment indentation in code blocks in macro calls
(the test is included).

Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits

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

llvm-svn: 178638
2013-04-03 12:38:53 +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
Daniel Jasper c238c87e12 Fix some inconsistent use of indentation.
Basically we have always special-cased the top-level statement of an
unwrapped line (the one with ParenLevel == 0) and that lead to several
inconsistencies. All added tests were formatted in a strange way, for
example:

Before:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa();
if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
        .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
            .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()) {
}

After:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa();
if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
        .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
        .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
        .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()) {
}

llvm-svn: 178542
2013-04-02 14:33:13 +00:00
Alexander Kornienko b5dad75e38 Alternative handling of comments adjacent to preprocessor directives.
Summary: Store comments in ScopedLineState

Reviewers: klimek, djasper

Reviewed By: klimek

CC: cfe-commits

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

llvm-svn: 178537
2013-04-02 13:04:06 +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
Daniel Jasper 6e42b1eb8b Improve formatting of function types.
Before: void * (*a)(int *, SomeType *);
After:  void *(*a)(int *, SomeType *);
llvm-svn: 178474
2013-04-01 17:13:26 +00:00
Alexander Kornienko efd98385c0 Fixed handling of comments before preprocessor directives.
Comments before preprocessor directives used to be stored with InPPDirective
flag set, which prevented correct comment splitting in this case. Fixed by
flushing comments before switching on InPPDirective. Added a new test and fixed
one of the existing tests.

llvm-svn: 178261
2013-03-28 18:40:55 +00:00
Alexander Kornienko fd433365e0 Insert extra new line before access specifiers.
Summary: Insert extra new line before access specifiers.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

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

llvm-svn: 178149
2013-03-27 17:08:02 +00:00
Alexander Kornienko ffd6d04a43 Split line comments
Summary:
Split line comments that exceed column limit + fixed leading whitespace
handling when splitting block comments.

Reviewers: djasper, klimek

Reviewed By: djasper

CC: cfe-commits

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

llvm-svn: 178133
2013-03-27 11:52:18 +00:00
Daniel Jasper dd9276e464 Better fix for r177725.
It turns out that

-foo;

can be an objective C method declaration. So instead of the previous
solution, recognize objective C methods only if we are in a declaration
scope.

llvm-svn: 177740
2013-03-22 16:55:40 +00:00
Daniel Jasper bc0fa39d69 Align comments to surrounding unformatted comments.
Before:
int a; // not formatted
// formatting this line only

After:
int a; // not formatted
       // formatting this line only

This makes clang-format stable independent of whether the whole
file or single lines are formatted in most cases.

llvm-svn: 177739
2013-03-22 16:25:51 +00:00
Daniel Jasper 399d1ee5a0 More precisely recognize ObjC method declarations.
Otherwise, +/- and the beginning of constants can be recognized
incorrectly.

Before:  #define A - 1
After:   #define A -1
llvm-svn: 177725
2013-03-22 10:44:43 +00:00
Daniel Jasper 5521365248 Make clang-format understand more line comments.
Apparently one needs to set LangOptions.LineComment.

Before "//* */" got reformatted to "/ /* */" as the lexer was returning
the token sequence (slash, comment). This could also lead to weird other
stuff, e.g. for people that like to using comments like:
//****************

llvm-svn: 177720
2013-03-22 10:01:29 +00:00
Alexander Kornienko 547a9f5264 Better block comment formatting.
Summary:
1. When splitting one-line block comment, use indentation and *s.
2. Remove trailing whitespace from all lines of a comment, not only the ones being splitted.
3. Add backslashes for all lines if a comment is used insed a preprocessor directive.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

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

llvm-svn: 177635
2013-03-21 12:28:10 +00:00
Douglas Gregor fb9126578e <rdar://problem/12368093> Extend module maps with a 'conflict' declaration, and warn when a newly-imported module conflicts with an already-imported module.
llvm-svn: 177577
2013-03-20 21:10:35 +00:00
Alexander Kornienko 674be0a3da Support for pointers-to-members usage via .*
Summary: Added support for pointers-to-members usage via .* and a few tests.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

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

llvm-svn: 177537
2013-03-20 16:41:56 +00:00
Daniel Jasper 291f936351 Remove assertion that can be triggered on bad input.
clang-format can't do anything useful, so it should leave the remainder
of the line unchanged, but it should not assert/segfault.

llvm-svn: 177530
2013-03-20 15:58:10 +00:00
Daniel Jasper 1a32a61ad4 Fix infinite-loop in unwrapped line parser.
Discovered when accidentally formatting a python file :-).

llvm-svn: 177527
2013-03-20 15:12:38 +00:00
Daniel Jasper 66dc2ec30b Do not consider comments when adjusting to local indent style.
Before (when only reformatting "int b"):
int a; // comment
       // comment
       int b;

After:
int a; // comment
       // comment
int b;

This also fixes llvm.org/PR15433.

llvm-svn: 177524
2013-03-20 14:31:47 +00:00