• Home
  • History
  • Annotate
  • only in /external/clang/lib/Format/
History log of /external/clang/lib/Format/
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
ef8225444452a1486bd721f3285301fe84643b00 21-Jul-2014 Stephen Hines <srhines@google.com> Update Clang for rebase to r212749.

This also fixes a small issue with arm_neon.h not being generated always.

Includes a cherry-pick of:
r213450 - fixes mac-specific header issue
r213126 - removes a default -Bsymbolic on Android

Change-Id: I2a790a0f5d3b2aab11de596fc3a74e7cbc99081d
ontinuationIndenter.cpp
ontinuationIndenter.h
ormat.cpp
ormatToken.h
okenAnnotator.cpp
okenAnnotator.h
nwrappedLineParser.cpp
6bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89 29-May-2014 Stephen Hines <srhines@google.com> Update Clang for 3.5 rebase (r209713).

Change-Id: I8c9133b0f8f776dc915f270b60f94962e771bc83
reakableToken.cpp
reakableToken.h
ontinuationIndenter.cpp
ontinuationIndenter.h
ormat.cpp
ormatToken.cpp
ormatToken.h
okenAnnotator.cpp
okenAnnotator.h
nwrappedLineParser.cpp
nwrappedLineParser.h
hitespaceManager.cpp
hitespaceManager.h
651f13cea278ec967336033dd032faef0e9fc2ec 24-Apr-2014 Stephen Hines <srhines@google.com> Updated to Clang 3.5a.

Change-Id: I8127eb568f674c2e72635b639a3295381fe8af82
ndroid.mk
reakableToken.cpp
reakableToken.h
MakeLists.txt
ontinuationIndenter.cpp
ontinuationIndenter.h
ncoding.h
ormat.cpp
ormatToken.cpp
ormatToken.h
okenAnnotator.cpp
okenAnnotator.h
nwrappedLineParser.cpp
nwrappedLineParser.h
hitespaceManager.cpp
hitespaceManager.h
b2ea69583aaff9fcc7b14c4c87ea2deda6c779c8 19-Nov-2013 Bill Wendling <isanbard@gmail.com> Merging r195128:
------------------------------------------------------------------------
r195128 | alexfh | 2013-11-19 06:30:44 -0800 (Tue, 19 Nov 2013) | 11 lines

Refactoring: replaced (*(I + x)) with I[x].

Summary: Pure refactoring, no semantic changes intended.

Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits, klimek

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_34@195140 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
a9f280942e3129a3d9e051bcf1bb5616243f212c 13-Nov-2013 Alexander Kornienko <alexfh@google.com> Correctly mark first token in the presence of UTF-8 BOM.

Summary: Fixes http://llvm.org/PR17753

Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits, klimek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194576 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
a7462b8ce22a3f754bf51eeeb01adafc42b32cea 12-Nov-2013 Alexander Kornienko <alexfh@google.com> Remove extra whitespace instead of breaking the line in comments when possible.

Summary: Solves the problem described in http://llvm.org/PR17756

Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits, klimek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194493 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
reakableToken.h
ontinuationIndenter.cpp
5486a421a47a8922337aa83ac3b0fbb098dc1fe4 12-Nov-2013 Alexander Kornienko <alexfh@google.com> Do not insert backslashes, when breaking line comments after preprocessor directives.

Summary: This solves http://llvm.org/PR17536

Reviewers: klimek, djasper

Reviewed By: klimek

CC: cfe-commits, klimek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194491 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
a7856d021a1f318f9319c0a3028f0d76e38b6ca1 09-Nov-2013 Daniel Jasper <djasper@google.com> clang-format: Fix alignment of ObjC string literals.

This used to interfere with AlwaysBreakBeforeMultilineStrings.

This fixes llvm.org/PR17856.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194310 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
0ce1c9ade71a2ed56dafddcd5d95e4e75fd91255 09-Nov-2013 Daniel Jasper <djasper@google.com> clang-format: Improve clang-format's detection about comment binding.

Before, existing code in the form of:

int a; // this is a.
// This is
// b.
int b;

Got turned into:

int a; // this is a.
// This is
// b.
int b;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194294 91177308-0d34-0410-b5e6-96231b3b80d8
hitespaceManager.cpp
8b156e2a040d7a652e821878b68822041f65d71a 08-Nov-2013 Daniel Jasper <djasper@google.com> clang-format: Improve formatting of operators forced to new lines.

Before:
unsigned ContentSize =
sizeof(int16_t) // DWARF ARange version number
+
sizeof(int32_t) // Offset of CU in the .debug_info section
+
sizeof(int8_t) // Pointer Size (in bytes)
+
sizeof(int8_t); // Segment Size (in bytes)

After:
unsigned ContentSize =
sizeof(int16_t) // DWARF ARange version number
+ sizeof(int32_t) // Offset of CU in the .debug_info section
+ sizeof(int8_t) // Pointer Size (in bytes)
+ sizeof(int8_t); // Segment Size (in bytes)

This fixes llvm.org/PR17687.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194276 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
c2e0329c8b84b16252184db4dd575c9e9fb93efe 08-Nov-2013 Daniel Jasper <djasper@google.com> clang-format: Don't auto-break short macros in WebKit style.

This fixes llvm.org/PR17842.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194268 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
deb61c5169531895a3cfa02d77b4d8f315f5e64b 08-Nov-2013 Daniel Jasper <djasper@google.com> clang-format: Improve linebreaking and indentation for ObjC calls.

Before:
popup_wdow_.reset([[RenderWidgetPopupWindow alloc]
iniithContentRect:
NSMakRet(origin_global.x, origin_global.y, pos.width(), pos.height())
syeMask:NSBorderlessWindowMask
bking:NSBackingStoreBuffered
der:NO]);
[self param:function( //
parameter)]

After:
popup_wdow_.reset([[RenderWidgetPopupWindow alloc]
iniithContentRect:NSMakRet(origin_global.x, origin_global.y, pos.width(),
pos.height())
syeMask:NSBorderlessWindowMask
bking:NSBackingStoreBuffered
der:NO]);
[self param:function( //
parameter)]

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194267 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
okenAnnotator.cpp
072ac6cfde19fb395d434b2bbcb66e210607cf1e 08-Nov-2013 Daniel Jasper <djasper@google.com> clang-format: Properly indent ObjC calls wrapped before first selector

Before:
[self // break
a:a
aa:aa
aaaaa:aaa];

After:
[self // break
a:a
aa:aa
aaaaa:aaa];

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194241 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
1a896a5a72d9af0259afe636535254c95dc6b355 08-Nov-2013 Daniel Jasper <djasper@google.com> clang-format: Make breaking before ternary operators configurable.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194229 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
ormat.cpp
okenAnnotator.cpp
f9504aa0c3fc7169d137b32d311f6c8102471cb1 07-Nov-2013 Daniel Jasper <djasper@google.com> clang-format: Improve binary operator detection in macros.

Before:
#define M(NAME) assert(!Context.Verifying &&#NAME);

After:
#define M(NAME) assert(!Context.Verifying && #NAME);

This fixes llvm.org/PR16156.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194216 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
966e6d3a174856ff3fe3d6cfe294ebae832f6c09 07-Nov-2013 Daniel Jasper <djasper@google.com> clang-format: Improve ObjC variadic and binary expression parameters.

Before:
[self aaaaaaaaaaaaaaa:aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa |
aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa |
aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa];
[self aaaaaaaaaaaaaaa:aaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa];

After:
[self aaaaaaaaaaaaaaa:aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa |
aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa |
aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa];
[self aaaaaaaaaaaaaaa:aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa];

This addresses llvm.org/PR15349 and llvm.org/PR16185.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194214 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
okenAnnotator.cpp
dbfb5f37f4d003ae6935b87a103b7827d5069690 07-Nov-2013 Daniel Jasper <djasper@google.com> clang-format: Improve formatting of constructor initializers.

Before:
Constructor()
: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa(aaaa,
aaaa)) {}
After:
Constructor()
: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaa(aaaa, aaaa)) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194210 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
okenAnnotator.h
59875ac81b97de87ac6c4c7cb256ab71b75114f2 07-Nov-2013 Daniel Jasper <djasper@google.com> clang-format: Remove old hack that mainly made incorrect tests pass.

As a side-effect, constructors definitions will correctly be recognized
and formatted as function declarations. Tests will be added in a
follow-up patch actually using the correct recognition.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194209 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
16a8b0e7c53ce57fab033ad59f45c619564ff1ef 07-Nov-2013 Daniel Jasper <djasper@google.com> clang-format: Fix corner case for brace alignment.

Before:
Constructor::Constructor()
: some_value{ //
aaaaaaa //
} {}

