summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/TokenAnnotator.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* clang-format: don't break code using __has_include, PR31908Nico Weber2017-02-101-1/+21
| | | | llvm-svn: 294772
* clang-format: Fix bad variable declaration detection.Daniel Jasper2017-02-071-1/+5
| | | | | | | | | | | | Before: LooooooooooooooooongType variable(nullptr, [](A *a) {}); After: LooooooooooooooooongType variable(nullptr, [](A *a) {}); llvm-svn: 294358
* clang-format: [JS] correcly format object literal methods.Martin Probst2017-02-071-0/+1
| | | | | | | | | | | | | | | | | | | | | 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: Fix bug with conflicting BreakBeforeBinaryOperations and ↵Daniel Jasper2017-02-061-1/+2
| | | | | | | | | | | | | | | | AlignAfterOpenBracket Fix for the formatting options combination of BreakBeforeBinaryOperators: All, AlignAfterOpenBracket: AlwaysBreak not handling long templates correctly. This patch allows a break after an opening left parenthesis, TemplateOpener, or bracket when both options are enabled. Patch by Daphne Pfister, thank you! Fixes llvm.org/PR30304. llvm-svn: 294179
* clang-format: [JS] Fix bugs in parsing and aligning template strings.Daniel Jasper2017-02-031-1/+3
| | | | llvm-svn: 294009
* clang-format: [Proto] Also supports implicit string literal concatenationDaniel Jasper2017-02-031-1/+2
| | | | llvm-svn: 293995
* clang-format: [JS] Properly set scopes inside template strings.Daniel Jasper2017-01-311-1/+3
| | | | | | | | | | | | | Before: var f = `aaaaaaaaaaaaa:${aaaaaaa .aaaaa} aaaaaaaa aaaaaaaaaaaaa:${aaaaaaa.aaaaa} aaaaaaaa`; After: var f = `aaaaaaaaaaaaa:${aaaaaaa.aaaaa} aaaaaaaa aaaaaaaaaaaaa:${aaaaaaa.aaaaa} aaaaaaaa`; llvm-svn: 293622
* clang-format: [JS] Fix incorrect line break in template strings.Daniel Jasper2017-01-311-3/+5
| | | | | | | | | | | Before: var f = `aaaa ${a ? 'a' : 'b' }`; After: var f = `aaaa ${a ? 'a' : 'b'}`; llvm-svn: 293618
* [clang-format] Refactor WhitespaceManager and friendsDaniel Jasper2017-01-311-2/+9
| | | | | | | | | | | | | | | | | | | The main motivation behind this is to cleanup the WhitespaceManager and make it more extensible for future alignment etc. features. Specifically, WhitespaceManager has started to copy more and more code that is already present in FormatToken. Instead, I think it makes more sense to actually store a reference to each FormatToken for each change. This has as a consequence led to a change in the calculation of indent levels. Now, we actually compute them for each Token ahead of time, which should be more efficient as it removes an unsigned value for the ParenState, which is used during the combinatorial exploration of the solution space. No functional changes intended. Review: https://reviews.llvm.org/D29300 llvm-svn: 293616
* [clang-format] Implement comment reflowing.Krasimir Georgiev2017-01-251-2/+8
| | | | | | | | | | | | | | | | | | 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: Improve support for override/final as variable names.Daniel Jasper2017-01-091-6/+4
| | | | | | | | | | | | | | | | Before: bool a = f() &&override.f(); bool a = f() &&final.f(); void f(const MyOverride & override); void f(const MyFinal & final); After: bool a = f() && override.f(); bool a = f() && final.f(); void f(const MyOverride &override); void f(const MyFinal &final); llvm-svn: 291434
* clang-format: Less eagerly try to keep label-value pairs on a line.Daniel Jasper2016-12-221-1/+1
| | | | | | | | | | | | | | | Before: string v = StrCat("aaaaaaaaaaaaaaaaaaaaaaaaaaa: ", SomeFunction(aaaaaaaaaaaa, aaaaaaaaaaaaaaa), bbbbbbbbbbbbbbbbbbbbbbb); After: string v = StrCat("aaaaaaaaaaaaaaaaaaaaaaaaaaa: ", SomeFunction(aaaaaaaaaaaa, aaaaaaaaaaaaaaa), bbbbbbbbbbbbbbbbbbbbbbb); llvm-svn: 290337
* clang-format: Fix bug in understanding string-label&value analysis.Daniel Jasper2016-12-201-2/+5
| | | | | | | | | | | | | | | While for <<-operators often used in log statments, a single key value pair is always on the second operator, e.g. llvm::errs() << "aaaaa=" << aaaaa; It is on the first operator for plus- or comma-concatenated strings: string s = "aaaaaaaaaa: " + aaaaaaaa; (the "=" not counting because that's a different operator precedence) llvm-svn: 290177
* clang-format: Slightly tweak the behavior of <<-wrapping.Daniel Jasper2016-12-191-2/+7
| | | | | | | | | | | | | | | Before: SomeLongLoggingStatementOrMacro() << "Some long text " << some_variable << "\n"; Before: SomeLongLoggingStatementOrMacro() << "Some long text " << some_variable << "\n"; Short logging statements are already special cased in a different part of the code. llvm-svn: 290094
* clang-format: Keep string-literal-label + value pairs on a line.Daniel Jasper2016-12-131-17/+13
| | | | | | | | | | | | | | | | | | | | | We have previously done that for <<-operators. This patch also adds this logic for "," and "+". Before: string v = "aaaaaaaaaaaaaaaa: " + aaaaaaaaaaaaaaaa + "aaaaaaaaaaaaaaaa: " + aaaaaaaaaaaaaaaa + "aaaaaaaaaaaaaaaa: " + aaaaaaaaaaaaaaaa; string v = StrCat("aaaaaaaaaaaaaaaa: ", aaaaaaaaaaaaaaaa, "aaaaaaaaaaaaaaaa: ", aaaaaaaaaaaaaaaa, "aaaaaaaaaaaaaaaa: ", aaaaaaaaaaaaaaaa); After: string v = "aaaaaaaaaaaaaaaa: " + aaaaaaaaaaaaaaaa + "aaaaaaaaaaaaaaaa: " + aaaaaaaaaaaaaaaa + "aaaaaaaaaaaaaaaa: " + aaaaaaaaaaaaaaaa; string v = StrCat("aaaaaaaaaaaaaaaa: ", aaaaaaaaaaaaaaaa, "aaaaaaaaaaaaaaaa: ", aaaaaaaaaaaaaaaa, "aaaaaaaaaaaaaaaa: ", aaaaaaaaaaaaaaaa); llvm-svn: 289531
* clang-format: Separate out a language kind for ObjC.Daniel Jasper2016-12-121-2/+5
| | | | | | | | | | | | | While C(++) and ObjC are generally formatted the same way and can be mixed, people might want to choose different styles based on the language. This patch recognizes .m and .mm files as ObjC and also implements a very crude detection of whether or not a .h file contains ObjC code. This can be improved over time. Also move most of the ObjC tests into their own test file to keep file size maintainable. llvm-svn: 289428
* clang-format: [JS] Properly format dict literals that skip labels.Daniel Jasper2016-11-291-0/+3
| | | | llvm-svn: 288121
* clang-format: Support ObjC selectors with unnamed parameters.Daniel Jasper2016-11-121-9/+28
| | | | | | This fixes llvm.org/PR28063. llvm-svn: 286715
* [clang-format] Fix PR30527: Regression when clang-format insert spaces in [] ↵Nico Weber2016-11-101-2/+12
| | | | | | | | | | | | | | | | | | | | when in template Actual regression was introduced in r272668. This revision fixes JS script, but also regress Cpp case. It manifests with spaces added when template is followed with array. Bug 30527 mentions case of array as a nested template type (foo<bar<baz>[]>). Fix is to detect such case and to prevent treating it as array initialization, but as a subscript case. However, before r272668, this case was treated simple because we were detecting it as a StartsObjCMethodExpr. Same was true for other similar case - array of templates (foo<int>[]). This patch tries to address two problems: 1) fixing regression 2) making sure both cases (array as a nested type, array of templates) which were entering StartsObjCMethodExpr branch are handled now appropriately. https://reviews.llvm.org/D26163 Patch from Branko Kokanovic <branko@kokanovic.org>! llvm-svn: 286507
* drop kw_module from ASI protection blockMartin Probst2016-11-101-2/+2
| | | | llvm-svn: 286469
* clang-format: [JS] do not break after declare namespace.Martin Probst2016-11-101-2/+14
| | | | | | | See TypeScript grammar for tokens following 'declare': https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#A.10 llvm-svn: 286467
* clang-format: [TypeScript] Fix bug in handling of non-null operator.Daniel Jasper2016-11-091-1/+7
| | | | | | | | | | Before: var i = x!-1; After: var i = x! - 1; llvm-svn: 286367
* clang-format: Better support for CUDA's triple brackets.Daniel Jasper2016-11-051-0/+2
| | | | | | | | | | | | | Before: aaaaaaaaaaaaaaa< aaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaaaaa><<<aaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaaaaaaaaa>>>(); After: aaaaaaaaaaaaaaa<aaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaaaaa> <<<aaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaaaaaaaaa>>>(); llvm-svn: 286041
* clang-format: Fix bug in function reference qualifier detection.Daniel Jasper2016-11-011-1/+1
| | | | | | | | | | | | | Before: template <typename T> void F(T) && = delete; After: template <typename T> void F(T) && = delete; llvm-svn: 285674
* clang-format: Fix incorrect pointer detection.Daniel Jasper2016-11-011-2/+3
| | | | | | | | | | Before: void f() { f(float{1}, a *a); } After: void f() { f(float{1}, a * a); } llvm-svn: 285673
* clang-format: [JS] Fix incorrect space when "as" is used as identifier.Daniel Jasper2016-11-011-1/+1
| | | | | | | | | | Before: aaaaa.as (); After: aaaaa.as(); llvm-svn: 285672
* clang-format: Fix incorrect binary operator detection.Daniel Jasper2016-11-011-1/+1
| | | | | | | | | | Before: int x = f(* + [] {}); After: int x = f(*+[] {}); llvm-svn: 285671
* clang-format: [JS] Fix formatting of generator functions.Daniel Jasper2016-11-011-1/+2
| | | | | | | | | | | | | | | | | | | Before: var x = { a: function* () { // } } After: var x = { a: function*() { // } } llvm-svn: 285670
* clang-format: [JS] Fix space when for is used as regular identifier.Daniel Jasper2016-11-011-0/+3
| | | | | | | | | | Before: x.for () = 1; After: x.for() = 1; llvm-svn: 285669
* Skip over AnnotatedLines with >50 levels of nesting; don't format them.Daniel Jasper2016-10-311-0/+15
| | | | | | | | | | | | | | | Reasoning: - ExpressionParser uses a lot of stack for these, bad in some environments. - Our formatting algorithm is N^3 and gets really slow. - The resulting formatting is unlikely to be any good. - This is probably generated code we're formatting by accident. We treat these as unparseable, and signal incomplete formatting. 50 is an arbitrary number, I've only seen real problems from ~150 levels. Patch by Sam McCall. Thank you. llvm-svn: 285570
* clang-format: [JS] Fix missing space after 'yield'.Daniel Jasper2016-10-311-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before: class X { delete(val) { return null; } * gen() { yield[1, 2]; } * gen() { yield{a: 1}; } }; After: class X { delete(val) { return null; } * gen() { yield [1, 2]; } * gen() { yield {a: 1}; } }; llvm-svn: 285569
* [Format] Cleanup after replacing constructor body with = defaultMalcolm Parsons2016-10-201-1/+2
| | | | | | | | | | | | | | Summary: Remove colon and commas after replacing constructor body with = default. Fix annotation of TT_CtorInitializerColon when preceded by a comment. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D25768 llvm-svn: 284732
* clang-format: Fix bad multi-variable for-loop formatting.Daniel Jasper2016-10-041-1/+3
| | | | | | | | | | Before: for (int*p, *q; p != q; p = p->next) { After: for (int *p, *q; p != q; p = p->next) { llvm-svn: 283246
* [clang-format] Don't allow newline after uppercase Obj-C block return typesDaniel Jasper2016-09-261-6/+11
| | | | | | | | | | | | | | Fixes the following: BOOL (^aaa)(void) = ^BOOL { }; The first BOOL's token was getting set to TT_FunctionAnnotationRParen incorrectly, which was causing an unexpected newline after (^aaa). This was introduced in r245846. Patch by Kent Sutherland, thank you! llvm-svn: 282448
* clang-format: Only special-case top-level */& in multivar-declstmts.Daniel Jasper2016-09-261-1/+1
| | | | | | | | | | Before (even with PointerAlignment: Left): vector<int *> a, b; After: vector<int*> a, b; llvm-svn: 282410
* clang-format: [JS] reserved words in method names.Martin Probst2016-09-221-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: Before: class X { delete () { ... } } After: class X { delete() { ... } } Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D24804 llvm-svn: 282138
* clang-format: [JS] whitespace required between ! and as.Martin Probst2016-09-061-0/+2
| | | | | | | | | | | | | | | | Summary: Before: x!as string After: x! as string Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D24272 llvm-svn: 280731
* clang-format: [JS] ignore comments when wrapping returns.Martin Probst2016-09-061-1/+6
| | | | | | | | | | | | | | | | | | | Summary: When code contains a comment between `return` and the value: return /* lengthy comment here */ ( lengthyValueComesHere); Do not wrap before the comment, as that'd break the code through JS' automatic semicolon insertion. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D24257 llvm-svn: 280730
* clang-format: [JS] nested and tagged template strings.Martin Probst2016-08-251-1/+9
| | | | | | | | | | | | | | | | | | | JavaScript template strings can be nested arbitrarily: foo = `text ${es.map(e => { return `<${e}>`; })} text`; This change lexes nested template strings using a stack of lexer states to correctly switch back to template string lexing on closing braces. Also, reuse the same stack for the token-stashed logic. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D22431 llvm-svn: 279727
* clang-format: [JS] supports casts to types starting with punctuation ("{[(").Martin Probst2016-08-221-0/+3
| | | | | | | | | | | | | | | | | | Before: x as{x: number} After: x as {x: number} Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D23761 llvm-svn: 279436
* clang-format: Add SpaceAfterTemplateSylvestre Ledru2016-08-091-2/+3
| | | | | | | | | | | | | | | | Summary: This is required for compliance with the Mozilla style guide. This is a rebase+minor change of Birunthan Mohanathas's patch Reviewers: djasper Subscribers: klimek, cfe-commits, opilarium Differential Revision: https://reviews.llvm.org/D23317 llvm-svn: 278121
* clang-format: [JS] Allow top-level conditionals again.Daniel Jasper2016-07-121-1/+1
| | | | | | | | I am not sure exactly which test breakage Martin was trying to fix in r273694. For now, fix the behavior for top-level conditionals, which (surprisingly) are actually used somewhat commonly. llvm-svn: 275183
* clang-format: [JS] Fix build breakage.Martin Probst2016-06-241-1/+1
| | | | | | Checking Line.MustBeDeclaration does actually break the field and param initializer use case. llvm-svn: 273694
* clang-format: [JS] handle conditionals in fields, default params.Martin Probst2016-06-231-2/+2
| | | | | | | | | | | | Summary: Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D21658 llvm-svn: 273619
* clang-format: [JS] recognize more type locations.Martin Probst2016-06-231-0/+11
| | | | | | | | | | | | Summary: Includes parenthesized type expressions and type aliases. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D21597 llvm-svn: 273603
* clang-format: [Proto] Use more compact format for text-formatted optionsDaniel Jasper2016-06-231-3/+0
| | | | | | | | | | | | | | | | | Before: enum Type { UNKNOWN = 0 [(some_options) = { a: aa, b: bb }]; }; After: enum Type { UNKNOWN = 0 [(some_options) = {a: aa, b: bb}]; }; llvm-svn: 273553
* clang-format: [JS] Do not break before 'as'.Martin Probst2016-06-221-0/+2
| | | | | | | | | | | | | | Summary: 'as' is a pseudo operator, so automatic semicolon insertion kicks in and the code fails to part. Reviewers: djasper Subscribers: klimek Differential Revision: http://reviews.llvm.org/D21576 llvm-svn: 273422
* clang-format: [JS] Fix failing format with TypeScript casts.Daniel Jasper2016-06-141-3/+3
| | | | | | | | | | | | Before, this could be formatted at all (with BracketAlignmentStyle AlwaysBreak): foo = <Bar[]>[ 1, /* */ 2 ]; llvm-svn: 272668
* clang-format: [JS] Support annotated classes.Daniel Jasper2016-06-141-1/+2
| | | | llvm-svn: 272654
* clang-format: [JS] Introduce JavaScriptWrapImports option.Martin Probst2016-06-131-3/+4
| | | | | | | | | | | | | | Summary: When turned on, clang-format wraps JavaScript imports (and importing exports), instead of forcing the entire import statement onto one line. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D21273 llvm-svn: 272558
OpenPOWER on IntegriCloud