summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2014-05-22 15:12:22 +0000
committerDaniel Jasper <djasper@google.com>2014-05-22 15:12:22 +0000
commitc64b09acc30e3b153088bb4e634102f64e23fd88 (patch)
treeb3d2394e7b524f44433c08736c84325bc84fa1c6 /clang/lib/Format
parente31d5b6a2cfd0ea1f42d3638fd3a31880de9b352 (diff)
downloadbcm5719-llvm-c64b09acc30e3b153088bb4e634102f64e23fd88.tar.gz
bcm5719-llvm-c64b09acc30e3b153088bb4e634102f64e23fd88.zip
clang-format: Introduce DisableFormat that prevents formatting.
And "none" pseudo-style indicating that formatting should be not applied. (1) Using .clang-format with "DisableFormat: true" effectively prevents formatting for all files within the folder containing such .clang-format file. (2) Using -fallback-style=none together with -style=file prevents formatting when .clang-format is not found, which can be used in on-save callback. Patch by Adam Strzelecki. Thank you! llvm-svn: 209446
Diffstat (limited to 'clang/lib/Format')
-rw-r--r--clang/lib/Format/Format.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 3df13669003..49c9a4a2f2e 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -223,6 +223,7 @@ template <> struct MappingTraits<FormatStyle> {
Style.SpaceBeforeParens);
}
IO.mapOptional("SpaceBeforeParens", Style.SpaceBeforeParens);
+ IO.mapOptional("DisableFormat", Style.DisableFormat);
}
};
@@ -314,6 +315,8 @@ FormatStyle getLLVMStyle() {
LLVMStyle.PenaltyReturnTypeOnItsOwnLine = 60;
LLVMStyle.PenaltyBreakBeforeFirstCallParameter = 19;
+ LLVMStyle.DisableFormat = false;
+
return LLVMStyle;
}
@@ -409,6 +412,12 @@ FormatStyle getGNUStyle() {
return Style;
}
+FormatStyle getNoStyle() {
+ FormatStyle NoStyle = getLLVMStyle();
+ NoStyle.DisableFormat = true;
+ return NoStyle;
+}
+
bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language,
FormatStyle *Style) {
if (Name.equals_lower("llvm")) {
@@ -423,6 +432,8 @@ bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language,
*Style = getWebKitStyle();
} else if (Name.equals_lower("gnu")) {
*Style = getGNUStyle();
+ } else if (Name.equals_lower("none")) {
+ *Style = getNoStyle();
} else {
return false;
}
@@ -1909,6 +1920,11 @@ private:
tooling::Replacements reformat(const FormatStyle &Style, Lexer &Lex,
SourceManager &SourceMgr,
std::vector<CharSourceRange> Ranges) {
+ if (Style.DisableFormat) {
+ tooling::Replacements EmptyResult;
+ return EmptyResult;
+ }
+
Formatter formatter(Style, Lex, SourceMgr, Ranges);
return formatter.format();
}
OpenPOWER on IntegriCloud