<p dir="ltr">Many of us compile(self hosting - were mostly interested in clang's behavior here) with -Werror to ensure we keep the build warning free. This also means we're pretty immediately impacted in the form of build breakage whenever someone makes the build warning-unclean.</p>

<div class="gmail_quote">On Oct 1, 2013 6:14 AM, "Vane, Edwin" <<a href="mailto:edwin.vane@intel.com">edwin.vane@intel.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">






<div lang="EN-US" link="blue" vlink="purple">
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Sorry about that. I didn’t even see the warning or the file static variable.<u></u><u></u></span></p>

<p class="MsoNormal"><a name="1417427ef1c1d6a1__MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></a></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri","sans-serif"">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri","sans-serif""> David Blaikie [mailto:<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>]
<br>
<b>Sent:</b> Monday, September 30, 2013 1:37 PM<br>
<b>To:</b> Vane, Edwin<br>
<b>Cc:</b> llvm cfe<br>
<b>Subject:</b> Re: r191666 - Moving style option formatting to libFormat<u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><u></u> <u></u></p>
<div>
<p class="MsoNormal">On Mon, Sep 30, 2013 at 6:31 AM, Edwin Vane <<a href="mailto:edwin.vane@intel.com" target="_blank">edwin.vane@intel.com</a>> wrote:<u></u><u></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<p class="MsoNormal">Author: revane<br>
Date: Mon Sep 30 08:31:48 2013<br>
New Revision: 191666<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=191666&view=rev" target="_blank">
http://llvm.org/viewvc/llvm-project?rev=191666&view=rev</a><br>
Log:<br>
Moving style option formatting to libFormat<br>
<br>
The help text for clang-format's -style option and the function that processes<br>
its value is moved to libFormat in this patch. The goal is to enable other<br>
tools that use libFormat and also have a -style option to behave consistently<br>
with clang-format.<br>
<br>
<br>
Modified:<br>
    cfe/trunk/include/clang/Format/Format.h<br>
    cfe/trunk/lib/Format/Format.cpp<br>
    cfe/trunk/tools/clang-format/ClangFormat.cpp<br>
<br>
Modified: cfe/trunk/include/clang/Format/Format.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=191666&r1=191665&r2=191666&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=191666&r1=191665&r2=191666&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Format/Format.h (original)<br>
+++ cfe/trunk/include/clang/Format/Format.h Mon Sep 30 08:31:48 2013<br>
@@ -347,6 +347,30 @@ tooling::Replacements reformat(const For<br>
 LangOptions getFormattingLangOpts(FormatStyle::LanguageStandard Standard =<br>
                                       FormatStyle::LS_Cpp11);<br>
<br>
+/// \brief Description to be used for help text for a llvm::cl option for<br>
+/// specifying format style. The description is closely related to the operation<br>
+/// of getStyle().<br>
+extern const char *StyleOptionHelpDescription;<br>
+<br>
+/// \brief Construct a FormatStyle based on \c StyleName.<br>
+///<br>
+/// \c StyleName can take several forms:<br>
+/// \li "{<key>: <value>, ...}" - Set specic style parameters.<br>
+/// \li "<style name>" - One of the style names supported by<br>
+/// getPredefinedStyle().<br>
+/// \li "file" - Load style configuration from a file called '.clang-format'<br>
+/// located in one of the parent directories of \c FileName or the current<br>
+/// directory if \c FileName is empty.<br>
+///<br>
+/// \param[in] StyleName Style name to interpret according to the description<br>
+/// above.<br>
+/// \param[in] FileName Path to start search for .clang-format if \c StyleName<br>
+/// == "file".<br>
+///<br>
+/// \returns FormatStyle as specified by \c StyleName. If no style could be<br>
+/// determined, the default is LLVM Style (see getLLVMStyle()).<br>
+FormatStyle getStyle(StringRef StyleName, StringRef FileName);<br>
+<br>
 } // end namespace format<br>
 } // end namespace clang<br>
<br>
<br>
Modified: cfe/trunk/lib/Format/Format.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=191666&r1=191665&r2=191666&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=191666&r1=191665&r2=191666&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Format/Format.cpp (original)<br>
+++ cfe/trunk/lib/Format/Format.cpp Mon Sep 30 08:31:48 2013<br>
@@ -27,6 +27,7 @@<br>
 #include "llvm/Support/Allocator.h"<br>
 #include "llvm/Support/Debug.h"<br>
 #include "llvm/Support/YAMLTraits.h"<br>
+#include "llvm/Support/Path.h"<br>
 #include <queue><br>
 #include <string><br>
<br>
@@ -1305,5 +1306,82 @@ LangOptions getFormattingLangOpts(Format<br>
   return LangOpts;<br>
 }<br>
