summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2013-05-19 00:53:30 +0000
committerAlexander Kornienko <alexfh@google.com>2013-05-19 00:53:30 +0000
commit006b5c89cec1ae5de19bcbef71c04c74754594fb (patch)
tree3330dbe770316ce2fe22e9666044acc88ef5707e /clang/lib/Format/Format.cpp
parent8cfbaa6988282d52f17b2ddb2944582804bbc247 (diff)
downloadbcm5719-llvm-006b5c89cec1ae5de19bcbef71c04c74754594fb.tar.gz
bcm5719-llvm-006b5c89cec1ae5de19bcbef71c04c74754594fb.zip
Clang-format: allow -style="{yaml/json}" on command line
Summary: + improved handling of default style and predefined styles. Reviewers: djasper, klimek Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D813 llvm-svn: 182205
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r--clang/lib/Format/Format.cpp32
1 files changed, 19 insertions, 13 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 3dd0002abb5..64a988df31b 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -60,7 +60,9 @@ template <> struct MappingTraits<clang::format::FormatStyle> {
ArrayRef<StringRef> Styles(StylesArray);
for (size_t i = 0, e = Styles.size(); i < e; ++i) {
StringRef StyleName(Styles[i]);
- if (Style == clang::format::getPredefinedStyle(StyleName)) {
+ clang::format::FormatStyle PredefinedStyle;
+ if (clang::format::getPredefinedStyle(StyleName, &PredefinedStyle) &&
+ Style == PredefinedStyle) {
IO.mapOptional("# BasedOnStyle", StyleName);
break;
}
@@ -69,7 +71,10 @@ template <> struct MappingTraits<clang::format::FormatStyle> {
StringRef BasedOnStyle;
IO.mapOptional("BasedOnStyle", BasedOnStyle);
if (!BasedOnStyle.empty())
- Style = clang::format::getPredefinedStyle(BasedOnStyle);
+ if (!clang::format::getPredefinedStyle(BasedOnStyle, &Style)) {
+ IO.setError(Twine("Unknown value for BasedOnStyle: ", BasedOnStyle));
+ return;
+ }
}
IO.mapOptional("AccessModifierOffset", Style.AccessModifierOffset);
@@ -180,18 +185,19 @@ FormatStyle getMozillaStyle() {
return MozillaStyle;
}
-FormatStyle getPredefinedStyle(StringRef Name) {
+bool getPredefinedStyle(StringRef Name, FormatStyle *Style) {
if (Name.equals_lower("llvm"))
- return getLLVMStyle();
- if (Name.equals_lower("chromium"))
- return getChromiumStyle();
- if (Name.equals_lower("mozilla"))
- return getMozillaStyle();
- if (Name.equals_lower("google"))
- return getGoogleStyle();
-
- llvm::errs() << "Unknown style " << Name << ", using Google style.\n";
- return getGoogleStyle();
+ *Style = getLLVMStyle();
+ else if (Name.equals_lower("chromium"))
+ *Style = getChromiumStyle();
+ else if (Name.equals_lower("mozilla"))
+ *Style = getMozillaStyle();
+ else if (Name.equals_lower("google"))
+ *Style = getGoogleStyle();
+ else
+ return false;
+
+ return true;
}
llvm::error_code parseConfiguration(StringRef Text, FormatStyle *Style) {
OpenPOWER on IntegriCloud