From 324f918438715b4a0d024af5930628c1674f4fcd Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Sat, 19 Jan 2019 08:50:56 +0000 Subject: Update the file headers across all of the LLVM projects in the monorepo 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@351636 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Format/Format.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'include/clang/Format/Format.h') diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index cb37b0c890..4bc0a5c472 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -1,9 +1,8 @@ //===--- Format.h - Format C++ code -----------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// /// -- cgit v1.2.3 From 48d130f239a8fc9dfeda5226608f056acb7188f3 Mon Sep 17 00:00:00 2001 From: Jordan Rupprecht Date: Thu, 28 Feb 2019 19:16:45 +0000 Subject: [clang-format][NFC] Allow getLLVMStyle() to take a language 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 --- include/clang/Format/Format.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include/clang/Format/Format.h') diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index 4bc0a5c472..94cceb30dc 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -1849,7 +1849,8 @@ private: /// Returns a format style complying with the LLVM coding standards: /// http://llvm.org/docs/CodingStandards.html. -FormatStyle getLLVMStyle(); +FormatStyle getLLVMStyle( + FormatStyle::LanguageKind Language = FormatStyle::LanguageKind::LK_Cpp); /// Returns a format style complying with one of Google's style guides: /// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml. -- cgit v1.2.3 From 0ba0294ffd68b08a82fbcf6e132974363331e777 Mon Sep 17 00:00:00 2001 From: Paul Hoad Date: Wed, 13 Mar 2019 08:07:46 +0000 Subject: [clang-format] [PR25010] AllowShortIfStatementsOnASingleLine not working if 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 --- include/clang/Format/Format.h | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'include/clang/Format/Format.h') diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index 94cceb30dc..4d34a559c8 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -241,8 +241,38 @@ struct FormatStyle { /// single line. ShortFunctionStyle AllowShortFunctionsOnASingleLine; + /// Different styles for handling short if lines + enum ShortIfStyle { + /// Never put short ifs on the same line. + /// \code + /// if (a) + /// return ; + /// else { + /// return; + /// } + /// \endcode + SIS_Never, + /// Without else put short ifs on the same line only if + /// the else is not a compound statement. + /// \code + /// if (a) return; + /// else + /// return; + /// \endcode + SIS_WithoutElse, + /// Always put short ifs on the same line if + /// the else is not a compound statement or not. + /// \code + /// if (a) return; + /// else { + /// return; + /// } + /// \endcode + SIS_Always, + }; + /// If ``true``, ``if (a) return;`` can be put on a single line. - bool AllowShortIfStatementsOnASingleLine; + ShortIfStyle AllowShortIfStatementsOnASingleLine; /// If ``true``, ``while (true) continue;`` can be put on a single /// line. -- cgit v1.2.3 From c7f101d7ac7ea1cedaf1915cff124c5bd2f8f9dc Mon Sep 17 00:00:00 2001 From: Paul Hoad Date: Wed, 13 Mar 2019 08:15:03 +0000 Subject: Revert "[clang-format] [PR25010] AllowShortIfStatementsOnASingleLine not 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 --- include/clang/Format/Format.h | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) (limited to 'include/clang/Format/Format.h') diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index 4d34a559c8..94cceb30dc 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -241,38 +241,8 @@ struct FormatStyle { /// single line. ShortFunctionStyle AllowShortFunctionsOnASingleLine; - /// Different styles for handling short if lines - enum ShortIfStyle { - /// Never put short ifs on the same line. - /// \code - /// if (a) - /// return ; - /// else { - /// return; - /// } - /// \endcode - SIS_Never, - /// Without else put short ifs on the same line only if - /// the else is not a compound statement. - /// \code - /// if (a) return; - /// else - /// return; - /// \endcode - SIS_WithoutElse, - /// Always put short ifs on the same line if - /// the else is not a compound statement or not. - /// \code - /// if (a) return; - /// else { - /// return; - /// } - /// \endcode - SIS_Always, - }; - /// If ``true``, ``if (a) return;`` can be put on a single line. - ShortIfStyle AllowShortIfStatementsOnASingleLine; + bool AllowShortIfStatementsOnASingleLine; /// If ``true``, ``while (true) continue;`` can be put on a single /// line. -- cgit v1.2.3 From fed577da962afe517c71a6120ba0b76b66dce648 Mon Sep 17 00:00:00 2001 From: Paul Hoad Date: Wed, 13 Mar 2019 08:26:39 +0000 Subject: [clang-format] [PR25010] AllowShortIfStatementsOnASingleLine not working if 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 --- include/clang/Format/Format.h | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'include/clang/Format/Format.h') diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index 94cceb30dc..4d34a559c8 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -241,8 +241,38 @@ struct FormatStyle { /// single line. ShortFunctionStyle AllowShortFunctionsOnASingleLine; + /// Different styles for handling short if lines + enum ShortIfStyle { + /// Never put short ifs on the same line. + /// \code + /// if (a) + /// return ; + /// else { + /// return; + /// } + /// \endcode + SIS_Never, + /// Without else put short ifs on the same line only if + /// the else is not a compound statement. + /// \code + /// if (a) return; + /// else + /// return; + /// \endcode + SIS_WithoutElse, + /// Always put short ifs on the same line if + /// the else is not a compound statement or not. + /// \code + /// if (a) return; + /// else { + /// return; + /// } + /// \endcode + SIS_Always, + }; + /// If ``true``, ``if (a) return;`` can be put on a single line. - bool AllowShortIfStatementsOnASingleLine; + ShortIfStyle AllowShortIfStatementsOnASingleLine; /// If ``true``, ``while (true) continue;`` can be put on a single /// line. -- cgit v1.2.3 From b8a307083a640d59f6459c7be2a7e6c4f035bd43 Mon Sep 17 00:00:00 2001 From: Jordan Rupprecht Date: Wed, 13 Mar 2019 20:34:34 +0000 Subject: [clang-format][NFC] Include TableGen in enum->string mapping used for debugging Running `clang-format -debug` prints "Unknown" for tablegen files because of this missing mapping, even though it is recognized as a tablegen file. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356097 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Format/Format.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/clang/Format/Format.h') diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index 4d34a559c8..d02f706a62 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -2089,6 +2089,8 @@ inline StringRef getLanguageName(FormatStyle::LanguageKind Language) { return "JavaScript"; case FormatStyle::LK_Proto: return "Proto"; + case FormatStyle::LK_TableGen: + return "TableGen"; case FormatStyle::LK_TextProto: return "TextProto"; default: -- cgit v1.2.3 From 9c0f34221d0091db37913871cdcd7b0c425d9ad9 Mon Sep 17 00:00:00 2001 From: Paul Hoad Date: Wed, 20 Mar 2019 20:49:43 +0000 Subject: [clang-format] BeforeHash added to IndentPPDirectives 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 --- include/clang/Format/Format.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'include/clang/Format/Format.h') diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index d02f706a62..13e36ea7cf 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -1126,7 +1126,16 @@ struct FormatStyle { /// # endif /// #endif /// \endcode - PPDIS_AfterHash + PPDIS_AfterHash, + /// Indents directives before the hash. + /// \code + /// #if FOO + /// #if BAR + /// #include + /// #endif + /// #endif + /// \endcode + PPDIS_BeforeHash }; /// The preprocessor directive indenting style to use. -- cgit v1.2.3 From e2755ead71aa45e2b4e65be9213db0a1fcea62fb Mon Sep 17 00:00:00 2001 From: Paul Hoad Date: Thu, 21 Mar 2019 13:09:22 +0000 Subject: [clang-format] Add basic support for formatting C# files 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 --- include/clang/Format/Format.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include/clang/Format/Format.h') diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index 13e36ea7cf..34a511f654 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -1258,6 +1258,8 @@ struct FormatStyle { LK_None, /// Should be used for C, C++. LK_Cpp, + /// Should be used for C#. + LK_CSharp, /// Should be used for Java. LK_Java, /// Should be used for JavaScript. @@ -1274,6 +1276,7 @@ struct FormatStyle { LK_TextProto }; bool isCpp() const { return Language == LK_Cpp || Language == LK_ObjC; } + bool isCSharp() const { return Language == LK_CSharp; } /// Language, this format style is targeted at. LanguageKind Language; @@ -2090,6 +2093,8 @@ inline StringRef getLanguageName(FormatStyle::LanguageKind Language) { switch (Language) { case FormatStyle::LK_Cpp: return "C++"; + case FormatStyle::LK_CSharp: + return "CSharp"; case FormatStyle::LK_ObjC: return "Objective-C"; case FormatStyle::LK_Java: -- cgit v1.2.3 From c4515d09740be87226d185f7728893d26c5af652 Mon Sep 17 00:00:00 2001 From: Paul Hoad Date: Sat, 23 Mar 2019 14:37:58 +0000 Subject: Clang-format: add finer-grained options for putting all arguments on one line 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 --- include/clang/Format/Format.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'include/clang/Format/Format.h') diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index 34a511f654..40f962016b 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -154,6 +154,38 @@ struct FormatStyle { /// \endcode bool AlignTrailingComments; + /// \brief If a function call or braced initializer list doesn't fit on a + /// line, allow putting all arguments onto the next line, even if + /// ``BinPackArguments`` is ``false``. + /// \code + /// true: + /// callFunction( + /// a, b, c, d); + /// + /// false: + /// callFunction(a, + /// b, + /// c, + /// d); + /// \endcode + bool AllowAllArgumentsOnNextLine; + + /// \brief If a constructor definition with a member initializer list doesn't + /// fit on a single line, allow putting all member initializers onto the next + /// line, if ```ConstructorInitializerAllOnOneLineOrOnePerLine``` is true. + /// Note that this parameter has no effect if + /// ```ConstructorInitializerAllOnOneLineOrOnePerLine``` is false. + /// \code + /// true: + /// MyClass::MyClass() : + /// member0(0), member1(2) {} + /// + /// false: + /// MyClass::MyClass() : + /// member0(0), + /// member1(2) {} + bool AllowAllConstructorInitializersOnNextLine; + /// If the function declaration doesn't fit on a line, /// allow putting all parameters of a function declaration onto /// the next line even if ``BinPackParameters`` is ``false``. @@ -1761,6 +1793,9 @@ struct FormatStyle { AlignEscapedNewlines == R.AlignEscapedNewlines && AlignOperands == R.AlignOperands && AlignTrailingComments == R.AlignTrailingComments && + AllowAllArgumentsOnNextLine == R.AllowAllArgumentsOnNextLine && + AllowAllConstructorInitializersOnNextLine == + R.AllowAllConstructorInitializersOnNextLine && AllowAllParametersOfDeclarationOnNextLine == R.AllowAllParametersOfDeclarationOnNextLine && AllowShortBlocksOnASingleLine == R.AllowShortBlocksOnASingleLine && -- cgit v1.2.3 From 595a8a043129a63c1be5d515e43d27e830ef0294 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 23 Mar 2019 17:57:31 +0000 Subject: Sync some doc changes ClangFormatStyleOptions.rst with doc comments in `Format.h` Summary: These changes were corrected directly in ClangFormatStyleOptions.rst (llvm-svn: 350192 and llvm-svn: 351976) but these sections can be produced automatically using `dump_format_style.py` so sync the corresponding doc comments in `Format.h` as well. Patch by Ronald Wampler Reviewers: eugene, sylvestre.ledru, djasper Reviewed By: sylvestre.ledru Subscribers: jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58186 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356842 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Format/Format.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/clang/Format/Format.h') diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index 40f962016b..fd84c924ff 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -1201,7 +1201,7 @@ struct FormatStyle { /// A vector of prefixes ordered by the desired groups for Java imports. /// - /// Each group is seperated by a newline. Static imports will also follow the + /// Each group is separated by a newline. Static imports will also follow the /// same grouping convention above all non-static imports. One group's prefix /// can be a subset of another - the longest prefix is always matched. Within /// a group, the imports are ordered lexicographically. -- cgit v1.2.3 From 7e997c278b6a5b1e2e39c7242dd854b3d10b58ee Mon Sep 17 00:00:00 2001 From: Ronald Wampler Date: Tue, 26 Mar 2019 20:18:14 +0000 Subject: [clang-format] Add style option AllowShortLambdasOnASingleLine 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 --- include/clang/Format/Format.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'include/clang/Format/Format.h') diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index fd84c924ff..f9d3f03a6c 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -306,6 +306,39 @@ struct FormatStyle { /// If ``true``, ``if (a) return;`` can be put on a single line. ShortIfStyle AllowShortIfStatementsOnASingleLine; + /// Different styles for merging short lambdas containing at most one + /// statement. + enum ShortLambdaStyle { + /// Never merge lambdas into a single line. + SLS_None, + /// Only merge empty lambdas. + /// \code + /// auto lambda = [](int a) {} + /// auto lambda2 = [](int a) { + /// return a; + /// }; + /// \endcode + SLS_Empty, + /// Merge lambda into a single line if argument of a function. + /// \code + /// auto lambda = [](int a) { + /// return a; + /// }; + /// sort(a.begin(), a.end(), ()[] { return x < y; }) + /// \endcode + SLS_Inline, + /// Merge all lambdas fitting on a single line. + /// \code + /// auto lambda = [](int a) {} + /// auto lambda2 = [](int a) { return a; }; + /// \endcode + SLS_All, + }; + + /// Dependent on the value, ``auto lambda []() { return 0; }`` can be put on a + /// single line. + ShortLambdaStyle AllowShortLambdasOnASingleLine; + /// If ``true``, ``while (true) continue;`` can be put on a single /// line. bool AllowShortLoopsOnASingleLine; @@ -1805,6 +1838,7 @@ struct FormatStyle { R.AllowShortFunctionsOnASingleLine && AllowShortIfStatementsOnASingleLine == R.AllowShortIfStatementsOnASingleLine && + AllowShortLambdasOnASingleLine == R.AllowShortLambdasOnASingleLine && AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine && AlwaysBreakAfterReturnType == R.AlwaysBreakAfterReturnType && AlwaysBreakBeforeMultilineStrings == -- cgit v1.2.3 From 5ae8ac7bf165af4ea7d254c2adc4bbc8a7c7b154 Mon Sep 17 00:00:00 2001 From: Reuben Thomas Date: Sat, 30 Mar 2019 12:32:35 +0000 Subject: [clang-format]: Add NonEmptyParentheses spacing option 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 --- include/clang/Format/Format.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'include/clang/Format/Format.h') diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index f9d3f03a6c..f5f93dd8b3 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -1690,6 +1690,17 @@ struct FormatStyle { /// } /// \endcode SBPO_ControlStatements, + /// Put a space before opening parentheses only if the parentheses are not + /// empty i.e. '()' + /// \code + /// void() { + /// if (true) { + /// f(); + /// g (x, y, z); + /// } + /// } + /// \endcode + SBPO_NonEmptyParentheses, /// Always put a space before opening parentheses, except when it's /// prohibited by the syntax rules (in function-like macro definitions) or /// when determined by other style rules (after unary operators, opening -- cgit v1.2.3 From 9a63380260860b657b72f07c4f0e61e382ab934a Mon Sep 17 00:00:00 2001 From: Reuben Thomas Date: Mon, 8 Apr 2019 12:54:48 +0000 Subject: [clang-format] Optionally insert a space after unary ! operator git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@357908 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Format/Format.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include/clang/Format/Format.h') diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index f5f93dd8b3..ac12dcb542 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -1628,6 +1628,13 @@ struct FormatStyle { /// \endcode bool SpaceAfterCStyleCast; + /// If ``true``, a space is inserted after the logical not operator (``!``). + /// \code + /// true: false: + /// ! someExpression(); vs. !someExpression(); + /// \endcode + bool SpaceAfterLogicalNot; + /// If \c true, a space will be inserted after the 'template' keyword. /// \code /// true: false: @@ -1911,6 +1918,7 @@ struct FormatStyle { PointerAlignment == R.PointerAlignment && RawStringFormats == R.RawStringFormats && SpaceAfterCStyleCast == R.SpaceAfterCStyleCast && + SpaceAfterLogicalNot == R.SpaceAfterLogicalNot && SpaceAfterTemplateKeyword == R.SpaceAfterTemplateKeyword && SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators && SpaceBeforeCpp11BracedList == R.SpaceBeforeCpp11BracedList && -- cgit v1.2.3 From 764bd63e5b6b19051d14a3172ee82fb3e83b8857 Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Mon, 8 Apr 2019 23:36:25 +0000 Subject: [clang-format] Add AfterCaseLabel to BraceWrapping Fixes PR38686 llvm-svn: 52527 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@357957 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Format/Format.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'include/clang/Format/Format.h') diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index ac12dcb542..d908b86c89 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -715,6 +715,22 @@ struct FormatStyle { /// AfterClass: true /// \endcode struct BraceWrappingFlags { + /// Wrap case labels. + /// \code + /// false: true: + /// switch (foo) { vs. switch (foo) { + /// case 1: { case 1: + /// bar(); { + /// break; bar(); + /// } break; + /// default: { } + /// plop(); default: + /// } { + /// } plop(); + /// } + /// } + /// \endcode + bool AfterCaseLabel; /// Wrap class definitions. /// \code /// true: -- cgit v1.2.3 From a5afdc4aba951595da88f793488fe431faed8bf1 Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Fri, 26 Apr 2019 07:05:47 +0000 Subject: [clang-format] Fix documentation for FixNamespaceComments Fixes PR40409 Differential Revision: https://reviews.llvm.org/D61174 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359280 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Format/Format.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/clang/Format/Format.h') diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index d908b86c89..fcbe0a7e93 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -1139,7 +1139,7 @@ struct FormatStyle { /// true: false: /// namespace a { vs. namespace a { /// foo(); foo(); - /// } // namespace a; } + /// } // namespace a } /// \endcode bool FixNamespaceComments; -- cgit v1.2.3