summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/TokenAnnotator.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* clang-format: [JS] consistenly format enums.Martin Probst2017-08-011-1/+3
| | | | | | | | | | | | Summary: Previously, const enums would get formatted differently because the modifier was not recognized. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D36144 llvm-svn: 309703
* clang-format: [JS] handle object types in extends positions.Martin Probst2017-08-011-1/+2
| | | | | | | | | | | | | | | | | Summary: clang-format would previously drop the whitespace after `extends` in code such as: class Foo extends {} {} Where the first set of curly braces is an inline object literal type. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D36131 llvm-svn: 309695
* [clang-format] Fix comment levels between '} else {' and PPDirective.Krasimir Georgiev2017-07-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This fixes a regression exposed by r307795 and rL308725 in which the level of a comment line between '} else {' and a preprocessor directive is incorrectly set as the level of the '} else {' line. For example, this : ``` int f(int i) { if (i) { ++i; } else { // comment #ifdef A --i; #endif } } ``` was formatted as: ``` int f(int i) { if (i) { ++i; } else { // comment #ifdef A --i; #endif } } ``` Reviewers: djasper, klimek Reviewed By: klimek Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D35794 llvm-svn: 308882
* Fix dereference of pointers in throw statements.Manuel Klimek2017-07-171-1/+2
| | | | | | | | | | | | Before: throw * x; After: throw *x; Patch by Erik Uhlmann. llvm-svn: 308185
* [clang-format] Keep level of comment before an empty lineKrasimir Georgiev2017-07-121-4/+13
| | | | | | | | | | | | | | | | | Summary: This patch fixes bug https://bugs.llvm.org/show_bug.cgi?id=3313: a comment line was aligned with the next #ifdef even in the presence of an empty line between them. Reviewers: djasper, klimek Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D35296 llvm-svn: 307795
* clang-format: [JS] do not wrap after "readonly".Martin Probst2017-07-071-5/+6
| | | | | | | | | | | | | | Summary: Breaks after "readonly" trigger automatic semicolon insertion in field declarations. Reviewers: krasimir, djasper Subscribers: klimek Differential Revision: https://reviews.llvm.org/D35112 llvm-svn: 307394
* [clang-format] Add space between a message field key and the opening bracket ↵Krasimir Georgiev2017-07-061-0/+2
| | | | | | | | | | | | | | | | | | in proto messages Summary: This patch updates the formatting of message fields of type `a{...}` to `a {...}` for proto messages. Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D35015 llvm-svn: 307261
* clang-format: [JS] space between pseudo keywords and template literals.Martin Probst2017-07-041-1/+5
| | | | | | | | | | | | | | | | | | | | Summary: Before: yield`foo`; After: yield `foo`; This reinstates commit 71d3b5cd91 / r307023 and fixes the logic by introducing an explicit table of JavaScript pseudo keywords. Reviewers: djasper Subscribers: klimek Differential Revision: https://reviews.llvm.org/D34953 llvm-svn: 307087
* Revert "clang-format: [JS] space between pseudo keywords and template literals."Martin Probst2017-07-031-5/+1
| | | | | | This reverts commit 71d3b5cd916106005ef23467e3f6c7fbca7bc499. llvm-svn: 307034
* [clang-format] Support text proto messagesKrasimir Georgiev2017-07-031-5/+24
| | | | | | | | | | | | | | Summary: This patch adds support for textual protocol buffer messages. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek, mgorny Differential Revision: https://reviews.llvm.org/D34441 llvm-svn: 307029
* clang-format: [JS] space between pseudo keywords and template literals.Martin Probst2017-07-031-1/+5
| | | | | | | | | | | | | | | | | Summary: Before: yield`foo`; After: yield `foo`; Reviewers: djasper Subscribers: klimek Differential Revision: https://reviews.llvm.org/D34938 llvm-svn: 307023
* [clang-format] Fix parsing of msg{field}-style proto optionsKrasimir Georgiev2017-06-291-2/+4
| | | | | | | | | | | | | | | | | | | | | | | Summary: This patch makes the `{` in `msg_field{field: OK}` in a proto option scope be treated as an assignment operator. Previosly the added test case was formatted as: ``` option (MyProto.options) = { field_a: OK field_b{field_c: OK} field_d: OKOKOK field_e: OK } ``` Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D34749 llvm-svn: 306672
* [clang-format] Support <>-style proto message fieldsKrasimir Georgiev2017-06-271-5/+20
| | | | | | | | | | | | | | | | | Summary: This patch adds support for <>-style proto message fields inside proto options. Previously these were wrongly treated as binary operators and as such were working only by chance for a limited number of cases. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D34621 llvm-svn: 306406
* clang-format: introduce InlineOnly short function styleFrancois Ferrand2017-06-211-2/+2
| | | | | | | | | | | | | | | | | | | Summary: This is the same as Inline, except it does not imply all empty functions are merged: with this style, empty functions are merged only if they also match the 'inline' criteria (i.e. defined in a class). This is helpful to avoid inlining functions in implementations files. Reviewers: djasper, krasimir Reviewed By: djasper Subscribers: klimek, rengolin, cfe-commits Differential Revision: https://reviews.llvm.org/D34399 llvm-svn: 305912
* clang-format: Fix C99 designated initializers corner casesFrancois Ferrand2017-06-191-5/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This fixes the missing space before the designated initializer when `Cpp11BracedListStyle=false` : const struct A a = { .a = 1, .b = 2 }; ^ Also, wrapping between opening brace and designated array initializers used to have an excessive penalty (like breaking between an expression and the subscript operator), leading to unexpected wrapping: const struct Aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaa = {[1] = aaaaaaaaaaaaaaaaaaaaaaaaaaa, [2] = bbbbbbbbbbbbbbbbbbbbbbbbbbb}; instead of: const struct Aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaa = { [1] = aaaaaaaaaaaaaaaaaaaaaaaaaaa, [2] = bbbbbbbbbbbbbbbbbbbbbbbbbbb}; Finally, designated array initializers are not binpacked, just like designated member initializers. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, krasimir, klimek Differential Revision: https://reviews.llvm.org/D33491 llvm-svn: 305696
* clang-format: Handle "if constexpr".Daniel Jasper2017-06-191-1/+6
| | | | | | | | | | | | | | | | | | | | c++1z adds the following constructions to the language: if constexpr (cond) statement1; else if constexpr (cond) statement2; else if constexpr (cond) statement3; else statement4; A first version of this was proposed in reviews.llvm.org/D26953 by Francis Visoiu Mistrih, but never commited. This patch additionally fixes the behavior when allowing short if statements on a single line and was authored by Jacob Bandes-Storch. Thank you to both authors. llvm-svn: 305666
* clang-format: [JS] recognize exported type definitions.Martin Probst2017-06-071-3/+9
| | | | | | | | | | Summary: Support "export type T = {...};", in addition to just "type T = {...};". Reviewers: klimek Differential Revision: https://reviews.llvm.org/D33980 llvm-svn: 304904
* clang-format: Introduce BreakConstructorInitializers optionFrancois Ferrand2017-05-241-6/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This option replaces the BreakConstructorInitializersBeforeComma option with an enum, thus introducing a mode where the colon stays on the same line as constructor declaration: // When it fits on line: Constructor() : initializer1(), initializer2() {} // When it does not fit: Constructor() : initializer1(), initializer2() {} // When ConstructorInitializerAllOnOneLineOrOnePerLine = true: Constructor() : initializer1(), initializer2() {} Reviewers: krasimir, djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D32479 llvm-svn: 303739
* clang-format: [JS] avoid line breaks before unindented r_parens.Martin Probst2017-05-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The change that enabled wrapping at the previous scope's indentation had unintended side-effects in that clang-format would prefer to wrap closing parentheses to the next line if it avoided a wrap on the next line (assuming very narrow lines): fooObject .someCall(barbazbam) .then(bam); Would get formatted as: fooObject.someCall(barbazbam ).then(bam); Because the ')' is now indented at the parent level (fooObject). Normally formatting a builder pattern style call sequence like that is outlawed in clang-format anyway. However for JavaScript this is special cased to support trailing .bind calls. This change disallows this special case when following a closing ')' to avoid the problem. Included are some random comment fixes. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D33399 llvm-svn: 303557
* clang-format: Allow customizing the penalty for breaking assignmentFrancois Ferrand2017-05-221-3/+4
| | | | | | | | | | | | | | | | | | | | | Summary: Add option to customize the penalty for breaking assignment This allows increasing the priority of the assignment, to prefer spliting an operation instead of splitting the assignment, e.g. : int a = bbbbbbbbbbbbbbbb + cccccccccccccccc; Reviewers: krasimir, djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D32477 llvm-svn: 303534
* [Format] Add curly braces to suppress a -Wmisleading-indentation warning ↵Craig Topper2017-05-211-1/+2
| | | | | | from gcc. llvm-svn: 303501
* [clang-format] Handle trailing comment sections in import statement linesKrasimir Georgiev2017-05-191-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch updates the handling of multiline trailing comment sections in import statement lines to make it more consistent with the case in general. This includes updating the parsing logic to collect the trailing comment sections and the formatting logic to not insert escaped newlines at the end of comment lines in import statement lines. Specifically, before this patch this code: ``` #include <a> // line 1 // line 2 ``` will be turned into two unwrapped lines, whereas this code: ``` int i; // line 1 // line 2 ``` is turned into a single unwrapped line, enabling reflowing across comments. An example where the old behaviour is bad is when partially formatting the lines 3 to 4 of this code: ``` #include <a> // line 1 // line 2 int i; ``` which gets turned into: ``` #include <a> // line 1 // line 2 int i; ``` because the two comment lines were independent and the indent was copied. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D33351 llvm-svn: 303415
* clang-format: [JS] for await, and fix a crash with for loops.Martin Probst2017-05-181-4/+4
| | | | | | | | | | | | | | Summary: The syntax is actually `for await (const x of y)` (d'oh). This also fixes a crash for `for` tokens not followed by additional tokens. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D33329 llvm-svn: 303382
* [clang-format] Make NoLineBreakFormatter respect MustBreakBeforeKrasimir Georgiev2017-05-181-16/+19
| | | | | | | | | | | | | | | | Summary: This patch makes NoLineBreakFormatter to insert a break before tokens where MustBreakBefore is true. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D33238 llvm-svn: 303332
* clang-format: [JS] for async loops.Martin Probst2017-05-151-3/+10
| | | | | | | | | | | | | | | Summary: JavaScript supports asynchronous loop iteration in async functions: for async (const x of y) ... Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D33193 llvm-svn: 303106
* JavaScript allows parameter lists to include trailing commas:Martin Probst2017-05-151-6/+10
| | | | | | | | | | | | | | | | | | | myFunction(param1, param2,); For symmetry with other parenthesized lists ([...], {...}), clang-format should wrap parenthesized lists one-per-line if they contain a trailing comma: myFunction( param1, param2, ); This is particularly useful in function declarations or calls with many arguments, e.g. commonly in constructors. Differential Revision: https://reviews.llvm.org/D33023 llvm-svn: 303049
* clang-format: [JS] fix non-null assertion operator recognition.Martin Probst2017-05-151-3/+3
| | | | | | | | | | | | | | | | | Summary: `getIdentifierInfo()` includes all keywords, whereas non-null assertion operators should only be recognized after non-keywords or pseudo keywords. Ideally this should list all tokens that clang-format recognizes as a keyword, but that are pseudo or no keywords in JS. For the time being, just recognize the specific bits users ran into (`namespace` in this case). Reviewers: djasper Subscribers: klimek Differential Revision: https://reviews.llvm.org/D33182 llvm-svn: 303038
* clang-format: [JS] support non-null assertions after all identifiers.Martin Probst2017-05-121-1/+2
| | | | | | | | | | | | | | | | | Summary: Previously: x = namespace !; Now: x = namespace!; Reviewers: djasper Subscribers: klimek Differential Revision: https://reviews.llvm.org/D33113 llvm-svn: 302893
* clang-format: [JS/Java] ignore Objective-C constructs in JS & Java.Martin Probst2017-04-261-1/+5
| | | | | | | | | | | | | | | | | | | | | | | Summary: Java and JavaScript support annotations and decorators, respectively, that use a leading "@" token. clang-format currently detects this as an Objective-C construct and applies special formatting, for example no whitespace around "=" operators. This change disables the distinction for Java and JavaScript, which leads to normal formatting of single line annotated and initialized properties. Before: class X { @foo() bar=false; } After: class X { @foo() bar = false; } Reviewers: djasper, bkramer Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D32532 llvm-svn: 301399
* formattingMartin Probst2017-04-261-7/+5
| | | | llvm-svn: 301398
* clang-format: [JS] prevent wraps before class members.Martin Probst2017-04-261-1/+5
| | | | | | | | | | | | Summary: In JavaScript/TypeScript, class member definitions that use modifiers can be subject to Automatic Semicolon Insertion (ASI). For example, "class X { get \n foo }" defines a property called "get" and a property called "foo", both with no type annotation. This change prevents wrapping after the modifier keywords (visibility modifiers, static, get and set) to prevent accidental ASI. Reviewers: djasper, bkramer Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D32531 llvm-svn: 301397
* clang-format: Properly match parens of macro parameter lists.Daniel Jasper2017-04-191-3/+4
| | | | | | | No tests yet, but this will be tested by the upcoming: https://reviews.llvm.org/D28462 llvm-svn: 300661
* [clang-format] Handle NSString literals by merging tokens.Alexander Kornienko2017-04-111-18/+13
| | | | | | | | | | | | | | | | | | | | Summary: This fixes a few outstanding bugs: * incorrect breaking of NSString literals containing double-width characters; * inconsistent formatting of ObjC dictionary literals containing NSString literals; * AlwaysBreakBeforeMultilineStrings ignoring implicitly-concatenated NSString literals. Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D31706 llvm-svn: 299927
* clang-format: [JS] fix whitespace around "of" operator.Martin Probst2017-04-051-2/+6
| | | | | | | | | | | | | | | | | | | Summary: Previously: import {of } from 'x'; of (null); Now: import {of} from 'x'; of(null); Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D31698 llvm-svn: 299533
* clang-format: Fix post-commit review comment of r299204, use Style.isCpp().Daniel Jasper2017-03-311-5/+5
| | | | | | Also, while at it, s/IsCpp/isCpp/ so that it follows LLVM style. llvm-svn: 299214
* [clang-format] disable adding extra space after MSVC '__super' keywordMartin Probst2017-03-161-1/+1
| | | | | | | | | | | clang-format treats MSVC `__super` keyword like all other keywords adding a single space after. This change disables this behavior for `__super`. Patch originally by jutocz (thanks!). Differential Revision: https://reviews.llvm.org/D30932 llvm-svn: 297936
* clang-format: Make it very slighly more expensive to wrap between "= {".Daniel Jasper2017-03-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | This prevents unwanted fallout from r296664. Specifically in proto formatting, this changed: optional Aaaaaaaa aaaaaaaa = 12 [ (aaa) = aaaa, (bbbbbbbbbbbbbbbbbbbbbbbbbb) = { aaaaaaaaaaaaaaaaa: true, aaaaaaaaaaaaaaaa: true } ]; Into: optional Aaaaaaaa aaaaaaaa = 12 [ (aaa) = aaaa, (bbbbbbbbbbbbbbbbbbbbbbbbbb) = {aaaaaaaaaaaaaaaaa: true, aaaaaaaaaaaaaaaa: true} ]; Which is considered less readable. Generally, it seems preferable to format such dict literals as blocks rather than contract them to one line. llvm-svn: 297696
* clang-format: [JS] allow breaking after non-null assertions.Martin Probst2017-03-131-5/+21
| | | | | | | | | | | | | | | | Summary: Previously clang-format would not break after any !. However in TypeScript, ! can be used as a post fix operator for non-nullability: x.foo()!.bar()!; With this change, clang-format will wrap after the ! if it is likely a post-fix non null operator. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D30705 llvm-svn: 297606
* clang-format: [JS] do not wrap after interface and type.Martin Probst2017-03-131-5/+4
| | | | | | | | | | | | | | | | | | | | | Summary: `interface` and `type` are pseudo keywords and cause automatic semicolon insertion when followed by a line break: interface // gets parsed as a long variable access to "interface" VeryLongInterfaceName { } With this change, clang-format not longer wraps after `interface` or `type`. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D30874 llvm-svn: 297605
* [clang-format] Add option to break before inheritance separation operator in ↵Andi-Bogdan Postelnicu2017-03-101-0/+14
| | | | | | | | class declaration. Differential Revision: https://reviews.llvm.org/D30487 llvm-svn: 297467
* clang-format: Get slightly better at understanding */&.Daniel Jasper2017-03-081-1/+2
| | | | | | | | | | Before: void f() { MACRO(A * const a); } After: void f() { MACRO(A *const a); } llvm-svn: 297268
* [clang-format] Fixed indent issue when adding a comment at the end of a ↵Andi-Bogdan Postelnicu2017-03-071-2/+2
| | | | | | | | return type in named function declaration. Differential Revision: https://reviews.llvm.org/D30646 llvm-svn: 297143
* clang-format: [JS] Properly format object literals with shorthands.Daniel Jasper2017-03-011-3/+4
| | | | | | | | | | | | | | | | | Before: return { a, b: 'b', c, }; After: return { a, b: 'b', c, }; llvm-svn: 296664
* clang-format: [JS/TS] Properly understand cast expressions.Daniel Jasper2017-03-011-2/+5
| | | | | | | | | | Many things were wrong: - We didn't always allow wrapping after "as", which can be necessary. - We used to Undestand the identifier after "as" as a start of a name. - We didn't properly parse the structure of the expression with "as" having the precedence of relational operators llvm-svn: 296659
* clang-format: [Java] Fix bug in enum formatting.Daniel Jasper2017-02-281-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | Before: public enum VeryLongEnum { ENUM_WITH_MANY_PARAMETERS("aaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbb", "ccccccccccccccccccc") , SECOND_ENUM("a", "b", "c"); private VeryLongEnum(String a, String b, String c) {} } After: public enum VeryLongEnum { ENUM_WITH_MANY_PARAMETERS("aaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbb", "ccccccccccccccccccc") , SECOND_ENUM("a", "b", "c"); private VeryLongEnum(String a, String b, String c) {} } llvm-svn: 296499
* clang-format: [JS] whitespace after async in arrow functions.Martin Probst2017-02-271-0/+8
| | | | | | | | | | | | | | | | | | | Summary: Async arrow functions should be marked with a whitespace after the async keyword, before the parameter list: x = async () => foo(); Before: x = async() => foo(); This makes it easier to tell apart an async arrow function from a call to a function called async. Reviewers: bkramer Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D30399 llvm-svn: 296330
* clang-format: Fix many Objective-C formatting regressions from r289428Nico Weber2017-02-241-10/+5
| | | | | | | | | | | | | | | r289428 added a separate language kind for Objective-C, but kept many "Language == LK_Cpp" checks untouched. This introduced a "IsCpp()" method that returns true for both C++ and Objective-C++, and replaces all comparisons of Language with LK_Cpp with calls to this new method. Also add a lot more test coverge for formatting things in LK_ObjC mode, by having FormatTest's verifyFormat() test for LK_ObjC everything that's being tested for LK_Cpp at the moment. Fixes PR32060 and many other things. llvm-svn: 296160
* clang-format: [JS] Improve line-wrapping behavior of template strings.Daniel Jasper2017-02-201-2/+5
| | | | | | | | Specifically, similar to other blocks, clang-format now wraps both after "${" and before the corresponding "}", if the contained expression spans multiple lines. llvm-svn: 295663
* clang-format: [JS/TS] Improve detection for array subscripts in types.Daniel Jasper2017-02-201-0/+3
| | | | | | | | | | | | Before: var someValue = (v as aaaaaaaaaaaaaaaaaaaa<T>[ ]).someFunction(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); After: var someValue = (v as aaaaaaaaaaaaaaaaaaaa<T>[]) .someFunction(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); llvm-svn: 295658
* clang-format: Don't remove existing spaces between identifier and ::.Daniel Jasper2017-02-171-3/+7
| | | | | | | | | | | | | | | | | | | | This can lead to bad behavior with macros that are used to annotate functions (e.g. ALWAYS_INLINE). Before, this: ALWAYS_INLINE ::std::string getName() ... was turned into: ALWAYS_INLINE::std::string getName() ... If it turns out that clang-format is failing to clean up a lot of the existing spaces now, we can add more analyses of the identifier. It should not currently. Cases where clang-format breaks nested name specifiers should be fine as clang-format wraps after the "::". Thus, a line getting longer and then shorter again should lead to the same original code. llvm-svn: 295437
OpenPOWER on IntegriCloud