summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
Commit message (Collapse)AuthorAgeFilesLines
...
* clang-format: [JS] Don't indent JavaScript IIFEs.Martin Probst2017-05-091-4/+23
| | | | | | | | | | | | | | | | Because IIFEs[1] are often used like an anonymous namespace around large sections of JavaScript code, it's useful not to indent to them (which effectively reduces the column limit by the indent amount needlessly). It's also common for developers to wrap these around entire files or libraries. When adopting clang-format, changing the indent entire file can reduce the usefulness of the blame annotations. Patch by danbeam, thanks! Differential Revision: https://reviews.llvm.org/D32989 llvm-svn: 302580
* clang-format: [JS] keep triple slash directives intact.Martin Probst2017-05-091-3/+4
| | | | | | | | | | | | | | | | | | | Summary: TypeScript uses triple slash directives of the form: /// <reference path="..."/> For various non-source instructions that should not be wrapped. Reference: https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D32997 llvm-svn: 302523
* [clang-format] Convert AlignEscapedNewlinesLeft to an enum, addingDaniel Jasper2017-05-082-7/+23
| | | | | | | | | | | | | | | | | | | | DontAlign This converts the clang-format option AlignEscapedNewlinesLeft from a boolean to an enum, named AlignEscapedNewlines, with options Left (prev. true), Right (prev. false), and a new option DontAlign. When set to DontAlign, the backslashes are placed just after the last token in each line: #define EXAMPLE \ do { \ int x = aaaaa; \ int b; \ int dddddddddd; \ } while (0) Patch by jtbandes. Thank you! llvm-svn: 302428
* [clang-format] Don’t propagate AvoidBinPacking into argumentDaniel Jasper2017-05-081-0/+4
| | | | | | | | | | | | subexpressions This is an attempt to fix the issue described in a recent email: http://lists.llvm.org/pipermail/cfe-dev/2017-April/053632.html Patch by jtbandes. Thank you! Review: https://reviews.llvm.org/D32475 llvm-svn: 302427
* clang-format: [JS] exponentiation operatorMartin Probst2017-05-042-0/+12
| | | | | | | | | | | | Summary: While its precedence should be higher than multiplicative, LLVM does not have a level for that, so for the time being just treat it as multiplicative. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D32864 llvm-svn: 302156
* clang-format: [JS] parse async function declarations.Martin Probst2017-04-271-6/+8
| | | | | | | | | | | | | | | | | | | | | | | Summary: Previously, clang-format would accidentally parse an async function declaration as a function expression, and thus not insert an unwrapped line for async functions, causing subsequent functions to run into the function: async function f() { x(); } function g() { ... With this change, async functions get parsed as top level function declarations and get their own unwrapped line context. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D32590 llvm-svn: 301538
* clang-format: [JS/Java] ignore Objective-C constructs in JS & Java.Martin Probst2017-04-261-1/+5
| | | | | | | | | | | | | | | | | | | | | | | Summary: Java and JavaScript support annotations and decorators, respectively, that use a leading "@" token. clang-format currently detects this as an Objective-C construct and applies special formatting, for example no whitespace around "=" operators. This change disables the distinction for Java and JavaScript, which leads to normal formatting of single line annotated and initialized properties. Before: class X { @foo() bar=false; } After: class X { @foo() bar = false; } Reviewers: djasper, bkramer Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D32532 llvm-svn: 301399
* formattingMartin Probst2017-04-261-7/+5
| | | | llvm-svn: 301398
* clang-format: [JS] prevent wraps before class members.Martin Probst2017-04-262-1/+9
| | | | | | | | | | | | Summary: In JavaScript/TypeScript, class member definitions that use modifiers can be subject to Automatic Semicolon Insertion (ASI). For example, "class X { get \n foo }" defines a property called "get" and a property called "foo", both with no type annotation. This change prevents wrapping after the modifier keywords (visibility modifiers, static, get and set) to prevent accidental ASI. Reviewers: djasper, bkramer Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D32531 llvm-svn: 301397
* clang-format: Fix bad corner case in formatting of function types.Daniel Jasper2017-04-241-1/+2
| | | | | | | | | | | | | | | | | | | | | | | Before: std::function< LoooooooooooongTemplatedType<SomeType>*( LooooooooooooooooooooongType type)> function; After: std::function< LoooooooooooongTemplatedType< SomeType>*( LooooooooooooooooongType type)> function; clang-format generally avoids having lines like "SomeType>*(" as they lead to parameter lists that don't belong together to be aligned. However, in case it is better than the alternative, which can even be violating the column limit. llvm-svn: 301182
* [clang-format] Replace IncompleteFormat by a struct with LineKrasimir Georgiev2017-04-213-13/+30
| | | | | | | | | | | | | | Summary: This patch replaces the boolean IncompleteFormat that is used to notify the client if an unrecoverable syntax error occurred by a struct that also contains a line number. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D32298 llvm-svn: 300985
* clang-format: Properly match parens of macro parameter lists.Daniel Jasper2017-04-191-3/+4
| | | | | | | No tests yet, but this will be tested by the upcoming: https://reviews.llvm.org/D28462 llvm-svn: 300661
* Fix mishandling of escaped newlines followed by newlines or nuls.Richard Smith2017-04-171-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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/+13
| | | | | | | | | | | | | | | | | | | | | | 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-115-38/+39
| | | | | | | | | | | | | | | | | | | | 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/+1
| | | | | | | | | | | | | | | | | | | 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-2/+6
| | | | | | | | | | | | | | | | | | | 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-1/+1
| | | | | | | | | | | | | | 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: Fix post-commit review comment of r299204, use Style.isCpp().Daniel Jasper2017-03-315-15/+14
| | | | | | Also, while at it, s/IsCpp/isCpp/ so that it follows LLVM style. llvm-svn: 299214
* clang-format: [JavaScript] Ignore QT keywords.Daniel Jasper2017-03-311-1/+3
| | | | llvm-svn: 299204
* Fix issues in clang-format's AlignConsecutive modes.Nikola Smiljanic2017-03-232-43/+105
| | | | | | Patch by Ben Harper. llvm-svn: 298574
* [clang-format] disable adding extra space after MSVC '__super' keywordMartin Probst2017-03-161-1/+1
| | | | | | | | | | | 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/+1
| | | | | | | | | | | | | 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-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | 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-2/+3
| | | | | | | | | | | | | | | 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-132-5/+22
| | | | | | | | | | | | | | | | 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-5/+4
| | | | | | | | | | | | | | | | | | | | | 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-104-4/+34
| | | | | | | | class declaration. Differential Revision: https://reviews.llvm.org/D30487 llvm-svn: 297467
* [clang-format] Use a reference in loop variable; NFCKrasimir Georgiev2017-03-101-1/+1
| | | | llvm-svn: 297455
* [clang-format] Look at NoLineBreak and NoLineBreakInOperand before ↵Krasimir Georgiev2017-03-081-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-1/+2
| | | | | | | | | | Before: void f() { MACRO(A * const a); } After: void f() { MACRO(A *const a); } llvm-svn: 297268
* [clang-format] Fixed a typo in Format.cpp and a clang-tidy nit about ↵Krasimir Georgiev2017-03-081-3/+3
| | | | | | std::function copying; NFC llvm-svn: 297265
* [clang-format] Fix parameter name comment; NFCKrasimir Georgiev2017-03-081-1/+1
| | | | llvm-svn: 297263
* [clang-format] Reformat BreakableToken.h; NFCKrasimir Georgiev2017-03-081-19/+14
| | | | llvm-svn: 297262
* [clang-format] Enable comment reflowing in multiline comments containing pragmasKrasimir Georgiev2017-03-083-12/+17
| | | | | | | | | | | | | | | | | 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] Fixed indent issue when adding a comment at the end of a ↵Andi-Bogdan Postelnicu2017-03-071-2/+2
| | | | | | | | 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-7/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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] Make NamespaceEndCommentFixer add at most one commentKrasimir Georgiev2017-03-061-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Don't write to LLVMStyle.JavaScriptQuotes twice. No behavior change.Nico Weber2017-03-021-1/+0
| | | | llvm-svn: 296749
* [clang-format] Use number of unwrapped lines for short namespaceKrasimir Georgiev2017-03-021-10/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-3/+4
| | | | | | | | | | | | | | | | | 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-2/+5
| | | | | | | | | | 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/+1
| | | | | | after namespace end llvm-svn: 296638
* [clang-format] Add a new flag FixNamespaceComments to FormatStyleKrasimir Georgiev2017-03-011-8/+25
| | | | | | | | | | | | | | | | 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-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: [Java] Fix bug in enum formatting.Daniel Jasper2017-02-281-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | 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-2/+2
| | | | | | | | | | | | | | | | | | | | 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-277-2/+229
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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/+8
| | | | | | | | | | | | | | | | | | | 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
OpenPOWER on IntegriCloud