After:
Constructor::Constructor()
: some_value{ //
aaaaaaa //
} {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194204 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
4281d73fb795ef867d4d4257023bef90d6f9c520 07-Nov-2013 Daniel Jasper <djasper@google.com> clang-format: Separate line-merging logic into its own class.

No functional changes (intended).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194179 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
2a80ad6fe7aa506b1df2bb638bc367d9e760f707 05-Nov-2013 Daniel Jasper <djasper@google.com> clang-format: Allow line merging and partial formatting of nested blocks

Before, clang-format would always format entire nested blocks, which
can be unwanted e.g. for long DEBUG({...}) statements. Also
clang-format would not allow to merge lines in nested blocks (e.g. to
put "if (a) return;" on one line in Google style).

This is the first step of several refactorings mostly focussing on the
additional functionality (by reusing the "format many lines" code to
format the children of a nested block). The next steps are:
* Pull out the line merging into its own class.
* Seperate the formatting of many lines from the formatting of a single
line (and the analysis of the solution space).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194090 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
dc837b1722d8e071d9ec0434aea487dbdfd57853 30-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: Fix indenting corner case with comment and else.

Before:
if (a) {
f();
}
// or else ..
else {
g();
}

After:
if (a) {
f();
}
// or else ..
else {
g();
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193684 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
8437957c9da906c24d4e385869c05d8e601c664d 30-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: Fix whitespaces in include directives.

Before (clang-format wouldn't change):
#include "a.h"
#include<a>

After:
#include "a.h"
#include <a>

This fixes llvm.org/PR16151.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193683 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
okenAnnotator.cpp
74b7363bcfc502dec34092af434da787cf9d5b9f 30-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: fix for \r\r\n produced in multiline block comments

Patch by Christopher Olsen. Thank you!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193678 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
d8ee5c1c8709c5fc060a48b598112f6eadb35d96 29-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: Option to control spacing in template argument lists.

Same as SpacesInParentheses, this option allows adding a space inside
the '<' and '>' of a template parameter list.

Patch by Christopher Olsen.

This fixes llvm.org/PR17301.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193614 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
52af94453e30d2e9d0f4b6a208c8d4c3ff7c85a9 29-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: Fix overloaded operator for global-scoped conversions.

Before:
operator::A();

After:
operator ::A();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193605 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
8f54d881723ca7058807eee871913c812618bfda 26-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: Fix ObjC method exprs with variadic parameters.

Before:
_versionLabel.text = [
NSString stringWithFormat:NSLocalizedString(@"version: %@", @"Label"),
[NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"]
];

After:
_versionLabel.text =
[NSString stringWithFormat:NSLocalizedString(@"version: %@", @"Label"),
[NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"]];

This fixed llvm.org/PR17695.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193475 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
28ce23a550d386b32aa60abbbf308d164992eb1e 25-Oct-2013 Rafael Espindola <rafael.espindola@gmail.com> I am about to change llvm::MemoryBuffer::getFile take take a Twine. Change
clang first so that the build still works.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193428 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
47066e46b9ce4f830ead3c7b9a4cb5bf0ac2c857 25-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: Adapt line break penalties for LLVM style.

Specifically make clang-format less eager to break after the opening
parenthesis of a function call.

Before:
aaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

After:
aaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

Apparently that is preferable. This penalties are adapted
conservatively, we might have to increase them a little bit further.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193410 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
852bce4ba3c59669a80d4755f07782a3c28c606b 24-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: Properly reset nested AnnotatedLine structure.

This fixes llvm.org/PR17682.

Without this patch, the following code leads to invalid reads/writes:
DEBUG({
return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
});
#if a
#else
#endif

Because of the #if-#else structure, the code is formatted and annotated
twice and becauce of the nested block, the annotated lines form a
hierarchical structure. This structure was not properly reset between
runs.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193352 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.h
74317e4d3a6e662412cdd971df57da326229fedb 24-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: Be more conservative about column layout formatting.

Specifically, if a braced list has at least one nested braced list,
format it either all on one line or in one column (i.e. one item per
line).

This seems in general to be an improvement as the structure of nested
braced lists can make a tightly packed outer braced list hard to read.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193345 91177308-0d34-0410-b5e6-96231b3b80d8
ormatToken.cpp
3c6aea7ac63265c769b5fe09e213ab1c4cee111e 24-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: Cleanup array initializer and dict initializer formatting.

Significant changes:
- Also recognize these literals with missing "@" for robustness.
- Reorganize tests.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193325 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
ormatToken.cpp
ormatToken.h
okenAnnotator.cpp
c96894305223479789b990522b2877e766979f17 22-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: Fix ObjC literal indentation in Google style.

Style guide demands a two-space indent.

Before:
NSArray *arguments = @[
kind == kUserTicket ? @"--user-store" : @"--system-store",
@"--print-tickets",
@"--productid",
@"com.google.Chrome"
];

After:
NSArray *arguments = @[
kind == kUserTicket ? @"--user-store" : @"--system-store",
@"--print-tickets",
@"--productid",
@"com.google.Chrome"
];

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193168 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
ormatToken.h
a07aa665a12ab23bef7aa4aedfe113dd8b13da57 22-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: Improve formatting of ObjC array literals.

Before:
NSArray *arguments =
@[ kind == kUserTicket ? @"--user-store" : @"--system-store",
@"--print-tickets", @"--productid", @"com.google.Chrome" ];
After:
NSArray *arguments = @[
kind == kUserTicket ? @"--user-store" : @"--system-store",
@"--print-tickets",
@"--productid",
@"com.google.Chrome"
];

This fixes llvm.org/PR15231.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193167 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
ormatToken.h
okenAnnotator.cpp
45206cac6339a675348a5675b5744148d3aba2f4 22-Oct-2013 Manuel Klimek <klimek@google.com> Remove incorrect assert.

If we run into the second preprocessor branch chain, the first branch
chain might have already set the maximum branch count on that level to
something > 0.

Fixes PR17645.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193153 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
d186f0b4c15d4c63e0ae7fbe6ca3207871ba2eb9 21-Oct-2013 Manuel Klimek <klimek@google.com> Fixes PR17617: Crash on joining short if statements.

Now that we iterate on the formatting multiple times when we
have chains of preprocessor branches, we need to correctly reset
the token's previous and next pointer for the first / last token.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193071 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.h
363193b1bd4d9e0f07d361113157b9d4f229f212 20-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: Better understand Lambda poarameters.

Before:
auto PointerBinding = [](const char * S) {};

After:
auto PointerBinding = [](const char *S) {};

This fixes llvm.org/PR17618.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193054 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
15eef85d4f918834ab83cfb941663463b573d6bf 20-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: Fix formatting of nested blocks after comment.

Before:
DEBUG({ // Comment that used to confuse clang-format.
fdafas();
});
Before:
DEBUG({ // Comments are now fine.
fdafas();
});

This fixed llvm.org/PR17619.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193051 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
b3c887dcb70220eced72935725cd94d7e8325912 20-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: Support case ranges.

Before (note the missing space before "..." which can lead to compile
errors):
switch (x) {
case 'A'... 'Z':
case 1... 5:
break;
}

After:
switch (x) {
case 'A' ... 'Z':
case 1 ... 5:
break;
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193050 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
a53bbae476f8f20d18250effb4cc3f110c9b8030 20-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: Improve formatting of ObjC dict literals.

Before:
NSDictionary *d = @{ @"nam" : NSUserNam(), @"dte" : [NSDate date],
@"processInfo" : [NSProcessInfo processInfo]
};

After:
NSDictionary *d = @{
@"nam" : NSUserNam(),
@"dte" : [NSDate date],
@"processInfo" : [NSProcessInfo processInfo]
};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193049 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
0baf33b73e2bd6657ee202e2016daf010b8b58b9 18-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: Be more aggressive on incorrect code.

Before, clang-format would not adjust leading indents if it found a
structural error (e.g. unmatched {}). It seems, however, that
clang-format has gotten good enough at parsing the code structure that
this hurts in almost all cases. Commonly, while writing code, it is
very useful to be able to correclty indent incomplete if statements or
for loops.

In case this leads to errors that we don't anticipate, we need to find
out and fix those.

This fixed llvm.org/PR17594.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192988 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
49c77b2e702b02a0fbac7b817ccb73e7c128f9d9 18-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: Don't force linebreak between return and multiline string.

This looks ugly and leads to llvm.org/PR17590.

Before (with AlwaysBreakBeforeMultilineStrings):
return
"aaaa"
"bbbb";

After:
return "aaaa"
"bbbb";

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192984 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
53eb05ac6a00b95baf5680d9378ae8819dd09471 18-Oct-2013 Daniel Jasper <djasper@google.com> Make clang-format slightly more willing to break before trailing annotations.

Specifically, prefer breaking before trailing annotations over breaking
before the first parameter.

Before:
void ffffffffffffffffffffffff(
int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) OVERRIDE;

After:
void ffffffffffffffffffffffff(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
OVERRIDE;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192983 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
9b3cb44cd2052aa7236c38b0ccb291221aab08f9 18-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: Improve formatting of templated builder-type calls.

Before:
aaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaa().aaaaaaaaaaaaaaaaa().has<
bbbbbbbbbbbbbbbbbbbbb>();

After:
aaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaa()
.aaaaaaaaaaaaaaaaaaaaaaaaaa()
.has<bbbbbbbbbbbbbbbbbbbbb>();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192981 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
c2827ec708b1611f2b0717bebc423b17a857631e 18-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: Make continuation indent width configurable.

Patch by Kim Gräsman. Thank you!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192964 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
ormat.cpp
f0fc89c358cdd0717c0e12eb4a90e4a6ce956e98 14-Oct-2013 Alexander Kornienko <alexfh@google.com> Keep track of indentation levels in static initializers for correct indentation with tabs.

Summary:
Store IndentationLevel in ParentState and use it instead of the
Line::Level when indening.
Also fixed incorrect indentation level calculation in formatFirstToken.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192563 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
ontinuationIndenter.h
ormat.cpp
aabfb2712e180bb11e5dfc4f2a273890a6c5da66 13-Oct-2013 Manuel Klimek <klimek@google.com> Automatically munch semicolons after blocks.

While it is mostly a user error to have the extra semicolon,
formatting it graciously will correctly format in the cases
where we do not fully understand the code (macros).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192543 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
nwrappedLineParser.h
ac4d0181928e3e22fa3929ca1b24ae7f14fb7628 12-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: Fix assertion on unterminated #ifs.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192535 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
78a4e619e775b0dbaa10c9feaea0adf1d3dfe507 12-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: No space in "<::" in C++11 mode.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192524 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
b18c258390f794d8803ef5ebbb56fb77bfea7ba4 11-Oct-2013 Alexander Kornienko <alexfh@google.com> Don't break string literals inside preprocessor directives.

Summary:
This way we avoid breaking code which uses unknown preprocessor
directives with long string literals. The specific use case in
http://llvm.org/PR17035 isn't very common, but it seems to be a good idea to
avoid this kind of problem anyway.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192507 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
okenAnnotator.cpp
ae76f7f850a9101a20191b10241ca72c23dc40dd 11-Oct-2013 Manuel Klimek <klimek@google.com> Support formatting of preprocessor branches.

We now correctly format:
void SomeFunction(int param1,
#ifdef X
NoTemplate param2,
#else
template <
#ifdef A
MyType<Some> >
#else
Type1, Type2>
#endif
param2,
#endif
param3) {
f();
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192503 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
ontinuationIndenter.h
ormat.cpp
ormatToken.cpp
ormatToken.h
okenAnnotator.cpp
nwrappedLineParser.cpp
nwrappedLineParser.h
hitespaceManager.cpp
hitespaceManager.h
1d82b1a33bcfe85f4834fb6920517ed07e9355d3 11-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: Don't remove 'unknown' tokens.

In certain macros or incorrect string literals, the token stream can
contain 'unknown' tokens, e.g. a single backslash or a set of empty
ticks. clang-format simply treated them as whitespace and removed them
prior to this patch.

This fixes llvm.org/PR17215

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192490 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
01fe9f9f320dd4342664376f24eb1a0d004d03c8 10-Oct-2013 Alexander Kornienko <alexfh@google.com> Correctly detect colon in bit fields. Fixes PR17333.

Summary: Colon was incorrectly detected as a start of inheritance list. Fixed.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192349 91177308-0d34-0410-b5e6-96231b3b80d8
ormatToken.h
okenAnnotator.cpp
6e7f1934f489b48a53b8c9af314921c0e55ee5b5 09-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: Fix template declaration line breaking with comment.

Before, clang-format would always insert a linebreak before the comment
in code like:
template <typename T> // T can be A, B or C.
struct S {};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192297 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
cea014bd8d280070caeb27e4e6e33e5723b4226f 08-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: Improve indentation when deriving from templated classes.

Before:
struct aaaaaaaaaaaaa : public aaaaaaaaaaaaaaaaaaa< //
aaaaaaaaaaaaaaaa> {};
struct aaaaaaaaaaaaaaaaaaaa : public aaaaaaaaaaaaaaaaaaa<
aaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaa> {};

After:
struct aaaaaaaaaaaaa : public aaaaaaaaaaaaaaaaaaa< //
aaaaaaaaaaaaaaaa> {};
struct aaaaaaaaaaaaaaaaaaaa
: public aaaaaaaaaaaaaaaaaaa<aaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaa> {};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192187 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
okenAnnotator.cpp
19ccb1227f5dc338d4b2d9dbbaeaa973c293f8d0 08-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: Improve constructor initializer linewrapping.

Specifically make ConstructorInitializerAllOnOneLineOrOnePerLine work
nicely with BreakConstructorInitializersBeforeComma.

This fixes llvm.org/PR17395.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192168 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
okenAnnotator.cpp
3d712898fcabf5747db25dac497747572d506c7a 07-Oct-2013 Manuel Klimek <klimek@google.com> Fix incorrect detection of class definitions with alignas specification.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192094 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
63cfb89cf75300b62f3aa1debaa44a4a1ce83b45 06-Oct-2013 Daniel Jasper <djasper@google.com> clang-format: Remove empty lines after visibility modifiers.

Formatting:
class C {
public:

f();
};

Now leads to:
class C {
public:
f();
};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192062 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
e5321c400c76517f10ee6090556f6d87c150b826 01-Oct-2013 Alexander Kornienko <alexfh@google.com> Refactoring: split addTokenToState into two methods.

Summary: Pure refactoring, should be no semantic changes.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191772 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
ontinuationIndenter.h
f4e12c8c1325ea04b54ed0b5869258254458b091 30-Sep-2013 Edwin Vane <edwin.vane@intel.com> Moving style option formatting to libFormat

The help text for clang-format's -style option and the function that processes
its value is moved to libFormat in this patch. The goal is to enable other
tools that use libFormat and also have a -style option to behave consistently
with clang-format.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191666 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
f78bf4a0132a3ea366ba3baadd9d6af26c617d11 30-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Improve alignment after 'return'.

Previously, comments, could totally confuse it.

Before:
return
// true if code is one of a or b.
code == a ||
code == b;

After:
return
// true if code is one of a or b.
code == a || code == b;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191654 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
okenAnnotator.cpp
20376989402fb187c0bc48209f46560b9e402ea2 29-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Fix assertion on incomplete string literals.

Before, this could would lead to an assert:
llvm::errs() << "
<< a;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191639 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
6967e786df73e9bdd3f1413a37f7266fae7c482e 27-Sep-2013 Alexander Kornienko <alexfh@google.com> Added a comment and another test for the UT_ForIndentation option

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191530 91177308-0d34-0410-b5e6-96231b3b80d8
hitespaceManager.cpp
3d9ffcf3aa0ed84fa297e3c461bb84e48221aa2d 27-Sep-2013 Alexander Kornienko <alexfh@google.com> Implemented tab usage only for indentation (http://llvm.org/PR17363)

Summary:
Changed UseTab to be a enum with three options: Never, Always,
ForIndentation (true/false are still supported when reading .clang-format).
IndentLevel should currently be propagated correctly for all tokens, except for
block comments. Please take a look at the general idea before I start dealing
with block comments.

Reviewers: klimek, djasper

Reviewed By: klimek

CC: cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191527 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
reakableToken.h
ontinuationIndenter.cpp
ormat.cpp
hitespaceManager.cpp
hitespaceManager.h
acf8e90b22cfea07ba2edeaa5101160eda8dc82c 27-Sep-2013 Alexander Kornienko <alexfh@google.com> Correctly indent with tabs when whitespace starts from the column not divisible by TabWidth.

Summary:
The width of the first inserted tab character depends on the initial
column, so we need to handle the first tab in a special manner.

Reviewers: klimek, djasper

Reviewed By: klimek

CC: cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191497 91177308-0d34-0410-b5e6-96231b3b80d8
hitespaceManager.cpp
hitespaceManager.h
6b3ff8c4caaa6782289a780e096fe56ad6434bb7 27-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Improve formatting of functions with multiple trailing tokens.

Before:
void SomeFunction(aaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaa) override
final;

After:
void SomeFunction(aaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaa) override final;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191494 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
48c099f45400e37ec1cde7de5eaee5cce65dbd42 27-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Fix formatting bug with comment in weird place.

Before:
template <typename T>
// T should be one of {A, B}.
void f() {}

After:
template <typename T>
// T should be one of {A, B}.
void f() {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191492 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
9b4de85e2f47a01974f451d21fed0276ff912e32 25-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Option to removing the space before assignment operators.

Patch contributed by Aaron Wishnick. Thank you!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191375 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
65da8e952da32730202356290bb889c8839bbef5 21-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Improve address-of-operator detection

Before:
size = sizeof * a;

After:
size = sizeof *a;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191139 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
ebaa1719fdd180e6dd9b4e6471e83500471a2f16 17-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Don't accidentally move tokens into preprocessor directive.

This fixes llvm.org/PR17265.

Before:
Foo::Foo()
#ifdef BAR
: baz(0)
#endif {
}

After:
Foo::Foo()
#ifdef BAR
: baz(0)
#endif
{
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190861 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
okenAnnotator.h
e63a48a21cb3416edc6bc75d4d24f3bcf23532d4 17-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Fix line breaking bug after empty ifs.

Before:
if () {
}
else {
}

After:
if () {
} else {
}

This fixed llvm.org/PR17262.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190855 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
26356ccf00f813cf358d420b55939fc737eb2cfa 17-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Don't split a >>-operator.

Before (with column limit 60):
aaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
> aaaaa);

After:
aaaaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaa >> aaaaa);

(Not sure how that could have stayed in that long without being
detected..)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190854 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
2c2f729d10cb10324bf2e7871867f7bbc19ad358 16-Sep-2013 Alexander Kornienko <alexfh@google.com> When in pre-c++11 mode, treat _T("xxx") as a single string literal, repeat the _T() part around each fragment. This addresses http://llvm.org/PR17122

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek, rsmith

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190804 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
reakableToken.h
ontinuationIndenter.cpp
ormat.cpp
hitespaceManager.cpp
d3d9e0f4a107e97b493e1d4c7c5b5dc15e7e137a 14-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Fix bug in style option AlwaysBreakTemplateDeclarations.

Before:
template <template <typename>
class Fooooooo, template <typename>
class Baaaaaaar>
struct C {};

After:
template <template <typename> class Fooooooo,
template <typename> class Baaaaaaar>
struct C {};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190747 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
ac885cd60267afbe67c9ed61515be3816032bba2 13-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Detect braced lists in subscript expressions.

Before (even with Style.Cpp11BracedListStyle):
f(MyMap[{ composite, key }]);

After:
f(MyMap[{composite, key}]);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190678 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
5798120bc015360951d13a06e17501b909ecd21d 13-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Fix incorrect enum parsing / layouting.

Before:
enum {
Bar = Foo < int,
int > ::value
};

After:
enum {
Bar = Foo<int, int>::value
};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190674 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
ormat.cpp
ormatToken.cpp
okenAnnotator.cpp
nwrappedLineParser.cpp
nwrappedLineParser.h
7e27400c90e9e295bcf5857eebf2d60c4b32106e 11-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Fix bug in pointer detection

Before:
for (int i = 0; i* 2 < z; i *= 2) {}
After:
for (int i = 0; i * 2 < z; i *= 2) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190546 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
73d845cbe26df2fb188e30853efb8ce4b0556afe 11-Sep-2013 Alexander Kornienko <alexfh@google.com> Support for CR LF newlines.

Summary:
reformat() tries to determine the newline style used in the input
(either LF or CR LF), and uses it for the output. Maybe not every single case is
supported, but at least the bug described in http://llvm.org/PR17182 should be
resolved.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190519 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
hitespaceManager.cpp
hitespaceManager.h
daa07e9ee76d438efa3c7e2c54b4d3d3ed19ea27 10-Sep-2013 Alexander Kornienko <alexfh@google.com> Don't divide L and #x in macro definitions. Fixes http://llvm.org/PR17144

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190408 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
6f6154c5f5976e3e57f34f6a755bdfa95b7ff745 10-Sep-2013 Alexander Kornienko <alexfh@google.com> Correctly calculate OriginalColumn after multi-line tokens.

Summary: This also unifies the handling of escaped newlines for all tokens.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190405 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
ontinuationIndenter.h
ormat.cpp
db8afe424991b34884afb13ecf97ac458e41da9e 10-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Understand function type typedefs with typeof.

Before:
typedef typeof(int(int, int)) * MyFunc;
After:
typedef typeof(int(int, int)) *MyFunc;

This fixes llvm.org/PR17178.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190401 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
83a7dcdf5fce1bdf74ce985419d77a41a51abfa2 10-Sep-2013 Alexander Kornienko <alexfh@google.com> Calculate and store ColumnWidth instead of CodePointCount in FormatTokens.

Summary:
This fixes various issues with mixed tabs and spaces handling, e.g.
when realigning block comments.

Reviewers: klimek, djasper

Reviewed By: djasper

CC: cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190395 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
ontinuationIndenter.cpp
ormat.cpp
ormatToken.cpp
ormatToken.h
okenAnnotator.cpp
14e25c0477bf9f51e980fdc23b7f0bff800f3ae7 08-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Keep empty lines and format 1-line nested blocks.

Let clang-format consistently keep up to one empty line (configured via
FormatStyle::MaxEmptyLinesToKeep) in nested blocks, e.g. lambdas. Also,
actually format single statements in nested blocks.

Before:
DEBUG({ int i; });
DEBUG({
int i;
// an empty line here would just be removed.
int j;
});

After:
DEBUG({ int i; });
DEBUG({
int i;

int j;
});

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190278 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
00e0f4315064734255171f013b534c6e32086d7a 06-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Fix regression introduced by r190038.

Before:
Constructor()
: aaaaaaaaaaaaaaaaaaaa(a), bbbbbbbbbbbbbbbbbbbbbbbb(b) {
}
After:
Constructor()
: aaaaaaaaaaaaaaaaaaaa(a), bbbbbbbbbbbbbbbbbbbbbbbb(b) {
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190209 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
e27dc5d8ab967912b9a3d792ad32cad63981a974 06-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Format typed enums with nested names.

The explicit type specified for an enum can actually have a nested name
specifier.

This fixes llvm.org/PR17125.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190208 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
520cca87e38185872212849562951906be5068e9 06-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Don't confuse operator[] with lambdas.

Before:
double &operator[](int i) { return 0; } int i;

After:
double &operator[](int i) { return 0; }
int i;

This fixes llvm.org/PR17134.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190207 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
51bb5d967d445613b9f08f6705491966f8616a2a 06-Sep-2013 Alexander Kornienko <alexfh@google.com> Don't remove trailing escaped newline from line comments.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190175 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
2f0a020d29286805e48b74b127fbf153af2c4ce7 06-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Fix regression introduced by r189353.

Before:
FirstToken->WhitespaceRange.getBegin()
.getLocWithOffset(First->LastNewlineOffset);

After:
FirstToken->WhitespaceRange.getBegin().getLocWithOffset(
First->LastNewlineOffset);

Re-add logic to prevent breaking after an empty set of parentheses.
Basically it seems that calling a function without parameters is more
like navigating along the same object than it is a separate step of a
builder-type call.

We might need to extends this in future to allow "short" parameters that
e.g. are an index accessing a specific element.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190126 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
db4813a3997fcf3864d1190f8021ef68e42cc057 06-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Fix regression introduced by r189337.

Before:
if (aaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) == 5) ...

After:
if (aaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
== 5) ...

Also precompute startsBinaryExpression() to improve performance.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190124 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
ormatToken.h
okenAnnotator.cpp
b77d741691a2775b5c31e29f021203cc659c26df 06-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Fix comment formatting bugs in nested blocks.

This fixes two issues:
1) The indent of a line comment was not adapted to the subsequent
statement as it would be outside of a nested block.
2) A missing DryRun flag caused actualy breaks to be inserted in
overly long comments while trying to come up with the best line
breaking decisions.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190123 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
ontinuationIndenter.h
ormat.cpp
okenAnnotator.cpp
okenAnnotator.h
b48aeb0c6422e2781ffb2d4627dc7c94f5cec9bc 05-Sep-2013 Douglas Gregor <dgregor@apple.com> Unbreak build with libc++, whose std::list<T> requires T to be complete.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190075 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.h
d98927d76557653fc517f997db89378267f9bdf3 05-Sep-2013 Daniel Jasper <djasper@google.com> Add ATTRIBUTE_UNUSED to silence unused-function warning in release
builds.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190061 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
e11e45f624bf848315cf7b1862b69baf76cd5a38 05-Sep-2013 Manuel Klimek <klimek@google.com> Fixes PR 17106 (explicitly typed enums are formatted differently).

Before:
enum X : int { A, B, C };

After:
enum X : int {
A,
B,
C
};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190054 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
0b62cc30c9aa462184de0435dc083d944a41d67f 05-Sep-2013 Alexander Kornienko <alexfh@google.com> Handle zero-width and double-width characters in string literals and comments.

Summary:
Count column width instead of the number of code points. This also
includes correct handling of tabs inside string literals and comments (with an
exception of multiline string literals/comments, where tabs are present before
the first escaped newline).

Reviewers: djasper, klimek

Reviewed By: klimek

CC: cfe-commits, klimek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190052 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
reakableToken.h
ontinuationIndenter.cpp
ncoding.h
ormat.cpp
ormatToken.h
hitespaceManager.cpp
2d65705ed0a72ab57b8a062c44c9caa377f9fd2a 05-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Quickfix for braced init lists detected as lambdas.

Before:
constexpr char hello [] { "hello" };

After:
constexpr char hello[]{ "hello" };

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190046 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
1a925bce18ea691d9bc7b2810715f37657ca8f51 05-Sep-2013 Daniel Jasper <djasper@google.com> Address post-commit review comments from r190038.

Mostly additional comments :-).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190042 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
ormat.cpp
okenAnnotator.h
ac2c974bc64d3767ad5e39451a874c50b3004b3a 05-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Fix parsing and indenting lambdas.

Before:
void f() {
other(x.begin(), x.end(), //
[&](int, int) { return 1; });
}

After:
void f() {
other(x.begin(), x.end(), //
[&](int, int) { return 1; });
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190039 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
okenAnnotator.cpp
nwrappedLineParser.cpp
567dcf95424d69657f75e4bfd028967ca1f9eb8d 05-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Enable formatting of nested blocks.

Among other things, this enables (better) formatting lambdas and
constructs like:
MACRO({
long_statement();
long_statement_2();
},
{
long_statement();
long_statement_2();
},
{ short_statement(); }, "");

This fixes llvm.org/PR15381.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190038 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
ontinuationIndenter.h
ormat.cpp
ormatToken.h
okenAnnotator.cpp
okenAnnotator.h
nwrappedLineParser.cpp
nwrappedLineParser.h
9321e8700275847458de753933689e30a3412fe2 04-Sep-2013 Alexander Kornienko <alexfh@google.com> Handle 'Cpp03' and 'Cpp11' strings in LanguageStandard serialization for
consistency of serialized form with the actual enum member names without
a prefix.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189936 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
b7d98a1bd42601a745328e118ed38034a391cc92 04-Sep-2013 Manuel Klimek <klimek@google.com> Remove code duplication in unwrapped line parser.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189933 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
753a5114f9076c545c33cf3ced0d76e27bc0a2d5 04-Sep-2013 Manuel Klimek <klimek@google.com> Implement parsing of blocks (^{ ... }) in the unwrapped line parser.

This patch makes sure we produce the right number of unwrapped lines,
a follow-up patch will make the whitespace formatting consistent.

Before:
void f() {
int i = {[operation setCompletionBlock : ^{ [self onOperationDone];
}]
}
;
}

After:
void f() {
int i = {[operation setCompletionBlock : ^{
[self onOperationDone];
}] };
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189932 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
nwrappedLineParser.h
31e44f7a5d50ab8f7f623a7d2e18d5d877ef400d 04-Sep-2013 Manuel Klimek <klimek@google.com> Fix layout of lambda captures.

Before:
int c = [ &, &a, a]{
[ =, c, &d]{
return b++;
}();
}();

After:
int c = [&, &a, a] {
[=, c, &d] {
return b++;
}();
}();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189924 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
nwrappedLineParser.cpp
b61a8afba4120f5f1f1af4c7d2a6646a65bd8020 03-Sep-2013 Manuel Klimek <klimek@google.com> First step towards correctly formatting lambdas.

Implements parsing of lambdas in the UnwrappedLineParser.
This introduces the correct line breaks; the formatting of
lambda captures are still incorrect, and the braces are also
still formatted as if they were braced init lists instead of
blocks.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189818 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
nwrappedLineParser.h
4e65c98f67b80a7f85ecd5b550a5e10a834f702c 02-Sep-2013 Alexander Kornienko <alexfh@google.com> Added WebKit style to the BasedOnStyle handling and to the relevant help messages.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189765 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
4b762a91faac0473fa380ea9731992b24867e2e6 02-Sep-2013 Alexander Kornienko <alexfh@google.com> Store first and last newline position in the token text for string literals and comments.

Summary:
Store first and last newline position in the token text for string literals and
comments to avoid doing .find('\n') for each possible solution.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189758 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
ormat.cpp
ormatToken.h
okenAnnotator.cpp
174f60f005167984d00682d1d38a2927b9c04684 02-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Fix segfault in overloaded operator parsing.

Before, constructs like:
using A::operator+;

caused a segfault. This fixes llvm.org/PR17050.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189749 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
67cf1dbdd2e1e167a34b849386916450649564cb 02-Sep-2013 Daniel Jasper <djasper@google.com> clang-format: Fix case-indentation in macros.

Before:
#define OPERATION_CASE(name) \
case OP_name: \
return operations::Operation##name

After:
#define OPERATION_CASE(name) \
case OP_name: \
return operations::Operation##name

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189743 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
ec17226e82979592c16c7815d2368240201d18fe 30-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Enable formatting of protocol buffer definitions.

Almost by accident, clang-format seems to be able to format protocol
buffer definitions (https://code.google.com/p/protobuf/).

The only change is that a space is required between numeric constants
and opening square brackets (for default values). While this might in
theory be used for array subscripts (int val = 4[MyArray]), I have not
seen this pattern in practice much. If this is wrong, we can make this
smarter in the future.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189663 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
4b434cf0c913a853cb5fd5011a631447836563b2 30-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Improve recovery from enums with errors.

Before:
namespace n {
enum Type {
One,
Two, // missing };
int i;
} void g() {
}

After:
namespace n {
enum Type {
One,
Two, // missing };
int i;
}
void g() {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189662 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
13d2aa5c8fbb62abf8531bc6e1b7aa89c60fba4f 30-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Fix incorrect indentation.

Before:
aaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbb.ccccccccccccccccc(
dddddddddddddddddddddddddddddd));
aaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(
dddddddddddddddddddddddddddddd));

After:
aaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbb.ccccccccccccccccc(
dddddddddddddddddddddddddddddd));
aaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(
dddddddddddddddddddddddddddddd));

This was overlooked when interducing the new builder-type call
detection in r189337. Also, some minor reorganization of a test.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189658 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
290824530199d9d3728edfbaeb5ccedb798d4498 30-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Don't indent builders relative to "return".

While this looks kind of nice, it wastes horizontal space and does not
seem to be common in the LLVM codebase.

Before:
return llvm::StringSwitch<Reference::Kind>(name)
.StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR)
.StartsWith(".eh_frame", ORDER_EH_FRAME)
.StartsWith(".init", ORDER_INIT)
.StartsWith(".fini", ORDER_FINI)
.StartsWith(".hash", ORDER_HASH)
.Default(ORDER_TEXT);

After:
return llvm::StringSwitch<Reference::Kind>(name)
.StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR)
.StartsWith(".eh_frame", ORDER_EH_FRAME)
.StartsWith(".init", ORDER_INIT)
.StartsWith(".fini", ORDER_FINI)
.StartsWith(".hash", ORDER_HASH)
.Default(ORDER_TEXT);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189657 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
eb331832830c51322a225a3de480189c7d6d7503 30-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Fix corner case in builder-type calls.

Before:
aaaaaaaaaaaaa->aaaaaaaaaaaaaaaaaaaaaaaa()->aaaaaaaaaaaaaae(
0)->aaaaaaaaaaaaaaa();

After:
aaaaaaaaaaaaa->aaaaaaaaaaaaaaaaaaaaaaaa()
->aaaaaaaaaaaaaae(0)
->aaaaaaaaaaaaaaa();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189655 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
dcc0c5bb7ce9a731ecbc0b8e8477979cd9e730c0 29-Aug-2013 Alexander Kornienko <alexfh@google.com> Better support for multiline string literals (including C++11 raw string literals).

Summary:
Calculate characters in the first and the last line correctly so that
we only break before the literal when needed.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189595 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
ontinuationIndenter.h
ormat.cpp
ormatToken.h
okenAnnotator.cpp
c41e8198dc1f24a1c6d35046fc4d478546761648 29-Aug-2013 Manuel Klimek <klimek@google.com> Fixes various problems with accounting for tabs in the original code.

We now count the original token's column directly when lexing the
tokens, where we already have all knowledge about where lines start.

Before this patch, formatting:
void f() {
\tg();
\th();
}
would incorrectly count the \t's as 1 character if only the line
containing h() was reformatted, and thus indent h() at offset 1.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189585 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
ormatToken.h
f54617858a0df936746b7f521a8ffb032289d02f 28-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Improve token breaking behavior.

Two changes:
* Don't add an extra penalty on breaking the same token multiple times.
Generally, we should prefer not to break, but once we break, the
normal line breaking penalties apply.
* Slightly increase the penalty for breaking comments. In general, the
author has put some thought into how to break the comment and we
should not overwrite this unnecessarily.

With a 40-column column limit, formatting
aaaaaa("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa");

Leads to:
Before:
aaaaaa(
"aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa "
"aaaaaaaaaaaaaaaa");

After:
aaaaaa("aaaaaaaaaaaaaaaa "
"aaaaaaaaaaaaaaaa "
"aaaaaaaaaaaaaaaa");

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189466 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
ormat.cpp
7143a21706d951ad53b5167a4dcd750f5997d208 28-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Fix segfault in 'incomplete' macros.

The code leading to a segfault was:
#pragma omp threadprivate(y)), // long comment leading to a line break

This fixes llvm.org/PR16513.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189460 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
c9346c996c9d5de130541c84206c4a4d5bba24e9 28-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Fix infinite loop in macro special case.

If escaped newlines are aligned right
(FormatStyle.AlignEscapedNewlinesLeft == false), and a line contained
too many characters to fit into the column limit, this would result in
a (virtually) endless loop creating a negative number of spaces.

Instead, allow the escaped newlines to be pushed past the column limit
in this case.

This fixes llvm.org/PR16515.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189459 91177308-0d34-0410-b5e6-96231b3b80d8
hitespaceManager.cpp
a4dd982805e89a37a080350bf8de9069135c5a60 28-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Don't insert space in __has_include

Before:
#if __has_include( <strstream>)
#include <strstream>
#endif

After:
#if __has_include(<strstream>)
#include <strstream>
#endif

This fixes llvm.org/PR16516.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189455 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
7186ccc86ee5802c33886d6dd4c5386c7e9fd1aa 28-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Fix corner case in ObjC interface definitions.

In
@implementation ObjcClass
- (void)method;
{
}
@end
the ObjC compiler seems to accept the superfluous comma after "method",
but clang-format used to assert on the subsequent "{".

This fixes llvm.org/PR16604.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189453 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
f439dcb4ecb444df538c42b3284c093886fc7ab1 28-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Improve braced init list detection:

Before:
std::this_thread::sleep_for(std::chrono::nanoseconds{
std::chrono::seconds { 1 }
} /
5);

After:
std::this_thread::sleep_for(
std::chrono::nanoseconds{ std::chrono::seconds{ 1 } } / 5);

This fixes llvm.org/PR16554.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189451 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
c476ea976badd316e3afd0f34afe1f030a710117 28-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Fix corner case in overloaded operator definitions.

Before:
SomeLoooooooooooooooooooooooooogType operator>
>(const SomeLooooooooooooooooooooooooogType &other);
SomeLoooooooooooooooooooooooooogType // break
operator>>(const SomeLooooooooooooooooooooooooogType &other);

After:
SomeLoooooooooooooooooooooooooogType
operator>>(const SomeLooooooooooooooooooooooooogType &other);
SomeLoooooooooooooooooooooooooogType // break
operator>>(const SomeLooooooooooooooooooooooooogType &other);

This fixes llvm.org/PR16328.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189450 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
081fc17374baf55cc6a6069a9f5a1596fb378ef3 28-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Fix space in decltype-constexprs.

Before:
static constexpr bool Bar = decltype(bar()) ::value;

After:
static constexpr bool Bar = decltype(bar())::value;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189449 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
d3fef0fe26da19685bdec6a1bd844505f604d593 27-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Format segments of builder-type calls one per line.

This fixes llvm.org/PR14818.

Before:
return llvm::StringSwitch<Reference::Kind>(name)
.StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR)
.StartsWith(".eh_frame", ORDER_EH_FRAME)
.StartsWith(".init", ORDER_INIT).StartsWith(".fini", ORDER_FINI)
.StartsWith(".hash", ORDER_HASH).Default(ORDER_TEXT);

After:
return llvm::StringSwitch<Reference::Kind>(name)
.StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR)
.StartsWith(".eh_frame", ORDER_EH_FRAME)
.StartsWith(".init", ORDER_INIT)
.StartsWith(".fini", ORDER_FINI)
.StartsWith(".hash", ORDER_HASH)
.Default(ORDER_TEXT);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189353 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
ontinuationIndenter.h
ormatToken.h
okenAnnotator.cpp
d489f8ceb735458b0e1f814e3f952b154f49c025 27-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Revamp builder-type call formatting.

Previously builder-type calls were only correctly recognized in
top-level calls.

This fixes llvm.org/PR16981.
Before:
someobj->Add((new util::filetools::Handler(dir))->OnEvent1(
NewPermanentCallback(this, &HandlerHolderClass::EventHandlerCBA))
->OnEvent2(NewPermanentCallback(
this, &HandlerHolderClass::EventHandlerCBB))
->OnEvent3(NewPermanentCallback(
this, &HandlerHolderClass::EventHandlerCBC))
->OnEvent5(NewPermanentCallback(
this, &HandlerHolderClass::EventHandlerCBD))
->OnEvent6(NewPermanentCallback(
this, &HandlerHolderClass::EventHandlerCBE)));

After:
someobj->Add((new util::filetools::Handler(dir))
->OnEvent1(NewPermanentCallback(
this, &HandlerHolderClass::EventHandlerCBA))
->OnEvent2(NewPermanentCallback(
this, &HandlerHolderClass::EventHandlerCBB))
->OnEvent3(NewPermanentCallback(
this, &HandlerHolderClass::EventHandlerCBC))
->OnEvent5(NewPermanentCallback(
this, &HandlerHolderClass::EventHandlerCBD))
->OnEvent6(NewPermanentCallback(
this, &HandlerHolderClass::EventHandlerCBE)));

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189337 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
okenAnnotator.cpp
okenAnnotator.h
451f1e0e5040db6a114217e7bd9767bf751d5bd3 27-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Fix bug in column layout.

Before (with 60 character limit in Google style):
return {
{aaaaaaaaaaaaaaaaaaaaaaaaa}, {aaaaaaaaaaaaaaaaa},
{aaaaaaaaaaaaaaaaaaaaaaaaa}, {aaaaaaaaaaaaaaaaa}};
After:
return {{aaaaaaaaaaaaaaaaaaaaaaaaa}, {aaaaaaaaaaaaaaaaa},
{aaaaaaaaaaaaaaaaaaaaaaaaa}, {aaaaaaaaaaaaaaaaa}};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189327 91177308-0d34-0410-b5e6-96231b3b80d8
ormatToken.cpp
332c67703f63fafd26cf88fc31faeb80c1523725 26-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Fix bug in column-layout formatting.

Specific arrangements of comments after trailing commas could confuse
the column width calculation, e.g. in:

vector<int> x = { a, b,
/* some */ /* comment */ };

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189211 91177308-0d34-0410-b5e6-96231b3b80d8
ormatToken.cpp
3618e6fae8b734ad94221d941417c12d4bd1e3a8 23-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Fix indentation relative to unary expressions.

This should be done, only if we are still in the unary expression's
scope.

Before:
bool aaaa = !aaaaaaaa( // break
aaaaaaaaaaa);
*aaaaaa = aaaaaaa( // break
aaaaaaaaaaaaaaaa);

After:
bool aaaa = !aaaaaaaa( // break
aaaaaaaaaaa); // <- (unchanged)
*aaaaaa = aaaaaaa( // break
aaaaaaaaaaaaaaaa); // <- (no longer indented relative to "*")

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189108 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
4df1ff96262b8bde75c6801ef42659f352aa2422 23-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Fix corner case for string splitting ..

.. in conjunction with Style.AlwaysBreakBeforeMultilineStrings. Also,
simplify the implementation by handling newly split strings and already
split strings by the same code.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189102 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
ontinuationIndenter.h
ed51c02f4c87ddb2d2f45193e4041921ac363f76 23-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Handle trailing commas in column layout of braced list.

Before, this was causing errors.

Also exit early in breakProtrudingToken() (before the expensive call to
SourceManager::getSpellingColumnNumber()). This makes formatting huge
(100k+-item) braced lists possible.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189094 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
ormatToken.cpp
259118e66086f1446f1d205de9d51708a6325914 22-Aug-2013 Daniel Jasper <djasper@google.com> Work around unused variable warning in release builds.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189028 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
d4a03dbb0bdbd4908375306283cb61813bd8f454 22-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Add column layout formatting for braced lists

With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:

static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};

Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).

Review: http://llvm-reviews.chandlerc.com/D1457

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189018 91177308-0d34-0410-b5e6-96231b3b80d8
MakeLists.txt
ontinuationIndenter.cpp
ontinuationIndenter.h
ormat.cpp
ormatToken.cpp
ormatToken.h
okenAnnotator.cpp
34f3d05d0ee625dfcac951e2851f212c4c1a8b83 21-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Indent relative to unary operators.

Before:
if (!aaaaaaaaaa( // break
aaaaa)) {
}

After:
if (!aaaaaaaaaa( // break
aaaaa)) {
}

Also cleaned up formatting using clang-format.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188891 91177308-0d34-0410-b5e6-96231b3b80d8
ontinuationIndenter.cpp
ormat.cpp
okenAnnotator.cpp
cbeb1c6f337f73fe7d1135b379e45fbda0c4766d 20-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Format enum struct/class like enum.

Patch by Joe Hermaszewski. Thank you!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188794 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
7df56bfcf7186f73c99564cd54216f07a8db7352 20-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Additional options for spaces around parentheses.

This patch adds four new options to control:
- Spaces after control keyworks (if(..) vs if (..))
- Spaces in empty parentheses (f( ) vs f())
- Spaces in c-style casts (( int )1.0 vs (int)1.0)
- Spaces in other parentheses (f(a) vs f( a ))

Patch by Joe Hermaszewski. Thank you for working on this!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188793 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
92495a8032d8624495a0ce769d5a6cdeba2dc8d8 19-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Fix return type line break decision.

This accidentally introduced by r186077, as function names were not
correctly recognized in templated declarations.

Before:
template <class TemplateIt>
SomeReturnType
SomeFunction(TemplateIt begin, TemplateIt end, TemplateIt* stop) {}

After:
template <class TemplateIt>
SomeReturnType SomeFunction(TemplateIt begin, TemplateIt end,
TemplateIt* stop) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188665 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
6b2afe445b3cfba4b8ae898f85f3540211bd65f8 16-Aug-2013 Daniel Jasper <djasper@google.com> Split UnwrappedLineFormatter into individual components.

Goals: Structure code better and make components easier to use for
future features (e.g. column layout for long braced initializers).

No functional changes intended.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188543 91177308-0d34-0410-b5e6-96231b3b80d8
MakeLists.txt
ontinuationIndenter.cpp
ontinuationIndenter.h
ormat.cpp
6315fec908431be8f11d9e3c29caadc77c748702 13-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Add option for the offset of constructor initializers.

Some coding styles use a different indent for constructor initializers.

Patch by Klemens Baum. Thank you.
Review: http://llvm-reviews.chandlerc.com/D1360

Post review changes: Changed data type to unsigned as a negative indent
width does not make sense and added test for configuration parsing.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188260 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
b644dd68d3d7261ceb8823595290439dc65530b1 13-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Improve boolean expression formatting in macros.

Before:
#define IF(a, b, c) if (a&&(b == c))

After:
#define IF(a, b, c) if (a && (b == c))

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188256 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
e60084d1e8a62716b80872f10e9828fbbb3cadfc 13-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Slightly adapt line break penalties.

Before:
aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa)
->aaaaaaaaa());
After:
aaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa)->aaaaaaaaa());

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188253 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
b349a78c9705a63a352d7b9210cafb2e9d27047c 12-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Improve stream-formatting.

Before:
CHECK(controller->WriteProto(FLAGS_row_key, FLAGS_proto)) << "\""
<< FLAGS_proto
<< "\"";

After:
SemaRef.Diag(Loc, diag::note_for_range_begin_end)
<< BEF << IsTemplate << Description << E->getType();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188175 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
53352600b7370b1d33b9fde1adda207fd9d7dcd1 12-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Correctly format alias declarations.

Before:
template <class CallbackClass>
using MyCallback = void(CallbackClass::*)(SomeObject * Data);");

After:
template <class CallbackClass>
using MyCallback = void (CallbackClass::*)(SomeObject *Data);");

Also fix three wrong indentations.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188172 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
2530fd5a235c1e57f8ebef2eae9b365042501009 12-Aug-2013 Manuel Klimek <klimek@google.com> This change fixes the formatting of statements such as catch (E& e).

Previously these were formatting as catch (E & e) because the inner parenthesis
was being marked as an expression.

Patch by Thomas Gibson-Robinson.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188153 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
2519d56d558eb40a23ede9bbba154514d0ec7ee2 08-Aug-2013 Arnold Schwaighofer <aschwaighofer@apple.com> Revert r187935 "Support for double width characters."

It broke a public build bot.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187957 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
712b7473f9de7cc1979c3754d03e15a2f492349e 08-Aug-2013 Alexander Kornienko <alexfh@google.com> Support for double width characters.

Summary: Only works for UTF-8-encoded files.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187935 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
d3a247cc4e136af6b71dc5968ca6190e6c68f4c5 07-Aug-2013 Manuel Klimek <klimek@google.com> Fixes a couple of bugs with the Allman brace breaking.

In particular, left braces after an enum declaration now occur on their
own line. Further, when short ifs/whiles are allowed these no longer
cause the left brace to be on the same line as the if/while when a
brace is included.

Patch by Thomas Gibson-Robinson.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187901 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
1dc6f745eb19c94527503012d798dc9b9b5ba6da 07-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Fix corner case in OpenMP pragma formatting.

Before:
#pragma omp reduction( | : var)
After:
#pragma omp reduction(| : var)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187892 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
efed68700e6352f50d120b246041054e76b0c6b9 07-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Improve formatting of builder-type calls.

This removes a formatting choice that was added at one point, but is
not generally liked by users. Specifically, in builder-type calls, do
(easily) break if the object before the ./-> is either a field or a
parameter-less function call. I.e., don't break after "aa.aa.aa" or
"aa.aa.aa()". In general, these sequences in builder-type calls are
seen as a single entity and thus breaking them up is a bad idea.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187865 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
e490705e6678a2e830cecacbe8142d9b369d8341 02-Aug-2013 Manuel Klimek <klimek@google.com> Implement Allman style.

Patch by Frank Miller.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187678 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
75e58bb0bde79d18ed4436769f017b5496745009 02-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Fix string breaking after "<<".

Before, clang-format would not break overly long string literals
following a "<<" with FormatStyle::AlwaysBreakBeforeMultilineStrings
being set.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187650 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
1eaa99779a254411600d77a715c761d9d84ec8bd 02-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Operator precendence in ObjC method exprs.

Patch (mostly) by Adam Strzelecki. Thanks!

Before:
[self aaaaaa:bbbbbbbbbbbbb
aaaaaaaaaa:bbbbbbbbbbbbbbbbb
aaaaa:bbbbbbbbbbb +
bbbbbbbbbbbb aaaa:bbb];

After:
[self aaaaaa:bbbbbbbbbbbbb
aaaaaaaaaa:bbbbbbbbbbbbbbbbb
aaaaa:bbbbbbbbbbb + bbbbbbbbbbbb
aaaa:bbb];

This fixes llvm.org/PR16150.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187631 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
ab3ce592d027e3a10fb21e703cab1507f8d9bb03 02-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Don't break empty 2nd operand of ternary expr.

Before:
some_quite_long_variable_name_ptr
?
: argv[9] ? ptr : argv[8] ? : argv[7] ? ptr : argv[6];
After:
some_quite_long_variable_name_ptr
?: argv[9] ? ptr : argv[8] ?: argv[7] ? ptr : argv[6];

Patch by Adam Strzelecki, thank you!!

This fixed llvm.org/PR16758.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187622 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
b7000ca629da16164f0073f5a7f9459ddf5ba281 01-Aug-2013 Daniel Jasper <djasper@google.com> Teach clang-format to understand static_asserts better.

Before:
template <bool B, bool C>
class A {
static_assert(B &&C, "Something is wrong");
};

After:
template <bool B, bool C>
class A {
static_assert(B && C, "Something is wrong");
};

(Note the spacing around '&&'). Also change the identifier table to always
understand all C++11 keywords (which seems like the right thing to do).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187589 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
aa9e7b18a88d715b63e7b65d1b26a1759decc177 01-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Improve line breaks in @property.

Before:
@property(nonatomic, assign,
readonly) NSString *looooooooooooooooooooooooooooongName;

After:
@property(nonatomic, assign, readonly)
NSString *looooooooooooooooooooooooooooongName;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187577 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
893ea8d0a6420591d966fa0e7135e510b1523b57 01-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Make alignment of trailing comments optional ..

.. in order to support WebKit style properly.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187549 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
hitespaceManager.cpp
eff18b9b6f1218a6bbe4869989b08867823a4e75 01-Aug-2013 Daniel Jasper <djasper@google.com> clang-format: Add more options to namespace indentation.

With this patch, clang-format can be configured to:
* not indent in namespace at all (former behavior).
* indent in namespace as in other blocks.
* indent only in inner namespaces (as required by WebKit style).

Also fix alignment of access specifiers in WebKit style.

Patch started by Marek Kurdej. Thank you!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187540 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
nwrappedLineParser.h
0236dd09c040f2e6124654d620dde94a595c5ab0 31-Jul-2013 Daniel Jasper <djasper@google.com> clang-format: Improve detection of templates.

