[clang] 51dbda5 - [clang-format][docfix] Update predefined styles in docs

2020-05-20 Thread Jake Merdich via cfe-commits

Author: Jake Merdich
Date: 2020-05-20T20:03:53-04:00
New Revision: 51dbda54384827533dcfcb712f918cee7acc3185

URL: 
https://github.com/llvm/llvm-project/commit/51dbda54384827533dcfcb712f918cee7acc3185
DIFF: 
https://github.com/llvm/llvm-project/commit/51dbda54384827533dcfcb712f918cee7acc3185.diff

LOG: [clang-format][docfix] Update predefined styles in docs

Summary:
The predefined styles that clang-format supports are listed in two
places, and neither is up-to-date. GNU style isn't mentioned at all!

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/docs/LibFormat.rst

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 2afa17973454..496e4c651921 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -151,6 +151,9 @@ the configuration (without a prefix: ``Auto``).
   * ``Microsoft``
 A style complying with `Microsoft's style guide
 
`_
+  * ``GNU``
+A style complying with the `GNU coding standards
+`_
 
 .. START_FORMAT_STYLE_OPTIONS
 

diff  --git a/clang/docs/LibFormat.rst b/clang/docs/LibFormat.rst
index 889fbbac8c7a..4ea84e658d1b 100644
--- a/clang/docs/LibFormat.rst
+++ b/clang/docs/LibFormat.rst
@@ -40,7 +40,7 @@ Style Options
 
 The style options describe specific formatting options that can be used in
 order to make `ClangFormat` comply with 
diff erent style guides. Currently,
-two style guides are hard-coded:
+several style guides are hard-coded:
 
 .. code-block:: c++
 
@@ -52,6 +52,26 @@ two style guides are hard-coded:
   /// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.
   FormatStyle getGoogleStyle();
 
+  /// Returns a format style complying with Chromium's style guide:
+  /// 
https://chromium.googlesource.com/chromium/src/+/master/styleguide/styleguide.md
+  FormatStyle getChromiumStyle();
+
+  /// Returns a format style complying with the GNU coding standards:
+  /// https://www.gnu.org/prep/standards/standards.html
+  FormatStyle getGNUStyle();
+
+  /// Returns a format style complying with Mozilla's style guide
+  /// 
https://firefox-source-docs.mozilla.org/code-quality/coding-style/index.html
+  FormatStyle getMozillaStyle();
+
+  /// Returns a format style complying with Webkit's style guide:
+  /// https://webkit.org/code-style-guidelines/
+  FormatStyle getWebkitStyle();
+
+  /// Returns a format style complying with Microsoft's style guide:
+  /// 
https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference
+  FormatStyle getMicrosoftStyle();
+
 These options are also exposed in the :doc:`standalone tools `
 through the `-style` option.
 



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


[clang] 52b03aa - [clang-format][PR46043] Parse git config w/ implicit values

2020-05-25 Thread Jake Merdich via cfe-commits

Author: Jake Merdich
Date: 2020-05-24T20:32:54-04:00
New Revision: 52b03aaa22f650bbd36ceb3bdae4699dae71b2b8

URL: 
https://github.com/llvm/llvm-project/commit/52b03aaa22f650bbd36ceb3bdae4699dae71b2b8
DIFF: 
https://github.com/llvm/llvm-project/commit/52b03aaa22f650bbd36ceb3bdae4699dae71b2b8.diff

LOG: [clang-format][PR46043] Parse git config w/ implicit values

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

Git's config is generally of the format 'key=val', but a setting
'key=true' can be written as just 'key'.  The git-clang-format script
expects a value and crashes in this case; this change handles implicit
'true' values in the script.

Reviewers: MyDeveloperDay, krasimir, sammccall

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/tools/clang-format/git-clang-format

Removed: 




diff  --git a/clang/tools/clang-format/git-clang-format 
b/clang/tools/clang-format/git-clang-format
index abbe3b7b97c6..f3cd585e7f4a 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -192,7 +192,12 @@ def load_git_config(non_string_options=None):
   out = {}
   for entry in run('git', 'config', '--list', '--null').split('\0'):
 if entry:
-  name, value = entry.split('\n', 1)
+  if '\n' in entry:
+name, value = entry.split('\n', 1)
+  else:
+# A setting with no '=' ('\n' with --null) is implicitly 'true'
+name = entry
+value = 'true'
   if name in non_string_options:
 value = run('git', 'config', non_string_options[name], name)
   out[name] = value



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


