summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorCameron Desrochers <Cameron.Desrochers@octasic.com>2019-11-15 11:48:06 -0500
committerCameron Desrochers <Cameron.Desrochers@octasic.com>2019-11-15 11:50:22 -0500
commit358eaa3dcea1dee6350c2cbf80aab3c25db4d4d9 (patch)
treef5ad11b9c447f3b23a89f8bd5b0cf3997b49080e /clang/lib/Format/Format.cpp
parent72768685567b5e2ef9820b80997c5aed615e9f57 (diff)
downloadbcm5719-llvm-358eaa3dcea1dee6350c2cbf80aab3c25db4d4d9.tar.gz
bcm5719-llvm-358eaa3dcea1dee6350c2cbf80aab3c25db4d4d9.zip
[clang-format] Flexible line endings
Line ending detection is now set with the `DeriveLineEnding` option. CRLF can now be used as the default line ending by setting `UseCRLF`. When line ending detection is disabled, all line endings are converted according to the `UseCRLF` option. Differential Revision: https://reviews.llvm.org/D19031
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r--clang/lib/Format/Format.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 60958597ad2..083c3a8f02f 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -467,6 +467,7 @@ template <> struct MappingTraits<FormatStyle> {
Style.ConstructorInitializerIndentWidth);
IO.mapOptional("ContinuationIndentWidth", Style.ContinuationIndentWidth);
IO.mapOptional("Cpp11BracedListStyle", Style.Cpp11BracedListStyle);
+ IO.mapOptional("DeriveLineEnding", Style.DeriveLineEnding);
IO.mapOptional("DerivePointerAlignment", Style.DerivePointerAlignment);
IO.mapOptional("DisableFormat", Style.DisableFormat);
IO.mapOptional("ExperimentalAutoDetectBinPacking",
@@ -546,6 +547,7 @@ template <> struct MappingTraits<FormatStyle> {
IO.mapOptional("StatementMacros", Style.StatementMacros);
IO.mapOptional("TabWidth", Style.TabWidth);
IO.mapOptional("TypenameMacros", Style.TypenameMacros);
+ IO.mapOptional("UseCRLF", Style.UseCRLF);
IO.mapOptional("UseTab", Style.UseTab);
}
};
@@ -762,6 +764,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
LLVMStyle.ConstructorInitializerIndentWidth = 4;
LLVMStyle.ContinuationIndentWidth = 4;
LLVMStyle.Cpp11BracedListStyle = true;
+ LLVMStyle.DeriveLineEnding = true;
LLVMStyle.DerivePointerAlignment = false;
LLVMStyle.ExperimentalAutoDetectBinPacking = false;
LLVMStyle.FixNamespaceComments = true;
@@ -792,6 +795,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
LLVMStyle.PointerAlignment = FormatStyle::PAS_Right;
LLVMStyle.SpacesBeforeTrailingComments = 1;
LLVMStyle.Standard = FormatStyle::LS_Latest;
+ LLVMStyle.UseCRLF = false;
LLVMStyle.UseTab = FormatStyle::UT_Never;
LLVMStyle.ReflowComments = true;
LLVMStyle.SpacesInParentheses = false;
@@ -1350,7 +1354,10 @@ public:
WhitespaceManager Whitespaces(
Env.getSourceManager(), Style,
- inputUsesCRLF(Env.getSourceManager().getBufferData(Env.getFileID())));
+ Style.DeriveLineEnding ?
+ inputUsesCRLF(Env.getSourceManager().getBufferData(Env.getFileID()),
+ Style.UseCRLF) :
+ Style.UseCRLF);
ContinuationIndenter Indenter(Style, Tokens.getKeywords(),
Env.getSourceManager(), Whitespaces, Encoding,
BinPackInconclusiveFunctions);
@@ -1371,8 +1378,10 @@ public:
}
private:
- static bool inputUsesCRLF(StringRef Text) {
- return Text.count('\r') * 2 > Text.count('\n');
+ static bool inputUsesCRLF(StringRef Text, bool DefaultToCRLF) {
+ size_t LF = Text.count('\n');
+ size_t CR = Text.count('\r') * 2;
+ return LF == CR ? DefaultToCRLF : CR > LF;
}
bool
OpenPOWER on IntegriCloud