Before:
template <typename... Types>
typename enable_if < 0<sizeof...(Types)>::type Foo() {}
After:
template <typename... Types>
typename enable_if<0 < sizeof...(Types)>::type Foo() {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187458 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
e8b10d3d5b90efaf60ad89e96f6500f971ceec41 26-Jul-2013 Daniel Jasper <djasper@google.com> clang-format: Add two new style options to support WebKit style.

New options:
* Break before the commas of constructor initializers and align
the commas with the colon.
* Break before binary operators

Additionally, for styles without column limit, don't just accept
linebreaks done by the user, but instead remove 'invalid' (according
to the current style) linebreaks and add 'required' ones.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187210 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
ormatToken.h
okenAnnotator.cpp
e865cc5e183a25983bc79aca2c9bc9a6fb775ab2 25-Jul-2013 Daniel Jasper <djasper@google.com> clang-format: Fix switch/case interaction with macros.

Before:
#define OPERATION_CASE(name) \
case OP_name: \
return operations::Operation##name

switch (OpCode) {
CASE(Add);
CASE(Subtract);
default:
return operations::Unknown;
}

After:
#define OPERATION_CASE(name) \
case OP_name: \
return operations::Operation##name;

switch (OpCode) {
CASE(Add);
CASE(Subtract);
default:
return operations::Unknown;
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187118 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
e05dc6d1b5eb12d47c8d3cb5120452ceef720568 24-Jul-2013 Daniel Jasper <djasper@google.com> clang-format: Initial (incomplete) support for the WebKit coding style.

This is far from implementing all the rules given by
http://www.webkit.org/coding/coding-style.html

The important new feature is the support for styles that don't have a
column limit. For such styles, clang-format will (at the moment) simply
respect the input's formatting decisions within statements.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187033 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
5e2169f94fca20bbfda317c222b156751a431c13 18-Jul-2013 Daniel Jasper <djasper@google.com> clang-format: Fix bad line break with pointers to members.

Before:
void f() {
(a->*
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)(aaaa,
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);
}

After:
void f() {
(a->*aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)(
aaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);
}

Also add missing test case.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186583 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
e0fa4c55a4bc6d2bbe0d9d657287c037158d5357 17-Jul-2013 Daniel Jasper <djasper@google.com> clang-format: Add space in corner case.

Before:
SomeType s __attribute__((unused))(InitValue);
After:
SomeType s __attribute__((unused)) (InitValue);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186535 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
215c57ff4a75388913dc392d03d84ec8c4c3ee1e 17-Jul-2013 Daniel Jasper <djasper@google.com> Improve line breaking before multi-line strings.

The AlwaysBreakBeforeMultilineStrings rule does not really make sense
if it does not a column gain.

Before (in Google style):
f(
"aaaa"
"bbbb");

After:
f("aaaa"
"bbbb");

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186515 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
b4b4a52f1c3b768473169bc7cb450d406e1b495c 17-Jul-2013 Alexander Kornienko <alexfh@google.com> Avoid breaking non-trailing block comments.

Motivating example:
// column limit ------------------->
void ffffffffffff(int aaaaaa /* test */);

Formatting before the patch:
void ffffffffffff(int aaaaaa /* test
*/);

Formatting after the patch:
void
ffffffffffff(int aaaaaa /* test */);



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186471 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
10c26b2e974f97c75fc3aaa302ca750f422cbce1 16-Jul-2013 Alexander Kornienko <alexfh@google.com> Don't break line comments with escaped newlines.

Summary:
These can appear when comments contain command lines with quoted line
breaks. As the text (including escaped newlines and '//' from consecutive lines)
is a single line comment, we used to break it even when it didn't exceed column
limit. This is a temporary solution, in the future we may want to support this
case completely - at least adjust leading whitespace when changing indentation
of the first line.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186456 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
561211d35b5a2825fba6d0c017044f6896b204fd 16-Jul-2013 Daniel Jasper <djasper@google.com> clang-format: Improve handling of unterminated string literals.

Before, clang-format would simply eat these as they were recognized as
whitespace. With this patch, they are mostly left alone.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186454 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
ormatToken.h
okenAnnotator.cpp
b5dc3f4f53981b681a565cdf1d49f18e817541ff 16-Jul-2013 Daniel Jasper <djasper@google.com> Revamp the formatting of C++11 braced init lists.

The fundamental concept is:
Format as if the braced init list was a function call (with parentheses
replaced by braces). If there is no name/type before the opening brace
(e.g. if the braced list is nested), assume a zero-length identifier
just before the opening brace.

This behavior is gated on a new style flag, which for now replaces the
SpacesInBracedLists style flag. Activate this style flag for Google
style to reflect recent style guide changes.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186433 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
e7d3bff31e3ef4fea1e2a5a7cd5441b6b0752e3f 16-Jul-2013 Daniel Jasper <djasper@google.com> clang-format: Improve detection of function types.

This fixes an incorrect detection that led to a formatting error.
Before:
some_var = function (*some_pointer_var)[0];
After:
some_var = function(*some_pointer_var)[0];

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186402 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
0c368787d9d1f92a3408b71b3f074a06edaa6bde 15-Jul-2013 Daniel Jasper <djasper@google.com> clang-format: Improve c-style cast detection.

Before:
#define x ((int) - 1)
#define p(q) ((int *) & q)
After:
#define x ((int)-1)
#define p(q) ((int *)&q)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186324 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
9637dda705e39110bfff66742542a58dd2470ad2 15-Jul-2013 Daniel Jasper <djasper@google.com> Improvement of change r186320.

Fixed a test that by now passed for the wrong reason.

Before:
llvm::outs() << "aaaaaaaaaaaaaaaaaaa: " << aaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaa);
After:
llvm::outs() << "aaaaaaaaaaaaaaaaaaa: "
<< aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaa);

Also reformatted Format.cpp with the latest changes (1 formatting fix
and 1 layout change of a <<-chain).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186322 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
3e12e87f98538c55c1eab79df79e5a00df6de8ec 15-Jul-2013 Daniel Jasper <djasper@google.com> Improve formatting of operator<< chains.

Before:
llvm::outs() << "aaaaaaaaaaaaaaaa: " << aaaaaaaaaaaaaaaa << "aaaaaaaaaaaaaaaa: "
<< aaaaaaaaaaaaaaaa << "aaaaaaaaaaaaaaaa: " << aaaaaaaaaaaaaaaa;

After:
llvm::outs() << "aaaaaaaaaaaaaaaa: " << aaaaaaaaaaaaaaaa
<< "aaaaaaaaaaaaaaaa: " << aaaaaaaaaaaaaaaa
<< "aaaaaaaaaaaaaaaa: " << aaaaaaaaaaaaaaaa;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186320 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
3aa29df37b140f9c6786b6863a0cac195071b598 15-Jul-2013 Craig Topper <craig.topper@gmail.com> Add 'static' and 'const' qualifiers to some arrays of strings.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186314 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
a0740f5ddf143d59b8e55d2cb6e39ed5059575b4 12-Jul-2013 Daniel Jasper <djasper@google.com> clang-format: Improve <<-formatting.

This fixes a regression caused by r186115.

Before:
Diag(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
bbbbbbbbb) << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
<< aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;

After:
Diag(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)
<< aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
<< aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186164 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
0fde9504af582459c93c43363db2680bcd726126 12-Jul-2013 Daniel Jasper <djasper@google.com> clang-format: Fix string literal breaking.

Before this patch, it did not cooperate with
Style::AlwaysBreakBeforeMultilineStrings. Thus, it would turn

aaaaaaaaaaaa(aaaaaaaaaaaaa, "aaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaa");

into:

aaaaaaaaaaaa(aaaaaaaaaaaaa, "aaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaa "
"aaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaa");

and only a second format step would lead to the desired (with that
option):

aaaaaaaaaaaa(aaaaaaaaaaaaa,
"aaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaa "
"aaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaa");

This could even lead to clang-format breaking the string at a different
character and thus leading to a completely different end result.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186154 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
011c35dabb4c8abcb7389d8fbc6316f8f23576ab 12-Jul-2013 Daniel Jasper <djasper@google.com> clang-format: Break before/between array subscript expressions.

clang-format used to treat array subscript expressions much like
function call (just replacing () with []). However, this is not really
appropriate especially for expressions with multiple subscripts.

Although it might seem counter-intuitive, the most consistent solution
seems to be to always (if necessary) break before a square bracket,
never after it. Also, multiple subscripts of the same expression should
be aligned if they are on subsequent lines.

Before:
aaaaaaaaaaaaaaaaaaaaaaaaa[aaaaaaaaaaaaaaaaaaaaaaaaa][
bbbbbbbbbbbbbbbbbbbbbbbbb] = c;
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa][
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb] = ccccccccccc;

After:
aaaaaaaaaaaaaaaaaaaaaaaaa[aaaaaaaaaaaaaaaaaaaaaaaaa]
[bbbbbbbbbbbbbbbbbbbbbbbbb] = c;
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa]
[bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb] = ccccccccccc;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186153 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
15ec3a871d5ae8a8d4c29ca2681532a9894898b6 11-Jul-2013 Daniel Jasper <djasper@google.com> clang-format: Fix bug concerning the alignment of "}".

Before:
int i; // indented 2 space more than clang-format would use.
SomeReturnType // clang-format invoked on this line.
SomeFunctionMakingLBraceEndInColumn80() {
} // This is the indent clang-format would prefer.

After:
int i; // indented 2 space more than clang-format would use.
SomeReturnType // clang-format invoked on this line.
SomeFunctionMakingLBraceEndInColumn80() {
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186120 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
20a0f8cff96505abb65233a2eaf3af3cd8536cd2 11-Jul-2013 Daniel Jasper <djasper@google.com> clang-format: Break before trailing annotations.

(if they are not function-like).

Before:
SomeFunction(aaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaa)
OVERRIDE;

After:
SomeFunction(aaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaa) OVERRIDE;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186117 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
faec47bcbadf462b3ac82618dcfca6ae3b8ce5d9 11-Jul-2013 Daniel Jasper <djasper@google.com> clang-format: Avoid line breaks before the first <<.

This puts a slight penalty on the linebreak before the first "<<", so
that clang-format generally tries to keep things on the first line.

User feedback has shown that this is generally desirable.

Before:
llvm::outs()
<< "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =" << aaaaaaaaaaaaaaaaaaaaaaaaaaa;

After:
llvm::outs() << "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ="
<< aaaaaaaaaaaaaaaaaaaaaaaaaaa;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186115 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
3262f4c10520cf11acea4cf590cfbf055924a41e 11-Jul-2013 Daniel Jasper <djasper@google.com> Improve detection of trailing return types.

Trailing return types can only occur in declaration contexts.

Before:
void f() { auto a = b -> c(); }

After:
void f() { auto a = b->c(); }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186087 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
e1f9a8e27f553dcb359dfd96a3fe3065de7c4dad 11-Jul-2013 Daniel Jasper <djasper@google.com> Fix indentation problem for comments in call chains

Before:
SomeObject
// Calling someFunction on SomeObject
.someFunction();

After:
SomeObject
// Calling someFunction on SomeObject
.someFunction();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186085 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
c18cff311118fc6a30929468fc82b2b35cbd7fbf 11-Jul-2013 Daniel Jasper <djasper@google.com> Keep trailing annotations close to their argument.

Before:
bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa GUARDED_BY(
aaaaaaaaaaaa);

After:
bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
GUARDED_BY(aaaaaaaaaaaa);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186077 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
c7bd68f9edcbca95e882d0ab18d09371f0bdb82c 10-Jul-2013 Daniel Jasper <djasper@google.com> Add experimental flag for adaptive parameter bin-packing.

This is not activated for any style, might change or go away
completely.

For those that want to play around with it, set
ExperimentalAutoDetectBinPacking to true.

clang-format will then:
Look at whether function calls/declarations/definitions are currently
formatted with one parameter per line (on a case-by-case basis). If so,
clang-format will avoid bin-packing the parameters. If all parameters
are on one line (thus that line is "inconclusive"), clang-format will
make the choice dependent on whether there are other bin-packed
calls/declarations in the same file.

The reason for this change is that bin-packing in some situations can be
really bad and an author might opt to put one parameter on each line. If
the author does that, he might want clang-format not to mess with that.
If the author is unhappy with the one-per-line formatting, clang-format
can easily be convinced to bin-pack by putting any two parameters on the
same line.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186003 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
ormatToken.h
okenAnnotator.cpp
2ca3741a962ded08866596577aaee2f4ab74c955 09-Jul-2013 Daniel Jasper <djasper@google.com> Initial support for formatting trailing return types.

This fixes llvm.org/PR15170.

For now, the basic formatting rules are (based on the C++11 standard):
* Surround the "->" with spaces.
* Break before "->".

Also fix typo.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185938 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
ormatToken.h
okenAnnotator.cpp
b1491798353b26c07b065c6975a91ff6214b8ff6 09-Jul-2013 Daniel Jasper <djasper@google.com> Avoid confusing indentations for chained function calls.

Basically treat a function with a trailing call similar to a function
with multiple parameters.

Before:
aaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa))
.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa();

After:
aaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa))
.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa();

Also fix typo.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185930 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
0de1c4d152b5fbf0b383e9fa8396e334f029c716 09-Jul-2013 Daniel Jasper <djasper@google.com> Fix alignment of closing brace in braced initializers.

Before:
someFunction(OtherParam, BracedList{
// comment 1 (Forcing intersting break)
param1, param2,
// comment 2
param3, param4
});
After:
someFunction(OtherParam, BracedList{
// comment 1 (Forcing intersting break)
param1, param2,
// comment 2
param3, param4
});

To do so, the UnwrappedLineParser now stores the information about the
kind of brace in the FormatToken.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185914 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
ormatToken.h
nwrappedLineParser.cpp
nwrappedLineParser.h
6561f6a13b79ed752748ede590792191edf78ce8 09-Jul-2013 Daniel Jasper <djasper@google.com> Format overloaded operators like other functions.

This fixes llvm.org/PR16328 (at least partially).

Before:
SomeLoooooooooooooooooooooooooooooogType operator<<(
const SomeLooooooooogType &a, const SomeLooooooooogType &b);

After:
SomeLoooooooooooooooooooooooooooooogType
operator<<(const SomeLooooooooogType &a, const SomeLooooooooogType &b);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185908 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
526df0f3a8d436e9084bd12118a2e119aa0bd724 08-Jul-2013 Daniel Jasper <djasper@google.com> Fix incorrect incorrect cast identification in clang-format.

This fixes llvm.org/PR16534.

Before:
aaaaa& operator+(const aaaaa&)LLVM_DELETED_FUNCTION;
After:
aaaaa& operator+(const aaaaa&) LLVM_DELETED_FUNCTION;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185828 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
2a409b62126d8f0b8f5749d5ed435ad2b394b526 08-Jul-2013 Daniel Jasper <djasper@google.com> Reformat clang-format's source files after r185822 and others.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185823 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
reakableToken.h
ncoding.h
ormat.cpp
ormatToken.h
okenAnnotator.cpp
nwrappedLineParser.h
hitespaceManager.cpp
hitespaceManager.h
88cc562ad2d3e75280d453f824e89380622f4c9c 08-Jul-2013 Daniel Jasper <djasper@google.com> Prefer similar line breaks.

This adds a penalty for clang-format for each break that occurs in
a set of parentheses (including fake parenthesis that determine
the range of certain operator precendences) that have not yet been
broken. Thereby, clang-format prefers similar line breaks.

This fixes llvm.org/PR15506.

Before:
const int kTrackingOptions =
NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited |
NSTrackingActiveAlways;

After:
const int kTrackingOptions = NSTrackingMouseMoved |
NSTrackingMouseEnteredAndExited |
NSTrackingActiveAlways;

Also removed ParenState::ForFakeParenthesis which has become unused.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185822 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
1659dedac63858de50ee60175a88c42ff974e61b 08-Jul-2013 Alexander Kornienko <alexfh@google.com> Fix for corner cases in code handling leading "* " decorations in block comments

Summary:
Fixes problems that lead to incorrect formatting of these and similar snippets:
/*
**
*/

/*
**/

/*
* */

/*
*test
*/

Clang-format used to think that all the cases above use "* " decoration, and
failed to calculate insertion position properly. It also used to remove leading
"* " in the last line.

Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185818 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
reakableToken.h
163fbf810eaffc2c7b0170d91b6196b032911957 08-Jul-2013 Craig Topper <craig.topper@gmail.com> Use SmallVectorImpl::reverse_iterator instead of SmallVector to avoid specifying the vector size.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185784 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
d6104f6c34639ebe66f83d955c5f32ea4a50c266 05-Jul-2013 Daniel Jasper <djasper@google.com> Fix formatting for allocation of new pointer variables.

Before:
T **t = new T * ;
T **q = new T * ();

After:
T **t = new T *;
T **q = new T *();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185699 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
07ca5477461dc1f3efa76ef9cf6f9dbaf66ddb98 05-Jul-2013 Daniel Jasper <djasper@google.com> Improve detection for preventing certain kind of formatting patterns.

This is a better implementation of r183097. The main purpose is to
prevent certain constructs to be formatted "like a block of text".

Before:
aaaaaaaaaaaaa<
aaaaaaaaaa, aaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa>* aaaa = new aaaaaaaaaaaaa<
aaaaaaaaaa, aaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa>(bbbbbbbbbbbbbbbbbbbbbbbb);
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb] = (*cccccccccccccccc)[
dddddddddddddddddddddddddddddddddddddddddddddddddddddddd];

After:
aaaaaaaaaaaaa<aaaaaaaaaa, aaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa>* aaaa =
new aaaaaaaaaaaaa<aaaaaaaaaa, aaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa>(
bbbbbbbbbbbbbbbbbbbbbbbb);
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb] =
(*cccccccccccccccc)[
dddddddddddddddddddddddddddddddddddddddddddddddddddddddd];

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185687 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
198c8bfee0b33ab0ed0c54224f460868f1c18e95 05-Jul-2013 Daniel Jasper <djasper@google.com> Don't break after a "(" following a binary operator.

Additionally, allow breaking after c-style casts, but with a high
penalty.

Before:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *foo = (
aaaaaaaaaaaaaaaaa *)bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
After:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *foo = (aaaaaaaaaaaaaaaaa *)
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;

This fixes llvm.org/PR16049.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185685 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
0bdc6434fa0fea933b6ab566eff751afdba40a2a 04-Jul-2013 Alexander Kornienko <alexfh@google.com> Fixed typo: NoneComment -> NonComment, no other changes.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185640 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
ormatToken.h
okenAnnotator.cpp
56312023bf62cb40d2e33ea5e14d55c1e42303a7 04-Jul-2013 Alexander Kornienko <alexfh@google.com> Added AlwaysBreakBeforeMultilineStrings option.

Summary:
Always breaking before multiline strings can help format complex
expressions containing multiline strings more consistently, and avoid consuming
too much horizontal space.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185622 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
6df7a2db6d74d41c4150b2c46b9a9e4e2db6c1dc 03-Jul-2013 Daniel Jasper <djasper@google.com> Don't insert confusing line breaks in comparisons.

In general, clang-format breaks after an operator if the LHS spans
multiple lines. Otherwise, this can lead to confusing effects and
effectively hide the operator precendence, e.g. in

if (aaaaaaaaaaaaaa ==
bbbbbbbbbbbbbb && c) { ...

This patch removes this rule for comparisons, if the LHS is not a binary
expression itself as many users were wondering why clang-format inserts
an unnecessary linebreak.

Before:
if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) >
5) { ...

After:
if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) > 5) { ...

In the long run, we might:
- Want to do this for other binary expressions as well.
- Do this only if the RHS is short or even only if it is a literal.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185530 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
6ac431c7bae27a42351d2c2ad03dddd5b005ffd5 02-Jul-2013 Daniel Jasper <djasper@google.com> Fix formatting of long declarations with const type.

Before (exceeding the column limit):
LoooooooooooooooooooooooooooooooooooooooongType const LoooooooooooooooooooooooooooooooooooooooongVariable;

After:
LoooooooooooooooooooooooooooooooooooooooongType const
LoooooooooooooooooooooooooooooooooooooooongVariable;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185418 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
f50dbfae1c5801d72d57fe5af90ad58871cea321 01-Jul-2013 Daniel Jasper <djasper@google.com> Fix incorrect token counting introduced by r185319.

This lead to weird formatting.
Before:
DoSomethingWithVector({ {} /* No data */ }, {
{ 1, 2 }
});
After:
DoSomethingWithVector({ {} /* No data */ }, { { 1, 2 } });

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185346 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
d446f737f0c4840f25a371bfc9ebedab69e4027d 01-Jul-2013 Alexander Kornienko <alexfh@google.com> Avoid column limit violation in block comments in certain cases.

Summary:
Add penalty when an excessively long line in a block comment can not be
broken on a leading whitespace. Lack of this addition can lead to severe column
width violations when they can be easily avoided.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185337 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
cbe86cc538b9e1af9f36b8a9c57ea51119306689 01-Jul-2013 Daniel Jasper <djasper@google.com> Don't align "} // namespace" comments.

This is not all bad, but people are often surprised by it.

Before:
namespace {
int SomeVariable = 0; // comment
} // namespace

After:
namespace {
int SomeVariable = 0; // comment
} // namespace

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185327 91177308-0d34-0410-b5e6-96231b3b80d8
hitespaceManager.cpp
c47d7f1237b022eabbbdcebf77506e8a81aa54bd 01-Jul-2013 Daniel Jasper <djasper@google.com> Don't add an extra space before ellipsis after pointers.

Before (for styles where the pointer binds to the type):
template <class... Ts> void Foo(Ts... ts) {}
template <class... Ts> void Foo(Ts* ... ts) {}
After:
template <class... Ts> void Foo(Ts... ts) {}
template <class... Ts> void Foo(Ts*... ts) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185321 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
3a1847e0a1810a0b1b963182abc59114cc5ff53d 01-Jul-2013 Daniel Jasper <djasper@google.com> Keep space between pointer and block comment.

Before: void f(int */* unused */) {}
After: void f(int * /* unused */) {}

The previous version seems to be valid C++ code but confuses many syntax
highlighters.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185320 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
02eacc2cf85fe11577bf6ff20f6c203e87147c57 01-Jul-2013 Daniel Jasper <djasper@google.com> Fix braced-list detection in lieu of trailing comments.

Before:
DoSomethingWithVector({
} /* No data */);
After:
DoSomethingWithVector({} /* No data */);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185319 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
e50947fcb029475f87578fb40f94982cec46c0c0 01-Jul-2013 Craig Topper <craig.topper@gmail.com> Put helper classes in an anonymous namespace.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185303 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
53d4f318d9fe8e09bd3afc3114abc04812840992 01-Jul-2013 Craig Topper <craig.topper@gmail.com> Use LLVM_DELETED_FUNCTION on unimplemented copy constructor and assignment operator.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185302 91177308-0d34-0410-b5e6-96231b3b80d8
ormatToken.h
14e66498781b7d81639bdc48716e09700552ac21 01-Jul-2013 Craig Topper <craig.topper@gmail.com> Put helper classes in an anonymous namespace.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185301 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
b8f716464b9f7eaae62aa9d646e7eca7f566990f 01-Jul-2013 Craig Topper <craig.topper@gmail.com> Use static for helper functions instead of an anonymous namespace per coding standards.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185300 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
cf1e216a2aa8ba3cc50cf046f5d057948b234a1f 01-Jul-2013 Craig Topper <craig.topper@gmail.com> Make string pointer const.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185296 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
83f81d712616130e62487f76522702fb8bca5002 01-Jul-2013 Craig Topper <craig.topper@gmail.com> Put helper classes into anonymous namespace.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185295 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
a1753f4be12737f36ce9c6eccccddd3be1ec514b 28-Jun-2013 Alexander Kornienko <alexfh@google.com> Use lexing mode based on FormatStyle.Standard.

Summary:
Some valid pre-C++11 constructs change meaning when lexed in C++11
mode, e.g.
#define x(_a) printf("foo"_a);
(example from http://llvm.org/bugs/show_bug.cgi?id=16342). "foo"_a is treated as
a user-defined string literal when parsed in C++11 mode.
In order to deal with this correctly, we need to set lexing mode according to
which standard the code conforms to. We already have a configuration value for
this (FormatStyle.Standard), which seems to be appropriate to use in this case
as well.

Reviewers: klimek

CC: cfe-commits, gribozavr

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185149 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
1907c57be5319397b722cbd3b8a4cdf2dbb8ce29 26-Jun-2013 Nico Weber <nicolasweber@gmx.de> Fix a comment.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184905 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
2726877196b41b922f10f794801b313980e1a8ad 26-Jun-2013 Nico Weber <nicolasweber@gmx.de> Run clang-format on lib/Format code after r184894. No other changes.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184896 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
nwrappedLineParser.cpp
861576b8019392f15c803ac14a4bc31fbd93aab2 26-Jun-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Don't put a space after parameter-naming block comments.

Before: f(a, b, /*doFoo=*/ false);
Now: f(a, b, /*doFoo=*/false);

This style is a lot more common:
$ ack -H '=\*\/\w' lib | wc -l
1281
$ ack -H '=\*\/ \w' lib | wc -l
70



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184894 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
0e5a8887ff30957f4bf59cc91965e7a620dbf34a 25-Jun-2013 Nico Weber <nicolasweber@gmx.de> Fix a comment.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184873 91177308-0d34-0410-b5e6-96231b3b80d8
ormatToken.h
465e8615a153ebd70eb27785af79f7e82e4a81d4 25-Jun-2013 Nico Weber <nicolasweber@gmx.de> Formatter/ObjC: Correctly format casts in objc message send expressions.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184804 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
a9a7f108a4a10da1f08fd4538a15f441bfee72c1 21-Jun-2013 Manuel Klimek <klimek@google.com> Add an option to not indent declarations when breaking after the type.

Make that option the default for LLVM style.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184563 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
8afa39b271d94969891dba014e0fc545b4873479 20-Jun-2013 Alexander Kornienko <alexfh@google.com> Use the same set of whitespace characters for all operations in BreakableToken.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184425 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
c36c5c247f53b0517b141ae5ae93f4580e9452ba 19-Jun-2013 Alexander Kornienko <alexfh@google.com> Fixed long-standing issue with incorrect length calculation of multi-line 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184340 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
f2b2c7da1f3bfed9b0bb194ff00d6e1e43d68d5c 19-Jun-2013 Alexander Kornienko <alexfh@google.com> Split long strings on word boundaries.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184304 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
d71b15badeecdc049440103ef044f9cdf5e1359c 17-Jun-2013 Alexander Kornienko <alexfh@google.com> Fix a problem in ExpressionParser leading to trailing comments affecting 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184078 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
22d0e2985d00010ed1d56168985ca34adc75b80a 17-Jun-2013 Alexander Kornienko <alexfh@google.com> Fixes incorrect indentation of line comments after break and re-alignment.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184076 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
hitespaceManager.cpp
16a0ec60507a4eec275a5c3a86d4501b1b7b817b 14-Jun-2013 Alexander Kornienko <alexfh@google.com> Don't remove backslashes from block comments.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183978 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
reakableToken.h
ormat.cpp
e3f1197cad5cda243093e8b39caa43f13111de89 12-Jun-2013 Alexander Kornienko <alexfh@google.com> Preserve newlines before block comments in static initializers.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183851 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
2b2faa53ecd32e823c55430d0889c11ea91b582c 11-Jun-2013 Alexander Kornienko <alexfh@google.com> Insert a space at the start of a line comment in case it starts with an 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183750 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
reakableToken.h
hitespaceManager.cpp
hitespaceManager.h
54e6c9d1f15153d1756642080866f10a91cc86ea 07-Jun-2013 Alexander Kornienko <alexfh@google.com> Improved handling of escaped newlines at the token start.

Summary: Remove them from the TokenText as well.

Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183536 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
ormatToken.h
2785b9aabcb2c3fd6f7dd8b63d3cd3d4b9bca284 07-Jun-2013 Alexander Kornienko <alexfh@google.com> Fixed calculation of penalty when breaking tokens.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183530 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
reakableToken.h
ormat.cpp
okenAnnotator.cpp
65d2c3829494d254039683c73f95843c29c661b4 06-Jun-2013 Daniel Jasper <djasper@google.com> Fix incorrect line breaking before trailing block comments.

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 */
...
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183420 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
9acb8b4355028887e8cc4aa8f683aceee021a62b 06-Jun-2013 Daniel Jasper <djasper@google.com> Fix clang-format's expression parser for leading }s.

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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183393 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
ff1a2e519ebcd6d7a060eac7ba8aca37b2bf89d0 06-Jun-2013 Daniel Jasper <djasper@google.com> Improve c-style cast detection.

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");

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183389 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
00895106f9ed602af67984ec4d225a0cdc8c12af 05-Jun-2013 Alexander Kornienko <alexfh@google.com> UTF-8 support for clang-format.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183312 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
reakableToken.h
ncoding.h
ormat.cpp
ormatToken.h
okenAnnotator.cpp
okenAnnotator.h
3b71155dc93fb3556dfe8b758ae6e448b6fbb9c8 03-Jun-2013 Alexander Kornienko <alexfh@google.com> Moved FormatToken to a separate header.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183115 91177308-0d34-0410-b5e6-96231b3b80d8
ormatToken.h
nwrappedLineParser.h
15f33f03e742fb6567e4789996fa0391a8e18068 03-Jun-2013 Daniel Jasper <djasper@google.com> Let clang-format remove empty lines before "}".

These lines almost never aid readability.

Before:
void f() {
int i; // some variable

}

After:
void f() {
int i; // some variable
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183112 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
ce912f45660613c1bc49696eb07ff7f8aecffe18 03-Jun-2013 Daniel Jasper <djasper@google.com> Improve detection preventing certain kind of formatting patterns.

An oversight in this detection made clang-format unable to format
the following nicely:
void aaaaaaaaaaaaaaaaaaa<aaaaaaaaaaaaaaaaaaaaaaaaaaa,
bbbbbbbbbbbbbbbbbbbbbbbbbb>(
cccccccccccccccccccccccccccc);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183097 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
5ef8aacd5f25767fc7bd1ec47c2b5f5fd1ac38eb 03-Jun-2013 Daniel Jasper <djasper@google.com> Fix line-breaking problem caused by comment.

Before, clang-format would not find a solution for formatting:
if ((aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ||
bbbbbbbbbbbbbbbbbb) && // aaaaaaaaaaaaaaaa
cccccc) {
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183096 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
0348be0c78781c5ddb8c271976812705410c731a 01-Jun-2013 Daniel Jasper <djasper@google.com> Improve recognition of template parameters.

Before: return a<b &&c> d;
After: return a < b && c > d;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183077 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
b8b4295b4ee161bfb76ff7b0ec1007bfd959553b 31-May-2013 Daniel Jasper <djasper@google.com> Improve clang-format's c-style cast detection.

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)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183014 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
f7ec1cc7f931833b2cb9876a5e7dfd6bf8681c6a 31-May-2013 Daniel Jasper <djasper@google.com> Improve clang-format's error recovery.

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(
};
..

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183009 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
8893b8a28d32359a5c778d9308780200a09402ba 31-May-2013 Daniel Jasper <djasper@google.com> Make formatting of empty blocks more consistent.

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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183008 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
c01897c3f6139304ed25e3f673bef77be209617f 31-May-2013 Daniel Jasper <djasper@google.com> Properly format nested conditional operators.

Before:
bool aaaaaa = aaaaaaaaaaaaa //
? aaaaaaaaaaaaaaa
: bbbbbbbbbbbbbbb //
? ccccccccccccccc
: ddddddddddddddd;

After:
bool aaaaaa = aaaaaaaaaaaaa //
? aaaaaaaaaaaaaaa
: bbbbbbbbbbbbbbb //
? ccccccccccccccc
: ddddddddddddddd;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183007 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
eb48366d41a6dcca236f1e28aea61efd569a3374 31-May-2013 Daniel Jasper <djasper@google.com> Fix detection/formatting of braced lists in ternary expressions.

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 };

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182992 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
cb4b40b86e284151d6ca14181f949655a9ceccd8 30-May-2013 Daniel Jasper <djasper@google.com> More fixes for clang-format's multiline comment breaking.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182940 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
920927016ed13bff83af016701b7d118a3dfed3b 30-May-2013 Daniel Jasper <djasper@google.com> Fix another clang-format crasher related to multi-line comments.

This fixes:
/*
*
* something long going over the column limit.
*/

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182932 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
b6dba337ba87c2f47a402ecccf4089ab86bbe70c 30-May-2013 Manuel Klimek <klimek@google.com> Add asserts to guard against regressions.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182916 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
e2c482f3720261dea180400816d4572d1986f423 30-May-2013 Daniel Jasper <djasper@google.com> Fix crasher when formatting certain block comments.

Smallest reproduction:
/*
**
*/

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182913 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
be9ed776e57fe606b5826a0d37a5a2dbfb927e63 30-May-2013 Manuel Klimek <klimek@google.com> Fixes error when splitting block comments.

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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182886 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
9c333b9c6fa08a6b7169556a6d23dac8b47918c2 29-May-2013 Manuel Klimek <klimek@google.com> Use a non-recursive implementation to reconstruct line breaks.

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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182861 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
b398701e4cbb9a55d90a60e3f4f4bc577446d098 29-May-2013 Manuel Klimek <klimek@google.com> The second step in the token refactoring.

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).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182859 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
okenAnnotator.h
nwrappedLineParser.h
hitespaceManager.cpp
hitespaceManager.h
c76d59d8ff564f918833c97caede7dce2d8cfe60 29-May-2013 Daniel Jasper <djasper@google.com> Add return missing in r182855.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182856 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
7e70f4c09c5e10c2690eac04d9d812fb8e4a0c0d 29-May-2013 Daniel Jasper <djasper@google.com> Leave some macros on their own line

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() {}
};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182855 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
bbc8776493fc0176d925a5b528e61ee400895047 29-May-2013 Daniel Jasper <djasper@google.com> Add option to always break template declarations.

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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182849 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
bac4681dd92a6bafe358f3bffaf81354cb5ef11c 28-May-2013 Daniel Jasper <djasper@google.com> Remove obsolete variable as discovered in post-commit review.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182796 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
88959b764ede8aac9118434f6c21c15463dff595 28-May-2013 Daniel Jasper <djasper@google.com> Support uniform inits in braced lists.

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 } };

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182788 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
3ff4a2fea4aa6e5182b7799ccb4352e56961a212 28-May-2013 Daniel Jasper <djasper@google.com> Fix formatting regression regarding pointers to arrays.

