[cfe-commits] [clang-tools-extra] r172546 - /clang-tools-extra/trunk/clang-format/ClangFormat.cpp
Daniel Jasper
djasper at google.com
Tue Jan 15 10:56:19 PST 2013
Author: djasper
Date: Tue Jan 15 12:56:19 2013
New Revision: 172546
URL: http://llvm.org/viewvc/llvm-project?rev=172546&view=rev
Log:
Add temporary option to invert the */& binding in a specific style.
This is temporarily necessary until styles are configurable through files
as it seems to be a contentious issue.
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=172546&r1=172545&r2=172546&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-format/ClangFormat.cpp (original)
+++ clang-tools-extra/trunk/clang-format/ClangFormat.cpp Tue Jan 15 12:56:19 2013
@@ -39,6 +39,11 @@
static cl::opt<bool> Inplace("i",
cl::desc("Inplace edit <file>, if specified."));
+// FIXME: Remove this when styles are configurable through files.
+static cl::opt<bool> InvertPointerBinding(
+ "invert-pointer-binding", cl::desc("Inverts the side to which */& bind"),
+ cl::init(false));
+
static cl::opt<std::string> FileName(cl::Positional, cl::desc("[<file>]"),
cl::init("-"));
@@ -54,12 +59,17 @@
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 FormatStyle getStyle() {
+ FormatStyle TheStyle = getGoogleStyle();
+ if (Style == "LLVM")
+ TheStyle = getLLVMStyle();
+ if (Style == "Chromium")
+ TheStyle = getChromiumStyle();
+ if (InvertPointerBinding) {
+ TheStyle.PointerAndReferenceBindToType =
+ !TheStyle.PointerAndReferenceBindToType;
+ }
+ return TheStyle;
}
static void format() {
@@ -82,8 +92,7 @@
End = Start.getLocWithOffset(Length);
std::vector<CharSourceRange> Ranges(
1, CharSourceRange::getCharRange(Start, End));
- tooling::Replacements Replaces = reformat(getStyle(Style), Lex, Sources,
- Ranges);
+ tooling::Replacements Replaces = reformat(getStyle(), Lex, Sources, Ranges);
Rewriter Rewrite(Sources, LangOptions());
tooling::applyAllReplacements(Replaces, Rewrite);
if (Inplace) {
More information about the cfe-commits
mailing list