summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/TokenAnnotator.cpp
Commit message (Collapse)AuthorAgeFilesLines
* clang-format: Support configurable list of foreach-macros.Daniel Jasper2014-04-011-3/+11
| | | | | | | | This fixes llvm.org/PR17242. Patch by Brian Green, thank you! llvm-svn: 205307
* Get rid of the adapted isLiteral method.Manuel Klimek2014-03-281-3/+6
| | | | | | We don't want to deviate from clang's standard terminology. llvm-svn: 204997
* Improve handling of bool expressions in template arguments.Manuel Klimek2014-03-271-3/+7
| | | | | | | Now correctly formats: foo<true && false>(); llvm-svn: 204950
* Fix bool expression special case.Manuel Klimek2014-03-271-4/+17
| | | | | | | | Clang-format now correctly formats: some_type<a * b> v; template <bool a, bool b> typename enabled_if<a && b>::type f() {} llvm-svn: 204913
* clang-format: Correctly identify ObjC Block with return type.Daniel Jasper2014-03-271-4/+6
| | | | llvm-svn: 204905
* clang-format: Fix incorrect &/* detection.Daniel Jasper2014-03-251-2/+4
| | | | | | | | | | Before: STATIC_ASSERT((a &b) == 0); After: STATIC_ASSERT((a & b) == 0); llvm-svn: 204709
* clang-format: Let a trailing comma in braced lists enforce linebreaks.Daniel Jasper2014-03-211-0/+8
| | | | | | | | | | | | | | Before: vector<int> x{1, 2, 3, 4, }; After: vector<int> x{ 1, 2, 3, 4, }; This fixes llvm.org/PR18519. llvm-svn: 204458
* clang-format: Fix for r204456.Daniel Jasper2014-03-211-1/+1
| | | | llvm-svn: 204457
* clang-format: Preserve meaning of trailing comments on parameters.Daniel Jasper2014-03-211-0/+21
| | | | | | | | | | | | | | | | | | Formatting: SomeFunction(a, b, // comment c); Before: SomeFunction(a, b, // comment c); After: SomeFunction(a, b, // comment c); llvm-svn: 204456
* Fix crasher bug.Manuel Klimek2014-03-181-13/+18
| | | | | | | | | | | | | | | Due to not resetting the fake rparen data on the token when iterating over annotated lines, we would pop the last element of the paren stack. This patch fixes the underlying root cause, and makes the code more robust against similar problems in the future: - reset the first token when iterating on the same annotated lines due to preprocessor branches - never pop the last element from the paren stack, so we do not crash, but rather incorrectly format - add assert()s so we can figure out if our assumptions are violated llvm-svn: 204140
* clang-format: Detect weird macro lambda usage.Daniel Jasper2014-03-111-1/+5
| | | | | | | | | | | | | | Before: void f() { MACRO((const AA & a) { return 1; }); } After: void f() { MACRO((const AA &a) { return 1; }); } llvm-svn: 203551
* clang-format: Add spaces between lambdas and comments.Daniel Jasper2014-03-101-1/+2
| | | | | | | | | | | | | | | | | | Before: void f() { bar([]() {}// Does not respect SpacesBeforeTrailingComments ); } After: void f() { bar([]() {} // Does not respect SpacesBeforeTrailingComments ); } This fixes llvm.org/PR19017. llvm-svn: 203466
* clang-format: Add spaces around trailing/lambda return types.Daniel Jasper2014-03-101-1/+2
| | | | | | | | | | Before: int c = []()->int { return 2; }(); After: int c = []() -> int { return 2; }(); llvm-svn: 203452
* clang-format: Don't wrap "const" etc. of function declarations.Daniel Jasper2014-02-171-2/+8
| | | | | | | | | | | | | | | | | Generally people seem to prefer wrapping the first function parameter over wrapping the trailing tokens "const", "override" and "final". This does not extend to function-like annotations and probably not to other non-standard annotations. Before: void someLongFunction(int SomeLongParameter) const { ... } After: void someLongFunction( int SomeLongParameter) const { ... } llvm-svn: 201504
* clang-format: Fix formatting of class template declaration.Daniel Jasper2014-02-141-0/+2
| | | | | | | | | | | | | | Before: template <class R, class C> struct Aaaaaaaaaaaaaaaaa<R (C::*)(int) const> : Aaaaaaaaaaaaaaaaa<R (C::*)(int)> {}; After: template <class R, class C> struct Aaaaaaaaaaaaaaaaa<R (C::*)(int) const> : Aaaaaaaaaaaaaaaaa<R (C::*)(int)> {}; llvm-svn: 201424
* clang-format: Fix range-based for-loop formatting.Daniel Jasper2014-02-071-0/+2
| | | | | | | | | | | | | | | Before: for (aaaaaaaaa aaaaaaaaaaaaaaaaaaaaa : aaaaaaaaaaaa.aaaaaaaaaaaa() .aaaaaaaaa() .a()) { } After: for (aaaaaaaaa aaaaaaaaaaaaaaaaaaaaa : aaaaaaaaaaaa.aaaaaaaaaaaa().aaaaaaaaa().a()) { } llvm-svn: 200968
* clang-format: More custom option fixes for protocol buffer files.Daniel Jasper2014-01-291-1/+2
| | | | | | | | | | | | | | | Before: repeated double value = 1 [(aaaaaaa.aaaaaaaaa) = { aaaaaaaaaaaaaaaa : AAAAAAAAAA, bbbbbbbbbbbbbbbb : BBBBBBBBBB }]; After: repeated double value = 1 [(aaaaaaa.aaaaaaaaa) = {aaaaaaaaaaaaaaaa : AAAAAAAAAA, bbbbbbbbbbbbbbbb : BBBBBBBBBB}]; llvm-svn: 200406
* clang-format: Fix formatting of custom proto options.Daniel Jasper2014-01-291-1/+1
| | | | | | | | | | | | | Before: repeated double value = 1 [(aaaaaaa.aaaaaaaaa) = { aaaaaaaaaaaaaaaaa : AAAAAAAA }]; After: repeated double value = 1 [(aaaaaaa.aaaaaaaaa) = {aaaaaaaaaaaaaaaaa : AAAAAAAA}]; llvm-svn: 200405
* clang-format: Understand __attribute__s preceding parameter lists.Daniel Jasper2014-01-281-12/+13
| | | | | | | | | | | | | | Before: ReturnType __attribute__((unused)) function(int i); After: ReturnType __attribute__((unused)) function(int i); This fixes llvm.org/PR18632. llvm-svn: 200337
* clang-format: Fix option formatting in protocol buffer files.Daniel Jasper2014-01-281-0/+1
| | | | | | | | | | Before: optional int32 foo[ default = true, deprecated = true ]; After: optional int32 foo[default = true, deprecated = true]; llvm-svn: 200327
* clang-format: Add support for a space after @propertyDaniel Jasper2014-01-281-0/+3
| | | | | | | | | Mozilla and WebKit seem to use a space after @property (verified by grepping their codebases) so we turn this on there as well. Change by Christian Legnitto. Thank you! llvm-svn: 200320
* clang-format: Fix incorrect space removal.Daniel Jasper2014-01-251-1/+1
| | | | | | | | | | | | Before: Deleted &operator=(const Deleted &)&= default; Deleted &operator=(const Deleted &)&&= delete; After: Deleted &operator=(const Deleted &)& = default; Deleted &operator=(const Deleted &)&& = delete; llvm-svn: 200073
* clang-format: Treat "." in protos like namespace separators.Daniel Jasper2014-01-221-1/+2
| | | | | | | | | | | | | Before: optional really.really.long.and.qualified.type.aaaaaaa .aaaaaaaa another_fiiiiiiiiiiiiiiiiiiiiield = 2; After: optional really.really.long.and.qualified.type.aaaaaaa.aaaaaaaa another_fiiiiiiiiiiiiiiiiiiiiield = 2; llvm-svn: 199796
* clang-format: text following #if is likely an expression.Daniel Jasper2014-01-211-1/+2
| | | | | | | | | | Before: #if AAAA &&BBBB After: #if AAAA && BBBB llvm-svn: 199713
* clang-format: Properly format custom options in protocol buffer definitions.Daniel Jasper2014-01-201-1/+2
| | | | | | | | | | Before: option(my_option) = "abc"; After: option (my_option) = "abc"; llvm-svn: 199672
* clang-format: Better support and testing for protocol buffers.Daniel Jasper2014-01-191-3/+14
| | | | | | | | | With this patch, there is dedicated testing for protocol buffers (https://developers.google.com/protocol-buffers/). Also some minor tweaks formatting tweaks. llvm-svn: 199580
* clang-format: Fix ObjC block as first call parameter formatting.Daniel Jasper2014-01-191-0/+2
| | | | | | | | | Before: foo (^{ bar(); }); After: foo(^{ bar(); }); llvm-svn: 199573
* clang-format: Don't break lines starting with "import <string-literal>"Daniel Jasper2014-01-171-0/+9
| | | | | | | | | The author might be missing the "#" or these might be protocol buffer definitions. Either way, we should not break the line or the string. There don't seem to be other valid use cases. llvm-svn: 199501
* clang-format: Improve formatting of ObjC Blocks with return type.Daniel Jasper2014-01-161-4/+10
| | | | | | | | | | Before: int a = [operation block:^int(int * i) { return 1; }]; After: int a = [operation block:^int(int *i) { return 1; }]; llvm-svn: 199411
* clang-format: Enable formatting of lambdas with explicit return type.Daniel Jasper2014-01-161-32/+2
| | | | | | | | | So clang-format can now format: int c = []()->int { return 2; }(); int c = []()->vector<int> { return { 2 }; }(); llvm-svn: 199368
* clang-format: Fixed formatting of JavaScript container literalsDaniel Jasper2014-01-151-5/+4
| | | | | | | | | | | | Before: var arr = [ 1, 2, 3 ]; var obj = {a : 1, b : 2, c : 3}; After: var arr = [1, 2, 3]; var obj = {a: 1, b: 2, c: 3}; llvm-svn: 199317
* clang-format: Fix corner case with comment in ctor initializer.Daniel Jasper2014-01-131-0/+1
| | | | | | | | | | | | | | | | | | | | Formatting: Constructor() : // Comment forcing unwanted break. aaaa(aaaa) {} Before: Constructor() : // Comment forcing unwanted break. aaaa(aaaa) {} After: Constructor() : // Comment forcing unwanted break. aaaa(aaaa) {} llvm-svn: 199107
* clang-format: Slightly adapt line break in edge case.Daniel Jasper2014-01-101-1/+1
| | | | | | | | | | | | | | | Before: SomeMap[std::pair(aaaaaaaaaaaa, bbbbbbbbbbbbbbb)] .insert(ccccccccccccccccccccccc); After: SomeMap[std::pair(aaaaaaaaaaaa, bbbbbbbbbbbbbbb)].insert( ccccccccccccccccccccccc); This seems to be about 3:1 more common in Google and Chromium style and I found only a handful of instances inside the LLVM codebase. llvm-svn: 198924
* clang-format: Understand ObjC boxed expressions.Daniel Jasper2014-01-101-0/+1
| | | | | | | | | Before: [dictionary setObject:@(1)forKey:@"number"]; After: [dictionary setObject:@(1) forKey:@"number"]; llvm-svn: 198920
* clang-format: Understand #pragma markDaniel Jasper2014-01-091-0/+15
| | | | | | | | | Before: #pragma mark Any non - hyphenated or hyphenated string(including parentheses). After: #pragma mark Any non-hyphenated or hyphenated string (including parentheses). llvm-svn: 198870
* clang-format: Fix spacing in Cpp11 braced lists:Daniel Jasper2014-01-081-1/+1
| | | | | | | | | | Before: vector<int> foo{ ::SomeFunction()}; After: vector<int> foo{::SomeFunction()}; llvm-svn: 198769
* clang-format: Spacing inside enum braces.Daniel Jasper2014-01-051-1/+3
| | | | | | | | | | Before (in Google style): enum ShortEnum {A, B, C}; After: enum ShortEnum { A, B, C }; llvm-svn: 198559
* clang-format: Allow formatting short enums on a single line.Daniel Jasper2014-01-051-3/+0
| | | | | | | | | | | | | | | | | Before: enum ShortEnum { A, B, C }; After: enum ShortEnum { A, B, C }; This seems to be the predominant choice in LLVM/Clang as well as in Google style. llvm-svn: 198558
* clang-format: Break default arguments less eagerly.Daniel Jasper2013-12-271-0/+2
| | | | | | | | | | | | Before: void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaa = 1); After: void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( int aaaaaaaaaaaaaaaaaaaaaaaaaaaa = 1); llvm-svn: 198070
* clang-format: Fix various problems in formatting ObjC blocks.Daniel Jasper2013-12-231-9/+22
| | | | | | Among other things, this fixes llvm.org/PR15269. llvm-svn: 197900
* clang-format: Better support for multi-line wide string literals.Daniel Jasper2013-12-201-2/+1
| | | | | | | | | | | Before: SomeFunction(L"A" L"B"); After: SomeFunction(L"A" L"B"); llvm-svn: 197785
* clang-format: Add special case for leading comments in braced lists.Daniel Jasper2013-12-191-6/+14
| | | | | | | | | | | | | | | | | | | A comment following the "{" of a braced list seems to almost always refer to the first element of the list and thus should be aligned to it. Before (with Cpp11 braced list style): SomeFunction({ // Comment 1 "first entry", // Comment 2 "second entry"}); After: SomeFunction({// Comment 1 "first entry", // Comment 2 "second entry"}); llvm-svn: 197725
* clang-format: Fix ObjC method expr in binary expressions.Daniel Jasper2013-12-181-1/+1
| | | | | | | | | | | | | | Before: bool a = ([aaaaaaaa aaaaa] == aaaaaaaaaaaaaaaaa || [aaaaaaaa aaaaa] == aaaaaaaaaaaaaaaaaaaa); After: bool a = ([aaaaaaaa aaaaa] == aaaaaaaaaaaaaaaaa || [aaaaaaaa aaaaa] == aaaaaaaaaaaaaaaaaaaa); This fixes llvm.org/PR18271. llvm-svn: 197552
* clang-format: Keep trailing annotations together.Daniel Jasper2013-12-161-6/+13
| | | | | | | | | | | | | | | | Before: virtual void aaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaa aaaa, aaaaaaaaaaa aaaaa) const override; virtual void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() const override; After: virtual void aaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaa aaaa, aaaaaaaaaaa aaaaa) const override; virtual void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() const override; llvm-svn: 197391
* Always break before the colon in constructor initializers, whenAlexander Kornienko2013-12-161-1/+2
| | | | | | | | | | | BreakConstructorInitializersBeforeComma is true. This option is used in WebKit style, so this also ensures initializer lists are not put on a single line, as per the WebKit coding guidelines. Patch by Florian Sowade! llvm-svn: 197386
* clang-format: Fix formatting of function type parameters.Daniel Jasper2013-12-161-5/+10
| | | | | | | | | Before: void f() { typedef void (*f)(int * a); } After: void f() { typedef void (*f)(int *a); } llvm-svn: 197369
* clang-format: Improve handling of raw string literals.Daniel Jasper2013-12-161-0/+6
| | | | | | | | | | | | | | | | Especially try to keep existing line breaks before raw string literals, as the code author might have aligned content to it. Thereby, clang-format now keeps things like: parseStyle(R"( BasedOnStyle: Google, ColumnLimit: 100)"); parseStyle( R"(BasedOnStyle: Google, ColumnLimit: 100)"); llvm-svn: 197368
* Implemented GNU-style formatting for compound statements.Alexander Kornienko2013-12-121-1/+2
| | | | | | | | | | | | | | | | Summary: Added BraceBreakingStyle::BS_GNU. I'm not sure about the correctness of static initializer formatting, but compound statements should be fine. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2372 llvm-svn: 197138
* Support GNU style rule to put a space before opening parenthesis.Alexander Kornienko2013-12-101-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The rule from the GNU style states: "We find it easier to read a program when it has spaces before the open-parentheses and after the commas." http://www.gnu.org/prep/standards/standards.html#index-spaces-before-open_002dparen This patch makes clang-format adds an option to put spaces before almost all open parentheses, except the cases, where different behavior is dictated by the style rules or language syntax: * preprocessor: ** function-like macro definitions can't have a space between the macro name and the parenthesis; ** `#if defined(...)` can have a space, but it seems, that it's more frequently used without a space in GCC, for example; * never add spaces after unary operators; * adding spaces between two opening parentheses is controlled with the `SpacesInParentheses` option; * never add spaces between `[` and `(` (there's no option yet). Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2326 llvm-svn: 196901
* clang-format: Be more conservative about braced list column layout.Daniel Jasper2013-12-091-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | Specifically disable it for nested braced lists as it commonly can look really weird. Eventually, we'll want to become smarter and format some of the nested lists better. Before: SomeStruct my_struct_array = { { aaaaaa, aaaaaaaa, aaaaaaaaaa, aaaaaaaaa, aaaaaaaaa, aaaaaaaaaa, aaaaaaaaaa, aaaaaaa, aaa }, { aaaa, aaaa, aaaa, aaaa, aaaa, aaaa, aaaa, aaa }, { aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaa, a, aaaaaaaaaa, aaaaaaaaa, aaa }, }; After: SomeStruct my_struct_array = { { aaaaaa, aaaaaaaa, aaaaaaaaaa, aaaaaaaaa, aaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaaa, aaaaaaa, aaa }, { aaaa, aaaa, aaaa, aaaa, aaaa, aaaa, aaaa, aaa }, { aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaa, a, aaaaaaaaaa, aaaaaaaaa, aaa }, }; llvm-svn: 196783
OpenPOWER on IntegriCloud