Before: f( (*PointerToArray)[10]);
After: f((*PointerToArray)[10]);

This fixes llvm.org/PR16163

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182777 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
dcb3f2aab329c80e97a44312d15299df4dc059be 28-May-2013 Manuel Klimek <klimek@google.com> Make UnwrappedLines and AnnotatedToken contain pointers to FormatToken.

The FormatToken is now not copyable any more.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182772 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
okenAnnotator.h
nwrappedLineParser.cpp
nwrappedLineParser.h
hitespaceManager.cpp
96e888b0dd3f114eee7e4455a74b8cb5f52e071d 28-May-2013 Manuel Klimek <klimek@google.com> A first step towards giving format tokens pointer identity.

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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182768 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
nwrappedLineParser.h
5ad390d27f8f7cb6628bc2c32beba4d25bc2718b 28-May-2013 Daniel Jasper <djasper@google.com> Initial support for designated initializers.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182767 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
okenAnnotator.h
d63312b1484a4642225c97e1dd013fe520b2b9a4 28-May-2013 Manuel Klimek <klimek@google.com> Disable tab expansion when counting the columns in block comments.

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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182760 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
c5cc4bf2699b0542f352738f84eee373cfcf670f 28-May-2013 Manuel Klimek <klimek@google.com> Fixes indentation of empty lines in block comments.

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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182757 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
431f5918281dd1f178bf838b7a47ab1d11c52961 28-May-2013 Daniel Jasper <djasper@google.com> Clean up formatting of function types.

Before:
int (*func)(void*);
void f() { int(*func)(void*); }

After (consistent space after "int"):
int (*func)(void*);
void f() { int (*func)(void*); }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182756 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
okenAnnotator.h
69c4371a978100d1538f414032f0a8750a0ca63f 28-May-2013 Daniel Jasper <djasper@google.com> Fix formatting of expressions containing ">>".

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;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182754 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
c04a5c38c8b1f317f4e606bd27baeba04b9b74ef 27-May-2013 David Blaikie <dblaikie@gmail.com> Remove unreachable return

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182742 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.h
131884a4bd9b72f8ced8c9f6d2b284f40fde1ea5 27-May-2013 Daniel Jasper <djasper@google.com> Improve formatting of templates.

Before: A < int&& > a;
After: A<int &&> a;

Also remove obsolete FIXMEs.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182741 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
de008c0f3bf66103185fc9f7f49995fa431451a6 27-May-2013 Manuel Klimek <klimek@google.com> Major refactoring of BreakableToken.

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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182738 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
reakableToken.h
ormat.cpp
nwrappedLineParser.h
hitespaceManager.cpp
hitespaceManager.h
512843a7dc01a4f1755e699d1e394a691a39c176 27-May-2013 Daniel Jasper <djasper@google.com> Improve indentation of assignments.

Before:
unsigned OriginalStartColumn = SourceMgr.getSpellingColumnNumber(
Current.FormatTok.getStartOfNonWhitespace()) -
1;

After:
unsigned OriginalStartColumn =
SourceMgr.getSpellingColumnNumber(
Current.FormatTok.getStartOfNonWhitespace()) -
1;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182733 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
b3778a61acca8ed127ba1b23013ca4c530539247 27-May-2013 Manuel Klimek <klimek@google.com> Address post-review comment from dblakie.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182732 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.h
259a038a97c37109752c70a05e17aa811de3bd8f 27-May-2013 Daniel Jasper <djasper@google.com> Fix hacky way of preventing a certain type of line break.

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);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182731 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
f2ff8126e9e9df368f31b1f968d8fc80f99809b3 26-May-2013 Nico Weber <nicolasweber@gmx.de> Formatter/ObjC: In dictionary literals, break after ':', not before it.

Before:
@{ NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
: regularFont, };

Now:
@{ NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee :
regularFont, };

':'s in dictionary literals (and the corresponding {}s) are now marked as
TT_ObjCDictLiteral too, which makes further improvements to dict literal
layout possible.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182716 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
okenAnnotator.h
6fb46b02599493d16e5130eff61050c72f65f89e 24-May-2013 Alexander Kornienko <alexfh@google.com> Ignore contents of #if 0 blocks.

Summary:
Added stack of preprocessor branching directives, and ignore all tokens
inside #if 0 except for preprocessor directives.

Reviewers: klimek, djasper

Reviewed By: klimek

CC: cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182658 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
nwrappedLineParser.h
ce93356e2719d2992763ea747b65beada99f4c9b 23-May-2013 Daniel Jasper <djasper@google.com> More tests and a fix for braced init lists.

Before: f(new vector<int> { 1, 2, 3 });
After: f(new vector<int>{ 1, 2, 3 });

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182614 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
854ca794c17679ba4d0e529e8eb8b6b3703d1984 23-May-2013 Manuel Klimek <klimek@google.com> Fix aligning of comments.

Previously we started sequences to align for single line comments when
the previous line had a trailing comment, but the sequence was broken
for other reasons.

Now we re-format:
// a
// b
f(); // c
to:
// a
// b
f(); // c

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182608 91177308-0d34-0410-b5e6-96231b3b80d8
hitespaceManager.cpp
23ad339cdb8ee55c5f243bc2573c5f9d6144a647 23-May-2013 Manuel Klimek <klimek@google.com> Fix aligning of comments that are at the start of the line.

Now correctly leaves:
f(); // comment
// comment
g(); // comment
... alone if the middle comment was aligned with g() before formatting.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182605 91177308-0d34-0410-b5e6-96231b3b80d8
hitespaceManager.cpp
de0d61fbe8bb0ba287eeed183bb98361d4e10c68 23-May-2013 Daniel Jasper <djasper@google.com> Increase test coverage for braced init lists.

Also fix a minor bug for constructor initializers with braced init lists.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182601 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
1bee0738b67b784f08d5e2f8351920260c9cfb1d 23-May-2013 Daniel Jasper <djasper@google.com> Improve formatting of braced lists.

Before: vector<int> v{ -1};
After: vector<int> v{-1};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182597 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
ebfb88c32adb40b64a44479708dc6931224ccf96 23-May-2013 Manuel Klimek <klimek@google.com> Stop aligning trailing comments which are aligned with the next line.

Previously we would align:
f(); // comment
// other comment
g();

Even if // other comment was at the start of the line. Now we do not
align trailing comments if they have been already aligned correctly
with the next line.

Thus,
f(); // comment
// other comment
g();
will not be changed, while:
f(); // comment
// other commment
g();
will lead to the two trailing comments being aligned.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182577 91177308-0d34-0410-b5e6-96231b3b80d8
hitespaceManager.cpp
ad3094b7d85a4f8eeaf3f60364d5e8796537f061 23-May-2013 Manuel Klimek <klimek@google.com> Use a SourceRange for the whitespace location in FormatToken.

Replaces the use of WhitespaceStart + WhitspaceLength.
This made a bug in the formatter obvous where we would incorrectly
calculate the next column.

FIXME: There's a similar bug left regarding TokenLength. We should
probably also move to have a TokenRange instead.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182572 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
nwrappedLineParser.h
hitespaceManager.cpp
2424eefa6936ec2dc35188e19c99e2f85428b52e 23-May-2013 Daniel Jasper <djasper@google.com> Improve formatting of braced lists.

Before:
vector<int> x { 1, 2, 3 };
After:
vector<int> x{ 1, 2, 3 };

Also add a style option to remove the spaces inside braced lists,
so that the above becomes:
std::vector<int> v{1, 2, 3};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182570 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
a3e21792f8774aa82964d52f8804f84152f79363 23-May-2013 Manuel Klimek <klimek@google.com> Fix no-assert compiles.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182569 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.h
80829bd8c3161cb706e28f29ac17a871f5eaaa5b 23-May-2013 Manuel Klimek <klimek@google.com> Expand parsing of braced init lists.

Allows formatting of C++11 braced init list constructs, like:
vector<int> v { 1, 2, 3 };
f({ 1, 2 });

This involves some changes of how tokens are handled in the
UnwrappedLineFormatter. Note that we have a plan to evolve the
design of the token flow into one where we create all tokens
up-front and then annotate them in the various layers (as we
currently already have to create all tokens at once anyway, the
current abstraction does not help). Thus, this introduces
FIXMEs towards that goal.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182568 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
nwrappedLineParser.h
0cd57b52c932c89fae03f0001add4821deaff5e7 22-May-2013 Manuel Klimek <klimek@google.com> Fix uninitialized access error found by valgrind.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182476 91177308-0d34-0410-b5e6-96231b3b80d8
hitespaceManager.cpp
e573c3f7fc40e813559ab4ff1e7eec4f66f1a50f 22-May-2013 Manuel Klimek <klimek@google.com> Makes whitespace management more consistent.

Instead of selectively storing some changes and directly generating
replacements for others, we now notify the WhitespaceManager of the
whitespace before every token (and optionally with more changes inside
tokens).

Then, we run over all whitespace in the very end in original source
order, where we have all information available to correctly align
comments and escaped newlines.

The future direction is to pull more of the comment alignment
implementation that is now in the BreakableToken into the
WhitespaceManager.

This fixes a bug when aligning comments or escaped newlines in unwrapped
lines that are handled out of order:
#define A \
f({ \
g(); \
});
... now gets correctly layouted.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182467 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
reakableToken.h
ormat.cpp
okenAnnotator.cpp
okenAnnotator.h
hitespaceManager.cpp
hitespaceManager.h
6e6efa7ec880559b7dd3096423b2345c0ff21c4c 22-May-2013 Daniel Jasper <djasper@google.com> Improve clang-format's stream formatting.

clang-format was a bit too aggressive when trying to keep labels and
values on the same line.

Before:
llvm::outs()
<< "aaaaaaaaaaaaaaaaaaa: " << aaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaa);
After:
llvm::outs() << "aaaaaaaaaaaaaaaaaaa: "
<< aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaa);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182458 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
24e19e4f96abd12f3f4b72b8a315b8ac257bc88f 22-May-2013 Daniel Jasper <djasper@google.com> Fix function declaration behavior.

This only affects styles that prevent bin packing. There, a break after
a template declaration also forced a line break after the function name.

Before:
template <class SomeType, class SomeOtherType>
SomeType
SomeFunction(SomeType Type, SomeOtherType OtherType) {}

After:
template <class SomeType, class SomeOtherType>
SomeType SomeFunction(SomeType Type, SomeOtherType OtherType) {}

This fixes llvm.org/PR16072.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182457 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
5ad72bb8eb8e5cc4c061ccd28632295213d319db 22-May-2013 Daniel Jasper <djasper@google.com> Improve handling of trailing 'const'.

Reduce the preference for breaking before a trailing 'const' according
to review comments on r182362.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182455 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
54b4e4468ec2bcd381ede70e1391bcdb59b8fd1a 22-May-2013 Daniel Jasper <djasper@google.com> Cut-off clang-format analysis.

If clang-format is confronted with long and deeply nested lines (e.g.
complex static initializers or function calls), it can currently try too
hard to find the optimal solution and never finish. The reason is that
the memoization does not work effectively for deeply nested lines.

This patch removes an earlier workaround and instead opts for
accepting a non-optimal solution in rare cases. However, it only does
so only in cases where it would have to analyze an excessive number of
states (currently set to 10000 - the most complex line in Format.cpp
requires ~800 states) so this should not change the behavior in a
relevant way.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182449 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
okenAnnotator.h
e033e87cbe77341777100093f8066167888d4440 21-May-2013 Daniel Jasper <djasper@google.com> Allow breaking before a trailing const.

Before:
void someLongFunction(
int someLongParameter) const;

After:
void someLongFunction(int someLongParameter)
const;

Also slightly cleanup tests.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182362 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
107db3c21133b71962bd8826c16d24652d6042a1 20-May-2013 Alexander Kornienko <alexfh@google.com> Minor fix: don't crash on empty configuration file, consider empty configuration files invalid.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182290 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
885f87b4be987fd8912779419ec88e3c37481967 19-May-2013 Alexander Kornienko <alexfh@google.com> Clang-format: allow -style="{yaml/json}" on command line

Summary: + improved handling of default style and predefined styles.

Reviewers: djasper, klimek

Reviewed By: klimek

CC: cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182205 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
399914b7a61a3823cc74ef3e47b1cde42528b9bf 17-May-2013 Daniel Jasper <djasper@google.com> Slightly modify the formatting rules for braced lists.

Basically, the new rule is: The opening "{" always has to be on the
same line as the first element if the braced list is nested
(e.g. in another braced list or in a function).

The solution that clang-format produces almost always adheres to this
rule anyway and this makes clang-format significantly faster for larger
lists. Added a test cases for the only exception I could find
(which doesn't seem to be very important at first sight).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182082 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
5d5b424589efe6b3dd963cb6a2b71b5583a4f6f2 16-May-2013 Daniel Jasper <djasper@google.com> Don't insert a break into include lines with trailing comments.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182003 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
f11bbb9b0e9b741c84214459526d3e5e137e9165 16-May-2013 Daniel Jasper <djasper@google.com> Add option to put short loops on a single line.

This enables things like:

for (int &v : vec) v *= 2;

Enabled for Google style.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182000 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
8a99945769aa83270bda4ae4890f519800aa19eb 16-May-2013 Daniel Jasper <djasper@google.com> Add a more convenient interface to use clang-format.

It turns out that several implementations go through the trouble of
setting up a SourceManager and Lexer and abstracting this into a
function makes usage easier.

Also abstracts SourceManager-independent ranges out of
tooling::Refactoring and provides a convenience function to create them
from line ranges.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181997 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
058f6f889a1df37f31bcf6b82060b8f815113471 16-May-2013 Daniel Jasper <djasper@google.com> Comments should not prevent single-line functions.

Before:
void f() {}
void g() {
} // comment

After:
void f() {}
void g() {} // comment

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181996 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
9a2f8d07bf820b524c7b23f6f625f206cad3bf96 16-May-2013 Daniel Jasper <djasper@google.com> Add back accidentally deleted line and add test for it.

Before:
f("a", "b"
"c");
After:
f("a", "b"
"c");

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181980 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
5be59ba8c9fb291f83970f0ebddceda70088bb28 15-May-2013 Daniel Jasper <djasper@google.com> Don't put short namespace on a single line.

Before:
namespace abc { class SomeClass; }
namespace def { void someFunction() {} }

After:
namespace abc {
class Def;
}
namespace def {
void someFunction() {}
}

Rationale:
a) Having anything other than forward declaration on the same line
as a namespace looks confusing.
b) Formatting namespace-forward-declaration-combinations different
from other stuff is inconsistent.
c) Wasting vertical space close to such forward declarations really
does not affect readability.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181887 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
5d823e3a00a3e21a0823288e6dee26a93758332b 15-May-2013 Daniel Jasper <djasper@google.com> Improve recognition of template definitions.

In the long run, this will probably be better fixed by a proper
expression parser..

Before:
template <typename F>
Matcher(const Matcher<F> & Other,
typename enable_if_c < is_base_of<F, T>::value &&
!is_same<F, T>::value > ::type * = 0)
: Implementation(new ImplicitCastMatcher<F>(Other)) {}

After:
template <typename F>
Matcher(const Matcher<F> & Other,
typename enable_if_c<is_base_of<F, T>::value &&
!is_same<F, T>::value>::type * = 0)
: Implementation(new ImplicitCastMatcher<F>(Other)) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181884 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
33f4b90476f24d269cac04915d951d8f05bd3a77 15-May-2013 Daniel Jasper <djasper@google.com> Break function declarations after multi-line return types.

Before:
template <typename A>
SomeLoooooooooooooooooooooongType<
typename some_namespace::SomeOtherType<A>::Type> Function() {}

After:
template <typename A>
SomeLoooooooooooooooooooooongType<
typename some_namespace::SomeOtherType<A>::Type>
Function() {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181877 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
9f3216199484a95fd765caa6555fd44e5c0ed1ea 15-May-2013 Daniel Jasper <djasper@google.com> Don't merge one-line functions in weird brace styles.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181872 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
caf42a3ef114900fd2ab927d1a13b4db000515e8 15-May-2013 Daniel Jasper <djasper@google.com> Remove diagnostics from clang-format.

We only ever implemented one and that one is not actually all that
helpful (e.g. gets incorrectly triggered by macros).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181871 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
nwrappedLineParser.h
a8fda85af8ddc91366b5522aee3a78a1fed206f7 15-May-2013 Daniel Jasper <djasper@google.com> Improve formatting of function types.

The function type detection in r181438 and r181764 detected function
types too eagerly. This led to inconsistent formatting of inline
assembly and (together with r181687) to an incorrect formatting of calls
in macros.

Before: #define DEREF_AND_CALL_F(parameter) f (*parameter)
After: #define DEREF_AND_CALL_F(parameter) f(*parameter)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181870 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
d741f02da9c91c197ba8816b4b454e1ad7cd47b6 14-May-2013 Daniel Jasper <djasper@google.com> Fix expression breaking for one-parameter-per-line styles.

Before:
if (aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||
aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||
aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||
aaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
After:
if (aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||
aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||
aaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181828 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
089f78d9cc1192244c9884e0e60dd82d415d8138 14-May-2013 Daniel Jasper <djasper@google.com> Fix uninitialized value bug found by valgrind.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181779 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
okenAnnotator.h
84f5ddfacc59c5d4878cd47b7794e53dc8e2e9f9 14-May-2013 Daniel Jasper <djasper@google.com> Correctly determine ranges for clang-format.

We have been assuming that CharSourceRange::getTokenRange() by itself
expands a range until the end of a token, but in fact it only sets
IsTokenRange to true. Thus, we have so far only considered the first
character of the last token to belong to an unwrapped line. This
did not really manifest in symptoms as all edit integrations
expand ranges to fully lines.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181778 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
1fb8d8814ae28a4ebe94652faafad8545a115bfe 14-May-2013 Daniel Jasper <djasper@google.com> Fix clang-format bug in unwrapped-line merging.

Before (in styles that allow it), clang-format would not merge an
if statement onto a single line, if only the second line was format
(e.g. in an editor integration):

if (a)
return; // clang-format invoked on this line.

With this patch, this gets properly merged to:

if (a) return; // ...

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181770 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
2a9805d227375efd988522873d4edc282010baae 14-May-2013 Manuel Klimek <klimek@google.com> Implement string literal breaking on unbreakable token sequences.

This fixes indentation where there are for example multiple closing
parentheses after a string literal, and where those parentheses
run over the end of the line.

During testing this revealed a bug in the implementation of
breakProtrudingToken: we don't want to change the state if we didn't
actually do anything.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181767 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
7424d79613a67ba200b6801468f2b59cde7ab087 14-May-2013 Daniel Jasper <djasper@google.com> Don't format sizeof/alignof as function types.

Before: A<sizeof (*x)> a;
After: A<sizeof(*x)> a;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181764 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
27c7f54cf7d18276be2979d5c795533cc5592675 13-May-2013 Daniel Jasper <djasper@google.com> Align a multiline string literal with the first part.

Before:
#define A(X) \
"aaaaa" #X "bbbbbb" \
"ccccc"

After:
#define A(X) \
"aaaaa" #X "bbbbbb" \
"ccccc"

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181732 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
2b6acb69f04ac5339fd39a9c03a0f5d076d51ac3 13-May-2013 Alexander Kornienko <alexfh@google.com> A better version of r181699: use raw_string_ostream.str() instead of manually calling .flush().

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181702 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
967d9e935d2379ea00726dc51fac5feeca50a4d0 13-May-2013 Manuel Klimek <klimek@google.com> Fix style according to post-commit review comments.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181701 91177308-0d34-0410-b5e6-96231b3b80d8
hitespaceManager.cpp
44135b8836fc3ffb84e540d8a097955271ccbc23 13-May-2013 Manuel Klimek <klimek@google.com> Implements brace breaking styles.

We now support "Linux" and "Stroustrup" brace breaking styles, which
gets us one step closer to support formatting WebKit, KDE & Linux code.

Linux brace breaking style:
namespace a
{
class A
{
void f()
{
if (x) {
f();
} else {
g();
}
}
}
}

Stroustrup brace breaking style:
namespace a {
class A {
void f()
{
if (x) {
f();
} else {
g();
}
}
}
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181700 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
af64032b085d3711405dbe8d98f71c463e0fb52b 13-May-2013 Alexander Kornienko <alexfh@google.com> Fixes [Bug 15960] YAMLTraits doesn't roundtrip on Windows.
Thanks to Kim Gräsman for help!


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181699 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
7c9a93ec7cea816e94a0674909c312f3d0227864 13-May-2013 Manuel Klimek <klimek@google.com> Implements UseTab for clang-format.

This is required for kernel linux kernel style formatting.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181693 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
hitespaceManager.cpp
hitespaceManager.h
c3df5ffb52cb656c3a4d0b4d70f8f28ed2390e78 13-May-2013 Daniel Jasper <djasper@google.com> Further improve optimization for nested calls.

Fake parentheses (i.e. emulated parentheses used to correctly handle
binary expressions) used to prevent the optimization implemented in
r180264.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181692 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
07a64eca75d96ce77d1ce8cb73d1cb0877695d06 13-May-2013 Manuel Klimek <klimek@google.com> Implements IndentWidth.

This is required for various styles that are for example based on
8-indent.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181690 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
378d93dcf7ec80661efc65642dc6266c9e13780a 13-May-2013 Daniel Jasper <djasper@google.com> Assume macros to contain declarations.

This seems to be the vastly more common case. If we find enough
examples to the contrary, we can make it smarter.

Before: #define MACRO void f(int * a)
After: #define MACRO void f(int *a)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181687 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
04abbb2125272a9930cbaee6530e7754566d8e66 10-May-2013 Daniel Jasper <djasper@google.com> When breaking at function calls, indent from function name.

Otherwise (when indenting from the wrapped -> or .), this looks
like a confusing indent.

Before:
aaaaaaa //
.aaaaaaa( //
aaaaaaa);
After:
aaaaaaa //
.aaaaaaa( //
aaaaaaa);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181595 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
89b3a7f76ffe333aa61ab63826834883236caf96 10-May-2013 Daniel Jasper <djasper@google.com> Always format entire macro definitions.

Thereby, the macro is consistently formatted (including the trailing
escaped newlines) even if clang-format is invoked only on single lines
of the macro.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181590 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
dd256314cf391063329e504f0ece46ee51bbfa2a 10-May-2013 Alexander Kornienko <alexfh@google.com> Config file support for clang-format, part 2.

Summary:
Adds actual config file reading to the clang-format utility.
Configuration file name is .clang-format. It is looked up for each input file
in its parent directories starting from immediate one. First found .clang-format
file is used. When using standard input, .clang-format is searched starting from
the current directory.
Added -dump-config option to easily create configuration files.

Reviewers: djasper, klimek

Reviewed By: klimek

CC: cfe-commits, jordan_rose, kimgr

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181589 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
6ea933c7e8f6988d5647af4a0eafd393a4c3685a 10-May-2013 Daniel Jasper <djasper@google.com> Fix bug when formatting overloaded operators.

Before, the actual operator of an overloaded operator declaration was
handled as a binary operator an thus, clang-format could not find valid
formattings for many examples, e.g.:

template <typename AAAAAAA, typename BBBBBBB>
AAAAAAA operator/(const AAAAAAA &a, BBBBBBB &b);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181585 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
okenAnnotator.h
4b7b104c2c66550ecc4ebfe39225fe067858b9aa 08-May-2013 Daniel Jasper <djasper@google.com> Further fix to pointer to member formatting.

With style where the *s go with the type:
Before: typedef bool* (Class:: *Member)() const;
After: typedef bool* (Class::*Member)() const;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181439 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
395228fdc343df39c2507e414dc1406a185c6d37 08-May-2013 Daniel Jasper <djasper@google.com> Fix formatting of pointers to members.

Before: int(S::*func)(void *);
After: int (S::*func)(void *);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181438 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
okenAnnotator.h
11e13801d8a25cea011c2a154380c371b6ddaaf6 08-May-2013 Daniel Jasper <djasper@google.com> Improve line breaking in binary expressions.

If the LHS of a binary expression is broken, clang-format should also
break after the operator as otherwise:
- The RHS can be easy to miss
- It can look as if clang-format doesn't understand operator precedence

Before:
bool aaaaaaaaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa !=
bbbbbbbbbbbbbbbbbb && ccccccccc == ddddddddddd;
After:
bool aaaaaaaaaaaaaaaaaaaaa =
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa != bbbbbbbbbbbbbbbbbb &&
ccccccccc == ddddddddddd;

As an additional note, clang-format would also be ok with the following
formatting, it just has a higher penalty (IMO correctly so).
bool aaaaaaaaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa !=
bbbbbbbbbbbbbbbbbb &&
ccccccccc == ddddddddddd;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181430 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
b2f063aeb93670c2415825be457b9e518a9fefdf 08-May-2013 Daniel Jasper <djasper@google.com> Change indentation of multi-line nested name specifiers.

Before:
aaaaaaaa::
aaaaaaaa::
aaaaaaaa();
After:
aaaaaaaa::
aaaaaaaa::
aaaaaaaa();

The reason for the change is that:
a) we are not sure which is better
b) it is a really rare edge case
c) it simplifies the code
d) it currently causes problems with memoization

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181421 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
d71ec16fffd10879bf74e531d9f7fb4c5ac4eaf8 07-May-2013 Alexander Kornienko <alexfh@google.com> Config file support for clang-format, part 1.

Summary:
Added parseConfiguration method, which reads FormatStyle from YAML
string. This supports all FormatStyle fields and an additional BasedOnStyle
field, which can be used to specify base style.

Reviewers: djasper, klimek

Reviewed By: djasper

CC: cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181326 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
dbef71ebc66fe5553db01eb8e95b696c3223e737 07-May-2013 Daniel Jasper <djasper@google.com> Correctly recognize dereference after 'delete'.

With certain styles:
Before: delete* x;
After: delete *x;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181318 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
fb59486ef3624d09896b09a978b28eb63cfd3c46 06-May-2013 Alexander Kornienko <alexfh@google.com> Added Mozilla style, cleaned get*Style methods.

Summary: Patch based on a patch by Ehsan Akhgari.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181196 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
7ff96ed7336b4f0efef05c10fd5ce5143918d4e1 06-May-2013 Daniel Jasper <djasper@google.com> Don't break comments after includes.

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
ormat.cpp
53e72cdcc0bc217cab33fa56858a0fe5b94ca453 06-May-2013 Daniel Jasper <djasper@google.com> Change indentation when breaking after a type.

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
ormat.cpp
okenAnnotator.cpp
okenAnnotator.h
c194c95036b7bf1281a6f2ed683f7c85ee5d2c20 06-May-2013 Daniel Jasper <djasper@google.com> Break the class-inheritance ":" to the new line.

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
okenAnnotator.cpp
f022018698ced7e538b338d4f7befef9f81051ea 06-May-2013 Daniel Jasper <djasper@google.com> Don't put a space before ellipsis.

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
okenAnnotator.cpp
454cb70f9470dc37d0c0646012877d64fb1e73d7 03-May-2013 Daniel Jasper <djasper@google.com> Add space between ; and (.

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
okenAnnotator.cpp
16a69ef481f4580c571b6c693a5d3dd64ea56b53 03-May-2013 Daniel Jasper <djasper@google.com> Fix expression recognition in for-loops.

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
okenAnnotator.cpp
fca24bc45192c254ca92ef1d7cef71a290392f31 25-Apr-2013 Daniel Jasper <djasper@google.com> 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180264 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
okenAnnotator.h
2972d049637349bb82f52a27ad3337cf4ab769b4 25-Apr-2013 Daniel Jasper <djasper@google.com> 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180253 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
hitespaceManager.cpp
hitespaceManager.h
94d6ad7b65b59f834bbc40e0caed5ceebca11932 24-Apr-2013 Daniel Jasper <djasper@google.com> Flip flag to merge short if-statements into one line for Google style.

This now allows clang-format to do:
if (a) return;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180187 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
af8497681e38106ad6f84408e029537e2a13d79d 24-Apr-2013 Daniel Jasper <djasper@google.com> 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180173 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
hitespaceManager.h
aae7bad5cdd804cb88e918e9defbf5faf69f4cfd 23-Apr-2013 Daniel Jasper <djasper@google.com> 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180105 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
001bf4e2bedfc6bc6a7638c098a004e4d57e308f 22-Apr-2013 Daniel Jasper <djasper@google.com> 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) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180001 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
919398bb40d5d643f38b6595f5e8eac641e89d50 17-Apr-2013 Alexander Kornienko <alexfh@google.com> 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179693 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
reakableToken.h
ormat.cpp
nwrappedLineParser.h
hitespaceManager.cpp
hitespaceManager.h
01218ffddc239a71951035d6c7698a11e323efe3 16-Apr-2013 Daniel Jasper <djasper@google.com> 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);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179570 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
e2657dd7aa2d5a41355f56c8dbb2104c6bf60648 15-Apr-2013 Alexander Kornienko <alexfh@google.com> Fix unused variable warning with assertions disabled.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179531 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
70ce7881fc30a39b795b2873f008e7eca72ba669 15-Apr-2013 Alexander Kornienko <alexfh@google.com> 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179526 91177308-0d34-0410-b5e6-96231b3b80d8
reakableToken.cpp
reakableToken.h
MakeLists.txt
ormat.cpp
hitespaceManager.cpp
hitespaceManager.h
67d080dafa74c7d126da522fec333a6e52a5ae35 12-Apr-2013 Manuel Klimek <klimek@google.com> 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179379 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
nwrappedLineParser.h
1407bee187d7b964d5293ac8bf4f7a490c78cec6 11-Apr-2013 Daniel Jasper <djasper@google.com> 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179287 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
2eb23b73f001e475c604652732f1a156f252352d 11-Apr-2013 Daniel Jasper <djasper@google.com> Fix formatting of overloaded assignment operators.

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
okenAnnotator.cpp
423dd93c8011aa8bca9b761b0b121ea8bce0fd03 10-Apr-2013 Manuel Klimek <klimek@google.com> Fixes recovering from errors when parsing braced init lists.

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
nwrappedLineParser.cpp
ac3223e45e7d17c65b143439313800eef4fdf71d 10-Apr-2013 Daniel Jasper <djasper@google.com> 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179167 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
okenAnnotator.h
5999f7634e80daf849a036aa830fc0e4b1e03555 09-Apr-2013 Daniel Jasper <djasper@google.com> Fix comments before labels.

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
ormat.cpp
99b0e14691b61d8db4f1d239a11615957071fb45 09-Apr-2013 Alexander Kornienko <alexfh@google.com> 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179099 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
3d713a72a01bf1d270d00040a3fb195121012c61 09-Apr-2013 Alexander Kornienko <alexfh@google.com> 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179064 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
bf71ba2988b34c45af968f0965e28ac952e4a15f 08-Apr-2013 Daniel Jasper <djasper@google.com> 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;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179049 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
okenAnnotator.h
65622aae92ff6e338abed83d31e512ee0e013dc7 08-Apr-2013 Daniel Jasper <djasper@google.com> Revert accidental commit r179015.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179016 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
okenAnnotator.h
c4ff76913ada469a70ed4bd960aeff038b6c2e1b 08-Apr-2013 Daniel Jasper <djasper@google.com> x

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179015 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
okenAnnotator.h
6b119d63f5036344acd4e00a6ff2b3c72f26966f 05-Apr-2013 Daniel Jasper <djasper@google.com> Allow breaking after 'class' for classes with looong names.

