summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/TokenAnnotator.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Dont break between (( in __attribute__((.Daniel Jasper2013-02-281-1/+4
| | | | | | | | | | | | | | Before: void aaaaaaaaaaaaaaaaaa() __attribute__( (aaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaa)); After: void aaaaaaaaaaaaaaaaaa() __attribute__((aaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaa)); llvm-svn: 176260
* No spaces around pointers to members.Daniel Jasper2013-02-281-2/+5
| | | | | | Before: (a ->* f)() After: (a->*f)() llvm-svn: 176252
* Fix spacing after binary operator as macro parameter.Daniel Jasper2013-02-281-1/+2
| | | | | | Before: COMPARE(a, == , b); After: COMPARE(a, ==, b); llvm-svn: 176241
* Fix formatting of multiplications in array subscripts.Daniel Jasper2013-02-271-0/+3
| | | | | | | | | | Before: a[a* a] = 1; After: a[a * a] = 1; llvm-svn: 176180
* Fix bad line break decision.Daniel Jasper2013-02-261-3/+3
| | | | | | | | | | | | Before: if (Intervals[i].getRange().getFirst() < Intervals[i - 1] .getRange().getLast()) {} After: if (Intervals[i].getRange().getFirst() < Intervals[i - 1].getRange().getLast()) {} llvm-svn: 176092
* In range-based for-loops, prefer splitting after ":".Daniel Jasper2013-02-261-1/+1
| | | | | | | | | | | | Before: for (const aaaaaaaaaaaaaaaaaaaaa & aaaaaaaaa : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} After: for (const aaaaaaaaaaaaaaaaaaaaa &aaaaaaaaa : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} llvm-svn: 176087
* Only keep empty lines in unwrapped lines if they preceed a line comment.Daniel Jasper2013-02-261-2/+0
| | | | | | | | | | | | | | | | | | 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 }; llvm-svn: 176086
* Allow breaking between a type and name in variable declarations.Daniel Jasper2013-02-241-32/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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) {} llvm-svn: 175999
* Better formatting of conditional expressions.Daniel Jasper2013-02-231-8/+24
| | | | | | | | | | | | | | | | | | | | | | | 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. llvm-svn: 175973
* Don't recognize unnamed pointer parameters as casts.Daniel Jasper2013-02-231-1/+2
| | | | | | | | This fixes llvm.org/PR15061. Before: virtual void f(int *)const; After: virtual void f(int *) const; llvm-svn: 175960
* Allow splitting between string literals and identifiers.Daniel Jasper2013-02-231-0/+6
| | | | | | | | | | | | | | | 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. llvm-svn: 175959
* Remove accidentally introduced no-op line.Daniel Jasper2013-02-211-1/+0
| | | | | | | Was used during experiments, but another if-statements a few lines before makes it (intentionally) useless. llvm-svn: 175803
* Consistently put {} onto the same line for empty functions.Daniel Jasper2013-02-211-2/+2
| | | | | | | | | | | | | | | | | This fixes llvm.org/PR15167. Before: LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL() : AAAAAAAA(10), BBBBBBBBB(10) { } LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL() : AAAAAAAA(10) {} After: LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL() : AAAAAAAA(10), BBBBBBBBB(10) {} LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL() : AAAAAAAA(10) {} llvm-svn: 175800
* Allow breaking between type and name in for loops.Daniel Jasper2013-02-211-3/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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)); llvm-svn: 175741
* Don't remove blank lines within unwrapped lines.Daniel Jasper2013-02-201-1/+3
| | | | | | | | | | | | | | | | | 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 }; llvm-svn: 175620
* Add missing clang-format null pointer check..Daniel Jasper2013-02-191-1/+2
| | | | | | .. and a test that triggers it in valid albeit questionable code. llvm-svn: 175554
* Correctly format macro with unfinished template declaration.Daniel Jasper2013-02-191-1/+2
| | | | | | | | | We can now format: #define A template <typename T> Before this created a segfault :-/. llvm-svn: 175533
* Improve indentation of builder type calls.Daniel Jasper2013-02-181-2/+1
| | | | | | | | | | | | | | | | | | | | | | | 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(); llvm-svn: 175444
* Improve formatting of builder-type calls.Daniel Jasper2013-02-181-1/+1
| | | | | | | | | | | | | Before: aaaaaaa->aaaaaaa->aaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)->aaaaaaaa(aaaaaaaaaaaaaaa); After: aaaaaaa->aaaaaaa ->aaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) ->aaaaaaaa(aaaaaaaaaaaaaaa); llvm-svn: 175441
* Correctly determine */& usage in more cases.Daniel Jasper2013-02-181-0/+8
| | | | | | | | | | | | | | 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) {} llvm-svn: 175439
* Use the correct type to hold enumeration valuesDmitri Gribenko2013-02-161-2/+2
| | | | llvm-svn: 175374
* Recognize < and > as binary expressions in builder-type calls.Daniel Jasper2013-02-151-3/+5
| | | | | | | | | | | | | | | | | 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(); llvm-svn: 175291
* Done break between 'operator' and '<<'.Daniel Jasper2013-02-151-1/+1
| | | | | | | | | | | | Before: ostream &operator <<(ostream &out, some::ns::SomeReallyLongType WithSomeReallyLongValue); After: ostream &operator<<(ostream &out, some::ns::SomeReallyLongType WithSomeReallyLongValue); llvm-svn: 175286
* Fix counting of parameters so that r175162 works as expected.Daniel Jasper2013-02-141-8/+11
| | | | | | | | | | | | | | | 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. llvm-svn: 175165
* Reduce penalty for breaking before ./-> after complex calls.Daniel Jasper2013-02-141-5/+6
| | | | | | | | | | | | | | | | | 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. llvm-svn: 175162
* Align superclasses for multiple inheritence.Daniel Jasper2013-02-141-2/+9
| | | | | | | | | | | | | | | | This fixes llvm.org/PR15179. Before: class ColorChooserMac : public content::ColorChooser, public content::WebContentsObserver { }; After: class ColorChooserMac : public content::ColorChooser, public content::WebContentsObserver { }; llvm-svn: 175147
* Allow breaking after the return type in function declarations.Daniel Jasper2013-02-131-1/+3
| | | | | | | | | | | | | | | | | 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() {} llvm-svn: 175074
* Formatter: Refactor the cast detection code to be a bit more readable.Nico Weber2013-02-131-9/+10
| | | | | | No functionality change. Also add another cast test. llvm-svn: 175029
* Formatter: Detect ObjC method expressions after casts.Nico Weber2013-02-131-1/+1
| | | | | | Not all casts are correctly detected yet, but it helps in some cases. llvm-svn: 175028
* Replace 'signed' with 'int'. 'signed' is not typical for LLVM styleDmitri Gribenko2013-02-121-1/+1
| | | | llvm-svn: 175015
* Fixing the MSVC compiler warning a different way; removed use of static_cast ↵Aaron Ballman2013-02-121-2/+2
| | | | | | and instead used a signed integer parameter. llvm-svn: 174996
* Removing a signed/unsigned mismatch warning triggered in MSVC 11.Aaron Ballman2013-02-121-1/+1
| | | | llvm-svn: 174986
* Formatter: Correctly format stars in `sizeof(int**)` and similar places.Nico Weber2013-02-121-14/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 llvm-svn: 174975
* Formatter: Detect ObjC message expressions after 'in' in loopNico Weber2013-02-111-3/+11
| | | | | | | | | | | | | | | | 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. llvm-svn: 174889
* Fix invalid formatting with spaces before trailing comments.Daniel Jasper2013-02-111-3/+7
| | | | | | | | 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. llvm-svn: 174879
* Fix formatting of overloaded operator definitions.Daniel Jasper2013-02-111-16/+12
| | | | | | | | | | | | Before: operatorvoid*(); operator vector< A< A>>(); After: operator void *(); operator vector<A<A> >(); llvm-svn: 174863
* Formatter: Remove now-unneeded code for formatting ':'s in ObjC method decls.Nico Weber2013-02-101-21/+0
| | | | | | | 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. llvm-svn: 174843
* Formatter: Detect ObjC array literals.Nico Weber2013-02-101-4/+11
| | | | | | | | 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. llvm-svn: 174822
* Fix handling of fake parenthesis during formatting.Daniel Jasper2013-02-081-1/+1
| | | | | | | | | | | | | | | | | | 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); llvm-svn: 174718
* Implement a tiny expression parser to improve formatting decisions.Daniel Jasper2013-02-081-6/+90
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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. llvm-svn: 174714
* clang-format: Don't put useless space in f( ::g()).Daniel Jasper2013-02-071-1/+2
| | | | llvm-svn: 174662
* Become a little smarter with formatting long chains of pipes.Daniel Jasper2013-02-061-1/+9
| | | | | | | | | | | | | | | | | | | | | 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; llvm-svn: 174545
* Formatter: Correctly detect ObjC message expressions preceded by a comment.Nico Weber2013-02-061-11/+14
| | | | llvm-svn: 174521
* Optionally derive formatting information from the input file.Daniel Jasper2013-02-061-42/+51
| | | | | | | | | | | | | 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. llvm-svn: 174504
* Fix an issue with the formatting of stars in default values.Daniel Jasper2013-02-061-1/+1
| | | | | | Before: void f(int *a = d *e, int b = 0); After: void f(int *a = d * e, int b = 0); llvm-svn: 174500
* Handle nested ObjC calls.Daniel Jasper2013-02-061-83/+88
| | | | | | | | | | | | | | 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. llvm-svn: 174498
* Formatter: No space after & and * in front of ObjC message expressions.Nico Weber2013-02-061-6/+10
| | | | | | | | | | | | | | 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. llvm-svn: 174489
* Formatter: Detect ObjC method expressions after unary operators.Nico Weber2013-02-051-6/+20
| | | | llvm-svn: 174384
* Initial support for formatting ObjC method declarations/calls.Daniel Jasper2013-02-051-16/+34
| | | | | | | | | | | | | | | | 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. llvm-svn: 174364
* Fix formatting regression introduced by r174307.Daniel Jasper2013-02-051-0/+2
| | | | | | | | | | 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 llvm-svn: 174361
OpenPOWER on IntegriCloud