Age | Commit message (Collapse) | Author |
|
LLVM/Clang basically don't use such comments and for Google-style,
include-lines are explicitly exempt from the column limit. Also, for
most cases, where the column limit is violated, the "better" solution
would be to move the comment to before the include, which clang-format
cannot do (yet).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181191 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
clang-format did not indent any declarations/definitions when breaking
after the type. With this change, it indents for all declarations but
does not indent for function definitions, i.e.:
Before:
const SomeLongTypeName&
some_long_variable_name;
typedef SomeLongTypeName
SomeLongTypeAlias;
const SomeLongReturnType*
SomeLongFunctionName();
const SomeLongReturnType*
SomeLongFunctionName() { ... }
After:
const SomeLongTypeName&
some_long_variable_name;
typedef SomeLongTypeName
SomeLongTypeAlias;
const SomeLongReturnType*
SomeLongFunctionName();
const SomeLongReturnType*
SomeLongFunctionName() { ... }
While it might seem inconsistent to indent function declarations, but
not definitions, there are two reasons for that:
- Function declarations are very similar to declarations of function
type variables, so there is another side to consistency to consider.
- There can be many function declarations on subsequent lines and not
indenting can make them harder to identify. Function definitions
are already separated by their body and not indenting
makes the function name slighly easier to find.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181187 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
This seems to be more common in LLVM, Google and Chromium.
Before:
class AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA :
public BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB,
public CCCCCCCCCCCCCCCCCCCCCCCCCCCCCC {
};
After:
class AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
: public BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB,
public CCCCCCCCCCCCCCCCCCCCCCCCCCCCCC {
};
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181183 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
Before: template <class ... Ts> void Foo(Ts ... ts) { Foo(ts ...); }
After: template <class... Ts> void Foo(Ts... ts) { Foo(ts...); }
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181182 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
commands. // rdar://12381408
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181071 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
MacroArgs object that provides information about
the argument tokens for a function macro.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181065 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
Before: for (int i = 0;(i < 10); ++i) {}
After: for (int i = 0; (i < 10); ++i) {}
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181020 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
Before: for (; a&& b;) {}
After: for (; a && b;) {}
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181017 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180808 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180264 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180253 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180173 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180105 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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) {}
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180001 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179693 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
We do this in general, but missed a few cases.
Before:
void aaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbb bbbb);
After:
void aaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
bbbb bbbb);
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179570 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179526 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179379 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179287 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
Before: SomeType &operator=(const SomeType & S);
After: SomeType &operator=(const SomeType &S);
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179270 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
Before we would build huge unwrapped lines which take a long time
to optimze.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179168 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179167 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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>
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179126 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
Before:
switch (...) {
// a
// b
// c
case first:
break;
}
After:
switch (...) {
// a
// b
// c
case first:
break;
}
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179107 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179099 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179064 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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;
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179049 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179027 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179016 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179015 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
address space in OpenCL.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178906 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
(Don't ask, this was a user request).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178888 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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;
}
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178887 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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;
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178860 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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) {
}
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178641 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178638 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
Updated tests and docs.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178556 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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()) {
}
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178542 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
Summary: Store comments in ScopedLineState
Reviewers: klimek, djasper
Reviewed By: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D609
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178537 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
Updated docs and tests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178487 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
Before: void * (*a)(int *, SomeType *);
After: void *(*a)(int *, SomeType *);
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178474 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178261 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178149 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178133 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177740 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177739 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
Otherwise, +/- and the beginning of constants can be recognized
incorrectly.
Before: #define A - 1
After: #define A -1
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177725 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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:
//****************
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177720 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177635 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
and warn when a newly-imported module conflicts with an already-imported module.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177577 91177308-0d34-0410-b5e6-96231b3b80d8
|