(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
okenAnnotator.cpp
27b91cc046f580fbe825f15b3e27f1b6407ee3e3 05-Apr-2013 Daniel Jasper <djasper@google.com> 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;
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178887 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
adc0f09585f10061007ec529451a6dd10f86fea6 05-Apr-2013 Daniel Jasper <djasper@google.com> 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;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178860 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
abfc9c160ad65e890b66480f3c52e9b5ef7bf4d8 04-Apr-2013 Daniel Jasper <djasper@google.com> Fix bug discovered with address sanitizer.

Now, this works again with an empty stack.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178779 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
8ed9f2b25f082a1643ab5310f9eec33cf31a7577 03-Apr-2013 Daniel Jasper <djasper@google.com> 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) {
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178641 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
okenAnnotator.h
4128e19d6f3ae42e840bc6aaf6ce6d052a46f7e4 03-Apr-2013 Alexander Kornienko <alexfh@google.com> 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178638 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
3776ef3a6c333e8fb57baf09972a7450c50c9fc5 03-Apr-2013 Daniel Jasper <djasper@google.com> Cleanup, add comments and address review comments.

No functional changes.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178626 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
3791130df5ad83e4a9872f90cc9675e90b772f88 02-Apr-2013 Daniel Jasper <djasper@google.com> 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()) {
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178542 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
f52d52790708132cc1a3b5c3aef1bed17eb6ff13 02-Apr-2013 Alexander Kornienko <alexfh@google.com> 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178537 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
81d2d38d2d774a2550fa0d2efffa707e7a53b39c 01-Apr-2013 Daniel Jasper <djasper@google.com> Improve formatting of function types.

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
ormat.cpp
okenAnnotator.cpp
9fdc00a237fe19b892f22780321ddfd1a3691d61 28-Mar-2013 Alexander Kornienko <alexfh@google.com> 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.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178261 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
94b748ff16172f0da2b842fe0d5bae438f07034f 27-Mar-2013 Alexander Kornienko <alexfh@google.com> 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178149 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.h
5262dd909a34f4c3e3f061009679fabb77b43ba4 27-Mar-2013 Alexander Kornienko <alexfh@google.com> 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178133 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
627707b9360597b65a9a0953d0ead2a08c3a0d5d 22-Mar-2013 Daniel Jasper <djasper@google.com> 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177740 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
nwrappedLineParser.cpp
c363dbb204b6c77b67dfed030436643947b37cbd 22-Mar-2013 Daniel Jasper <djasper@google.com> 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177739 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
b5985420d5910e068b0c8b84b8af2223e6bdf130 22-Mar-2013 Daniel Jasper <djasper@google.com> More precisely recognize ObjC method declarations.

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
okenAnnotator.cpp
b64eca09dd3bcd18eb1a5cca2b123b169340bdd5 22-Mar-2013 Daniel Jasper <djasper@google.com> 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:
//****************

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177720 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
7c22cf340995ab9107810aa39a190db3e0332294 21-Mar-2013 Alexander Kornienko <alexfh@google.com> 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177635 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
54a38bd5cf243310290f34b43fc940a498a00f90 20-Mar-2013 Alexander Kornienko <alexfh@google.com> 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177537 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
92f9faf3cf1065f987f227e0c2fdf06fcccf1ae8 20-Mar-2013 Daniel Jasper <djasper@google.com> 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177530 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
6fe554eb4e7075cbfda927c4747d7346a27637f1 20-Mar-2013 Daniel Jasper <djasper@google.com> Fix infinite-loop in unwrapped line parser.

Discovered when accidentally formatting a python file :-).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177527 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
83a90e5e6525acdb8cc4778ed102cd3952559f15 20-Mar-2013 Daniel Jasper <djasper@google.com> 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177524 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
64f092865c01c72ecb9e380432e241f3af55c249 20-Mar-2013 Daniel Jasper <djasper@google.com> Reduce penalty for breaks after "(" for functions with parameters.

Before:
aaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
After:
aaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177521 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
f9955d309d3de328e65563baf2d34571249dccbb 20-Mar-2013 Daniel Jasper <djasper@google.com> Add extra indentation for multiline comparisons.

This seems to be generally more desired.

Before:
if (aaaaaaaa &&
bbbbbbbb >
cccccccc) {}
After:
if (aaaaaaaa &&
bbbbbbbb >
cccccccc) {}

Also: Some formatting cleanup on clang-format's files.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177514 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
nwrappedLineParser.cpp
bcca7e484117f3155ff98f9560996e760ca4f786 20-Mar-2013 Daniel Jasper <djasper@google.com> Don't remove all indentation when in #defines.

Otherwise, this can become hard to read.

Before: #define A \
case 1:
After: #define A \
case 1:

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177509 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
9322aaee900b872c98f8fc10b38a231cb1e9b57a 20-Mar-2013 Daniel Jasper <djasper@google.com> Improve formatting of function types in template parameters.

Before: A<int * (int)>;
After: A<int *(int)>;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177505 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
c30eb51b639e132af458fbf7647eefae6edb93ac 19-Mar-2013 Daniel Jasper <djasper@google.com> Fix indentation for case: // comment.

Before:
switch (x) {
case 1:
// Do amazing stuff
{
g();
f();
}
}

After:
switch (x) {
case 1:
// Do amazing stuff
{
g();
f();
}
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177420 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
052685c170fcc4fa057c68a44425e6d9b945a167 19-Mar-2013 Alexander Kornienko <alexfh@google.com> Split long lines in multi-line comments.

Summary: This is implementation for /* */ comments only.

Reviewers: djasper, klimek

Reviewed By: djasper

CC: cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177415 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
cf6d76af806f7e1ba97be7b72b31bc78b919e0f0 18-Mar-2013 Daniel Jasper <djasper@google.com> Fix clang-format segfault.

When annotating "lines" starting with ":", clang-format would segfault.
This could actually happen in valid code, e.g.
#define A :

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177283 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
3af59ce065310fd3d0820a6e2644d4ca688be810 15-Mar-2013 Daniel Jasper <djasper@google.com> Improve formatting of chained calls.

clang-format already prevented sequences like:
...
SomeParameter).someFunction(
...

as those are quite confusing. This failed on:
...
SomeParameter).someFunction(otherFunction(
...

Fixed in this patch.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177157 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
1fdd8b351e28ee175157e61dac1b3f62b79b7a62 15-Mar-2013 Alexander Kornienko <alexfh@google.com> Indent all lines in a multi-line comment by the same amount.

Summary:
Do this to avoid spoling nicely formatted multi-line comments (e.g.
with code examples or similar stuff).

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177153 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
f753615897c86928517e48e4d106e669d59618c5 14-Mar-2013 Alexander Kornienko <alexfh@google.com> Multi-line comment alignment

Summary:
Aligns continuation lines of multi-line comments to the base
indentation level +1:
class A {
/*
* test
*/
void f() {}
};

The first revision is work in progress. The implementation is not yet complete.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177080 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
bfa1edd8247b80e951a570ff2486fe5fa9898c41 14-Mar-2013 Daniel Jasper <djasper@google.com> Slightly improve formatting of longer pipe statements.

The stronger binding of a string ending in :/= does not really make
sense if it is the only character.

Before:
llvm::outs() << aaaaaaaaaaaaaaaaaaaaaaaa
<< "=" << bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;

After:
llvm::outs() << aaaaaaaaaaaaaaaaaaaaaaaa << "="
<< bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177075 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
923ebef120a37122ce50722a85cbe42c0c2dab53 14-Mar-2013 Daniel Jasper <djasper@google.com> Basic support for formatting asm() statments.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177073 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
okenAnnotator.h
d3cf17b5f1fed43dbd0cd35c43d15139803c9c84 14-Mar-2013 Daniel Jasper <djasper@google.com> Fix dereference formatting in for-loops.

Before: for (char **a = b; * a; ++a) {}
After: for (char **a = b; *a; ++a) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177037 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
8ef19a22956defa392df46c79e2d499ab7b16647 14-Mar-2013 Daniel Jasper <djasper@google.com> Improve formatting of trailing annotations.

Before:
bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa __attribute__((
unused));

After:
bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
__attribute__((unused));

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177034 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
6a365aaa057a8c445d25344c0433726c752b3e7d 13-Mar-2013 Daniel Jasper <djasper@google.com> Fix incorrect cast identification.

Before: int a = sizeof(int *)+ b;"
After: int a = sizeof(int *) + b;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176957 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
6050a1e53aa3cd3b21d65d440413af5a5ac1d466 13-Mar-2013 Daniel Jasper <djasper@google.com> Fix comment indentation before labels.

Before:
switch (x) {
// if 1, do f()
case 1:
f();
}

After:
switch (x) {
// if 1, do f()
case 1:
f();
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176953 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
8d0d19aa33751d89390e6a2bb2c2b19def287abe 13-Mar-2013 Daniel Jasper <djasper@google.com> Fix formatting issue with builder-type calls.

Before:
->aaaaaa()->aaaaaaaaaaa(aaaaaaaa()->aaaaaa()->aaaaa() - aaaaaaaaa()->aaaaaa()
->aaaaa());

After:
a->aaaaaa()->aaaaaaaaaaa(aaaaaaaa()->aaaaaa()->aaaaa() -
aaaaaaaaa()->aaaaaa()->aaaaa());

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176952 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
e74de28ec3692986f3467a7f160a0e293277fa7e 13-Mar-2013 Alexander Kornienko <alexfh@google.com> Added AnnotatedToken::isOneOf + a few other refactorings

Summary: <subj>

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176951 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
okenAnnotator.h
6f21a988990ff5872822dcb049bd8fc65ce3d236 13-Mar-2013 Daniel Jasper <djasper@google.com> Fix formatting of new arrays of pointers.

Before:
A = new SomeType * [Length];
A = new SomeType *[Length]();

After:
A = new SomeType *[Length];
A = new SomeType *[Length]();

Small formatting cleanups with clang-format.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176936 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
3fd9ccdd9f8d259bcf518e7056cfd419d992e984 12-Mar-2013 Alexander Kornienko <alexfh@google.com> Implemented formatting of rvalue references

Summary:
Handle "&&" usage as rvalue reference, added tests and fixed incorrect
tests that interfere with this feature.

http://llvm.org/bugs/show_bug.cgi?id=15051

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176874 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
4ba9bfd89d0ceb4eae161a4a21dd8e50be752754 12-Mar-2013 Daniel Jasper <djasper@google.com> Remove bad space after "default".

Before:
switch (x) {
default : {}
}

After:
switch (x) {
default: {}
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176861 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
aa62d0c4fc9449d4c438fe200ef329b067c037c7 08-Mar-2013 Manuel Klimek <klimek@google.com> Fixes breaking of string literals.

1. We now ignore all non-default string literals, including raw
literals.
2. We do not break inside escape sequences any more.

FIXME: We still break in trigraphs.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176710 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
f302354a7d1a63186fb0d9aa600ce3257be1f690 07-Mar-2013 Daniel Jasper <djasper@google.com> Remove unncessary whitespace when triggered on empty line.

With the cursor located at "I", clang-format would not do anything to:

int a;

I

int b;

With this patch, it reduces the number of empty lines as necessary, and
removes unnecessary whitespace. It does not change/reformat "int a;" or
"int b;".

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176650 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
0090591e505637cf2d9ea3b45768334d78d24ca2 04-Mar-2013 Manuel Klimek <klimek@google.com> Make sure to not split string literals at the first character.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176447 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
1eee6c4269af28eb4e3500de7fc39c1eb8b26aa3 04-Mar-2013 Daniel Jasper <djasper@google.com> Format a line if a range in its leading whitespace was selected.

With [] marking the selected range, clang-format invoked on

[ ] int a;

Would so far not reformat anything. With this patch, it formats a
line if its leading whitespace is touched.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176435 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.h
516fb31d0536040334032e2af6b62cd6a5479d1c 01-Mar-2013 Daniel Jasper <djasper@google.com> Remove whitespace at end of file.

This fixes the rest of llvm.org/PR15062.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176361 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
8a5d7cd100ebfb8c6b353ee4ad5b14ab4105d32d 01-Mar-2013 Daniel Jasper <djasper@google.com> Correctly format arrays of pointers and function types.

Before:
void f(Type(*parameter)[10]) {}
int(*func)(void *);

After:
void f(Type (*parameter)[10]) {}
int (*func)(void *);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176356 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
248497199bc56e86d1c089beb9529f3b3d77abb1 01-Mar-2013 Daniel Jasper <djasper@google.com> Normal indent for last element of builder-type call.

In builder type call, we indent to the laster function calls.
However, for the last element of such a call, we don't need to do
so, as that normally just wastes space and does not increase
readability.

Before:
aaaaaa->aaaaaa->aaaaaa( // break
aaaaaa);
aaaaaaaaaaaaaaaaaaaaa->aaaaaaaaaaaaaaaaaaaaaa
->aaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

After:
aaaaaa->aaaaaa->aaaaaa( // break
aaaaaa);
aaaaaaaaaaaaaaaaaaaaa->aaaaaaaaaaaaaaaaaaaaaa->aaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176352 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
okenAnnotator.h
812c045e591495b940f5a9102b146bb43b970e1f 01-Mar-2013 Daniel Jasper <djasper@google.com> Remove trailing whitespace of line comments.

This fixed llvm.org/PR15378.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176351 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
bc30c71d20f05bc39b5dd73f06ee4dede9c55710 01-Mar-2013 Manuel Klimek <klimek@google.com> Implements breaking string literals at slashes.

We now break at a slash if we do not find a space to break on.

Also fixes a bug where we would go over the limit when breaking the
second line.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176350 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
af31fd7021e685280da9155e5017f1053b05fdf8 01-Mar-2013 Manuel Klimek <klimek@google.com> Implement fallback split point for string literals.

If we don't find a natural split point (currently space) in a string
literal protruding over the line, we just split at the last possible
point.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176349 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
25e81b255cea00fe633f2822c1d1d708ef871a59 28-Feb-2013 Daniel Jasper <djasper@google.com> Reduce penalty for splitting after "{" in static initializers.

This fixes llvm.org/PR15379.

Before:
const uint8_t aaaaaaaaaaaaaaaaaaaaaa[0] = { 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // comment
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // comment
0x00, 0x00, 0x00, 0x00 // comment
};

After:
const uint8_t aaaaaaaaaaaaaaaaaaaaaa[0] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment
0x00, 0x00, 0x00, 0x00 // comment
};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176262 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
8ed4100410ea055a03be5ec4a92a947a0ee664cd 28-Feb-2013 Daniel Jasper <djasper@google.com> Dont break between (( in __attribute__((.

Before:
void aaaaaaaaaaaaaaaaaa() __attribute__(
(aaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaa));

After:
void aaaaaaaaaaaaaaaaaa()
__attribute__((aaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaa));

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176260 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
9c3c7b3130bc72b3f50703c11b85152b1264fc90 28-Feb-2013 Daniel Jasper <djasper@google.com> No spaces around pointers to members.

Before: (a ->* f)()
After: (a->*f)()

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176252 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
a4d4621b206f941cc58d9d0bc7c67a8e705c9d49 28-Feb-2013 Daniel Jasper <djasper@google.com> Improve formatting of #defines.

Two improvements:
1) Always leave at least one space before "\". Otherwise is can look bad
and there is a risk of unwillingly joining to characters to a different
token.
2) Use the full column limit for single-line #defines.
Fixes llvm.org/PR15148

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176245 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
b6f02f3bcb5ddcd7c7f1a3571d554fe55c72968f 28-Feb-2013 Daniel Jasper <djasper@google.com> Fix bug when formatting "A<A<A>>".

Before:
A<A<A>> ReadKansas(int aaaaaaaaaaaaaaaaaaaaaaaaaaa,
int aaaaaaaaaaaaaaaaaaaaaaa);
Before:
A<A<A>> ReadKansas(int aaaaaaaaaaaaaaaaaaaaaaaaaaa,
int aaaaaaaaaaaaaaaaaaaaaaa);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176244 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
3a39ac7cee044cf7d9b524b529a97d5f075ee695 28-Feb-2013 Daniel Jasper <djasper@google.com> Fix incorrect recognition of bin-packing.

Before (in Google style):
Constructor()
: aaaaa(aaaaaa), aaaaa(aaaaaa), aaaaa(aaaaaa), aaaaa(aaaaaa), aaaaa(
aaaaaa) {}

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176242 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
807809c421811509f488f3ebd249585025ad918a 28-Feb-2013 Daniel Jasper <djasper@google.com> Fix spacing after binary operator as macro parameter.

Before: COMPARE(a, == , b);
After: COMPARE(a, ==, b);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176241 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
9c65b069821b7de79427e291b006293a0f55ff8f 27-Feb-2013 Daniel Jasper <djasper@google.com> Fix formatting of multiplications in array subscripts.

Before:
a[a* a] = 1;

After:
a[a * a] = 1;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176180 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
faab0d35da240bde26a6281ed1cfa14c44585a5a 27-Feb-2013 Daniel Jasper <djasper@google.com> Enable bin-packing in Google style.

After some discussions, it seems that this is the better path in
the long run. Does not change Chromium style, as there, bin packing
is forbidden by the style guide.

Also fix two minor bugs wrt. formatting:
1. If a call parameter is a function call itself and is split before
the "." or "->", split before the next parameter.
2. If a call parameter is string literal that has to be split onto
two lines, split before the next parameter.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176177 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
518ee34467c0722e253a58efea20456e96aa5802 26-Feb-2013 Daniel Jasper <djasper@google.com> Fix bad line break decision.

Before:
if (Intervals[i].getRange().getFirst() < Intervals[i - 1]
.getRange().getLast()) {}

After:
if (Intervals[i].getRange().getFirst() <
Intervals[i - 1].getRange().getLast()) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176092 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
84a1a63b034744b68a27ec171dca5b1b7cf303f0 26-Feb-2013 Daniel Jasper <djasper@google.com> In range-based for-loops, prefer splitting after ":".

Before:
for (const aaaaaaaaaaaaaaaaaaaaa &
aaaaaaaaa : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}

After:
for (const aaaaaaaaaaaaaaaaaaaaa &aaaaaaaaa :
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176087 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
1ef81d57fbcc26080c98e140e7c82db6d2aeba87 26-Feb-2013 Daniel Jasper <djasper@google.com> Only keep empty lines in unwrapped lines if they preceed a line comment.

Empty lines followed by line comments are often used to highlight the
comment. Empty lines somewhere else are usually left over from manual or
automatic formatting and should probably be removed.

Before (clang-format would keep):
S s = {
a,

b
};

After:
S s = { a, b };

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176086 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
0fb382bfbfbfee73763a213b2257042ed342c4b0 26-Feb-2013 Daniel Jasper <djasper@google.com> Only break string literals as a last resort.

We might want to move towards doing this if the formatting can be
significantly improved, but we need to carefully evaluate the different
situations first.

Before (the string literal was split by clang-format here):
aaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaa, aaaaaa("aaa aaaaa aaa aaa aaaaa aaa "
"aaaaa aaa aaa aaaaaa"));

After:
aaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaa,
aaaaaa("aaa aaaaa aaa aaa aaaaa aaa aaaaa aaa aaa aaaaaa"));

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176084 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
9c3e71acb53a67f305a54f3d6d6decb143acaae4 25-Feb-2013 Daniel Jasper <djasper@google.com> Re-add hack that caused regression.

This fixes llvm.org/PR15350.

Before:
Constructor(int Parameter = 0)
: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaa),
aaaaaaaaaaaa(aaaaaaaaaaaaaaaaa) {}

After:
Constructor(int Parameter = 0)
: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaa),
aaaaaaaaaaaa(aaaaaaaaaaaaaaaaa) {}

I think the correct solution is to put the VariablePos into
ParenState, not LineState. Added FIXME.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176027 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
3c08a818a6ac9115fe8880af9bbf5a0a87bdffaa 24-Feb-2013 Daniel Jasper <djasper@google.com> Allow breaking between a type and name in variable declarations.

This fixes llvm.org/PR14967 and is generall necessary to avoid
situations where the column limit is exceeded. The challenge is
restricting such lines splits, otherwise clang-format suddenly starts
breaking at bad places.

Before:
ReallyLongReturnType<TemplateParam1, TemplateParam2>
ReallyReallyLongFunctionName(
const std::string &SomeParameter,
const SomeType<string,
SomeOtherTemplateParameter> &ReallyReallyLongParameterName,
const SomeType<string,
SomeOtherTemplateParameter> &AnotherLongParameterName) {}

After:
ReallyLongReturnType<TemplateParam1, TemplateParam2>
ReallyReallyLongFunctionName(
const std::string &SomeParameter,
const SomeType<string, SomeOtherTemplateParameter> &
ReallyReallyLongParameterName,
const SomeType<string, SomeOtherTemplateParameter> &
AnotherLongParameterName) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175999 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
okenAnnotator.h
237d4c1c785be13656bff6c09e5b7ccd066ff5ba 23-Feb-2013 Daniel Jasper <djasper@google.com> Better formatting of conditional expressions.

In conditional expressions, if the condition is split over multiple
lines, also break before both operands.

This prevents formattings like:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ? b : c;

Which are bad, because they suggestion incorrect operator precedence:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ? b : c);

This lead to the discovery that the expression parser incorrectly
handled conditional operators and that it could also handle semicolons
(which in turn reduced the amount of special casing for for-loops). As a
side-effect, we can now apply the bin-packing configuration to the
sections of for-loops.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175973 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
37eff83413a064c504c5a42097e4f5dd0b2962d2 23-Feb-2013 Daniel Jasper <djasper@google.com> Don't recognize unnamed pointer parameters as casts.

This fixes llvm.org/PR15061.

Before: virtual void f(int *)const;
After: virtual void f(int *) const;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175960 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
3a204418482c9ae70ad482e781132c54306c3aa6 23-Feb-2013 Daniel Jasper <djasper@google.com> Allow splitting between string literals and identifiers.

Also don't break in long include directives as that is not desired.

We can now format:

#include "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
#define LL_FORMAT "ll"
printf("aaaaa: %d, bbbbbbbbb: %" LL_FORMAT "d, cccccccc: %" LL_FORMAT
"d, ddddddddd: %" LL_FORMAT "d\n");

Before, this led to weird results.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175959 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
1c1303b1fa988ffae7e269fbdbd5a50e4ba860a0 21-Feb-2013 Daniel Jasper <djasper@google.com> Remove accidentally introduced no-op line.

Was used during experiments, but another if-statements a few lines
before makes it (intentionally) useless.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175803 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
f11a705c6075b12cbae5632ba4de433bc9bc105f 21-Feb-2013 Daniel Jasper <djasper@google.com> Consistently put {} onto the same line for empty functions.

This fixes llvm.org/PR15167.

Before:
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL()
: AAAAAAAA(10), BBBBBBBBB(10) {
}
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL() : AAAAAAAA(10) {}

After:
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL()
: AAAAAAAA(10), BBBBBBBBB(10) {}
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL() : AAAAAAAA(10) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175800 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
7d81281fc39f6d40d86be6600adba13c05b4a639 21-Feb-2013 Daniel Jasper <djasper@google.com> Allow breaking between type and name in for loops.

This fixes llvm.org/PR15033.

Also: Always break before a parameter, if the previous parameter was
split over multiple lines. This was necessary to make the right
decisions in for-loops, almost always makes the code more readable and
also fixes llvm.org/PR14873.

Before:
for (llvm::ArrayRef<NamedDecl *>::iterator I = FD->getDeclsInPrototypeScope()
.begin(), E = FD->getDeclsInPrototypeScope().end();
I != E; ++I) {
}
foo(bar(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
ccccccccccccccccccccccccccccc), d, bar(e, f));

After:
for (llvm::ArrayRef<NamedDecl *>::iterator
I = FD->getDeclsInPrototypeScope().begin(),
E = FD->getDeclsInPrototypeScope().end();
I != E; ++I) {
}
foo(bar(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
ccccccccccccccccccccccccccccc),
d, bar(e, f));

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175741 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
e9a6226c7a2fd1c30a00990cdeb69b89f5599fb3 20-Feb-2013 Manuel Klimek <klimek@google.com> Fix regression in string literal alignment.

Now correctly indents (again):
a = a + "a"
"a"
"a";

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175630 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
b56b6d1bd6f41d7b944a9631a9ab481cafe6535b 20-Feb-2013 Manuel Klimek <klimek@google.com> Fixes bug in string literal alignment.

We now indent the following correctly:
1. some + "literal" /* comment */
"literal";
2. breaking string literals after which we have another string literal.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175628 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
c4615b7aaf97e303a4fc675956f7f5572d492885 20-Feb-2013 Daniel Jasper <djasper@google.com> Don't remove blank lines within unwrapped lines.

If the code author decides to put empty lines anywhere into the code we
should treat them equally, i.e. reduce them to the configured
MaxEmptyLinesToKeep.

With this change, we e.g. keep the newline in:
SomeType ST = {
// First value
a,

// Second value
b
};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175620 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
8092a940922f307edb569036a3bb6bb722fb3a3d 20-Feb-2013 Manuel Klimek <klimek@google.com> Implements breaking of string literals if they stick out.

An alternative strategy to calculating the break on demand when hitting
a token that would need to be broken would be to put all possible breaks
inside the token into the optimizer.

Currently only supports breaking at spaces; more break points to come.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175613 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
03628b86a9c50e066412fb0e49908686ff117378 19-Feb-2013 Daniel Jasper <djasper@google.com> Add missing clang-format null pointer check..

.. and a test that triggers it in valid albeit questionable code.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175554 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
34511fb79201ba9ed39c97f3a7ea0f157a79436d 19-Feb-2013 Daniel Jasper <djasper@google.com> Correctly format macro with unfinished template declaration.

We can now format:
#define A template <typename T>

Before this created a segfault :-/.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175533 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
d78967088c02b69166810cffae5471bccea91ca3 19-Feb-2013 Daniel Jasper <djasper@google.com> Fix bug in LineState comparison function.

The key bug was

if (Other.StartOfLineLevel < StartOfLineLevel) ..

instead of

if (Other.StartOfLineLevel != StartOfLineLevel) ..

Also cleaned up the function to be more consistent in the comparisons.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175500 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
82282dc907a04b1931f8f578693b035ad751fd3b 18-Feb-2013 Daniel Jasper <djasper@google.com> Improve indentation of builder type calls.

In builder-type calls, it can be very confusing to just indent
parameters from the start of the line. Instead, indent 4 from the
correct function call.

Before:
aaaaaaaaaaaaaaaaaaa()->aaaaaa(bbbbb)->aaaaaaaaaaaaaaaaaaa( // break
aaaaaaaaaaaaaa);
aaaaaaaaaaaaaaaaaaaaaaa *aaaaaaaaa = aaaaaa->aaaaaaaaaaaa()->aaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
->aaaaaaaaaaaaaaaaa();

After:
aaaaaaaaaaaaaaaaaaa()->aaaaaa(bbbbb)->aaaaaaaaaaaaaaaaaaa( // break
aaaaaaaaaaaaaa);
aaaaaaaaaaaaaaaaaaaaaaa *aaaaaaaaa = aaaaaa->aaaaaaaaaaaa()
->aaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
->aaaaaaaaaaaaaaaaa();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175444 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
515f65df40624a767bc8763a0b6b678146b8e3c9 18-Feb-2013 Daniel Jasper <djasper@google.com> Improve formatting of builder-type calls.

Before:
aaaaaaa->aaaaaaa->aaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)->aaaaaaaa(aaaaaaaaaaaaaaa);

After:
aaaaaaa->aaaaaaa
->aaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
->aaaaaaaa(aaaaaaaaaaaaaaa);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175441 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
29333160cfd863a451ddb6fd505c3619c3724c95 18-Feb-2013 Daniel Jasper <djasper@google.com> Reformat lines if they were "moved around".

An unwrapped line can get moved around if there is no newline before
it and the previous line was formatted.

Example:

template<typename T> // Cursor is on this line when hitting "format"
T *getFETokenInfo() const { return static_cast<T*>(FETokenInfo); }

"return .." is the second unwrapped line in this scenario. I does not
touch any reformatted region. Thus, the result of formatting is:

template <typename T> T *getFETokenInfo() const { return static_cast<T *>(FETokenInfo); }

After second format (and arguably desired end-result):

template <typename T> T *getFETokenInfo() const {
return static_cast<T *>(FETokenInfo);
}

This fixes: llvm.org/PR15060.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175440 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
d0f349be1422a123fdb28d6dd556f7300e6d51e9 18-Feb-2013 Daniel Jasper <djasper@google.com> Correctly determine */& usage in more cases.

This fixes llvm.org/PR15248.

Before:
Test::Test(int b) : a(b *b) {}
for (int i = 0; i < a *a; ++i) {}

After:
Test::Test(int b) : a(b * b) {}
for (int i = 0; i < a * a; ++i) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175439 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
66d19bdeef25611c9188b3f27b7d578df4b9a447 18-Feb-2013 Daniel Jasper <djasper@google.com> Always break after multi-line string literals.

Otherwise, other parameters can be quite hidden.
Reformatted unittests/Format/FormatTest.cpp after this.

Before:
someFunction("Always break between multi-line"
" string literals", and, other, parameters);

After:
someFunction("Always break between multi-line"
" string literals",
and, other, parameters);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175436 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
cf5767d65a0ee64b22c242eb758e8684a6ea5a59 18-Feb-2013 Daniel Jasper <djasper@google.com> Prevent line breaks that make stuff hard to read.

