[clang-tools-extra] r351261 - [clang-tidy] add options documentation to readability-identifier-naming checker

2019-01-15 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Tue Jan 15 14:06:49 2019
New Revision: 351261

URL: http://llvm.org/viewvc/llvm-project?rev=351261&view=rev
Log:
[clang-tidy] add options documentation to readability-identifier-naming checker

Summary:
The documentation for this clang-checker did not explain what the options are. 
But this checkers only works with at least some options defined.

To discover the options, you have to read the source code. This shouldn't be 
necessary for users who just have access to the clang-tidy binary.

This revision, explains the options and gives an example.

Patch by MyDeveloperDay.

Reviewers: JonasToth, Eugene.Zelenko

Reviewed By: JonasToth

Subscribers: xazax.hun, Eugene.Zelenko

Differential Revision: https://reviews.llvm.org/D56563

Modified:

clang-tools-extra/trunk/docs/clang-tidy/checks/readability-identifier-naming.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-identifier-naming.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/readability-identifier-naming.rst?rev=351261&r1=351260&r2=351261&view=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-identifier-naming.rst
 (original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-identifier-naming.rst
 Tue Jan 15 14:06:49 2019
@@ -5,14 +5,1919 @@ readability-identifier-naming
 
 Checks for identifiers naming style mismatch.
 
-This check will try to enforce coding guidelines on the identifiers naming.
-It supports `lower_case`, `UPPER_CASE`, `camelBack` and `CamelCase` casing and
-tries to convert from one to another if a mismatch is detected.
+This check will try to enforce coding guidelines on the identifiers naming. It
+supports one of the following casing types and tries to convert from one to
+another if a mismatch is detected
 
-It also supports a fixed prefix and suffix that will be prepended or
-appended to the identifiers, regardless of the casing.
+Casing types inclde:
+
+ - ``lower_case``,
+ - ``UPPER_CASE``,
+ - ``camelBack``,
+ - ``CamelCase``,
+ - ``camel_Snake_Back``,
+ - ``Camel_Snake_Case``,
+ - ``aNy_CasE``.
+
+It also supports a fixed prefix and suffix that will be prepended or appended
+to the identifiers, regardless of the casing.
 
 Many configuration options are available, in order to be able to create
-different rules for different kind of identifier. In general, the
-rules are falling back to a more generic rule if the specific case is not
-configured.
+different rules for different kinds of identifiers. In general, the rules are
+falling back to a more generic rule if the specific case is not configured.
+
+Options
+---
+
+The following options are describe below:
+
+ - :option:`AbstractClassCase`, :option:`AbstractClassPrefix`, 
:option:`AbstractClassSuffix`
+ - :option:`ClassCase`, :option:`ClassPrefix`, :option:`ClassSuffix`
+ - :option:`ClassConstantCase`, :option:`ClassConstantPrefix`, 
:option:`ClassConstantSuffix`
+ - :option:`ClassMemberCase`, :option:`ClassMemberPrefix`, 
:option:`ClassMemberSuffix`
+ - :option:`ClassMethodCase`, :option:`ClassMethodPrefix`, 
:option:`ClassMethodSuffix`
+ - :option:`ConstantCase`, :option:`ConstantPrefix`, :option:`ConstantSuffix`
+ - :option:`ConstantMemberCase`, :option:`ConstantMemberPrefix`, 
:option:`ConstantMemberSuffix`
+ - :option:`ConstantParameterCase`, :option:`ConstantParameterPrefix`, 
:option:`ConstantParameterSuffix`
+ - :option:`ConstantPointerParameterCase`, 
:option:`ConstantPointerParameterPrefix`, 
:option:`ConstantPointerParameterSuffix`
+ - :option:`ConstexprFunctionCase`, :option:`ConstexprFunctionPrefix`, 
:option:`ConstexprFunctionSuffix`
+ - :option:`ConstexprMethodCase`, :option:`ConstexprMethodPrefix`, 
:option:`ConstexprMethodSuffix`
+ - :option:`ConstexprVariableCase`, :option:`ConstexprVariablePrefix`, 
:option:`ConstexprVariableSuffix`
+ - :option:`EnumCase`, :option:`EnumPrefix`, :option:`EnumSuffix`
+ - :option:`EnumConstantCase`, :option:`EnumConstantPrefix`, 
:option:`EnumConstantSuffix`
+ - :option:`FunctionCase`, :option:`FunctionPrefix`, :option:`FunctionSuffix`
+ - :option:`GlobalConstantCase`, :option:`GlobalConstantPrefix`, 
:option:`GlobalConstantSuffix`
+ - :option:`GlobalConstantPointerCase`, :option:`GlobalConstantPointerPrefix`, 
:option:`GlobalConstantPointerSuffix`
+ - :option:`GlobalFunctionCase`, :option:`GlobalFunctionPrefix`, 
:option:`GlobalFunctionSuffix`
+ - :option:`GlobalPointerCase`, :option:`GlobalPointerPrefix`, 
:option:`GlobalPointerSuffix`
+ - :option:`GlobalVariableCase`, :option:`GlobalVariablePrefix`, 
:option:`GlobalVariableSuffix`
+ - :option:`InlineNamespaceCase`, :option:`InlineNamespacePrefix`, 
:option:`InlineNamespaceSuffix`
+ - :option:`LocalConstantCase`, :option:`LocalConstantPrefix`, 
:option:`LocalConstantSuffix`
+ - :option:`LocalConstantPointerCase`, :option:`LocalConstantPointerPrefix`, 
:option:`Loca

[clang-tools-extra] r355132 - [clang-tidy] add OverrideMacro to modernize-use-override check

2019-02-28 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Thu Feb 28 12:00:48 2019
New Revision: 355132

URL: http://llvm.org/viewvc/llvm-project?rev=355132&view=rev
Log:
[clang-tidy] add OverrideMacro to modernize-use-override check

Summary:
The usefulness of **modernize-use-override** can be reduced if you have to live 
in an environment where you support multiple compilers, some of which sadly are 
not yet fully C++11 compliant

some codebases have to use override as a macro OVERRIDE e.g.

```
// GCC 4.7 supports explicit virtual overrides when C++11 support is enabled.
```

This allows code to be compiled with C++11 compliant compilers and get warnings 
and errors that clang, MSVC,gcc can give, while still allowing other legacy pre 
C++11 compilers to compile the code. This can be an important step towards 
modernizing C++ code whilst living in a legacy codebase.

When it comes to clang tidy, the use of the **modernize-use-override** is one 
of the most useful checks, but the messages reported are inaccurate for that 
codebase if the standard approach is to use the macros OVERRIDE and/or FINAL.

When combined with fix-its that introduce the C++11 override keyword, they 
become fatal, resulting in the modernize-use-override check being turned off to 
prevent the introduction of such errors.

This revision, allows the possibility for the replacement **override **to be a 
macro instead, Allowing the clang-tidy check to be run on  both pre and post 
C++11 code, and allowing fix-its to be applied.

Reviewers: alexfh, JonasToth, hokein, Eugene.Zelenko, aaron.ballman

Reviewed By: alexfh, JonasToth

Subscribers: lewmpk, malcolm.parsons, jdoerfert, xazax.hun, cfe-commits, 
llvm-commits

Tags: #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D57087

Added:

clang-tools-extra/trunk/test/clang-tidy/modernize-use-override-with-macro.cpp

clang-tools-extra/trunk/test/clang-tidy/modernize-use-override-with-no-macro-inscope.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.h
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-override.rst

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp?rev=355132&r1=355131&r2=355132&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp Thu Feb 
28 12:00:48 2019
@@ -17,8 +17,16 @@ namespace clang {
 namespace tidy {
 namespace modernize {
 
+UseOverrideCheck::UseOverrideCheck(StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IgnoreDestructors(Options.get("IgnoreDestructors", false)),
+  OverrideSpelling(Options.get("OverrideSpelling", "override")),
+  FinalSpelling(Options.get("FinalSpelling", "final")) {}
+
 void UseOverrideCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "IgnoreDestructors", IgnoreDestructors);
+  Options.store(Opts, "OverrideSpelling", OverrideSpelling);
+  Options.store(Opts, "FinalSpelling", FinalSpelling);
 }
 
 void UseOverrideCheck::registerMatchers(MatchFinder *Finder) {
@@ -78,6 +86,8 @@ void UseOverrideCheck::check(const Match
   const auto *Method = Result.Nodes.getNodeAs("method");
   const SourceManager &Sources = *Result.SourceManager;
 
+  ASTContext &Context = *Result.Context;
+
   assert(Method != nullptr);
   if (Method->getInstantiatedFromMemberFunction() != nullptr)
 Method = Method->getInstantiatedFromMemberFunction();
@@ -97,25 +107,24 @@ void UseOverrideCheck::check(const Match
 return; // Nothing to do.
 
   std::string Message;
-
   if (OnlyVirtualSpecified) {
-Message =
-"prefer using 'override' or (rarely) 'final' instead of 'virtual'";
+Message = "prefer using '%0' or (rarely) '%1' instead of 'virtual'";
   } else if (KeywordCount == 0) {
-Message = "annotate this function with 'override' or (rarely) 'final'";
+Message = "annotate this function with '%0' or (rarely) '%1'";
   } else {
 StringRef Redundant =
-HasVirtual ? (HasOverride && HasFinal ? "'virtual' and 'override' are"
+HasVirtual ? (HasOverride && HasFinal ? "'virtual' and '%0' are"
   : "'virtual' is")
-   : "'override' is";
-StringRef Correct = HasFinal ? "'final'" : "'override'";
+   : "'%0' is";
+StringRef Correct = HasFinal ? "'%1'" : "'%0'";
 
 Message = (llvm::Twine(Redundant) +
" redundant since the function is already declared " + Correct)
   .str();
   }
 
-  DiagnosticBuilder Diag = diag(Method->getLocation(), Message);
+  auto Diag = diag(Method->getLoca

r355182 - [clang-format] [NFC] clang-format the Format library

2019-03-01 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Fri Mar  1 01:09:54 2019
New Revision: 355182

URL: http://llvm.org/viewvc/llvm-project?rev=355182&view=rev
Log:
[clang-format] [NFC] clang-format the Format library

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.

Modified:
cfe/trunk/lib/Format/BreakableToken.cpp
cfe/trunk/lib/Format/BreakableToken.h
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/FormatToken.h
cfe/trunk/lib/Format/FormatTokenLexer.h
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/lib/Format/UnwrappedLineFormatter.h
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.h
cfe/trunk/lib/Format/WhitespaceManager.cpp

Modified: cfe/trunk/lib/Format/BreakableToken.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=355182&r1=355181&r2=355182&view=diff
==
--- cfe/trunk/lib/Format/BreakableToken.cpp (original)
+++ cfe/trunk/lib/Format/BreakableToken.cpp Fri Mar  1 01:09:54 2019
@@ -62,12 +62,10 @@ static StringRef getLineCommentIndentPre
   return LongestPrefix;
 }
 
-static BreakableToken::Split getCommentSplit(StringRef Text,
- unsigned ContentStartColumn,
- unsigned ColumnLimit,
- unsigned TabWidth,
- encoding::Encoding Encoding,
- const FormatStyle &Style) {
+static BreakableToken::Split
+getCommentSplit(StringRef Text, unsigned ContentStartColumn,
+unsigned ColumnLimit, unsigned TabWidth,
+encoding::Encoding Encoding, const FormatStyle &Style) {
   LLVM_DEBUG(llvm::dbgs() << "Comment split: \"" << Text
   << "\", Column limit: " << ColumnLimit
   << ", Content start: " << ContentStartColumn << 
"\n");
@@ -191,7 +189,7 @@ bool switchesFormatting(const FormatToke
 
 unsigned
 BreakableToken::getLengthAfterCompression(unsigned RemainingTokenColumns,
-  Split Split) const {
+  Split Split) const {
   // Example: consider the content
   // lala  lala
   // - RemainingTokenColumns is the original number of columns, 10;
@@ -870,23 +868,20 @@ void BreakableLineCommentSection::reflow
 // the next line.
 unsigned WhitespaceLength =
 Lines[LineIndex].data() - tokenAt(LineIndex).TokenText.data() - Offset;
-Whitespaces.replaceWhitespaceInToken(*Tokens[LineIndex],
- Offset,
+Whitespaces.replaceWhitespaceInToken(*Tokens[LineIndex], Offset,
  /*ReplaceChars=*/WhitespaceLength,
  /*PreviousPostfix=*/"",
  /*CurrentPrefix=*/"",
  /*InPPDirective=*/false,
  /*Newlines=*/0,
  /*Spaces=*/0);
-
   }
   // Replace the indent and prefix of the token with the reflow prefix.
   unsigned Offset =
   Lines[LineIndex].data() - tokenAt(LineIndex).TokenText.data();
   unsigned WhitespaceLength =
   Content[LineIndex].data() - Lines[LineIndex].data();
-  Whitespaces.replaceWhitespaceInToken(*Tokens[LineIndex],
-   Offset,
+  Whitespaces.replaceWhitespaceInToken(*Tokens[LineIndex], Offset,
/*ReplaceChars=*/WhitespaceLength,
/*PreviousPostfix=*/"",
/*CurrentPrefix=*/ReflowPrefix,

Modified: cfe/trunk/lib/Format/BreakableToken.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.h?rev=355182&r1=355181&r2=355182&view=diff
==
--- cfe/trunk/lib/Format/BreakableToken.h (original)
+++ cfe/trunk/lib/Format/BreakableToken.h Fri Mar  1 01:09:54 2019
@@ -146,9 +146,7 @@ public:
   //  * @param loong line
   //  * continuation
   //  */
-  virtual unsigned getContentIndent(unsigned LineIndex) const {
-return 0;
-  }
+  virtual unsigned getContentIndent(unsigned LineIndex) const { return 0; }
 
   /// Returns a range (offset, length) at which to break the l

r355266 - [clang-format] clang-format off/on not respected when using C Style comments

2019-03-02 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Sat Mar  2 01:08:51 2019
New Revision: 355266

URL: http://llvm.org/viewvc/llvm-project?rev=355266&view=rev
Log:
[clang-format] clang-format off/on not respected when using C Style comments

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

Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/SortIncludesTest.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=355266&r1=355265&r2=355266&view=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Sat Mar  2 01:08:51 2019
@@ -1786,9 +1786,10 @@ tooling::Replacements sortCppIncludes(co
 Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev);
 
 StringRef Trimmed = Line.trim();
-if (Trimmed == "// clang-format off")
+if (Trimmed == "// clang-format off" || Trimmed == "/* clang-format off 
*/")
   FormattingOff = true;
-else if (Trimmed == "// clang-format on")
+else if (Trimmed == "// clang-format on" ||
+ Trimmed == "/* clang-format on */")
   FormattingOff = false;
 
 const bool EmptyLineSkipped =

Modified: cfe/trunk/unittests/Format/SortIncludesTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/SortIncludesTest.cpp?rev=355266&r1=355265&r2=355266&view=diff
==
--- cfe/trunk/unittests/Format/SortIncludesTest.cpp (original)
+++ cfe/trunk/unittests/Format/SortIncludesTest.cpp Sat Mar  2 01:08:51 2019
@@ -117,6 +117,43 @@ TEST_F(SortIncludesTest, SupportClangFor
  "// clang-format on\n"));
 }
 
+TEST_F(SortIncludesTest, SupportClangFormatOffCStyle) {
+  EXPECT_EQ("#include \n"
+"#include \n"
+"#include \n"
+"/* clang-format off */\n"
+"#include \n"
+"#include \n"
+"#include \n"
+"/* clang-format on */\n",
+sort("#include \n"
+ "#include \n"
+ "#include \n"
+ "/* clang-format off */\n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "/* clang-format on */\n"));
+
+  // Not really turning it off
+  EXPECT_EQ("#include \n"
+"#include \n"
+"#include \n"
+"/* clang-format offically */\n"
+"#include \n"
+"#include \n"
+"#include \n"
+"/* clang-format onwards */\n",
+sort("#include \n"
+ "#include \n"
+ "#include \n"
+ "/* clang-format offically */\n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "/* clang-format onwards */\n"));
+}
+
 TEST_F(SortIncludesTest, IncludeSortingCanBeDisabled) {
   FmtStyle.SortIncludes = false;
   EXPECT_EQ("#include \"a.h\"\n"


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r355450 - [clang-format] broken after lambda with return type template with boolean literal

2019-03-05 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Tue Mar  5 14:20:25 2019
New Revision: 355450

URL: http://llvm.org/viewvc/llvm-project?rev=355450&view=rev
Log:
[clang-format] broken after lambda with return type template with boolean 
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

Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=355450&r1=355449&r2=355450&view=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Tue Mar  5 14:20:25 2019
@@ -1442,6 +1442,8 @@ bool UnwrappedLineParser::tryToParseLamb
 case tok::lessequal:
 case tok::question:
 case tok::colon:
+case tok::kw_true:
+case tok::kw_false:
   nextToken();
   break;
 case tok::arrow:

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=355450&r1=355449&r2=355450&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Mar  5 14:20:25 2019
@@ -11936,6 +11936,21 @@ TEST_F(FormatTest, FormatsLambdas) {
   "// broken:\n"
   "auto foo{[]() -> foo<2 ? 1 : 0> { return {}; }};\n"
   "} // namespace bar");
+  verifyFormat("[]() -> a<1> {};");
+  verifyFormat("[]() -> a<1> { ; };");
+  verifyFormat("[]() -> a<1> { ; }();");
+  verifyFormat("[a, a]() -> a {};");
+  verifyFormat("[]() -> a {};");
+  verifyFormat("[]() -> a { ; };");
+  verifyFormat("[]() -> a { ; }();");
+  verifyFormat("[a, a]() -> a {};");
+  verifyFormat("[]() -> a {};");
+  verifyFormat("[]() -> a { ; };");
+  verifyFormat("[]() -> a { ; }();");
+  verifyFormat("auto foo{[]() -> foo { ; }};");
+  verifyFormat("namespace bar {\n"
+   "auto foo{[]() -> foo { ; }};\n"
+   "} // namespace bar");
   verifyFormat("auto  = [](int i, // break for some reason\n"
"   int j) -> int {\n"
"  return (i * 
j);\n"


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r356029 - [clang-format] [PR25010] AllowShortIfStatementsOnASingleLine not working if an "else" statement is present

2019-03-13 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Wed Mar 13 01:07:46 2019
New Revision: 356029

URL: http://llvm.org/viewvc/llvm-project?rev=356029&view=rev
Log:
[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

Modified:

clang-tools-extra/trunk/docs/clang-tidy/checks/readability-identifier-naming.rst
clang-tools-extra/trunk/docs/conf.py

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-identifier-naming.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/readability-identifier-naming.rst?rev=356029&r1=356028&r2=356029&view=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-identifier-naming.rst
 (original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-identifier-naming.rst
 Wed Mar 13 01:07:46 2019
@@ -9,7 +9,7 @@ This check will try to enforce coding gu
 supports one of the following casing types and tries to convert from one to
 another if a mismatch is detected
 
-Casing types inclde:
+Casing types include:
 
  - ``lower_case``,
  - ``UPPER_CASE``,

Modified: clang-tools-extra/trunk/docs/conf.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/conf.py?rev=356029&r1=356028&r2=356029&view=diff
==
--- clang-tools-extra/trunk/docs/conf.py (original)
+++ clang-tools-extra/trunk/docs/conf.py Wed Mar 13 01:07:46 2019
@@ -26,7 +26,7 @@ from datetime import date
 
 # Add any Sphinx extension module names here, as strings. They can be 
extensions
 # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
-extensions = ['sphinx.ext.todo', 'sphinx.ext.mathjax']
+extensions = ['sphinx.ext.todo', 'sphinx.ext.mathjax', 
'sphinxcontrib.spelling' ]
 
 # Add any paths that contain templates here, relative to this directory.
 templates_path = ['_templates']


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r356029 - [clang-format] [PR25010] AllowShortIfStatementsOnASingleLine not working if an "else" statement is present

2019-03-13 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Wed Mar 13 01:07:46 2019
New Revision: 356029

URL: http://llvm.org/viewvc/llvm-project?rev=356029&view=rev
Log:
[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

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
cfe/trunk/unittests/Format/FormatTestSelective.cpp

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=356029&r1=356028&r2=356029&view=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Wed Mar 13 01:07:46 2019
@@ -365,10 +365,47 @@ the configuration (without a prefix: ``A
   };
   void f() { bar(); }
 
+**AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``)
+  Dependent on the value, ``if (a) return 0;`` can be put on a
+  single line.
 
+  Possible values:
 
-**AllowShortIfStatementsOnASingleLine** (``bool``)
-  If ``true``, ``if (a) return;`` can be put on a single line.
+  * ``SIS_Never`` (in configuration: ``Never``)
+Do not allow short if functions.
+
+.. code-block:: c++
+
+   if (a)
+ return;
+   else
+ return;
+
+  * ``SIS_WithoutElse`` (in configuration: ``WithoutElse``)
+Allow short if functions on the same line, as long as else
+is not a compound statement.
+
+.. code-block:: c++
+
+   if (a) return;
+   else
+ return;
+
+   if (a)
+ return;
+   else {
+ return;
+   }
+
+  * ``SIS_Always`` (in configuration: ``Always``)
+Allow short if statements even if the else is a compound statement.
+
+.. code-block:: c++
+
+   if (a) return;
+   else {
+  return;
+   }
 
 **AllowShortLoopsOnASingleLine** (``bool``)
   If ``true``, ``while (true) continue;`` can be put on a single

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=356029&r1=356028&r2=356029&view=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Wed Mar 13 01:07:46 2019
@@ -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.

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=356029&r1=356028&r2=356029&view=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Mar 13 01:07:46 2019
@@ -106,6 +106,18 @@ template <> struct ScalarEnumerationTrai
   }
 };
 
+template <> struct ScalarEnumerationTraits {
+  static void enumeration(IO &IO, FormatStyle::ShortIfStyle &Value) {
+IO.enumCase(Value, "Never", FormatStyle::SIS_Never);
+IO.enumCase(Value, "Always", FormatStyle::SIS_Always);
+IO.enumCase(Value

r356030 - Revert "[clang-format] [PR25010] AllowShortIfStatementsOnASingleLine not working if an "else" statement is present"

2019-03-13 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Wed Mar 13 01:15:03 2019
New Revision: 356030

URL: http://llvm.org/viewvc/llvm-project?rev=356030&view=rev
Log:
Revert "[clang-format] [PR25010] AllowShortIfStatementsOnASingleLine not 
working if an "else" statement is present"

This reverts commit b358cbb9b78389e20f7be36e1a98e26515c3ecce.

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
cfe/trunk/unittests/Format/FormatTestSelective.cpp

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=356030&r1=356029&r2=356030&view=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Wed Mar 13 01:15:03 2019
@@ -365,47 +365,10 @@ the configuration (without a prefix: ``A
   };
   void f() { bar(); }
 
-**AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``)
-  Dependent on the value, ``if (a) return 0;`` can be put on a
-  single line.
 
-  Possible values:
 
-  * ``SIS_Never`` (in configuration: ``Never``)
-Do not allow short if functions.
-
-.. code-block:: c++
-
-   if (a)
- return;
-   else
- return;
-
-  * ``SIS_WithoutElse`` (in configuration: ``WithoutElse``)
-Allow short if functions on the same line, as long as else
-is not a compound statement.
-
-.. code-block:: c++
-
-   if (a) return;
-   else
- return;
-
-   if (a)
- return;
-   else {
- return;
-   }
-
-  * ``SIS_Always`` (in configuration: ``Always``)
-Allow short if statements even if the else is a compound statement.
-
-.. code-block:: c++
-
-   if (a) return;
-   else {
-  return;
-   }
+**AllowShortIfStatementsOnASingleLine** (``bool``)
+  If ``true``, ``if (a) return;`` can be put on a single line.
 
 **AllowShortLoopsOnASingleLine** (``bool``)
   If ``true``, ``while (true) continue;`` can be put on a single

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=356030&r1=356029&r2=356030&view=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Wed Mar 13 01:15:03 2019
@@ -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.

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=356030&r1=356029&r2=356030&view=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Mar 13 01:15:03 2019
@@ -106,18 +106,6 @@ template <> struct ScalarEnumerationTrai
   }
 };
 
-template <> struct ScalarEnumerationTraits {
-  static void enumeration(IO &IO, FormatStyle::ShortIfStyle &Value) {
-IO.enumCase(Value, "Never", FormatStyle::SIS_Never);
-IO.enumCase(Value, "Always", FormatStyle::SIS_Always);
-IO.enumCase(Value, "WithoutElse", FormatStyle::SIS_WithoutElse);
-
-// For backward compatibility.
-IO.enumCase(Value, "false", FormatStyle::SIS_Never);
-IO.enumCase(Value, "true", FormatStyle::SIS_WithoutElse);
-  }
-};
-
 template <> struct ScalarEnumerationTraits {
   static void enumeration(IO &IO, FormatStyle::BinPackStyle &Value) {
 IO.enumCase(Value, "Auto", FormatStyle::BPS_Auto);
@@ -643,7 +631,7 @@ FormatStyle getLLVMStyle(FormatStyle::La
   LLVMStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All;
   LLVMStyle.AllowShortBlocksOnASingleLine = false;
   LLVMStyle.AllowShortCaseLabelsOnASingleLine = false;
- 

[clang-tools-extra] r356030 - Revert "[clang-format] [PR25010] AllowShortIfStatementsOnASingleLine not working if an "else" statement is present"

2019-03-13 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Wed Mar 13 01:15:03 2019
New Revision: 356030

URL: http://llvm.org/viewvc/llvm-project?rev=356030&view=rev
Log:
Revert "[clang-format] [PR25010] AllowShortIfStatementsOnASingleLine not 
working if an "else" statement is present"

This reverts commit b358cbb9b78389e20f7be36e1a98e26515c3ecce.

Modified:

clang-tools-extra/trunk/docs/clang-tidy/checks/readability-identifier-naming.rst
clang-tools-extra/trunk/docs/conf.py

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-identifier-naming.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/readability-identifier-naming.rst?rev=356030&r1=356029&r2=356030&view=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-identifier-naming.rst
 (original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-identifier-naming.rst
 Wed Mar 13 01:15:03 2019
@@ -9,7 +9,7 @@ This check will try to enforce coding gu
 supports one of the following casing types and tries to convert from one to
 another if a mismatch is detected
 
-Casing types include:
+Casing types inclde:
 
  - ``lower_case``,
  - ``UPPER_CASE``,

Modified: clang-tools-extra/trunk/docs/conf.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/conf.py?rev=356030&r1=356029&r2=356030&view=diff
==
--- clang-tools-extra/trunk/docs/conf.py (original)
+++ clang-tools-extra/trunk/docs/conf.py Wed Mar 13 01:15:03 2019
@@ -26,7 +26,7 @@ from datetime import date
 
 # Add any Sphinx extension module names here, as strings. They can be 
extensions
 # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
-extensions = ['sphinx.ext.todo', 'sphinx.ext.mathjax', 
'sphinxcontrib.spelling' ]
+extensions = ['sphinx.ext.todo', 'sphinx.ext.mathjax']
 
 # Add any paths that contain templates here, relative to this directory.
 templates_path = ['_templates']


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r356031 - [clang-format] [PR25010] AllowShortIfStatementsOnASingleLine not working if an "else" statement is present

2019-03-13 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Wed Mar 13 01:26:39 2019
New Revision: 356031

URL: http://llvm.org/viewvc/llvm-project?rev=356031&view=rev
Log:
[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

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
cfe/trunk/unittests/Format/FormatTestSelective.cpp

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=356031&r1=356030&r2=356031&view=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Wed Mar 13 01:26:39 2019
@@ -365,10 +365,47 @@ the configuration (without a prefix: ``A
   };
   void f() { bar(); }
 
+**AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``)
+  Dependent on the value, ``if (a) return 0;`` can be put on a
+  single line.
 
+  Possible values:
 
-**AllowShortIfStatementsOnASingleLine** (``bool``)
-  If ``true``, ``if (a) return;`` can be put on a single line.
+  * ``SIS_Never`` (in configuration: ``Never``)
+Do not allow short if functions.
+
+.. code-block:: c++
+
+   if (a)
+ return;
+   else
+ return;
+
+  * ``SIS_WithoutElse`` (in configuration: ``WithoutElse``)
+Allow short if functions on the same line, as long as else
+is not a compound statement.
+
+.. code-block:: c++
+
+   if (a) return;
+   else
+ return;
+
+   if (a)
+ return;
+   else {
+ return;
+   }
+
+  * ``SIS_Always`` (in configuration: ``Always``)
+Allow short if statements even if the else is a compound statement.
+
+.. code-block:: c++
+
+   if (a) return;
+   else {
+  return;
+   }
 
 **AllowShortLoopsOnASingleLine** (``bool``)
   If ``true``, ``while (true) continue;`` can be put on a single

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=356031&r1=356030&r2=356031&view=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Wed Mar 13 01:26:39 2019
@@ -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.

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=356031&r1=356030&r2=356031&view=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Mar 13 01:26:39 2019
@@ -106,6 +106,18 @@ template <> struct ScalarEnumerationTrai
   }
 };
 
+template <> struct ScalarEnumerationTraits {
+  static void enumeration(IO &IO, FormatStyle::ShortIfStyle &Value) {
+IO.enumCase(Value, "Never", FormatStyle::SIS_Never);
+IO.enumCase(Value, "Always", FormatStyle::SIS_Always);
+IO.enumCase(Value

r356575 - [clang-format] structured binding in range for detected as Objective C

2019-03-20 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Wed Mar 20 10:10:23 2019
New Revision: 356575

URL: http://llvm.org/viewvc/llvm-project?rev=356575&view=rev
Log:
[clang-format] structured binding in range for detected as Objective C

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> 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

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=356575&r1=356574&r2=356575&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Mar 20 10:10:23 2019
@@ -410,7 +410,10 @@ private:
  Parent->isUnaryOperator() ||
  // FIXME(bug 36976): ObjC return types shouldn't use TT_CastRParen.
  Parent->isOneOf(TT_ObjCForIn, TT_CastRParen) ||
- getBinOpPrecedence(Parent->Tok.getKind(), true, true) > 
prec::Unknown);
+ // for (auto && [A,B] : C)  && structure binding seen as 
ObjCMethodExpr
+ (Parent->isNot(tok::ampamp) &&
+  getBinOpPrecedence(Parent->Tok.getKind(), true, true) >
+  prec::Unknown));
 bool ColonFound = false;
 
 unsigned BindingIncrease = 1;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=356575&r1=356574&r2=356575&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Mar 20 10:10:23 2019
@@ -12926,6 +12926,9 @@ TEST_F(FormatTest, GuessLanguageWithCpp1
 guessLanguage("foo.h", "[[using gsl: suppress(\"type\")]];"));
   EXPECT_EQ(
   FormatStyle::LK_Cpp,
+  guessLanguage("foo.h", "for (auto &&[endpoint, stream] : streams_)"));
+  EXPECT_EQ(
+  FormatStyle::LK_Cpp,
   guessLanguage("foo.h",
 "[[clang::callable_when(\"unconsumed\", \"unknown\")]]"));
   EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "[[foo::bar, ...]]"));


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r356613 - [clang-format] BeforeHash added to IndentPPDirectives

2019-03-20 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Wed Mar 20 13:49:43 2019
New Revision: 356613

URL: http://llvm.org/viewvc/llvm-project?rev=356613&view=rev
Log:
[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

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/docs/ReleaseNotes.rst
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=356613&r1=356612&r2=356613&view=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Wed Mar 20 13:49:43 2019
@@ -1411,6 +1411,16 @@ the configuration (without a prefix: ``A
#  endif
#endif
 
+  * ``PPDIS_BeforeHash`` (in configuration: ``BeforeHash``)
+Indents directives before the hash.
+
+.. code-block:: c++
+
+   #if FOO
+ #if BAR
+   #include 
+ #endif
+   #endif
 
 
 **IndentWidth** (``unsigned``)

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=356613&r1=356612&r2=356613&view=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Wed Mar 20 13:49:43 2019
@@ -170,8 +170,8 @@ AST Matchers
 clang-format
 
 
-
-- ...
+- Added new option `PPDIS_BeforeHash` (in configuration: `BeforeHash`) to
+ `IndentPPDirectives` which indents preprocessor directives before the hash.
 
 libclang
 

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=356613&r1=356612&r2=356613&view=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Wed Mar 20 13:49:43 2019
@@ -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.

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=356613&r1=356612&r2=356613&view=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Mar 20 13:49:43 2019
@@ -174,6 +174,7 @@ struct ScalarEnumerationTraitshttp://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=356613&r1=356612&r2=356613&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Mar 20 13:49:43 2019
@@ -1924,12 +1924,15 @@ void TokenAnnotator::setCommentLineLevel
 NextNonCommentLine->First->NewlinesBefore <= 1 &&
 NextNonCommentLine->First->OriginalColumn ==
 (*I)->First->OriginalColumn) {
-  // Align comments for preprocessor lines with the # in column 0.
-  // Otherwise, align with the next line.
-  (*I)->Level = (NextNonCommentLine->Type == LT_PreprocessorDirective ||
- NextNonCommentLine->Type == LT_ImportStatement)
-? 0
-: NextNonCommentLine->Level;
+  // Align comments for preprocessor lines with the # in column 0 if
+  // preprocessor lines are not indented. Otherwise, align with the next
+  // line.
+  (*I)->Level =
+  (Style.IndentPPDirectives != FormatStyle::PPDIS_BeforeHash &&
+   (NextNonCommentLine->Type == LT_PreprocessorDirective ||
+NextNonCommentLine->Type == LT_ImportStatement))
+  ? 0
+  : NextNonCommentLine->Level;
 } else {
   NextNonCommentLine = (*I)->First->isNot(tok::r_brace) ? (*I) : nullptr;
 }

Modified: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
URL: 
http://llvm.or

r356615 - [clang-format][NFC] fix release notes build issue

2019-03-20 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Wed Mar 20 14:02:12 2019
New Revision: 356615

URL: http://llvm.org/viewvc/llvm-project?rev=356615&view=rev
Log:
[clang-format][NFC] fix release notes build issue

build issue from r356613

Modified:
cfe/trunk/docs/ReleaseNotes.rst

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=356615&r1=356614&r2=356615&view=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Wed Mar 20 14:02:12 2019
@@ -171,7 +171,7 @@ clang-format
 
 
 - Added new option `PPDIS_BeforeHash` (in configuration: `BeforeHash`) to
- `IndentPPDirectives` which indents preprocessor directives before the hash.
+  `IndentPPDirectives` which indents preprocessor directives before the hash.
 
 libclang
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r356662 - [clang-format] Add basic support for formatting C# files

2019-03-21 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Thu Mar 21 06:09:22 2019
New Revision: 356662

URL: http://llvm.org/viewvc/llvm-project?rev=356662&view=rev
Log:
[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

Added:
cfe/trunk/unittests/Format/FormatTestCSharp.cpp
Modified:
cfe/trunk/docs/ClangFormat.rst
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/docs/ReleaseNotes.rst
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/FormatToken.h
cfe/trunk/lib/Format/FormatTokenLexer.cpp
cfe/trunk/lib/Format/FormatTokenLexer.h
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/tools/clang-format/ClangFormat.cpp
cfe/trunk/unittests/Format/CMakeLists.txt

Modified: cfe/trunk/docs/ClangFormat.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormat.rst?rev=356662&r1=356661&r2=356662&view=diff
==
--- cfe/trunk/docs/ClangFormat.rst (original)
+++ cfe/trunk/docs/ClangFormat.rst Thu Mar 21 06:09:22 2019
@@ -11,12 +11,12 @@ Standalone Tool
 ===
 
 :program:`clang-format` is located in `clang/tools/clang-format` and can be 
used
-to format C/C++/Java/JavaScript/Objective-C/Protobuf code.
+to format C/C++/Java/JavaScript/Objective-C/Protobuf/C# code.
 
 .. code-block:: console
 
   $ clang-format -help
-  OVERVIEW: A tool to format C/C++/Java/JavaScript/Objective-C/Protobuf code.
+  OVERVIEW: A tool to format C/C++/Java/JavaScript/Objective-C/Protobuf/C# 
code.
 
   If no arguments are specified, it formats the code from standard input
   and writes the result to the standard output.

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=356662&r1=356661&r2=356662&view=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Thu Mar 21 06:09:22 2019
@@ -7,8 +7,8 @@ supported by :doc:`LibFormat` and :doc:`
 
 When using :program:`clang-format` command line utility or
 ``clang::format::reformat(...)`` functions from code, one can either use one of
-the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit) or create a
-custom style by configuring specific style options.
+the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft) or
+create a custom style by configuring specific style options.
 
 
 Configuring Style with clang-format