<br>
+const char *StyleOptionHelpDescription =<br>
+    "Coding style, currently supports:\n"<br>
+    "  LLVM, Google, Chromium, Mozilla, WebKit.\n"<br>
+    "Use -style=file to load style configuration from\n"<br>
+    ".clang-format file located in one of the parent\n"<br>
+    "directories of the source file (or current\n"<br>
+    "directory for stdin).\n"<br>
+    "Use -style=\"{key: value, ...}\" to set specific\n"<br>
+    "parameters, e.g.:\n"<br>
+    "  -style=\"{BasedOnStyle: llvm, IndentWidth: 8}\"";<br>
+<br>
+FormatStyle getStyle(StringRef StyleName, StringRef FileName) {<br>
+  // Fallback style in case the rest of this function can't determine a style.<br>
+  StringRef FallbackStyle = "LLVM";<u></u><u></u></p>
</blockquote>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Introducing this variable caused the file-scoped static FallbackStyle to become unused. I removed that variable in r191682 to fix the Clang -Werror build. Please adjust as necessary if my fix wasn't appropriate.<br>

<br>
- David<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<p class="MsoNormal">+  FormatStyle Style;<br>
+  getPredefinedStyle(FallbackStyle, &Style);<br>
+<br>
+  if (StyleName.startswith("{")) {<br>
+    // Parse YAML/JSON style from the command line.<br>
+    if (llvm::error_code ec = parseConfiguration(StyleName, &Style)) {<br>
+      llvm::errs() << "Error parsing -style: " << ec.message()<br>
+                   << ", using " << FallbackStyle << " style\n";<br>
+    }<br>
+    return Style;<br>
+  }<br>
+<br>
+  if (!StyleName.equals_lower("file")) {<br>
+    if (!getPredefinedStyle(StyleName, &Style))<br>
+      llvm::errs() << "Invalid value for -style, using " << FallbackStyle<br>
+                   << " style\n";<br>
+    return Style;<br>
+  }<br>
+<br>
+  SmallString<128> Path(FileName);<br>
+  llvm::sys::fs::make_absolute(Path);<br>
+  for (StringRef Directory = Path;<br>
+       !Directory.empty();<br>
+       Directory = llvm::sys::path::parent_path(Directory)) {<br>
+    if (!llvm::sys::fs::is_directory(Directory))<br>
+      continue;<br>
+    SmallString<128> ConfigFile(Directory);<br>
+<br>
+    llvm::sys::path::append(ConfigFile, ".clang-format");<br>
+    DEBUG(llvm::dbgs() << "Trying " << ConfigFile << "...\n");<br>
+    bool IsFile = false;<br>
+    // Ignore errors from is_regular_file: we only need to know if we can read<br>
+    // the file or not.<br>
+    llvm::sys::fs::is_regular_file(Twine(ConfigFile), IsFile);<br>
+<br>
+    if (!IsFile) {<br>
+      // Try _clang-format too, since dotfiles are not commonly used on Windows.<br>
+      ConfigFile = Directory;<br>
+      llvm::sys::path::append(ConfigFile, "_clang-format");<br>
+      DEBUG(llvm::dbgs() << "Trying " << ConfigFile << "...\n");<br>
+      llvm::sys::fs::is_regular_file(Twine(ConfigFile), IsFile);<br>
+    }<br>
+<br>
+    if (IsFile) {<br>
+      OwningPtr<llvm::MemoryBuffer> Text;<br>
+      if (llvm::error_code ec = llvm::MemoryBuffer::getFile(ConfigFile, Text)) {<br>
+        llvm::errs() << ec.message() << "\n";<br>
+        continue;<br>
+      }<br>
+      if (llvm::error_code ec = parseConfiguration(Text->getBuffer(), &Style)) {<br>
+        llvm::errs() << "Error reading " << ConfigFile << ": " << ec.message()<br>
+                     << "\n";<br>
+        continue;<br>
+      }<br>
+      DEBUG(llvm::dbgs() << "Using configuration file " << ConfigFile << "\n");<br>
+      return Style;<br>
+    }<br>
+  }<br>
+  llvm::errs() << "Can't find usable .clang-format, using " << FallbackStyle<br>
+               << " style\n";<br>
+  return Style;<br>
+}<br>
+<br>
 } // namespace format<br>
 } // namespace clang<br>
