summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/TokenAnnotator.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* clang-format: Improve alignment after 'return'.Daniel Jasper2013-09-301-0/+4
| | | | | | | | | | | | | | | | | 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; llvm-svn: 191654
* clang-format: Fix assertion on incomplete string literals.Daniel Jasper2013-09-291-1/+5
| | | | | | | | Before, this could would lead to an assert: llvm::errs() << " << a; llvm-svn: 191639
* clang-format: Improve formatting of functions with multiple trailing tokens.Daniel Jasper2013-09-271-1/+4
| | | | | | | | | | | | | Before: void SomeFunction(aaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaa) override final; After: void SomeFunction(aaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaa) override final; llvm-svn: 191494
* clang-format: Option to removing the space before assignment operators.Daniel Jasper2013-09-251-0/+3
| | | | | | Patch contributed by Aaron Wishnick. Thank you! llvm-svn: 191375
* clang-format: Improve address-of-operator detectionDaniel Jasper2013-09-211-1/+1
| | | | | | | | | | Before: size = sizeof * a; After: size = sizeof *a; llvm-svn: 191139
* clang-format: Don't accidentally move tokens into preprocessor directive.Daniel Jasper2013-09-171-29/+36
| | | | | | | | | | | | | | | | | | | | | This fixes llvm.org/PR17265. Before: Foo::Foo() #ifdef BAR : baz(0) #endif { } After: Foo::Foo() #ifdef BAR : baz(0) #endif { } llvm-svn: 190861
* clang-format: Fix line breaking bug after empty ifs.Daniel Jasper2013-09-171-0/+1
| | | | | | | | | | | | | | | | | Before: if () { } else { } After: if () { } else { } This fixed llvm.org/PR17262. llvm-svn: 190855
* clang-format: Don't split a >>-operator.Daniel Jasper2013-09-171-0/+3
| | | | | | | | | | | | | | | 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..) llvm-svn: 190854
* clang-format: Fix bug in style option AlwaysBreakTemplateDeclarations.Daniel Jasper2013-09-141-0/+3
| | | | | | | | | | | | | | | Before: template <template <typename> class Fooooooo, template <typename> class Baaaaaaar> struct C {}; After: template <template <typename> class Fooooooo, template <typename> class Baaaaaaar> struct C {}; llvm-svn: 190747
* clang-format: Fix incorrect enum parsing / layouting.Daniel Jasper2013-09-131-0/+6
| | | | | | | | | | | | | | | Before: enum { Bar = Foo < int, int > ::value }; After: enum { Bar = Foo<int, int>::value }; llvm-svn: 190674
* clang-format: Fix bug in pointer detectionDaniel Jasper2013-09-111-1/+1
| | | | | | | | | Before: for (int i = 0; i* 2 < z; i *= 2) {} After: for (int i = 0; i * 2 < z; i *= 2) {} llvm-svn: 190546
* Don't divide L and #x in macro definitions. Fixes http://llvm.org/PR17144Alexander Kornienko2013-09-101-0/+2
| | | | | | | | | | | | Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1639 llvm-svn: 190408
* clang-format: Understand function type typedefs with typeof.Daniel Jasper2013-09-101-0/+5
| | | | | | | | | | | Before: typedef typeof(int(int, int)) * MyFunc; After: typedef typeof(int(int, int)) *MyFunc; This fixes llvm.org/PR17178. llvm-svn: 190401
* Calculate and store ColumnWidth instead of CodePointCount in FormatTokens.Alexander Kornienko2013-09-101-6/+7
| | | | | | | | | | | | | | | | 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 llvm-svn: 190395
* clang-format: Fix regression introduced by r189353.Daniel Jasper2013-09-061-1/+2
| | | | | | | | | | | | | | | | | | | | 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. llvm-svn: 190126
* clang-format: Fix regression introduced by r189337.Daniel Jasper2013-09-061-1/+6
| | | | | | | | | | | | | | | Before: if (aaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) == 5) ... After: if (aaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) == 5) ... Also precompute startsBinaryExpression() to improve performance. llvm-svn: 190124
* clang-format: Fix comment formatting bugs in nested blocks.Daniel Jasper2013-09-061-4/+21
| | | | | | | | | | | 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. llvm-svn: 190123
* clang-format: Fix parsing and indenting lambdas.Daniel Jasper2013-09-051-1/+2
| | | | | | | | | | | | | | | | Before: void f() { other(x.begin(), x.end(), // [&](int, int) { return 1; }); } After: void f() { other(x.begin(), x.end(), // [&](int, int) { return 1; }); } llvm-svn: 190039
* clang-format: Enable formatting of nested blocks.Daniel Jasper2013-09-051-11/+22
| | | | | | | | | | | | | | | | | | 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. llvm-svn: 190038
* Fix layout of lambda captures.Manuel Klimek2013-09-041-2/+7
| | | | | | | | | | | | | | | | | | Before: int c = [ &, &a, a]{ [ =, c, &d]{ return b++; }(); }(); After: int c = [&, &a, a] { [=, c, &d] { return b++; }(); }(); llvm-svn: 189924
* Store first and last newline position in the token text for string literals ↵Alexander Kornienko2013-09-021-1/+1
| | | | | | | | | | | | | | | | | | 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 llvm-svn: 189758
* clang-format: Fix segfault in overloaded operator parsing.Daniel Jasper2013-09-021-2/+3
| | | | | | | | | Before, constructs like: using A::operator+; caused a segfault. This fixes llvm.org/PR17050. llvm-svn: 189749
* clang-format: Enable formatting of protocol buffer definitions.Daniel Jasper2013-08-301-1/+2
| | | | | | | | | | | | | 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. llvm-svn: 189663
* Better support for multiline string literals (including C++11 raw string ↵Alexander Kornienko2013-08-291-2/+1
| | | | | | | | | | | | | | | | | | 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 llvm-svn: 189595
* clang-format: Don't insert space in __has_includeDaniel Jasper2013-08-281-1/+2
| | | | | | | | | | | | | | | | Before: #if __has_include( <strstream>) #include <strstream> #endif After: #if __has_include(<strstream>) #include <strstream> #endif This fixes llvm.org/PR16516. llvm-svn: 189455
* clang-format: Fix corner case in overloaded operator definitions.Daniel Jasper2013-08-281-1/+4
| | | | | | | | | | | | | | | | | | 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. llvm-svn: 189450
* clang-format: Fix space in decltype-constexprs.Daniel Jasper2013-08-281-1/+2
| | | | | | | | | | Before: static constexpr bool Bar = decltype(bar()) ::value; After: static constexpr bool Bar = decltype(bar())::value; llvm-svn: 189449
* clang-format: Format segments of builder-type calls one per line.Daniel Jasper2013-08-271-4/+2
| | | | | | | | | | | | | | | | | | | | | | 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); llvm-svn: 189353
* clang-format: Revamp builder-type call formatting.Daniel Jasper2013-08-271-47/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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))); llvm-svn: 189337
* clang-format: Fix indentation relative to unary expressions.Daniel Jasper2013-08-231-15/+56
| | | | | | | | | | | | | | | | | | | 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 "*") llvm-svn: 189108
* clang-format: Add column layout formatting for braced listsDaniel Jasper2013-08-221-4/+15
| | | | | | | | | | | | | | | | | | | | 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 llvm-svn: 189018
* clang-format: Indent relative to unary operators.Daniel Jasper2013-08-211-7/+7
| | | | | | | | | | | | | | | | Before: if (!aaaaaaaaaa( // break aaaaa)) { } After: if (!aaaaaaaaaa( // break aaaaa)) { } Also cleaned up formatting using clang-format. llvm-svn: 188891
* clang-format: Additional options for spaces around parentheses.Daniel Jasper2013-08-201-6/+13
| | | | | | | | | | | | 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! llvm-svn: 188793
* clang-format: Fix return type line break decision.Daniel Jasper2013-08-191-4/+7
| | | | | | | | | | | | | | | | | 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) {} llvm-svn: 188665
* clang-format: Improve boolean expression formatting in macros.Daniel Jasper2013-08-131-1/+2
| | | | | | | | | | Before: #define IF(a, b, c) if (a&&(b == c)) After: #define IF(a, b, c) if (a && (b == c)) llvm-svn: 188256
* clang-format: Slightly adapt line break penalties.Daniel Jasper2013-08-131-1/+1
| | | | | | | | | | | Before: aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) ->aaaaaaaaa()); After: aaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa)->aaaaaaaaa()); llvm-svn: 188253
* clang-format: Correctly format alias declarations.Daniel Jasper2013-08-121-5/+6
| | | | | | | | | | | | | | 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. llvm-svn: 188172
* This change fixes the formatting of statements such as catch (E& e).Manuel Klimek2013-08-121-1/+2
| | | | | | | | | Previously these were formatting as catch (E & e) because the inner parenthesis was being marked as an expression. Patch by Thomas Gibson-Robinson. llvm-svn: 188153
* clang-format: Fix corner case in OpenMP pragma formatting.Daniel Jasper2013-08-071-1/+2
| | | | | | | | | Before: #pragma omp reduction( | : var) After: #pragma omp reduction(| : var) llvm-svn: 187892
* clang-format: Improve formatting of builder-type calls.Daniel Jasper2013-08-071-2/+0
| | | | | | | | | | | 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. llvm-svn: 187865
* clang-format: Operator precendence in ObjC method exprs.Daniel Jasper2013-08-011-0/+5
| | | | | | | | | | | | | | | | | | | | 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. llvm-svn: 187631
* clang-format: Don't break empty 2nd operand of ternary expr.Daniel Jasper2013-08-011-3/+6
| | | | | | | | | | | | | | | | 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. llvm-svn: 187622
* Teach clang-format to understand static_asserts better.Daniel Jasper2013-08-011-0/+3
| | | | | | | | | | | | | | | | | | | 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). llvm-svn: 187589
* clang-format: Improve line breaks in @property.Daniel Jasper2013-08-011-1/+3
| | | | | | | | | | | | Before: @property(nonatomic, assign, readonly) NSString *looooooooooooooooooooooooooooongName; After: @property(nonatomic, assign, readonly) NSString *looooooooooooooooooooooooooooongName; llvm-svn: 187577
* clang-format: Improve detection of templates.Daniel Jasper2013-07-301-1/+1
| | | | | | | | | | | Before: template <typename... Types> typename enable_if < 0<sizeof...(Types)>::type Foo() {} After: template <typename... Types> typename enable_if<0 < sizeof...(Types)>::type Foo() {} llvm-svn: 187458
* clang-format: Add two new style options to support WebKit style.Daniel Jasper2013-07-261-3/+19
| | | | | | | | | | | | | 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. llvm-svn: 187210
* clang-format: Fix bad line break with pointers to members.Daniel Jasper2013-07-181-1/+1
| | | | | | | | | | | | | | | | | | | Before: void f() { (a->* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)(aaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb); } After: void f() { (a->*aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)( aaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb); } Also add missing test case. llvm-svn: 186583
* clang-format: Add space in corner case.Daniel Jasper2013-07-171-0/+4
| | | | | | | | | Before: SomeType s __attribute__((unused))(InitValue); After: SomeType s __attribute__((unused)) (InitValue); llvm-svn: 186535
* Improve line breaking before multi-line strings.Daniel Jasper2013-07-171-9/+3
| | | | | | | | | | | | | | | | 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"); llvm-svn: 186515
* Don't break line comments with escaped newlines.Alexander Kornienko2013-07-161-2/+3
| | | | | | | | | | | | | | | | | | | | 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 llvm-svn: 186456
OpenPOWER on IntegriCloud