summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
Commit message (Collapse)AuthorAgeFilesLines
...
* [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 llvm-svn: 356662
* [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 llvm-svn: 356613
* [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 llvm-svn: 356575
* [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!). llvm-svn: 356449
* [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!). llvm-svn: 356447
* [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(). llvm-svn: 356099
* [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 llvm-svn: 356031
* Revert "[clang-format] [PR25010] AllowShortIfStatementsOnASingleLine not ↵Paul Hoad2019-03-132-26/+10
| | | | | | | | working if an "else" statement is present" This reverts commit b358cbb9b78389e20f7be36e1a98e26515c3ecce. llvm-svn: 356030
* [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 llvm-svn: 356029
* 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 llvm-svn: 355831
* [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 llvm-svn: 355450
* [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 llvm-svn: 355434
* [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 llvm-svn: 355266
* [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. llvm-svn: 355182
* [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 llvm-svn: 355158
* [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 llvm-svn: 355123
* [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 llvm-svn: 354880
* [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 llvm-svn: 354452
* 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 llvm-svn: 354183
* [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 llvm-svn: 353531
* [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 llvm-svn: 353033
* [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 llvm-svn: 352622
* [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 llvm-svn: 352125
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-1929-116/+87
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [clang] Change to range-based invocation of llvm::sortMandeep Singh Grang2019-01-181-1/+1
| | | | llvm-svn: 351573
* clang-format: [JS] support goog.requireType.Martin Probst2019-01-071-0/+1
| | | | | | | | | | | | | | Summary: It's a new primitive for importing symbols, and should be treated like the (previously handled) `goog.require` and `goog.forwardDeclare`. Reviewers: krasimir Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D56385 llvm-svn: 350516
* [clang-format] Do not treat asm clobber [ as ObjCExpr, refinedKrasimir Georgiev2018-11-221-5/+6
| | | | | | | | | | | | | | | | | | | Summary: r346756 refined clang-format to not treat the `[` in `asm (...: [] ..)` as an ObjCExpr. However that's not enough, as we might have a comma-separated list of such clobbers as in the newly added test. This updates the detection to instead look at the Line's first token being `asm` and not mark `[`-s as ObjCExprs in this case. Reviewers: djasper, benhamilton Reviewed By: djasper, benhamilton Subscribers: benhamilton, cfe-commits Differential Revision: https://reviews.llvm.org/D54795 llvm-svn: 347465
* [clang-format] JS: don't treat is: as a type matcherKrasimir Georgiev2018-11-201-2/+15
| | | | | | | | | | | | | | | | Summary: Clang-format is treating all occurences of `is` in js as type matchers. In some cases this is wrong, as it might be a dict key. Reviewers: mprobst Reviewed By: mprobst Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D54753 llvm-svn: 347307
* [clang-format] Do not treat the asm clobber [ as ObjCExprKrasimir Georgiev2018-11-131-2/+3
| | | | | | | | | | | | | | | | | Summary: The opening square of an inline asm clobber was being annotated as an ObjCExpr. This caused, amongst other things, the ObjCGuesser to guess header files containing that pattern as ObjC files. Reviewers: benhamilton Reviewed By: benhamilton Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D54111 llvm-svn: 346756
* [clang-format] Support breaking consecutive string literals for TableGenJordan Rupprecht2018-11-121-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: clang-format can get confused by string literals in TableGen: it knows that strings can be broken up, but doesn't seem to understand how that can be indented across line breaks, and arranges them in a weird triangular pattern. Take this output example from `clang-format tools/llvm-objcopy/ObjcopyOpts.td` (which has now been formatted in rL345896 with this patch applied): ``` defm keep_global_symbols : Eq< "keep-global-symbols", "Reads a list of symbols from <filename> and " "runs as if " "--keep-global-symbol=<symbol> " "is set for each one. " "<filename> " "contains one " "symbol per line " "and may contain " "comments " "beginning " "with" " '#'" ". " "Lead" "ing " ``` Reviewers: alexshap, MaskRay, djasper Reviewed By: MaskRay Subscribers: krasimir, mgorny, cfe-commits Differential Revision: https://reviews.llvm.org/D53952 llvm-svn: 346687
* Fix ClangFormat issue of recognizing ObjC subscript as C++ attributes when ↵Yan Zhang2018-11-091-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | message target is a result of a C-style method. Summary: The issue is that for array subscript like: ``` arr[[Foo() bar]]; ``` ClangFormat will recognize it as C++11 attribute syntax and put a space between 'arr' and first '[', like: ``` arr [[Foo() bar]]; ``` Now it is fixed. Tested with: ``` ninja FormatTests ``` Reviewers: benhamilton Reviewed By: benhamilton Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D54288 llvm-svn: 346566
* [Format] Add debugging to ObjC language guesserBen Hamilton2018-11-051-4/+13
| | | | | | | | | | | | | | | | | Summary: To handle diagnosing bugs where ObjCHeaderStyleGuesser guesses wrong, this diff adds a bit more debug logging to the Objective-C language guesser. Reviewers: krasimir Reviewed By: krasimir Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D54110 llvm-svn: 346144
* [clang-format] tweaked another case of lambda formattingKrasimir Georgiev2018-10-314-5/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This is done in order to improve cases where the lambda's body is moved too far to the right. Consider the following snippet with column limit set to 79: ``` void f() { leader::MakeThisCallHere(&leader_service_, cq_.get(), [this, liveness](const leader::ReadRecordReq& req, std::function<void()> done) { logger_->HandleReadRecord( req, resp, std::move(done)); }); leader::MakeAnother(&leader_service_, cq_.get(), [this, liveness](const leader::ReadRecordReq& req, std::function<void()> done) { logger_->HandleReadRecord( req, resp, std::move(done), a); }); } ``` The tool favors extra indentation for the lambda body and so the code incurs extra wrapping and adjacent calls are indented to a different level. I find this behavior annoying and I'd like the tool to favor new lines and, thus, use the extra width. The fix, reduced, brings the following formatting. Before: function(1, [] { DoStuff(); // }, 1); After: function( 1, [] { DoStuff(); // }, 1); Refer to the new tests in FormatTest.cpp Contributed by oleg.smolsky! Reviewers: djasper, klimek, krasimir Subscribers: cfe-commits, owenpan Tags: #clang Differential Revision: https://reviews.llvm.org/D52676 llvm-svn: 345753
* NFC: Remove the ObjC1/ObjC2 distinction from clang (and related projects)Erik Pilkington2018-10-301-2/+1
| | | | | | | | | | We haven't supported compiling ObjC1 for a long time (and never will again), so there isn't any reason to keep these separate. This patch replaces LangOpts::ObjC1 and LangOpts::ObjC2 with LangOpts::ObjC. Differential revision: https://reviews.llvm.org/D53547 llvm-svn: 345637
* [clang-format] Break before next parameter after a formatted multiline raw ↵Krasimir Georgiev2018-10-251-7/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | string parameter Summary: Currently clang-format breaks before the next parameter after multiline parameters (also recursively for the parent expressions of multiline parameters). However, it fails to do so for formatted multiline raw string literals: ``` $ cat test.cc // Examples // Regular multiline tokens int x = f(R"(multi line)", 2); } int y = g(h(R"(multi line)"), 2); // Formatted multiline tokens int z = f(R"pb(multi: 1 # line: 2)pb", 2); int w = g(h(R"pb(multi: 1 # line: 2)pb"), 2); $ clang-format -style=google test.cc // Examples // Regular multiline tokens int x = f(R"(multi line)", 2); } int y = g(h(R"(multi line)"), 2); // Formatted multiline tokens int z = f(R"pb(multi: 1 # line: 2)pb", 2); int w = g(h(R"pb(multi: 1 # line: 2)pb"), 2); ``` This patch addresses this inconsistency by forcing breaking after multiline formatted raw string literals. This requires a little tweak to the indentation chosen for the contents of a formatted raw string literal: in case when that's a parameter and not the last one, the indentation is based off of the uniform indentation of all of the parameters. Reviewers: sammccall Reviewed By: sammccall Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D52448 llvm-svn: 345242
* Java annotation declaration being handled correctlyHans Wennborg2018-10-191-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | Previously, Java annotation declarations (@interface AnnotationName) were being handled as ObjC interfaces. This caused the brace formatting to mess up, so that when you had a class with an interface defined in it, it would indent the final brace of the class. It used to format this class like so: class A { @interface B {} } But will now just skip the @interface and format it like so: class A { @interface B {} } Patch by Sam Maier! Differential Revision: https://reviews.llvm.org/D53434 llvm-svn: 344789
* [clang-format] Fix BraceWrapping AfterFunction for ObjC methodsBen Hamilton2018-10-121-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: > clang-format --version > clang-format version 7.0.0 (tags/RELEASE_700/final) > echo "@implementation Foo\n- (void)foo:(id)bar\n{\n}\n@end\n" |clang-format -style='{BreakBeforeBraces: Custom, BraceWrapping: {AfterFunction: true}}' ``` @implementation Foo - (void)foo:(id)bar { } @end ``` with patch: > bin/clang-format --version > clang-format version 8.0.0 (trunk 344285) > echo "@implementation Foo\n- (void)foo:(id)bar\n{\n}\n@end\n" |bin/clang-format -style='{BreakBeforeBraces: Custom, BraceWrapping: {AfterFunction: true}}' ``` @implementation Foo - (void)foo:(id)bar { } @end ``` Contributed by hultman@. Reviewers: benhamilton, jolesiak, klimek, Wizard Reviewed By: benhamilton Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D53197 llvm-svn: 344406
* Lift VFS from clang to llvm (NFC)Jonas Devlieghere2018-10-101-3/+4
| | | | | | | | | | | | | | | | | | | This patch moves the virtual file system form clang to llvm so it can be used by more projects. Concretely the patch: - Moves VirtualFileSystem.{h|cpp} from clang/Basic to llvm/Support. - Moves the corresponding unit test from clang to llvm. - Moves the vfs namespace from clang::vfs to llvm::vfs. - Formats the lines affected by this change, mostly this is the result of the added llvm namespace. RFC on the mailing list: http://lists.llvm.org/pipermail/llvm-dev/2018-October/126657.html Differential revision: https://reviews.llvm.org/D52783 llvm-svn: 344140
* clang-format: Don't insert spaces in front of :: for Java 8 Method References.Nico Weber2018-10-051-1/+7
| | | | | | | | | | | | | The existing code kept the space if it was there for identifiers, and it didn't handle `this`. After this patch, for Java `this` is handled in addition to identifiers, and existing space is always stripped between identifier and `::`. Also accept `::` in addition to `.` in front of `<` in `foo::<T>bar` generic calls. Differential Revision: https://reviews.llvm.org/D52842 llvm-svn: 343872
* [clang-format] Java import sorting in clang-formatKrasimir Georgiev2018-10-051-4/+173
| | | | | | Contributed by SamMaier! llvm-svn: 343862
* clang-format: better handle statement macrosFrancois Ferrand2018-10-026-6/+37
| | | | | | | | | | | | | | | | | | | | | | Summary: Some macros are used in the body of function, and actually contain the trailing semicolon: they should thus be automatically followed by a new line, and not get merged with the next line. This is for example the case with Qt's Q_UNUSED macro: void foo(int a, int b) { Q_UNUSED(a) return b; } This patch deals with these cases by introducing a new option to specify list of statement macros. This re-uses the system already in place for foreach macros, to ensure there is no impact on performance. Reviewers: krasimir, djasper, klimek Reviewed By: krasimir Subscribers: acoomans, mgrang, alexfh, klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D33440 llvm-svn: 343602
* [clang-format] Update comment, NFCIKrasimir Georgiev2018-10-011-4/+0
| | | | | | | | The initializer of `ParameterCount` was updated from 1 to 0 in r175165, but the comment was never touched: https://github.com/llvm-mirror/clang/commit/9fc56f2636137fcde8acb38865555ed6c7b84dfd llvm-svn: 343517
* [clang-format] Fix typo in comment, NFCIKrasimir Georgiev2018-10-011-1/+1
| | | | llvm-svn: 343513
* [ClangFormat] 'try' of function-try-block doesn't obey BraceWrappingOwen Pan2018-09-281-0/+2
| | | | | | | | It should respond to AfterFunction, not AfterControlStatement. Fixes PR39067 llvm-svn: 343305
* clang-format: [JS] conditional types.Martin Probst2018-09-272-0/+8
| | | | | | | | | | | | | | | | | | | | | Summary: This change adds some rudimentary support for conditional types. Specifically it avoids breaking before `extends` and `infer` keywords, which are subject to Automatic Semicolon Insertion, so breaking before them creates incorrect syntax. The actual formatting of the type expression is odd, but there is as of yet no clear idea on how to format these. See https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#conditional-types. Reviewers: krasimir Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D52536 llvm-svn: 343179
* llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)Fangrui Song2018-09-262-2/+2
| | | | | | | | | | | | | | Summary: The convenience wrapper in STLExtras is available since rL342102. Reviewers: rsmith, #clang, dblaikie Reviewed By: rsmith, #clang Subscribers: mgrang, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D52576 llvm-svn: 343147
* clang-format: [JS] space after parameter naming.Martin Probst2018-09-261-1/+3
| | | | | | | | | | | | | | | | | | | Summary: Previously: foo(/*bar=*/baz); Now: foo(/*bar=*/ baz); The run-in parameter naming comment is not intended in JS. Reviewers: mboehme Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D52535 llvm-svn: 343080
* [clang-format] Do not merge short case labels if followed by a block.Owen Pan2018-09-211-0/+2
| | | | | | | | | Do not allow short case labels on a single line if the label is followed by a left brace. Fixes PR38926. llvm-svn: 342708
* [clang-Format] Fix indentation of member call after blockIlya Biryukov2018-09-172-1/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: before patch: > echo "test() {([]() -> {int b = 32;return 3;}).as("");});" | clang-format -style=Google ``` test() { ([]() -> { int b = 32; return 3; }) .as(); }); ``` after patch: > echo "test() {([]() -> {int b = 32;return 3;}).as("");});" | clang-format -style=Google ``` test() { ([]() -> { int b = 32; return 3; }).as(); }); ``` Patch by Anders Karlsson (ank)! Reviewers: klimek Reviewed By: klimek Subscribers: danilaml, acoomans, klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D45719 llvm-svn: 342363
* [clang-format] Wrapped block after case label should not be merged into one lineOwen Pan2018-09-131-0/+4
| | | | | | | | PR38854 Differential Revision: http://reviews.llvm.org/D51719 llvm-svn: 342116
OpenPOWER on IntegriCloud