summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/UnwrappedLineParser.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [clang-format] Don't add namespace end comments for unbalanced right braces ↵Krasimir Georgiev2017-03-011-0/+1
| | | | | | after namespace end llvm-svn: 296638
* Fix r296605 so that stuff in #ifndef SWIG blocks is still formatted.Daniel Jasper2017-03-011-1/+2
| | | | llvm-svn: 296608
* clang-format: Ignore contents of #ifdef SWIG .. #endif blocks.Daniel Jasper2017-03-011-6/+6
| | | | | | | | Those blocks are used if C++ code is SWIG-wrapped (see swig.org) and usually do not contain C++ code. Also cleanup the implementation of for #if 0 and #if false a bit. llvm-svn: 296605
* [clang-format] Add a NamespaceEndCommentsFixerKrasimir Georgiev2017-02-271-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch adds a NamespaceEndCommentsFixer TokenAnalyzer for clang-format, which fixes end namespace comments. It currently supports inserting and updating existing wrong comments. Example source: ``` namespace A { int i; } namespace B { int j; } // namespace A ``` after formatting: ``` namespace A { int i; } // namespace A namespace B { int j; } // namespace B ``` Reviewers: klimek, djasper Reviewed By: djasper Subscribers: klimek, mgorny Differential Revision: https://reviews.llvm.org/D30269 llvm-svn: 296341
* clang-format: Fix many Objective-C formatting regressions from r289428Nico Weber2017-02-241-4/+3
| | | | | | | | | | | | | | | 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] Break before a sequence of line comments aligned with the ↵Krasimir Georgiev2017-02-081-12/+67
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | next line. Summary: Make the comment alignment respect sections of line comments originally alinged with the next token. Until now the decision how to break a continuous sequence of line comments into sections was taken without reference to the next token. source: ``` class A { public: // comment about public // comment about a int a; } ``` format before: ``` class A { public: // comment about public // comment about a int a; } ``` format after: ``` class A { public: // comment about public // comment about a int a; } ``` Reviewers: djasper, klimek Reviewed By: klimek Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29626 llvm-svn: 294435
* clang-format: [JS] correcly format object literal methods.Martin Probst2017-02-071-8/+17
| | | | | | | | | | | | | | | | | | | | | Summary: In JavaScript, object literals can contain methods: var x = { a() { return 1; }, }; Previously, clang-format always parsed nested {} inside a braced list as further braced lists. Special case this logic for JavaScript to try parsing as a braced list, but fall back to parsing as a child block. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D29656 llvm-svn: 294315
* clang-format: [JS] handle parenthesized class expressions.Martin Probst2017-02-071-5/+15
| | | | | | | | | | | | | | | | | | | | Summary: In JavaScript, classes are expressions, so they can appear e.g. in argument lists. var C = foo(class { bar() { return 1; } }; Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29635 llvm-svn: 294302
* [clang-format] Don't reflow across comment pragmas.Krasimir Georgiev2017-02-021-4/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The comment reflower wasn't taking comment pragmas as reflow stoppers. This patch fixes that. source: ``` // long long long long // IWYU pragma: ``` format with column limit = 20 before: ``` // long long long // long IWYU pragma: ``` format with column limit = 20 after: ``` // long long long // long // IWYU pragma: ``` Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29450 llvm-svn: 293898
* [clang-format] Fix breaking of comment sections in unwrapped lines ↵Krasimir Georgiev2017-02-021-2/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | containing newlines. Summary: The breaking of line comment sections was misaligning the case where the first comment line is on an unwrapped line containing newlines. In this case, the breaking column must be based on the source column of the last token that is preceded by a newline, not on the first token of the unwrapped line. source: ``` enum A { a, // line 1 // line 2 }; ``` format before: ``` enum A { a, // line 1 // line 2 }; ``` format after: ``` enum A { a, // line 1 // line 2 }; ``` Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29444 llvm-svn: 293891
* [clang-format] Fix regression merging comments across newlines.Krasimir Georgiev2017-01-311-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This fixes a regression that causes example: ``` enum A { a, // line a // line b b }; ``` to be formatted as follows: ``` enum A { a, // line a // line b b }; ``` Reviewers: djasper, klimek Reviewed By: klimek Subscribers: cfe-commits, sammccall, djasper, klimek Differential Revision: https://reviews.llvm.org/D29322 llvm-svn: 293624
* [clang-format] Separate line comment sections after a right brace from ↵Krasimir Georgiev2017-01-301-7/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | comment sections in the scope. Summary: The following two comment lines form a single comment section: ``` if (1) { // line 1 // line 2 } ``` This is because the break of a comment section was based on the original column of the first token of the previous line (in this case, the 'if'). This patch splits these two comment lines into different sections by taking into account the original column of the right brace preceding the first line comment where applicable. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29291 llvm-svn: 293539
* [clang-format] Implement comment reflowing.Krasimir Georgiev2017-01-251-3/+53
| | | | | | | | | | | | | | | | | | Summary: This presents a version of the comment reflowing with less mutable state inside the comment breakable token subclasses. The state has been pushed into the driving breakProtrudingToken method. For this, the API of BreakableToken is enriched by the methods getSplitBefore and getLineLengthAfterSplitBefore. Reviewers: klimek Reviewed By: klimek Subscribers: djasper, klimek, mgorny, cfe-commits, ioeric Differential Revision: https://reviews.llvm.org/D28764 llvm-svn: 293055
* clang-format: [JS] revert over-eager ASI check.Martin Probst2017-01-161-2/+1
| | | | | | | | | | | | Summary: Change r291428 introduced ASI detection after closing curly braces. That would generally be correct, however this breaks indentation for structural statements. What happens is that CompoundStatementIndenter increases indentation for the current line, then after reading ASI creates a new line (with the increased line level), and only after the structural parser sees e.g. the if/then/else branch closed, line level is reduced. That leads to the new line started by ASI having a level too high. Reviewers: djasper Subscribers: sammccall, cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D28763 llvm-svn: 292099
* clang-format: [JS] ASI after importsMartin Probst2017-01-091-5/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Automatic semicolon insertion should break import and export statements: Before, this would format on one line: // Note: no semi after 'x' below! import {x} from 'x' export function foo() {} Into: import {x} from 'x' export function foo() {} With this change, the statements get separated. This also improves automatic semicolon insertion to consider closing braces preceding declarations and statements. Reviewers: klimek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D28465 llvm-svn: 291428
* clang-format: [JS] avoid indent after ambient function declarations.Martin Probst2017-01-041-1/+4
| | | | | | | | | | | | | | | | | | | | | Summary: Before: declare function foo(); let x = 1; After: declare function foo(); let x = 1; The problem was that clang-format would unconditionally try to parse a child block, even though ambient function declarations do not have a body (similar to forward declarations). Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D28246 llvm-svn: 290959
* clang-format: Improve braced-list detection.Daniel Jasper2016-12-131-2/+2
| | | | | | | | | | | Before: vector<int> v { 12 } GUARDED_BY(mutex); After: vector<int> v{12} GUARDED_BY(mutex); llvm-svn: 289525
* clang-format: [JS] do not break after declare namespace.Martin Probst2016-11-101-8/+8
| | | | | | | | | | | | | | | | | Summary: See TypeScript grammar for tokens following 'declare': https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#A.10 Additional minor change: clang-format: [JS] Prevent ASI before const. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D26274 llvm-svn: 286468
* clang-format: [JS] Fix formatting of generator functions.Daniel Jasper2016-11-011-2/+4
| | | | | | | | | | | | | | | | | | | Before: var x = { a: function* () { // } } After: var x = { a: function*() { // } } llvm-svn: 285670
* clang-format: [JS] Fix template string ASI.Martin Probst2016-10-211-3/+8
| | | | | | | | | | | | | | | | | | | Summary: Previously, automatic semicolon insertion would add an unwrapped line when a template string contained a line break. var x = `foo${ bar}`; Would be formatted with `bar...` on a separate line and no indent. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D25675 llvm-svn: 284807
* clang-format: [JS] ASI insertion after boolean literals.Martin Probst2016-09-181-1/+3
| | | | | | | | | | | | | | | | | | | | | Summary: Before when a semicolon was missing after a boolean literal: a = true return 1; clang-format would parse this as one line and format as: a = true return 1; It turns out that C++ does not consider `true` and `false` to be literals, we have to check for that explicitly. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D24574 llvm-svn: 281856
* clang-format: [JS] handle object literals with casts.Martin Probst2016-08-191-1/+2
| | | | | | | | | | | | Summary: E.g. `{a: 1} as b`. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D23714 llvm-svn: 279250
* clang-format: Fix incorrect detection of QT-signals access specifier.Daniel Jasper2016-07-271-1/+1
| | | | | | | | | | | | | | | | | Before: void f() { label: signals .baz(); } After: void f() { label: signals.baz(); } llvm-svn: 276854
* clang-format: [Proto] Fix "import public" after r273179.Daniel Jasper2016-06-201-0/+2
| | | | llvm-svn: 273196
* clang-format: [Proto] Don't do bad things if imports are missing ;.Daniel Jasper2016-06-201-4/+15
| | | | llvm-svn: 273179
* clang-format: [JS] no ASI on `import {x as\n y}`.Martin Probst2016-06-011-5/+5
| | | | | | | | | | | | Summary: ASI did not handle the ES6 `as` operator correctly. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D20817 llvm-svn: 271401
* clang-format: [JS] fix async parsing.Martin Probst2016-05-291-4/+9
| | | | | | | | | | | | | | Summary: Only treat the sequence `async function` as the start of a function expression, as opposed to every occurrence of the token `async` (whoops). Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D20737 llvm-svn: 271184
* clang-format: Fix incorrect indentation in last line of macro definitionDaniel Jasper2016-05-191-0/+2
| | | | | | | | | | | | | | | | | | Before: #define MACRO(a) \ if (a) { \ f(); \ } else \ g() After: #define MACRO(a) \ if (a) { \ f(); \ } else \ g() llvm-svn: 270028
* clang-format: Support enum type template arguments.Daniel Jasper2016-05-081-0/+7
| | | | | | | | | | | | | Before: template <enum E> class A { public : E *f(); }; After: template <enum E> class A { public: E *f(); }; llvm-svn: 268878
* clang-format: [JS] generator and async functions.Martin Probst2016-04-241-8/+23
| | | | | | | | | | | | | | | For generators, see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_generators async functions are not quite in the spec yet, but stage 3 and already widely used: http://tc39.github.io/ecmascript-asyncawait/ Reviewers: djasper Subscribers: klimek Differential Revision: http://reviews.llvm.org/D19204 llvm-svn: 267368
* reuse mustBeJSIdent for interface detectionMartin Probst2016-04-191-7/+8
| | | | llvm-svn: 266790
* clang-format: [JS] support `interface` as a free standing identifier.Martin Probst2016-04-191-0/+15
| | | | | | | | | | | | | | | Summary: `interface` can be used as a fee standing identifier in JavaScript/TypeScript. This change uses the heuristic of whether it's followed by another identifier as an indication. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D19240 llvm-svn: 266789
* clang-format: [JS] simplify import/export.Martin Probst2016-04-191-9/+9
| | | | | | | | | | | | | | | | | | | Summary: Change `import` and `export` parsing to special case the renaming syntax (`import x, {y as bar} ...`, `export {x}`) and otherwise just parse a regular structural element. This simplifies the code a bit and should be more correct - it's easier to recognise the specific import syntax than to recognise arbitrary expressions and declarations. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D19242 llvm-svn: 266743
* clang-format: Last line in incomplete block is indented incorrectlyMarianne Mailhot-Sarrasin2016-04-141-0/+3
| | | | | | | | | | Indentation of the last line was reset to the initial indentation of the block when reaching EOF. Patch by Maxime Beaulieu Differential Revision: http://reviews.llvm.org/D19065 llvm-svn: 266321
* [clang-format] Walk backwards from end() instead of forwards from rend().Benjamin Kramer2016-04-111-1/+1
| | | | | | | | This should've been forwards from rbegin(), reverse iterators are just too confusing to be used by mere mortals. Fixes out-of-bounds walks over the list. llvm-svn: 265934
* clang-format: [JS] do not insert semicolons after wrapped annotations.Martin Probst2016-04-111-0/+7
| | | | | | | | | | Reviewers: djasper Subscribers: klimek Differential Revision: http://reviews.llvm.org/D18943 llvm-svn: 265916
* clang-format: Fix label-in-if statement in macros where it is actually used.Daniel Jasper2016-04-061-1/+3
| | | | | | | | | | | | | | | | Before: #define A \ if (a) \ label: \ f() After: #define A \ if (a) \ label: \ f() llvm-svn: 265557
* clang-format: Support labels in brace-less ifs.Daniel Jasper2016-04-061-0/+3
| | | | | | | | | | | | | | | | While I am not personally convinced about the usefulness of this construct, we should break it. Before: if (a) label: f(); After: if (a) label: f(); llvm-svn: 265545
* clang-format: [JS] Handle certain cases of ASI.Daniel Jasper2016-03-141-1/+71
| | | | | | | | | | | | | | Automatic Semicolon Insertion can only be properly handled by parsing source code. However conservatively catching just a few, common situations prevents breaking code during development, which greatly improves usability. JS code should still use semicolons, and ASI code should be flagged by a compiler or linter. Patch by Martin Probst. Thank you. llvm-svn: 263470
* clang-format: [JS] Support destructuring assignments in for loops.Daniel Jasper2016-03-051-0/+2
| | | | | | | | | | | | Before: for (let { a, b } of x) { } After: for (let {a, b} of x) { } llvm-svn: 262776
* clang-format: [JS/TypeScript] Support "enum" as an optional property name, too.Daniel Jasper2016-02-031-1/+2
| | | | | | | | | | | Before: enum?: string []; After: enum?: string[]; llvm-svn: 259628
* clang-format: [JS] Support exporting abstract classes.Daniel Jasper2016-01-121-0/+4
| | | | | | | | | | | Before: export abstract class X {y: number;} (and all sorts of other havoc in more complicated cases). After: export abstract class X { y: number; } llvm-svn: 257451
* clang-format: [JS] Teach clang-format about "export interface".Daniel Jasper2016-01-111-1/+2
| | | | llvm-svn: 257406
* clang-format: [JS] Support semicolons in TypeScript's TypeMemberLists.Daniel Jasper2016-01-091-44/+67
| | | | | | | | | | | | | | Before: var x: { a: string; b: number; } = {}; After: var x: {a: string; b: number;} = {}; llvm-svn: 257255
* clang-format: [JS] Support more ES6 classes.Daniel Jasper2016-01-081-0/+2
| | | | | | | | | | | | | | | Before: foo = class { constructor() {} } ; After: foo = class { constructor() {} }; llvm-svn: 257154
* clang-format: [JS] Support more ES6 imports.Daniel Jasper2016-01-071-8/+7
| | | | | | | | | | | Before: import a, {X, Y} from 'some/module.js'; After: import a, {X, Y} from 'some/module.js'; llvm-svn: 257038
* clang-format: [JS/TypeScript] Support "enum" as property name.Daniel Jasper2015-12-291-7/+16
| | | | | | | | | | | Before: enum: string []; After: enum: string[]; llvm-svn: 256546
* clang-format: [TableGen] Support ;-less include lines.Daniel Jasper2015-12-251-1/+9
| | | | llvm-svn: 256412
* clang-format: [JS] Support arrays of object-type literals.Daniel Jasper2015-12-221-1/+1
| | | | | | | | | | | | | | | Before: interface I { o: {} []; } After: interface I { o: {}[]; } llvm-svn: 256247
* clang-format: Properly set the BlockKind for more blocks.Daniel Jasper2015-12-211-1/+3
| | | | | | | | | | | | | | | Before: void f() { struct Dummy { }; f(); } After: void f() { struct Dummy {}; f(); } llvm-svn: 256175
OpenPOWER on IntegriCloud