<br>
Modified: cfe/trunk/tools/clang-format/ClangFormat.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=191666&r1=191665&r2=191666&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=191666&r1=191665&r2=191666&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/tools/clang-format/ClangFormat.cpp (original)<br>
+++ cfe/trunk/tools/clang-format/ClangFormat.cpp Mon Sep 30 08:31:48 2013<br>
@@ -63,15 +63,7 @@ LineRanges("lines", cl::desc("<start lin<br>
            cl::cat(ClangFormatCategory));<br>
 static cl::opt<std::string><br>
     Style("style",<br>
-          cl::desc("Coding style, currently supports:\n"<br>
-                   "  LLVM, Google, Chromium, Mozilla, WebKit.\n"<br>
-                   "Use -style=file to load style configuration from\n"<br>
-                   ".clang-format file located in one of the parent\n"<br>
-                   "directories of the source file (or current\n"<br>
-                   "directory for stdin).\n"<br>
-                   "Use -style=\"{key: value, ...}\" to set specific\n"<br>
-                   "parameters, e.g.:\n"<br>
-                   "  -style=\"{BasedOnStyle: llvm, IndentWidth: 8}\""),<br>
+          cl::desc(clang::format::StyleOptionHelpDescription),<br>
           cl::init("file"), cl::cat(ClangFormatCategory));<br>
<br>
 static cl::opt<std::string><br>
@@ -114,72 +106,6 @@ static FileID createInMemoryFile(StringR<br>
   return Sources.createFileID(Entry, SourceLocation(), SrcMgr::C_User);<br>
 }<br>
<br>
-FormatStyle getStyle(StringRef StyleName, StringRef FileName) {<br>
-  FormatStyle Style;<br>
-  getPredefinedStyle(FallbackStyle, &Style);<br>
-<br>
-  if (StyleName.startswith("{")) {<br>
-    // Parse YAML/JSON style from the command line.<br>
-    if (error_code ec = parseConfiguration(StyleName, &Style)) {<br>
-      llvm::errs() << "Error parsing -style: " << ec.message()<br>
-                   << ", using " << FallbackStyle << " style\n";<br>
-    }<br>
-    return Style;<br>
-  }<br>
-<br>
-  if (!StyleName.equals_lower("file")) {<br>
-    if (!getPredefinedStyle(StyleName, &Style))<br>
-      llvm::errs() << "Invalid value for -style, using " << FallbackStyle<br>
-                   << " style\n";<br>
-    return Style;<br>
-  }<br>
-<br>
-  if (FileName == "-")<br>
-    FileName = AssumeFilename;<br>
-  SmallString<128> Path(FileName);<br>
-  llvm::sys::fs::make_absolute(Path);<br>
-  for (StringRef Directory = Path;<br>
-       !Directory.empty();<br>
-       Directory = llvm::sys::path::parent_path(Directory)) {<br>
-    if (!llvm::sys::fs::is_directory(Directory))<br>
-      continue;<br>
-    SmallString<128> ConfigFile(Directory);<br>
-<br>
-    llvm::sys::path::append(ConfigFile, ".clang-format");<br>
-    DEBUG(llvm::dbgs() << "Trying " << ConfigFile << "...\n");<br>
-    bool IsFile = false;<br>
-    // Ignore errors from is_regular_file: we only need to know if we can read<br>
-    // the file or not.<br>
-    llvm::sys::fs::is_regular_file(Twine(ConfigFile), IsFile);<br>
-<br>
-    if (!IsFile) {<br>
-      // Try _clang-format too, since dotfiles are not commonly used on Windows.<br>
-      ConfigFile = Directory;<br>
-      llvm::sys::path::append(ConfigFile, "_clang-format");<br>
-      DEBUG(llvm::dbgs() << "Trying " << ConfigFile << "...\n");<br>
-      llvm::sys::fs::is_regular_file(Twine(ConfigFile), IsFile);<br>
-    }<br>
-<br>
-    if (IsFile) {<br>
-      OwningPtr<MemoryBuffer> Text;<br>
-      if (error_code ec = MemoryBuffer::getFile(ConfigFile, Text)) {<br>
-        llvm::errs() << ec.message() << "\n";<br>
-        continue;<br>
-      }<br>
-      if (error_code ec = parseConfiguration(Text->getBuffer(), &Style)) {<br>
-        llvm::errs() << "Error reading " << ConfigFile << ": " << ec.message()<br>
-                     << "\n";<br>
-        continue;<br>
-      }<br>
-      DEBUG(llvm::dbgs() << "Using configuration file " << ConfigFile << "\n");<br>
-      return Style;<br>
-    }<br>
-  }<br>
-  llvm::errs() << "Can't find usable .clang-format, using " << FallbackStyle<br>
-               << " style\n";<br>
-  return Style;<br>
-}<br>
-<br>
 // Parses <start line>:<end line> input to a pair of line numbers.<br>
 // Returns true on error.<br>
 static bool parseLineRange(StringRef Input, unsigned &FromLine,<br>
@@ -269,7 +195,8 @@ static bool format(std::string FileName)<br>
   if (fillRanges(Sources, ID, Code.get(), Ranges))<br>
     return true;<br>
<br>
-  FormatStyle FormatStyle = getStyle(Style, FileName);<br>
+  FormatStyle FormatStyle =<br>
+      getStyle(Style, (FileName == "-") ? AssumeFilename : FileName);<br>
   Lexer Lex(ID, Sources.getBuffer(ID), Sources,<br>
             getFormattingLangOpts(FormatStyle.Standard));<br>
   tooling::Replacements Replaces = reformat(FormatStyle, Lex, Sources, Ranges);<br>
@@ -340,8 +267,9 @@ int main(int argc, const char **argv) {<br>
     cl::PrintHelpMessage();<br>
<br>
   if (DumpConfig) {<br>
-    std::string Config = clang::format::configurationAsText(<br>
-        clang::format::getStyle(Style, FileNames.empty() ? "-" : FileNames[0]));<br>
+    std::string Config =<br>
+        clang::format::configurationAsText(clang::format::getStyle(<br>
+            Style, FileNames.empty() ? AssumeFilename : FileNames[0]));<br>
     llvm::outs() << Config << "\n";<br>
     return 0;<br>
   }<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><u></u><u></u></p>
</blockquote>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div>
</div>
</div>

</blockquote></div>