| Commit message (Collapse) | Author | Age | Files | Lines |
... | |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Very similar to what we do for record definitions:
- tighten down what is an enum definition, so that we don't mistake a
function for an enum
- allow common idioms around declarations (we'll want to handle that
more centrally in the future)
We now correctly format:
enum X f() {
a();
return 42;
}
llvm-svn: 173075
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
We now only put empty blocks into a single line, if all of:
- all tokens of the structural element fit into a single line
- we're not in a control flow statement
Note that we usually don't put record definitions into a single line, as
there's usually at least one more token (the semicolon) after the
closing brace. This doesn't hold when we are in a context where there is
no semicolon, like "enum E {}".
There were some missing tests around joining lines around the corner
cases of the allowed number of columns, so this patch adds some.
llvm-svn: 173055
|
|
|
|
|
|
|
|
|
|
|
| |
We now indent:
extern "C" {
int a;
}
without additional indent inside the extern "C" block.
llvm-svn: 173045
|
|
|
|
|
|
|
| |
Now correctly formats:
template <> class A<int> {} a;
llvm-svn: 173038
|
|
|
|
|
|
|
| |
Now correctly formats:
class A::B {} n;
llvm-svn: 173019
|
|
|
|
|
|
|
|
|
| |
Previously, we would not detect brace initializer lists in return
statements, thus:
return (a)(b) { 1, 2, 3 };
would put the semicolon onto the next line.
llvm-svn: 173017
|
|
|
|
|
|
|
|
|
|
| |
Manually fix the order of UnwrappedLineParser.cpp as that one didn't
have its associated header as the first header.
This also uncovered a subtle inclusion order dependency as CLog.h didn't
include LLVM.h to pick up using declarations it relied upon.
llvm-svn: 172892
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This patch prepares being able to test for and fix more problems (see
FIXME in the test for example).
Previously we would output unwrapped lines for preprocessor directives
at the point where we also parsed the hash token. Since often
projections only terminate (and thus output their own unwrapped line)
after peeking at the next token, this would lead to the formatter seeing
the preprocessor directives out-of-order (slightly earlier). To be able
to correctly identify lines to merge, the formatter needs a well-defined
order of unwrapped lines, which this patch introduces.
llvm-svn: 172819
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Before:
switch (foo) {
case a: {
int a = g();
h(a);
}
break;
}
Now:
switch (foo) {
case a: {
int a = g();
h(a);
} break;
}
llvm-svn: 172789
|
|
|
|
| |
llvm-svn: 172616
|
|
|
|
|
|
|
|
| |
Leave a quick "// Uncomment this." hint to enable the debug output in
tests. FIXME: figure out whether we want to enable debug command line
handling for all tests.
llvm-svn: 172608
|
|
|
|
| |
llvm-svn: 172606
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
It was quite convoluted leading to us accidentally introducing O(N^2)
complexity while copying from UnwrappedLine to AnnotatedLine. We might
still want to improve the datastructure in AnnotatedLine (most
importantly not put them in a vector where they need to be copied on
vector resizing but that will be done as a follow-up.
This fixes most of the regression in llvm.org/PR14959.
No formatting changes intended.
llvm-svn: 172602
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This switches to parsing record definitions only if we can clearly
identify them. We're specifically allowing common patterns for
visibility control through macros and attributes, but we cannot
currently fix all instances. This fixes all known bugs we have though.
Before:
static class A f() {
return g();
} int x;
After:
static class A f() {
return g();
}
int x;
llvm-svn: 172530
|
|
|
|
|
|
|
|
|
|
|
| |
Note that I don't know whether we should put {} on a single line in this
case, but it is probably a theoretical issue as in practice such
structs, classes or unions won't be empty.
Before: union A {}
a;
After: union A {} a;
llvm-svn: 172355
|
|
|
|
| |
llvm-svn: 172239
|
|
|
|
|
|
|
| |
if { foo; }
would previously crash clang-format.
llvm-svn: 172232
|
|
|
|
|
|
|
|
| |
Now we correctly parse and format:
verifyFormat("struct foo a = { bar };
int n;
llvm-svn: 172229
|
|
|
|
| |
llvm-svn: 172211
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Summary: Uses DiagnosticsEngine to output diagnostics.
Reviewers: djasper, klimek
Reviewed By: djasper
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D278
llvm-svn: 172071
|
|
|
|
|
|
|
| |
void f() {}
now gets formatted in one line.
llvm-svn: 172067
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Previously, we would not indent:
SOME_MACRO({
int i;
});
correctly. This is fixed by adding the trailing }); to the unwrapped
line starting with SOME_MACRO({, so the formatter can correctly match
the braces and indent accordingly.
Also fixes incorrect parsing of initializer lists, like:
int a[] = { 1 };
llvm-svn: 172058
|
|
|
|
|
|
|
| |
After re-writing the same loop multiple times, we deicided it's time to
add this as an optional debugging help.
llvm-svn: 172050
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Previously:
@protocol myProtocol
- (void)mandatoryWithInt:(int)i;
@optional - (void) optional;
@required - (void) required;
@end
Now:
@protocol myProtocol
- (void)mandatoryWithInt:(int)i;
@optional
- (void)optional;
@required
- (void)required;
@end
llvm-svn: 172023
|
|
|
|
|
|
|
| |
Just reuse the @interface code for this. It accepts slightly more than
necessary (@implementation cannot have protocol lists), but that's ok.
llvm-svn: 172019
|
|
|
|
| |
llvm-svn: 172003
|
|
|
|
|
|
| |
Pull pieces of the @interface code into reusable methods.
llvm-svn: 172001
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Previously:
@interface Foo + (id)init; @end
Now:
@interface Foo
+ (id)init;
@end
Some tweaking remains, but this is a good first step.
llvm-svn: 171995
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Previously, we'd always start at indent level 0 after a preprocessor
directive, now we layout the following snippet (column limit 69) as
follows:
functionCallTo(someOtherFunction(
withSomeParameters, whichInSequence,
areLongerThanALine(andAnotherCall,
B
withMoreParamters,
whichStronglyInfluenceTheLayout),
andMoreParameters),
trailing);
Note that the different jumping indent is a different issue that will be
addressed separately.
This is the first step towards handling #ifdef->#else->#endif chains
correctly.
llvm-svn: 171974
|
|
|
|
|
|
|
|
|
|
|
|
| |
This is a first step towards supporting more complex structures such
as #ifs inside unwrapped lines. This patch mostly converts the array-based
UnwrappedLine into a linked-list-based UnwrappedLine. Future changes will
allow multiple children for each Token turning the UnwrappedLine into a
tree.
No functional changes intended.
llvm-svn: 171856
|
|
|
|
|
|
| |
@package is an Objective-C 2 feature, so turn on ObjC2 as well.
llvm-svn: 171766
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Previous indent:
class A {
}
a;
void f() {
};
With this patch:
class A {
} a;
void f() {
}
;
The patch introduces a production for classes and structs, and parses
the rest of the line to the semicolon after the class scope.
This allowed us to remove a long-standing wart in the parser that would
just much the semicolon after any block.
Due to this suboptimal formating some tests were broken.
Some unrelated formatting tests broke; those hit a bug in the ast
printing, and need to be fixed separately.
llvm-svn: 171761
|
|
|
|
| |
llvm-svn: 171737
|
|
|
|
|
|
| |
All changes done by clang-format itself. No functional changes.
llvm-svn: 171732
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
| |
while parsing #define's.
llvm-svn: 171717
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
|
| |
Uses indent 0 for macros for now and resets the indent state to the
level prior to the preprocessor directive.
llvm-svn: 171639
|
|
|
|
|
|
| |
A preprocessor directive cannot be started while we're parsing one.
llvm-svn: 171635
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This changes formatting from:
inline namespace X {
class A {
};
}
to:
inline namespace X {
class A {
};
}
llvm-svn: 171266
|
|
|
|
|
|
|
|
| |
Apply all formatting changes that clang-format would apply to its own source
code. All choices seem to improve readability (or at least not make it worse).
No functional changes.
llvm-svn: 171039
|
|
|
|
|
|
|
|
|
| |
More specifically:
- Improve formatting of static initializers.
- Fix formatting of lines comments in enums.
- Fix formmating of trailing line comments.
llvm-svn: 170316
|
|
|
|
|
|
|
|
|
|
|
|
| |
Reviewers: klimek
Reviewed By: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D198
llvm-svn: 169738
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Summary: FormatTokenLexer is here, FormatTokenBuffer is on the way. This will allow to re-parse unwrapped lines when needed.
Reviewers: djasper, klimek
Reviewed By: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D186
llvm-svn: 169605
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
|
|
|
|
|
|
| |
Reviewers: klimek, djasper
Reviewed By: klimek
CC: cfe-commits, silvas
Differential Revision: http://llvm-reviews.chandlerc.com/D176
llvm-svn: 169518
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|