Before:
aaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaa).aaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaa).aaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

After:
aaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaa)
.aaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaa)
.aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175432 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
6ba52aab96c96b6d91ed7f5844f607b32f7f41c4 16-Feb-2013 Dmitri Gribenko <gribozavr@gmail.com> Use the correct type to hold enumeration values


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175374 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
4a544e5856ceadef1c095c7d1ae5c8d760851d59 15-Feb-2013 Daniel Jasper <djasper@google.com> Recognize < and > as binary expressions in builder-type calls.

The current heuristic assumes that there can't be binary operators in
builder-type calls (excluding assigments). However, it also excluded
< and > in general, which is wrong. Now they are only excluded if they
are template parameters.

Before:
return aaaaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa()i
.aaaaaa() < aaaaaaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa().aaaaaa();

After:
return aaaaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa().aaaaaa() <
aaaaaaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa().aaaaaa();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175291 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
dc2efa1c10c4646d692cc57db9fdbbebe3a48255 15-Feb-2013 Daniel Jasper <djasper@google.com> Done break between 'operator' and '<<'.

Before:
ostream &operator
<<(ostream &out, some::ns::SomeReallyLongType WithSomeReallyLongValue);

After:
ostream &operator<<(ostream &out,
some::ns::SomeReallyLongType WithSomeReallyLongValue);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175286 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
b130a54940171a95422a20a07ee8fdfe009806a5 15-Feb-2013 Daniel Jasper <djasper@google.com> Re-enable ConstructorInitializerAllOnOneLineOrOnePerLine option.

This got lost and was untested as the same effect is achieved by
avoiding bin packing, which is active in Google style by default.
However, moving forward, we want more control over the bin packing
option(s) and thus, this flag should work as expected.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175277 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
7878a7bdebceaa8d8a893abb295027cde619e467 15-Feb-2013 Daniel Jasper <djasper@google.com> Prevent only breaking before "?" in conditional expressions.

This is almost always more readable.

Before:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
? aaaaaaaaaaaaaaaaaaaaaaaaaaa : aaaaaaaaaaaaaaaaaaaaaaaaaaa;

After:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
? aaaaaaaaaaaaaaaaaaaaaaaaaaa
: aaaaaaaaaaaaaaaaaaaaaaaaaaa;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175262 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
9fc56f2636137fcde8acb38865555ed6c7b84dfd 14-Feb-2013 Daniel Jasper <djasper@google.com> Fix counting of parameters so that r175162 works as expected.

Before:
aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()
.aaaaaaaaaaaaaaaaa());

After:
aaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa().aaaaaaaaaaaaaaaaa());

Not sure which of the formattings above is better, but we should not pick
one by accident.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175165 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
okenAnnotator.h
fc75908a7f58903a92c47e1ae02f9a05c36c9f59 14-Feb-2013 Daniel Jasper <djasper@google.com> Reduce penalty for breaking before ./-> after complex calls.

This gives a clearer separation of the context, e.g. in GMOCK
statements.

Before:
EXPECT_CALL(SomeObject,
SomeFunction(Parameter)).WillRepeatedly(Return(SomeValue));

After:
EXPECT_CALL(SomeObject, SomeFunction(Parameter))
.WillRepeatedly(Return(SomeValue));

Minor format cleanups.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175162 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
c78c6b35d398b4c9414e7c5c7e413e28a66c8c5f 14-Feb-2013 Daniel Jasper <djasper@google.com> Remove the trailing whitespace of formatted lines.

So far, clang-format has always assumed the whitespace belonging to the
subsequent token. This has the negative side-effect that when
clang-format formats a line, it does not remove its trailing whitespace,
as it belongs to the next token.

Thus, this patch fixes most of llvm.org/PR15062.

We are not zapping a file's trailing whitespace so far, as this does not
belong to any token we see during formatting. We need to fix this in a
subsequent patch.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175152 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
c5cfa490a1fa4eb1a3a17803c6125b42abd73455 14-Feb-2013 Daniel Jasper <djasper@google.com> Get less confused by trailing comma in Google style.

The formatter can now format:
void aaaaaaaaaaaaaaaaaa(int level,
double *min_x,
double *max_x,
double *min_y,
double *max_y,
double *min_z,
double *max_z, ) {
}

Although this is invalid code, it frequently happens during development and
clang-format should be nicer :-).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175151 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
6cabab48dacc1317821f8f078ed2d4c603b67aff 14-Feb-2013 Daniel Jasper <djasper@google.com> Align superclasses for multiple inheritence.

This fixes llvm.org/PR15179.

Before:
class ColorChooserMac : public content::ColorChooser,
public content::WebContentsObserver {
};

After:
class ColorChooserMac : public content::ColorChooser,
public content::WebContentsObserver {
};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175147 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
okenAnnotator.h
a03ab10f0e4d888139b3b694dd55d176982f72a4 13-Feb-2013 Daniel Jasper <djasper@google.com> Allow breaking after the return type in function declarations.

This has so far been disabled for Google style, but should be done
before breaking at nested name specifiers or in template parameters.

Before (in Google style):
template <typename T>
aaaaaaaa::aaaaa::aaaaaa<T, aaaaaaaaaaaaaaaaaaaaaaaaa> aaaaaaaaaaaaaaaaaaaaaaaa<
T>::aaaaaaa() {}

After:
template <typename T>
aaaaaaaa::aaaaa::aaaaaa<T, aaaaaaaaaaaaaaaaaaaaaaaaa>
aaaaaaaaaaaaaaaaaaaaaaaa<T>::aaaaaaa() {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175074 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
42f458d164cbbee23e55e874b6cee7026ca721ca 13-Feb-2013 Daniel Jasper <djasper@google.com> Fix comment alignment close to the column limit.

Due to an error in one of the expressions, we used to not align comments
although it would have been possible.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175068 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
62a48fbb891267873a71e1147d39200363a49276 13-Feb-2013 Manuel Klimek <klimek@google.com> Pull search state out as class members.

Fix some comments.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175052 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
32a2fd7631026f2fe248381546c5e6149f4f95ee 13-Feb-2013 Manuel Klimek <klimek@google.com> An attempt to make the search algorithm easier to understand.

- clear ownership: the SpecificBumpPtrAllocator owns all StateNodes
- this allows us to simplify the memoization data structure into a
std::set (FIXME: figure out whether we want to use a hash based
data structure).
- introduces StateNode as recursive data structure, instead of using
Edge and the Seen-map combined to drill through the graph
- using a count to stabilize the penalty instead of relying on the
container
- pulled out a method to forward-apply states in the end

This leads to a ~40% runtime decrease on Nico's benchmark.

Main FiXME is that the parameter lists of some function get too long.
I'd vote for either pulling the Queue etc into the Formatter proper,
or creating an inner class just for the search algorithm.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175051 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
37d693160eba22343e08d7bcf66cd132ace77e5c 13-Feb-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Refactor the cast detection code to be a bit more readable.

No functionality change. Also add another cast test.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175029 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
4c2cc603f5239f3b2963ce3e5d25adcf4d0a028d 13-Feb-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Detect ObjC method expressions after casts.

Not all casts are correctly detected yet, but it helps in some cases.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175028 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
b0112e122650cbc9a1a0af42ad84b7178ba0a876 12-Feb-2013 Dmitri Gribenko <gribozavr@gmail.com> Replace 'signed' with 'int'. 'signed' is not typical for LLVM style


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175015 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
89a0daa0ec1fbc43489e3bb9e9648c816258f00f 12-Feb-2013 Daniel Jasper <djasper@google.com> Fix crash for incomplete labels in macros.

Still the formatting can be improved, but at least we don't assert any
more. This happened when trying to format lib/Sema/SemaType.cpp.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175003 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
468e399cfa371a0b698e566d89ffa786b9696f94 12-Feb-2013 Aaron Ballman <aaron@aaronballman.com> Fixing the MSVC compiler warning a different way; removed use of static_cast and instead used a signed integer parameter.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174996 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
be9f4208632ca301384a6f484bc88ef8c3331523 12-Feb-2013 Aaron Ballman <aaron@aaronballman.com> Removing a signed/unsigned mismatch warning triggered in MSVC 11.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174986 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
9ece2bb8499251f3e7cdf65e7a65b38aaeead0d8 12-Feb-2013 Daniel Jasper <djasper@google.com> Fix bug in the adjustment to existing lines.

Before (if only the second line was reformatted):
void f() {}
void g() {}

After:
void f() {}
void g() {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174978 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
95e8e468af284afb11ec1f994d0b5076fc7423d9 12-Feb-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Correctly format stars in `sizeof(int**)` and similar places.

This redoes how '*' and '&' are classified as pointer / reference markers when
followed by ')', '>', or ','.

Previously, determineStarAmpUsage() marked a single '*' and '&' followed by
')', '>', or ',' as pointer or reference marker. Now, all '*'s and '&'s
preceding ')', '>', or ',' are marked as pointer / reference markers. Fixes
PR14884.

Since only the last '*' in 'int ***' was marked as pointer before (the rest
were unary operators, which don't reach spaceRequiredBetween()),
spaceRequiredBetween() now had to be thought about handing multiple '*'s in
sequence.

Before:
return sizeof(int * *);
Type **A = static_cast<Type * *>(P);

Now:
return sizeof(int**);
Type **A = static_cast<Type **>(P);

While here, also make all methods of AnnotatingParser except parseLine()
private.

Review URL: http://llvm-reviews.chandlerc.com/D384



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174975 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
c2e6d2a4a7fe9dfa7d52a38c6048b7b18e6b591a 11-Feb-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Detect ObjC message expressions after 'in' in loop

Before:
for (id foo in[self getStuffFor : bla]) {
}

Now:
for (id foo in [self getStuffFor:bla]) {
}

"in" is treated as loop keyword if the line starts with "for", and as a
regular identifier else. To check for "in", its IdentifierInfo is handed
through a few layers.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174889 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
okenAnnotator.h
3f4535e44965f46cf603146141d2d27a1cef1f7f 11-Feb-2013 Manuel Klimek <klimek@google.com> Get rid of manual debug output, now that the test runner supports it.

You can run tests with -debug instead now.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174880 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
729a743b317d877df3978e88a4a247d2edbf2090 11-Feb-2013 Daniel Jasper <djasper@google.com> Fix invalid formatting with spaces before trailing comments.

In google style, trailing comments are separated by two spaces. This
patch fixes the counting of these spaces and prevents clang-format from
creating a line with 81 columns.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174879 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
okenAnnotator.h
a28fc067e3ee8eb84368530e878ce094f39651d3 11-Feb-2013 Manuel Klimek <klimek@google.com> Fixes handling of empty lines in macros.

Now correctly formats:
#define A \
\
b;
to
#define A b;

Added the state whether an unwrapped line is a macro to the debug
output.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174878 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
2b4c924f85e156d66c01b3f16c850892c47dcc7a 11-Feb-2013 Daniel Jasper <djasper@google.com> Fix formatting of overloaded operator definitions.

Before:
operatorvoid*();
operator vector< A< A>>();

After:
operator void *();
operator vector<A<A> >();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174863 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
okenAnnotator.h
8c7f38cb42b1d15b131af95aaa4f2b5a823ce580 10-Feb-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Remove now-unneeded code for formatting ':'s in ObjC method decls.

The more general code for formatting ObjC method exprs does this and more,
it's no longer necessary to special-case this. No behavior change.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174843 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
d74fcdb630dad817f5d462edd6d12bb95e3f27f1 10-Feb-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Initial support for ObjC dictionary literals.

Before:
@{
foo:
bar
}
;

Now:
@{ foo : bar };

parseBracedList() already does the right thing from an UnwrappedLineParser
perspective, so check for "@{" in all loops that process constructs that can
contain expressions and call parseBracedList() if found.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174840 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
2afbe523648eb591709ac9262f024457eb019bd6 10-Feb-2013 Nico Weber <nicolasweber@gmx.de> Reformat formatter code. No functionality change.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174823 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
051860ee770bf83c3e66ab893be3642bb8bc2680 10-Feb-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Detect ObjC array literals.

Use this to add a space after "@[" and before "]" for now.

Later, I want to use this to format multi-line array literals nicer, too.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174822 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
okenAnnotator.h
52635ff9fb530dfdfc6a94e52a2270bf1bb8346b 08-Feb-2013 Manuel Klimek <klimek@google.com> Fix indentation-detection at indent level 0.

This correctly formats:
{
a;
}
where { is incorrectly indented by 2, but is at level 0, when
reformatting only 'a;'.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174737 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
547d5db5ed482e23edf62130ffdee86ba810d432 08-Feb-2013 Manuel Klimek <klimek@google.com> Takes the context into account when re-indenting regions.

Fixes llvm.org/PR14916.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174720 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
087387a1e9ce5abeb4f348e14f64e5c2273eaedb 08-Feb-2013 Daniel Jasper <djasper@google.com> Fix handling of fake parenthesis during formatting.

They are much easier to handle when attached to the previous token.

Before:
unsigned Indent =
formatFirstToken(TheLine.First, IndentForLevel[TheLine.Level] >=
0 ? IndentForLevel[TheLine.Level]
: TheLine.Level * 2, TheLine.InPPDirective, PreviousEndOfLineColumn);

After:
unsigned Indent = formatFirstToken(
TheLine.First, IndentForLevel[TheLine.Level] >= 0
? IndentForLevel[TheLine.Level] : TheLine.Level * 2,
TheLine.InPPDirective, PreviousEndOfLineColumn);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174718 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
okenAnnotator.h
29f123b2fa0435bb1962f0d9e9a2e660f35fbb2f 08-Feb-2013 Daniel Jasper <djasper@google.com> Implement a tiny expression parser to improve formatting decisions.

With this patch, the formatter introduces 'fake' parenthesis according
to the operator precedence of binary operators.

Before:
return aaaa & AAAAAAAAAAAAAAAAAAAAAAAAAAAAA || bbbb &
BBBBBBBBBBBBBBBBBBBBBBBBBBBBB || cccc & CCCCCCCCCCCCCCCCCCCCCCCCCC ||
dddd & DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD;
f(aaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa &&
aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaaaaaaa);

After:
return aaaa & AAAAAAAAAAAAAAAAAAAAAAAAAAAAA ||
bbbb & BBBBBBBBBBBBBBBBBBBBBBBBBBBBB ||
cccc & CCCCCCCCCCCCCCCCCCCCCCCCCC ||
dddd & DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD;
f(aaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaaaaaaa);

Future improvements:
- Get rid of some of the hacky ways to nicely format certain constructs.
- Merge this parser and the AnnotatingParser as we now have several parsers
that analyze (), [], etc.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174714 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
okenAnnotator.h
ce3d1a68d98f8a557ba5a5391cae8278ae6f29d2 08-Feb-2013 Daniel Jasper <djasper@google.com> Avoid unnecessary line breaks in nested ObjC calls.

Before:
[pboard setData:[NSData dataWithBytes:&button
length:sizeof(button)]
forType:kBookmarkButtonDragType];
After:
[pboard setData:[NSData dataWithBytes:&button length:sizeof(button)]
forType:kBookmarkButtonDragType];

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174701 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
daf1a15d734d154f07d5a0328d3ef59cd9a68f13 07-Feb-2013 Daniel Jasper <djasper@google.com> clang-format: Don't put useless space in f( ::g()).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174662 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
474e46211a141e4566c399b80ae26e3580b70c90 06-Feb-2013 Daniel Jasper <djasper@google.com> Fix bug in the alignment of comments.

Before:
const char *test[] = {
// A
"aaaa",
// B
"aaaaa",
};

After:
const char *test[] = {
// A
"aaaa",
// B
"aaaaa",
};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174549 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
4e8a7b4a95962f63a938c0d21c9aca0a51b78345 06-Feb-2013 Daniel Jasper <djasper@google.com> Become a little smarter with formatting long chains of pipes.

Assign a high penalty to breaking before "<<" if the previous token is a
string literal ending in ":" or "=".

Before:
llvm::outs()
<< "aaaaaaaaaaaaaaaaa = " << aaaaaaaaaaaaaaaaa << "bbbbbbbbbbbbbbbbb = "
<< bbbbbbbbbbbbbbbbb << "ccccccccccccccccc = " << ccccccccccccccccc
<< "ddddddddddddddddd = " << ddddddddddddddddd << "eeeeeeeeeeeeeeeee = "
<< eeeeeeeeeeeeeeeee;

After:
llvm::outs() << "aaaaaaaaaaaaaaaaa = " << aaaaaaaaaaaaaaaaa
<< "bbbbbbbbbbbbbbbbb = " << bbbbbbbbbbbbbbbbb
<< "ccccccccccccccccc = " << ccccccccccccccccc
<< "ddddddddddddddddd = " << ddddddddddddddddd
<< "eeeeeeeeeeeeeeeee = " << eeeeeeeeeeeeeeeee;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174545 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
15417ef20e3cda668351c67cc580587913f6bee8 06-Feb-2013 Daniel Jasper <djasper@google.com> Align trailing block comments like trailing line comments.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174537 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
4ed7f3e003c906d9fdb92a9484feeb8ac6e28e2f 06-Feb-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Correctly detect ObjC message expressions preceded by a comment.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174521 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
b3507cd01ead99113eed92a815b826f26f6dbadb 06-Feb-2013 Manuel Klimek <klimek@google.com> Fix handling of comments in macros.

We now correctly format:
// Written as a macro, it is reformatted from:
#define foo(a) \
do { \
/* Initialize num to zero. */ \
int num = 10; \
/* This line ensures a is never zero. */ \
int i = a == 0 ? 1 : a; \
i = num / i; /* This division is OK. */ \
return i; \
} while (false)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174517 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
7fc2db0acd3fb0f38db19764eef137ae3a9edc9f 06-Feb-2013 Manuel Klimek <klimek@google.com> Much semicolon after namespaces.

We now leave the semicolon in the line of the closing brace in:
namespace {
...
};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174514 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
9e9e6e0297a96e237b53e6be433749065bcea5f8 06-Feb-2013 Daniel Jasper <djasper@google.com> Fix formatting of ObjC method calls.

This fixes llvm.org/PR15165.

We now correctly align:
[image_rep drawInRect:drawRect
fromRect:NSZeroRect
operation:NSCompositeCopy
fraction:1.0
ssssssssdd:NO
hints:nil];

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174513 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
b8b1ce12362860e55590c55fd43db875c9193357 06-Feb-2013 Manuel Klimek <klimek@google.com> Parse record declarations with token pasted identifiers.

This is pretty common in macros:
#define A(X, Y) class X##Y {};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174512 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
36ba0ff4b632cff7424693b9818bcc8d9ea7798a 06-Feb-2013 Daniel Jasper <djasper@google.com> Fix a formatting bug caused by comments in expressions.

This fixes llvm.org/PR15162.

Before:
bool aaaaaaaaaaaaa = // comment
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaa;

After:
bool aaaaaaaaaaaaa = // comment
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaaa;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174508 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
8ff690ab478b33e0d830a6203de12d191d94f8ff 06-Feb-2013 Daniel Jasper <djasper@google.com> Optionally derive formatting information from the input file.

With this patch, clang-format can analyze the input file for two
properties:
1. Is "int *a" or "int* a" more common.
2. Are non-C++03 constructs used, e.g. A<A<A>>.

With Google-style, clang-format will now use the more common style for
(1) and format C++03 compatible, unless it finds C++11 constructs in the
input.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174504 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
okenAnnotator.h
6b5ba8be528bf614d5f4477a4cdbd7c3b19714a6 06-Feb-2013 Daniel Jasper <djasper@google.com> Fix an issue with the formatting of stars in default values.

Before: void f(int *a = d *e, int b = 0);
After: void f(int *a = d * e, int b = 0);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174500 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
4e778091b0ff42895644ca8bef30f1a91ba6b32b 06-Feb-2013 Daniel Jasper <djasper@google.com> Handle nested ObjC calls.

Properly handle annotation contexts while calculating extra information
for each token. This enable nested ObjC calls and thus solves (most of)
llvm.org/PR15164. E.g., we can now format:

[contentsContainer replaceSubview:[subviews objectAtIndex:0]
with:contentsNativeView];

Also fix a problem with the formatting of types in casts as this was
trivial now.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174498 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
e8a97985f72b4e11435ff2107c0f11e925fb6d96 06-Feb-2013 Nico Weber <nicolasweber@gmx.de> Formatter: No space after & and * in front of ObjC message expressions.

1. let determineStarAmp() check of unary operators before checking for
"is next '['". That check was added in r173150, and the test from that
revision passes either way.

2. change determineStarAmp() to categorize '*' and '&' after '=' as unary
operator.

3. don't let parseSquare() overwrite the type of a '*' or '&' before the start
of an objc message expression if has the role of unary operator.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174489 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
ee0feec7362053f22b6c01d12e1bfa06fb3ac93f 05-Feb-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Detect ObjC method expressions after unary operators.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174384 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
63d7cedca8616921c1908c88c2f23fcd67bbab99 05-Feb-2013 Daniel Jasper <djasper@google.com> Initial support for formatting ObjC method declarations/calls.

We can now format stuff like:
- (void)doSomethingWith:(GTMFoo *)theFoo
rect:(NSRect)theRect
interval:(float)theInterval {
[myObject doFooWith:arg1 //
name:arg2
error:arg3];

}

This seems to fix everything mentioned in llvm.org/PR14939.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174364 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
okenAnnotator.h
d399bfff5a57325d8e63116c70aa727b1fb43232 05-Feb-2013 Daniel Jasper <djasper@google.com> Fix some linebreak decisions in Google format.

Before:
f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa +
aaaaaaaaaaaaaaaaaaaa);
aaaaaaa(aaaaaaaaaaaaa, aaaaaaaaaaaaa, aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaa));

After:
f(aaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaa);
aaaaaaa(aaaaaaaaaaaaa,
aaaaaaaaaaaaa,
aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaa));

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174363 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
5b7e7b0ec77f49c1b24deffc9b7032ca16ca9f0d 05-Feb-2013 Daniel Jasper <djasper@google.com> Fix formatting regression introduced by r174307.

In preprocessor definitions, we would not parse all the tokens and thus
not annotate them anymore. This led to a wrong formatting of comments
in google style:

#endif // HEADER_GUARD -- requires two spaces

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174361 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
cda165056890b8ccfc6e2897c711388c5fb518c0 04-Feb-2013 Daniel Jasper <djasper@google.com> Improve handling of trailing block comments

This is a follow up to r174309 to actually make it work.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174314 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
fa543accd8945c39d5128612c8822d0ab4ad594c 04-Feb-2013 Daniel Jasper <djasper@google.com> Improve formatting of stream operators.

If there are string literals on either side of a '<<', chances are
high that they represent logically separate concepts. Otherwise,
the author could just have just a single literal (possible split
over multiple lines).

So, we can now nicely format things like:
cout << "somepacket = {\n"
<< " val a = " << ValueA << "\n"
<< " val b = " << ValueB << "\n"
<< "}";

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174310 91177308-0d34-0410-b5e6-96231b3b80d8
okenAnnotator.cpp
2752ff35854b295837b8088e44d5a932be60e107 04-Feb-2013 Daniel Jasper <djasper@google.com> Improve handling of trailing block comments.

We can now (even in non-bin-packing modes) format:
someFunction(1, /* comment 1 */
2, /* comment 2 */
3, /* comment 3 */
aaa);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174309 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
8159d2f271c9142b46a672ac2c45821911171a7d 04-Feb-2013 Daniel Jasper <djasper@google.com> Fix an error in formatting of for-loops.

Two minor changes:
* Slight penalty for breaking at "," as opposed to ";".
* Don't apply bin-packing rules to for-loops.

Before:
for (int aaaaaa = aaaaaaaaaa; aaaaaa < bbbbbbbb; ++aaaaaa,
++ccccccccccccccc) {}

After:
for (int aaaaaa = aaaaaaaaaa; aaaaaa < bbbbbbbb;
++aaaaaa, ++ccccccccccccccc) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174308 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
0178673f541685cf5067814dfeee2644078e39a9 04-Feb-2013 Daniel Jasper <djasper@google.com> Restructuring of token annotation for formatting.

This combines several changes:
* Calculation token type (e.g. for * and &) in the AnnotatingParser.
* Calculate the scope binding strength in the AnnotatingParser.
* Let <> and [] scopes bind stronger than () and {} scopes.
* Add minimal debugging output.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174307 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
okenAnnotator.h
6bd0232b4f58e7ad40f687b09b0eb897bcc3fd1e 03-Feb-2013 Daniel Jasper <djasper@google.com> Fix bug in formatting of nested initializers.

We can now format:
SomeArrayOfSomeType a = { { { 1, 2, 3 } }, { { 1, 2, 3 } },
{ { 111111111111111111111111111111,
222222222222222222222222222222,
333333333333333333333333333333 } },
{ { 1, 2, 3 } }, { { 1, 2, 3 } } };

Before, we did strange things there.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174291 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
67581942138bb5ce25bcf3a67fff278ca4fa5f7d 01-Feb-2013 Daniel Jasper <djasper@google.com> Hopefully fix windows build due to non-standard pair implementation.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174169 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
68ef0df17ed6de26084c3a11a4cabbd69a5a2465 01-Feb-2013 Daniel Jasper <djasper@google.com> Revamp of the basic layouting algorithm in clang-format.

In order to end up with good solutions, clang-format needs to try
"all" combinations of line breaks, evaluate them and select the
best one. Before, we have done this using a DFS with memoization
and cut-off conditions. However, this approach is very limited
as shown by the huge static initializer in the attachment of
llvm.org/PR14959.

Instead, this new implementation uses a variant of Dijkstra's
algorithm to do a prioritized BFS over the solution space.

Some numbers:
lib/Format/TokenAnnotator.cpp: 1.5s -> 0.15s
Attachment of PR14959: 10min+ (didn't finish) -> 10s

No functional changes intended.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174166 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
bd04f2aa2247f2fda3fd8f3fee90479ba2c94499 31-Jan-2013 Manuel Klimek <klimek@google.com> Never break inside something that was a preprocessor directive.

Just put it in one unwrapped line and let the formatter handle it.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174063 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
f343cabb68d495041706b8e2f1ed48fbac3cba06 31-Jan-2013 Daniel Jasper <djasper@google.com> Several improvements to the formatting of static initializers.

1. Never avoid bin packing in static initializers as this can
lead to terrible results.
2. If an element has to be broken over multiple lines, break after
the following comma.

This should be a step forward, but there are still many cases
especially with nested static initializers that we handle badly.
More patches will follow.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174061 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
okenAnnotator.cpp
afcbd859f839db4133311147c1bc7db29dfaea10 30-Jan-2013 Daniel Jasper <djasper@google.com> Don't generate no-op replacements.

No functional changes.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173916 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
32d28ee6061930b2a9c170cbaaeea028c88a7b89 29-Jan-2013 Daniel Jasper <djasper@google.com> Move the token annotator into separate files.

No functional changes. Also removed experimental-warning from all of
clang-format's files, as it is no longer accurate.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173830 91177308-0d34-0410-b5e6-96231b3b80d8
MakeLists.txt
ormat.cpp
okenAnnotator.cpp
okenAnnotator.h
nwrappedLineParser.cpp
nwrappedLineParser.h
d4f2c2e21addd8ed0a50b92f062d3229cde0506a 29-Jan-2013 Daniel Jasper <djasper@google.com> Improve formatting of code with comments.

Before:
aaaaaaa(aaaaaa( // comment
aaaaaaa));
<big mess>

After:
aaaaaaa(aaaaaa( // comment
aaaaaaaa));
function(/* parameter 1 */ aaaaaaa,
/* parameter 2 */ aaaaaaa,
/* parameter 3 */ aaaaaaa,
/* parameter 4 */ aaaaaaa);

(the latter example was only wrong in the one-arg-per-line mode, e.g. in
Google style).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173821 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
f1579605adf03f94a2ddddc95c764737ead0efe5 29-Jan-2013 Daniel Jasper <djasper@google.com> Allow all parameters on next line for function calls in Chrome.

The style guide only forbids this for function declarations. So,
now

someFunction(
aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa, aaaaaaaaaaaa);

Is allowed in Chromium mode.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173806 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
f40fb4beaa22b4e53cd8b5319836b361ebfa6c62 29-Jan-2013 Daniel Jasper <djasper@google.com> Split ">>" in "A<B<C> >" in Chromium style.

It needs to be compatible with C++03.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173805 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
b3109e35d75a543d167906384347c017812e5dbf 29-Jan-2013 Daniel Jasper <djasper@google.com> Fix uninitialized error caused by r173801.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173803 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
adc6aba07293928122629e9d8a91a37144254831 29-Jan-2013 Daniel Jasper <djasper@google.com> Calculate the split penalty upfront.

This is
a) More efficient.
b) Important as we move forward with further metrics for penalty.

No functional changes intended.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173801 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
1a1ce8330ba3248e36615adef3759ad22fc18c8d 29-Jan-2013 Daniel Jasper <djasper@google.com> Fix a comment and reformat clang-format with clang-format

Not all changes might be ideal, but IMO all are acceptable.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173793 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
2e60377273fb451587a60209997148480754b9fa 29-Jan-2013 Daniel Jasper <djasper@google.com> Initial support for multiple variable declarations.

Before:
SomeType aaaaaaaaaaaaaaaaa = aaaaaa->aaaaaaaaaaaaaaaaa(),
aaaaaaaaaaa = aaaaaa->aaaaaaaaaaa();
After:
SomeType aaaaaaaaaaaaaaaaa = aaaaaa->aaaaaaaaaaaaaaaaa(),
aaaaaaaaaaa = aaaaaa->aaaaaaaaaaa();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173792 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
93384a910cb98f3a128b76e6043f149e1b384c65 29-Jan-2013 Daniel Jasper <djasper@google.com> Reverting changes from r173785 (removing empty lines before "}").

This needs some more thinking, e.g. for namespaces, chains of if-else
if, ...

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173787 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
8df364fc0b3d89fb4ea632c6824a121a8c7752a5 29-Jan-2013 Daniel Jasper <djasper@google.com> Remove empty lines before "}".

Those empty lines waste vertical whitespace and almost never
increase readability.

Before:
void f() {
DoSomething();

}

After:
void f() {
DoSomething();
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173785 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
7522318ce2b2280dc679b62a4193c8f179632c16 28-Jan-2013 Daniel Jasper <djasper@google.com> Fix a bug that would lead to bad line break decisions in for loops.

Before:
for (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaa = aaaaaaaaaaaaaaa
.aaaaaaaaaaaaaaaa;
aaaaaaaaaaa != aaaaaaaaaaaaaaaaaaa; ++aaaaaaaaaaa) {}

After:
for (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaa =
aaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaa;
aaaaaaaaaaa != aaaaaaaaaaaaaaaaaaa; ++aaaaaaaaaaa) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173695 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
d75ff6496bfb599a9edde41681873919d4d44152 28-Jan-2013 Daniel Jasper <djasper@google.com> Don't put a function's return type on its own line in Google style.

This would be against the style guide:
http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml?showone=Function_Declarations_and_Definitions#Function_Declarations_and_Definitions

Not sure what to do as a last resort if the function signature does not
fit onto a single line in Google style ..

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173690 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
83f25ba0499f18b91501fb6538c49ebc7827bea0 28-Jan-2013 Daniel Jasper <djasper@google.com> Let clang-format break after a function's return type.

Before:
TypeSpecDecl *TypeSpecDecl::Create(ASTContext &C, DeclContext *DC,
SourceLocation L, IdentifierInfo *II,
Type *T) {}

After:
TypeSpecDecl *
TypeSpecDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
IdentifierInfo *II, Type *T) {}