[clang] 0c332a7 - [clang-format] Preserve whitespace in selected macros

2020-06-29 Thread Jake Merdich via cfe-commits

Author: Jake Merdich
Date: 2020-06-29T09:57:47-04:00
New Revision: 0c332a7784c649038bd237a60fa18b45a3dea90d

URL: 
https://github.com/llvm/llvm-project/commit/0c332a7784c649038bd237a60fa18b45a3dea90d
DIFF: 
https://github.com/llvm/llvm-project/commit/0c332a7784c649038bd237a60fa18b45a3dea90d.diff

LOG: [clang-format] Preserve whitespace in selected macros

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

When the c preprocessor stringizes tokens, the generated string literals
are affected by the whitespace. This means clang-format can affect
codegen silently, adding spaces and newlines to strings.  Practically
speaking, the vast majority of cases will be harmless, only affecting
single identifiers or debug macros.

In the interest of doing no harm in other cases though, this introduces
a blacklist option 'WhitespaceSensitiveMacros', which contains a list of
names of function-like macros whose contents should not be touched by
clang-format, period. Clang-format can't automatically detect these
without a real compile context, so users will have to specify it
explicitly (it still beats clang-format off'ing at every invocation).

Defaults include "STRINGIZE", "PP_STRINGIZE", and "BOOST_PP_STRINGIZE".

Subscribers: kristof.beyls, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/lib/Format/FormatToken.h
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 496e4c651921..e84676760c30 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2694,6 +2694,23 @@ the configuration (without a prefix: ``Auto``).
 Use tabs whenever we need to fill whitespace that spans at least from
 one tab stop to the next one.
 
+**WhitespaceSensitiveMacros** (``std::vector``)
+  A vector of macros which are whitespace-sensitive and should not be touched.
+
+  These are expected to be macros of the form:
+
+  .. code-block:: c++
+
+STRINGIZE(...)
+
+  In the .clang-format configuration file, this can be configured like:
+
+  .. code-block:: yaml
+
+WhitespaceSensitiveMacros: ['STRINGIZE', 'PP_STRINGIZE']
+
+  For example: BOOST_PP_STRINGIZE.
+
 
 
 .. END_FORMAT_STYLE_OPTIONS

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 96b73211d9ff..3549ec9eee0e 100755
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1425,6 +1425,17 @@ struct FormatStyle {
   /// For example: TESTSUITE
   std::vector NamespaceMacros;
 
+  /// A vector of macros which are whitespace-sensitive and shouldn't be
+  /// touched.
+  ///
+  /// These are expected to be macros of the form:
+  /// \code
+  ///   STRINGIZE(...)
+  /// \endcode
+  ///
+  /// For example: STRINGIZE
+  std::vector WhitespaceSensitiveMacros;
+
   tooling::IncludeStyle IncludeStyle;
 
   /// Indent case labels one level from the switch statement.

diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index d83410b1f7e1..0d277a6464af 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -599,6 +599,8 @@ template <> struct MappingTraits {
 IO.mapOptional("TypenameMacros", Style.TypenameMacros);
 IO.mapOptional("UseCRLF", Style.UseCRLF);
 IO.mapOptional("UseTab", Style.UseTab);
+IO.mapOptional("WhitespaceSensitiveMacros",
+   Style.WhitespaceSensitiveMacros);
   }
 };
 
@@ -933,6 +935,9 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.SortUsingDeclarations = true;
   LLVMStyle.StatementMacros.push_back("Q_UNUSED");
   LLVMStyle.StatementMacros.push_back("QT_REQUIRE_VERSION");
+  LLVMStyle.WhitespaceSensitiveMacros.push_back("STRINGIZE");
+  LLVMStyle.WhitespaceSensitiveMacros.push_back("PP_STRINGIZE");
+  LLVMStyle.WhitespaceSensitiveMacros.push_back("BOOST_PP_STRINGIZE");
 
   // Defaults that 
diff er when not C++.
   if (Language == FormatStyle::LK_TableGen) {

diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 2ad839a6a4f0..d4287f53fde3 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -102,6 +102,7 @@ namespace format {
   TYPE(TrailingUnaryOperator)  
\
   TYPE(TypenameMacro)  
\
   TYPE(UnaryOperator)  
\
+  TYPE(UntouchableMacroFunc)   
\
   TYPE(CSharpStringLiteral)
\