summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format
Commit message (Collapse)AuthorAgeFilesLines
...
* clang-format: Support ObjC selectors with unnamed parameters.Daniel Jasper2016-11-121-0/+20
| | | | | | This fixes llvm.org/PR28063. llvm-svn: 286715
* [clang-format] Fix PR30527: Regression when clang-format insert spaces in [] ↵Nico Weber2016-11-101-0/+20
| | | | | | | | | | | | | | | | | | | | 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
* clang-format: [JS] do not break after declare namespace.Martin Probst2016-11-101-0/+31
| | | | | | | 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-0/+1
| | | | | | | | | | 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
* Fixed column shift when formatting line containing bit shift operatorsMalcolm Parsons2016-11-031-0/+12
| | | | | | | | | | | | | | | | | | | Summary: During clang-format source lexing >> and << operators are split and treated as two less/greater operators but column position of following tokens was not adjusted accordingly. Fixes PR26887 Patch by Paweł Żukowski. Reviewers: djasper Subscribers: malcolm.parsons, mprobst, klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D25439 llvm-svn: 285934
* clang-format: Fix bug in function reference qualifier detection.Daniel Jasper2016-11-011-1/+4
| | | | | | | | | | | | | 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-0/+1
| | | | | | | | | | 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-0/+1
| | | | | | | | | | Before: aaaaa.as (); After: aaaaa.as(); llvm-svn: 285672
* clang-format: Fix incorrect binary operator detection.Daniel Jasper2016-11-011-0/+1
| | | | | | | | | | Before: int x = f(* + [] {}); After: int x = f(*+[] {}); llvm-svn: 285671
* clang-format: [JS] Fix formatting of generator functions.Daniel Jasper2016-11-011-0/+5
| | | | | | | | | | | | | | | | | | | 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/+1
| | | | | | | | | | 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/+24
| | | | | | | | | | | | | | | 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/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Bug 28065 - clang-format incorrectly aligns backslash.Andi-Bogdan Postelnicu2016-10-261-0/+11
| | | | llvm-svn: 285178
* clang-format: [JS] Fix template string ASI.Martin Probst2016-10-211-0/+6
| | | | | | | | | | | | | | | | | | | 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
* [Format] Cleanup after replacing constructor body with = defaultMalcolm Parsons2016-10-201-0/+18
| | | | | | | | | | | | | | 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
* Make DeletedLines local variables in checkEmptyNamespace.Eric Liu2016-10-051-0/+18
| | | | | | | | | | | | Summary: Patch by Sam McCall! Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D25162 llvm-svn: 283332
* [clang-format] append newline after code when inserting new headers at the ↵Eric Liu2016-10-051-3/+11
| | | | | | | | | | | | | | | | end of the code which does not end with newline. Summary: append newline after code when inserting new headers at the end of the code which does not end with newline. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D21026 llvm-svn: 283330
* clang-format: Fix bad multi-variable for-loop formatting.Daniel Jasper2016-10-041-0/+1
| | | | | | | | | | 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-0/+2
| | | | | | | | | | | | | | 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-0/+1
| | | | | | | | | | Before (even with PointerAlignment: Left): vector<int *> a, b; After: vector<int*> a, b; llvm-svn: 282410
* [clang-format] support header deletion in cleanupAroundReplacemnts.Eric Liu2016-09-231-2/+57
| | | | | | | | | | | | | | | | | | Summary: - If a replacement has offset UINT_MAX, length 0, and a replacement text that is an #include directive, this will insert the #include into the correct block in the \p Code. - If a replacement has offset UINT_MAX, length 1, and a replacement text that is the name of the header to be removed, the header will be removed from \p Code if it exists. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D24829 llvm-svn: 282253
* clang-format: [JS] reserved words in method names.Martin Probst2016-09-221-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | 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] Fix line breaks before comments when sorting imports.Martin Probst2016-09-191-0/+10
| | | | | | | | | | | | | | | Summary: Previously, clang-format would always insert an additional line break after the import block if the main body started with a comment, due to loosing track of the first non-import line. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D24708 llvm-svn: 281888
* clang-format: [JS] Do not wrap taze annotation comments.Martin Probst2016-09-181-0/+6
| | | | | | | | | | | | | | | | | | | | | Summary: `// taze: ... from ...` comments are used help tools where a specific global symbol comes from. Before: // taze: many, different, symbols from // 'some_long_location_here' After: // taze: many, different, symbols from 'some_long_location_here' Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D24477 llvm-svn: 281857
* clang-format: [JS] ASI insertion after boolean literals.Martin Probst2016-09-181-0/+12
| | | | | | | | | | | | | | | | | | | | | 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] Fix a crash in handledTemplateStrings.Daniel Jasper2016-09-171-0/+3
| | | | llvm-svn: 281816
* Remove redundant comma around parenthesis in parameter list.Eric Liu2016-09-131-56/+56
| | | | | | | | | | Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D24501 llvm-svn: 281344
* Also cleanup comments around redundant colons/commas in format::cleanup.Eric Liu2016-09-091-13/+8
| | | | | | | | | | Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D24400 llvm-svn: 281064
* clang-format: [JavaScript] Change default AllowShortFunctionsOnASingleLineDaniel Jasper2016-09-071-22/+59
| | | | | | for Google style to "empty". llvm-svn: 280878
* clang-format: [JavaScript] Do requoting in a separate passDaniel Jasper2016-09-071-0/+8
| | | | | | | | | | | | | | | | | | The attempt to fix requoting behavior in r280487 after changes to tooling::Replacements are incomplete. We essentially need to add to replacements at the same position, one to insert a line break and one to change the quoting and that's incompatible with the new tooling::Replacement API, which does not allow for order-dependent Replacements. To make the order clear, Replacements::merge() has to be used, but that requires the merged Replacement to actually refer to the changed text, which is hard to reproduce for the requoting. This change fixes the behavior by moving the requoting to a completely separate pass. The added benefit is that no weird ColumnWidth calculations are necessary anymore and this should just work even if we implement string literal splitting in the future. llvm-svn: 280874
* clang-format: [JS] whitespace required between ! and as.Martin Probst2016-09-061-0/+1
| | | | | | | | | | | | | | | | 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-0/+2
| | | | | | | | | | | | | | | | | | | 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] merge requoting replacements.Martin Probst2016-09-021-0/+7
| | | | | | | | | | | | | | | | | Summary: When formatting source code that needs both requoting and reindentation, merge the replacements to avoid erroring out for conflicting replacements. Also removes the misleading Replacements parameter from the TokenAnalyzer API. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D24155 llvm-svn: 280487
* clang-format: [JS] handle default bindings in imports.Martin Probst2016-09-021-0/+20
| | | | | | | | | | | | | | | | Summary: Default imports appear outside of named bindings in curly braces: import A from 'a'; import A, {symbol} from 'a'; Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D23973 llvm-svn: 280486
* clang-format: [JS] Sort all JavaScript imports if any changed.Martin Probst2016-09-021-18/+7
| | | | | | | | | | | | | | | Summary: User feedback is that they expect *all* imports to be sorted if any import was affected by a change, not just imports up to the first non-affected line, as clang-format currently does. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D23972 llvm-svn: 280485
* clang-format: Correctly calculate affected ranges when sorting #includes.Daniel Jasper2016-08-301-2/+14
| | | | | | affectedRanges takes a start and an end offset, not offset and length. llvm-svn: 280165
* clang-format: [JS] nested and tagged template strings.Martin Probst2016-08-251-1/+13
| | | | | | | | | | | | | | | | | | | 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: [JS] handle object literals with casts.Martin Probst2016-08-191-0/+1
| | | | | | | | | | | | Summary: E.g. `{a: 1} as b`. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D23714 llvm-svn: 279250
* Make clang-format remove duplicate headers when sorting #includes.Eric Liu2016-08-101-6/+83
| | | | | | | | | | | | Summary: When sorting #includes, #include directives that have the same text will be deduplicated when sorting #includes, and only the first #include in the duplicate #includes remains. If the `Cursor` is provided and put on a deleted #include, it will be put on the remaining #include in the duplicate #includes. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D23274 llvm-svn: 278206
* clang-format: Add SpaceAfterTemplateSylvestre Ledru2016-08-091-0/+7
| | | | | | | | | | | | | | | | 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
* Implement tooling::Replacements as a class.Eric Liu2016-08-012-75/+91
| | | | | | | | | | | | | | | | | | | Summary: - Implement clang::tooling::Replacements as a class to provide interfaces to control how replacements for a single file are combined and provide guarantee on the order of replacements being applied. - tooling::Replacements only contains replacements for the same file now. Use std::map<std::string, tooling::Replacements> to represent multi-file replacements. - Error handling for the interface change will be improved in followup patches. Reviewers: djasper, klimek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D21748 llvm-svn: 277335
* clang-format: Fix incorrect detection of QT-signals access specifier.Daniel Jasper2016-07-271-0/+4
| | | | | | | | | | | | | | | | | Before: void f() { label: signals .baz(); } After: void f() { label: signals.baz(); } llvm-svn: 276854
* 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
* Make tooling::applyAllReplacements return llvm::Expected<string> instead of ↵Eric Liu2016-07-118-39/+63
| | | | | | | | | | | | | | | | empty string to indicate potential error. Summary: return llvm::Expected<> to carry error status and error information. This is the first step towards introducing "Error" into tooling::Replacements. Reviewers: djasper, klimek Subscribers: ioeric, klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D21601 llvm-svn: 275062
* clang-format: [JS] Sort imports case insensitive.Martin Probst2016-07-091-0/+21
| | | | | | | | | | | | Summary: ASCII case sorting does not help finding imported symbols quickly, and it is common to have e.g. class Foo and function fooFactory exported/imported from the same file. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D22146 llvm-svn: 274977
* clang-format: [JS] support trailing commas in imports.Martin Probst2016-07-091-0/+4
| | | | | | | | | | Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D22147 llvm-svn: 274976
* 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
OpenPOWER on IntegriCloud