This fixes llvm.org/PR14717.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173688 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
02b771e3110f7799f93d5d17dc6fefc5713387c3 28-Jan-2013 Daniel Jasper <djasper@google.com> Make continuations in constructor initializers consistent.

Before:
Constructor
: LooooooooooooooooooooongVariable(
LooooooooooooooooooooongValue) {}

After:
Constructor
: LooooooooooooooooooooongVariable(
LooooooooooooooooooooongValue) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173685 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
3b9a8fc5bee5434bebc9058646896423adac625b 28-Jan-2013 Daniel Jasper <djasper@google.com> Initial support for formatting range-based for-loops.

Before (in good cases):
for (auto aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
for (auto aaaaaaaaaaaaaaaaaaaa : aaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaa,
aaaa)) {}

After:
for (auto aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa :
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
for (auto aaaaaaaaaaaaaaaaaaaa :
aaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaa, aaaa)) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173684 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
bfe6fd4f00257b113ea3bcb4efef8d9f9f245882 28-Jan-2013 Daniel Jasper <djasper@google.com> Improve formatting of conditional expressions.

Before we did not really systematically format those. Now, we format the
different cases as:

- 1 Line: a ? b : c;
- 2 Lines: short ? loooooooooong
: loooooooooong
- 2 Lines: loooooooooooooooong
? short : short
- 3 Lines: loooooooooooooooong
? loooooooooooooong
: loooooooooooooong

Not sure whether "?" and ":" should go on the new line, but it seems to
be the most consistent approach.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173683 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
ae8699bde649e2ed1f66414b4283b862f11056dd 28-Jan-2013 Daniel Jasper <djasper@google.com> Several small changes in formatting decisions.

1. Use a hanging ident for function calls nested in binary expressions.
E.g.:
int aaaaa = aaaaaaaaa && aaaaaaaaaa(
aaaaaaaaaa);

2. Slightly improve heuristic for builder type expressions and reduce
penalty for breaking before "." and "->" in those.

3. Remove mostly obsolete metric of decreasing indent level. This
fixes: llvm.org/PR14931.

Changes #1 and #2 were necessary to keep tests passing after #3.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173680 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
5f2173ee723fd17b758f2a35a5bb39ca74eca523 28-Jan-2013 Daniel Jasper <djasper@google.com> Improve indentation after breaking at nested name specifiers.

These always represent a continuation and we should increase the ident.

Before:
aaaaaaaaa(aaaaaaaaaaaaaaaaaaaaa::
aaaaaaaaaaaaaaaaaaaa);

After:
aaaaaaaaa(aaaaaaaaaaaaaaaaaaaaa::
aaaaaaaaaaaaaaaaaaaa);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173675 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
986e17ff3bd3df2762f88569cab3fdfbabc08bb1 28-Jan-2013 Daniel Jasper <djasper@google.com> Avoid confusing identations for multi-parameter functions.

Before:
aaaaaaaa(aaaaaaaaa(
aaaaaaaaaa(),
aaaaaaaaa);

After:
aaaaaaaa(aaaaaaaaa(
aaaaaaaaaa(),
aaaaaaaaa);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173673 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
3499ddac3f075cbda6347067190fcc7a972dcaca 25-Jan-2013 Daniel Jasper <djasper@google.com> Fix some alignment and line break decisions.

This combines two small changes:
1) Put a penalty on breaking after "<"
2) Only produce a hanging indent when parameters are separated by
commas.

Before:
aaaaaaaaaaaaaaaaaaaaaaaa<
aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa>(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
aaaaaa(new Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaa));

After:
aaaaaaaaaaaaaaaaaaaaaaaa<aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa>(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
aaaaaa(new Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaa));

This changes one ObjC test, but AFAICT this is not according to any
style guide (neither before nor after). We probably should be aligning
on the ":" there according to:
http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml?showone=Method_Invocations#Method_Invocations

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173457 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
63f003644420fff0ea3d463e68aee83f2f5842cd 25-Jan-2013 Daniel Jasper <djasper@google.com> Allow breaking after "::" if absolutely necessary.

Otherwise, really long nested name specifiers can easily lead to a
violation of the column limit.

Not sure about the rules for indentation in those cases, so input is
appreciated (see tests.).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173438 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
e438bac04165937036e41c321fa0d5567d1e520c 23-Jan-2013 Daniel Jasper <djasper@google.com> Add extra indent for nested calls inside if's.

Before:
if (aaaaaaaaaa(
aaaaaaaaaa)) {}

After:
if (aaaaaaaaaa(
aaaaaaaaaa)) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173290 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
f39c8859b087151617aa2c8b193d0b332503e3ca 23-Jan-2013 Daniel Jasper <djasper@google.com> Don't try to align builder-type continuations on assignments.

Before:
int aaaa = aaaaa().aaaaa() // force break
.aaaaa();
After:
int aaaa = aaaaa().aaaaa() // force break
.aaaaa();

The other indent is just wrong and confusing.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173273 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
13cb7c2c46bca6f52fd217091ef2922a3eca46f5 23-Jan-2013 Daniel Jasper <djasper@google.com> Don't try to do a hanging ident after assignments.

Before:
bool aaaa = aaaaaaaaaaa(
aaaaaaaaaaaaaaaaa);

After:
bool aaaa = aaaaaaaaaaa(
aaaaaaaaaaaaaaaaa);

The other indentation was a nice attempt but doesn't work in many cases.
Not sure what the right long term solution is as the "After: " is still
not nice. We either need to figure out what to do in the cases where it
"doesn't work" or come up with a third solution, e.g. falling back to:

bool aaaa =
aaaaaaaaaaa(
aaaaaaaaaaaaaaaaa);

which should always work and nicely highlight the structure.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173268 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
7ccbc2156bfe473f080b585130d70e51c4b62bb0 23-Jan-2013 Manuel Klimek <klimek@google.com> Fix handling of macro definitions.

Now correctly formats:
#define A (1)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173264 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
a32a7fda316289dca6aac1352fde3caf14a1cb2f 23-Jan-2013 Manuel Klimek <klimek@google.com> Fixes layouting regression and invalid-read.

Layouting would prevent breaking before + in
a[b + c] = d;
Regression detected by code review.

Also fixes an invalid-read found by the valgrind bot.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173262 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
20d3583857c2cc99dcc9c27ff5f23916df9c0812 23-Jan-2013 Daniel Jasper <djasper@google.com> Fix the formatting of pointer/reference types in range-based for loops.

Before: for (int & a : Values) {}
After: for (int &a : Values) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173259 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
7006e7ebc0098b7627bd3cc13367ea576c25dcbb 23-Jan-2013 Daniel Jasper <djasper@google.com> Removing the penalty for breaking after "=".

Having seen more cases, this actually was not a good thing to do in the
first place. We can still improve on what we do now, but breaking after
the "=" is good in many cases.

Before:
aaaaaaaaaaaaa = aa->aaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaa));

After:
aaaaaaaaaaaaa =
aa->aaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaa));

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173257 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
4bfc65aab5408f76dfe38e3f4e4375fadeda3bc3 23-Jan-2013 Daniel Jasper <djasper@google.com> Fix another regression for pointer types.

Before: if (int * a = &b) ...
After: if (int *a = &b) ...

Also changed all the existing tests to test the expressions in question
both in a declaration and in an expression context.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173256 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
218b6dfaee321cec558e15d47b68155dd9f35684 23-Jan-2013 Daniel Jasper <djasper@google.com> Fix regression in formatting pointer types.

We will need a more principled solution, but we should not leave this
unfixed until we come up with one.

Before: void f() { int * a; }
After: void f() { int *a; }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173252 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
836b58f564e07e806d3d0b41a193fde0921013c7 23-Jan-2013 Manuel Klimek <klimek@google.com> Fixes incorrect handling of the declaration context stack.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173250 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
092a2c7373c02d1653bea1feb1ada05363b02bc2 23-Jan-2013 Manuel Klimek <klimek@google.com> Fix segfaults in the formatter.

Also: expletive deleted.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173247 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
8f4bd7a20f89d9065bebadd270e6bc7822257d37 23-Jan-2013 Daniel Jasper <djasper@google.com> Add option to allow putting all parameters onto the next line.

This only affects styles where BinPackParameters is false.

With AllowAllParametersOnNextLine:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaa, aaaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaa, aaaaaaaaaaa);

Without it:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaa,
aaaaaaaaaa,
aaaaaaaaaa,
aaaaaaaaaaa,
aaaaaaaaaaa);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173246 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
70b03f4edaefcc5b9aa2e084d1c12e9d91b32a77 23-Jan-2013 Manuel Klimek <klimek@google.com> Allow us to better guess the context of an unwrapped line.

This gives us the ability to guess better defaults for whether a *
between identifiers is a pointer dereference or binary operator.

Now correctly formats:
void f(a *b);
void f() { f(a * b); }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173243 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
nwrappedLineParser.h
86721d2a4610ac0a4b162952ec409df1fe397d58 22-Jan-2013 Manuel Klimek <klimek@google.com> Implements more principled comment parsing.

Changing nextToken() in the UnwrappedLineParser to get the next
non-comment token. This allows us to correctly layout a whole class of
snippets, like:

if /* */(/* */ a /* */) /* */
f() /* */; /* */
else /* */
g();

Fixes a bug in the formatter where we would assume there is a previous
non-comment token.
Also adds the indent level of an unwrapped line to the debug output in
the parser.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173168 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
nwrappedLineParser.h
3298327e0e6ecb31ca8f3d0996043292e7c860f2 22-Jan-2013 Daniel Jasper <djasper@google.com> Let the formatter be more restrictive for breaking around . and ->

Before:
aaaaaaaaaaaaaaa(aaaaaaaaa, aaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaa)
.aaaaaaaaaaaaaaaaaa();

After:
aaaaaaaaaaaaaaa(aaaaaaaaa, aaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaa).aaaaaaaaaaaaaaaaaa();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173160 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
ffee17126e10a0e2febfcfbf61d8e0d6e2fcf4c0 22-Jan-2013 Daniel Jasper <djasper@google.com> Fix "*" formatting when creating arrays of pointers.

Before: A = new int * [10]();
After: A = new int *[10]();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173150 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
821627e5865c29357aef0e4f175b0abd083bf191 21-Jan-2013 Daniel Jasper <djasper@google.com> Remove "incorrect" aligning of trailing comments.

We used to align trailing comments belong to different things.
Before:
void f() { // some function..
}
int a; // some variable..

After:
void f() { // some function..
}
int a; // some variable..

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173100 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
05bf827fb8c0812e14d287c24e6f0a0b8e64377e 21-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Set MatchingParen for [], to match <>, (), {}. No functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173078 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
3f29fbb9d86dc58730bbfcdd26dc6ee6a401cbd4 21-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Rename LSquare to Left to make parseSquare() more consistent with the other paren parsing methods.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173077 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
308232c0aef773d24693f9e456dc3bc983934f7f 21-Jan-2013 Manuel Klimek <klimek@google.com> Fixes various problems around enum parsing.

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;
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173075 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
2f1ac41a6d8d202dcc39ab8eb56ccea823dc062e 21-Jan-2013 Manuel Klimek <klimek@google.com> Fixes formatting of empty blocks.

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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173055 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
032f25329565adfc542f001953565091eccba130 21-Jan-2013 Daniel Jasper <djasper@google.com> Fix parsing of templated declarations.

Before: template <template <typename T>, typename P > class X;
After: template <template <typename T>, typename P> class X;

More importantly, the token annotations for the second ">" are now computed
correctly.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173047 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
d19dc2ddf3f8630cfdbefec490c0000c14bee6bd 21-Jan-2013 Manuel Klimek <klimek@google.com> Fixes indent in linkage specification blocks.

We now indent:
extern "C" {
int a;
}

without additional indent inside the extern "C" block.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173045 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
9c8c40e7334a59159392d020dd4339b86326ec00 21-Jan-2013 Daniel Jasper <djasper@google.com> Fix bug discovered by valgrind.

When trying to merge lines, we should not touch lines that are invalid,
as we don't know how long they might be.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173043 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
3a3408cceb438af7cdebb5b3d938abb916162bb4 21-Jan-2013 Manuel Klimek <klimek@google.com> Fixes detection of class template specializations.

Now correctly formats:
template <> class A<int> {} a;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173038 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
7f5b025e9b9a981a257d83063064ac6e58239d76 21-Jan-2013 Manuel Klimek <klimek@google.com> Allow for nested name specifiers in record declarations.

Now correctly formats:
class A::B {} n;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173019 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
c44ee89cb448e34aada006b707eb45a1280f31e3 21-Jan-2013 Manuel Klimek <klimek@google.com> Fix parsing of return statements.

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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173017 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
nwrappedLineParser.h
b1ba0efc3d1dc1daa5d82c40bc504e1f368c4fa0 19-Jan-2013 Chandler Carruth <chandlerc@gmail.com> Re-sort all the headers. Lots of regressions have crept in here.
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172892 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
nwrappedLineParser.h
ba287dc2fa46af68a84d69004ffc086e3e7311f1 18-Jan-2013 Manuel Klimek <klimek@google.com> Fix comment.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172831 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.h
4c1281283513ff5cd37ee224639e2f3853ec9ea8 18-Jan-2013 Manuel Klimek <klimek@google.com> Fixes issues around pulling in the next line in simple if statements.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172822 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
525fe168c25a8273899281c5d2326c722fc3f2a5 18-Jan-2013 Manuel Klimek <klimek@google.com> Fixes problems with line merging in the face of preprocessor directives.

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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172819 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
nwrappedLineParser.h
c79afdae8a2e12d1e8f27a2ae0a43dfca3b8283b 18-Jan-2013 Daniel Jasper <djasper@google.com> Reduce penalty for splitting between ")" and ".".

').' is likely part of a builder pattern statement.
This is based upon a patch developed by Nico Weber. Thank you!

Before:
int foo() {
return llvm::StringSwitch<Reference::Kind>(name).StartsWith(
".eh_frame_hdr", ORDER_EH_FRAMEHDR).StartsWith(
".eh_frame", ORDER_EH_FRAME).StartsWith(".init", ORDER_INIT).StartsWith(
".fini", ORDER_FINI).StartsWith(".hash", ORDER_HASH).Default(ORDER_TEXT);
}

After:
int foo() {
return llvm::StringSwitch<Reference::Kind>(name)
.StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR)
.StartsWith(".eh_frame", ORDER_EH_FRAME)
.StartsWith(".init", ORDER_INIT).StartsWith(".fini", ORDER_FINI)
.StartsWith(".hash", ORDER_HASH).Default(ORDER_TEXT);
}

Probably not ideal, but makes many cases much more readable.

The changes to overriding-ftemplate-comments.cpp don't seem better or
worse. We should address those soon.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172804 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
7d1185de4405637094d64f960f2b6d01f8bce04e 18-Jan-2013 Daniel Jasper <djasper@google.com> Also align trailing line comments in include directives.

Before:
#include <a> // for x
#include <a/b/c> // for yz
After:
#include <a> // for x
#include <a/b/c> // for yz

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172799 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
dcc2a6269ba86285b20ee76487807b9cd20cefbe 18-Jan-2013 Daniel Jasper <djasper@google.com> Let the formatter align trailing line comments where possible.

Before:
int a; // comment
int bbbbb; // comment

After:
int a; // comment
int bbbbb; // comment

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172798 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
94fb72932c806c549f5c51f4bfa99fa7b481324a 18-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: After case blocks, "break" goes on the same line as the "}", PR14907.

Before:
switch (foo) {
case a: {
int a = g();
h(a);
}
break;
}

Now:
switch (foo) {
case a: {
int a = g();
h(a);
} break;
}



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172789 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
6a21a556a728325e1fae4387128d149927a4fbff 18-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: The contents of @selector() should be formatted as a selector.

Before: @selector(foo: )
Now: @selector(foo:)



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172781 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
5096a44f2ec5ab9e5b801424e04919f4fcf29f1d 17-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Get bit tests in ifs right.

It's generally not possible to know if 'a' '*' 'b' is a multiplication
expression or a variable declaration with a purely lexer-based approach. The
formatter currently uses a heuristic that classifies this token sequence as a
multiplication in rhs contexts (after '=' or 'return') and as a declaration
else.

Because of this, it gets bit tests in ifs, such as "if (a & b)" wrong. However,
declarations in ifs always have to be followed by '=', so this patch changes
the formatter to classify '&' as an operator if it's at the start of an if
statement.

Before:
if (a& b)
if (int* b = f())

Now:
if (a & b)
if (int* b = f())



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172731 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
60ca75d4d1878f8a45799316f462d4d0114238b4 17-Jan-2013 Daniel Jasper <djasper@google.com> Allow breaking after the trailing const after a function declaration.

Before:
void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) const GUARDED_BY(
aaaaaaaaaaaaa);

After:
void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) const
GUARDED_BY(aaaaaaaaaaaaa);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172718 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
2c6cc48a38455969b4602a2d37ce620101b7eebc 17-Jan-2013 Daniel Jasper <djasper@google.com> Improve handling of comments in static initializers.

Also adding more tests.

We can now keep the formatting of something like:

static SomeType type = { aaaaaaaaaaaaaaaaaaaa, /* comment */
aaaaaaaaaaaaaaaaaaaa /* comment */,
/* comment */ aaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaa, // comment
aaaaaaaaaaaaaaaaaaaa };

Note that the comment in the first line is handled like a trailing line comment
as that is likely what the user intended.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172711 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
aab60054553c35f6761cf96f3476997f250f1f4a 17-Jan-2013 Nico Weber <nicolasweber@gmx.de> Revert most of r172140.

r172140 changed the formatter to produce "-(id) foo" instead of "- (id)foo"
in google style, with a link to
http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml#Method_Declarations_and_Definitions
as reference. But now that I look at that link again, it seems I didn't
read it very carefully the first time round.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172703 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
16618240a8a28d84de6d950f89145a78645e26e7 16-Jan-2013 Daniel Jasper <djasper@google.com> Fix a bug where we would move a following line into a comment.

Before: Constructor() : a(a), // comment a(a) {}
After: Constructor() : a(a), // comment
a(a) {}

Needed this as a quick fix. Will add more tests for this in a future
commit.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172624 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
1f2b07898f66524fd7fe1b177fb0d7c58016e93b 16-Jan-2013 Daniel Jasper <djasper@google.com> Fix parsing error in conditional expressions.

We used to incorrectly parse

aaaaaa ? aaaaaa(aaaaaa) : aaaaaaaa;

Due to an l_paren being followed by a colon, we assumed it to be part of
a constructor initializer. Thus, we never found the colon belonging to
the conditional expression, marked the line as bing incorrect and did
not format it.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172621 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
48bd7b72b8911147ec9bdeaa8ebb211543fd23a9 16-Jan-2013 Daniel Jasper <djasper@google.com> Improve understanding of unary operators.

Before: int x = ** a;
After: int x = **a;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172619 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
df3736aa70443ac0f33af094989b4ba88d73f568 16-Jan-2013 Daniel Jasper <djasper@google.com> Disable inlining of short ifs in Google style.

Various reasons seem to speak against it, so I am disabling this for
now.

Changed tests to still test this option.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172618 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
0df6acdf4f6faf7579775a739e1c09448c076c0f 16-Jan-2013 Daniel Jasper <djasper@google.com> Add option to avoid "bin-packing" of parameters.

"Bin-packing" here means allowing multiple parameters on one line, if a
function call/declaration is spread over multiple lines.

This is required by the Chromium style guide and probably desired for
the Google style guide. Not making changes to LLVM style as I don't have
enough data.

With this enabled, we format stuff like:
aaaaaaaaaaaaaaa(aaaaaaaaaa,
aaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaa).aaaaaaaaaaaaaaaaaa();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172617 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
ca547dbbb1e10c801158f2eecaf3d49e1071b0e3 16-Jan-2013 Manuel Klimek <klimek@google.com> Add debugging support for split penalties.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172616 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
8fa37999164844a926448ef4656bbf7c42070235 16-Jan-2013 Manuel Klimek <klimek@google.com> Use standard llvm Debug.h support for debugging output.

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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172608 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
d881875b6c78386c4f0da911c1110f9ed1235c6a 16-Jan-2013 Alexander Kornienko <alexfh@google.com> Clang Format: Handle missing semicolon

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172606 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
3f8cdbf9932c874b7ca4ee3d850a236d9c729961 16-Jan-2013 Daniel Jasper <djasper@google.com> Calculate the total length of a line up to each token up front.

This makes the tedious fitsIntoLimit() method unnecessary and I can
replace one hack (constructor initializers) by a slightly better hack.

Furthermore, this will enable calculating whether a certain part of a
line fits into the limit for future modifications.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172604 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.h
cbb6c41f3cec4a940201a8e2e65743c9f26c3673 16-Jan-2013 Daniel Jasper <djasper@google.com> Change the datastructure for UnwrappedLines.

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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172602 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
nwrappedLineParser.h
6b825c2e1e691deca41c6f979164b5d20c203593 16-Jan-2013 Daniel Jasper <djasper@google.com> Never merge < and ::, as it produces different tokens.

Before: vector<::Type> t;
After: vector< ::Type> t;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172601 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
55b08e769f05987942c307fde8eb168df01e504f 16-Jan-2013 Daniel Jasper <djasper@google.com> Remove errors were if statements were incorrectly put on a single line.

Before: if (a) // This comment confused clang-format f();
After: if (a) // No more confusion
f();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172600 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
19132303666ca434aefae2e725d76f9c57336e44 15-Jan-2013 Manuel Klimek <klimek@google.com> Do not traverse the break-state when we know we cannot break anyway.

This is an optimization that djasper spottet. For now, we do not format
anything after the first token that belongs to such an implicit string
literal. All our state is not made for handling that anyway, so we'll
revisit this if we find a problem.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172537 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
407a31afffc936291d719665b9edb72532c0ed3b 15-Jan-2013 Manuel Klimek <klimek@google.com> Fix formatting of preprocessor directives (incluces, warnings & errors).

Treat tokens inside <> for includes and everything from the second token
of a warning / error on as an implicit string literal, e.g. do not
change its whitespace at all.

Now correctly formats:
#include < path with space >
#error Leave all white!!!!! space* alone!

Note that for #error and #warning we still format the space up to the
first token of the text, so:
# error Text
will become
#error Text

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172536 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
b369c2cb31358f749b9ced97440a6c457f38eaae 15-Jan-2013 Daniel Jasper <djasper@google.com> Improve operator kind detection in presence of comments.

We used to incorrectly identify some operators (*, &, +, -, etc.) if
there were comments around them.

Example:
Before: int a = /**/ - 1;
After: int a = /**/ -1;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172533 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
47ea7f64108163491ed74dc746c8d94e10764704 15-Jan-2013 Manuel Klimek <klimek@google.com> Fixes various bugs around the keywords class, struct and union.

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;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172530 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
nwrappedLineParser.h
2c7739e3cbf1357c0ef8d894045a300331053565 14-Jan-2013 Manuel Klimek <klimek@google.com> Fixes formatting of nested brace initializers.

We now format this correctly:
Status::Rep Status::global_reps[3] = {
{ kGlobalRef, OK_CODE, NULL, NULL, NULL },
{ kGlobalRef, CANCELLED_CODE, NULL, NULL, NULL },
{ kGlobalRef, UNKNOWN_CODE, NULL, NULL, NULL }
};

