summaryrefslogtreecommitdiff
path: root/lib/Format/Format.cpp
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
commita065461c16984d11995b2fc4f5101bc3dea8a44f (patch)
tree7e1431ee724919230cd9ee9fb50c738b5e468fe2 /lib/Format/Format.cpp
parentb362f6258eabe56443956024c2df7d0f785f3e4d (diff)
downloadclang-a065461c16984d11995b2fc4f5101bc3dea8a44f.tar.gz
clang-a065461c16984d11995b2fc4f5101bc3dea8a44f.tar.bz2
clang-a065461c16984d11995b2fc4f5101bc3dea8a44f.tar.xz
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! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209446 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r--lib/Format/Format.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index 3df1366900..49c9a4a2f2 100644
--- a/lib/Format/Format.cpp
+++ b/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();
}