@@ -403,6 +403,15 @@ struct ScalarEnumerationTraits<FormatStyle::LambdaBodyIndentationKind> {
403403 }
404404};
405405
406+ template <> struct ScalarEnumerationTraits <FormatStyle::LineEndingStyle> {
407+ static void enumeration (IO &IO, FormatStyle::LineEndingStyle &Value) {
408+ IO.enumCase (Value, " LF" , FormatStyle::LE_LF);
409+ IO.enumCase (Value, " CRLF" , FormatStyle::LE_CRLF);
410+ IO.enumCase (Value, " DeriveLF" , FormatStyle::LE_DeriveLF);
411+ IO.enumCase (Value, " DeriveCRLF" , FormatStyle::LE_DeriveCRLF);
412+ }
413+ };
414+
406415template <>
407416struct ScalarEnumerationTraits <FormatStyle::NamespaceIndentationKind> {
408417 static void enumeration (IO &IO,
@@ -784,6 +793,9 @@ template <> struct MappingTraits<FormatStyle> {
784793 bool BreakBeforeInheritanceComma = false ;
785794 bool BreakConstructorInitializersBeforeComma = false ;
786795
796+ bool DeriveLineEnding = true ;
797+ bool UseCRLF = false ;
798+
787799 // For backward compatibility.
788800 if (!IO.outputting ()) {
789801 IO.mapOptional (" AlignEscapedNewlinesLeft" , Style.AlignEscapedNewlines );
@@ -794,13 +806,15 @@ template <> struct MappingTraits<FormatStyle> {
794806 BreakConstructorInitializersBeforeComma);
795807 IO.mapOptional (" ConstructorInitializerAllOnOneLineOrOnePerLine" ,
796808 OnCurrentLine);
809+ IO.mapOptional (" DeriveLineEnding" , DeriveLineEnding);
797810 IO.mapOptional (" DerivePointerBinding" , Style.DerivePointerAlignment );
798811 IO.mapOptional (" IndentFunctionDeclarationAfterType" ,
799812 Style.IndentWrappedFunctionNames );
800813 IO.mapOptional (" IndentRequires" , Style.IndentRequiresClause );
801814 IO.mapOptional (" PointerBindsToType" , Style.PointerAlignment );
802815 IO.mapOptional (" SpaceAfterControlStatementKeyword" ,
803816 Style.SpaceBeforeParens );
817+ IO.mapOptional (" UseCRLF" , UseCRLF);
804818 }
805819
806820 IO.mapOptional (" AccessModifierOffset" , Style.AccessModifierOffset );
@@ -871,7 +885,6 @@ template <> struct MappingTraits<FormatStyle> {
871885 Style.ConstructorInitializerIndentWidth );
872886 IO.mapOptional (" ContinuationIndentWidth" , Style.ContinuationIndentWidth );
873887 IO.mapOptional (" Cpp11BracedListStyle" , Style.Cpp11BracedListStyle );
874- IO.mapOptional (" DeriveLineEnding" , Style.DeriveLineEnding );
875888 IO.mapOptional (" DerivePointerAlignment" , Style.DerivePointerAlignment );
876889 IO.mapOptional (" DisableFormat" , Style.DisableFormat );
877890 IO.mapOptional (" EmptyLineAfterAccessModifier" ,
@@ -908,6 +921,7 @@ template <> struct MappingTraits<FormatStyle> {
908921 IO.mapOptional (" KeepEmptyLinesAtTheStartOfBlocks" ,
909922 Style.KeepEmptyLinesAtTheStartOfBlocks );
910923 IO.mapOptional (" LambdaBodyIndentation" , Style.LambdaBodyIndentation );
924+ IO.mapOptional (" LineEnding" , Style.LineEnding );
911925 IO.mapOptional (" MacroBlockBegin" , Style.MacroBlockBegin );
912926 IO.mapOptional (" MacroBlockEnd" , Style.MacroBlockEnd );
913927 IO.mapOptional (" MaxEmptyLinesToKeep" , Style.MaxEmptyLinesToKeep );
@@ -1003,7 +1017,6 @@ template <> struct MappingTraits<FormatStyle> {
10031017 IO.mapOptional (" StatementMacros" , Style.StatementMacros );
10041018 IO.mapOptional (" TabWidth" , Style.TabWidth );
10051019 IO.mapOptional (" TypenameMacros" , Style.TypenameMacros );
1006- IO.mapOptional (" UseCRLF" , Style.UseCRLF );
10071020 IO.mapOptional (" UseTab" , Style.UseTab );
10081021 IO.mapOptional (" WhitespaceSensitiveMacros" ,
10091022 Style.WhitespaceSensitiveMacros );
@@ -1052,6 +1065,13 @@ template <> struct MappingTraits<FormatStyle> {
10521065 else if (!OnNextLine)
10531066 Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
10541067 }
1068+
1069+ if (Style.LineEnding == FormatStyle::LE_DeriveLF) {
1070+ if (!DeriveLineEnding)
1071+ Style.LineEnding = UseCRLF ? FormatStyle::LE_CRLF : FormatStyle::LE_LF;
1072+ else if (UseCRLF)
1073+ Style.LineEnding = FormatStyle::LE_DeriveCRLF;
1074+ }
10551075 }
10561076};
10571077
@@ -1329,7 +1349,6 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
13291349 LLVMStyle.ConstructorInitializerIndentWidth = 4 ;
13301350 LLVMStyle.ContinuationIndentWidth = 4 ;
13311351 LLVMStyle.Cpp11BracedListStyle = true ;
1332- LLVMStyle.DeriveLineEnding = true ;
13331352 LLVMStyle.DerivePointerAlignment = false ;
13341353 LLVMStyle.DisableFormat = false ;
13351354 LLVMStyle.EmptyLineAfterAccessModifier = FormatStyle::ELAAMS_Never;
@@ -1363,6 +1382,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
13631382 LLVMStyle.JavaScriptWrapImports = true ;
13641383 LLVMStyle.KeepEmptyLinesAtTheStartOfBlocks = true ;
13651384 LLVMStyle.LambdaBodyIndentation = FormatStyle::LBI_Signature;
1385+ LLVMStyle.LineEnding = FormatStyle::LE_DeriveLF;
13661386 LLVMStyle.MaxEmptyLinesToKeep = 1 ;
13671387 LLVMStyle.NamespaceIndentation = FormatStyle::NI_None;
13681388 LLVMStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Auto;
@@ -1416,7 +1436,6 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
14161436 LLVMStyle.StatementMacros .push_back (" Q_UNUSED" );
14171437 LLVMStyle.StatementMacros .push_back (" QT_REQUIRE_VERSION" );
14181438 LLVMStyle.TabWidth = 8 ;
1419- LLVMStyle.UseCRLF = false ;
14201439 LLVMStyle.UseTab = FormatStyle::UT_Never;
14211440 LLVMStyle.WhitespaceSensitiveMacros .push_back (" BOOST_PP_STRINGIZE" );
14221441 LLVMStyle.WhitespaceSensitiveMacros .push_back (" CF_SWIFT_NAME" );
@@ -2190,11 +2209,11 @@ class Formatter : public TokenAnalyzer {
21902209
21912210 WhitespaceManager Whitespaces (
21922211 Env.getSourceManager (), Style,
2193- Style.DeriveLineEnding
2212+ Style.LineEnding > FormatStyle::LE_CRLF
21942213 ? WhitespaceManager::inputUsesCRLF (
21952214 Env.getSourceManager ().getBufferData (Env.getFileID ()),
2196- Style.UseCRLF )
2197- : Style.UseCRLF );
2215+ Style.LineEnding == FormatStyle::LE_DeriveCRLF )
2216+ : Style.LineEnding == FormatStyle::LE_CRLF );
21982217 ContinuationIndenter Indenter (Style, Tokens.getKeywords (),
21992218 Env.getSourceManager (), Whitespaces, Encoding,
22002219 BinPackInconclusiveFunctions);
0 commit comments