summaryrefslogtreecommitdiffstats
path: root/lib/Format
Commit message (Collapse)AuthorAgeFilesLines
* [clang-format] Fix bug in block comment reflow that joins * and /Owen Pan2019-05-032-2/+21
| | | | | | | | Fixes PR41213 Differential Revision: https://reviews.llvm.org/D61276 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359943 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] Fix a bug in AlignConsecutiveDeclarations.Owen Pan2019-05-011-3/+15
| | | | | | | | Fixes PR37175 Differential Revision: https://reviews.llvm.org/D61222 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359711 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] Fix bug that misses some function-like macro usagesOwen Pan2019-05-011-4/+9
| | | | | | | | Fixes PR41483 Differential Revision: https://reviews.llvm.org/D61297 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359687 91177308-0d34-0410-b5e6-96231b3b80d8
* Use llvm::stable_sortFangrui Song2019-04-243-14/+10
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359098 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] Fix bug in reflow of block comments containing CR/LFOwen Pan2019-04-234-5/+8
| | | | | | | | Fix PR36119 Differential Revision: https://reviews.llvm.org/D60996 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359029 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] Fix incorrect formatting of keyword macro definitionOwen Pan2019-04-181-1/+1
| | | | | | | | See PR39719 Differential Revision: https://reviews.llvm.org/D60853 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@358710 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] Fix indent of trailing raw string param after newlineKrasimir Georgiev2019-04-182-11/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Currently clang-format uses ContinuationIndent to indent the contents of a raw string literal that is the last parameter of the function call. This is to achieve formatting similar to trailing: ``` f(1, 2, R"pb( x: y)pb"); ``` However this had the unfortunate consequence of producing format like this: ``` fffffff(1, 2, R"pb( a: b )pb"); ``` This patch makes clang-format consider indenting a trailing raw string param after a newline based off the start of the format delimiter, producing: ``` fffffff(1, 2, R"pb( a: b )pb"); ``` Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60558 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@358689 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] Remove unused Environment constructor.Alexander Kornienko2019-04-181-4/+0
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@358630 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] [PR41170] Break after return type ignored with certain ↵Paul Hoad2019-04-151-3/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | comments positions Summary: Addresses https://bugs.llvm.org/show_bug.cgi?id=41170 The AlwaysBreakAfterReturn type setting can go wrong if the line ends with a comment ``` void foo() /* comment */ ``` or ``` void foo() // comment ``` It will incorrectly see such functions as Declarations and not Definitions The following code addresses this by looking for function which end with `; <comment>` rather than just `;` or `<comment>` Reviewers: klimek, djasper, reuk, russellmcc, owenpan, sammccall Reviewed By: owenpan Subscribers: lebedev.ri, cfe-commits, sammccall Tags: #clang Differential Revision: https://reviews.llvm.org/D60363 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@358375 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] Use SpacesBeforeTrailingComments for "option" directiveKrasimir Georgiev2019-04-121-1/+4
| | | | | | | | | | | | | | | | | | | | | | Summary: AnnotatingParser::next() is needed to implicitly set TT_BlockComment versus TT_LineComment. On most other paths through AnnotatingParser::parseLine(), all tokens are consumed to achieve that. This change updates one place where this wasn't done. Contributed by @dchai! Reviewers: krasimir Reviewed By: krasimir Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60541 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@358275 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] Add AfterCaseLabel to BraceWrappingOwen Pan2019-04-082-6/+16
| | | | | | | | Fixes PR38686 llvm-svn: 52527 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@357957 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] Optionally insert a space after unary ! operatorReuben Thomas2019-04-082-1/+4
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@357908 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] Fix bug https://bugs.llvm.org/show_bug.cgi?id=41413Owen Pan2019-04-071-3/+9
| | | | | | Differential Revision: https://reviews.llvm.org/D60374 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@357877 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] Fix Bug 41407Owen Pan2019-04-061-1/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D60359 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@357851 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] BreakAfterReturnType ignored on functions with numeric ↵Paul Hoad2019-04-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | template parameters Summary: Addresses PR40696 - https://bugs.llvm.org/show_bug.cgi?id=40696 The BreakAfterReturnType didn't work if it had a single arguments which was a template with an integer template parameter ``` int foo(A<8> a) { return a; } ``` When run with the Mozilla style. would not break after the `int` ``` int TestFn(A<8> a) { return a; } ``` This revision resolves this issue by allowing numeric constants to be considered function parameters if if seen inside `<>` Reviewers: djasper, klimek, JonasToth, krasimir, reuk, alexfh Reviewed By: klimek Subscribers: cfe-commits, llvm-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D59309 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@357837 91177308-0d34-0410-b5e6-96231b3b80d8
* Updating Chromium's Java import orderNico Weber2019-04-041-3/+10
| | | | | | | | | | Adding in androidx as another import group. Differential Revision: https://reviews.llvm.org/D60203 Patch from Sam Maier <smaier@chromium.org>! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@357700 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] Preserve include blocks in ObjC Google styleKrasimir Georgiev2019-04-041-0/+5
| | | | | | | | | | | | | | | | | | Summary: r357567 started to regroup include block for Google style; it was meant to apply only for C++. This patch reverts this for ObjC. Reviewers: ioeric Reviewed By: ioeric Subscribers: thakis, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60263 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@357695 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] Do not emit replacements while regrouping if Cpp includes are OKKrasimir Georgiev2019-04-031-4/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Currently clang-format would always emit a replacement for multi-block #include sections if `IBS_Regroup`, even if the sections are correct: ``` % cat ~/test.h #include <a.h> #include "b.h" % bin/clang-format --output-replacements-xml -style=google ~/test.h <?xml version='1.0'?> <replacements xml:space='preserve' incomplete_format='false'> <replacement offset='0' length='30'>#include &lt;a.h>&#10;&#10;#include "b.h"</replacement> </replacements> % ``` This change makes clang-format not emit replacements in this case. The logic is similar to the one implemented for Java in r354452. Reviewers: ioeric Reviewed By: ioeric Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60199 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@357599 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] Regroup #includes into blocks for Google styleEric Liu2019-04-031-0/+1
| | | | | | | | | | | | | | | | | Summary: Regrouping #includes in blocks separated by blank lines when sorting C++ #include headers was implemented recently, and it has been preferred in Google's C++ style guide: https://google.github.io/styleguide/cppguide.html#Names_and_Order_of_Includes Reviewers: sammccall, klimek Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60116 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@357567 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] [PR41187] moves Java import statements to the wrong location ↵Paul Hoad2019-03-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | if code contains statements that start with the word import Summary: Import sorting of java file, incorrectly move import statement to after a function beginning with the word import. Make 1 character change to regular expression to ensure there is always at least one space/tab after the word import Previously clang-format --style="LLVM" would format ``` import X; class C { void m() { importFile(); } } ``` as ``` class C { void m() { importFile(); import X; } } ``` Reviewers: djasper, klimek, reuk, JonasToth Reviewed By: klimek Subscribers: cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D59684 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@357345 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format]: Add NonEmptyParentheses spacing optionReuben Thomas2019-03-303-4/+14
| | | | | | | | | | | | | This patch aims to add support for the following rules from the JUCE coding standards: - Always put a space before an open parenthesis that contains text - e.g. foo (123); - Never put a space before an empty pair of open/close parenthesis - e.g. foo(); Patch by Reuben Thomas Differential Revision: https://reviews.llvm.org/D55170 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@357344 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] Add style option AllowShortLambdasOnASingleLineRonald Wampler2019-03-264-6/+35
| | | | | | | | | | | | | | | | | Summary: This option `AllowShortLambdasOnASingleLine` similar to the other `AllowShort*` options, but applied to C++ lambdas. Reviewers: djasper, klimek Reviewed By: klimek Subscribers: MyDeveloperDay, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D57687 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@357027 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] Refine structured binding detectionKrasimir Georgiev2019-03-251-8/+8
| | | | | | | | | | | | | | | | | | | | | Summary: Revision r356575 had the unfortunate consequence that now clang-format never detects an ObjC call expression after `&&`. This patch tries harder to distinguish between C++17 structured bindings and ObjC call expressions and adds a few regression tests. Reviewers: klimek Reviewed By: klimek Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59774 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356928 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert "[clang-format] Keep protobuf "package" statement on one line"Haojian Wu2019-03-251-3/+3
| | | | | | | | | | | | | This reverts commit r356835. This patch causes a regression, see the test below: verifyFormat("// Detached comment\n\n" "// Leading comment\n" "syntax = \"proto2\"; // trailing comment\n\n" "// in foo.bar package\n" "package foo.bar; // foo.bar package\n"); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356912 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] Keep protobuf "package" statement on one linePaul Hoad2019-03-231-3/+3
| | | | | | | | | | | | | | | | | | | | Summary: Top-level "package" and "import" statements should generally be kept on one line, for all languages. Reviewers: sammccall, krasimir, MyDeveloperDay Reviewed By: MyDeveloperDay Subscribers: MyDeveloperDay, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59627 Patch By: dchai (Donald Chai) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356835 91177308-0d34-0410-b5e6-96231b3b80d8
* Clang-format: add finer-grained options for putting all arguments on one linePaul Hoad2019-03-232-6/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Add two new options, AllowAllArgumentsOnNextLine and AllowAllConstructorInitializersOnNextLine. These mirror the existing AllowAllParametersOfDeclarationOnNextLine and allow me to support an internal style guide where I work. I think this would be generally useful, some have asked for it on stackoverflow: https://stackoverflow.com/questions/30057534/clang-format-binpackarguments-not-working-as-expected https://stackoverflow.com/questions/38635106/clang-format-how-to-prevent-all-function-arguments-on-next-line Reviewers: djasper, krasimir, MyDeveloperDay Reviewed By: MyDeveloperDay Subscribers: jkorous, MyDeveloperDay, aol-nnov, lebedev.ri, uohcsemaj, cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D40988 Patch By: russellmcc (Russell McClellan) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356834 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] correctly format protobuf fields named "enum".Paul Hoad2019-03-231-0/+4
| | | | | | | | | | | | | | | | | | Summary: Similar to TypeScript, "enum" is not a reserved word. Reviewers: krasimir, MyDeveloperDay Reviewed By: MyDeveloperDay Subscribers: MyDeveloperDay, cfe-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D59629 Patch by: dchai (Donald Chai) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356833 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] Add basic support for formatting C# filesPaul Hoad2019-03-218-13/+352
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here so I'm sending this revision in to test the water as to whether this might be something we'd consider landing. Tracking in Bugzilla as: https://bugs.llvm.org/show_bug.cgi?id=40850 Justification: C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted. I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++. (Braces/Breaking/Spaces/Indent etc..) Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it fails to compile. Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare. Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how `{ set;get }` is formatted. Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth Reviewed By: klimek Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D58404 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356662 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] BeforeHash added to IndentPPDirectivesPaul Hoad2019-03-204-10/+20
| | | | | | | | | | | | | | | | | | Summary: The option BeforeHash added to IndentPPDirectives. Fixes Bug 36019. https://bugs.llvm.org/show_bug.cgi?id=36019 Reviewers: djasper, klimek, krasimir, sammccall, mprobst, Nicola, MyDeveloperDay Reviewed By: klimek, MyDeveloperDay Subscribers: kadircet, MyDeveloperDay, mnussbaum, geleji, ufna, cfe-commits Patch by to-mix. Differential Revision: https://reviews.llvm.org/D52150 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356613 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] structured binding in range for detected as Objective CPaul Hoad2019-03-201-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Sometime after 6.0.0 and the current trunk 9.0.0 the following code would be considered as objective C and not C++ Reported by: https://twitter.com/mattgodbolt/status/1096188576503644160 $ clang-format.exe test.h Configuration file(s) do(es) not support Objective-C: C:\clang\build\.clang-format --- test.h -- ``` std::vector<std::pair<std::string,std::string>> C; void foo() { for (auto && [A,B] : C) { std::string D = A + B; } } ``` The following code fixes this issue of incorrect detection Reviewers: djasper, klimek, JonasToth, reuk Reviewed By: klimek Subscribers: cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D59546 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356575 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] [JS] handle private members.Martin Probst2019-03-193-0/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Addresses PR40999 https://bugs.llvm.org/show_bug.cgi?id=40999 Private fields and methods in JavaScript would get incorrectly indented (it sees them as preprocessor directives and hence left aligns them) In this revision `#identifier` tokens `tok::hash->tok::identifier` are merged into a single new token `tok::identifier` with the `#` contained inside the TokenText. Before: ``` class Example { pub = 1; static pub2 = "foo"; static #priv2 = "bar"; method() { this.#priv = 5; } static staticMethod() { switch (this.#priv) { case '1': break; } } this.#privateMethod(); // infinite loop } static #staticPrivateMethod() {} } ``` After this fix the code will be correctly indented ``` class Example { pub = 1; #priv = 2; static pub2 = "foo"; static #priv2 = "bar"; method() { this.#priv = 5; } static staticMethod() { switch (this.#priv) { case '1': #priv = 3; break; } } #privateMethod() { this.#privateMethod(); // infinite loop } static #staticPrivateMethod() {} } ``` NOTE: There might be some JavaScript code out there which uses the C processor to preprocess .js files http://www.nongnu.org/espresso/js-cpp.html. It's not clear how this revision or even private fields and methods would interact. Patch originally by MyDeveloperDays (thanks!). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356449 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] [JS] Don't break between template string and tagMartin Probst2019-03-191-0/+5
| | | | | | | | | | | | | | | | | | | Before: const x = veryLongIdentifier `hello`; After: const x = veryLongIdentifier`hello`; While it's allowed to have the template string and tag identifier separated by a line break, currently the clang-format output is not stable when a break is forced. Additionally, disallowing a line break makes it clear that the identifier is actually a tag for a template string. Patch originally by mitchellwills (thanks!). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356447 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] Propagate inferred language to getLLVMStyle() in ↵Jordan Rupprecht2019-03-131-1/+1
| | | | | | | | getPredefinedStyle() rC355158 added an optional language parameter to getLLVMStyle(), but this parameter was not used in getPredefinedStyle(). Because unit tests directly specify the style, this codepath wasn't tested. Add an additional unit test for getStyle(). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356099 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] [PR25010] AllowShortIfStatementsOnASingleLine not working if ↵Paul Hoad2019-03-132-10/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | an "else" statement is present Summary: Addressing: PR25010 - https://bugs.llvm.org/show_bug.cgi?id=25010 Code like: ``` if(true) var++; else { var--; } ``` is reformatted to be ``` if (true) var++; else { var--; } ``` Even when `AllowShortIfStatementsOnASingleLine` is true The following revision comes from a +1'd suggestion in the PR to support AllowShortIfElseStatementsOnASingleLine This suppresses the clause prevents the merging of the if when there is a compound else Reviewers: klimek, djasper, JonasToth, alexfh, krasimir, reuk Reviewed By: reuk Subscribers: reuk, Higuoxing, jdoerfert, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D59087 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356031 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert "[clang-format] [PR25010] AllowShortIfStatementsOnASingleLine not ↵Paul Hoad2019-03-132-26/+10
| | | | | | | | working if an "else" statement is present" This reverts commit b358cbb9b78389e20f7be36e1a98e26515c3ecce. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356030 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] [PR25010] AllowShortIfStatementsOnASingleLine not working if ↵Paul Hoad2019-03-132-10/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | an "else" statement is present Summary: Addressing: PR25010 - https://bugs.llvm.org/show_bug.cgi?id=25010 Code like: ``` if(true) var++; else { var--; } ``` is reformatted to be ``` if (true) var++; else { var--; } ``` Even when `AllowShortIfStatementsOnASingleLine` is true The following revision comes from a +1'd suggestion in the PR to support AllowShortIfElseStatementsOnASingleLine This suppresses the clause prevents the merging of the if when there is a compound else Reviewers: klimek, djasper, JonasToth, alexfh, krasimir, reuk Reviewed By: reuk Subscribers: reuk, Higuoxing, jdoerfert, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D59087 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356029 91177308-0d34-0410-b5e6-96231b3b80d8
* clang-format: distinguish ObjC call subexpressions after r355434Krasimir Georgiev2019-03-111-2/+19
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: The revision r355434 had the unfortunate side-effect that it started to recognize certain ObjC expressions with a call subexpression followed by a `a->b` subexpression as C++ lambda expressions. This patch adds a bit of logic to handle these cases and documents them in tests. The commented-out test cases in the new test suite are ones that were problematic before r355434. Reviewers: MyDeveloperDay, gribozavr Reviewed By: MyDeveloperDay, gribozavr Subscribers: MyDeveloperDay, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59210 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@355831 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] broken after lambda with return type template with boolean ↵Paul Hoad2019-03-051-0/+2
| | | | | | | | | | | | | | | | | | | | | literal Summary: A Lamdba with a return type template with a boolean literal (true,false) behaves differently to an integer literal https://bugs.llvm.org/show_bug.cgi?id=40910 Reviewers: klimek, djasper, JonasToth, alexfh, krasimir, jkorous Reviewed By: jkorous Subscribers: jkorous, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D58922 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@355450 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] Fix lambdas returning template specialization that contains ↵Jan Korous2019-03-051-0/+19
| | | | | | | | | | | | operator in parameter A template specialization of a template foo<int N> can contain integer constants and a whole bunch of operators - e. g. foo< 1 ? !0 : (3+1)%4 > Inspired by https://reviews.llvm.org/D58922 Differential Revision: https://reviews.llvm.org/D58934 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@355434 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] clang-format off/on not respected when using C Style commentsPaul Hoad2019-03-021-2/+3
| | | | | | | | | | | | | | | | | | | Summary: If the clang-format on/off is in a /* comment */ then the sorting of headers is not ignored PR40901 - https://bugs.llvm.org/show_bug.cgi?id=40901 Reviewers: djasper, klimek, JonasToth, krasimir, alexfh Reviewed By: alexfh Subscribers: alexfh, cfe-commits, llvm-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D58819 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@355266 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] [NFC] clang-format the Format libraryPaul Hoad2019-03-0112-123/+96
| | | | | | | | | | | Previously revisions commited non-clang-formatted changes to the Format library, this means submitting any revision e.g. {D55170} can cause additional whitespace changes to potentially be included in a revision. Commit a non functional change using latest build Windows clang-format r351376 with no other changes, to remove these differences All FormatTests pass [==========] 652 tests from 20 test cases ran. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@355182 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format][TableGen] Don't add spaces around items in square braces.Jordan Rupprecht2019-03-011-0/+5
| | | | | | | | | | | | | | | | | | | Summary: clang-formatting wants to add spaces around items in square braces, e.g. [1, 2] -> [ 1, 2 ]. Based on a quick check [1], it seems like most cases are using the [1, 2] format, so make that the consistent one. [1] in llvm `.td` files, the regex `\[[^ ]` (bracket followed by not-a-space) shows up ~400 times, but `\[\s[^ ]` (bracket followed by one space and one not-a-space) shows up ~40 times => ~90% uses this format. Reviewers: djasper, krasimir, MyDeveloperDay Reviewed By: MyDeveloperDay Subscribers: MyDeveloperDay, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D55964 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@355158 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format][NFC] Allow getLLVMStyle() to take a languageJordan Rupprecht2019-02-281-6/+4
| | | | | | | | | | | | | | | | | | | Summary: getLLVMStyle() sets the default style, but doesn't take the language as a parameter, so can't set default parameters when they differ from C++. This change adds LanguageKind as an input to getLLVMStyle so that we can start doing that. See D55964 as a motivation for this, where we want Tablegen to be formatted differently than C++. Reviewers: djasper, krasimir, MyDeveloperDay Reviewed By: MyDeveloperDay Subscribers: jdoerfert, MyDeveloperDay, kristina, cfe-commits, arphaman Tags: #clang Differential Revision: https://reviews.llvm.org/D56943 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@355123 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] SpaceBeforeParens for lambda expressionsAndrew Ng2019-02-261-1/+3
| | | | | | | | | Add support for lambda expressions to the SpaceBeforeParens formatting option. Differential Revision: https://reviews.llvm.org/D58241 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@354880 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] Do not emit replacements if Java imports are OKKrasimir Georgiev2019-02-201-7/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Currently clang-format would always emit a replacement for a block of Java imports even if it is correctly formatted: ``` % cat /tmp/Aggregator.java import X; % clang-format /tmp/Aggregator.java import X; % clang-format -output-replacements-xml /tmp/Aggregator.java <?xml version='1.0'?> <replacements xml:space='preserve' incomplete_format='false'> <replacement offset='0' length='9'>import X;</replacement> </replacements> % ``` This change makes clang-format not emit replacements in this case. Note that there is logic to not emit replacements in this case for C++. Reviewers: ioeric Reviewed By: ioeric Subscribers: jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58436 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@354452 91177308-0d34-0410-b5e6-96231b3b80d8
* clang-format with UseTab: Always sometimes doesn't insert the right amount ↵Alexander Kornienko2019-02-151-4/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | of tabs. Trailing comments are not always aligned properly when UseTab is set to Always. Consider: int a; // x int bbbbbbbb; // x With .clang-format: --- Language: Cpp BasedOnStyle: LLVM UseTab: Always ... The trailing comments of this code block should be aligned, but aren't To align the first trailing comment it needs to insert 8 spaces. This should be one tab plus six spaces. It skips the logic of the first partial tab in FirstTabWidth (=2) + Style.TabWidth (=8) <= Spaces (=8) and only inserts one tab. Proposed fix and test is attached. Patch by Hylke Kleve. Differential revision: https://reviews.llvm.org/D57655 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@354183 91177308-0d34-0410-b5e6-96231b3b80d8
* [Format/ObjC] Fix [foo bar]->baz formatting as lambda arrowBen Hamilton2019-02-082-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Currently, `UnwrappedLineParser` thinks an arrow token after an ObjC method expression is a C++ lambda arrow, so it formats: ``` [foo bar]->baz ``` as: ``` [foo bar] -> baz ``` Because `UnwrappedLineParser` runs before `TokenAnnotator`, it can't know if the arrow token is after an ObjC method expression or not. This diff makes `TokenAnnotator` remove the TT_LambdaArrow on the arrow token if it follows an ObjC method expression. Test Plan: New test added. Ran test with: % ninja FormatTests && ./tools/clang/unittests/Format/FormatTests Confirmed test failed before diff and passed after diff. Reviewers: krasimir, djasper, sammccall Reviewed By: sammccall Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D57923 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@353531 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] Fix breaking of qualified operatorKrasimir Georgiev2019-02-041-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: From https://bugs.llvm.org/show_bug.cgi?id=40516 ``` $ cat a.cpp const NamespaceName::VeryLongClassName &NamespaceName::VeryLongClassName::myFunction() { // do stuff } const NamespaceName::VeryLongClassName &NamespaceName::VeryLongClassName::operator++() { // do stuff } $ ~/ll/build/opt/bin/clang-format -style=LLVM a.cpp const NamespaceName::VeryLongClassName & NamespaceName::VeryLongClassName::myFunction() { // do stuff } const NamespaceName::VeryLongClassName &NamespaceName::VeryLongClassName:: operator++() { // do stuff } ``` What was happening is that the split penalty before `operator` was being set to a smaller value by a prior if block. Moved checks around to fix this and added a regression test. Reviewers: djasper Reviewed By: djasper Tags: #clang Differential Revision: https://reviews.llvm.org/D57604 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@353033 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] Fix line parsing for noexcept lambdasBen Hamilton2019-01-301-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: > $ echo "int c = [b]() mutable noexcept { return [&b] { return b++; }(); }();" |clang-format ``` int c = [b]() mutable noexcept { return [&b] { return b++; }(); } (); ``` with patch: > $ echo "int c = [b]() mutable noexcept { return [&b] { return b++; }(); }();" |bin/clang-format ``` int c = [b]() mutable noexcept { return [&b] { return b++; }(); }(); ``` Contributed by hultman. Reviewers: benhamilton, jolesiak, klimek, Wizard Reviewed By: benhamilton Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D56909 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@352622 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang-format] square parens with one token are not Objective-C message sendsAlex Lorenz2019-01-241-2/+7
| | | | | | | | | | | | | | | The commit r322690 introduced support for ObjC detection in header files. Unfortunately some C headers that use designated initializers are now incorrectly detected as Objective-C. This commit fixes it by ensuring that `[ token ]` is not annotated as an Objective-C message send. rdar://45504376 Differential Revision: https://reviews.llvm.org/D56226 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@352125 91177308-0d34-0410-b5e6-96231b3b80d8