<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<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.<o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></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:dblaikie@gmail.com]
<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<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p> </o:p></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:<o:p></o:p></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";<o:p></o:p></p>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></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<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></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">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><o:p></o:p></p>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</div>
</body>
</html>