@@ -68,6 +68,10 @@ An example of a configuration file for m
   Language: Proto
   # Don't format .proto files.
   DisableFormat: true
+  ---
+  Language: CSharp
+  # Use 100 columns for C#.
+  ColumnLimit: 100
   ...
 
 An easy way to get a valid ``.clang-format`` file containing all configuration
@@ -144,6 +148,9 @@ the configuration (without a prefix: ``A
   * ``WebKit``
 A style complying with `WebKit's style guide
 `_
+  * ``Microsoft``
+A style complying with `Microsoft's style guide
+
`_
 
 .. START_FORMAT_STYLE_OPTIONS
 
@@ -1552,6 +1559,9 @@ the confi

r356821 - [clang-format][NFC] correct the release notes

2019-03-22 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Fri Mar 22 15:47:34 2019
New Revision: 356821

URL: http://llvm.org/viewvc/llvm-project?rev=356821&view=rev
Log:
[clang-format][NFC] correct the release notes

Move the clang-format notes to the correct section

Modified:
cfe/trunk/docs/ReleaseNotes.rst

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=356821&r1=356820&r2=356821&view=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Fri Mar 22 15:47:34 2019
@@ -165,12 +165,13 @@ release of Clang. Users of the build sys
 AST Matchers
 
 
-- Add language support for clang-formatting C# files
-- Add Microsoft coding style to encapsulate default C# formatting style
+- ...
 
 clang-format
 
 
+- Add language support for clang-formatting C# files
+- Add Microsoft coding style to encapsulate default C# formatting style
 - Added new option `PPDIS_BeforeHash` (in configuration: `BeforeHash`) to
   `IndentPPDirectives` which indents preprocessor directives before the hash.
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r356833 - [clang-format] correctly format protobuf fields named "enum".

2019-03-23 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Sat Mar 23 07:24:30 2019
New Revision: 356833

URL: http://llvm.org/viewvc/llvm-project?rev=356833&view=rev
Log:
[clang-format] correctly format protobuf fields named "enum".

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)

Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTestProto.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=356833&r1=356832&r2=356833&view=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Sat Mar 23 07:24:30 2019
@@ -2018,6 +2018,10 @@ bool UnwrappedLineParser::parseEnum() {
   FormatTok->isOneOf(tok::colon, tok::question))
 return false;
 
+  // In protobuf, "enum" can be used as a field name.
+  if (Style.Language == FormatStyle::LK_Proto && FormatTok->is(tok::equal))
+return false;
+
   // Eat up enum class ...
   if (FormatTok->Tok.is(tok::kw_class) || FormatTok->Tok.is(tok::kw_struct))
 nextToken();

Modified: cfe/trunk/unittests/Format/FormatTestProto.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestProto.cpp?rev=356833&r1=356832&r2=356833&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp Sat Mar 23 07:24:30 2019
@@ -107,6 +107,12 @@ TEST_F(FormatTestProto, FormatsEnums) {
"};");
 }
 
+TEST_F(FormatTestProto, EnumAsFieldName) {
+  verifyFormat("message SomeMessage {\n"
+   "  required int32 enum = 1;\n"
+   "}");
+}
+
 TEST_F(FormatTestProto, UnderstandsReturns) {
   verifyFormat("rpc Search(SearchRequest) returns (SearchResponse);");
 }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r356834 - Clang-format: add finer-grained options for putting all arguments on one line

2019-03-23 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Sat Mar 23 07:37:58 2019
New Revision: 356834

URL: http://llvm.org/viewvc/llvm-project?rev=356834&view=rev
Log:
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)

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=356834&r1=356833&r2=356834&view=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Sat Mar 23 07:37:58 2019
@@ -277,6 +277,41 @@ the configuration (without a prefix: ``A
 int a; // My comment a  vs. int a; // My comment a
 int b = 2; // comment  bint b = 2; // comment about b
 
+**AllowAllArgumentsOnNextLine** (``bool``)
+  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-block:: c++
+
+true:
+callFunction(
+a, b, c, d);
+
+false:
+callFunction(a,
+ b,
+ c,
+ d);
+
+**AllowAllConstructorInitializersOnNextLine** (``bool``)
+  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-block:: c++
+
+true:
+MyClass::MyClass() :
+member0(0), member1(2) {}
+
+false:
+MyClass::MyClass() :
+member0(0),
+member1(2) {}
+
 **AllowAllParametersOfDeclarationOnNextLine** (``bool``)
   If the function declaration doesn't fit on a line,
   allow putting all parameters of a function declaration onto

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=356834&r1=356833&r2=356834&view=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Sat Mar 23 07:37:58 2019
@@ -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 &&
+  

r356835 - [clang-format] Keep protobuf "package" statement on one line

2019-03-23 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Sat Mar 23 07:43:41 2019
New Revision: 356835

URL: http://llvm.org/viewvc/llvm-project?rev=356835&view=rev
Log:
[clang-format] Keep protobuf "package" statement on one line

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)

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestProto.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=356835&r1=356834&r2=356835&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Sat Mar 23 07:43:41 2019
@@ -1119,10 +1119,10 @@ public:
   return LT_ImportStatement;
 }
 
-// In .proto files, top-level options are very similar to import statements
-// and should not be line-wrapped.
+// In .proto files, top-level options and package statements are very
+// similar to import statements and should not be line-wrapped.
 if (Style.Language == FormatStyle::LK_Proto && Line.Level == 0 &&
-CurrentToken->is(Keywords.kw_option)) {
+CurrentToken->isOneOf(Keywords.kw_option, Keywords.kw_package)) {
   next();
   if (CurrentToken && CurrentToken->is(tok::identifier))
 return LT_ImportStatement;

Modified: cfe/trunk/unittests/Format/FormatTestProto.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestProto.cpp?rev=356835&r1=356834&r2=356835&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp Sat Mar 23 07:43:41 2019
@@ -393,6 +393,12 @@ TEST_F(FormatTestProto, FormatsOptions)
"};");
 }
 
