summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix mishandling of escaped newlines followed by newlines or nuls.Richard Smith2017-04-171-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, if an escaped newline was followed by a newline or a nul, we'd lex the escaped newline as a bogus space character. This led to a bunch of different broken corner cases: For the pattern "\\\n\0#", we would then have a (horizontal) space whose spelling ends in a newline, and would decide that the '#' is at the start of a line, and incorrectly start preprocessing a directive in the middle of a logical source line. If we were already in the middle of a directive, this would result in our attempting to process multiple directives at the same time! This resulted in crashes, asserts, and hangs on invalid input, as discovered by fuzz-testing. For the pattern "\\\n" at EOF (with an implicit following nul byte), we would produce a bogus trailing space character with spelling "\\\n". This was mostly harmless, but would lead to clang-format getting confused and misformatting in rare cases. We now produce a trailing EOF token with spelling "\\\n", consistent with our handling for other similar cases -- an escaped newline is always part of the token containing the next character, if any. For the pattern "\\\n\n", this was somewhat more benign, but would produce an extraneous whitespace token to clients who care about preserving whitespace. However, it turns out that our lexing for line comments was relying on this bug due to an off-by-one error in its computation of the end of the comment, on the slow path where the comment might contain escaped newlines. llvm-svn: 300515
* [clang-format] Recognize Java logical shift assignment operator Nico Weber2017-04-111-0/+12
| | | | | | | | | | | | | | | | | | | | | | At present, clang-format mangles Java containing logical right shift operators ('>>>=' or '>>>'), splitting them in two, resulting in invalid code: public class Minimal { public void func(String args) { int i = 42; - i >>>= 1; + i >> >= 1; return i; } } This adds both forms of logical right shift to the FormatTokenLexer, so clang-format won't attempt to split them and insert bogus whitespace. https://reviews.llvm.org/D31652 Patch from Richard Bradfield <bradfier@fstab.me>! llvm-svn: 299952
* [clang-format] Handle NSString literals by merging tokens.Alexander Kornienko2017-04-111-4/+12
| | | | | | | | | | | | | | | | | | | | 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: Support formatting utf-8 character literals in C++11+ mode.Nico Weber2017-04-051-0/+13
| | | | | | | | | | | | | | | | | | | clang-format <<END auto c1 = u8'a'; auto c2 = u'a'; END Before: auto c1 = u8 'a'; auto c2 = u'a'; Now: auto c1 = u8'a'; auto c2 = u'a'; Patch from Denis Gladkikh <llvm@denis.gladkikh.email>! llvm-svn: 299574
* clang-format: [JS] fix whitespace around "of" operator.Martin Probst2017-04-051-0/+2
| | | | | | | | | | | | | | | | | | | 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 crash in NamespaceEndCommentsFixer (PR32438)Matthias Gehre2017-04-041-0/+15
| | | | | | | | | | | | | | Summary: The new test case was crashing before. Now it passes as expected. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D31441 llvm-svn: 299465
* clang-format: [JavaScript] Ignore QT keywords.Daniel Jasper2017-03-311-0/+2
| | | | llvm-svn: 299204
* Fix issues in clang-format's AlignConsecutive modes.Nikola Smiljanic2017-03-231-5/+82
| | | | | | Patch by Ben Harper. llvm-svn: 298574
* [clang-format] disable adding extra space after MSVC '__super' keywordMartin Probst2017-03-161-0/+4
| | | | | | | | | | | 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: Fix bug in wrapping behavior of operators.Daniel Jasper2017-03-161-0/+3
| | | | | | | | | | | | | Before (even violating the column limit): auto Diag = diag() << aaaaaaaaaaaaaaaa(aaaaaaaaaaaa, aaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaa); After: auto Diag = diag() << aaaaaaaaaaaaaaaa(aaaaaaaaaaaa, aaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaa); llvm-svn: 297931
* clang-format: Make it very slighly more expensive to wrap between "= {".Daniel Jasper2017-03-141-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | 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] do not wrap @see tags.Martin Probst2017-03-131-0/+7
| | | | | | | | | | | | | | | Summary: @see is special among JSDoc tags in that it is commonly followed by URLs. The JSDoc spec suggests that users should wrap URLs in an additional {@link url...} tag (@see http://usejsdoc.org/tags-see.html), but this is very commonly violated, with @see being followed by a "naked" URL. This change special cases all JSDoc lines that contain an @see not to be wrapped to account for that. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D30883 llvm-svn: 297607
* clang-format: [JS] allow breaking after non-null assertions.Martin Probst2017-03-131-0/+6
| | | | | | | | | | | | | | | | 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-0/+14
| | | | | | | | | | | | | | | | | | | | | 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/+12
| | | | | | | | class declaration. Differential Revision: https://reviews.llvm.org/D30487 llvm-svn: 297467
* [clang-format] Look at NoLineBreak and NoLineBreakInOperand before ↵Krasimir Georgiev2017-03-081-2/+87
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | breakProtrudingToken Summary: This patch makes ContinuationIndenter call breakProtrudingToken only if NoLineBreak and NoLineBreakInOperand is false. Previously, clang-format required two runs to converge on the following example with 24 columns: Note that the second operand shouldn't be splitted according to NoLineBreakInOperand, but the token breaker doesn't take that into account: ``` func(a, "long long long long", c); ``` After first run: ``` func(a, "long long " "long long", c); ``` After second run, where NoLineBreakInOperand is taken into account: ``` func(a, "long long " "long long", c); ``` With the patch, clang-format now obtains in one run: ``` func(a, "long long long" "long", c); ``` which is a better token split overall. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D30575 llvm-svn: 297274
* clang-format: Get slightly better at understanding */&.Daniel Jasper2017-03-081-0/+1
| | | | | | | | | | Before: void f() { MACRO(A * const a); } After: void f() { MACRO(A *const a); } llvm-svn: 297268
* [clang-format] Enable comment reflowing in multiline comments containing pragmasKrasimir Georgiev2017-03-081-1/+21
| | | | | | | | | | | | | | | | | Summary: This patch enables comment reflowing of lines not matching the comment pragma regex in multiline comments containing comment pragma lines. Previously, these comments were dumped without being reindented to the result. Reviewers: djasper, mprobst Reviewed By: mprobst Subscribers: klimek, mprobst, cfe-commits Differential Revision: https://reviews.llvm.org/D30697 llvm-svn: 297261
* [clang-format] Followup of D30646 - unbreak the buildAndi-Bogdan Postelnicu2017-03-071-2/+2
| | | | llvm-svn: 297148
* [clang-format] Fixed indent issue when adding a comment at the end of a ↵Andi-Bogdan Postelnicu2017-03-071-0/+5
| | | | | | | | return type in named function declaration. Differential Revision: https://reviews.llvm.org/D30646 llvm-svn: 297143
* [clang-format] Support namespaces ending in semicolonKrasimir Georgiev2017-03-071-1/+84
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch adds support for namespaces ending in semicolon to the namespace comment fixer. source: ``` namespace A { int i; int j; }; ``` clang-format before: ``` namespace A { int i; int j; } // namespace A; ``` clang-format after: ``` namespace A { int i; int j; }; // namespace A ``` Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D30688 llvm-svn: 297140
* [clang-format] Add tests for ambiguous namespaces to the comment fixerKrasimir Georgiev2017-03-061-0/+80
| | | | llvm-svn: 297034
* [clang-format] Make NamespaceEndCommentFixer add at most one commentKrasimir Georgiev2017-03-061-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Until now, NamespaceEndCommentFixer was adding missing comments for every run, which results in multiple end comments for: ``` namespace { int i; int j; } #if A int a = 1; #else int a = 2; #endif ``` result before: ``` namespace { int i; int j; }// namespace // namespace #if A int a = 1; #else int a = 2; #endif ``` result after: ``` namespace { int i; int j; }// namespace #if A int a = 1; #else int a = 2; #endif ``` Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D30659 llvm-svn: 297028
* [clang-format] Use number of unwrapped lines for short namespaceKrasimir Georgiev2017-03-022-14/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch makes the namespace comment fixer use the number of unwrapped lines that a namespace spans to detect it that namespace is short, thus not needing end comments to be added. This is needed to ensure clang-format is idempotent. Previously, a short namespace was detected by the original source code lines. This has the effect of requiring two runs for this example: ``` namespace { class A; } ``` after first run: ``` namespace { class A; } ``` after second run: ``` namespace { class A; } // namespace ``` Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D30528 llvm-svn: 296736
* clang-format: [JS] Properly format object literals with shorthands.Daniel Jasper2017-03-011-0/+5
| | | | | | | | | | | | | | | | | 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-0/+3
| | | | | | | | | | 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] Don't add namespace end comments for unbalanced right braces ↵Krasimir Georgiev2017-03-011-0/+12
| | | | | | after namespace end llvm-svn: 296638
* [clang-format] Add a new flag FixNamespaceComments to FormatStyleKrasimir Georgiev2017-03-011-21/+45
| | | | | | | | | | | | | | | | Summary: This patch enables namespace end comments under a new flag FixNamespaceComments, which is enabled for the LLVM and Google styles. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D30405 llvm-svn: 296632
* Fix r296605 so that stuff in #ifndef SWIG blocks is still formatted.Daniel Jasper2017-03-011-8/+16
| | | | llvm-svn: 296608
* clang-format: Ignore contents of #ifdef SWIG .. #endif blocks.Daniel Jasper2017-03-011-0/+8
| | | | | | | | 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: [Java] Fix bug in enum formatting.Daniel Jasper2017-02-281-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* Blacklist arbitrary @\\w+ JSDoc tags from wrapping.Martin Probst2017-02-281-0/+24
| | | | | | | | | | | | | | | | | | | | Summary: Also limits the blacklisting to only apply when the tag is actually followed by a parameter in curly braces. /** @mods {long.type.must.not.wrap} */ vs /** @const this is a long description that may wrap. */ Reviewers: djasper Subscribers: klimek, krasimir, cfe-commits Differential Revision: https://reviews.llvm.org/D30452 llvm-svn: 296467
* [clang-format] Add a NamespaceEndCommentsFixerKrasimir Georgiev2017-02-272-1/+352
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: [JS] whitespace after async in arrow functions.Martin Probst2017-02-271-0/+2
| | | | | | | | | | | | | | | | | | | 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-0/+7
| | | | | | | | | | | | | | | 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-36/+20
| | | | | | | | 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: Prevent weird line-wraps in complex lambda introducersDaniel Jasper2017-02-201-4/+14
| | | | | | | | | | | | | | | | | | | Before: aaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( [aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa]() -> ::std:: unordered_set<aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa> { // }); After: aaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( [aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa]() -> ::std::unordered_set< aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa> { // }); llvm-svn: 295659
* 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-0/+2
| | | | | | | | | | | | | | | | | | | | 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
* [clang-format] Align block comment decorationsKrasimir Georgiev2017-02-162-8/+196
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch implements block comment decoration alignment. source: ``` /* line 1 * line 2 */ ``` result before: ``` /* line 1 * line 2 */ ``` result after: ``` /* line 1 * line 2 */ ``` Reviewers: djasper, bkramer, klimek Reviewed By: klimek Subscribers: mprobst, cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29943 llvm-svn: 295312
* [clang-format] Remove dead code in FormatTestComments, NFCKrasimir Georgiev2017-02-141-7/+0
| | | | llvm-svn: 295044
* clang-format: don't break code using __has_include, PR31908Nico Weber2017-02-101-0/+5
| | | | llvm-svn: 294772
* [clang-format] Move comment tests to their own file.Krasimir Georgiev2017-02-083-2085/+2177
| | | | | | | | | | | | | | Summary: With a growing suite of comment-related tests, it makes sense to take them out of the main test file. No functional changes. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek, mgorny Differential Revision: https://reviews.llvm.org/D29713 llvm-svn: 294439
* [clang-format] Break before a sequence of line comments aligned with the ↵Krasimir Georgiev2017-02-081-0/+116
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: Fix bad variable declaration detection.Daniel Jasper2017-02-071-0/+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/+12
| | | | | | | | | | | | | | | | | | | | | 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] exclaim preceding regex literals.Martin Probst2017-02-071-0/+1
| | | | | | | | | | | | | | | | | | | | Summary: Regex detection would incorrectly classify a trailing `!` operator (nullability cast) followed by a `/` as the start of a regular expression literal. This fixes code such as: var foo = x()! / 10; Which would previously parse a regexp all the way to the end of the source file (or next `/`). Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29634 llvm-svn: 294304
* clang-format: [JS] handle parenthesized class expressions.Martin Probst2017-02-071-0/+4
| | | | | | | | | | | | | | | | | | | | 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: Fix bug with conflicting BreakBeforeBinaryOperations and ↵Daniel Jasper2017-02-061-0/+38
| | | | | | | | | | | | | | | | 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-0/+4
| | | | llvm-svn: 294009
OpenPOWER on IntegriCloud