[cfe-commits] [clang-tools-extra] r172432 - /clang-tools-extra/trunk/clang-format/ClangFormat.cpp

Daniel Jasper djasper at google.com
Mon Jan 14 08:26:38 PST 2013


Author: djasper
Date: Mon Jan 14 10:26:38 2013
New Revision: 172432

URL: http://llvm.org/viewvc/llvm-project?rev=172432&view=rev
Log:
Add support for Chromium style.

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

Modified: clang-tools-extra/trunk/clang-format/ClangFormat.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-format/ClangFormat.cpp?rev=172432&r1=172431&r2=172432&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-format/ClangFormat.cpp (original)
+++ clang-tools-extra/trunk/clang-format/ClangFormat.cpp Mon Jan 14 10:26:38 2013
@@ -33,7 +33,8 @@
     "length", cl::desc("Format a range of this length, -1 for end of file."),
     cl::init(-1));
 static cl::opt<std::string> Style(
-    "style", cl::desc("Coding style, currently supports: LLVM, Google."),
+    "style",
+    cl::desc("Coding style, currently supports: LLVM, Google, Chromium."),
     cl::init("LLVM"));
 static cl::opt<bool> Inplace("i",
                              cl::desc("Inplace edit <file>, if specified."));
@@ -53,6 +54,14 @@
   return Sources.createFileID(Entry, SourceLocation(), SrcMgr::C_User);
 }
 
+static FormatStyle getStyle(StringRef name) {
+  if (name == "LLVM")
+    return getLLVMStyle();
+  if (name == "Chromium")
+    return getChromiumStyle();
+  return getGoogleStyle();
+}
+
 static void format() {
   FileManager Files((FileSystemOptions()));
   DiagnosticsEngine Diagnostics(
@@ -73,8 +82,8 @@
     End = Start.getLocWithOffset(Length);
   std::vector<CharSourceRange> Ranges(
       1, CharSourceRange::getCharRange(Start, End));
-  FormatStyle FStyle = Style == "LLVM" ? getLLVMStyle() : getGoogleStyle();
-  tooling::Replacements Replaces = reformat(FStyle, Lex, Sources, Ranges);
+  tooling::Replacements Replaces = reformat(getStyle(Style), Lex, Sources,
+                                            Ranges);
   Rewriter Rewrite(Sources, LangOptions());
   tooling::applyAllReplacements(Replaces, Rewrite);
   if (Inplace) {





More information about the cfe-commits mailing list