| Commit message (Collapse) | Author | Age | Files | Lines |
... | |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Summary:
Fixes a problem where \t,\v or \f could lead to a crash when placed as
a first character in a line comment. The cause is that rtrim and ltrim handle
these characters, but our code didn't, so some invariants could be broken.
Reviewers: klimek
Reviewed By: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D1013
llvm-svn: 184425
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
comments.
Summary:
A trailing block comment having multiple lines would cause extremely
high penalties if the summary length of its lines is more than the column limit.
Fixed by always considering only the last line of a multi-line block comment.
Removed a long-standing FIXME from relevant tests and added a motivating test
modelled after problem cases from real code.
Reviewers: klimek
Reviewed By: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D1010
llvm-svn: 184340
|
|
|
|
|
|
|
|
|
|
|
|
| |
Summary: Split strings at word boundaries, when there are no spaces and slashes.
Reviewers: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D1003
llvm-svn: 184304
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
indentation of an expression after a line break.
Summary:
E.g. the second line in
return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
b; //
is indented 4 characters more than in
return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
b;
Reviewers: klimek
Reviewed By: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D984
llvm-svn: 184078
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Summary:
Selectively propagate the information about token kind in
WhitespaceManager::replaceWhitespaceInToken.For correct alignment of new
segments of line comments in order to align them correctly. Don't set
BreakBeforeParameter in breakProtrudingToken for line comments, as it introduces
a break after the _next_ parameter. Added tests for related functions.
Reviewers: klimek
Reviewed By: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D980
llvm-svn: 184076
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Summary:
Don't remove backslashes from block comments. Previously this
/* \ \ \ \ \ \
*/
would be turned to this:
/*
*/
which spoils some kinds of ASCII-art, people use in their comments. The behavior
was related to handling escaped newlines in block comments inside preprocessor
directives. This patch makes handling it in a more civilized way.
Reviewers: klimek
Reviewed By: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D979
llvm-svn: 183978
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Summary:
Basically, don't special-case line comments in this regard. And fixed
an incorrect test, that relied on the wrong behavior.
Reviewers: klimek
Reviewed By: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D962
llvm-svn: 183851
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
alphanumeric character.
Summary:
"//Test" becomes "// Test". This change is aimed to improve code
readability and conformance to certain coding styles. If a comment starts with a
non-alphanumeric character, the space isn't added, e.g. "//-*-c++-*-" stays
unchanged.
Reviewers: klimek
Reviewed By: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D949
llvm-svn: 183750
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Summary: Remove them from the TokenText as well.
Reviewers: klimek
Reviewed By: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D935
llvm-svn: 183536
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Summary:
Introduced two new style parameters: PenaltyBreakComment and
PenaltyBreakString. Add penalty for each character of a breakable token beyond
the column limit (this relates mainly to comments, as they are broken only on
whitespace). Tuned PenaltyBreakComment to prefer comment breaking over breaking
inside most binary expressions.
Fixed a bug that prevented *, & and && from being considered TT_BinaryOperator
in the presense of adjacent comments.
Reviewers: klimek, djasper
Reviewed By: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D933
llvm-svn: 183530
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Before, clang-format would happily move a trailing block comment to a
new line, which normally changes the perceived binding of that comment.
E.g., it would move:
void f() { /* comment */
...
}
to:
void f() {
/* comment */
...
}
llvm-svn: 183420
|
|
|
|
|
|
|
|
| |
The leading "}" in the construct "} else if (..) {" was confusing the
expression parser. Thus, no fake parentheses were generated and the
indentation was broken in some cases.
llvm-svn: 183393
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Before:
return (my_int) aaaa;
template <> void f<int>(int i)SOME_ANNOTATION;
f("aaaa" SOME_MACRO(aaaa)"aaaa");
After:
return (my_int)aaaa;
template <> void f<int>(int i) SOME_ANNOTATION;
f("aaaa" SOME_MACRO(aaaa) "aaaa");
llvm-svn: 183389
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Summary:
Detect if the file is valid UTF-8, and if this is the case, count code
points instead of just using number of bytes in all (hopefully) places, where
number of columns is needed. In particular, use the new
FormatToken.CodePointCount instead of TokenLength where appropriate.
Changed BreakableToken implementations to respect utf-8 character boundaries
when in utf-8 mode.
Reviewers: klimek, djasper
Reviewed By: djasper
CC: cfe-commits, rsmith, gribozavr
Differential Revision: http://llvm-reviews.chandlerc.com/D918
llvm-svn: 183312
|
|
|
|
| |
llvm-svn: 183115
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
These lines almost never aid readability.
Before:
void f() {
int i; // some variable
}
After:
void f() {
int i; // some variable
}
llvm-svn: 183112
|
|
|
|
|
|
|
|
|
|
| |
An oversight in this detection made clang-format unable to format
the following nicely:
void aaaaaaaaaaaaaaaaaaa<aaaaaaaaaaaaaaaaaaaaaaaaaaa,
bbbbbbbbbbbbbbbbbbbbbbbbbb>(
cccccccccccccccccccccccccccc);
llvm-svn: 183097
|
|
|
|
|
|
|
|
|
|
| |
Before, clang-format would not find a solution for formatting:
if ((aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ||
bbbbbbbbbbbbbbbbbb) && // aaaaaaaaaaaaaaaa
cccccc) {
}
llvm-svn: 183096
|
|
|
|
|
|
| |
Before: return a<b &&c> d;
After: return a < b && c > d;
llvm-svn: 183077
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Before:
x[(uint8) y];
x = (uint8) y;
void f() { x = (uint8) y; }
#define AA(X) sizeof(((X *) NULL)->a)
After:
x[(uint8)y];
x = (uint8)y;
void f() { x = (uint8)y; }
#define AA(X) sizeof(((X *)NULL)->a)
llvm-svn: 183014
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
If a "}" is found inside parenthesis, this is probably a case of
missing parenthesis. This enables continuing to format after stuff code
like:
class A {
void f(
};
..
llvm-svn: 183009
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
With this patch, the simplified rule is:
If the block is part of a declaration (class, namespace, function,
enum, ..), merge an empty block onto a single line. Otherwise
(specifically for the compound statements of if, for, while, ...),
keep the braces on two separate lines.
The reasons are:
- Mostly the formatting of empty blocks does not matter much.
- Empty compound statements are really rare and are usually just
inserted while still working on the code. If they are on two lines,
inserting code is easier. Also, overlooking the "{}" of an
"if (...) {}" can be really bad.
- Empty declarations are not uncommon, e.g. empty constructors. Putting
them on one line saves vertical space at no loss of readability.
llvm-svn: 183008
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Before:
bool aaaaaa = aaaaaaaaaaaaa //
? aaaaaaaaaaaaaaa
: bbbbbbbbbbbbbbb //
? ccccccccccccccc
: ddddddddddddddd;
After:
bool aaaaaa = aaaaaaaaaaaaa //
? aaaaaaaaaaaaaaa
: bbbbbbbbbbbbbbb //
? ccccccccccccccc
: ddddddddddddddd;
llvm-svn: 183007
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Before:
foo = aaaaaaaaaaa ? vector<int> {
aaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa, aaaaa
}
: vector<int>{ bbbbbbbbbbbbbbbbbbbbbbbbbbb, bbbbbbbbbbbbbbbbbbbb, bbbbb };
After:
foo = aaaaaaaaaaa ? vector<int>{ aaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaa, aaaaa }
: vector<int>{ bbbbbbbbbbbbbbbbbbbbbbbbbbb,
bbbbbbbbbbbbbbbbbbbb, bbbbb };
llvm-svn: 182992
|
|
|
|
| |
llvm-svn: 182940
|
|
|
|
|
|
|
|
|
|
| |
This fixes:
/*
*
* something long going over the column limit.
*/
llvm-svn: 182932
|
|
|
|
| |
llvm-svn: 182916
|
|
|
|
|
|
|
|
|
| |
Smallest reproduction:
/*
**
*/
llvm-svn: 182913
|
|
|
|
|
|
|
|
| |
When trying to fall back to search from the end onwards, we
would still find leading whitespace if the leading whitespace
went on after the end of the line.
llvm-svn: 182886
|
|
|
|
|
|
|
|
|
| |
Now that the TokenAnnotator does not require stack space anymore,
reconstructing the lines has become the limiting factor. This patch
fixes that problem, allowing large files with multiple megabytes of
single unwrapped lines to be formatted.
llvm-svn: 182861
|
|
|
|
|
|
|
|
|
|
| |
Gets rid of AnnotatedToken, putting everything into FormatToken.
FormatTokens are created once, and only referenced by pointer. This
enables multiple future features, like having tokens shared between
multiple UnwrappedLines (while there's still work to do to fully enable
that).
llvm-svn: 182859
|
|
|
|
| |
llvm-svn: 182856
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
If an identifier is on its own line and it is all upper case, it is highly
likely that this is a macro that is meant to stand on a line by itself.
Before:
class A : public QObject {
Q_OBJECT A() {}
};
Ater:
class A : public QObject {
Q_OBJECT
A() {}
};
llvm-svn: 182855
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
With option enabled (e.g. in Google-style):
template <typename T>
void f() {}
With option disabled:
template <typename T> void f() {}
Enabling this for Google-style and Chromium-style, not sure which other
styles would prefer that.
llvm-svn: 182849
|
|
|
|
| |
llvm-svn: 182796
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This made it necessary to remove an error detection which would let us
bail out of braced lists in certain situations of missing "}". However,
as we always entirely escape from the braced list on finding ";", this
should not be a big problem.
With this, we can no format braced lists with uniformat inits:
return { arg1, SomeType { parameter } };
llvm-svn: 182788
|
|
|
|
|
|
|
|
|
| |
Before: f( (*PointerToArray)[10]);
After: f((*PointerToArray)[10]);
This fixes llvm.org/PR16163
llvm-svn: 182777
|
|
|
|
|
|
| |
The FormatToken is now not copyable any more.
llvm-svn: 182772
|
|
|
|
|
|
|
|
|
|
|
| |
With this patch, we create all tokens in one go before parsing and pass
an ArrayRef<FormatToken*> to the UnwrappedLineParser. The
UnwrappedLineParser is switched to use pointer-to-token internally.
The UnwrappedLineParser still copies the tokens into the UnwrappedLines.
This will be fixed in an upcoming patch.
llvm-svn: 182768
|
|
|
|
| |
llvm-svn: 182767
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
To fully support this, we also need to expand tabs in the text before
the block comment. This patch breaks indentation when there was a
non-standard mixture of spaces and tabs used for indentation, but
fixes a regression in the simple case:
{
/*
* Comment.
*/
int i;
}
Is now formatted correctly, if there were tabs used for indentation
before.
llvm-svn: 182760
|
|
|
|
|
|
|
|
|
|
|
| |
Block comment indentation of empty lines regressed, as we did not
have a test for it.
/* Comment with...
*
* empty line. */
is now formatted correctly again.
llvm-svn: 182757
|
|
|
|
|
|
|
|
|
|
|
|
| |
Before:
int (*func)(void*);
void f() { int(*func)(void*); }
After (consistent space after "int"):
int (*func)(void*);
void f() { int (*func)(void*); }
llvm-svn: 182756
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This gets turned into two ">" operators at the beginning in order to
simplify template parameter handling. Thus, we need a special case to
handle those two binary operators correctly.
With this patch, clang-format can now correctly handle cases like:
aaaaaa = aaaaaaa(aaaaaaa, // break
aaaaaa) >>
bbbbbb;
llvm-svn: 182754
|
|
|
|
| |
llvm-svn: 182742
|
|
|
|
|
|
|
|
|
| |
Before: A < int&& > a;
After: A<int &&> a;
Also remove obsolete FIXMEs.
llvm-svn: 182741
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Unify handling of whitespace when breaking protruding tokens with other
whitespace replacements.
As a side effect, the BreakableToken structure changed significantly:
- have a common base class for single-line breakable tokens, as they are
much more similar
- revamp handling of multi-line comments; we now calculate the
information about lines in multi-line comments similar to normal
tokens, and always issue replacements
As a result, we were able to get rid of special casing of trailing
whitespace deletion for comments in the whitespace manager and the
BreakableToken and fixed bugs related to tab handling and escaped
newlines.
llvm-svn: 182738
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Before:
unsigned OriginalStartColumn = SourceMgr.getSpellingColumnNumber(
Current.FormatTok.getStartOfNonWhitespace()) -
1;
After:
unsigned OriginalStartColumn =
SourceMgr.getSpellingColumnNumber(
Current.FormatTok.getStartOfNonWhitespace()) -
1;
llvm-svn: 182733
|
|
|
|
| |
llvm-svn: 182732
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
In general, we like to avoid line breaks like:
...
SomeParameter, OtherParameter).DoSomething(
...
as they tend to make code really hard to read (how would you even indent the
next line?). Previously we have implemented this in a hacky way, which has now
shown to lead to problems. This fixes a few weird looking formattings, such as:
Before:
aaaaa(
aaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
.aaaaa(aaaaa),
aaaaaaaaaaaaaaaaaaaaa);
After:
aaaaa(aaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa).aaaaa(aaaaa),
aaaaaaaaaaaaaaaaaaaaa);
llvm-svn: 182731
|