- fixed a bug where BreakBeforeClosingBrace would be set on the wrong
state
- added penalties for breaking between = and {, and between { and any
other non-{ token

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172433 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
6f5bb2c93c31a7977382c5079d85db8ca3267cd0 14-Jan-2013 Daniel Jasper <djasper@google.com> Make single-line if statements optional.

Now, "if (a) return;" is only allowed, if this option is set.

Also add a Chromium style which is currently identical to Google style
except for this option.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172431 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
fd0ca976bd55167364ba1178e884d275cc6ef30b 14-Jan-2013 Daniel Jasper <djasper@google.com> Fix a bug in the line merging.

If the first line of a merge would exactly fit into the column limit,
an unsigned overflow made us not break.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172426 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
2b9c10bd8f80c004756308a5163fa7eda27eb5ce 14-Jan-2013 Daniel Jasper <djasper@google.com> Fix bug that would lead to joining preprocessor directives.

Before: #include "a.h" #include "b.h"
After: #include "a.h"
#include "b.h"

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172424 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
e0b15ea7edeceb41decddfeabaf6fac935ed7baf 14-Jan-2013 Daniel Jasper <djasper@google.com> Put simple preprocessor directives on a single line.

Before: #define A \
A
After: #define A A

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172423 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
feb18f5ff2cfa952fec4e751eb9665706c4674af 14-Jan-2013 Daniel Jasper <djasper@google.com> Put short if statements on a single line.

Before: if (a)
return;
After: if (a) return;

Not yet sure, whether this is always desired, but we can add options and
make this a style parameter as we go along.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172413 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
995e8207877f6f5c8ed7d63f9b61e156dd171e50 14-Jan-2013 Daniel Jasper <djasper@google.com> Refactor datastructure used in clang-format.

Main difference, add an AnnotatedLine class to hold information about a
line while formatting. At the same time degrade the UnwrappedLine class
to a class solely used for communicating between the UnwrappedLineParser
and the Formatter.

No functional changes intended.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172403 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
4abbb535f0f050aea6373e26e769643c3c61a9b1 14-Jan-2013 Daniel Jasper <djasper@google.com> Improve understanding post increment and decrement.

Before: (a->f()) ++;
a[42] ++;
After: (a->f())++;
a[42]++;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172400 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
a4ae9f30ef7bccdaa3feef8036af07fbb91f107c 14-Jan-2013 Alexander Kornienko <alexfh@google.com> Custom DiagnosticConsumer parameter of reformat() + silence diagnostics in unit tests.

Summary:
Added tests for clang-format diagnostics. Added DiagnosticConsumer
argument to clang::format::reformat().

Reviewers: klimek, djasper

Reviewed By: djasper

CC: cfe-commits, thakis, rafael.espindola

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172399 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
487f64b2ae3f991216eb1346a62ea18156f0b519 13-Jan-2013 Daniel Jasper <djasper@google.com> Stronger respect the input codes line breaks wrt. comments.

clang-format should not change whether or not there is a line break
before a line comment as this strongly influences the percieved binding.

User input: void f(int a,
// b is awesome
int b);
void g(int a, // a is awesome
int b);
Before: void f(int a, // b is awesome
int b);
void g(int a, // a is awesome
int b);
After: <unchanged from input>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172361 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
1774603d8b34f86bd254d85a125592fcb323a488 13-Jan-2013 Daniel Jasper <djasper@google.com> Format unions like structs and classes.

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;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172355 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
4e9008ac62b4c403c5c30724953664dcbb03d02e 13-Jan-2013 Daniel Jasper <djasper@google.com> Always put a space after ",".

I am not aware of a case where that would be wrong. The specific case I
am fixing are function parameters wrapped in parenthesis (e.g. in
macros).

Before: function(a,(b));
After: function(a, (b));

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172351 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
8134e1e575f862799c361b9c146eae7672010fa0 13-Jan-2013 Daniel Jasper <djasper@google.com> Don't put spaces around hyphens in include paths.

Before: #include <a - a>
After: #include <a-a>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172350 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
4981bd0ca215570ef1e2e1c1c64a2c399069dc42 13-Jan-2013 Daniel Jasper <djasper@google.com> Improve identification of c-style casts.

A ")" before any of "=", "{" or ";" won't be a cast. This fixes issues
with the formatting of unnamed parameters.

Before: void f(int *){}
After: void f(int *) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172349 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
cd458330d0cdced36a49f1d66cd9c5908f46d939 13-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Don't insert a space before unary operators after selector names.

Before:
[color getRed: &r green: &g blue: &b alpha: &a];

Now:
[color getRed:&r green:&g blue:&b alpha:&a];



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172337 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
ea86563962102149609f6442491d884bc337a175 12-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Remove debugging junk I accidentally landed in r172333.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172334 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
e8ccc81a9f66361450148338b8457dd2c6ad11de 12-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Prefer breaking before ObjC selector names over breaking at their ':'

Before:
if ((self = [super initWithContentRect:contentRect styleMask:
styleMask backing:NSBackingStoreBuffered defer:YES])) {

Now:
if ((self = [super initWithContentRect:contentRect styleMask:styleMask
backing:NSBackingStoreBuffered defer:YES])) {




git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172333 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
cfa88f893915ceb8ae4ce2f17c46c24a4d67502f 12-Jan-2013 Dmitri Gribenko <gribozavr@gmail.com> Remove useless 'llvm::' qualifier from names like StringRef and others that are
brought into 'clang' namespace by clang/Basic/LLVM.h


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172323 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.h
b14d1cae88b7966da5112ea58009140d49a0fb2d 12-Jan-2013 Rafael Espindola <rafael.espindola@gmail.com> Remove unused private field.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172314 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
b312314cd7aaf8a4c3902aa28c8bc0a9662a8e9b 12-Jan-2013 Daniel Jasper <djasper@google.com> Fix incorrect comparison operator causing loooong formatting times.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172308 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
f681fa8238b82822a3d939f0e4df80660666f8b1 12-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Remove an always-false condition.

canBreakBefore() does not allow breaking after ':' for LT_ObjCMethodDecl lines,
so if Newline is true in addTokenToState() for ':' then LT_ObjCMethodDecl
cannot be set. No functionality change.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172307 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
774b97312ddffe64435a1428f904211ee46cf289 12-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Remove a redundant CurrentLineType check.

The containing if checks for this already. No functionality change.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172306 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
bcfdd263b79c766db9154b009bd831ef83090c83 12-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Initial support for formatting Objective-C method expressions.

This follows the approach suggested by djasper in PR14911: When a '[' is
seen that's at the start of a line, follows a binary operator, or follows one
of : [ ( return throw, that '[' and its closing ']' are marked as
TT_ObjCMethodExpr and every ':' in that range that isn't part of a ternary
?: is marked as TT_ObjCMethodExpr as well.

Update the layout routines to not output spaces around ':' tokens that are
marked TT_ObjCMethodExpr, and only allow breaking after such tokens, not
before.

Before:
[self adjustButton : closeButton_ ofKind : NSWindowCloseButton];

Now:
[self adjustButton:closeButton_ ofKind:NSWindowCloseButton];



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172304 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
5e9f91c342f8efffe0423d516997ddbc408c9f53 12-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: * and & are binary operators before ( and [.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172303 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
2355cebe3847acd4ce175e3a88788b8effd93c6e 12-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: * and & are binary operators after ) and ].

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172302 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
cc191d1980101bba47d3d67acf782890076fa5c3 12-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: + and - after { are unary operators.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172301 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
67015ed2f40d6f69ee9e15d79aa88530f4b4afe2 11-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Format ObjC static and instance methods consistently, add a test for that.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172254 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
6eca03fcac1e408470d48e6309a280d3681f717d 11-Jan-2013 Manuel Klimek <klimek@google.com> Fix crashes in UnwrappedLineParser on missing parens.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172239 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
d5688cf3e314819ca196053ac245c19a7c321332 11-Jan-2013 Manuel Klimek <klimek@google.com> Fix single-line optimization for ObjC.

Puts blocks always into multiple lines when they start with an ObjC
keyword or minus.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172238 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
d465843f5376c7c1574fe61338cbf3dc50684d5b 11-Jan-2013 Manuel Klimek <klimek@google.com> Fix crash on invalid.

if { foo; }
would previously crash clang-format.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172232 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
606e07ecc0b7b0e01d23baa833b4b4c73af0d4f4 11-Jan-2013 Manuel Klimek <klimek@google.com> Fix parsing of initializer lists with elaborated type specifier.

Now we correctly parse and format:
verifyFormat("struct foo a = { bar };
int n;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172229 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
nwrappedLineParser.h
517e894c56211f57c487bdaba8ead0edc84396fe 11-Jan-2013 Manuel Klimek <klimek@google.com> Implements pulling simple blocks into a single line.

void f() { return 42; }

The final change that implements the feature.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172225 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
088dab50b76d235cd5b0e701048efccfcea3677e 11-Jan-2013 Daniel Jasper <djasper@google.com> Correct spacing around new and delete.

This fixes llvm.org/PR14913.

Before: A *a = new(placement) A;
After: A *a = new (placement) A;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172212 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
276a209451b8724807f2741f49c90bf27fc280c7 11-Jan-2013 Alexander Kornienko <alexfh@google.com> clang-format: a bit nicer error message.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172211 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
7d19bc2c8882457e833dfe9741ac5a4a7198e46f 11-Jan-2013 Daniel Jasper <djasper@google.com> Improve handling of trailing declaration annotations.

Before:
void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) GUARDED_BY(
aaaaaaaaaaaaa);

After:
void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
GUARDED_BY(aaaaaaaaaaaaa);

Also did some formatting cleanups with clang-format on the way.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172200 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
7e9bf8c249a5a9717447a00a8669596002a5569a 11-Jan-2013 Daniel Jasper <djasper@google.com> Improved formatting of constructor initializers

Added option to put each constructor initializer on its own line
if not all initializers fit on a single line. Enabling this for
Google style now as the style guide (arguable) suggests it. Not
sure whether we also want it for LLVM.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172196 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
604eb4c741e58a114e2ae073991bb7944203b755 11-Jan-2013 Daniel Jasper <djasper@google.com> Refactor IndentState into two classes.

As we keep adding more stuff to it, this structure is easier to
maintain. At one point we might think about making it an actual
class with specific accessors, etc.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172188 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
cd52bdaaf076b0082c07c6b3d88937fb737054f1 11-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Put spaces in ObjC method decls in the right place for Google style.

Objective-C method declarations look like this:

- (returntype)name:(type)argname anothername:(type)arg2name;

In google style, there's no space after the leading '-' but one after
"(returntype)" instead (but none after the argument types), see
http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml#Method_Declarations_and_Definitions

Not inserting the space after '-' is easy, but to insert the space after the
return type, the formatter needs to know that a closing parenthesis ends the
return type. To do this, I tweaked the code in parse() to check for this, which
in turn required moving detection of TT_ObjCMethodSpecifier from annotate() to
parse(), because parse() runs before annotate().

(To keep things interesting, the return type is optional, but it's almost
always there in practice.)

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



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172140 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
7084823f8ec4367019940b26245e01684b62c7e1 10-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: No spaces around '=' in @property lines.

Before:
@property(assign, getter = isEditable) BOOL editable;

Now:
@property(assign, getter=isEditable) BOOL editable;

It'd be nice if some Apple person could let me know if spaces are preferred
around '=' in @synthesize lines (see FIXME in the test).



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172110 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
5f500df1b28e6b1c49d4256dda130ecd8696ea2e 10-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatting: In @implementation etc lines, put a space before protocol lists.

Don't do this in Google style though:
http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml#Protocols

Most other places (function declarations, variable declarations) still get
this wrong, and since this looks very similiar to template instantiations to
the lexer (`id <MyProtocol> a = ...`), it's going to be hard to fix in some
places.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172099 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
f9ea2ed30a8dec954f3d78ca43afc0be914bb1db 10-Jan-2013 Manuel Klimek <klimek@google.com> Refactoring the outermost structure of the formatter.

This is the last step of pure shuffling stuff around, the next step will
be the actual feature.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172098 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
81ed2f1cd7202e84bf1f3868a60a36904499c94c 10-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Don't put a space in ObjC number literals like @+50

Before:
@ -4.5

Now:
@-4.5



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172095 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
ed91bbaa8c4c92a1c94c9a7a5f4141551718cf6b 10-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Add space before '(' in @implemenation, @interface, @protocol lines

The first token in @implementation, @interface, and @protocol lines is now
marked TT_ObjCDecl, and lines starting with a TT_ObjCDecl token are now marked
LT_ObjCMethodDecl.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172093 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
94fc6f15d99a16abe6c28a7baa3f2358450920d1 10-Jan-2013 Manuel Klimek <klimek@google.com> Pull calculation whether a line fits one level up.

This is the next step towards being able to configure multiple unwrapped
lines into one.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172092 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
3f8c7f3a07df65580a9ca0fe3e956b8a40956a79 10-Jan-2013 Manuel Klimek <klimek@google.com> Pulling formatFirstToken one level up.

This prepares the code for single line optimizations and changes the
dependencies between single-line-formats to the indent of the first
token.

Conceptually, the first token is "between" the lines anyway, as the
whitespace for the first token includes the previous end-of-line, which
needs to be escaped when inside a preprocessor directive.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172083 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
c8c8a478639f1474f4c53d12befc405934083633 10-Jan-2013 Manuel Klimek <klimek@google.com> Fixes layout of right braces.

We now decide whether a newline should go before the closing brace
depending on whether a newline was inserted after the opening brace.

For example, we now insert a newline before '};' in:
static SomeClass WithALoooooooooooooooooooongName = {
100000000, \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"
};
... while not inserting a newline here:
static SomeClass = { a, b, c, d, e, f, g, h, i, j,
looooooooooooooooooooooooooooooooooongname,
looooooooooooooooooooooooooooooong };

Also fixes the formating of (column limit 25):
int x = {
avariable,
b(alongervariable)
};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172076 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
3048aeae0654b34dcae561494c1b28872c88a5c8 10-Jan-2013 Alexander Kornienko <alexfh@google.com> Basic support for diagnostics.

Summary: Uses DiagnosticsEngine to output diagnostics.

Reviewers: djasper, klimek

Reviewed By: djasper

CC: cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172071 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
nwrappedLineParser.h
2851c16443dcdb9d8bb509d321fb827a560b47bc 10-Jan-2013 Manuel Klimek <klimek@google.com> Fixes formatting of function calls etc inside an initializer list.

We're now formatting (column limit 25):
int x = {
avariable,
b(alongervariable) };

This also fixes:
Aaa({
int i;
}, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
ccccccccccccccccc));
... where we would previously break after the '},'.

Putting the closing curly into an extra line when there's a break
directly after the first curly will be done in a subsequent patch.

Paired with djasper.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172070 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
36fab8d70eee342d66e03c9b09c029f126196103 10-Jan-2013 Manuel Klimek <klimek@google.com> Do not add newline in empty blocks.

void f() {}
now gets formatted in one line.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172067 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
46ef852618b18bc79e403b37a12c9b692e76126b 10-Jan-2013 Daniel Jasper <djasper@google.com> Improvements to function type and ObjC block formatting.

Before: int (^myBlock) (int) = ^(int num) {}
A<void ()>;
int (*b)(int);

After: int (^myBlock)(int) = ^(int num) {}
A<void()>;
int(*b)(int);

For function types and function pointer types, this patch only makes
the behavior consistent (for types that are keywords and other types).
For the latter function pointer type declarations, we'll probably
want to add a space after "int".

Also added LangOpts.Bool = 1, so we handle "A<bool()>" appropriately
Moved the LangOpts-settings to a public place for use by tests
and clang-format binary.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172065 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
bb42bf1a8bfd18fa2beec7fcbcb73f738fb455ba 10-Jan-2013 Manuel Klimek <klimek@google.com> Fix layout of blocks inside statements.

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 };

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172058 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
nwrappedLineParser.h
5cf7cf317f684dc61b8a0e4476440b5635b80db4 10-Jan-2013 Daniel Jasper <djasper@google.com> Improve clang-format's understanding of casts.

This fixes llvm.org/PR14684.

Before: int *pa = (int *) & a;
After: int *pa = (int *)&a;

We still don't understand all kinds of casts. I added a FIXME to
address that.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172056 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
4c60fc6cb9928fe03b6b4794260edb779b2c44e1 10-Jan-2013 Manuel Klimek <klimek@google.com> Introduce a define to switch on debug output.

After re-writing the same loop multiple times, we deicided it's time to
add this as an optional debugging help.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172050 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
700e710544a50ec63f984b9b098530bf9107920a 10-Jan-2013 Daniel Jasper <djasper@google.com> Do more error checking for '{}'.

This fixes llvm.org/PR14883, where clang-format would run into an
assertion on:

void f() { return } 42

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172049 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
880e538536d1a7597eb5805d67a08e3941577c7f 10-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Remove unused @-formatting code.

@optional @property is put on two different unwrapped lines now, so this is no
longer necessary.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172024 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
b530fa374a8d4d96e61bf1dae8f4a73f4b3d2436 10-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: @optional and @required go on their own line.

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



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172023 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
50767d8c8f2f667255bdb99692c0467ce992bc67 10-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Add support for @implementation.

Just reuse the @interface code for this. It accepts slightly more than
necessary (@implementation cannot have protocol lists), but that's ok.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172019 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
nwrappedLineParser.h
049c44767370b7257d17a5c32d407f19efa01c6f 09-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Make parseObjCUntilAtEnd() actually work.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172003 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
1abe6ea5b8961a0fc14c2e0bdbd7451f643ca065 09-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatting: Add support for @protocol.

Pull pieces of the @interface code into reusable methods.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172001 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
nwrappedLineParser.h
27d1367871a6eab347346497e87ea1adb2fd15a5 09-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Add support for @interface.

Previously:
@interface Foo + (id)init; @end

Now:
@interface Foo
+ (id)init;
@end

Some tweaking remains, but this is a good first step.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171995 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
nwrappedLineParser.h
526ed11ad9743c773df76bd1649d33fb92c2b8cb 09-Jan-2013 Manuel Klimek <klimek@google.com> Enables layouting unwrapped lines around preprocessor directives.

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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171974 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
nwrappedLineParser.h
3fc0bb779e751de71166c20a365cd5c28c3de8ed 09-Jan-2013 Daniel Jasper <djasper@google.com> Only align after assignments on the top level.

This fixes llvm.org/PR14870 and we no longer mess up:
template <typename T1, typename T2 = char, typename T3 = char,
typename T4 = char>
void f();

It removes the nice aligment for assignments inside other expressions,
but I am not sure those are actually practically relevant. If so, we can
fix those later.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171966 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
ceb99ab9d721848c0851c59f3fdd9c1ca85c58be 09-Jan-2013 Daniel Jasper <djasper@google.com> Don't simply give up when exceeding 80cols, choose an "ok" option.

This addresses llvm.org/PR14847.

We can now format something like:
int aaaaaaaaaaaaaaaaaaaaaaaaaaa =
// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaiaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;

clang-format unavoidably exceeds the column limit, but does not just
flush everything into a single line. Moreover, it tries to minimize the
number of characters beyond the column limit.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171964 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
d64f73812f3e6473ef8b6b6ec909bb9d8a510843 09-Jan-2013 Daniel Jasper <djasper@google.com> Correctly format wrapped function call parameters in templated functions.

This fixes llvm.org/PR14846.

Before:
template <typename T>
void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
int aaaaaaaaaaaaaaaaa);

After:
template <typename T>
void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
int aaaaaaaaaaaaaaaaa);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171963 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
043835aa876b1edeca0a05def0cc0989faa15892 09-Jan-2013 Daniel Jasper <djasper@google.com> Allow comments in the middle of statements to be on their own line.

This fixes llvm.org/PR14860.

Before, we messed up the format of:
if (DeclaratorInfo.isFunctionDeclarator() &&
//getDeclSpecContextFromDeclaratorContext(Context) == DSC_top_level &&
Tok.is(tok::semi) && NextToken().is(tok::l_brace)) {
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171961 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
886568dc24eb0a1ccf73bf32d1eafa8fd4008cc6 09-Jan-2013 Daniel Jasper <djasper@google.com> Fix ObjC block declarations.

Before: int ( ^ Block1) (int, int) = ^ (int i, int j)
After: int (^Block1) (int, int) = ^(int i, int j)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171959 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
9c837d05c9e6d6971900d36b1e462ed3666b7487 09-Jan-2013 Daniel Jasper <djasper@google.com> Improve formatting of conditional operators.

This addresses llvm.org/PR14864.

We used to completely mess this up and now format as:
Diag(NewFD->getLocation(),
getLangOpts().MicrosoftExt ? diag::ext_function_specialization_in_class :
diag::err_function_specialization_in_class)
<< NewFD->getDeclName();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171957 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
2db356d619fbf56e342fbc3fd5301e2e539e51b6 08-Jan-2013 Daniel Jasper <djasper@google.com> Don't break after unary operators.

Before:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaa, *
aaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

After:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaa, *aaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171890 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
cb4d690820295d93c1cea6c13fb4409b8c1db2cf 08-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Format @ literals better. Array and dictionary literals need more work.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171887 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
765561ff8fa636cc88d133b85ecb592094104554 08-Jan-2013 Daniel Jasper <djasper@google.com> Don't put spaces around ##.

In Clang/LLVM this seems to be the more common formatting for ##s. There
might still be case that we miss, but we'll fix those as we go along.

Before:

#define A(X)
void function ## X();

After:

#define A(X)
void function##X();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171862 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
26f7e78018ed6ce8aa11b5eef94c772ca4ee48bf 08-Jan-2013 Daniel Jasper <djasper@google.com> Change the data structure used in clang-format.

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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171856 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
nwrappedLineParser.h
6092d4ed09a2368871993d9a45717f24394329ce 07-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Support @public/@protected/@package/@private.

@package is an Objective-C 2 feature, so turn on ObjC2 as well.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171766 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
de7685487c5d628dd9fe64c4f861cd1888f50fc7 07-Jan-2013 Manuel Klimek <klimek@google.com> Fix parsing of variable declarations directly after a class / struct.

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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171761 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
nwrappedLineParser.h
a9ccdd1b8ef31d1942193ffa6bc32781055cf493 07-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Add tests for try/catch. Let 'throw' start an expression.

Before:
throw a *b;

Now:
throw a * b;



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171754 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
d0af4b46741560cf2e52d819e1f3a2506a1e7a3c 07-Jan-2013 Nico Weber <nicolasweber@gmx.de> Formatter: Don't put spaces betwen @ and objc keywords.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171753 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
da92771074afd709cbea552ae38717ac73d8011b 07-Jan-2013 Daniel Jasper <djasper@google.com> Small refactoring of the formatter code.

This should make it slightly more readable as it more clearly separates
what happens where. No intended functional changes. More of this to
come..

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171748 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
decf7bcafd71af8c31cbc17eec1d6d050e2a1ea2 07-Jan-2013 Nico Weber <nicolasweber@gmx.de> Fix typo.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171740 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
f0ab0a38d9482eef5495db845ff53ee689f9c80e 07-Jan-2013 Manuel Klimek <klimek@google.com> s/parseStatement/parseStructuralElement/g in the UnwrappedLineParser.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171737 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
nwrappedLineParser.h
cd162384a552ef4e4913244f4f14b9a3e5a791e1 07-Jan-2013 Daniel Jasper <djasper@google.com> Reformat clang-formats source code.

All changes done by clang-format itself. No functional changes.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171732 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
nwrappedLineParser.h
9cda8000434be3360abb38fe1690fa24ae3d48be 07-Jan-2013 Daniel Jasper <djasper@google.com> 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171731 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
7ad4effaa96905ef9dbc3815760b06b1d1639390 07-Jan-2013 Daniel Jasper <djasper@google.com> 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171725 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
71607512cb70db3c1be8f0287153b681531687fc 07-Jan-2013 Daniel Jasper <djasper@google.com> 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171724 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
dd5b1018d97a9666da92d320485a727ac63ee89a 07-Jan-2013 Manuel Klimek <klimek@google.com> 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171720 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
c3d0c82ab0ce17c684c0192f14059d8e4d63156c 07-Jan-2013 Manuel Klimek <klimek@google.com> Remove outdated FIXME and add explanation for error handling strategy
while parsing #define's.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171717 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
f39f6ff8ea2c9136f890a47f0ab784359e9706e6 07-Jan-2013 Manuel Klimek <klimek@google.com> Remove outdated fixme.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171716 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
d544c574ccbcbfcb5b3c3edd19956143826008cf 07-Jan-2013 Manuel Klimek <klimek@google.com> 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171715 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
6cf581436e9e59a18f6a362027a69eaaa9b67597 07-Jan-2013 Manuel Klimek <klimek@google.com> 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 "//".

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171713 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
9541938d4e3b9cbafdf0e1a28900c535b82767a4 07-Jan-2013 Manuel Klimek <klimek@google.com> 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).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171706 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.h
46a46a20a3ec397192550915964cb227e87b79b2 07-Jan-2013 Daniel Jasper <djasper@google.com> 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));

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171705 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
a5342db6fcc6ee3fae084f584ecb019726de9cca 06-Jan-2013 Manuel Klimek <klimek@google.com> 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171666 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
nwrappedLineParser.h
f6fd00b12ae7d89436d32851c9bcc8dd3d046ad3 05-Jan-2013 Manuel Klimek <klimek@google.com> 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171640 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
nwrappedLineParser.h
c37b4d60f926bf440dfcc312bd6482fed3176e33 05-Jan-2013 Manuel Klimek <klimek@google.com> 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171639 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
nwrappedLineParser.h
6f8424b79863fc9810393c95ecdee97895ab6f26 05-Jan-2013 Manuel Klimek <klimek@google.com> Fixes PR14811: Crash when formatting some macros

A preprocessor directive cannot be started while we're parsing one.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171635 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
d4397b99e2fcb189002d04410d7c3bf85ab4bba3 05-Jan-2013 Manuel Klimek <klimek@google.com> 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171556 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
nwrappedLineParser.h
9bb0d280faaedd528d2af7eeaf06c9f262345ad2 04-Jan-2013 Daniel Jasper <djasper@google.com> Correctly format dereference and address of in array parameters.

Before: InvalidRegions[ &R] = 0;
After: InvalidRegions[&R] = 0;

This fixes llvm.org/PR14793

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171522 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
1f42f11870325d1869eb7d51b98ebf5e6d7bcc26 04-Jan-2013 Daniel Jasper <djasper@google.com> Let the formatter ignore UnwrappedLines containing errors.

This prevents code like:

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

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171495 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
060143e4ad7f80c4349d472c06a63a953650c2a9 02-Jan-2013 Manuel Klimek <klimek@google.com> 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171401 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
5eda31ee30106c769b5829683761d42e6e50467f 02-Jan-2013 Daniel Jasper <djasper@google.com> 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);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171400 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
ba3d3074e8ef4c4c05ac062b073b2e082e6a0206 02-Jan-2013 Daniel Jasper <djasper@google.com> 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 :-)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171396 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
a080a187fa7e538da3212c7d5e678e4b7ae03253 02-Jan-2013 Manuel Klimek <klimek@google.com> 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171393 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
nwrappedLineParser.h
ef5b9c3d38a1f6d0921591cb2749e529a8cc4a2e 02-Jan-2013 Daniel Jasper <djasper@google.com> Correctly format pointers and references in casts.

This fixes llvm.org/PR14747.

Before: Type *A = (Type * ) P;
After: Type *A = (Type *) P;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171390 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
1f0754bf761f7d4910348ce3aba867d34473bceb 02-Jan-2013 Daniel Jasper <djasper@google.com> Understand unary operators after "return" and "case".

This fixes llvm.org/PR14746.

Before: return - 1;
After: return -1;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171389 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
9a64fb5690ba2b53c761def068e20ec64c584d96 02-Jan-2013 Daniel Jasper <djasper@google.com> 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);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171388 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
723f0304eaaf1aed20aece9021a1bb8578477e75 02-Jan-2013 Daniel Jasper <djasper@google.com> Prefer to break after operators over breaking after "(".

Before:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

After:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171386 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
b99083e60325a28063fb588f458a871151971fdc 02-Jan-2013 Chandler Carruth <chandlerc@gmail.com> Re-sort #include lines using the llvm/utils/sort_includes.py script.

Removes a duplicate #include as well as cleaning up some sort order
regressions since I last ran the script over Clang.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171364 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
5d334407e68e45e3e7baa0cd140d4fd75e7483d6 02-Jan-2013 Daniel Jasper <djasper@google.com> Understand * and & in ternary expressions.

Before: "int a = b ? *c : * d;"
After: "int a = b ? *c : *d;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171358 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
4dc41def6129bcecd4d08e5ffafe021aa7b1fa2a 02-Jan-2013 Daniel Jasper <djasper@google.com> 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) {

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171357 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
1f94f2b484dc74e09fe31dd5ea9d3f715be6c133 30-Dec-2012 Dmitri Gribenko <gribozavr@gmail.com> Formatter: parse and format inline namespaces like regular namespaces

This changes formatting from:

inline namespace X {
class A {
};
}

to:

inline namespace X {
class A {
};
}



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171266 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
d7610b8a744b2459ce2e66fea7d3a3d56ce23dba 24-Dec-2012 Daniel Jasper <djasper@google.com> Let clang-format format itself.

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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171039 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
nwrappedLineParser.h
a4974cf6ae618f04d5dd7fc45bc18bff41ca86bf 24-Dec-2012 Daniel Jasper <djasper@google.com> 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();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171038 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
cf225b67e66d7a85773b7bf7907c0fef4374c31b 24-Dec-2012 Daniel Jasper <djasper@google.com> 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;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171032 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
f6aef6a25bd47f2a7bfc24938e29b746fdccdc72 24-Dec-2012 Daniel Jasper <djasper@google.com> 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()() {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171028 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
e2c7acf58856fec94ed2b8089116e1ad80e3c30f 24-Dec-2012 Daniel Jasper <djasper@google.com> 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) { .. }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171007 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
00d5a04dc0eaa0f067656033ab81fc352c5a991a 23-Dec-2012 Nico Weber <nicolasweber@gmx.de> 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.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170993 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
b23ae0c5104a4fec4c2ff603143fe142ec409249 21-Dec-2012 Nico Weber <nicolasweber@gmx.de> format: Handle #import as include directive too.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170914 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
cd1a32b1f02016fe5ebb1142aadccc54bbdf5d89 21-Dec-2012 Daniel Jasper <djasper@google.com> 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>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170910 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
5f04ef52837c82e99baac4e6041526f829c4e04b 21-Dec-2012 Fariborz Jahanian <fjahanian@apple.com> Fix typo.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170904 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
a324a0e673cf486de281c84af3f09ba58627bbd2 21-Dec-2012 Daniel Jasper <djasper@google.com> 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170899 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
675d2e34889a1b7e9d4cc659a4cdc33ce0f5b152 21-Dec-2012 Daniel Jasper <djasper@google.com> Use OperatorPrecedence.h in clang-format

No indented functional changes other than handling more operators
correctly.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170875 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
98e6b4a65fcc81b1be11f09837e0fc8fac85897b 21-Dec-2012 Daniel Jasper <djasper@google.com> Formatting fixes for PR14680

Also, some (automated) formatting fixes and slight cleanups.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170873 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
154120cde4f56ed04261bab302fdbbed1a7f080b 20-Dec-2012 Fariborz Jahanian <fjahanian@apple.com> Add objective-C style formatting to clang format and
use it to format xml declaration tags.
// rdar://12378714


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170727 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
1321eb593c8e13738dcaf72e409aa466c8cf6463 18-Dec-2012 Daniel Jasper <djasper@google.com> 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170457 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
9a0b494f999dfd47152565f7bbeaa69b3fef8feb 17-Dec-2012 Daniel Jasper <djasper@google.com> 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170337 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
05b1ac8791ee89fdf0b275631ab8118febc7c33d 17-Dec-2012 Daniel Jasper <djasper@google.com> Fix several formatting problems.

More specifically:
- Improve formatting of static initializers.
- Fix formatting of lines comments in enums.
- Fix formmating of trailing line comments.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170316 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
nwrappedLineParser.h
8b39c6693aadd30f77ac039de69130c22e066994 10-Dec-2012 Daniel Jasper <djasper@google.com> Addi formatting tests for pointer template parameters.

Fix spacing before ",".

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169746 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
56e49c5cc2b05e805c7aa9dc53672711e540d58b 10-Dec-2012 Alexander Kornienko <alexfh@google.com> Clang-format: error recovery for access specifiers

Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169738 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
422daa1b838788c3ef564640f9d91f52d7deffbe 07-Dec-2012 Matt Beaumont-Gay <matthewbg@google.com> Appease -Wnon-virtual-dtor

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169648 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.h
469a21b14c8d00001ad30a925020ee5a81c9b8b5 07-Dec-2012 Alexander Kornienko <alexfh@google.com> Clang-format: extracted FormatTokenSource from UnwrappedLineParser.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169605 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
nwrappedLineParser.h
c74e2794bebaab41213f23b27c09c21cb1e1f81b 07-Dec-2012 Daniel Jasper <djasper@google.com> Small tweaks to clang-format.

Now not joining keywords with '::' and not putting a space between
a pointer pointer.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169594 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
15757316d67cb7a854d53a0402d67ad58347600a 06-Dec-2012 Alexander Kornienko <alexfh@google.com> 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169520 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
nwrappedLineParser.h
a3a2b3a1e86a93d2044106046a4dca13a3558fba 06-Dec-2012 Alexander Kornienko <alexfh@google.com> Clang-format: detect unbalanced braces.

Reviewers: klimek, djasper

Reviewed By: klimek

CC: cfe-commits, silvas

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169518 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
d56a737842f28db4403430082c4d2686bc6cc3b3 06-Dec-2012 Daniel Jasper <djasper@google.com> Improve clang-format's handling of unary operators.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169500 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
3b5943f535eca0e0b91f4bcda9d09c9c275cf855 06-Dec-2012 Daniel Jasper <djasper@google.com> "<<" alignment for clang-format.

Also, small fix for handling the first token correctly.

Review: http://llvm-reviews.chandlerc.com/D177

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169488 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
dfbb3197de8407a4209f328e4de1ae73bac70b8b 05-Dec-2012 Daniel Jasper <djasper@google.com> Remove bad and useless enum to bool conversion.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169390 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
2e97cfc78743fcaa988e3c45f7af1002063f780c 05-Dec-2012 Alexander Kornienko <alexfh@google.com> 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169387 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
nwrappedLineParser.h
33182dd0f7d5b5e913b1957c2cb6dc04942efd46 05-Dec-2012 Daniel Jasper <djasper@google.com> 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169384 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
720ffb644400661b927c6359aac5677dab036ed4 05-Dec-2012 Alexander Kornienko <alexfh@google.com> Follow-up to r169286, addresses comments in http://llvm-reviews.chandlerc.com/D164#comment-4 : comments and a method rename

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169382 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
nwrappedLineParser.h
112fb27ab48ae3256173806a073ba7b88aa6531a 05-Dec-2012 Daniel Jasper <djasper@google.com> Small tweaks to automatic formatting.

Recognize '!=' as a binary operator and assume that there are no
type definitions on the RHS of an assignment.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169363 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
accb0b0ad36138855e7d81f210588ad9b3c9de48 04-Dec-2012 Daniel Jasper <djasper@google.com> Add missing destructors found with -Wnon-virtual-dtor.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169303 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.h
cff563c0123bbb8d959c93ed371d27cbc6bc4a29 04-Dec-2012 Alexander Kornienko <alexfh@google.com> 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169286 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
nwrappedLineParser.h
393b008bcebb0a678a5a0a93ad69e28a30a62e84 04-Dec-2012 Alexander Kornienko <alexfh@google.com> Clang-format error recovery part 1

Reviewers: klimek

CC: cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169278 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
20409155c75e78bceb622a5e0d1fad40df70f34d 04-Dec-2012 Daniel Jasper <djasper@google.com> Make parenthesis counting and aligning a bit saner.

Review: http://llvm-reviews.chandlerc.com/D162

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169274 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
a166e73d39d2f554d0f35f94c9804284d1ff804a 04-Dec-2012 Alexander Kornienko <alexfh@google.com> Enum formatting implementation

Reviewers: djasper, klimek

Reviewed By: klimek

CC: cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169272 91177308-0d34-0410-b5e6-96231b3b80d8
nwrappedLineParser.cpp
8822d3a99c07c7d874f8bfd81a7fe02059b9c19e 04-Dec-2012 Daniel Jasper <djasper@google.com> Small fixes to unary operator recognition and handling of include
directives.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169261 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
a88bb45f11c1e27f9caf60a85a8e1774d3e09ead 04-Dec-2012 Daniel Jasper <djasper@google.com> Replace workarounds with correct fixes.

Also fix header guard.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169254 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
55fc873017f10f6f566b182b70f6fc22aefa3464 04-Dec-2012 Chandler Carruth <chandlerc@gmail.com> Sort all of Clang's files under 'lib', and fix up the broken headers
uncovered.

This required manually correcting all of the incorrect main-module
headers I could find, and running the new llvm/utils/sort_includes.py
script over the files.

I also manually added quite a few missing headers that were uncovered by
shuffling the order or moving headers up to be main-module-headers.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169237 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
nwrappedLineParser.cpp
nwrappedLineParser.h
0be4b36830a26026726d05aae5434c6658abc65f 03-Dec-2012 Manuel Klimek <klimek@google.com> Fixes a compile warning and crash in the tests.

The necessity of this fix points to a problem with the design
of the addToken during the optimiation phase, which we need to address
in a much more principled way.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169151 91177308-0d34-0410-b5e6-96231b3b80d8
ormat.cpp
12feb121146805a117c5d3439907a6a48ebc7365 03-Dec-2012 Benjamin Kramer <benny.kra@googlemail.com> libclangFormat is not libclangTooling, but it depends on it.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169139 91177308-0d34-0410-b5e6-96231b3b80d8
MakeLists.txt
akefile
bac016bd3f67ca2f4db1ddc619e611759352b84d 03-Dec-2012 Daniel Jasper <djasper@google.com> 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169137 91177308-0d34-0410-b5e6-96231b3b80d8
MakeLists.txt
ormat.cpp
akefile
nwrappedLineParser.cpp
nwrappedLineParser.h