summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTest.cpp
Commit message (Collapse)AuthorAgeFilesLines
* 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: Fix incorrect binary operator detection.Daniel Jasper2016-11-011-0/+1
| | | | | | | | | | Before: int x = f(* + [] {}); After: int x = f(*+[] {}); llvm-svn: 285671
* 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
* Bug 28065 - clang-format incorrectly aligns backslash.Andi-Bogdan Postelnicu2016-10-261-0/+11
| | | | llvm-svn: 285178
* 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: 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-011-24/+16
| | | | | | | | | | | | | | | | | | | 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
* Make tooling::applyAllReplacements return llvm::Expected<string> instead of ↵Eric Liu2016-07-111-8/+16
| | | | | | | | | | | | | | | | 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: Restrict r272537 to function ref qualifiers.Daniel Jasper2016-06-131-0/+1
| | | | | | | | | | | | Seems this isn't generally desirable. Before: int const * a; After: int const* a; llvm-svn: 272548
* clang-format: Fix incorrect function type detection.Daniel Jasper2016-06-131-0/+1
| | | | | | | | | | Before: returnsFunction (&param1, &param2)(param); After: returnsFunction(&param1, &param2)(param); llvm-svn: 272538
* clang-format: Don't merge const and &, e.g. in function ref qualifiers.Daniel Jasper2016-06-131-0/+2
| | | | | | | | | | | | | | | | | Before (when aligning & to the right): SomeType MemberFunction(const Deleted &) const&; After: SomeType MemberFunction(const Deleted &) const &; This also applies to variable declarations, e.g.: int const * a; However, this form is very uncommon (most people would write "const int* a" instead) and contracting to "const*" might actually send the wrong signal of what the const binds to. llvm-svn: 272537
* clang-format: Fix incorrect cast detection.Daniel Jasper2016-06-131-0/+1
| | | | | | | | | | Before: auto s = sizeof...(Ts)-1; After: auto s = sizeof...(Ts) - 1; llvm-svn: 272536
* clang-format: Don't indent lambda body relative to its return type.Daniel Jasper2016-06-131-0/+4
| | | | | | | | | | | | | | | | Before: []() // -> int { return 1; // }; After: []() // -> int { return 1; // }; llvm-svn: 272535
* clang-format: Fix incorrect calculation of "length" of /**/ comments.Daniel Jasper2016-06-081-0/+8
| | | | | | This could lead to column limit violations. llvm-svn: 272125
* clang-format: Fix bug in function ref qualifier identification.Daniel Jasper2016-06-081-0/+1
| | | | | | | | | | | | | | .. and simplify it. Before: void A::f()&& {} void f() && {} After: void A::f() && {} void f() && {} llvm-svn: 272124
* clang-format: Allow splitting the line after /**/-comments.Daniel Jasper2016-05-271-0/+2
| | | | | | | While it might change the meaning of the comment in rare circumstances, it is better than violating the column limit. llvm-svn: 270975
* [clang-format] moved unit tests related to replacements cleaner from ↵Eric Liu2016-05-271-29/+0
| | | | | | FormatTest.cpp to CleanUpTest.cpp. llvm-svn: 270971
* clang-format: Fix incorrect indentation in last line of macro definitionDaniel Jasper2016-05-191-0/+6
| | | | | | | | | | | | | | | | | | Before: #define MACRO(a) \ if (a) { \ f(); \ } else \ g() After: #define MACRO(a) \ if (a) { \ f(); \ } else \ g() llvm-svn: 270028
* clang-format: Fix enumerator case ranges.Daniel Jasper2016-05-191-0/+1
| | | | | | | | | | Before: case a... b: break; After: case a ... b: break; llvm-svn: 270027
* [clang-format] Make formatReplacements() also sort #includes.Eric Liu2016-05-181-0/+25
| | | | | | | | | | | | Summary: [clang-format] Make formatReplacements() also sort #includes. Reviewers: bkramer, djasper Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D20362 llvm-svn: 269924
* clang-format: Fix space after argument comments.Daniel Jasper2016-05-081-1/+1
| | | | | | | | | | Before: f(/*a=*/a, /*b=*/ ::b); After: f(/*a=*/a, /*b=*/::b); llvm-svn: 268879
* clang-format: Support enum type template arguments.Daniel Jasper2016-05-081-0/+4
| | | | | | | | | | | | | Before: template <enum E> class A { public : E *f(); }; After: template <enum E> class A { public: E *f(); }; llvm-svn: 268878
* Added Fixer implementation and fix() interface in clang-format for removing ↵Eric Liu2016-04-251-0/+29
| | | | | | | | | | | | | | | | | redundant code. Summary: After applying replacements, redundant code like extra commas or empty namespaces might be introduced. Fixer can detect and remove any redundant code introduced by replacements. The current implementation only handles redundant commas. Reviewers: djasper, klimek Subscribers: ioeric, mprobst, klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D18551 llvm-svn: 267416
* clang-format: Improve heuristics to detect function declarations/definitions.Daniel Jasper2016-04-181-0/+8
| | | | | | | Specifically understand ellipses in parameter lists and treat trailing reference qualifiers and the "{" as signals. llvm-svn: 266599
* clang-format: Last line in incomplete block is indented incorrectlyMarianne Mailhot-Sarrasin2016-04-141-3/+2
| | | | | | | | | | 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: Implemented tab usage for continuation and indentationMarianne Mailhot-Sarrasin2016-04-141-0/+226
| | | | | | | | | | Use tabs to fill whitespace at the start of a line. Patch by Maxime Beaulieu Differential Revision: http://reviews.llvm.org/D19028 llvm-svn: 266320
* clang-format: Fix label-in-if statement in macros where it is actually used.Daniel Jasper2016-04-061-0/+6
| | | | | | | | | | | | | | | | 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/+6
| | | | | | | | | | | | | | | | 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: Fix incorrect function annotation detection.Daniel Jasper2016-04-061-0/+6
| | | | | | | | | | | | | Before: MACRO( abc).function() // wrap << abc; After: MACRO(abc).function() // wrap << abc; llvm-svn: 265540
* clang-format: Fix cast detection on "this".Daniel Jasper2016-04-051-0/+1
| | | | | | | | | | | | Before: auto x = (X) this; After: auto x = (X)this; This fixes llvm.org/PR27198. llvm-svn: 265385
* Added formatAndApplyAllReplacements that works on multiple files in libTooling.Eric Liu2016-03-291-1/+2
| | | | | | | | | | | | | | Summary: formatAndApplyAllReplacements takes a set of Replacements, applies them on a Rewriter, and reformats the changed code. Reviewers: klimek, djasper Subscribers: ioeric, klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D17852 llvm-svn: 264745
* Dsiable FormatStyle::GetStyleOfFile test case for mingw.Eric Liu2016-03-241-1/+1
| | | | llvm-svn: 264289
* Added support for different VFSs in format::getStyle. Disable ↵Eric Liu2016-03-241-0/+34
| | | | | | platform-related test case for MS compilers to avoid breaking buildbot. llvm-svn: 264277
* Revert "Added support for different VFSs in format::getStyle."Eric Liu2016-03-241-28/+0
| | | | | | This reverts commit r264253. It is breaking the buildbot http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/2203 llvm-svn: 264257
* Added support for different VFSs in format::getStyle.Eric Liu2016-03-241-0/+28
| | | | | | | | | | | | | | | | Summary: Previously, format::getStyle assumes that the given file resides in the real file system, which prevents the use of virtual file system in testing etc. This patch adds a parameter in format::getStyle interface so that users can specify the right file system. By default, the file system is the real file system. Reviewers: djasper, klimek Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D18399 llvm-svn: 264253
* clang-format: Make include sorting's main include detection configurable.Daniel Jasper2016-03-211-0/+2
| | | | | | | | | | This patch adds a regular expression to configure suffixes of an included file to check whether it is the "main" include of the current file. Previously, clang-format has allowed arbitrary suffixes on the formatted file, which is still the case when no IncludeMainRegex is specified. llvm-svn: 263943
* clang-format: Slightly weaken AlignAfterOpenBracket=AlwaysBreak.Daniel Jasper2016-03-171-5/+24
| | | | | | | | | | | | | | | | | | If a call takes a single argument, using AlwaysBreak can lead to lots of wasted lines and additional indentation without improving the readability in a significant way. Before: caaaaaaaaaaaall( caaaaaaaaaaaall( caaaaaaaaaaaall( caaaaaaaaaaaaaaaaaaaaaaall(aaaaaaaaaaaaaa, aaaaaaaaa)))); After: caaaaaaaaaaaall(caaaaaaaaaaaall(caaaaaaaaaaaall( caaaaaaaaaaaaaaaaaaaaaaall(aaaaaaaaaaaaaa, aaaaaaaaa)))); llvm-svn: 263709
* clang-format: [JS] Optionally re-quote string literals.Daniel Jasper2016-03-021-1/+1
| | | | | | | | | | | | | | | | | | | | | Turns "foo" into 'foo' (or vice versa, depending on configuration). This makes it more convenient to follow the Google JavaScript style guide: https://google.github.io/styleguide/javascriptguide.xml?showone=Strings#Strings This functionality is behind the option "JavaScriptQuotes", which can be: * "leave" (no re-quoting) * "single" (change to single quotes) * "double" (change to double quotes) This also changes single quoted JavaScript string literals to be treated as tok::string_literal, not tok::char_literal, which fixes two unrelated tests. Patch by Martin Probst. Thank you. llvm-svn: 262534
* [clang-format] Detect constructor initializers preceded by `noexcept`.Daniel Jasper2016-03-011-0/+3
| | | | | | Patch by Erik Kessler, thank you. llvm-svn: 262402
* Add functions to apply replacements and reformat them.Manuel Klimek2016-03-011-1/+45
| | | | | | | | | | | | | | | | This is a commonly useful feature to have, and we have implemented it multiple times with different kinds of bugs. This implementation centralizes the idea in a set of functions that we can then use from the various tools. Reverts r262234, which is a revert of r262232, and puts the functions into FOrmat.h, as they are closely coupled to clang-format, and we otherwise introduce a cyclic dependency between libFormat and libTooling. Patch by Eric Liu. llvm-svn: 262323
* clang-format: Correctly apply wrap before multi-line RHS rule toDaniel Jasper2016-03-011-0/+4
| | | | | | | | | | | | | | | ternary expressions. Before: return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ? aaaaa : bbbbbbbbbbbbbbb + cccccccccccccccc; After: return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ? aaaaa : bbbbbbbbbbbbbbb + cccccccccccccccc; llvm-svn: 262293
* clang-format: Increase the penalty for breaking between array subscripts.Daniel Jasper2016-03-011-0/+2
| | | | | | | | | | | | Before: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[aaaaaaaaaaaaaaaaaaaaaaa] [a].aaaaaaaaaaaaaaaaaaaaaa(); After: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[aaaaaaaaaaaaaaaaaaaaaaa][a] .aaaaaaaaaaaaaaaaaaaaaa(); llvm-svn: 262292
* Remove use of builtin comma operator.Richard Trieu2016-02-181-1/+2
| | | | | | Cleanup for upcoming Clang warning -Wcomma. No functionality change intended. llvm-svn: 261271
* clang-format: Make indentation after "<<" more consistent.Daniel Jasper2016-02-111-0/+7
| | | | | | | | | | | | | | | | | | | | | | Before: Diag(aaaaaaaaaaaaaaaaaaaa, aaaaaaaa) << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); Diag(aaaaaaaaaaaaaaaaaaaa, aaaaaaaa) << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) << aaa; After: Diag(aaaaaaaaaaaaaaaaaaaa, aaaaaaaa) << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); Diag(aaaaaaaaaaaaaaaaaaaa, aaaaaaaa) << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) << aaa; llvm-svn: 260517
OpenPOWER on IntegriCloud