+TEST_F(FormatTestProto, DoesntWrapPackageStatements) {
+  verifyFormat(
+  "package"
+  " some.really.long.package.that.exceeds.the.column.limit;");
+}
+
 TEST_F(FormatTestProto, FormatsService) {
   verifyFormat("service SearchService {\n"
"  rpc Search(SearchRequest) returns (SearchResponse) {\n"


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r357345 - [clang-format] [PR41187] moves Java import statements to the wrong location if code contains statements that start with the word import

2019-03-30 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Sat Mar 30 06:05:40 2019
New Revision: 357345

URL: http://llvm.org/viewvc/llvm-project?rev=357345&view=rev
Log:
[clang-format] [PR41187] moves Java import statements to the wrong location 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

Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/SortImportsTestJava.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=357345&r1=357344&r2=357345&view=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Sat Mar 30 06:05:40 2019
@@ -1983,7 +1983,7 @@ static void sortJavaImports(const Format
 namespace {
 
 const char JavaImportRegexPattern[] =
-"^[\t ]*import[\t ]*(static[\t ]*)?([^\t ]*)[\t ]*;";
+"^[\t ]*import[\t ]+(static[\t ]*)?([^\t ]*)[\t ]*;";
 
 } // anonymous namespace
 

Modified: cfe/trunk/unittests/Format/SortImportsTestJava.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/SortImportsTestJava.cpp?rev=357345&r1=357344&r2=357345&view=diff
==
--- cfe/trunk/unittests/Format/SortImportsTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/SortImportsTestJava.cpp Sat Mar 30 06:05:40 2019
@@ -262,6 +262,21 @@ TEST_F(SortImportsTestJava, NoNewlineAtE
  "import org.a;"));
 }
 
+TEST_F(SortImportsTestJava, ImportNamedFunction) {
+  EXPECT_EQ("import X;\n"
+"class C {\n"
+"  void m() {\n"
+"importFile();\n"
+"  }\n"
+"}\n",
+sort("import X;\n"
+ "class C {\n"
+ "  void m() {\n"
+ "importFile();\n"
+ "  }\n"
+ "}\n"));
+}
+
 TEST_F(SortImportsTestJava, NoReplacementsForValidImports) {
   // Identical #includes have led to a failure with an unstable sort.
   std::string Code = "import org.a;\n"


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r357837 - [clang-format] BreakAfterReturnType ignored on functions with numeric template parameters

2019-04-06 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Sat Apr  6 03:13:04 2019
New Revision: 357837

URL: http://llvm.org/viewvc/llvm-project?rev=357837&view=rev
Log:
[clang-format] BreakAfterReturnType ignored on functions with numeric 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

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=357837&r1=357836&r2=357837&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Sat Apr  6 03:13:04 2019
@@ -2095,7 +2095,7 @@ static bool isFunctionDeclarationName(co
 return true;
   for (const FormatToken *Tok = Next->Next; Tok && Tok != Next->MatchingParen;
Tok = Tok->Next) {
-if (Tok->is(tok::l_paren) && Tok->MatchingParen) {
+if (Tok->isOneOf(tok::l_paren, TT_TemplateOpener) && Tok->MatchingParen) {
   Tok = Tok->MatchingParen;
   continue;
 }

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=357837&r1=357836&r2=357837&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sat Apr  6 03:13:04 2019
@@ -5709,6 +5709,42 @@ TEST_F(FormatTest, ReturnTypeBreakingSty
"}\n"
"template  T *f(T &c);\n", // No break here.
Style);
+  verifyFormat("int\n"
+   "foo(A a)\n"
+   "{\n"
+   "  return a;\n"
+   "}\n",
+   Style);
+  verifyFormat("int\n"
+   "foo(A<8> a)\n"
+   "{\n"
+   "  return a;\n"
+   "}\n",
+   Style);
+  verifyFormat("int\n"
+   "foo(A, 8> a)\n"
+   "{\n"
+   "  return a;\n"
+   "}\n",
+   Style);
+  verifyFormat("int\n"
+   "foo(A, bool> a)\n"
+   "{\n"
+   "  return a;\n"
+   "}\n",
+   Style);
+  verifyFormat("int\n"
+   "foo(A, bool> a)\n"
+   "{\n"
+   "  return a;\n"
+   "}\n",
+   Style);
+  verifyFormat("int\n"
+   "foo(A, 8> a)\n"
+   "{\n"
+   "  return a;\n"
+   "}\n",
+   Style);
 }
 
 TEST_F(FormatTest, AlwaysBreakBeforeMultilineStrings) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r358375 - [clang-format] [PR41170] Break after return type ignored with certain comments positions

2019-04-15 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Mon Apr 15 00:47:15 2019
New Revision: 358375

URL: http://llvm.org/viewvc/llvm-project?rev=358375&view=rev
Log:
[clang-format] [PR41170] Break after return type ignored with certain 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 `; 
` rather than just `;` or ``

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

Modified:
cfe/trunk/lib/Format/TokenAnnotator.h
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.h?rev=358375&r1=358374&r2=358375&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.h (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.h Mon Apr 15 00:47:15 2019
@@ -99,9 +99,17 @@ public:
   /// function declaration. Asserts MightBeFunctionDecl.
   bool mightBeFunctionDefinition() const {
 assert(MightBeFunctionDecl);
-// FIXME: Line.Last points to other characters than tok::semi
-// and tok::lbrace.
-return !Last->isOneOf(tok::semi, tok::comment);
+// Try to determine if the end of a stream of tokens is either the
+// Definition or the Declaration for a function. It does this by looking 
for
+// the ';' in foo(); and using that it ends with a ; to know this is the
+// Definition, however the line could end with
+//foo(); /* comment */
+// or
+//foo(); // comment
+// or
+//foo() // comment
+// endsWith() ignores the comment.
+return !endsWith(tok::semi);
   }
 
   /// \c true if this line starts a namespace definition.

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=358375&r1=358374&r2=358375&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Apr 15 00:47:15 2019
@@ -5768,6 +5768,26 @@ TEST_F(FormatTest, ReturnTypeBreakingSty
"  return a;\n"
"}\n",
Style);
+
+  Style = getGNUStyle();
+
+  // Test for comments at the end of function declarations.
+  verifyFormat("void\n"
+   "foo (int a, /*abc*/ int b) // def\n"
+   "{\n"
+   "}\n",
+   Style);
+
+  verifyFormat("void\n"
+   "foo (int a, /* abc */ int b) /* def */\n"
+   "{\n"
+   "}\n",
+   Style);
+
+  // Definitions that should not break after return type
+  verifyFormat("void foo (int a, int b); // def\n", Style);
+  verifyFormat("void foo (int a, int b); /* def */\n", Style);
+  verifyFormat("void foo (int a, int b);\n", Style);
 }
 
 TEST_F(FormatTest, AlwaysBreakBeforeMultilineStrings) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r353535 - [clang-tidy] Add options to bugprone-argument-comment to add missing argument comments to literals

2019-02-08 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Fri Feb  8 09:00:01 2019
New Revision: 353535

URL: http://llvm.org/viewvc/llvm-project?rev=353535&view=rev
Log:
[clang-tidy] Add options to bugprone-argument-comment to add missing argument 
comments to literals

bugprone-argument-comment only supports identifying those comments which do not 
match the function parameter name

This revision add 3 options to adding missing argument comments to literals 
(granularity on type is added to control verbosity of fixit)

```
CheckOptions:
  - key: bugprone-argument-comment.CommentBoolLiterals
value:   '1'
  - key: bugprone-argument-comment.CommentFloatLiterals
value:   '1'
  - key: bugprone-argument-comment.CommentIntegerLiterals
value:   '1'
  - key: bugprone-argument-comment.CommentStringLiterals
value:   '1'
  - key: bugprone-argument-comment.CommentCharacterLiterals
value:   '1'
  - key: bugprone-argument-comment.CommentUserDefinedLiterals
value:   '1'
  - key: bugprone-argument-comment.CommentNullPtrs
value:   '1'
```

After applying these options, literal arguments will be preceded with 
/*ParameterName=*/

Reviewers: JonasToth, Eugene.Zelenko, alexfh, hokein, aaron.ballman

Reviewed By: aaron.ballman, Eugene.Zelenko

Differential Revision: https://reviews.llvm.org/D57674

Added:

clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-literals.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.h
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-argument-comment.rst

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.cpp?rev=353535&r1=353534&r2=353535&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.cpp Fri 
Feb  8 09:00:01 2019
@@ -11,6 +11,7 @@
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Lex/Lexer.h"
 #include "clang/Lex/Token.h"
+
 #include "../utils/LexerUtils.h"
 
 using namespace clang::ast_matchers;
@@ -23,17 +24,37 @@ ArgumentCommentCheck::ArgumentCommentChe
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
   StrictMode(Options.getLocalOrGlobal("StrictMode", 0) != 0),
+  CommentBoolLiterals(Options.getLocalOrGlobal("CommentBoolLiterals", 0) !=
+  0),
+  CommentIntegerLiterals(
+  Options.getLocalOrGlobal("CommentIntegerLiterals", 0) != 0),
+  CommentFloatLiterals(
+  Options.getLocalOrGlobal("CommentFloatLiterals", 0) != 0),
+  CommentStringLiterals(
+  Options.getLocalOrGlobal("CommentStringLiterals", 0) != 0),
+  CommentUserDefinedLiterals(
+  Options.getLocalOrGlobal("CommentUserDefinedLiterals", 0) != 0),
+  CommentCharacterLiterals(
+  Options.getLocalOrGlobal("CommentCharacterLiterals", 0) != 0),
+  CommentNullPtrs(Options.getLocalOrGlobal("CommentNullPtrs", 0) != 0),
   IdentRE("^(/\\* *)([_A-Za-z][_A-Za-z0-9]*)( *= *\\*/)$") {}
 
 void ArgumentCommentCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "StrictMode", StrictMode);
+  Options.store(Opts, "CommentBoolLiterals", CommentBoolLiterals);
+  Options.store(Opts, "CommentIntegerLiterals", CommentIntegerLiterals);
+  Options.store(Opts, "CommentFloatLiterals", CommentFloatLiterals);
+  Options.store(Opts, "CommentStringLiterals", CommentStringLiterals);
+  Options.store(Opts, "CommentUserDefinedLiterals", 
CommentUserDefinedLiterals);
+  Options.store(Opts, "CommentCharacterLiterals", CommentCharacterLiterals);
+  Options.store(Opts, "CommentNullPtrs", CommentNullPtrs);
 }
 
 void ArgumentCommentCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   callExpr(unless(cxxOperatorCallExpr()),
-   // NewCallback's arguments relate to the pointed function, don't
-   // check them against NewCallback's parameter names.
+   // NewCallback's arguments relate to the pointed function,
+   // don't check them against NewCallback's parameter names.
// FIXME: Make this configurable.
unless(hasDeclaration(functionDecl(
hasAnyName("NewCallback", "NewPermanentCallback")
@@ -126,8 +147,8 @@ static bool isLikelyTypo(llvm::ArrayRef<
 
 const unsigned Threshold = 2;
 // Other parameters must be an edit distance at least Threshold more away
-// from this parameter. This gives us greate

r371719 - [clang-format] Add new style option IndentGotoLabels

2019-09-12 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Thu Sep 12 03:07:14 2019
New Revision: 371719

URL: http://llvm.org/viewvc/llvm-project?rev=371719&view=rev
Log:
[clang-format] Add new style option IndentGotoLabels

Summary:
This option determines whether goto labels are indented according to scope. 
Setting this option to false causes goto labels to be flushed to the left.
This is mostly copied from [[ 
http://lists.llvm.org/pipermail/cfe-dev/2015-September/045014.html | this patch 
]] submitted by Christian Neukirchen that didn't make its way into trunk.

```
 true:  false:
 int f() {  vs. int f() {
   if (foo()) {   if (foo()) {
   label1:  label1:
 bar(); bar();
   }  }
 label2:label2:
   return 1;  return 1;
 }  }
```

Reviewers: klimek, MyDeveloperDay

Reviewed By: MyDeveloperDay

Subscribers: cfe-commits

Tags: #clang, #clang-tools-extra

Patch by: tetsuo-cpp

Differential Revision: https://reviews.llvm.org/D67037

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.h
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=371719&r1=371718&r2=371719&view=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Thu Sep 12 03:07:14 2019
@@ -1527,6 +1527,23 @@ the configuration (without a prefix: ``A
plop();  plop();
  }  }
 
+**IndentGotoLabels** (``bool``)
+  Indent goto labels.
+
+  When ``false``, goto labels are flushed left.
+
+  .. code-block:: c++
+
+ true:  false:
+ int f() {  vs. int f() {
+   if (foo()) {   if (foo()) {
+   label1:  label1:
+ bar(); bar();
+   }  }
+ label2:label2:
+   return 1;  return 1;
+ }  }
+
 **IndentPPDirectives** (``PPDirectiveIndentStyle``)
   The preprocessor directive indenting style to use.
 

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=371719&r1=371718&r2=371719&view=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Thu Sep 12 03:07:14 2019
@@ -1265,6 +1265,22 @@ struct FormatStyle {
   /// \endcode
   bool IndentCaseLabels;
 
+  /// Indent goto labels.
+  ///
+  /// When ``false``, goto labels are flushed left.
+  /// \code
+  ///true:  false:
+  ///int f() {  vs. int f() {
+  ///  if (foo()) {   if (foo()) {
+  ///  label1:  label1:
+  ///bar(); bar();
+  ///  }  }
+  ///label2:label2:
+  ///  return 1;  return 1;
+  ///}  }
+  /// \endcode
+  bool IndentGotoLabels;
+
   /// Options for indenting preprocessor directives.
   enum PPDirectiveIndentStyle {
 /// Does not indent any directives.
@@ -1990,6 +2006,7 @@ struct FormatStyle {
IncludeStyle.IncludeBlocks == R.IncludeStyle.IncludeBlocks &&
IncludeStyle.IncludeCategories == R.IncludeStyle.IncludeCategories 
&&
IndentCaseLabels == R.IndentCaseLabels &&
+   IndentGotoLabels == R.IndentGotoLabels &&
IndentPPDirectives == R.IndentPPDirectives &&
IndentWidth == R.IndentWidth && Language == R.Language &&
IndentWrappedFunctionNames == R.IndentWrappedFunctionNames &&

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=371719&r1=371718&r2=371719&view=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Thu Sep 12 03:07:14 2019
@@ -453,6 +453,7 @@ template <> struct MappingTraitshttp://llvm.org/viewvc/llvm-project/cfe/trunk/lib/

r371720 - [clang-format] [PR43100] clang-format C# support does not add a space between "using" and paren

2019-09-12 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Thu Sep 12 03:18:53 2019
New Revision: 371720

URL: http://llvm.org/viewvc/llvm-project?rev=371720&view=rev
Log:
[clang-format] [PR43100] clang-format C#  support does not add a space between 
"using" and paren

Summary:
Addresses https://bugs.llvm.org/show_bug.cgi?id=43100

Formatting using statement in C# with clang-format removes the space between 
using and paren even when SpaceBeforeParens is !

```
using(FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, 
FileShare.Read, bufferSize : 1))
```

this change simply overcomes this for when using C# settings in the 
.clang-format file

```
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, 
FileShare.Read, bufferSize : 1))
```

All FormatTests pass..

```
[==] 688 tests from 21 test cases ran. (88508 ms total)
[  PASSED  ] 688 tests.
```

Reviewers: djasper, klimek, owenpan

Reviewed By: owenpan

Subscribers: llvm-commits, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D2

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestCSharp.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=371720&r1=371719&r2=371720&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Sep 12 03:18:53 2019
@@ -2611,6 +2611,10 @@ bool TokenAnnotator::spaceRequiredBetwee
 return Style.Language == FormatStyle::LK_JavaScript ||
!Left.TokenText.endswith("=*/");
   if (Right.is(tok::l_paren)) {
+// using (FileStream fs...
+if (Style.isCSharp() && Left.is(tok::kw_using) &&
+Style.SpaceBeforeParens != FormatStyle::SBPO_Never)
+  return true;
 if ((Left.is(tok::r_paren) && Left.is(TT_AttributeParen)) ||
 (Left.is(tok::r_square) && Left.is(TT_AttributeSquare)))
   return true;

Modified: cfe/trunk/unittests/Format/FormatTestCSharp.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestCSharp.cpp?rev=371720&r1=371719&r2=371720&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestCSharp.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestCSharp.cpp Thu Sep 12 03:18:53 2019
@@ -165,6 +165,21 @@ TEST_F(FormatTestCSharp, Attributes) {
"public string Host {\n  set;\n  get;\n}");
 }
 
+TEST_F(FormatTestCSharp, CSharpUsing) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
+  Style.SpaceBeforeParens = FormatStyle::SBPO_Always;
+  verifyFormat("public void foo() {\n"
+   "  using (StreamWriter sw = new StreamWriter (filenameA)) {}\n"
+   "}",
+   Style);
+
+  Style.SpaceBeforeParens = FormatStyle::SBPO_Never;
+  verifyFormat("public void foo() {\n"
+   "  using(StreamWriter sw = new StreamWriter(filenameB)) {}\n"
+   "}",
+   Style);
+}
+
 TEST_F(FormatTestCSharp, CSharpRegions) {
   verifyFormat("#region aaa a "
"aaa long region");


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r372246 - [clang-format][PR41964] Fix crash with SIGFPE when TabWidth is set to 0 and line starts with tab

2019-09-18 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Wed Sep 18 11:57:09 2019
New Revision: 372246

URL: http://llvm.org/viewvc/llvm-project?rev=372246&view=rev
Log:
[clang-format][PR41964] Fix crash with SIGFPE when TabWidth is set to 0 and 
line starts with tab

Summary:
clang-format 8.0 crashes with SIGFPE (floating point exception) when formatting 
following file:
app.cpp:
void a() {
//line starts with '\t'
}

$ clang-format -style='{TabWidth: 0}' app.cpp

Reviewers: owenpan, klimek, russellmcc, timwoj

Reviewed By: klimek

Subscribers: cfe-commits

Tags: #clang-tools-extra, #clang

Differential Revision: https://reviews.llvm.org/D67670

Modified:
cfe/trunk/lib/Format/Encoding.h
cfe/trunk/lib/Format/FormatTokenLexer.cpp
cfe/trunk/lib/Format/WhitespaceManager.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/Encoding.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Encoding.h?rev=372246&r1=372245&r2=372246&view=diff
==
--- cfe/trunk/lib/Format/Encoding.h (original)
+++ cfe/trunk/lib/Format/Encoding.h Wed Sep 18 11:57:09 2019
@@ -67,7 +67,8 @@ inline unsigned columnWidthWithTabs(Stri
 if (TabPos == StringRef::npos)
   return TotalWidth + columnWidth(Tail, Encoding);
 TotalWidth += columnWidth(Tail.substr(0, TabPos), Encoding);
-TotalWidth += TabWidth - (TotalWidth + StartColumn) % TabWidth;
+if (TabWidth)
+  TotalWidth += TabWidth - (TotalWidth + StartColumn) % TabWidth;
 Tail = Tail.substr(TabPos + 1);
   }
 }

Modified: cfe/trunk/lib/Format/FormatTokenLexer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatTokenLexer.cpp?rev=372246&r1=372245&r2=372246&view=diff
==
--- cfe/trunk/lib/Format/FormatTokenLexer.cpp (original)
+++ cfe/trunk/lib/Format/FormatTokenLexer.cpp Wed Sep 18 11:57:09 2019
@@ -657,7 +657,8 @@ FormatToken *FormatTokenLexer::getNextTo
 ++Column;
 break;
   case '\t':
-Column += Style.TabWidth - Column % Style.TabWidth;
+Column +=
+Style.TabWidth - (Style.TabWidth ? Column % Style.TabWidth : 0);
 break;
   case '\\':
 if (i + 1 == e || (Text[i + 1] != '\r' && Text[i + 1] != '\n'))

Modified: cfe/trunk/lib/Format/WhitespaceManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/WhitespaceManager.cpp?rev=372246&r1=372245&r2=372246&view=diff
==
--- cfe/trunk/lib/Format/WhitespaceManager.cpp (original)
+++ cfe/trunk/lib/Format/WhitespaceManager.cpp Wed Sep 18 11:57:09 2019
@@ -815,19 +815,24 @@ void WhitespaceManager::appendIndentText
 Text.append(Spaces, ' ');
 break;
   case FormatStyle::UT_Always: {
-unsigned FirstTabWidth =
-Style.TabWidth - WhitespaceStartColumn % Style.TabWidth;
-// Insert only spaces when we want to end up before the next tab.
-if (Spaces < FirstTabWidth || Spaces == 1) {
+if (Style.TabWidth) {
+  unsigned FirstTabWidth =
+  Style.TabWidth - WhitespaceStartColumn % Style.TabWidth;
+
+  // Insert only spaces when we want to end up before the next tab.
+  if (Spaces < FirstTabWidth || Spaces == 1) {
+Text.append(Spaces, ' ');
+break;
+  }
+  // Align to the next tab.
+  Spaces -= FirstTabWidth;
+  Text.append("\t");
+
+  Text.append(Spaces / Style.TabWidth, '\t');
+  Text.append(Spaces % Style.TabWidth, ' ');
+} else if (Spaces == 1) {
   Text.append(Spaces, ' ');
-  break;
 }
-// Align to the next tab.
-Spaces -= FirstTabWidth;
-Text.append("\t");
-
-Text.append(Spaces / Style.TabWidth, '\t');
-Text.append(Spaces % Style.TabWidth, ' ');
 break;
   }
   case FormatStyle::UT_ForIndentation:
@@ -837,14 +842,16 @@ void WhitespaceManager::appendIndentText
   // the first one.
   if (Indentation > Spaces)
 Indentation = Spaces;
-  unsigned Tabs = Indentation / Style.TabWidth;
-  Text.append(Tabs, '\t');
-  Spaces -= Tabs * Style.TabWidth;
+  if (Style.TabWidth) {
+unsigned Tabs = Indentation / Style.TabWidth;
+Text.append(Tabs, '\t');
+Spaces -= Tabs * Style.TabWidth;
+  }
 }
 Text.append(Spaces, ' ');
 break;
   case FormatStyle::UT_ForContinuationAndIndentation:
-if (WhitespaceStartColumn == 0) {
+if (WhitespaceStartColumn == 0 && Style.TabWidth) {
   unsigned Tabs = Spaces / Style.TabWidth;
   Text.append(Tabs, '\t');
   Spaces -= Tabs * Style.TabWidth;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=372246&r1=372245&r2=372246&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (origi

r372249 - [clang-format][PR41899] PointerAlignment: Left leads to useless space in lambda intializer expression

2019-09-18 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Wed Sep 18 12:11:40 2019
New Revision: 372249

URL: http://llvm.org/viewvc/llvm-project?rev=372249&view=rev
Log:
[clang-format][PR41899] PointerAlignment: Left leads to useless space in lambda 
intializer expression

Summary:
https://bugs.llvm.org/show_bug.cgi?id=41899

```auto lambda = [&a = a]() { a = 2; };```

is formatted as

```auto lambda = [& a = a]() { a = 2; };```

With an extra space if PointerAlignment is set to Left

> The space "& a" looks strange when there is no type in the lambda's 
> intializer expression. This can be worked around with by setting 
> "PointerAlignment: Right", but ideally "PointerAlignment: Left" would not add 
> a space in this case.

Reviewers: klimek, owenpan, krasimir, timwoj

Reviewed By: klimek

Subscribers: cfe-commits

Tags: #clang-tools-extra, #clang

Differential Revision: https://reviews.llvm.org/D67718

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=372249&r1=372248&r2=372249&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Sep 18 12:11:40 2019
@@ -2580,7 +2580,8 @@ bool TokenAnnotator::spaceRequiredBetwee
 (Style.PointerAlignment != FormatStyle::PAS_Right &&
  !Line.IsMultiVariableDeclStmt) &&
 Left.Previous &&
-!Left.Previous->isOneOf(tok::l_paren, tok::coloncolon));
+!Left.Previous->isOneOf(tok::l_paren, tok::coloncolon,
+tok::l_square));
   if (Right.is(tok::star) && Left.is(tok::l_paren))
 return false;
   const auto SpaceRequiredForArrayInitializerLSquare =

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=372249&r1=372248&r2=372249&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Sep 18 12:11:40 2019
@@ -14074,6 +14074,15 @@ TEST_F(FormatTest, TypenameMacros) {
   verifyFormat("STACK_OF(int*)* a;", Macros);
 }
 
+TEST_F(FormatTest, AmbersandInLamda) {
+  // Test case reported in https://bugs.llvm.org/show_bug.cgi?id=41899
+  FormatStyle AlignStyle = getLLVMStyle();
+  AlignStyle.PointerAlignment = FormatStyle::PAS_Left;
+  verifyFormat("auto lambda = [&a = a]() { a = 2; };", AlignStyle);
+  AlignStyle.PointerAlignment = FormatStyle::PAS_Right;
+  verifyFormat("auto lambda = [&a = a]() { a = 2; };", AlignStyle);
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r372497 - Clang-format: Add Whitesmiths indentation style

2019-09-22 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Sun Sep 22 05:00:34 2019
New Revision: 372497

URL: http://llvm.org/viewvc/llvm-project?rev=372497&view=rev
Log:
Clang-format: Add Whitesmiths indentation style

Summary:
This patch adds support for the Whitesmiths indentation style to clang-format. 
It’s an update to a patch submitted in 2015 (D6833), but reworks it to use the 
newer API.

There are still some issues with this patch, primarily around `switch` and 
`case` support. The added unit test won’t currently pass because of the 
remaining issues.

Reviewers: mboehme, MyDeveloperDay, djasper

Reviewed By: MyDeveloperDay

Subscribers: krasimir, MyDeveloperDay, echristo, cfe-commits

Patch By: @timwoj (Tim Wojtulewicz)

Tags: #clang

Differential Revision: https://reviews.llvm.org/D67627

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=372497&r1=372496&r2=372497&view=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Sun Sep 22 05:00:34 2019
@@ -1128,6 +1128,34 @@ the configuration (without a prefix: ``A
 B
   };
 
+  * ``BS_Whitesmiths`` (in configuration: ``Whitesmiths``)
+Like ``Allman`` but always indent braces and line up code with braces.
+
+.. code-block:: c++
+
+  try
+{
+foo();
+}
+  catch ()
+{
+}
+  void foo() { bar(); }
+  class foo
+{
+};
+  if (foo())
+{
+}
+  else
+{
+}
+  enum X : int
+{
+A,
+B
+};
+
   * ``BS_GNU`` (in configuration: ``GNU``)
 Always break before braces and add an extra level of indentation to
 braces of control statements, not to those of class, function

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=372497&r1=372496&r2=372497&view=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Sun Sep 22 05:00:34 2019
@@ -733,6 +733,32 @@ struct FormatStyle {
 /// B
 ///   };
 /// \endcode
+BS_Whitesmiths,
+/// Like ``Allman`` but always indent braces and line up code with braces.
+/// \code
+///try
+/// {
+/// foo();
+/// }
+///   catch ()
+/// {
+/// }
+///   void foo() { bar(); }
+///   class foo
+/// {
+/// };
+///   if (foo())
+/// {
+/// }
+///   else
+/// {
+/// }
+///   enum X : int
+/// {
+/// A,
+/// B
+/// };
+/// \endcode
 BS_GNU,
 /// Like ``Attach``, but break before functions.
 /// \code

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=372497&r1=372496&r2=372497&view=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Sun Sep 22 05:00:34 2019
@@ -931,6 +931,11 @@ unsigned ContinuationIndenter::getNewLin
 return std::max(State.Stack.back().LastSpace,
 State.Stack.back().Indent + Style.ContinuationIndentWidth);
 
+  if (Style.BreakBeforeBraces == FormatStyle::BS_Whitesmiths &&
+  State.Line->First->is(tok::kw_enum))
+return (Style.IndentWidth * State.Line->First->IndentLevel) +
+   Style.IndentWidth;
+
   if (NextNonComment->is(tok::l_brace) && NextNonComment->BlockKind == 
BK_Block)
 return Current.NestingLevel == 0 ? State.FirstIndent
  : State.Stack.back().Indent;

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=372497&r1=372496&r2=372497&view=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Sun Sep 22 05:00:34 2019
@@ -165,6 +165,7 @@ template <> struct ScalarEnumerationTrai
 IO.enumCase(Value, "Mozilla", FormatStyle::BS_Mozilla);
 IO.enumCase(Value, "Stroustrup", FormatStyle::BS_Stroustrup);
 IO.enumCase(Value, "Allman", FormatStyle::BS_Allman);
+IO.enumCase(Value, "Whitesmiths", FormatStyle::BS_Whitesmiths);
 IO.enumCase(Value, "GNU", FormatStyle::BS_GNU);
 IO.enumCase(V

r372689 - [clang-format] NFC clang-format the clang-format unit tests

2019-09-23 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Mon Sep 23 23:35:37 2019
New Revision: 372689

URL: http://llvm.org/viewvc/llvm-project?rev=372689&view=rev
Log:
[clang-format] NFC clang-format the clang-format unit tests

Summary:
It is annoying that the clang-format tests aren't themselves clang-formatted, 
if you use a format on save option in VS or vim this file gets massively 
changed then you have to `git difftool` all the other changes back out, which 
is risky.

I know people don't like mass clang-format changes but sometimes it becomes 
unmanageable to not. There are no other changes here other than just the 
reformat.

clang-format tests all pass.

```
[==] 691 tests from 21 test cases ran. (55990 ms total)
[  PASSED  ] 691 tests.
```

Reviewers: klimek, owenpan, timwoj

Reviewed By: owenpan

Subscribers: cfe-commits

Tags: #clang-tools-extra, #clang

Differential Revision: https://reviews.llvm.org/D67888

Modified:
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=372689&r1=372688&r2=372689&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Sep 23 23:35:37 2019
@@ -29,11 +29,7 @@ FormatStyle getGoogleStyle() { return ge
 
 class FormatTest : public ::testing::Test {
 protected:
-  enum StatusCheck {
-SC_ExpectComplete,
-SC_ExpectIncomplete,
-SC_DoNotCheck
-  };
+  enum StatusCheck { SC_ExpectComplete, SC_ExpectIncomplete, SC_DoNotCheck };
 
   std::string format(llvm::StringRef Code,
  const FormatStyle &Style = getLLVMStyle(),
@@ -332,13 +328,15 @@ TEST_F(FormatTest, RemovesEmptyLines) {
 format("namespace {\n"
"int i;\n"
"\n"
-   "}", LLVMWithNoNamespaceFix));
+   "}",
+   LLVMWithNoNamespaceFix));
   EXPECT_EQ("namespace {\n"
 "int i;\n"
 "}",
 format("namespace {\n"
"int i;\n"
-   "}", LLVMWithNoNamespaceFix));
+   "}",
+   LLVMWithNoNamespaceFix));
   EXPECT_EQ("namespace {\n"
 "int i;\n"
 "\n"
@@ -346,13 +344,15 @@ TEST_F(FormatTest, RemovesEmptyLines) {
 format("namespace {\n"
"int i;\n"
"\n"
-   "};", LLVMWithNoNamespaceFix));
+   "};",
+   LLVMWithNoNamespaceFix));
   EXPECT_EQ("namespace {\n"
 "int i;\n"
 "};",
 format("namespace {\n"
"int i;\n"
-   "};", LLVMWithNoNamespaceFix));
+   "};",
+   LLVMWithNoNamespaceFix));
   EXPECT_EQ("namespace {\n"
 "int i;\n"
 "\n"
@@ -903,7 +903,8 @@ TEST_F(FormatTest, FormatsForLoop) {
   verifyFormat("for (Foo *x = 0; x != in; x++) {\n}");
   verifyFormat("Foo *x;\nfor (x = 0; x != in; x++) {\n}");
   verifyFormat("Foo *x;\nfor (x in y) {\n}");
-  verifyFormat("for (const Foo &baz = in.value(); !baz.at_end(); ++baz) 
{\n}");
+  verifyFormat(
+  "for (const Foo &baz = in.value(); !baz.at_end(); ++baz) {\n}");
 
   FormatStyle NoBinPacking = getLLVMStyle();
   NoBinPacking.BinPackParameters = false;
@@ -1295,20 +1296,26 @@ TEST_F(FormatTest, ShortCaseLabels) {
"#endif\n"
"}",
Style));
-  EXPECT_EQ("switch (a) {\n" "case 0:\n"
-"  return; // long long long long long long long long long long 
long long comment\n"
-"  // line\n" "}",
+  EXPECT_EQ("switch (a) {\n"
+"case 0:\n"
+"  return; // long long long long long long long long long long "
+"long long comment\n"
+"  // line\n"
+"}",
 format("switch (a) {\n"
-   "case 0: return; // long long long long long long long long 
long long long long comment line\n"
+   "case 0: return; // long long long long long long long long 
"
+   "long long long long comment line\n"
"}",
Style));
   EXPECT_EQ("switch (a) {\n"
 "case 0:\n"
-"  return; /* long long long long long long long long long long 
long long comment\n"
+"  return; /* long long long long long long long long long long "
+"long long comment\n"
 " line */\n"
 "}",
 format("switch (a) {\n"
-   "case 0: return; /* long long long long long long long long 
long long long long comment line */\n"
+   "case 0: return; /* long long long long long long long long 
"
+   "long long long long comment line */\n"
 

r372760 - [clang-format] [PR36858] Add missing .hh and .cs extensions from python support utilities

2019-09-24 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Tue Sep 24 07:00:06 2019
New Revision: 372760

URL: http://llvm.org/viewvc/llvm-project?rev=372760&view=rev
Log:
[clang-format] [PR36858] Add missing .hh and .cs extensions from python support 
utilities

Summary: https://bugs.llvm.org/show_bug.cgi?id=36858 identifies .hh as a 
missing C++ header extension file while making this change I realized there was 
no support for .cs files which were added recently

Reviewers: pseyfert, klimek, owenpan

Reviewed By: klimek

Subscribers: cfe-commits

Tags: #clang-tools-extra, #clang

Differential Revision: https://reviews.llvm.org/D67949

Modified:
cfe/trunk/tools/clang-format/clang-format-diff.py
cfe/trunk/tools/clang-format/git-clang-format

Modified: cfe/trunk/tools/clang-format/clang-format-diff.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/clang-format-diff.py?rev=372760&r1=372759&r2=372760&view=diff
==
--- cfe/trunk/tools/clang-format/clang-format-diff.py (original)
+++ cfe/trunk/tools/clang-format/clang-format-diff.py Tue Sep 24 07:00:06 2019
@@ -43,8 +43,8 @@ def main():
   help='custom pattern selecting file paths to reformat '
   '(case sensitive, overrides -iregex)')
   parser.add_argument('-iregex', metavar='PATTERN', default=
-  r'.*\.(cpp|cc|c\+\+|cxx|c|cl|h|hpp|m|mm|inc|js|ts|proto'
-  r'|protodevel|java)',
+  
r'.*\.(cpp|cc|c\+\+|cxx|c|cl|h|hh|hpp|m|mm|inc|js|ts|proto'
+  r'|protodevel|java|cs)',
   help='custom pattern selecting file paths to reformat '
   '(case insensitive, overridden by -regex)')
   parser.add_argument('-sort-includes', action='store_true', default=False,

Modified: cfe/trunk/tools/clang-format/git-clang-format
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/git-clang-format?rev=372760&r1=372759&r2=372760&view=diff
==
--- cfe/trunk/tools/clang-format/git-clang-format (original)
+++ cfe/trunk/tools/clang-format/git-clang-format Tue Sep 24 07:00:06 2019
@@ -77,13 +77,14 @@ def main():
   'c', 'h',  # C
   'm',  # ObjC
   'mm',  # ObjC++
-  'cc', 'cp', 'cpp', 'c++', 'cxx', 'hpp', 'hxx',  # C++
+  'cc', 'cp', 'cpp', 'c++', 'cxx', 'hh', 'hpp', 'hxx',  # C++
   'cu',  # CUDA
   # Other languages that clang-format supports
   'proto', 'protodevel',  # Protocol Buffers
   'java',  # Java
   'js',  # JavaScript
   'ts',  # TypeScript
+  'cs',  # C Sharp
   ])
 
   p = argparse.ArgumentParser(


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r372919 - [clang-format] Modified SortIncludes and IncludeCategories to priority for sorting #includes within the Group Category.

2019-09-25 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Wed Sep 25 13:33:01 2019
New Revision: 372919

URL: http://llvm.org/viewvc/llvm-project?rev=372919&view=rev
Log:
[clang-format] Modified SortIncludes and IncludeCategories to priority for 
sorting #includes within the Group Category.

Summary:
This new Style rule is made as a part of adding support for NetBSD KNF in 
clang-format. NetBSD have it's own priority of includes which should be 
followed while formatting NetBSD code. This style sorts the Cpp Includes 
according to the priorities of NetBSD, as mentioned in the [Style 
Guide](http://cvsweb.netbsd.org/bsdweb.cgi/src/share/misc/style?rev=HEAD&content-type=text/x-cvsweb-markup)
 The working of this Style rule shown below:

**Configuration:**
This revision introduces a new field under IncludeCategories named 
`SortPriority` which defines the priority of ordering the `#includes` and the 
`Priority` will define the categories for grouping the `#include blocks`.

Reviewers: cfe-commits, mgorny, christos, MyDeveloperDay

Reviewed By: MyDeveloperDay

Subscribers: lebedev.ri, rdwampler, christos, mgorny, krytarowski

Patch By: Manikishan

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D64695

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/include/clang/Tooling/Inclusions/HeaderIncludes.h
cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp
cfe/trunk/lib/Tooling/Inclusions/IncludeStyle.cpp
cfe/trunk/unittests/Format/SortIncludesTest.cpp

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=372919&r1=372918&r2=372919&view=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Wed Sep 25 13:33:01 2019
@@ -1511,6 +1511,13 @@ the configuration (without a prefix: ``A
   can also assign negative priorities if you have certain headers that
   always need to be first.
 
+  There is a third and optional field ``SortPriority`` which can used while
+  ``IncludeBloks = IBS_Regroup`` to define the priority in which ``#includes``
+  should be ordered, and value of ``Priority`` defines the order of
+  ``#include blocks`` and also enables to group ``#includes`` of different
+  priority for order.``SortPriority`` is set to the value of ``Priority``
+  as default if it is not assigned.
+
   To configure this in the .clang-format file, use:
 
   .. code-block:: yaml
@@ -1518,12 +1525,14 @@ the configuration (without a prefix: ``A
 IncludeCategories:
   - Regex:   '^"(llvm|llvm-c|clang|clang-c)/'
 Priority:2
+SortPriority:2
   - Regex:   '^(<|"(gtest|gmock|isl|json)/)'
 Priority:3
   - Regex:   '<[[:alnum:].]+>'
 Priority:4
   - Regex:   '.*'
 Priority:1
+SortPriority:0
 
 **IncludeIsMainRegex** (``std::string``)
   Specify a regular expression of suffixes that are allowed in the

Modified: cfe/trunk/include/clang/Tooling/Inclusions/HeaderIncludes.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Inclusions/HeaderIncludes.h?rev=372919&r1=372918&r2=372919&view=diff
==
--- cfe/trunk/include/clang/Tooling/Inclusions/HeaderIncludes.h (original)
+++ cfe/trunk/include/clang/Tooling/Inclusions/HeaderIncludes.h Wed Sep 25 
13:33:01 2019
@@ -32,6 +32,7 @@ public:
   /// 0. Otherwise, returns the priority of the matching category or INT_MAX.
   /// NOTE: this API is not thread-safe!
   int getIncludePriority(StringRef IncludeName, bool CheckMainHeader) const;
+  int getSortIncludePriority(StringRef IncludeName, bool CheckMainHeader) 
const;
 
 private:
   bool isMainHeader(StringRef IncludeName) const;

Modified: cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h?rev=372919&r1=372918&r2=372919&view=diff
==
--- cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h (original)
+++ cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h Wed Sep 25 
13:33:01 2019
@@ -58,6 +58,8 @@ struct IncludeStyle {
 std::string Regex;
 /// The priority to assign to this category.
 int Priority;
+/// The custom priority to sort before grouping.
+int SortPriority;
 bool operator==(const IncludeCategory &Other) const {
   return Regex == Other.Regex && Priority == Other.Priority;
 }

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=372919&r1=372918&r2=372919&view=diff

r373165 - [clang-format] Reference qualifiers in member templates causing extra indentation.

2019-09-29 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Sun Sep 29 06:45:38 2019
New Revision: 373165

URL: http://llvm.org/viewvc/llvm-project?rev=373165&view=rev
Log:
[clang-format] Reference qualifiers in member templates causing extra 
indentation.

Summary:
The following code

```
struct f {
  template 
  void bar() && noexcept {}
};
```

will be formatted to the following with LLVM style, and
`AlwaysBreakTemplateDeclarations: Yes`

```
struct f {
  template 
  void bar() && noexcept {}
};
```

The indentation of the `void bar()` line is wrong.

Reviewers: klimek, owenpan, krasimir, timwoj, MyDeveloperDay

Reviewed By: klimek, MyDeveloperDay

Subscribers: MyDeveloperDay, ilya-biryukov, llvm-commits, cfe-commits

Patch By: AndWass

Tags: #clang-format, #clang, #llvm

Differential Revision: https://reviews.llvm.org/D68072

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=373165&r1=373164&r2=373165&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Sun Sep 29 06:45:38 2019
@@ -65,7 +65,7 @@ public:
   AnnotatingParser(const FormatStyle &Style, AnnotatedLine &Line,
const AdditionalKeywords &Keywords)
   : Style(Style), Line(Line), CurrentToken(Line.First), AutoFound(false),
-Keywords(Keywords) {
+TrailingReturnFound(false), Keywords(Keywords) {
 Contexts.push_back(Context(tok::unknown, 1, /*IsExpression=*/false));
 resetTokenMetadata(CurrentToken);
   }
@@ -1389,7 +1389,11 @@ private:
 } else if (Current.is(tok::arrow) && AutoFound && Line.MustBeDeclaration &&
Current.NestingLevel == 0) {
   Current.Type = TT_TrailingReturnArrow;
-} else if (Current.isOneOf(tok::star, tok::amp, tok::ampamp)) {
+  TrailingReturnFound = true;
+} else if (Current.is(tok::star) ||
+   (Current.isOneOf(tok::amp, tok::ampamp) &&
+(Current.NestingLevel != 0 || !Line.MightBeFunctionDecl ||
+ TrailingReturnFound))) {
   Current.Type = determineStarAmpUsage(Current,
Contexts.back().CanBeExpression &&
Contexts.back().IsExpression,
@@ -1412,6 +1416,8 @@ private:
 Current.Type = TT_ConditionalExpr;
   }
 } else if (Current.isBinaryOperator() &&
+   !(Line.MightBeFunctionDecl && Current.NestingLevel == 0 &&
+ Current.isOneOf(tok::amp, tok::ampamp)) &&
(!Current.Previous || Current.Previous->isNot(tok::l_square)) &&
(!Current.is(tok::greater) &&
 Style.Language != FormatStyle::LK_TextProto)) {
@@ -1486,10 +1492,12 @@ private:
   // colon after this, this is the only place which annotates the 
identifier
   // as a selector.)
   Current.Type = TT_SelectorName;
-} else if (Current.isOneOf(tok::identifier, tok::kw_const) &&
+} else if (Current.isOneOf(tok::identifier, tok::kw_const, tok::amp,
+   tok::ampamp) &&
Current.Previous &&
!Current.Previous->isOneOf(tok::equal, tok::at) &&
-   Line.MightBeFunctionDecl && Contexts.size() == 1) {
+   Line.MightBeFunctionDecl && !TrailingReturnFound &&
+   Contexts.size() == 1) {
   // Line.MightBeFunctionDecl can only be true after the parentheses of a
   // function declaration have been found.
   Current.Type = TT_TrailingAnnotation;
@@ -1767,6 +1775,7 @@ private:
   AnnotatedLine &Line;
   FormatToken *CurrentToken;
   bool AutoFound;
+  bool TrailingReturnFound;
   const AdditionalKeywords &Keywords;
 
   // Set of "<" tokens that do not open a template parameter list. If 
parseAngle
@@ -2680,6 +2689,14 @@ bool TokenAnnotator::spaceRequiredBetwee
   Right.MatchingParen->endsSequence(TT_DictLiteral, tok::at))
 // Objective-C dictionary literal -> no space before closing brace.
 return false;
+  if (Right.Type == TT_TrailingAnnotation &&
+  Right.isOneOf(tok::amp, tok::ampamp) &&
+  Left.isOneOf(tok::kw_const, tok::kw_volatile) &&
+  (!Right.Next || Right.Next->is(tok::semi)))
+// Match const and volatile ref-qualifiers without any additional
+// qualifiers such as
+// void Fn() const &;
+return Style.PointerAlignment != FormatStyle::PAS_Left;
   return true;
 }
 

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=373165&r1=373164&r2=373165&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sun Sep 29 06:4

r373388 - [clang-format] [PR43372] - clang-format shows replacements in DOS files when no replacement is needed

2019-10-01 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Tue Oct  1 13:20:22 2019
New Revision: 373388

URL: http://llvm.org/viewvc/llvm-project?rev=373388&view=rev
Log:
[clang-format] [PR43372] - clang-format shows replacements in DOS files when no 
replacement is needed

Summary:
This is a patch to fix PR43372 (https://bugs.llvm.org/show_bug.cgi?id=43372) - 
clang-format can't format file with includes, ( which really keep providing 
replacements for already sorted headers.)

A similar issue was addressed by @krasimir in {D60199}, however, this seemingly 
only prevented the issue when the files being formatted did not contain windows 
line endings (\r\n)

It's possible this is related to 
https://twitter.com/StephanTLavavej/status/1176722938243895296 given who 
@STL_MSFT  works for!

As people often used the existence of replacements to determine if a file needs 
clang-formatting, this is probably pretty important for windows users

There may be a better way of comparing 2 strings and ignoring \r (which appear 
in both Results and Code), I couldn't choose between this idiom or the copy_if 
approach, but I'm happy to change it to whatever people consider more 
performant.

Reviewers: krasimir, klimek, owenpan, ioeric

Reviewed By: krasimir

Subscribers: cfe-commits, STL_MSFT, krasimir

Tags: #clang-format, #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D68227

Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/SortImportsTestJava.cpp
cfe/trunk/unittests/Format/SortIncludesTest.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=373388&r1=373387&r2=373388&view=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Tue Oct  1 13:20:22 2019
@@ -1825,6 +1825,28 @@ FindCursorIndex(const SmallVectorImpl(Code, FileName, Ranges, FirstStartColumn,
- NextStartColumn, LastStartColumn);
+NextStartColumn, LastStartColumn);
   llvm::Optional CurrentCode = None;
   tooling::Replacements Fixes;
   unsigned Penalty = 0;

Modified: cfe/trunk/unittests/Format/SortImportsTestJava.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/SortImportsTestJava.cpp?rev=373388&r1=373387&r2=373388&view=diff
==
--- cfe/trunk/unittests/Format/SortImportsTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/SortImportsTestJava.cpp Tue Oct  1 13:20:22 2019
@@ -285,6 +285,13 @@ TEST_F(SortImportsTestJava, NoReplacemen
   sortIncludes(FmtStyle, Code, GetCodeRange(Code), "input.java").empty());
 }
 
+TEST_F(SortImportsTestJava, NoReplacementsForValidImportsWindows) {
+  std::string Code = "import org.a;\r\n"
+ "import org.b;\r\n";
+  EXPECT_TRUE(
+  sortIncludes(FmtStyle, Code, GetCodeRange(Code), "input.java").empty());
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang

Modified: cfe/trunk/unittests/Format/SortIncludesTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/SortIncludesTest.cpp?rev=373388&r1=373387&r2=373388&view=diff
==
--- cfe/trunk/unittests/Format/SortIncludesTest.cpp (original)
+++ cfe/trunk/unittests/Format/SortIncludesTest.cpp Tue Oct  1 13:20:22 2019
@@ -724,6 +724,14 @@ TEST_F(SortIncludesTest, DoNotOutputRepl
   EXPECT_EQ(Code, sort(Code, "input.h", 0));
 }
 
+TEST_F(SortIncludesTest,
+   DoNotOutputReplacementsForSortedBlocksWithRegroupingWindows) {
+  Style.IncludeBlocks = Style.IBS_Regroup;
+  std::string Code = "#include \"b.h\"\r\n"
+ "\r\n"
+ "#include \r\n";
+  EXPECT_EQ(Code, sort(Code, "input.h", 0));
+}
 
 TEST_F(SortIncludesTest, DoNotRegroupGroupsInGoogleObjCStyle) {
   FmtStyle = getGoogleStyle(FormatStyle::LK_ObjC);


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r373647 - [clang-format] Add ability to wrap braces after multi-line control statements

2019-10-03 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Thu Oct  3 11:42:31 2019
New Revision: 373647

URL: http://llvm.org/viewvc/llvm-project?rev=373647&view=rev
Log:
[clang-format] Add ability to wrap braces after multi-line control statements

Summary:
Change the BraceWrappingFlags' AfterControlStatement from a bool to an enum 
with three values:

* "Never": This is the default, and does not do any brace wrapping after 
control statements.
* "MultiLine": This only wraps braces after multi-line control statements (this 
really only happens when a ColumnLimit is specified).
* "Always": This always wraps braces after control statements.

The first and last options are backwards-compatible with "false" and "true", 
respectively.

The new "MultiLine" option is useful for when a wrapped control statement's 
indentation matches the subsequent block's indentation. It makes it easier to 
see at a glance where the control statement ends and where the block's code 
begins. For example:

```
if (
  foo
  && bar )
{
  baz();
}
```

vs.

```
if (
  foo
  && bar ) {
  baz();
}
```

Short control statements (1 line) do not wrap the brace to the next line, e.g.

```
if (foo) {
  bar();
} else {
  baz();
}
```

Reviewers: sammccall, owenpan, reuk, MyDeveloperDay, klimek

Reviewed By: MyDeveloperDay

Subscribers: MyDeveloperDay, cfe-commits

Patch By: mitchell-stellar

Tags: #clang-format, #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D68296

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
cfe/trunk/unittests/Format/FormatTestObjC.cpp

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=373647&r1=373646&r2=373647&view=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Thu Oct  3 11:42:31 2019
@@ -778,24 +778,46 @@ the configuration (without a prefix: ``A
   class foo
   {};
 
-  * ``bool AfterControlStatement`` Wrap control statements 
(``if``/``for``/``while``/``switch``/..).
+  * ``BraceWrappingAfterControlStatementStyle AfterControlStatement``
+Wrap control statements (``if``/``for``/``while``/``switch``/..).
 
-.. code-block:: c++
+Possible values:
 
-  true:
-  if (foo())
-  {
-  } else
-  {}
-  for (int i = 0; i < 10; ++i)
-  {}
-
-  false:
-  if (foo()) {
-  } else {
-  }
-  for (int i = 0; i < 10; ++i) {
-  }
+* ``BWACS_Never`` (in configuration: ``Never``)
+  Never wrap braces after a control statement.
+
+  .. code-block:: c++
+
+if (foo()) {
+} else {
+}
+for (int i = 0; i < 10; ++i) {
+}
+
+* ``BWACS_MultiLine`` (in configuration: ``MultiLine``)
+  Only wrap braces after a multi-line control statement.
+
+  .. code-block:: c++
+
+if (foo && bar &&
+baz)
+{
+  quux();
+}
+while (foo || bar) {
+}
+
+* ``BWACS_Always`` (in configuration: ``Always``)
+  Always wrap braces after a control statement.
+
+  .. code-block:: c++
+
+if (foo())
+{
+} else
+{}
+for (int i = 0; i < 10; ++i)
+{}
 
   * ``bool AfterEnum`` Wrap enum definitions.
 

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=373647&r1=373646&r2=373647&view=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Thu Oct  3 11:42:31 2019
@@ -782,6 +782,40 @@ struct FormatStyle {
   /// The brace breaking style to use.
   BraceBreakingStyle BreakBeforeBraces;
 
+  // Different ways to wrap braces after control statements.
+  enum BraceWrappingAfterControlStatementStyle {
+/// Never wrap braces after a control statement.
+/// \code
+///   if (foo()) {
+///   } else {
+///   }
+///   for (int i = 0; i < 10; ++i) {
+///   }
+/// \endcode
+BWACS_Never,
+/// Only wrap braces after a multi-line control statement.
+/// \code
+///   if (foo && bar &&
+///   baz)
+///   {
+/// quux();
+///   }
+///   while (foo || bar) {
+///   }
+/// \endcode
+BWACS_MultiLine,
+/// Always wrap braces after a control statement.
+/// \code
+///   if (foo())
+///   {
+///   } else
+///   {}
+///   for (int i = 0; i < 10; ++i)
+///   {}
+/// \endcode
+BWACS_Always
+  };
+
   /// Precise control over the wrapping of braces.
   /// \code
   /// 

r373707 - [clang-format] [PR43333] Fix C# breaking before function name when using Attributes

2019-10-04 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Fri Oct  4 00:56:49 2019
New Revision: 373707

URL: http://llvm.org/viewvc/llvm-project?rev=373707&view=rev
Log:
[clang-format] [PR4] Fix C# breaking before function name when using 
Attributes

Summary:
This is  a fix for https://bugs.llvm.org/show_bug.cgi?id=4

This comes with 3 main parts

  - C# attributes cause function names on a new line even when 
AlwaysBreakAfterReturnType is set to None
  - Add AlwaysBreakAfterReturnType  to None by default in the Microsoft style,
  - C# unit tests are not using Microsoft style (which we created to define the 
default C# style to match a vanilla C# project).

Reviewers: owenpan, klimek, russellmcc, mitchell-stellar

Reviewed By: mitchell-stellar

Subscribers: cfe-commits

Tags: #clang-tools-extra, #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D67629

Modified:
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestCSharp.cpp

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=373707&r1=373706&r2=373707&view=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Fri Oct  4 00:56:49 2019
@@ -489,38 +489,38 @@ struct FormatStyle {
 
   /// Different ways to break after the template declaration.
   enum BreakTemplateDeclarationsStyle {
-  /// Do not force break before declaration.
-  /// ``PenaltyBreakTemplateDeclaration`` is taken into account.
-  /// \code
-  ///template  T foo() {
-  ///}
-  ///template  T foo(int a,
-  ///int b) {
-  ///}
-  /// \endcode
-  BTDS_No,
-  /// Force break after template declaration only when the following
-  /// declaration spans multiple lines.
-  /// \code
-  ///template  T foo() {
-  ///}
-  ///template 
-  ///T foo(int a,
-  ///  int b) {
-  ///}
-  /// \endcode
-  BTDS_MultiLine,
-  /// Always break after template declaration.
-  /// \code
-  ///template 
-  ///T foo() {
-  ///}
-  ///template 
-  ///T foo(int a,
-  ///  int b) {
-  ///}
-  /// \endcode
-  BTDS_Yes
+/// Do not force break before declaration.
+/// ``PenaltyBreakTemplateDeclaration`` is taken into account.
+/// \code
+///template  T foo() {
+///}
+///template  T foo(int a,
+///int b) {
+///}
+/// \endcode
+BTDS_No,
+/// Force break after template declaration only when the following
+/// declaration spans multiple lines.
+/// \code
+///template  T foo() {
+///}
+///template 
+///T foo(int a,
+///  int b) {
+///}
+/// \endcode
+BTDS_MultiLine,
+/// Always break after template declaration.
+/// \code
+///template 
+///T foo() {
+///}
+///template 
+///T foo(int a,
+///  int b) {
+///}
+/// \endcode
+BTDS_Yes
   };
 
   /// The template declaration breaking style to use.
@@ -2186,6 +2186,10 @@ FormatStyle getWebKitStyle();
 /// http://www.gnu.org/prep/standards/standards.html
 FormatStyle getGNUStyle();
 
+/// Returns a format style complying with Microsoft style guide:
+/// 
https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017
+FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind Language);
+
 /// Returns style indicating formatting should be not applied at all.
 FormatStyle getNoStyle();
 

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=373707&r1=373706&r2=373707&view=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Fri Oct  4 00:56:49 2019
@@ -473,7 +473,10 @@ bool ContinuationIndenter::mustBreak(con
   }
 
   // If the return type spans multiple lines, wrap before the function name.
-  if ((Current.is(TT_FunctionDeclarationName) ||
+  if (((Current.is(TT_FunctionDeclarationName) &&
+// Don't break before a C# function when no break after return type
+(!Style.isCSharp() ||
+ Style.AlwaysBreakAfterReturnType != FormatStyle::RT

r373709 - [clang-format] [PR43338] C# clang format has space issues betweern C# only keywords

2019-10-04 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Fri Oct  4 01:10:22 2019
New Revision: 373709

URL: http://llvm.org/viewvc/llvm-project?rev=373709&view=rev
Log:
[clang-format] [PR43338] C# clang format has space issues betweern C# only 
keywords

Summary:
When formatting C# there can be issues with a lack of spaces between `using (` 
, `foreach (` and generic types

The C# code

```
public class Foo
{
Dictionary foo;
}

```
will be formatted as

```
public class Foo
{
Dictionaryfoo;
   ^   missing a space
}
```

This revision also reverts some of {D2} in order to make this cleaner and 
resolve an issues seen by @owenpan that the formatting didn't add a space when 
not in a code block

This also transforms C# foreach commands to be seen as tok::kw_for commands (to 
ensure foreach gets the same Brace Wrapping behavior as for without littering 
the code with `if(Style.isCSharp())`

Reviewers: owenpan, klimek, russellmcc, mitchell-stellar

Reviewed By: mitchell-stellar

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D67660

Modified:
cfe/trunk/lib/Format/FormatTokenLexer.cpp
cfe/trunk/lib/Format/FormatTokenLexer.h
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestCSharp.cpp

Modified: cfe/trunk/lib/Format/FormatTokenLexer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatTokenLexer.cpp?rev=373709&r1=373708&r2=373709&view=diff
==
--- cfe/trunk/lib/Format/FormatTokenLexer.cpp (original)
+++ cfe/trunk/lib/Format/FormatTokenLexer.cpp Fri Oct  4 01:10:22 2019
@@ -80,6 +80,8 @@ void FormatTokenLexer::tryMergePreviousT
   return;
 if (tryMergeCSharpNullConditionals())
   return;
+if (tryTransformCSharpForEach())
+  return;
 static const tok::TokenKind JSRightArrow[] = {tok::equal, tok::greater};
 if (tryMergeTokens(JSRightArrow, TT_JsFatArrow))
   return;
@@ -254,6 +256,21 @@ bool FormatTokenLexer::tryMergeCSharpNul
   return true;
 }
 
+// In C# transform identifier foreach into kw_foreach
+bool FormatTokenLexer::tryTransformCSharpForEach() {
+  if (Tokens.size() < 1)
+return false;
+  auto &Identifier = *(Tokens.end() - 1);
+  if (!Identifier->is(tok::identifier))
+return false;
+  if (Identifier->TokenText != "foreach")
+return false;
+
+  Identifier->Type = TT_ForEachMacro;
+  Identifier->Tok.setKind(tok::kw_for);
+  return true;
+}
+
 bool FormatTokenLexer::tryMergeLessLess() {
   // Merge X,less,less,Y into X,lessless,Y unless X or Y is less.
   if (Tokens.size() < 3)

Modified: cfe/trunk/lib/Format/FormatTokenLexer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatTokenLexer.h?rev=373709&r1=373708&r2=373709&view=diff
==
--- cfe/trunk/lib/Format/FormatTokenLexer.h (original)
+++ cfe/trunk/lib/Format/FormatTokenLexer.h Fri Oct  4 01:10:22 2019
@@ -53,6 +53,7 @@ private:
   bool tryMergeCSharpKeywordVariables();
   bool tryMergeCSharpNullConditionals();
   bool tryMergeCSharpDoubleQuestion();
+  bool tryTransformCSharpForEach();
 
   bool tryMergeTokens(ArrayRef Kinds, TokenType NewType);
 

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=373709&r1=373708&r2=373709&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Oct  4 01:10:22 2019
@@ -2640,10 +2640,6 @@ bool TokenAnnotator::spaceRequiredBetwee
 return Style.Language == FormatStyle::LK_JavaScript ||
!Left.TokenText.endswith("=*/");
   if (Right.is(tok::l_paren)) {
-// using (FileStream fs...
-if (Style.isCSharp() && Left.is(tok::kw_using) &&
-Style.SpaceBeforeParens != FormatStyle::SBPO_Never)
-  return true;
 if ((Left.is(tok::r_paren) && Left.is(TT_AttributeParen)) ||
 (Left.is(tok::r_square) && Left.is(TT_AttributeSquare)))
   return true;
@@ -2742,7 +2738,15 @@ bool TokenAnnotator::spaceRequiredBefore
 // and "%d %d"
 if (Left.is(tok::numeric_constant) && Right.is(tok::percent))
   return Right.WhitespaceRange.getEnd() != 
Right.WhitespaceRange.getBegin();
-  } else if (Style.Language == FormatStyle::LK_JavaScript || Style.isCSharp()) 
{
+  } else if (Style.isCSharp()) {
+// space between type and variable e.g. Dictionary foo;
+if (Left.is(TT_TemplateCloser) && Right.is(TT_StartOfName))
+  return true;
+// space between keywords and paren e.g. "using ("
+if (Right.is(tok::l_paren))
+  if (Left.is(tok::kw_using))
+return spaceRequiredBeforeParens(Left);
+  } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;
 // for await ( ...

r373746 - [clang-format] [PR42417] clang-format inserts a space after '->' for operator->() overloading

2019-10-04 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Fri Oct  4 06:24:15 2019
New Revision: 373746

URL: http://llvm.org/viewvc/llvm-project?rev=373746&view=rev
Log:
[clang-format] [PR42417] clang-format inserts a space after '->' for 
operator->() overloading

Summary:
https://bugs.llvm.org/show_bug.cgi?id=42417

This revision removes the extra space between the opertor-> and the parens ()

```
class Bug {
auto operator-> () -> int*;
auto operator++(int) -> int;
};
```

Reviewers: klimek, owenpan, byoungyoung, mitchell-stellar

Reviewed By: mitchell-stellar

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D68242

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=373746&r1=373745&r2=373746&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Oct  4 06:24:15 2019
@@ -1393,7 +1393,9 @@ private:
Style.Language == FormatStyle::LK_Java) {
   Current.Type = TT_LambdaArrow;
 } else if (Current.is(tok::arrow) && AutoFound && Line.MustBeDeclaration &&
-   Current.NestingLevel == 0) {
+   Current.NestingLevel == 0 &&
+   !Current.Previous->is(tok::kw_operator)) {
+  // not auto operator->() -> xxx;
   Current.Type = TT_TrailingReturnArrow;
   TrailingReturnFound = true;
 } else if (Current.is(tok::star) ||

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=373746&r1=373745&r2=373746&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Oct  4 06:24:15 2019
@@ -4956,6 +4956,10 @@ TEST_F(FormatTest, DontBreakBeforeQualif
 
 TEST_F(FormatTest, TrailingReturnType) {
   verifyFormat("auto foo() -> int;\n");
+  // correct trailing return type spacing
+  verifyFormat("auto operator->() -> int;\n");
+  verifyFormat("auto operator++(int) -> int;\n");
+
   verifyFormat("struct S {\n"
"  auto bar() const -> int;\n"
"};");


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r373750 - [clang-format] [PR43531] clang-format damages "alternative representations" for operators

2019-10-04 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Fri Oct  4 07:16:59 2019
New Revision: 373750

URL: http://llvm.org/viewvc/llvm-project?rev=373750&view=rev
Log:
[clang-format] [PR43531] clang-format damages "alternative representations" for 
operators

Summary:
https://bugs.llvm.org/show_bug.cgi?id=43531

Fix for clang-format incorrectly handles "alternative operators" as described 
by https://en.cppreference.com/w/cpp/language/operator_alternative

compl = ~
not = !

these are unary operators, and clang-format will remove the space between them 
and a numeric constant

this incorrectly formats the following code

```
int a compl 5;
int a not 5;
```

into:

```
int a compl5;
int a not5;
```

The code adds FIXME unit tests for "alternative token" representations for {} 
[] and # as defined by the same link, which would require a more detailed 
change to the FormatTokenLexer

Reviewers: klimek, reuk, owenpan, mitchell-stellar, STL_MSFT

Reviewed By: mitchell-stellar

Subscribers: cfe-commits

Tags: #clang-format, #clang-tools-extra, #clang

Differential Revision: https://reviews.llvm.org/D68332

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=373750&r1=373749&r2=373750&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Oct  4 07:16:59 2019
@@ -2900,9 +2900,19 @@ bool TokenAnnotator::spaceRequiredBefore
   return false;
 return true;
   }
-  if (Left.is(TT_UnaryOperator))
+  if (Left.is(TT_UnaryOperator)) {
+// The alternative operators for ~ and ! are "compl" and "not".
+// If they are used instead, we do not want to combine them with
+// the token to the right, unless that is a left paren.
+if (!Right.is(tok::l_paren)) {
+  if (Left.is(tok::exclaim) && Left.TokenText == "not")
+return true;
+  if (Left.is(tok::tilde) && Left.TokenText == "compl")
+return true;
+}
 return (Style.SpaceAfterLogicalNot && Left.is(tok::exclaim)) ||
Right.is(TT_BinaryOperator);
+  }
 
   // If the next token is a binary operator or a selector name, we have
   // incorrectly classified the parenthesis as a cast. FIXME: Detect correctly.

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=373750&r1=373749&r2=373750&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Oct  4 07:16:59 2019
@@ -14609,6 +14609,48 @@ TEST_F(FormatTest, AmbersandInLamda) {
   verifyFormat("auto lambda = [&a = a]() { a = 2; };", AlignStyle);
 }
 
+TEST_F(FormatTest, AlternativeOperators) {
+  // Test case for ensuring alternate operators are not
+  // combined with their right most neighbour.
+  verifyFormat("int a and b;");
+  verifyFormat("int a and_eq b;");
+  verifyFormat("int a bitand b;");
+  verifyFormat("int a bitor b;");
+  verifyFormat("int a compl b;");
+  verifyFormat("int a not b;");
+  verifyFormat("int a not_eq b;");
+  verifyFormat("int a or b;");
+  verifyFormat("int a xor b;");
+  verifyFormat("int a xor_eq b;");
+  verifyFormat("return this not_eq bitand other;");
+  verifyFormat("bool operator not_eq(const X bitand other)");
+
+  verifyFormat("int a and 5;");
+  verifyFormat("int a and_eq 5;");
+  verifyFormat("int a bitand 5;");
+  verifyFormat("int a bitor 5;");
+  verifyFormat("int a compl 5;");
+  verifyFormat("int a not 5;");
+  verifyFormat("int a not_eq 5;");
+  verifyFormat("int a or 5;");
+  verifyFormat("int a xor 5;");
+  verifyFormat("int a xor_eq 5;");
+
+  verifyFormat("int a compl(5);");
+  verifyFormat("int a not(5);");
+
+  /* FIXME handle alternate tokens
+   * https://en.cppreference.com/w/cpp/language/operator_alternative
+  // alternative tokens
+  verifyFormat("compl foo();"); //  ~foo();
+  verifyFormat("foo() <%%>;");  // foo();
+  verifyFormat("void foo() <%%>;"); // void foo(){}
+  verifyFormat("int a <:1:>;"); // int a[1];[
+  verifyFormat("%:define ABC abc"); // #define ABC abc
+  verifyFormat("%:%:"); // ##
+  */
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r373751 - [clang-format] C++11 braced lists should respect the SpacesInParentheses setting

2019-10-04 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Fri Oct  4 07:25:20 2019
New Revision: 373751

URL: http://llvm.org/viewvc/llvm-project?rev=373751&view=rev
Log:
[clang-format] C++11 braced lists should respect the SpacesInParentheses setting

Summary:
According to the clang-format documentation, "Fundamentally, C++11 braced lists 
are formatted exactly like function calls would be formatted in their place. If 
the braced list follows a name (e.g. a type or variable name), clang-format 
formats as if the `{}` were the parentheses of a function call with that name."

This patch furthers the treatment of C++11 braced list braces as parentheses by 
respecting the `SpacesInParentheses` setting.

Reviewers: MyDeveloperDay, reuk, owenpan

Reviewed By: MyDeveloperDay

Subscribers: cfe-commits

Tags: #clang-format, #clang

Patch By: mitchell-stellar

Differential Revision: https://reviews.llvm.org/D68415

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=373751&r1=373750&r2=373751&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Oct  4 07:25:20 2019
@@ -2196,7 +2196,8 @@ void TokenAnnotator::calculateFormatting
 if (Current->is(TT_LineComment)) {
   if (Current->Previous->BlockKind == BK_BracedInit &&
   Current->Previous->opensScope())
-Current->SpacesRequiredBefore = Style.Cpp11BracedListStyle ? 0 : 1;
+Current->SpacesRequiredBefore =
+(Style.Cpp11BracedListStyle && !Style.SpacesInParentheses) ? 0 : 1;
   else
 Current->SpacesRequiredBefore = Style.SpacesBeforeTrailingComments;
 
@@ -2520,7 +2521,9 @@ bool TokenAnnotator::spaceRequiredBetwee
 return Left.is(tok::hash);
   if (Left.isOneOf(tok::hashhash, tok::hash))
 return Right.is(tok::hash);
-  if (Left.is(tok::l_paren) && Right.is(tok::r_paren))
+  if ((Left.is(tok::l_paren) && Right.is(tok::r_paren)) ||
+  (Left.is(tok::l_brace) && Left.BlockKind != BK_Block &&
+   Right.is(tok::r_brace) && Right.BlockKind != BK_Block))
 return Style.SpaceInEmptyParentheses;
   if (Left.is(tok::l_paren) || Right.is(tok::r_paren))
 return (Right.is(TT_CastRParen) ||
@@ -2636,7 +2639,7 @@ bool TokenAnnotator::spaceRequiredBetwee
   if ((Left.is(tok::l_brace) && Left.BlockKind != BK_Block) ||
   (Right.is(tok::r_brace) && Right.MatchingParen &&
Right.MatchingParen->BlockKind != BK_Block))
-return !Style.Cpp11BracedListStyle;
+return Style.Cpp11BracedListStyle ? Style.SpacesInParentheses : true;
   if (Left.is(TT_BlockComment))
 // No whitespace in x(/*foo=*/1), except for JavaScript.
 return Style.Language == FormatStyle::LK_JavaScript ||

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=373751&r1=373750&r2=373751&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Oct  4 07:25:20 2019
@@ -8214,6 +8214,34 @@ TEST_F(FormatTest, LayoutCxx11BraceIniti
   SpaceBeforeBrace.SpaceBeforeCpp11BracedList = true;
   verifyFormat("vector x {1, 2, 3, 4};", SpaceBeforeBrace);
   verifyFormat("f({}, {{}, {}}, MyMap[{k, v}]);", SpaceBeforeBrace);
+
+  FormatStyle SpaceBetweenBraces = getLLVMStyle();
+  SpaceBetweenBraces.SpacesInAngles = true;
+  SpaceBetweenBraces.SpacesInParentheses = true;
+  SpaceBetweenBraces.SpacesInSquareBrackets = true;
+  verifyFormat("vector< int > x{ 1, 2, 3, 4 };", SpaceBetweenBraces);
+  verifyFormat("f( {}, { {}, {} }, MyMap[ { k, v } ] );", SpaceBetweenBraces);
+  verifyFormat("vector< int > x{ // comment 1\n"
+   " 1, 2, 3, 4 };",
+   SpaceBetweenBraces);
+  SpaceBetweenBraces.ColumnLimit = 20;
+  EXPECT_EQ("vector< int > x{\n"
+"1, 2, 3, 4 };",
+format("vectorx{1,2,3,4};", SpaceBetweenBraces));
+  SpaceBetweenBraces.ColumnLimit = 24;
+  EXPECT_EQ("vector< int > x{ 1, 2,\n"
+" 3, 4 };",
+format("vectorx{1,2,3,4};", SpaceBetweenBraces));
+  EXPECT_EQ("vector< int > x{\n"
+"1,\n"
+"2,\n"
+"3,\n"
+"4,\n"
+"};",
+format("vectorx{1,2,3,4,};", SpaceBetweenBraces));
+  verifyFormat("vector< int > x{};", SpaceBetweenBraces);
+  SpaceBetweenBraces.SpaceInEmptyParentheses = true;
+  verifyFormat("vector< int > x{ };", SpaceBetweenBraces);
 }
 
 TEST_F(FormatTest, FormatsBracedListsInColumnLayout) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinf

r373821 - [clang-format] SpacesInSquareBrackets should affect lambdas with parameters too

2019-10-05 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Sat Oct  5 02:55:23 2019
New Revision: 373821

URL: http://llvm.org/viewvc/llvm-project?rev=373821&view=rev
Log:
[clang-format] SpacesInSquareBrackets should affect lambdas with parameters too

Summary:
This patch makes the `SpacesInSquareBrackets` setting also apply to C++ lambdas 
with parameters.

Looking through the revision history, it appears support for only array 
brackets was added, and lambda brackets were ignored. Therefore, I am inclined 
to think it was simply an omission, rather than a deliberate choice.

See https://bugs.llvm.org/show_bug.cgi?id=17887 and 
https://reviews.llvm.org/D4944.

Reviewers: MyDeveloperDay, reuk, owenpan

Reviewed By: MyDeveloperDay

Subscribers: cfe-commits

Patch by: mitchell-stellar

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D68473

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=373821&r1=373820&r2=373821&view=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Sat Oct  5 02:55:23 2019
@@ -2301,7 +2301,8 @@ the configuration (without a prefix: ``A
 
 **SpacesInSquareBrackets** (``bool``)
   If ``true``, spaces will be inserted after ``[`` and before ``]``.
-  Lambdas or unspecified size array declarations will not be affected.
+  Lambdas without arguments or unspecified size array declarations will not be
+  affected.
 
   .. code-block:: c++
 

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=373821&r1=373820&r2=373821&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Sat Oct  5 02:55:23 2019
@@ -2616,8 +2616,8 @@ bool TokenAnnotator::spaceRequiredBetwee
   if (Left.is(tok::l_square))
 return (Left.is(TT_ArrayInitializerLSquare) && Right.isNot(tok::r_square) 
&&
 SpaceRequiredForArrayInitializerLSquare(Left, Style)) ||
-   (Left.isOneOf(TT_ArraySubscriptLSquare,
- TT_StructuredBindingLSquare) &&
+   (Left.isOneOf(TT_ArraySubscriptLSquare, TT_StructuredBindingLSquare,
+ TT_LambdaLSquare) &&
 Style.SpacesInSquareBrackets && Right.isNot(tok::r_square));
   if (Right.is(tok::r_square))
 return Right.MatchingParen &&
@@ -2626,7 +2626,8 @@ bool TokenAnnotator::spaceRequiredBetwee
  Style)) ||
 (Style.SpacesInSquareBrackets &&
  Right.MatchingParen->isOneOf(TT_ArraySubscriptLSquare,
-  TT_StructuredBindingLSquare)) ||
+  TT_StructuredBindingLSquare,
+  TT_LambdaLSquare)) ||
 Right.MatchingParen->is(TT_AttributeParen));
   if (Right.is(tok::l_square) &&
   !Right.isOneOf(TT_ObjCMethodExpr, TT_LambdaLSquare,

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=373821&r1=373820&r2=373821&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sat Oct  5 02:55:23 2019
@@ -10515,10 +10515,6 @@ TEST_F(FormatTest, ConfigurableSpacesInS
 
   FormatStyle Spaces = getLLVMStyle();
   Spaces.SpacesInSquareBrackets = true;
-  // Lambdas unchanged.
-  verifyFormat("int c = []() -> int { return 2; }();\n", Spaces);
-  verifyFormat("return [i, args...] {};", Spaces);
-
   // Not lambdas.
   verifyFormat("int a[ 5 ];", Spaces);
   verifyFormat("a[ 3 ] += 42;", Spaces);
@@ -10529,6 +10525,9 @@ TEST_F(FormatTest, ConfigurableSpacesInS
   verifyFormat("std::unique_ptr foo() {}", Spaces);
   verifyFormat("int i = a[ a ][ a ]->f();", Spaces);
   verifyFormat("int i = (*b)[ a ]->f();", Spaces);
+  // Lambdas.
+  verifyFormat("int c = []() -> int { return 2; }();\n", Spaces);
+  verifyFormat("return [ i, args... ] {};", Spaces);
 }
 
 TEST_F(FormatTest, ConfigurableSpaceBeforeAssignmentOperators) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r373844 - [clang-format][docs] Fix the Google C++ and Chromium style guide URLs

2019-10-06 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Sun Oct  6 02:37:58 2019
New Revision: 373844

URL: http://llvm.org/viewvc/llvm-project?rev=373844&view=rev
Log:
[clang-format][docs] Fix the Google C++ and Chromium style guide URLs

Summary: The Google C++ and Chromium style guides are broken in the 
clang-format docs. This patch updates them.

Reviewers: djasper, MyDeveloperDay

Reviewed By: MyDeveloperDay

Subscribers: cfe-commits

Tags: #clang

Patch by: m4tx

Differential Revision: https://reviews.llvm.org/D61256

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=373844&r1=373843&r2=373844&view=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Sun Oct  6 02:37:58 2019
@@ -141,7 +141,7 @@ the configuration (without a prefix: ``A
 `_
   * ``Chromium``
 A style complying with `Chromium's style guide
-`_
+
`_
   * ``Mozilla``
 A style complying with `Mozilla's style guide
 `_


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r373921 - [clang-format] [NFC] Ensure clang-format is itself clang-formatted.

2019-10-07 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Mon Oct  7 09:53:35 2019
New Revision: 373921

URL: http://llvm.org/viewvc/llvm-project?rev=373921&view=rev
Log:
[clang-format] [NFC] Ensure clang-format is itself clang-formatted.

Summary:
Before making a proposed change, ensure ClangFormat.cpp is fully 
clang-formatted,

no functional change just clang-formatting using the in tree .clang-format.

Reviewers: mitchell-stellar

Reviewed By: mitchell-stellar

Subscribers: Eugene.Zelenko, cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D68551

Modified:
cfe/trunk/tools/clang-format/ClangFormat.cpp

Modified: cfe/trunk/tools/clang-format/ClangFormat.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=373921&r1=373920&r2=373921&view=diff
==
--- cfe/trunk/tools/clang-format/ClangFormat.cpp (original)
+++ cfe/trunk/tools/clang-format/ClangFormat.cpp Mon Oct  7 09:53:35 2019
@@ -51,13 +51,14 @@ static cl::list
  "Can only be used with one input file."),
 cl::cat(ClangFormatCategory));
 static cl::list
-LineRanges("lines", cl::desc(": - format a range of\n"
- "lines (both 1-based).\n"
- "Multiple ranges can be formatted by specifying\n"
- "several -lines arguments.\n"
- "Can't be used with -offset and -length.\n"
- "Can only be used with one input file."),
-   cl::cat(ClangFormatCategory));
+LineRanges("lines",
+   cl::desc(": - format a range of\n"
+"lines (both 1-based).\n"
+"Multiple ranges can be formatted by specifying\n"
+"several -lines arguments.\n"
+"Can't be used with -offset and -length.\n"
+"Can only be used with one input file."),
+   cl::cat(ClangFormatCategory));
 static cl::opt
 Style("style", cl::desc(clang::format::StyleOptionHelpDescription),
   cl::init(clang::format::DefaultFormatStyle),
@@ -72,12 +73,12 @@ static cl::opt
   cl::init(clang::format::DefaultFallbackStyle),
   cl::cat(ClangFormatCategory));
 
-static cl::opt
-AssumeFileName("assume-filename",
-   cl::desc("When reading from stdin, clang-format assumes this\n"
-"filename to look for a style config file (with\n"
-"-style=file) and to determine the language."),
-   cl::init(""), cl::cat(ClangFormatCategory));
+static cl::opt AssumeFileName(
+"assume-filename",
+cl::desc("When reading from stdin, clang-format assumes this\n"
+ "filename to look for a style config file (with\n"
+ "-style=file) and to determine the language."),
+cl::init(""), cl::cat(ClangFormatCategory));
 
 static cl::opt Inplace("i",
  cl::desc("Inplace edit s, if specified."),
@@ -249,8 +250,8 @@ static bool format(StringRef FileName) {
   // On Windows, overwriting a file with an open file mapping doesn't work,
   // so read the whole file into memory when formatting in-place.
   ErrorOr> CodeOrErr =
-  !OutputXML && Inplace ? MemoryBuffer::getFileAsStream(FileName) :
-  MemoryBuffer::getFileOrSTDIN(FileName);
+  !OutputXML && Inplace ? MemoryBuffer::getFileAsStream(FileName)
+: MemoryBuffer::getFileOrSTDIN(FileName);
   if (std::error_code EC = CodeOrErr.getError()) {
 errs() << EC.message() << "\n";
 return true;
@@ -264,20 +265,21 @@ static bool format(StringRef FileName) {
   // https://en.wikipedia.org/wiki/Byte_order_mark#Byte_order_marks_by_encoding
   // for more information.
   StringRef BufStr = Code->getBuffer();
-  const char *InvalidBOM = llvm::StringSwitch(BufStr)
-.StartsWith(llvm::StringLiteral::withInnerNUL("\x00\x00\xFE\xFF"),
-  "UTF-32 (BE)")
-.StartsWith(llvm::StringLiteral::withInnerNUL("\xFF\xFE\x00\x00"),
-  "UTF-32 (LE)")
-.StartsWith("\xFE\xFF", "UTF-16 (BE)")
-.StartsWith("\xFF\xFE", "UTF-16 (LE)")
-.StartsWith("\x2B\x2F\x76", "UTF-7")
-.StartsWith("\xF7\x64\x4C", "UTF-1")
-.StartsWith("\xDD\x73\x66\x73", "UTF-EBCDIC")
-.StartsWith("\x0E\xFE\xFF", "SCSU")
-.StartsWith("\xFB\xEE\x28", "BOCU-1")
-.StartsWith("\x84\x31\x95\x33", "GB-18030")
-.Default(nullptr);
+  const char *InvalidBOM =
+  llvm::StringSwitch(BufStr)
+  .StartsWith(llvm::StringLiteral::withInnerNUL("\x00\x00\xFE\xFF"),
+  "UTF-32 (BE)")
+  .StartsWith(llvm::StringLiteral::withInnerNUL("\xFF\xFE\x00\x00"),
+  "UTF-32 (LE)")
+  .StartsWith("\xFE\xFF", "UTF-16 (BE)")
+ 

r373922 - [clang-format] [PR27004] omits leading space for noexcept when formatting operator delete()

2019-10-07 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Mon Oct  7 10:03:44 2019
New Revision: 373922

URL: http://llvm.org/viewvc/llvm-project?rev=373922&view=rev
Log:
[clang-format] [PR27004] omits leading space for noexcept when formatting 
operator delete()

Summary:
clang-format is incorrectly thinking the parameter parens are part of a cast 
operation, this is resulting in there sometimes being not space between the 
paren and the noexcept (and other keywords like volatile etc..)

```
void operator++(int) noexcept;
void operator++(int &) noexcept;
void operator delete(void *, std::size_t, const std::nothrow_t &)noexcept;
```

Reviewers: klimek, owenpan, mitchell-stellar

Reviewed By: mitchell-stellar

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D68481

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=373922&r1=373921&r2=373922&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Oct  7 10:03:44 2019
@@ -1611,6 +1611,13 @@ private:
 if (Tok.Next->is(tok::question))
   return false;
 
+// Functions which end with decorations like volatile, noexcept are 
unlikely
+// to be casts.
+if (Tok.Next->isOneOf(tok::kw_noexcept, tok::kw_volatile, tok::kw_const,
+  tok::kw_throw, tok::l_square, tok::arrow,
+  Keywords.kw_override, Keywords.kw_final))
+  return false;
+
 // As Java has no function types, a "(" after the ")" likely means that 
this
 // is a cast.
 if (Style.Language == FormatStyle::LK_Java && Tok.Next->is(tok::l_paren))

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=373922&r1=373921&r2=373922&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Oct  7 10:03:44 2019
@@ -14678,6 +14678,33 @@ TEST_F(FormatTest, AlternativeOperators)
   */
 }
 
+TEST_F(FormatTest, NotCastRPaen) {
+
+  verifyFormat("void operator++(int) noexcept;");
+  verifyFormat("void operator++(int &) noexcept;");
+  verifyFormat("void operator delete(void *, std::size_t, const std::nothrow_t 
"
+   "&) noexcept;");
+  verifyFormat(
+  "void operator delete(std::size_t, const std::nothrow_t &) noexcept;");
+  verifyFormat("void operator delete(const std::nothrow_t &) noexcept;");
+  verifyFormat("void operator delete(std::nothrow_t &) noexcept;");
+  verifyFormat("void operator delete(nothrow_t &) noexcept;");
+  verifyFormat("void operator delete(foo &) noexcept;");
+  verifyFormat("void operator delete(foo) noexcept;");
+  verifyFormat("void operator delete(int) noexcept;");
+  verifyFormat("void operator delete(int &) noexcept;");
+  verifyFormat("void operator delete(int &) volatile noexcept;");
+  verifyFormat("void operator delete(int &) const");
+  verifyFormat("void operator delete(int &) = default");
+  verifyFormat("void operator delete(int &) = delete");
+  verifyFormat("void operator delete(int &) [[noreturn]]");
+  verifyFormat("void operator delete(int &) throw();");
+  verifyFormat("void operator delete(int &) throw(int);");
+  verifyFormat("auto operator delete(int &) -> int;");
+  verifyFormat("auto operator delete(int &) override");
+  verifyFormat("auto operator delete(int &) final");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r374399 - [clang-format] throws an incorrect assertion in consumeToken() formatting the MSVC stl

2019-10-10 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Thu Oct 10 10:54:47 2019
New Revision: 374399

URL: http://llvm.org/viewvc/llvm-project?rev=374399&view=rev
Log:
[clang-format] throws an incorrect assertion in consumeToken() formatting the 
MSVC stl

Summary:
An incorrect assertion is thrown when clang-formatting MSVC's STL library

```
Assertion failed: !Line.startsWith(tok::hash), file 
C:/llvm/llvm-project/clang/lib/Format/TokenAnnotator.cpp, line 847
Stack dump:
0.  Program arguments: C:\llvm\build\bin\clang-format.exe -i -n 
./stl/inc/xkeycheck.h
```

```
Enable warning C4005 to find the forbidden define.
```

Reviewers: mitchell-stellar, STL_MSFT, klimek, krasimir

Reviewed By: mitchell-stellar

Subscribers: cfe-commits

Tags: #clang-format, #clang-tools-extra, #clang

Differential Revision: https://reviews.llvm.org/D68707

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=374399&r1=374398&r2=374399&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Oct 10 10:54:47 2019
@@ -845,7 +845,6 @@ private:
   break;
 case tok::kw_if:
 case tok::kw_while:
-  assert(!Line.startsWith(tok::hash));
   if (Tok->is(tok::kw_if) && CurrentToken &&
   CurrentToken->isOneOf(tok::kw_constexpr, tok::identifier))
 next();

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=374399&r1=374398&r2=374399&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Oct 10 10:54:47 2019
@@ -14723,6 +14723,12 @@ TEST_F(FormatTest, NotCastRPaen) {
   verifyFormat("auto operator delete(int &) final");
 }
 
-} // end namespace
-} // end namespace format
-} // end namespace clang
+TEST_F(FormatTest, STLWhileNotDefineChed) {
+  verifyFormat("#if defined(while)\n"
+   "#define while EMIT WARNING C4005\n"
+   "#endif // while");
+}
+
+} // namespace
+} // namespace format
+} // namespace clang


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r374663 - [clang-format] Proposal for clang-format to give compiler style warnings

2019-10-12 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Sat Oct 12 08:36:05 2019
New Revision: 374663

URL: http://llvm.org/viewvc/llvm-project?rev=374663&view=rev
Log:
[clang-format] Proposal for clang-format to give compiler style warnings

Summary:
Related somewhat to {D29039}

On seeing a quote on twitter by @invalidop

> If it's not formatted with clang-format it's a build error.

This made me want to change the way I use clang-format into a tool that could 
optionally show me where my source code violates clang-format syle.

When I'm making a change to clang-format itself, one thing I like to do to test 
the change is to ensure I didn't cause a huge wave of changes, what I want to 
do is simply run this on a known formatted directory and see if any new 
differences arrive in a manner I'm used to.

This started me thinking that we should allow build systems to run clang-format 
on a whole tree and emit compiler style warnings about files that fail 
clang-format in a form that would make them as a warning in most build systems 
and because those build systems range in their construction I don't think its 
unreasonable to NOT expect them to have to do the directory searching or 
parsing the output replacements themselves, but simply transform that into an 
error code when there are changes required.

I am starting this by suggesing adding a -n or -dry-run command line argument 
which would emit a warning/error of the form

Support for various common compiler command line argumuments like '-Werror' and 
'-ferror-limit' could make this very flexible to be integrated into build 
systems and CI systems.

```
> $ /usr/bin/clang-format --dry-run ClangFormat.cpp -ferror-limit=3 
> -fcolor-diagnostics
> ClangFormat.cpp:54:29: warning: code should be clang-formatted 
> [-Wclang-format-violations]
> static cl::list
> ^
> ClangFormat.cpp:55:20: warning: code should be clang-formatted 
> [-Wclang-format-violations]
> LineRanges("lines", cl::desc(": - format a range of\n"
>^
> ClangFormat.cpp:55:77: warning: code should be clang-formatted 
> [-Wclang-format-violations]
> LineRanges("lines", cl::desc(": - format a range of\n"
> ^
```

Reviewers: mitchell-stellar, klimek, owenpan

Reviewed By: klimek

Subscribers: mgorny, cfe-commits

Tags: #clang-format, #clang-tools-extra, #clang

Differential Revision: https://reviews.llvm.org/D68554

Added:
cfe/trunk/test/Format/dry-run-alias.cpp
cfe/trunk/test/Format/dry-run.cpp
Modified:
cfe/trunk/tools/clang-format/CMakeLists.txt
cfe/trunk/tools/clang-format/ClangFormat.cpp

Added: cfe/trunk/test/Format/dry-run-alias.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Format/dry-run-alias.cpp?rev=374663&view=auto
==
--- cfe/trunk/test/Format/dry-run-alias.cpp (added)
+++ cfe/trunk/test/Format/dry-run-alias.cpp Sat Oct 12 08:36:05 2019
@@ -0,0 +1,4 @@
+// RUN: clang-format -style=LLVM -i -n %s 2> %t.stderr
+// RUN: grep -E "*code should be clang-formatted*" %t.stderr
+
+int a ;

Added: cfe/trunk/test/Format/dry-run.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Format/dry-run.cpp?rev=374663&view=auto
==
--- cfe/trunk/test/Format/dry-run.cpp (added)
+++ cfe/trunk/test/Format/dry-run.cpp Sat Oct 12 08:36:05 2019
@@ -0,0 +1,4 @@
+// RUN: clang-format -style=LLVM -i --dry-run %s 2> %t.stderr
+// RUN: grep -E "*code should be clang-formatted*" %t.stderr
+
+int a ;

Modified: cfe/trunk/tools/clang-format/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/CMakeLists.txt?rev=374663&r1=374662&r2=374663&view=diff
==
--- cfe/trunk/tools/clang-format/CMakeLists.txt (original)
+++ cfe/trunk/tools/clang-format/CMakeLists.txt Sat Oct 12 08:36:05 2019
@@ -7,6 +7,7 @@ add_clang_tool(clang-format
 set(CLANG_FORMAT_LIB_DEPS
   clangBasic
   clangFormat
+  clangFrontend
   clangRewrite
   clangToolingCore
   )

Modified: cfe/trunk/tools/clang-format/ClangFormat.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=374663&r1=374662&r2=374663&view=diff
==
--- cfe/trunk/tools/clang-format/ClangFormat.cpp (original)
+++ cfe/trunk/tools/clang-format/ClangFormat.cpp Sat Oct 12 08:36:05 2019
@@ -18,6 +18,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Version.h"
 #include "clang/Format/Format.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/Rewrite/Core/Rewriter.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
@@ -108,6 +109,54 @@ static cl::opt
 Verbose("verbose", cl::desc("If set, shows the list of processed files"),
  

r374720 - [clang-format] Proposal for clang-format to give compiler style warnings

2019-10-13 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Sun Oct 13 07:51:45 2019
New Revision: 374720

URL: http://llvm.org/viewvc/llvm-project?rev=374720&view=rev
Log:
[clang-format] Proposal for clang-format to give compiler style warnings

relanding {D68554} with fixed lit tests, checked on Windows and MacOS

Added:
cfe/trunk/test/Format/dry-run-alias.cpp
cfe/trunk/test/Format/dry-run.cpp
Modified:
cfe/trunk/tools/clang-format/CMakeLists.txt
cfe/trunk/tools/clang-format/ClangFormat.cpp

Added: cfe/trunk/test/Format/dry-run-alias.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Format/dry-run-alias.cpp?rev=374720&view=auto
==
--- cfe/trunk/test/Format/dry-run-alias.cpp (added)
+++ cfe/trunk/test/Format/dry-run-alias.cpp Sun Oct 13 07:51:45 2019
@@ -0,0 +1,4 @@
+// RUN: clang-format -style=LLVM -i -n %s 2> %t.stderr
+// RUN: grep -E "(.*)code should be clang-formatted(.*)" %t.stderr
+
+int a ;

Added: cfe/trunk/test/Format/dry-run.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Format/dry-run.cpp?rev=374720&view=auto
==
--- cfe/trunk/test/Format/dry-run.cpp (added)
+++ cfe/trunk/test/Format/dry-run.cpp Sun Oct 13 07:51:45 2019
@@ -0,0 +1,4 @@
+// RUN: clang-format -style=LLVM -i --dry-run %s 2> %t.stderr
+// RUN: grep -E "(.*)code should be clang-formatted(.*)" %t.stderr
+
+int a ;

Modified: cfe/trunk/tools/clang-format/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/CMakeLists.txt?rev=374720&r1=374719&r2=374720&view=diff
==
--- cfe/trunk/tools/clang-format/CMakeLists.txt (original)
+++ cfe/trunk/tools/clang-format/CMakeLists.txt Sun Oct 13 07:51:45 2019
@@ -7,6 +7,7 @@ add_clang_tool(clang-format
 set(CLANG_FORMAT_LIB_DEPS
   clangBasic
   clangFormat
+  clangFrontend
   clangRewrite
   clangToolingCore
   )

Modified: cfe/trunk/tools/clang-format/ClangFormat.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=374720&r1=374719&r2=374720&view=diff
==
--- cfe/trunk/tools/clang-format/ClangFormat.cpp (original)
+++ cfe/trunk/tools/clang-format/ClangFormat.cpp Sun Oct 13 07:51:45 2019
@@ -18,6 +18,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Version.h"
 #include "clang/Format/Format.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/Rewrite/Core/Rewriter.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
@@ -108,6 +109,54 @@ static cl::opt
 Verbose("verbose", cl::desc("If set, shows the list of processed files"),
 cl::cat(ClangFormatCategory));
 
+// Use --dry-run to match other LLVM tools when you mean do it but don't
+// actually do it
+static cl::opt
+DryRun("dry-run",
+   cl::desc("If set, do not actually make the formatting changes"),
+   cl::cat(ClangFormatCategory));
+
+// Use -n as a common command as an alias for --dry-run. (git and make use -n)
+static cl::alias DryRunShort("n", cl::desc("Alias for --dry-run"),
+ cl::cat(ClangFormatCategory), 
cl::aliasopt(DryRun),
+ cl::NotHidden);
+
+// Emulate being able to turn on/off the warning.
+static cl::opt
+WarnFormat("Wclang-format-violations",
+   cl::desc("Warnings about individual formatting changes needed. "
+"Used only with --dry-run or -n"),
+   cl::init(true), cl::cat(ClangFormatCategory), cl::Hidden);
+
+static cl::opt
+NoWarnFormat("Wno-clang-format-violations",
+ cl::desc("Do not warn about individual formatting changes "
+  "needed. Used only with --dry-run or -n"),
+ cl::init(false), cl::cat(ClangFormatCategory), cl::Hidden);
+
+static cl::opt ErrorLimit(
+"ferror-limit",
+cl::desc("Set the maximum number of clang-format errors to emit before "
+ "stopping (0 = no limit). Used only with --dry-run or -n"),
+cl::init(0), cl::cat(ClangFormatCategory));
+
+static cl::opt
+WarningsAsErrors("Werror",
+ cl::desc("If set, changes formatting warnings to errors"),
+ cl::cat(ClangFormatCategory));
+
+static cl::opt
+ShowColors("fcolor-diagnostics",
+   cl::desc("If set, and on a color-capable terminal controls "
+"whether or not to print diagnostics in color"),
+   cl::init(true), cl::cat(ClangFormatCategory), cl::Hidden);
+
+static cl::opt
+NoShowColors("fno-color-diagnostics",
+ cl::desc("If set, and on a color-capable terminal controls "
+  "whether or not to print diagnostics in color"),
+ cl::init(false), cl::cat(

Re: [PATCH] D12492: [Clang-Format] Add AlwaysBreakBeforeElse and AlwaysBreakBeforeCatch Style to avoid cuddled else/catch

2015-09-14 Thread Paul Hoad via cfe-commits
MyDeveloperDay updated this revision to Diff 34741.
MyDeveloperDay added a comment.

Handle subsequent catch statements


http://reviews.llvm.org/D12492

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -9131,6 +9131,50 @@
WebKitBraceStyle);
 }
 
+TEST_F(FormatTest, AlwaysBreakBeforeElse) {
+  FormatStyle BeforeElse = getLLVMStyle();
+  BeforeElse.AlwaysBreakBeforeElse = true;
+  verifyFormat("void foo() {\n"
+   "  if (a) {\n"
+   "a();\n"
+   "  }\n"
+   "  else {\n"
+   "b();\n"
+   "  }\n"
+   "}\n",
+   BeforeElse);
+
+  verifyFormat("void foo() {\n"
+   "  if (a) {\n"
+   "a();\n"
+   "  }\n"
+   "  else if (b) {\n"
+   "b();\n"
+   "  }\n"
+   "  else {\n"
+   "b();\n"
+   "  }\n"
+   "}\n",
+   BeforeElse);
+}
+
+TEST_F(FormatTest, AlwaysBreakBeforeCatch) {
+  FormatStyle BeforeCatch = getLLVMStyle();
+  BeforeCatch.AlwaysBreakBeforeCatch = true;
+  verifyFormat("void foo() {\n"
+   "  try {\n"
+   "a();\n"
+   "  }\n"
+   "  catch (exception &) {\n"
+   "b();\n"
+   "  }\n"
+   "  catch (exception &) {\n"
+   "b();\n"
+   "  }\n"
+   "}\n",
+   BeforeCatch);
+}
+
 TEST_F(FormatTest, CatchExceptionReferenceBinding) {
   verifyFormat("void f() {\n"
"  try {\n"
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1272,8 +1272,11 @@
 --Line->Level;
   }
   if (FormatTok->Tok.is(tok::kw_else)) {
-if (Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup)
+if (Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup ||
+Style.AlwaysBreakBeforeElse) {
   addUnwrappedLine();
+}
+
 nextToken();
 if (FormatTok->Tok.is(tok::l_brace)) {
   CompoundStatementIndenter Indenter(this, Style, Line->Level);
@@ -1316,7 +1319,8 @@
 parseBlock(/*MustBeDeclaration=*/false);
 if (Style.BreakBeforeBraces == FormatStyle::BS_Allman ||
 Style.BreakBeforeBraces == FormatStyle::BS_GNU ||
-Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup) {
+Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup ||
+Style.AlwaysBreakBeforeCatch) {
   addUnwrappedLine();
 } else {
   NeedsUnwrappedLine = true;
@@ -1356,7 +1360,8 @@
 parseBlock(/*MustBeDeclaration=*/false);
 if (Style.BreakBeforeBraces == FormatStyle::BS_Allman ||
 Style.BreakBeforeBraces == FormatStyle::BS_GNU ||
-Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup) {
+Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup ||
+Style.AlwaysBreakBeforeCatch) {
   addUnwrappedLine();
 } else {
   NeedsUnwrappedLine = true;
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -217,6 +217,8 @@
Style.AlwaysBreakAfterDefinitionReturnType);
 IO.mapOptional("AlwaysBreakBeforeMultilineStrings",
Style.AlwaysBreakBeforeMultilineStrings);
+IO.mapOptional("AlwaysBreakBeforeElse", Style.AlwaysBreakBeforeElse);
+IO.mapOptional("AlwaysBreakBeforeCatch", Style.AlwaysBreakBeforeCatch);
 IO.mapOptional("AlwaysBreakTemplateDeclarations",
Style.AlwaysBreakTemplateDeclarations);
 IO.mapOptional("BinPackArguments", Style.BinPackArguments);
@@ -357,6 +359,8 @@
   LLVMStyle.AllowShortLoopsOnASingleLine = false;
   LLVMStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
   LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
+  LLVMStyle.AlwaysBreakBeforeElse = false;
+  LLVMStyle.AlwaysBreakBeforeCatch = false;
   LLVMStyle.AlwaysBreakTemplateDeclarations = false;
   LLVMStyle.BinPackParameters = true;
   LLVMStyle.BinPackArguments = true;
@@ -420,6 +424,8 @@
   GoogleStyle.AllowShortIfStatementsOnASingleLine = true;
   GoogleStyle.AllowShortLoopsOnASingleLine = true;
   GoogleStyle.AlwaysBreakBeforeMultilineStrings = true;
+  GoogleStyle.AlwaysBreakBeforeElse = false;
+  GoogleStyle.AlwaysBreakBeforeCatch = false;
   GoogleStyle.AlwaysBreakTemplateDeclarations = true;
   GoogleStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
   GoogleStyle.DerivePointerAlignment = true;
Index: include/clang/Format/Format.h

Re: [PATCH] D12921: clang-format: Support 'template<>' (no space).

2015-09-17 Thread Paul Hoad via cfe-commits
MyDeveloperDay added a subscriber: MyDeveloperDay.
MyDeveloperDay added a comment.

This looks like a good small change.

What is interesting to me is that even the twiki page about template is 
inconsistent in its style (https://en.wikipedia.org/wiki/Template_(C%2B%2B)), 
so its not like there is "one style to rule them all"  (some have spaces, some 
do not)

@djasper, I don't understand here what we mean by "cost" in your review comment 
 (performance, maintainability?), the change has unit tests to keep it honest 
and its just an additional expression on an 'if', is there something else we 
should be concerned about when submitting patches? (long term maintainability?)

It does sound a little to me like we might be want to reject it because we 
don't like this style and don't want to proliferate its continued use, and 
can't understand why anyone would do it that way.  Unfortunately that is not 
very realistic for those of us who want to introduce clang-format into a code 
base that predates clang, google and for some of us even the internet! which 
might have it own style guide which doesn't quite match clang (not quite)

In my view this finite control over every aspect of a style is what 
clang-format needs, we need clang-format to allow the individuals who maintain 
large code bases to be able to fine tune the style to meet our companies own 
documented style, then we can introduce it to automate that style. But the 
concept that we might be able to alter that style guide of our company and 
inflict a tidal wave of changes onto previously conforming code is 
unfortunately not possible.

I know this may not match llvm,clangs requirements but they are possibly the 
requirements to ensure clang-format becomes completely ubiquitous in the 
industry.

This review like my own review for similar finite control over else and catch 
(http://reviews.llvm.org/D12492) is obviously not the way that clang-format 
wants to go, we want to contribute but can't do it if our patches aren't 
included, do you have a recommendation?

Could I ask you to reconsider this review, I'm willing to help.


http://reviews.llvm.org/D12921



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12921: clang-format: Support 'template<>' (no space).

2015-09-17 Thread Paul Hoad via cfe-commits
MyDeveloperDay added a comment.

Oh and we might want to run clang-format by the guys at http://cppreference.com 
seems they don't like the space either!   just saying


http://reviews.llvm.org/D12921



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12492: [Clang-Format] Add AlwaysBreakBeforeElse and AlwaysBreakBeforeCatch Style to avoid cuddled else/catch

2015-09-17 Thread Paul Hoad via cfe-commits
MyDeveloperDay updated this revision to Diff 34971.
MyDeveloperDay added a comment.

full file diff


http://reviews.llvm.org/D12492

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  lib/Format/UnwrappedLineParser.cpp
  tools/CMakeLists.txt
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -9131,6 +9131,50 @@
WebKitBraceStyle);
 }
 
+TEST_F(FormatTest, AlwaysBreakBeforeElse) {
+  FormatStyle BeforeElse = getLLVMStyle();
+  BeforeElse.AlwaysBreakBeforeElse = true;
+  verifyFormat("void foo() {\n"
+   "  if (a) {\n"
+   "a();\n"
+   "  }\n"
+   "  else {\n"
+   "b();\n"
+   "  }\n"
+   "}\n",
+   BeforeElse);
+
+  verifyFormat("void foo() {\n"
+   "  if (a) {\n"
+   "a();\n"
+   "  }\n"
+   "  else if (b) {\n"
+   "b();\n"
+   "  }\n"
+   "  else {\n"
+   "b();\n"
+   "  }\n"
+   "}\n",
+   BeforeElse);
+}
+
+TEST_F(FormatTest, AlwaysBreakBeforeCatch) {
+  FormatStyle BeforeCatch = getLLVMStyle();
+  BeforeCatch.AlwaysBreakBeforeCatch = true;
+  verifyFormat("void foo() {\n"
+   "  try {\n"
+   "a();\n"
+   "  }\n"
+   "  catch (exception &) {\n"
+   "b();\n"
+   "  }\n"
+   "  catch (exception &) {\n"
+   "b();\n"
+   "  }\n"
+   "}\n",
+   BeforeCatch);
+}
+
 TEST_F(FormatTest, CatchExceptionReferenceBinding) {
   verifyFormat("void f() {\n"
"  try {\n"
Index: tools/CMakeLists.txt
===
--- tools/CMakeLists.txt
+++ tools/CMakeLists.txt
@@ -21,4 +21,5 @@
 # on top of the Clang tooling platform. We keep them in a separate repository
 # to keep the primary Clang repository small and focused.
 # It also may be included by LLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR.
-add_llvm_external_project(clang-tools-extra extra)
+#add_llvm_external_project(clang-tools-extra extra)
+add_subdirectory(extra)
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1272,8 +1272,11 @@
 --Line->Level;
   }
   if (FormatTok->Tok.is(tok::kw_else)) {
-if (Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup)
+if (Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup ||
+Style.AlwaysBreakBeforeElse) {
   addUnwrappedLine();
+}
+
 nextToken();
 if (FormatTok->Tok.is(tok::l_brace)) {
   CompoundStatementIndenter Indenter(this, Style, Line->Level);
@@ -1316,7 +1319,8 @@
 parseBlock(/*MustBeDeclaration=*/false);
 if (Style.BreakBeforeBraces == FormatStyle::BS_Allman ||
 Style.BreakBeforeBraces == FormatStyle::BS_GNU ||
-Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup) {
+Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup ||
+Style.AlwaysBreakBeforeCatch) {
   addUnwrappedLine();
 } else {
   NeedsUnwrappedLine = true;
@@ -1356,7 +1360,8 @@
 parseBlock(/*MustBeDeclaration=*/false);
 if (Style.BreakBeforeBraces == FormatStyle::BS_Allman ||
 Style.BreakBeforeBraces == FormatStyle::BS_GNU ||
-Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup) {
+Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup ||
+Style.AlwaysBreakBeforeCatch) {
   addUnwrappedLine();
 } else {
   NeedsUnwrappedLine = true;
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -217,6 +217,8 @@
Style.AlwaysBreakAfterDefinitionReturnType);
 IO.mapOptional("AlwaysBreakBeforeMultilineStrings",
Style.AlwaysBreakBeforeMultilineStrings);
+IO.mapOptional("AlwaysBreakBeforeElse", Style.AlwaysBreakBeforeElse);
+IO.mapOptional("AlwaysBreakBeforeCatch", Style.AlwaysBreakBeforeCatch);
 IO.mapOptional("AlwaysBreakTemplateDeclarations",
Style.AlwaysBreakTemplateDeclarations);
 IO.mapOptional("BinPackArguments", Style.BinPackArguments);
@@ -357,6 +359,8 @@
   LLVMStyle.AllowShortLoopsOnASingleLine = false;
   LLVMStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
   LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
+  LLVMStyle.AlwaysBreakBeforeElse = false;
+  LLVMStyle.AlwaysBreakBeforeCatch = false;
   LLVMStyle.AlwaysBreakTemplateDeclarations = false;
   LLVMStyle.BinPackParameters = true;
   LLVMStyle.BinP

Re: [PATCH] D12492: [Clang-Format] Add AlwaysBreakBeforeElse and AlwaysBreakBeforeCatch Style to avoid cuddled else/catch

2015-09-17 Thread Paul Hoad via cfe-commits
MyDeveloperDay added inline comments.


Comment at: docs/ClangFormatStyleOptions.rst:247
@@ -246,1 +246,3 @@
 
+**AlwaysBreakBeforeElse** (``bool``)
+  If ``true``, always break before ``else``.

djasper wrote:
> Hm, I think these should be grouped in some way and interact with 
> BreakBeforeBraces.
> 
> I theory, I'd like to have a lot of different flags and make 
> BreakBeforeBraces select specific presents for them. However, maybe we can 
> put all the brace breaking options together in some nice way (don't have a 
> very good idea yet).
> 
> Not saying that you need to do all of this, but pulling these two options out 
> from the other BreakBeforeBraces options seems a little undesirable. They 
> essentially also just define what we do around braces.
Well I agree, ideally the BreakBeforeBraces styles should be implemented by 
setting the finite control on each element

Then code like this

if (Style.BreakBeforeBraces == FormatStyle::BS_Allman ||
Style.BreakBeforeBraces == FormatStyle::BS_GNU ||
Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup ||
Style.AlwaysBreakBeforeCatch) {
 ...
}

could become

if (Style.AlwaysBreakBeforeCatch) {
...
}

This would simply require some code in the initializer that says

if (Style.BreakBeforeBraces == FormatStyle::BS_Allman ||
Style.BreakBeforeBraces == FormatStyle::BS_GNU ||
Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup)
{
Style.AlwaysBreakBeforeCatch=true;
}

if (Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup)
{
Style.AlwaysBreakBeforeElse=true;
}

This would allow those of us not using one of the 5 chosen styles to build our 
teams style guide via the individual capabilities

Removing all the BS_Stroustrup/Allman etc.. from the UnwrappedLineParser will 
greatly improve its readability


http://reviews.llvm.org/D12492



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12921: clang-format: Support 'template<>' (no space).

2015-09-17 Thread Paul Hoad via cfe-commits
MyDeveloperDay added a comment.

> The point here that it this space is utterly irrelevant


So I totally take the point but if it doesn't matter then why does clang-format 
automatically add one to my "template<>" why not simply leave it alone?

> We never intended clang-format to provide control over every aspect of 
> formatting


I know that when new people come along on an open source project they want to 
change the world, for that I apologize, we weren't here for the previous 
decisions, but maybe clang-format is turning into something that is different 
from what was originally intended, maybe it CAN become the code formatting tool 
for those teams out there that are not quite/can't  do it the google way.

> We'd rather have it support a limited set of (important) style options really 
> well


And that I understand, but for those of us whose style does not exactly meet 
one of the 5 what can WE do other than submit patches to give finer control.

I don't want to argue but I would like you (who seems to be the gatekeeper for 
clang-format) to consider.


http://reviews.llvm.org/D12921



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12492: [Clang-Format] Add AlwaysBreakBeforeElse and AlwaysBreakBeforeCatch Style to avoid cuddled else/catch

2015-09-22 Thread Paul Hoad via cfe-commits
MyDeveloperDay added a comment.

@djasper I'm more than happy with that, just ping me if you need me the rework 
the change afterwards to fit


http://reviews.llvm.org/D12492



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12407: [clang-format-vs] Add an option to reformat source code when file is saved to disk

2015-09-23 Thread Paul Hoad via cfe-commits
MyDeveloperDay added a comment.

I tried downloaded the diff and tried this, I met a couple of issues with 
applying the patch due to line endings in .cs file and csproj (but that could 
be my fault) - (I was using 2013 to build clang library and clang format)

I also had to up the version because I had previously installed a 3.8.0 version 
of the extension from the trunk, but I suspect that an uninstall/reinstall 
would have solved that.

my csproj needed me to re-add the ComponentModel reference (which I think 
requires the VS 2010 SDK which I'm not sure was required before)

So my line in the CS proj ended up being a little different  (Version Public 
Key etc..)



But it seem to work well in the version I tried (namely VS2013 Premium and  
VS2015 Enterprise)

but VS2010 did not work for me, it installed ok, but  initially  it was 
disabled by default, (not sure why), going to the extension manager and 
enabling and restarting devenv didn't make it work.

Very nice feature for forcing the change across a file.


http://reviews.llvm.org/D12407



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12407: [clang-format-vs] Add an option to reformat source code when file is saved to disk

2015-09-23 Thread Paul Hoad via cfe-commits
MyDeveloperDay added a comment.

Actually the 2010 failure may be my fault, I only have Visual C# installed for 
VS2010 and not the C++ compilers, as such it doesn't seem to understand C/C++ 
as the content type

if (!textBuffer.ContentType.IsOfType("C/C++"))

is failing because the ContentType is "plaintext", my guess is unless you 
install the C++ parts of VS it doesn't add the "File Type" or C/C++ and hence 
it can't detect that a .h file is anything other than plaintext, let me recheck 
VS2010 support after adding in the C++ support


http://reviews.llvm.org/D12407



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12407: [clang-format-vs] Add an option to reformat source code when file is saved to disk

2015-09-24 Thread Paul Hoad via cfe-commits
MyDeveloperDay added a comment.

Having installed the VS2010 C++ compilers the format on save does work BUT... 
you have to disable and enable the setting in tools->options->LLVM/Clang first, 
its as if the setting is NOT read on startup


http://reviews.llvm.org/D12407



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12407: [clang-format-vs] Add an option to reformat source code when file is saved to disk

2015-09-24 Thread Paul Hoad via cfe-commits
MyDeveloperDay added a comment.

I went back and retested VS2010, VS2013 and VS2015. so in all cases I

1. start Visual studio
2. open a .h file (with incorrect style) - (via the recent file menu)
3. make a minor edit of whitespace
4. hit save file

In allcases it does NOT reformat the file

Now do

Tools->Options->LLVM/CLang
The setting is currently True for reformat on save
Turn it to False press OK
Tools->Options->LLVM/CLang
The setting is now False
Turn it to True press ok

now return to the file and press save

The file will now be reformatted.

After this point any subsequent edits and save will reformat the page, perhaps 
others can try.


http://reviews.llvm.org/D12407



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12407: [clang-format-vs] Add an option to reformat source code when file is saved to disk

2015-09-26 Thread Paul Hoad via cfe-commits
MyDeveloperDay added a comment.

After a little digging, the problem is based on the fact that the extension 
doesn't load until we use it, so the nBeforeSave won't fire, so after doing 
Ctrl-R,Ctrl-F once it will work

This exact same problem is mentioned here

http://schmalls.com/2015/01/19/adventures-in-visual-studio-extension-development-part-2

Quote:

So, we implement all of the event functionality and try out the extension. 
**The first time we save a file, no arranging happens. If we run the arrange 
command from the menu item, it runs fine and then subsequent file saves also 
get arranged. **That seems weird. It turns out that Visual Studio only loads 
the extensions as needed. We have to add another one of our provide attributes, 
ProvideAutoLoadAttribute, to the VSPackage class to get the extension to load 
sooner.
[ProvideAutoLoad("ADFC4E64-0397-11D1-9F4E-00A0C911004F")]
I found the GUID to pass to this from a blog post I found to get the extension 
to load as soon as possible. After further research on MSDN, it turns out to be 
the same as the UIContextGuids80.NoSolution field. The remarks seem to indicate 
that it would only become active when a solution is closed or Visual Studio is 
started with the "Show Empty Environment" option set in startup; however, it 
looks like it happens when Visual Studio is started no matter the value of the 
startup setting. There are other useful contexts in the UIContextGuids80 Class. 
The attribute can be rewritten as shown.


http://reviews.llvm.org/D12407



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12492: [Clang-Format] Add AlwaysBreakBeforeElse and AlwaysBreakBeforeCatch Style to avoid cuddled else/catch

2015-09-29 Thread Paul Hoad via cfe-commits
MyDeveloperDay added a comment.

I don't have permission to commit

This looks good though.


http://reviews.llvm.org/D12492



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D12492: [Clang-Format] Add AlwaysBreakBeforeElse Style to avoid cuddled else

2015-08-31 Thread Paul Hoad via cfe-commits
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: nikola, djasper, poiru, klimek.
MyDeveloperDay added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

Implementation of Jarkko Hietaniemi original AlwaysBreakBeforeElse to avoid 
cuddled braces on an "else" statement.

WebKit Style + Linux BreakBeforeBraces style gives cuddled else brackets, this 
patch adds an AlwaysBreakBeforeElse style to allow required brace style such 
that the else is placed on a newline after the closing brace of the if

Patch by: Jarkko Hietaniemi

http://reviews.llvm.org/D12492

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -9131,6 +9131,33 @@
WebKitBraceStyle);
 }
 
+TEST_F(FormatTest, AlwaysBreakBeforeElse) {
+FormatStyle BeforeElse = getLLVMStyle();
+BeforeElse.AlwaysBreakBeforeElse = true;
+verifyFormat("void foo() {\n"
+"  if (a) {\n"
+"a();\n"
+"  }\n"
+"  else {\n"
+"b();\n"
+"  }\n"
+"}\n",
+BeforeElse);
+
+verifyFormat("void foo() {\n"
+"  if (a) {\n"
+"a();\n"
+"  }\n"
+"  else if (b) {\n"
+"b();\n"
+"  }\n"
+"  else {\n"
+"b();\n"
+"  }\n"
+"}\n",
+BeforeElse);
+}
+
 TEST_F(FormatTest, CatchExceptionReferenceBinding) {
   verifyFormat("void f() {\n"
"  try {\n"
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1272,8 +1272,11 @@
 --Line->Level;
   }
   if (FormatTok->Tok.is(tok::kw_else)) {
-if (Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup)
+if (Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup ||
+Style.AlwaysBreakBeforeElse) {
   addUnwrappedLine();
+}
+
 nextToken();
 if (FormatTok->Tok.is(tok::l_brace)) {
   CompoundStatementIndenter Indenter(this, Style, Line->Level);
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -217,6 +217,8 @@
Style.AlwaysBreakAfterDefinitionReturnType);
 IO.mapOptional("AlwaysBreakBeforeMultilineStrings",
Style.AlwaysBreakBeforeMultilineStrings);
+IO.mapOptional("AlwaysBreakBeforeElse",
+   Style.AlwaysBreakBeforeElse);
 IO.mapOptional("AlwaysBreakTemplateDeclarations",
Style.AlwaysBreakTemplateDeclarations);
 IO.mapOptional("BinPackArguments", Style.BinPackArguments);
@@ -357,6 +359,7 @@
   LLVMStyle.AllowShortLoopsOnASingleLine = false;
   LLVMStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
   LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
+  LLVMStyle.AlwaysBreakBeforeElse = false;
   LLVMStyle.AlwaysBreakTemplateDeclarations = false;
   LLVMStyle.BinPackParameters = true;
   LLVMStyle.BinPackArguments = true;
@@ -420,6 +423,7 @@
   GoogleStyle.AllowShortIfStatementsOnASingleLine = true;
   GoogleStyle.AllowShortLoopsOnASingleLine = true;
   GoogleStyle.AlwaysBreakBeforeMultilineStrings = true;
+  GoogleStyle.AlwaysBreakBeforeElse = false;
   GoogleStyle.AlwaysBreakTemplateDeclarations = true;
   GoogleStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
   GoogleStyle.DerivePointerAlignment = true;
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -138,6 +138,9 @@
   /// template declaration.
   bool AlwaysBreakTemplateDeclarations;
 
+  /// \brief If \c true, always break before 'else'.
+  bool AlwaysBreakBeforeElse;
+
   /// \brief If \c false, a function call's arguments will either be all on the
   /// same line or will have one line each.
   bool BinPackArguments;
@@ -465,6 +468,8 @@
R.AlwaysBreakBeforeMultilineStrings &&
AlwaysBreakTemplateDeclarations ==
R.AlwaysBreakTemplateDeclarations &&
+   AlwaysBreakBeforeElse ==
+   R.AlwaysBreakBeforeElse &&
BinPackArguments == R.BinPackArguments &&
BinPackParameters == R.BinPackParameters &&
BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators &&
Index: docs/ClangFormatStyleOptions.rst
===
--- docs/ClangFormatStyleOptions.rst
+++ docs/ClangFormatStyleOptions.rst
@@ -244,6 +244,9 @@
   If ``true``, always break after the ``template<...>`` of a
   template declaration.
 
+**AlwaysBrea

Re: [PATCH] D12407: [clang-format-vs] Add an option to reformat source code when file is saved to disk

2015-08-31 Thread Paul Hoad via cfe-commits
MyDeveloperDay added a subscriber: MyDeveloperDay.
MyDeveloperDay added a comment.

This is definitely a nice to have, it would be nice in the future to have an 
option that only reformatted the changed lines only, nice idea though


http://reviews.llvm.org/D12407



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12492: [Clang-Format] Add AlwaysBreakBeforeElse and AlwaysBreakBeforeCatch Style to avoid cuddled else/catch

2015-09-04 Thread Paul Hoad via cfe-commits
MyDeveloperDay retitled this revision from "[Clang-Format] Add 
AlwaysBreakBeforeElse Style to avoid cuddled else" to "[Clang-Format] Add 
AlwaysBreakBeforeElse and AlwaysBreakBeforeCatch Style to avoid cuddled 
else/catch".
MyDeveloperDay updated the summary for this revision.
MyDeveloperDay updated this revision to Diff 34023.
MyDeveloperDay added a comment.

As this patch has not been reviewed yet, and in using the tool in my own 
environment I noticed the same is true for catch statments, I want to see 
try {
}
catch (exception &e) {
}

not

try {
} catch (exception &e) {
}


http://reviews.llvm.org/D12492

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -9131,6 +9131,47 @@
WebKitBraceStyle);
 }
 
+TEST_F(FormatTest, AlwaysBreakBeforeElse) {
+  FormatStyle BeforeElse = getLLVMStyle();
+  BeforeElse.AlwaysBreakBeforeElse = true;
+  verifyFormat("void foo() {\n"
+   "  if (a) {\n"
+   "a();\n"
+   "  }\n"
+   "  else {\n"
+   "b();\n"
+   "  }\n"
+   "}\n",
+   BeforeElse);
+
+  verifyFormat("void foo() {\n"
+   "  if (a) {\n"
+   "a();\n"
+   "  }\n"
+   "  else if (b) {\n"
+   "b();\n"
+   "  }\n"
+   "  else {\n"
+   "b();\n"
+   "  }\n"
+   "}\n",
+   BeforeElse);
+}
+
+TEST_F(FormatTest, AlwaysBreakBeforeCatch) {
+  FormatStyle BeforeCatch = getLLVMStyle();
+  BeforeCatch.AlwaysBreakBeforeCatch = true;
+  verifyFormat("void foo() {\n"
+   "  try {\n"
+   "a();\n"
+   "  }\n"
+   "  catch (exception &) {\n"
+   "b();\n"
+   "  }\n"
+   "}\n",
+   BeforeCatch);
+}
+
 TEST_F(FormatTest, CatchExceptionReferenceBinding) {
   verifyFormat("void f() {\n"
"  try {\n"
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1272,8 +1272,11 @@
 --Line->Level;
   }
   if (FormatTok->Tok.is(tok::kw_else)) {
-if (Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup)
+if (Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup ||
+Style.AlwaysBreakBeforeElse) {
   addUnwrappedLine();
+}
+
 nextToken();
 if (FormatTok->Tok.is(tok::l_brace)) {
   CompoundStatementIndenter Indenter(this, Style, Line->Level);
@@ -1316,7 +1319,8 @@
 parseBlock(/*MustBeDeclaration=*/false);
 if (Style.BreakBeforeBraces == FormatStyle::BS_Allman ||
 Style.BreakBeforeBraces == FormatStyle::BS_GNU ||
-Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup) {
+Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup ||
+Style.AlwaysBreakBeforeCatch) {
   addUnwrappedLine();
 } else {
   NeedsUnwrappedLine = true;
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -217,6 +217,8 @@
Style.AlwaysBreakAfterDefinitionReturnType);
 IO.mapOptional("AlwaysBreakBeforeMultilineStrings",
Style.AlwaysBreakBeforeMultilineStrings);
+IO.mapOptional("AlwaysBreakBeforeElse", Style.AlwaysBreakBeforeElse);
+IO.mapOptional("AlwaysBreakBeforeCatch", Style.AlwaysBreakBeforeCatch);
 IO.mapOptional("AlwaysBreakTemplateDeclarations",
Style.AlwaysBreakTemplateDeclarations);
 IO.mapOptional("BinPackArguments", Style.BinPackArguments);
@@ -357,6 +359,8 @@
   LLVMStyle.AllowShortLoopsOnASingleLine = false;
   LLVMStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
   LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
+  LLVMStyle.AlwaysBreakBeforeElse = false;
+  LLVMStyle.AlwaysBreakBeforeCatch = false;
   LLVMStyle.AlwaysBreakTemplateDeclarations = false;
   LLVMStyle.BinPackParameters = true;
   LLVMStyle.BinPackArguments = true;
@@ -420,6 +424,8 @@
   GoogleStyle.AllowShortIfStatementsOnASingleLine = true;
   GoogleStyle.AllowShortLoopsOnASingleLine = true;
   GoogleStyle.AlwaysBreakBeforeMultilineStrings = true;
+  GoogleStyle.AlwaysBreakBeforeElse = false;
+  GoogleStyle.AlwaysBreakBeforeCatch = false;
   GoogleStyle.AlwaysBreakTemplateDeclarations = true;
   GoogleStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
   GoogleStyle.DerivePointerAlignment = true;
Index: include/clang/Format/Format.h
===

[clang] [clang-format][NFC] Annotate function decl l_paren (PR #97938)

2024-07-08 Thread Paul Hoad via cfe-commits

https://github.com/phoad107185 approved this pull request.


https://github.com/llvm/llvm-project/pull/97938
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] extend clang-format directive with options to prevent formatting for one line (PR #118566)

2024-12-17 Thread Paul Hoad via cfe-commits

phoad107185 wrote:

> > I struggle with changes that encourage people to not be fully 
> > clang-formatted, I would prefer to ask why we need this feature, can we 
> > have some examples of where this would be used?
> 
> This makes it so only one line isn't formatted instead of the current 
> solution which is 2 lines unformatted. Additionally, if you start writing 
> code in between the unformatted region you inherit the unformatted scope. 
> Being able to disable the formatter for only a single line means the 
> formatter will be disabled for the shortest amount of code possible.

While I understand the reason I would ask again, what exactly are you disabling 
on a single line and why? Does the clang-format team really want to maintain 
more reasons to "not" format code? I would rather put the effort into 
understanding why you are having to use the // clang-format off in the first 
place

I work on a project (in my day job) with millions of lines of code, EVERY file 
is 100% clang-formatted, without any // clang-format off statements. When I hit 
a problem I report it against clang-format or even submit a fix. 

So again to reiterate my question why do we need this feature? what is the 
reason and why doesn't the current capabilities support what you need.


https://github.com/llvm/llvm-project/pull/118566
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits