26#include "llvm/ADT/Sequence.h"
27#include "llvm/ADT/StringSet.h"
30#define DEBUG_TYPE "format-formatter"
32using clang::format::FormatStyle;
34LLVM_YAML_IS_SEQUENCE_VECTOR(FormatStyle::RawStringFormat)
35LLVM_YAML_IS_SEQUENCE_VECTOR(FormatStyle::BinaryOperationBreakRule)
48struct ScalarEnumerationTraits<FormatStyle::BreakBeforeNoexceptSpecifierStyle> {
51 IO.enumCase(
Value,
"Never", FormatStyle::BBNSS_Never);
52 IO.enumCase(
Value,
"OnlyWithParen", FormatStyle::BBNSS_OnlyWithParen);
53 IO.enumCase(
Value,
"Always", FormatStyle::BBNSS_Always);
57template <>
struct MappingTraits<FormatStyle::AlignConsecutiveStyle> {
59 IO.enumCase(
Value,
"None", FormatStyle::AlignConsecutiveStyle{});
60 IO.enumCase(
Value,
"Consecutive",
61 FormatStyle::AlignConsecutiveStyle(
66 IO.enumCase(
Value,
"AcrossEmptyLines",
67 FormatStyle::AlignConsecutiveStyle(
72 IO.enumCase(
Value,
"AcrossComments",
73 FormatStyle::AlignConsecutiveStyle(
78 IO.enumCase(
Value,
"AcrossEmptyLinesAndComments",
79 FormatStyle::AlignConsecutiveStyle(
86 IO.enumCase(
Value,
"true",
87 FormatStyle::AlignConsecutiveStyle(
92 IO.enumCase(
Value,
"false", FormatStyle::AlignConsecutiveStyle{});
95 static void mapping(IO &IO, FormatStyle::AlignConsecutiveStyle &
Value) {
96 IO.mapOptional(
"Enabled",
Value.Enabled);
97 IO.mapOptional(
"AcrossEmptyLines",
Value.AcrossEmptyLines);
98 IO.mapOptional(
"AcrossComments",
Value.AcrossComments);
99 IO.mapOptional(
"AlignCompound",
Value.AlignCompound);
100 IO.mapOptional(
"AlignFunctionDeclarations",
101 Value.AlignFunctionDeclarations);
102 IO.mapOptional(
"AlignFunctionPointers",
Value.AlignFunctionPointers);
103 IO.mapOptional(
"PadOperators",
Value.PadOperators);
108struct MappingTraits<FormatStyle::ShortCaseStatementsAlignmentStyle> {
110 FormatStyle::ShortCaseStatementsAlignmentStyle &
Value) {
111 IO.mapOptional(
"Enabled",
Value.Enabled);
112 IO.mapOptional(
"AcrossEmptyLines",
Value.AcrossEmptyLines);
113 IO.mapOptional(
"AcrossComments",
Value.AcrossComments);
114 IO.mapOptional(
"AlignCaseArrows",
Value.AlignCaseArrows);
115 IO.mapOptional(
"AlignCaseColons",
Value.AlignCaseColons);
120struct ScalarEnumerationTraits<FormatStyle::AttributeBreakingStyle> {
122 IO.enumCase(
Value,
"Always", FormatStyle::ABS_Always);
123 IO.enumCase(
Value,
"Leave", FormatStyle::ABS_Leave);
124 IO.enumCase(
Value,
"LeaveAll", FormatStyle::ABS_LeaveAll);
125 IO.enumCase(
Value,
"Never", FormatStyle::ABS_Never);
130struct ScalarEnumerationTraits<FormatStyle::ArrayInitializerAlignmentStyle> {
132 FormatStyle::ArrayInitializerAlignmentStyle &
Value) {
133 IO.enumCase(
Value,
"None", FormatStyle::AIAS_None);
134 IO.enumCase(
Value,
"Left", FormatStyle::AIAS_Left);
135 IO.enumCase(
Value,
"Right", FormatStyle::AIAS_Right);
139template <>
struct ScalarEnumerationTraits<FormatStyle::BinaryOperatorStyle> {
141 IO.enumCase(
Value,
"All", FormatStyle::BOS_All);
142 IO.enumCase(
Value,
"true", FormatStyle::BOS_All);
143 IO.enumCase(
Value,
"None", FormatStyle::BOS_None);
144 IO.enumCase(
Value,
"false", FormatStyle::BOS_None);
145 IO.enumCase(
Value,
"NonAssignment", FormatStyle::BOS_NonAssignment);
150struct ScalarEnumerationTraits<FormatStyle::BinPackParametersStyle> {
152 IO.enumCase(
Value,
"BinPack", FormatStyle::BPPS_BinPack);
153 IO.enumCase(
Value,
"OnePerLine", FormatStyle::BPPS_OnePerLine);
154 IO.enumCase(
Value,
"AlwaysOnePerLine", FormatStyle::BPPS_AlwaysOnePerLine);
157 IO.enumCase(
Value,
"true", FormatStyle::BPPS_BinPack);
158 IO.enumCase(
Value,
"false", FormatStyle::BPPS_OnePerLine);
162template <>
struct ScalarEnumerationTraits<FormatStyle::BinPackStyle> {
164 IO.enumCase(
Value,
"Auto", FormatStyle::BPS_Auto);
165 IO.enumCase(
Value,
"Always", FormatStyle::BPS_Always);
166 IO.enumCase(
Value,
"Never", FormatStyle::BPS_Never);
171struct ScalarEnumerationTraits<FormatStyle::BitFieldColonSpacingStyle> {
173 FormatStyle::BitFieldColonSpacingStyle &
Value) {
174 IO.enumCase(
Value,
"Both", FormatStyle::BFCS_Both);
175 IO.enumCase(
Value,
"None", FormatStyle::BFCS_None);
176 IO.enumCase(
Value,
"Before", FormatStyle::BFCS_Before);
177 IO.enumCase(
Value,
"After", FormatStyle::BFCS_After);
181template <>
struct ScalarEnumerationTraits<FormatStyle::BraceBreakingStyle> {
183 IO.enumCase(
Value,
"Attach", FormatStyle::BS_Attach);
184 IO.enumCase(
Value,
"Linux", FormatStyle::BS_Linux);
185 IO.enumCase(
Value,
"Mozilla", FormatStyle::BS_Mozilla);
186 IO.enumCase(
Value,
"Stroustrup", FormatStyle::BS_Stroustrup);
187 IO.enumCase(
Value,
"Allman", FormatStyle::BS_Allman);
188 IO.enumCase(
Value,
"Whitesmiths", FormatStyle::BS_Whitesmiths);
189 IO.enumCase(
Value,
"GNU", FormatStyle::BS_GNU);
190 IO.enumCase(
Value,
"WebKit", FormatStyle::BS_WebKit);
191 IO.enumCase(
Value,
"Custom", FormatStyle::BS_Custom);
195template <>
struct MappingTraits<FormatStyle::BraceWrappingFlags> {
196 static void mapping(IO &IO, FormatStyle::BraceWrappingFlags &Wrapping) {
197 IO.mapOptional(
"AfterCaseLabel", Wrapping.AfterCaseLabel);
198 IO.mapOptional(
"AfterClass", Wrapping.AfterClass);
199 IO.mapOptional(
"AfterControlStatement", Wrapping.AfterControlStatement);
200 IO.mapOptional(
"AfterEnum", Wrapping.AfterEnum);
201 IO.mapOptional(
"AfterExternBlock", Wrapping.AfterExternBlock);
202 IO.mapOptional(
"AfterFunction", Wrapping.AfterFunction);
203 IO.mapOptional(
"AfterNamespace", Wrapping.AfterNamespace);
204 IO.mapOptional(
"AfterObjCDeclaration", Wrapping.AfterObjCDeclaration);
205 IO.mapOptional(
"AfterStruct", Wrapping.AfterStruct);
206 IO.mapOptional(
"AfterUnion", Wrapping.AfterUnion);
207 IO.mapOptional(
"BeforeCatch", Wrapping.BeforeCatch);
208 IO.mapOptional(
"BeforeElse", Wrapping.BeforeElse);
209 IO.mapOptional(
"BeforeLambdaBody", Wrapping.BeforeLambdaBody);
210 IO.mapOptional(
"BeforeWhile", Wrapping.BeforeWhile);
211 IO.mapOptional(
"IndentBraces", Wrapping.IndentBraces);
212 IO.mapOptional(
"SplitEmptyFunction", Wrapping.SplitEmptyFunction);
213 IO.mapOptional(
"SplitEmptyRecord", Wrapping.SplitEmptyRecord);
214 IO.mapOptional(
"SplitEmptyNamespace", Wrapping.SplitEmptyNamespace);
232struct ScalarEnumerationTraits<
233 FormatStyle::BraceWrappingAfterControlStatementStyle> {
236 FormatStyle::BraceWrappingAfterControlStatementStyle &
Value) {
237 IO.enumCase(
Value,
"Never", FormatStyle::BWACS_Never);
238 IO.enumCase(
Value,
"MultiLine", FormatStyle::BWACS_MultiLine);
239 IO.enumCase(
Value,
"Always", FormatStyle::BWACS_Always);
242 IO.enumCase(
Value,
"false", FormatStyle::BWACS_Never);
243 IO.enumCase(
Value,
"true", FormatStyle::BWACS_Always);
248struct ScalarEnumerationTraits<
249 FormatStyle::BreakBeforeConceptDeclarationsStyle> {
252 IO.enumCase(
Value,
"Never", FormatStyle::BBCDS_Never);
253 IO.enumCase(
Value,
"Allowed", FormatStyle::BBCDS_Allowed);
254 IO.enumCase(
Value,
"Always", FormatStyle::BBCDS_Always);
257 IO.enumCase(
Value,
"true", FormatStyle::BBCDS_Always);
258 IO.enumCase(
Value,
"false", FormatStyle::BBCDS_Allowed);
263struct ScalarEnumerationTraits<FormatStyle::BreakBeforeInlineASMColonStyle> {
265 FormatStyle::BreakBeforeInlineASMColonStyle &
Value) {
266 IO.enumCase(
Value,
"Never", FormatStyle::BBIAS_Never);
267 IO.enumCase(
Value,
"OnlyMultiline", FormatStyle::BBIAS_OnlyMultiline);
268 IO.enumCase(
Value,
"Always", FormatStyle::BBIAS_Always);
273struct ScalarEnumerationTraits<FormatStyle::BreakBinaryOperationsStyle> {
275 FormatStyle::BreakBinaryOperationsStyle &
Value) {
276 IO.enumCase(
Value,
"Never", FormatStyle::BBO_Never);
277 IO.enumCase(
Value,
"OnePerLine", FormatStyle::BBO_OnePerLine);
278 IO.enumCase(
Value,
"RespectPrecedence", FormatStyle::BBO_RespectPrecedence);
282template <>
struct ScalarTraits<
clang::tok::TokenKind> {
284 llvm::raw_ostream &Out) {
291 static StringRef
input(StringRef Scalar,
void *,
294#define PUNCTUATOR(Name, Spelling) \
295 if (Scalar == Spelling) { \
296 Value = clang::tok::Name; \
299#include "clang/Basic/TokenKinds.def"
300 return "unknown operator";
303 static QuotingType
mustQuote(StringRef) {
return QuotingType::None; }
306template <>
struct MappingTraits<FormatStyle::BinaryOperationBreakRule> {
307 static void mapping(IO &IO, FormatStyle::BinaryOperationBreakRule &
Value) {
308 IO.mapOptional(
"Operators",
Value.Operators);
310 if (!IO.outputting())
311 Value.Style = FormatStyle::BBO_OnePerLine;
312 IO.mapOptional(
"Style",
Value.Style);
313 IO.mapOptional(
"MinChainLength",
Value.MinChainLength);
317template <>
struct MappingTraits<FormatStyle::BreakBinaryOperationsOptions> {
319 FormatStyle::BreakBinaryOperationsOptions &
Value) {
320 IO.enumCase(
Value,
"Never",
321 FormatStyle::BreakBinaryOperationsOptions(
322 {FormatStyle::BBO_Never, {}}));
323 IO.enumCase(
Value,
"OnePerLine",
324 FormatStyle::BreakBinaryOperationsOptions(
325 {FormatStyle::BBO_OnePerLine, {}}));
326 IO.enumCase(
Value,
"RespectPrecedence",
327 FormatStyle::BreakBinaryOperationsOptions(
328 {FormatStyle::BBO_RespectPrecedence, {}}));
332 FormatStyle::BreakBinaryOperationsOptions &
Value) {
333 IO.mapOptional(
"Default",
Value.Default);
334 IO.mapOptional(
"PerOperator",
Value.PerOperator);
339struct ScalarEnumerationTraits<FormatStyle::BreakConstructorInitializersStyle> {
342 IO.enumCase(
Value,
"BeforeColon", FormatStyle::BCIS_BeforeColon);
343 IO.enumCase(
Value,
"BeforeComma", FormatStyle::BCIS_BeforeComma);
344 IO.enumCase(
Value,
"AfterColon", FormatStyle::BCIS_AfterColon);
345 IO.enumCase(
Value,
"AfterComma", FormatStyle::BCIS_AfterComma);
350struct ScalarEnumerationTraits<FormatStyle::BreakInheritanceListStyle> {
352 FormatStyle::BreakInheritanceListStyle &
Value) {
353 IO.enumCase(
Value,
"BeforeColon", FormatStyle::BILS_BeforeColon);
354 IO.enumCase(
Value,
"BeforeComma", FormatStyle::BILS_BeforeComma);
355 IO.enumCase(
Value,
"AfterColon", FormatStyle::BILS_AfterColon);
356 IO.enumCase(
Value,
"AfterComma", FormatStyle::BILS_AfterComma);
361struct ScalarEnumerationTraits<FormatStyle::BreakTemplateDeclarationsStyle> {
363 FormatStyle::BreakTemplateDeclarationsStyle &
Value) {
364 IO.enumCase(
Value,
"Leave", FormatStyle::BTDS_Leave);
365 IO.enumCase(
Value,
"No", FormatStyle::BTDS_No);
366 IO.enumCase(
Value,
"MultiLine", FormatStyle::BTDS_MultiLine);
367 IO.enumCase(
Value,
"Yes", FormatStyle::BTDS_Yes);
370 IO.enumCase(
Value,
"false", FormatStyle::BTDS_MultiLine);
371 IO.enumCase(
Value,
"true", FormatStyle::BTDS_Yes);
375template <>
struct ScalarEnumerationTraits<FormatStyle::BracedListStyle> {
377 IO.enumCase(
Value,
"Block", FormatStyle::BLS_Block);
378 IO.enumCase(
Value,
"FunctionCall", FormatStyle::BLS_FunctionCall);
379 IO.enumCase(
Value,
"AlignFirstComment", FormatStyle::BLS_AlignFirstComment);
382 IO.enumCase(
Value,
"false", FormatStyle::BLS_Block);
383 IO.enumCase(
Value,
"true", FormatStyle::BLS_AlignFirstComment);
387template <>
struct ScalarEnumerationTraits<FormatStyle::DAGArgStyle> {
389 IO.enumCase(
Value,
"DontBreak", FormatStyle::DAS_DontBreak);
390 IO.enumCase(
Value,
"BreakElements", FormatStyle::DAS_BreakElements);
391 IO.enumCase(
Value,
"BreakAll", FormatStyle::DAS_BreakAll);
396struct ScalarEnumerationTraits<FormatStyle::DefinitionReturnTypeBreakingStyle> {
399 IO.enumCase(
Value,
"None", FormatStyle::DRTBS_None);
400 IO.enumCase(
Value,
"All", FormatStyle::DRTBS_All);
401 IO.enumCase(
Value,
"TopLevel", FormatStyle::DRTBS_TopLevel);
404 IO.enumCase(
Value,
"false", FormatStyle::DRTBS_None);
405 IO.enumCase(
Value,
"true", FormatStyle::DRTBS_All);
410struct ScalarEnumerationTraits<FormatStyle::EscapedNewlineAlignmentStyle> {
412 FormatStyle::EscapedNewlineAlignmentStyle &
Value) {
413 IO.enumCase(
Value,
"DontAlign", FormatStyle::ENAS_DontAlign);
414 IO.enumCase(
Value,
"Left", FormatStyle::ENAS_Left);
415 IO.enumCase(
Value,
"LeftWithLastLine", FormatStyle::ENAS_LeftWithLastLine);
416 IO.enumCase(
Value,
"Right", FormatStyle::ENAS_Right);
419 IO.enumCase(
Value,
"true", FormatStyle::ENAS_Left);
420 IO.enumCase(
Value,
"false", FormatStyle::ENAS_Right);
425struct ScalarEnumerationTraits<FormatStyle::EmptyLineAfterAccessModifierStyle> {
428 IO.enumCase(
Value,
"Never", FormatStyle::ELAAMS_Never);
429 IO.enumCase(
Value,
"Leave", FormatStyle::ELAAMS_Leave);
430 IO.enumCase(
Value,
"Always", FormatStyle::ELAAMS_Always);
435struct ScalarEnumerationTraits<
436 FormatStyle::EmptyLineBeforeAccessModifierStyle> {
439 IO.enumCase(
Value,
"Never", FormatStyle::ELBAMS_Never);
440 IO.enumCase(
Value,
"Leave", FormatStyle::ELBAMS_Leave);
441 IO.enumCase(
Value,
"LogicalBlock", FormatStyle::ELBAMS_LogicalBlock);
442 IO.enumCase(
Value,
"Always", FormatStyle::ELBAMS_Always);
447struct ScalarEnumerationTraits<FormatStyle::EnumTrailingCommaStyle> {
449 IO.enumCase(
Value,
"Leave", FormatStyle::ETC_Leave);
450 IO.enumCase(
Value,
"Insert", FormatStyle::ETC_Insert);
451 IO.enumCase(
Value,
"Remove", FormatStyle::ETC_Remove);
456struct ScalarEnumerationTraits<FormatStyle::IndentExternBlockStyle> {
458 IO.enumCase(
Value,
"AfterExternBlock", FormatStyle::IEBS_AfterExternBlock);
459 IO.enumCase(
Value,
"Indent", FormatStyle::IEBS_Indent);
460 IO.enumCase(
Value,
"NoIndent", FormatStyle::IEBS_NoIndent);
461 IO.enumCase(
Value,
"true", FormatStyle::IEBS_Indent);
462 IO.enumCase(
Value,
"false", FormatStyle::IEBS_NoIndent);
466template <>
struct MappingTraits<FormatStyle::IntegerLiteralSeparatorStyle> {
467 static void mapping(IO &IO, FormatStyle::IntegerLiteralSeparatorStyle &
Base) {
468 IO.mapOptional(
"Binary",
Base.Binary);
469 IO.mapOptional(
"BinaryMinDigitsInsert",
Base.BinaryMinDigitsInsert);
470 IO.mapOptional(
"BinaryMaxDigitsRemove",
Base.BinaryMaxDigitsRemove);
471 IO.mapOptional(
"Decimal",
Base.Decimal);
472 IO.mapOptional(
"DecimalMinDigitsInsert",
Base.DecimalMinDigitsInsert);
473 IO.mapOptional(
"DecimalMaxDigitsRemove",
Base.DecimalMaxDigitsRemove);
474 IO.mapOptional(
"Hex",
Base.Hex);
475 IO.mapOptional(
"HexMinDigitsInsert",
Base.HexMinDigitsInsert);
476 IO.mapOptional(
"HexMaxDigitsRemove",
Base.HexMaxDigitsRemove);
479 IO.mapOptional(
"BinaryMinDigits",
Base.BinaryMinDigitsInsert);
480 IO.mapOptional(
"DecimalMinDigits",
Base.DecimalMinDigitsInsert);
481 IO.mapOptional(
"HexMinDigits",
Base.HexMinDigitsInsert);
485template <>
struct ScalarEnumerationTraits<FormatStyle::JavaScriptQuoteStyle> {
487 IO.enumCase(
Value,
"Leave", FormatStyle::JSQS_Leave);
488 IO.enumCase(
Value,
"Single", FormatStyle::JSQS_Single);
489 IO.enumCase(
Value,
"Double", FormatStyle::JSQS_Double);
493template <>
struct MappingTraits<FormatStyle::KeepEmptyLinesStyle> {
495 IO.mapOptional(
"AtEndOfFile",
Value.AtEndOfFile);
496 IO.mapOptional(
"AtStartOfBlock",
Value.AtStartOfBlock);
497 IO.mapOptional(
"AtStartOfFile",
Value.AtStartOfFile);
501template <>
struct ScalarEnumerationTraits<FormatStyle::LanguageKind> {
503 IO.enumCase(
Value,
"C", FormatStyle::LK_C);
504 IO.enumCase(
Value,
"Cpp", FormatStyle::LK_Cpp);
505 IO.enumCase(
Value,
"Java", FormatStyle::LK_Java);
506 IO.enumCase(
Value,
"JavaScript", FormatStyle::LK_JavaScript);
507 IO.enumCase(
Value,
"ObjC", FormatStyle::LK_ObjC);
508 IO.enumCase(
Value,
"Proto", FormatStyle::LK_Proto);
509 IO.enumCase(
Value,
"TableGen", FormatStyle::LK_TableGen);
510 IO.enumCase(
Value,
"TextProto", FormatStyle::LK_TextProto);
511 IO.enumCase(
Value,
"CSharp", FormatStyle::LK_CSharp);
512 IO.enumCase(
Value,
"Json", FormatStyle::LK_Json);
513 IO.enumCase(
Value,
"Verilog", FormatStyle::LK_Verilog);
517template <>
struct ScalarEnumerationTraits<FormatStyle::LanguageStandard> {
519 IO.enumCase(
Value,
"c++03", FormatStyle::LS_Cpp03);
520 IO.enumCase(
Value,
"C++03", FormatStyle::LS_Cpp03);
521 IO.enumCase(
Value,
"Cpp03", FormatStyle::LS_Cpp03);
523 IO.enumCase(
Value,
"c++11", FormatStyle::LS_Cpp11);
524 IO.enumCase(
Value,
"C++11", FormatStyle::LS_Cpp11);
526 IO.enumCase(
Value,
"c++14", FormatStyle::LS_Cpp14);
527 IO.enumCase(
Value,
"c++17", FormatStyle::LS_Cpp17);
528 IO.enumCase(
Value,
"c++20", FormatStyle::LS_Cpp20);
530 IO.enumCase(
Value,
"Latest", FormatStyle::LS_Latest);
531 IO.enumCase(
Value,
"Cpp11", FormatStyle::LS_Latest);
532 IO.enumCase(
Value,
"Auto", FormatStyle::LS_Auto);
537struct ScalarEnumerationTraits<FormatStyle::LambdaBodyIndentationKind> {
539 FormatStyle::LambdaBodyIndentationKind &
Value) {
540 IO.enumCase(
Value,
"Signature", FormatStyle::LBI_Signature);
541 IO.enumCase(
Value,
"OuterScope", FormatStyle::LBI_OuterScope);
545template <>
struct ScalarEnumerationTraits<FormatStyle::LineEndingStyle> {
547 IO.enumCase(
Value,
"LF", FormatStyle::LE_LF);
548 IO.enumCase(
Value,
"CRLF", FormatStyle::LE_CRLF);
549 IO.enumCase(
Value,
"DeriveLF", FormatStyle::LE_DeriveLF);
550 IO.enumCase(
Value,
"DeriveCRLF", FormatStyle::LE_DeriveCRLF);
555struct ScalarEnumerationTraits<FormatStyle::NamespaceIndentationKind> {
557 FormatStyle::NamespaceIndentationKind &
Value) {
558 IO.enumCase(
Value,
"None", FormatStyle::NI_None);
559 IO.enumCase(
Value,
"Inner", FormatStyle::NI_Inner);
560 IO.enumCase(
Value,
"All", FormatStyle::NI_All);
565struct ScalarEnumerationTraits<FormatStyle::NumericLiteralComponentStyle> {
567 FormatStyle::NumericLiteralComponentStyle &
Value) {
568 IO.enumCase(
Value,
"Leave", FormatStyle::NLCS_Leave);
569 IO.enumCase(
Value,
"Upper", FormatStyle::NLCS_Upper);
570 IO.enumCase(
Value,
"Lower", FormatStyle::NLCS_Lower);
574template <>
struct MappingTraits<FormatStyle::NumericLiteralCaseStyle> {
575 static void mapping(IO &IO, FormatStyle::NumericLiteralCaseStyle &
Value) {
576 IO.mapOptional(
"ExponentLetter",
Value.ExponentLetter);
577 IO.mapOptional(
"HexDigit",
Value.HexDigit);
578 IO.mapOptional(
"Prefix",
Value.Prefix);
579 IO.mapOptional(
"Suffix",
Value.Suffix);
583template <>
struct ScalarEnumerationTraits<FormatStyle::OperandAlignmentStyle> {
585 IO.enumCase(
Value,
"DontAlign", FormatStyle::OAS_DontAlign);
586 IO.enumCase(
Value,
"Align", FormatStyle::OAS_Align);
587 IO.enumCase(
Value,
"AlignAfterOperator",
588 FormatStyle::OAS_AlignAfterOperator);
591 IO.enumCase(
Value,
"true", FormatStyle::OAS_Align);
592 IO.enumCase(
Value,
"false", FormatStyle::OAS_DontAlign);
597struct ScalarEnumerationTraits<FormatStyle::PackConstructorInitializersStyle> {
600 IO.enumCase(
Value,
"Never", FormatStyle::PCIS_Never);
601 IO.enumCase(
Value,
"BinPack", FormatStyle::PCIS_BinPack);
602 IO.enumCase(
Value,
"CurrentLine", FormatStyle::PCIS_CurrentLine);
603 IO.enumCase(
Value,
"NextLine", FormatStyle::PCIS_NextLine);
604 IO.enumCase(
Value,
"NextLineOnly", FormatStyle::PCIS_NextLineOnly);
608template <>
struct ScalarEnumerationTraits<FormatStyle::PointerAlignmentStyle> {
610 IO.enumCase(
Value,
"Middle", FormatStyle::PAS_Middle);
611 IO.enumCase(
Value,
"Left", FormatStyle::PAS_Left);
612 IO.enumCase(
Value,
"Right", FormatStyle::PAS_Right);
615 IO.enumCase(
Value,
"true", FormatStyle::PAS_Left);
616 IO.enumCase(
Value,
"false", FormatStyle::PAS_Right);
621struct ScalarEnumerationTraits<FormatStyle::PPDirectiveIndentStyle> {
623 IO.enumCase(
Value,
"None", FormatStyle::PPDIS_None);
624 IO.enumCase(
Value,
"AfterHash", FormatStyle::PPDIS_AfterHash);
625 IO.enumCase(
Value,
"BeforeHash", FormatStyle::PPDIS_BeforeHash);
626 IO.enumCase(
Value,
"Leave", FormatStyle::PPDIS_Leave);
631struct ScalarEnumerationTraits<FormatStyle::QualifierAlignmentStyle> {
633 IO.enumCase(
Value,
"Leave", FormatStyle::QAS_Leave);
634 IO.enumCase(
Value,
"Left", FormatStyle::QAS_Left);
635 IO.enumCase(
Value,
"Right", FormatStyle::QAS_Right);
636 IO.enumCase(
Value,
"Custom", FormatStyle::QAS_Custom);
640template <>
struct MappingTraits<FormatStyle::RawStringFormat> {
641 static void mapping(IO &IO, FormatStyle::RawStringFormat &Format) {
642 IO.mapOptional(
"Language", Format.Language);
643 IO.mapOptional(
"Delimiters", Format.Delimiters);
644 IO.mapOptional(
"EnclosingFunctions", Format.EnclosingFunctions);
645 IO.mapOptional(
"CanonicalDelimiter", Format.CanonicalDelimiter);
646 IO.mapOptional(
"BasedOnStyle", Format.BasedOnStyle);
650template <>
struct ScalarEnumerationTraits<FormatStyle::ReflowCommentsStyle> {
652 IO.enumCase(
Value,
"Never", FormatStyle::RCS_Never);
653 IO.enumCase(
Value,
"IndentOnly", FormatStyle::RCS_IndentOnly);
654 IO.enumCase(
Value,
"Always", FormatStyle::RCS_Always);
656 IO.enumCase(
Value,
"false", FormatStyle::RCS_Never);
657 IO.enumCase(
Value,
"true", FormatStyle::RCS_Always);
662struct ScalarEnumerationTraits<FormatStyle::ReferenceAlignmentStyle> {
664 IO.enumCase(
Value,
"Pointer", FormatStyle::RAS_Pointer);
665 IO.enumCase(
Value,
"Middle", FormatStyle::RAS_Middle);
666 IO.enumCase(
Value,
"Left", FormatStyle::RAS_Left);
667 IO.enumCase(
Value,
"Right", FormatStyle::RAS_Right);
672struct ScalarEnumerationTraits<FormatStyle::RemoveParenthesesStyle> {
674 IO.enumCase(
Value,
"Leave", FormatStyle::RPS_Leave);
675 IO.enumCase(
Value,
"MultipleParentheses",
676 FormatStyle::RPS_MultipleParentheses);
677 IO.enumCase(
Value,
"ReturnStatement", FormatStyle::RPS_ReturnStatement);
682struct ScalarEnumerationTraits<FormatStyle::RequiresClausePositionStyle> {
684 FormatStyle::RequiresClausePositionStyle &
Value) {
685 IO.enumCase(
Value,
"OwnLine", FormatStyle::RCPS_OwnLine);
686 IO.enumCase(
Value,
"OwnLineWithBrace", FormatStyle::RCPS_OwnLineWithBrace);
687 IO.enumCase(
Value,
"WithPreceding", FormatStyle::RCPS_WithPreceding);
688 IO.enumCase(
Value,
"WithFollowing", FormatStyle::RCPS_WithFollowing);
689 IO.enumCase(
Value,
"SingleLine", FormatStyle::RCPS_SingleLine);
694struct ScalarEnumerationTraits<FormatStyle::RequiresExpressionIndentationKind> {
697 IO.enumCase(
Value,
"Keyword", FormatStyle::REI_Keyword);
698 IO.enumCase(
Value,
"OuterScope", FormatStyle::REI_OuterScope);
703struct ScalarEnumerationTraits<FormatStyle::ReturnTypeBreakingStyle> {
705 IO.enumCase(
Value,
"None", FormatStyle::RTBS_None);
706 IO.enumCase(
Value,
"Automatic", FormatStyle::RTBS_Automatic);
707 IO.enumCase(
Value,
"ExceptShortType", FormatStyle::RTBS_ExceptShortType);
708 IO.enumCase(
Value,
"All", FormatStyle::RTBS_All);
709 IO.enumCase(
Value,
"TopLevel", FormatStyle::RTBS_TopLevel);
710 IO.enumCase(
Value,
"TopLevelDefinitions",
711 FormatStyle::RTBS_TopLevelDefinitions);
712 IO.enumCase(
Value,
"AllDefinitions", FormatStyle::RTBS_AllDefinitions);
717struct ScalarEnumerationTraits<FormatStyle::SeparateDefinitionStyle> {
719 IO.enumCase(
Value,
"Leave", FormatStyle::SDS_Leave);
720 IO.enumCase(
Value,
"Always", FormatStyle::SDS_Always);
721 IO.enumCase(
Value,
"Never", FormatStyle::SDS_Never);
725template <>
struct ScalarEnumerationTraits<FormatStyle::ShortBlockStyle> {
727 IO.enumCase(
Value,
"Never", FormatStyle::SBS_Never);
728 IO.enumCase(
Value,
"false", FormatStyle::SBS_Never);
729 IO.enumCase(
Value,
"Always", FormatStyle::SBS_Always);
730 IO.enumCase(
Value,
"true", FormatStyle::SBS_Always);
731 IO.enumCase(
Value,
"Empty", FormatStyle::SBS_Empty);
735template <>
struct MappingTraits<FormatStyle::ShortFunctionStyle> {
737 IO.enumCase(
Value,
"None", FormatStyle::ShortFunctionStyle());
738 IO.enumCase(
Value,
"Empty",
739 FormatStyle::ShortFunctionStyle::setEmptyOnly());
740 IO.enumCase(
Value,
"Inline",
741 FormatStyle::ShortFunctionStyle::setEmptyAndInline());
742 IO.enumCase(
Value,
"InlineOnly",
743 FormatStyle::ShortFunctionStyle::setInlineOnly());
744 IO.enumCase(
Value,
"All", FormatStyle::ShortFunctionStyle::setAll());
747 IO.enumCase(
Value,
"true", FormatStyle::ShortFunctionStyle::setAll());
748 IO.enumCase(
Value,
"false", FormatStyle::ShortFunctionStyle());
752 IO.mapOptional(
"Empty",
Value.Empty);
753 IO.mapOptional(
"Inline",
Value.Inline);
754 IO.mapOptional(
"Other",
Value.Other);
758template <>
struct ScalarEnumerationTraits<FormatStyle::ShortIfStyle> {
760 IO.enumCase(
Value,
"Never", FormatStyle::SIS_Never);
761 IO.enumCase(
Value,
"WithoutElse", FormatStyle::SIS_WithoutElse);
762 IO.enumCase(
Value,
"OnlyFirstIf", FormatStyle::SIS_OnlyFirstIf);
763 IO.enumCase(
Value,
"AllIfsAndElse", FormatStyle::SIS_AllIfsAndElse);
766 IO.enumCase(
Value,
"Always", FormatStyle::SIS_OnlyFirstIf);
767 IO.enumCase(
Value,
"false", FormatStyle::SIS_Never);
768 IO.enumCase(
Value,
"true", FormatStyle::SIS_WithoutElse);
772template <>
struct ScalarEnumerationTraits<FormatStyle::ShortLambdaStyle> {
774 IO.enumCase(
Value,
"None", FormatStyle::SLS_None);
775 IO.enumCase(
Value,
"false", FormatStyle::SLS_None);
776 IO.enumCase(
Value,
"Empty", FormatStyle::SLS_Empty);
777 IO.enumCase(
Value,
"Inline", FormatStyle::SLS_Inline);
778 IO.enumCase(
Value,
"All", FormatStyle::SLS_All);
779 IO.enumCase(
Value,
"true", FormatStyle::SLS_All);
783template <>
struct ScalarEnumerationTraits<FormatStyle::ShortRecordStyle> {
785 IO.enumCase(
Value,
"Never", FormatStyle::SRS_Never);
786 IO.enumCase(
Value,
"EmptyAndAttached", FormatStyle::SRS_EmptyAndAttached);
787 IO.enumCase(
Value,
"Empty", FormatStyle::SRS_Empty);
788 IO.enumCase(
Value,
"Always", FormatStyle::SRS_Always);
792template <>
struct MappingTraits<FormatStyle::SortIncludesOptions> {
794 IO.enumCase(
Value,
"Never", FormatStyle::SortIncludesOptions{});
795 IO.enumCase(
Value,
"CaseInsensitive",
796 FormatStyle::SortIncludesOptions{
true,
799 IO.enumCase(
Value,
"CaseSensitive",
800 FormatStyle::SortIncludesOptions{
true,
805 IO.enumCase(
Value,
"false", FormatStyle::SortIncludesOptions{});
806 IO.enumCase(
Value,
"true",
807 FormatStyle::SortIncludesOptions{
true,
813 IO.mapOptional(
"Enabled",
Value.Enabled);
814 IO.mapOptional(
"IgnoreCase",
Value.IgnoreCase);
815 IO.mapOptional(
"IgnoreExtension",
Value.IgnoreExtension);
820struct ScalarEnumerationTraits<FormatStyle::SortJavaStaticImportOptions> {
822 FormatStyle::SortJavaStaticImportOptions &
Value) {
823 IO.enumCase(
Value,
"Before", FormatStyle::SJSIO_Before);
824 IO.enumCase(
Value,
"After", FormatStyle::SJSIO_After);
829struct ScalarEnumerationTraits<FormatStyle::SortUsingDeclarationsOptions> {
831 FormatStyle::SortUsingDeclarationsOptions &
Value) {
832 IO.enumCase(
Value,
"Never", FormatStyle::SUD_Never);
833 IO.enumCase(
Value,
"Lexicographic", FormatStyle::SUD_Lexicographic);
834 IO.enumCase(
Value,
"LexicographicNumeric",
835 FormatStyle::SUD_LexicographicNumeric);
838 IO.enumCase(
Value,
"false", FormatStyle::SUD_Never);
839 IO.enumCase(
Value,
"true", FormatStyle::SUD_LexicographicNumeric);
844struct ScalarEnumerationTraits<FormatStyle::SpaceAroundPointerQualifiersStyle> {
847 IO.enumCase(
Value,
"Default", FormatStyle::SAPQ_Default);
848 IO.enumCase(
Value,
"Before", FormatStyle::SAPQ_Before);
849 IO.enumCase(
Value,
"After", FormatStyle::SAPQ_After);
850 IO.enumCase(
Value,
"Both", FormatStyle::SAPQ_Both);
854template <>
struct MappingTraits<FormatStyle::SpaceBeforeParensCustom> {
855 static void mapping(IO &IO, FormatStyle::SpaceBeforeParensCustom &Spacing) {
856 IO.mapOptional(
"AfterControlStatements", Spacing.AfterControlStatements);
857 IO.mapOptional(
"AfterForeachMacros", Spacing.AfterForeachMacros);
858 IO.mapOptional(
"AfterFunctionDefinitionName",
859 Spacing.AfterFunctionDefinitionName);
860 IO.mapOptional(
"AfterFunctionDeclarationName",
861 Spacing.AfterFunctionDeclarationName);
862 IO.mapOptional(
"AfterIfMacros", Spacing.AfterIfMacros);
863 IO.mapOptional(
"AfterNot", Spacing.AfterNot);
864 IO.mapOptional(
"AfterOverloadedOperator", Spacing.AfterOverloadedOperator);
865 IO.mapOptional(
"AfterPlacementOperator", Spacing.AfterPlacementOperator);
866 IO.mapOptional(
"AfterRequiresInClause", Spacing.AfterRequiresInClause);
867 IO.mapOptional(
"AfterRequiresInExpression",
868 Spacing.AfterRequiresInExpression);
869 IO.mapOptional(
"BeforeNonEmptyParentheses",
870 Spacing.BeforeNonEmptyParentheses);
875struct ScalarEnumerationTraits<FormatStyle::SpaceBeforeParensStyle> {
877 IO.enumCase(
Value,
"Never", FormatStyle::SBPO_Never);
878 IO.enumCase(
Value,
"ControlStatements",
879 FormatStyle::SBPO_ControlStatements);
880 IO.enumCase(
Value,
"ControlStatementsExceptControlMacros",
881 FormatStyle::SBPO_ControlStatementsExceptControlMacros);
882 IO.enumCase(
Value,
"NonEmptyParentheses",
883 FormatStyle::SBPO_NonEmptyParentheses);
884 IO.enumCase(
Value,
"Always", FormatStyle::SBPO_Always);
885 IO.enumCase(
Value,
"Custom", FormatStyle::SBPO_Custom);
888 IO.enumCase(
Value,
"false", FormatStyle::SBPO_Never);
889 IO.enumCase(
Value,
"true", FormatStyle::SBPO_ControlStatements);
890 IO.enumCase(
Value,
"ControlStatementsExceptForEachMacros",
891 FormatStyle::SBPO_ControlStatementsExceptControlMacros);
896struct ScalarEnumerationTraits<FormatStyle::SpaceInEmptyBracesStyle> {
898 IO.enumCase(
Value,
"Always", FormatStyle::SIEB_Always);
899 IO.enumCase(
Value,
"Block", FormatStyle::SIEB_Block);
900 IO.enumCase(
Value,
"Never", FormatStyle::SIEB_Never);
904template <>
struct ScalarEnumerationTraits<FormatStyle::SpacesInAnglesStyle> {
906 IO.enumCase(
Value,
"Never", FormatStyle::SIAS_Never);
907 IO.enumCase(
Value,
"Always", FormatStyle::SIAS_Always);
908 IO.enumCase(
Value,
"Leave", FormatStyle::SIAS_Leave);
911 IO.enumCase(
Value,
"false", FormatStyle::SIAS_Never);
912 IO.enumCase(
Value,
"true", FormatStyle::SIAS_Always);
916template <>
struct MappingTraits<FormatStyle::SpacesInLineComment> {
917 static void mapping(IO &IO, FormatStyle::SpacesInLineComment &Space) {
919 int signedMaximum =
static_cast<int>(Space.Maximum);
920 IO.mapOptional(
"Minimum", Space.Minimum);
921 IO.mapOptional(
"Maximum", signedMaximum);
922 Space.Maximum =
static_cast<unsigned>(signedMaximum);
924 if (Space.Maximum < std::numeric_limits<unsigned>::max())
925 Space.Minimum = std::min(Space.Minimum, Space.Maximum);
929template <>
struct MappingTraits<FormatStyle::SpacesInParensCustom> {
930 static void mapping(IO &IO, FormatStyle::SpacesInParensCustom &Spaces) {
931 IO.mapOptional(
"ExceptDoubleParentheses", Spaces.ExceptDoubleParentheses);
932 IO.mapOptional(
"InCStyleCasts", Spaces.InCStyleCasts);
933 IO.mapOptional(
"InConditionalStatements", Spaces.InConditionalStatements);
934 IO.mapOptional(
"InEmptyParentheses", Spaces.InEmptyParentheses);
935 IO.mapOptional(
"Other", Spaces.Other);
939template <>
struct ScalarEnumerationTraits<FormatStyle::SpacesInParensStyle> {
941 IO.enumCase(
Value,
"Never", FormatStyle::SIPO_Never);
942 IO.enumCase(
Value,
"Custom", FormatStyle::SIPO_Custom);
946template <>
struct ScalarEnumerationTraits<FormatStyle::TrailingCommaStyle> {
948 IO.enumCase(
Value,
"None", FormatStyle::TCS_None);
949 IO.enumCase(
Value,
"Wrapped", FormatStyle::TCS_Wrapped);
954struct ScalarEnumerationTraits<FormatStyle::TrailingCommentsAlignmentKinds> {
956 FormatStyle::TrailingCommentsAlignmentKinds &
Value) {
957 IO.enumCase(
Value,
"Leave", FormatStyle::TCAS_Leave);
958 IO.enumCase(
Value,
"Always", FormatStyle::TCAS_Always);
959 IO.enumCase(
Value,
"Never", FormatStyle::TCAS_Never);
963template <>
struct MappingTraits<FormatStyle::TrailingCommentsAlignmentStyle> {
965 FormatStyle::TrailingCommentsAlignmentStyle &
Value) {
966 IO.enumCase(
Value,
"Leave",
967 FormatStyle::TrailingCommentsAlignmentStyle(
968 {FormatStyle::TCAS_Leave, 0,
true}));
970 IO.enumCase(
Value,
"Always",
971 FormatStyle::TrailingCommentsAlignmentStyle(
972 {FormatStyle::TCAS_Always, 0,
true}));
974 IO.enumCase(
Value,
"Never",
975 FormatStyle::TrailingCommentsAlignmentStyle(
976 {FormatStyle::TCAS_Never, 0,
true}));
979 IO.enumCase(
Value,
"true",
980 FormatStyle::TrailingCommentsAlignmentStyle(
981 {FormatStyle::TCAS_Always, 0,
true}));
982 IO.enumCase(
Value,
"false",
983 FormatStyle::TrailingCommentsAlignmentStyle(
984 {FormatStyle::TCAS_Never, 0,
true}));
988 FormatStyle::TrailingCommentsAlignmentStyle &
Value) {
989 IO.mapOptional(
"AlignPPAndNotPP",
Value.AlignPPAndNotPP);
990 IO.mapOptional(
"Kind",
Value.Kind);
991 IO.mapOptional(
"OverEmptyLines",
Value.OverEmptyLines);
995template <>
struct ScalarEnumerationTraits<FormatStyle::UseTabStyle> {
997 IO.enumCase(
Value,
"Never", FormatStyle::UT_Never);
998 IO.enumCase(
Value,
"false", FormatStyle::UT_Never);
999 IO.enumCase(
Value,
"Always", FormatStyle::UT_Always);
1000 IO.enumCase(
Value,
"true", FormatStyle::UT_Always);
1001 IO.enumCase(
Value,
"ForIndentation", FormatStyle::UT_ForIndentation);
1002 IO.enumCase(
Value,
"ForContinuationAndIndentation",
1003 FormatStyle::UT_ForContinuationAndIndentation);
1004 IO.enumCase(
Value,
"AlignWithSpaces", FormatStyle::UT_AlignWithSpaces);
1009struct ScalarEnumerationTraits<
1010 FormatStyle::WrapNamespaceBodyWithEmptyLinesStyle> {
1013 FormatStyle::WrapNamespaceBodyWithEmptyLinesStyle &
Value) {
1014 IO.enumCase(
Value,
"Never", FormatStyle::WNBWELS_Never);
1015 IO.enumCase(
Value,
"Always", FormatStyle::WNBWELS_Always);
1016 IO.enumCase(
Value,
"Leave", FormatStyle::WNBWELS_Leave);
1020template <>
struct MappingTraits<FormatStyle> {
1023 IO.mapOptional(
"Language", Style.Language);
1025 StringRef BasedOnStyle;
1026 if (IO.outputting()) {
1027 StringRef Styles[] = {
"LLVM",
"Google",
"Chromium",
"Mozilla",
1028 "WebKit",
"GNU",
"Microsoft",
"clang-format"};
1029 for (StringRef StyleName : Styles) {
1030 FormatStyle PredefinedStyle;
1032 Style == PredefinedStyle) {
1033 BasedOnStyle = StyleName;
1038 IO.mapOptional(
"BasedOnStyle", BasedOnStyle);
1039 if (!BasedOnStyle.empty()) {
1040 FormatStyle::LanguageKind OldLanguage = Style.Language;
1041 FormatStyle::LanguageKind Language =
1042 ((FormatStyle *)IO.getContext())->Language;
1044 IO.setError(Twine(
"Unknown value for BasedOnStyle: ", BasedOnStyle));
1047 Style.Language = OldLanguage;
1062 const bool IsGoogleOrChromium = BasedOnStyle.equals_insensitive(
"google") ||
1063 BasedOnStyle.equals_insensitive(
"chromium");
1064 bool OnCurrentLine = IsGoogleOrChromium;
1065 bool OnNextLine =
true;
1067 bool BreakBeforeInheritanceComma =
false;
1068 bool BreakConstructorInitializersBeforeComma =
false;
1070 bool DeriveLineEnding =
true;
1071 bool UseCRLF =
false;
1073 bool SpaceInEmptyBlock =
false;
1074 bool SpaceInEmptyParentheses =
false;
1075 bool SpacesInConditionalStatement =
false;
1076 bool SpacesInCStyleCastParentheses =
false;
1077 bool SpacesInParentheses =
false;
1079 if (IO.outputting()) {
1080 IO.mapOptional(
"AlignAfterOpenBracket", Style.AlignAfterOpenBracket);
1084 if (IsGoogleOrChromium) {
1085 FormatStyle::LanguageKind Language = Style.Language;
1086 if (Language == FormatStyle::LK_None)
1087 Language = ((FormatStyle *)IO.getContext())->Language;
1088 if (Language == FormatStyle::LK_JavaScript)
1090 else if (Language == FormatStyle::LK_Java)
1092 }
else if (BasedOnStyle.equals_insensitive(
"webkit")) {
1095 IO.mapOptional(
"AlignAfterOpenBracket", LocalBAS);
1096 Style.BreakAfterOpenBracketBracedList =
false;
1097 Style.BreakAfterOpenBracketFunction =
false;
1098 Style.BreakAfterOpenBracketIf =
false;
1099 Style.BreakAfterOpenBracketLoop =
false;
1100 Style.BreakAfterOpenBracketSwitch =
false;
1101 Style.BreakBeforeCloseBracketBracedList =
false;
1102 Style.BreakBeforeCloseBracketFunction =
false;
1103 Style.BreakBeforeCloseBracketIf =
false;
1104 Style.BreakBeforeCloseBracketLoop =
false;
1105 Style.BreakBeforeCloseBracketSwitch =
false;
1109 Style.AlignAfterOpenBracket =
false;
1112 Style.BreakBeforeCloseBracketBracedList =
true;
1113 Style.BreakBeforeCloseBracketFunction =
true;
1114 Style.BreakBeforeCloseBracketIf =
true;
1117 Style.BreakAfterOpenBracketBracedList =
true;
1118 Style.BreakAfterOpenBracketFunction =
true;
1119 Style.BreakAfterOpenBracketIf =
true;
1122 Style.AlignAfterOpenBracket =
true;
1128 if (!IO.outputting()) {
1129 IO.mapOptional(
"AlignEscapedNewlinesLeft", Style.AlignEscapedNewlines);
1130 IO.mapOptional(
"AllowAllConstructorInitializersOnNextLine", OnNextLine);
1131 IO.mapOptional(
"AlwaysBreakAfterReturnType", Style.BreakAfterReturnType);
1132 IO.mapOptional(
"AlwaysBreakTemplateDeclarations",
1133 Style.BreakTemplateDeclarations);
1134 IO.mapOptional(
"BreakBeforeInheritanceComma",
1135 BreakBeforeInheritanceComma);
1136 IO.mapOptional(
"BreakConstructorInitializersBeforeComma",
1137 BreakConstructorInitializersBeforeComma);
1138 IO.mapOptional(
"ConstructorInitializerAllOnOneLineOrOnePerLine",
1140 IO.mapOptional(
"DeriveLineEnding", DeriveLineEnding);
1141 IO.mapOptional(
"DerivePointerBinding", Style.DerivePointerAlignment);
1142 IO.mapOptional(
"KeepEmptyLinesAtEOF", Style.KeepEmptyLines.AtEndOfFile);
1143 IO.mapOptional(
"KeepEmptyLinesAtTheStartOfBlocks",
1144 Style.KeepEmptyLines.AtStartOfBlock);
1145 IO.mapOptional(
"IndentFunctionDeclarationAfterType",
1146 Style.IndentWrappedFunctionNames);
1147 IO.mapOptional(
"IndentRequires", Style.IndentRequiresClause);
1148 IO.mapOptional(
"PointerBindsToType", Style.PointerAlignment);
1149 IO.mapOptional(
"SpaceAfterControlStatementKeyword",
1150 Style.SpaceBeforeParens);
1151 IO.mapOptional(
"SpaceInEmptyBlock", SpaceInEmptyBlock);
1152 IO.mapOptional(
"SpaceInEmptyParentheses", SpaceInEmptyParentheses);
1153 IO.mapOptional(
"SpacesInConditionalStatement",
1154 SpacesInConditionalStatement);
1155 IO.mapOptional(
"SpacesInCStyleCastParentheses",
1156 SpacesInCStyleCastParentheses);
1157 IO.mapOptional(
"SpacesInParentheses", SpacesInParentheses);
1158 IO.mapOptional(
"UseCRLF", UseCRLF);
1161 IO.mapOptional(
"AccessModifierOffset", Style.AccessModifierOffset);
1162 IO.mapOptional(
"AlignArrayOfStructures", Style.AlignArrayOfStructures);
1163 IO.mapOptional(
"AlignConsecutiveAssignments",
1164 Style.AlignConsecutiveAssignments);
1165 IO.mapOptional(
"AlignConsecutiveBitFields",
1166 Style.AlignConsecutiveBitFields);
1167 IO.mapOptional(
"AlignConsecutiveDeclarations",
1168 Style.AlignConsecutiveDeclarations);
1169 IO.mapOptional(
"AlignConsecutiveMacros", Style.AlignConsecutiveMacros);
1170 IO.mapOptional(
"AlignConsecutiveShortCaseStatements",
1171 Style.AlignConsecutiveShortCaseStatements);
1172 IO.mapOptional(
"AlignConsecutiveTableGenBreakingDAGArgColons",
1173 Style.AlignConsecutiveTableGenBreakingDAGArgColons);
1174 IO.mapOptional(
"AlignConsecutiveTableGenCondOperatorColons",
1175 Style.AlignConsecutiveTableGenCondOperatorColons);
1176 IO.mapOptional(
"AlignConsecutiveTableGenDefinitionColons",
1177 Style.AlignConsecutiveTableGenDefinitionColons);
1178 IO.mapOptional(
"AlignEscapedNewlines", Style.AlignEscapedNewlines);
1179 IO.mapOptional(
"AlignOperands", Style.AlignOperands);
1180 IO.mapOptional(
"AlignTrailingComments", Style.AlignTrailingComments);
1181 IO.mapOptional(
"AllowAllArgumentsOnNextLine",
1182 Style.AllowAllArgumentsOnNextLine);
1183 IO.mapOptional(
"AllowAllParametersOfDeclarationOnNextLine",
1184 Style.AllowAllParametersOfDeclarationOnNextLine);
1185 IO.mapOptional(
"AllowBreakBeforeNoexceptSpecifier",
1186 Style.AllowBreakBeforeNoexceptSpecifier);
1187 IO.mapOptional(
"AllowBreakBeforeQtProperty",
1188 Style.AllowBreakBeforeQtProperty);
1189 IO.mapOptional(
"AllowShortBlocksOnASingleLine",
1190 Style.AllowShortBlocksOnASingleLine);
1191 IO.mapOptional(
"AllowShortCaseExpressionOnASingleLine",
1192 Style.AllowShortCaseExpressionOnASingleLine);
1193 IO.mapOptional(
"AllowShortCaseLabelsOnASingleLine",
1194 Style.AllowShortCaseLabelsOnASingleLine);
1195 IO.mapOptional(
"AllowShortCompoundRequirementOnASingleLine",
1196 Style.AllowShortCompoundRequirementOnASingleLine);
1197 IO.mapOptional(
"AllowShortEnumsOnASingleLine",
1198 Style.AllowShortEnumsOnASingleLine);
1199 IO.mapOptional(
"AllowShortFunctionsOnASingleLine",
1200 Style.AllowShortFunctionsOnASingleLine);
1201 IO.mapOptional(
"AllowShortIfStatementsOnASingleLine",
1202 Style.AllowShortIfStatementsOnASingleLine);
1203 IO.mapOptional(
"AllowShortLambdasOnASingleLine",
1204 Style.AllowShortLambdasOnASingleLine);
1205 IO.mapOptional(
"AllowShortLoopsOnASingleLine",
1206 Style.AllowShortLoopsOnASingleLine);
1207 IO.mapOptional(
"AllowShortNamespacesOnASingleLine",
1208 Style.AllowShortNamespacesOnASingleLine);
1209 IO.mapOptional(
"AllowShortRecordOnASingleLine",
1210 Style.AllowShortRecordOnASingleLine);
1211 IO.mapOptional(
"AlwaysBreakAfterDefinitionReturnType",
1212 Style.AlwaysBreakAfterDefinitionReturnType);
1213 IO.mapOptional(
"AlwaysBreakBeforeMultilineStrings",
1214 Style.AlwaysBreakBeforeMultilineStrings);
1215 IO.mapOptional(
"AttributeMacros", Style.AttributeMacros);
1216 IO.mapOptional(
"BinPackArguments", Style.BinPackArguments);
1217 IO.mapOptional(
"BinPackLongBracedList", Style.BinPackLongBracedList);
1218 IO.mapOptional(
"BinPackParameters", Style.BinPackParameters);
1219 IO.mapOptional(
"BitFieldColonSpacing", Style.BitFieldColonSpacing);
1220 IO.mapOptional(
"BracedInitializerIndentWidth",
1221 Style.BracedInitializerIndentWidth);
1222 IO.mapOptional(
"BraceWrapping", Style.BraceWrapping);
1223 IO.mapOptional(
"BreakAdjacentStringLiterals",
1224 Style.BreakAdjacentStringLiterals);
1225 IO.mapOptional(
"BreakAfterAttributes", Style.BreakAfterAttributes);
1226 IO.mapOptional(
"BreakAfterJavaFieldAnnotations",
1227 Style.BreakAfterJavaFieldAnnotations);
1228 IO.mapOptional(
"BreakAfterOpenBracketBracedList",
1229 Style.BreakAfterOpenBracketBracedList);
1230 IO.mapOptional(
"BreakAfterOpenBracketFunction",
1231 Style.BreakAfterOpenBracketFunction);
1232 IO.mapOptional(
"BreakAfterOpenBracketIf", Style.BreakAfterOpenBracketIf);
1233 IO.mapOptional(
"BreakAfterOpenBracketLoop",
1234 Style.BreakAfterOpenBracketLoop);
1235 IO.mapOptional(
"BreakAfterOpenBracketSwitch",
1236 Style.BreakAfterOpenBracketSwitch);
1237 IO.mapOptional(
"BreakAfterReturnType", Style.BreakAfterReturnType);
1238 IO.mapOptional(
"BreakArrays", Style.BreakArrays);
1239 IO.mapOptional(
"BreakBeforeBinaryOperators",
1240 Style.BreakBeforeBinaryOperators);
1241 IO.mapOptional(
"BreakBeforeCloseBracketBracedList",
1242 Style.BreakBeforeCloseBracketBracedList);
1243 IO.mapOptional(
"BreakBeforeCloseBracketFunction",
1244 Style.BreakBeforeCloseBracketFunction);
1245 IO.mapOptional(
"BreakBeforeCloseBracketIf",
1246 Style.BreakBeforeCloseBracketIf);
1247 IO.mapOptional(
"BreakBeforeCloseBracketLoop",
1248 Style.BreakBeforeCloseBracketLoop);
1249 IO.mapOptional(
"BreakBeforeCloseBracketSwitch",
1250 Style.BreakBeforeCloseBracketSwitch);
1251 IO.mapOptional(
"BreakBeforeConceptDeclarations",
1252 Style.BreakBeforeConceptDeclarations);
1253 IO.mapOptional(
"BreakBeforeBraces", Style.BreakBeforeBraces);
1254 IO.mapOptional(
"BreakBeforeInlineASMColon",
1255 Style.BreakBeforeInlineASMColon);
1256 IO.mapOptional(
"BreakBeforeTemplateCloser",
1257 Style.BreakBeforeTemplateCloser);
1258 IO.mapOptional(
"BreakBeforeTernaryOperators",
1259 Style.BreakBeforeTernaryOperators);
1260 IO.mapOptional(
"BreakBinaryOperations", Style.BreakBinaryOperations);
1261 IO.mapOptional(
"BreakConstructorInitializers",
1262 Style.BreakConstructorInitializers);
1263 IO.mapOptional(
"BreakFunctionDefinitionParameters",
1264 Style.BreakFunctionDefinitionParameters);
1265 IO.mapOptional(
"BreakInheritanceList", Style.BreakInheritanceList);
1266 IO.mapOptional(
"BreakStringLiterals", Style.BreakStringLiterals);
1267 IO.mapOptional(
"BreakTemplateDeclarations",
1268 Style.BreakTemplateDeclarations);
1269 IO.mapOptional(
"ColumnLimit", Style.ColumnLimit);
1270 IO.mapOptional(
"CommentPragmas", Style.CommentPragmas);
1271 IO.mapOptional(
"CompactNamespaces", Style.CompactNamespaces);
1272 IO.mapOptional(
"ConstructorInitializerIndentWidth",
1273 Style.ConstructorInitializerIndentWidth);
1274 IO.mapOptional(
"ContinuationIndentWidth", Style.ContinuationIndentWidth);
1275 IO.mapOptional(
"Cpp11BracedListStyle", Style.Cpp11BracedListStyle);
1276 IO.mapOptional(
"DerivePointerAlignment", Style.DerivePointerAlignment);
1277 IO.mapOptional(
"DisableFormat", Style.DisableFormat);
1278 IO.mapOptional(
"EmptyLineAfterAccessModifier",
1279 Style.EmptyLineAfterAccessModifier);
1280 IO.mapOptional(
"EmptyLineBeforeAccessModifier",
1281 Style.EmptyLineBeforeAccessModifier);
1282 IO.mapOptional(
"EnumTrailingComma", Style.EnumTrailingComma);
1283 IO.mapOptional(
"ExperimentalAutoDetectBinPacking",
1284 Style.ExperimentalAutoDetectBinPacking);
1285 IO.mapOptional(
"FixNamespaceComments", Style.FixNamespaceComments);
1286 IO.mapOptional(
"ForEachMacros", Style.ForEachMacros);
1287 IO.mapOptional(
"IfMacros", Style.IfMacros);
1288 IO.mapOptional(
"IncludeBlocks", Style.IncludeStyle.IncludeBlocks);
1289 IO.mapOptional(
"IncludeCategories", Style.IncludeStyle.IncludeCategories);
1290 IO.mapOptional(
"IncludeIsMainRegex", Style.IncludeStyle.IncludeIsMainRegex);
1291 IO.mapOptional(
"IncludeIsMainSourceRegex",
1292 Style.IncludeStyle.IncludeIsMainSourceRegex);
1293 IO.mapOptional(
"IndentAccessModifiers", Style.IndentAccessModifiers);
1294 IO.mapOptional(
"IndentCaseBlocks", Style.IndentCaseBlocks);
1295 IO.mapOptional(
"IndentCaseLabels", Style.IndentCaseLabels);
1296 IO.mapOptional(
"IndentExportBlock", Style.IndentExportBlock);
1297 IO.mapOptional(
"IndentExternBlock", Style.IndentExternBlock);
1298 IO.mapOptional(
"IndentGotoLabels", Style.IndentGotoLabels);
1299 IO.mapOptional(
"IndentPPDirectives", Style.IndentPPDirectives);
1300 IO.mapOptional(
"IndentRequiresClause", Style.IndentRequiresClause);
1301 IO.mapOptional(
"IndentWidth", Style.IndentWidth);
1302 IO.mapOptional(
"IndentWrappedFunctionNames",
1303 Style.IndentWrappedFunctionNames);
1304 IO.mapOptional(
"InsertBraces", Style.InsertBraces);
1305 IO.mapOptional(
"InsertNewlineAtEOF", Style.InsertNewlineAtEOF);
1306 IO.mapOptional(
"InsertTrailingCommas", Style.InsertTrailingCommas);
1307 IO.mapOptional(
"IntegerLiteralSeparator", Style.IntegerLiteralSeparator);
1308 IO.mapOptional(
"JavaImportGroups", Style.JavaImportGroups);
1309 IO.mapOptional(
"JavaScriptQuotes", Style.JavaScriptQuotes);
1310 IO.mapOptional(
"JavaScriptWrapImports", Style.JavaScriptWrapImports);
1311 IO.mapOptional(
"KeepEmptyLines", Style.KeepEmptyLines);
1312 IO.mapOptional(
"KeepFormFeed", Style.KeepFormFeed);
1313 IO.mapOptional(
"LambdaBodyIndentation", Style.LambdaBodyIndentation);
1314 IO.mapOptional(
"LineEnding", Style.LineEnding);
1315 IO.mapOptional(
"MacroBlockBegin", Style.MacroBlockBegin);
1316 IO.mapOptional(
"MacroBlockEnd", Style.MacroBlockEnd);
1317 IO.mapOptional(
"Macros", Style.Macros);
1318 IO.mapOptional(
"MacrosSkippedByRemoveParentheses",
1319 Style.MacrosSkippedByRemoveParentheses);
1320 IO.mapOptional(
"MainIncludeChar", Style.IncludeStyle.MainIncludeChar);
1321 IO.mapOptional(
"MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
1322 IO.mapOptional(
"NamespaceIndentation", Style.NamespaceIndentation);
1323 IO.mapOptional(
"NamespaceMacros", Style.NamespaceMacros);
1324 IO.mapOptional(
"NumericLiteralCase", Style.NumericLiteralCase);
1325 IO.mapOptional(
"ObjCBinPackProtocolList", Style.ObjCBinPackProtocolList);
1326 IO.mapOptional(
"ObjCBlockIndentWidth", Style.ObjCBlockIndentWidth);
1327 IO.mapOptional(
"ObjCBreakBeforeNestedBlockParam",
1328 Style.ObjCBreakBeforeNestedBlockParam);
1329 IO.mapOptional(
"ObjCPropertyAttributeOrder",
1330 Style.ObjCPropertyAttributeOrder);
1331 IO.mapOptional(
"ObjCSpaceAfterMethodDeclarationPrefix",
1332 Style.ObjCSpaceAfterMethodDeclarationPrefix);
1333 IO.mapOptional(
"ObjCSpaceAfterProperty", Style.ObjCSpaceAfterProperty);
1334 IO.mapOptional(
"ObjCSpaceBeforeProtocolList",
1335 Style.ObjCSpaceBeforeProtocolList);
1336 IO.mapOptional(
"OneLineFormatOffRegex", Style.OneLineFormatOffRegex);
1337 IO.mapOptional(
"PackConstructorInitializers",
1338 Style.PackConstructorInitializers);
1339 IO.mapOptional(
"PenaltyBreakAssignment", Style.PenaltyBreakAssignment);
1340 IO.mapOptional(
"PenaltyBreakBeforeFirstCallParameter",
1341 Style.PenaltyBreakBeforeFirstCallParameter);
1342 IO.mapOptional(
"PenaltyBreakBeforeMemberAccess",
1343 Style.PenaltyBreakBeforeMemberAccess);
1344 IO.mapOptional(
"PenaltyBreakComment", Style.PenaltyBreakComment);
1345 IO.mapOptional(
"PenaltyBreakFirstLessLess",
1346 Style.PenaltyBreakFirstLessLess);
1347 IO.mapOptional(
"PenaltyBreakOpenParenthesis",
1348 Style.PenaltyBreakOpenParenthesis);
1349 IO.mapOptional(
"PenaltyBreakScopeResolution",
1350 Style.PenaltyBreakScopeResolution);
1351 IO.mapOptional(
"PenaltyBreakString", Style.PenaltyBreakString);
1352 IO.mapOptional(
"PenaltyBreakTemplateDeclaration",
1353 Style.PenaltyBreakTemplateDeclaration);
1354 IO.mapOptional(
"PenaltyExcessCharacter", Style.PenaltyExcessCharacter);
1355 IO.mapOptional(
"PenaltyIndentedWhitespace",
1356 Style.PenaltyIndentedWhitespace);
1357 IO.mapOptional(
"PenaltyReturnTypeOnItsOwnLine",
1358 Style.PenaltyReturnTypeOnItsOwnLine);
1359 IO.mapOptional(
"PointerAlignment", Style.PointerAlignment);
1360 IO.mapOptional(
"PPIndentWidth", Style.PPIndentWidth);
1361 IO.mapOptional(
"QualifierAlignment", Style.QualifierAlignment);
1363 if (Style.QualifierAlignment == FormatStyle::QAS_Right)
1364 Style.QualifierOrder = {
"type",
"const",
"volatile"};
1365 else if (Style.QualifierAlignment == FormatStyle::QAS_Left)
1366 Style.QualifierOrder = {
"const",
"volatile",
"type"};
1367 else if (Style.QualifierAlignment == FormatStyle::QAS_Custom)
1368 IO.mapOptional(
"QualifierOrder", Style.QualifierOrder);
1369 IO.mapOptional(
"RawStringFormats", Style.RawStringFormats);
1370 IO.mapOptional(
"ReferenceAlignment", Style.ReferenceAlignment);
1371 IO.mapOptional(
"ReflowComments", Style.ReflowComments);
1372 IO.mapOptional(
"RemoveBracesLLVM", Style.RemoveBracesLLVM);
1373 IO.mapOptional(
"RemoveEmptyLinesInUnwrappedLines",
1374 Style.RemoveEmptyLinesInUnwrappedLines);
1375 IO.mapOptional(
"RemoveParentheses", Style.RemoveParentheses);
1376 IO.mapOptional(
"RemoveSemicolon", Style.RemoveSemicolon);
1377 IO.mapOptional(
"RequiresClausePosition", Style.RequiresClausePosition);
1378 IO.mapOptional(
"RequiresExpressionIndentation",
1379 Style.RequiresExpressionIndentation);
1380 IO.mapOptional(
"SeparateDefinitionBlocks", Style.SeparateDefinitionBlocks);
1381 IO.mapOptional(
"ShortNamespaceLines", Style.ShortNamespaceLines);
1382 IO.mapOptional(
"SkipMacroDefinitionBody", Style.SkipMacroDefinitionBody);
1383 IO.mapOptional(
"SortIncludes", Style.SortIncludes);
1384 IO.mapOptional(
"SortJavaStaticImport", Style.SortJavaStaticImport);
1385 IO.mapOptional(
"SortUsingDeclarations", Style.SortUsingDeclarations);
1386 IO.mapOptional(
"SpaceAfterCStyleCast", Style.SpaceAfterCStyleCast);
1387 IO.mapOptional(
"SpaceAfterLogicalNot", Style.SpaceAfterLogicalNot);
1388 IO.mapOptional(
"SpaceAfterOperatorKeyword",
1389 Style.SpaceAfterOperatorKeyword);
1390 IO.mapOptional(
"SpaceAfterTemplateKeyword",
1391 Style.SpaceAfterTemplateKeyword);
1392 IO.mapOptional(
"SpaceAroundPointerQualifiers",
1393 Style.SpaceAroundPointerQualifiers);
1394 IO.mapOptional(
"SpaceBeforeAssignmentOperators",
1395 Style.SpaceBeforeAssignmentOperators);
1396 IO.mapOptional(
"SpaceBeforeCaseColon", Style.SpaceBeforeCaseColon);
1397 IO.mapOptional(
"SpaceBeforeCpp11BracedList",
1398 Style.SpaceBeforeCpp11BracedList);
1399 IO.mapOptional(
"SpaceBeforeCtorInitializerColon",
1400 Style.SpaceBeforeCtorInitializerColon);
1401 IO.mapOptional(
"SpaceBeforeInheritanceColon",
1402 Style.SpaceBeforeInheritanceColon);
1403 IO.mapOptional(
"SpaceBeforeJsonColon", Style.SpaceBeforeJsonColon);
1404 IO.mapOptional(
"SpaceBeforeParens", Style.SpaceBeforeParens);
1405 IO.mapOptional(
"SpaceBeforeParensOptions", Style.SpaceBeforeParensOptions);
1406 IO.mapOptional(
"SpaceBeforeRangeBasedForLoopColon",
1407 Style.SpaceBeforeRangeBasedForLoopColon);
1408 IO.mapOptional(
"SpaceBeforeSquareBrackets",
1409 Style.SpaceBeforeSquareBrackets);
1410 IO.mapOptional(
"SpaceInEmptyBraces", Style.SpaceInEmptyBraces);
1411 IO.mapOptional(
"SpacesBeforeTrailingComments",
1412 Style.SpacesBeforeTrailingComments);
1413 IO.mapOptional(
"SpacesInAngles", Style.SpacesInAngles);
1414 IO.mapOptional(
"SpacesInContainerLiterals",
1415 Style.SpacesInContainerLiterals);
1416 IO.mapOptional(
"SpacesInLineCommentPrefix",
1417 Style.SpacesInLineCommentPrefix);
1418 IO.mapOptional(
"SpacesInParens", Style.SpacesInParens);
1419 IO.mapOptional(
"SpacesInParensOptions", Style.SpacesInParensOptions);
1420 IO.mapOptional(
"SpacesInSquareBrackets", Style.SpacesInSquareBrackets);
1421 IO.mapOptional(
"Standard", Style.Standard);
1422 IO.mapOptional(
"StatementAttributeLikeMacros",
1423 Style.StatementAttributeLikeMacros);
1424 IO.mapOptional(
"StatementMacros", Style.StatementMacros);
1425 IO.mapOptional(
"TableGenBreakingDAGArgOperators",
1426 Style.TableGenBreakingDAGArgOperators);
1427 IO.mapOptional(
"TableGenBreakInsideDAGArg",
1428 Style.TableGenBreakInsideDAGArg);
1429 IO.mapOptional(
"TabWidth", Style.TabWidth);
1430 IO.mapOptional(
"TemplateNames", Style.TemplateNames);
1431 IO.mapOptional(
"TypeNames", Style.TypeNames);
1432 IO.mapOptional(
"TypenameMacros", Style.TypenameMacros);
1433 IO.mapOptional(
"UseTab", Style.UseTab);
1434 IO.mapOptional(
"VariableTemplates", Style.VariableTemplates);
1435 IO.mapOptional(
"VerilogBreakBetweenInstancePorts",
1436 Style.VerilogBreakBetweenInstancePorts);
1437 IO.mapOptional(
"WhitespaceSensitiveMacros",
1438 Style.WhitespaceSensitiveMacros);
1439 IO.mapOptional(
"WrapNamespaceBodyWithEmptyLines",
1440 Style.WrapNamespaceBodyWithEmptyLines);
1445 if (Style.AlwaysBreakAfterDefinitionReturnType != FormatStyle::DRTBS_None &&
1446 Style.BreakAfterReturnType == FormatStyle::RTBS_None) {
1447 if (Style.AlwaysBreakAfterDefinitionReturnType ==
1448 FormatStyle::DRTBS_All) {
1449 Style.BreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
1450 }
else if (Style.AlwaysBreakAfterDefinitionReturnType ==
1451 FormatStyle::DRTBS_TopLevel) {
1452 Style.BreakAfterReturnType = FormatStyle::RTBS_TopLevelDefinitions;
1458 if (BreakBeforeInheritanceComma &&
1459 Style.BreakInheritanceList == FormatStyle::BILS_BeforeColon) {
1460 Style.BreakInheritanceList = FormatStyle::BILS_BeforeComma;
1466 if (BreakConstructorInitializersBeforeComma &&
1467 Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeColon) {
1468 Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;
1471 if (!IsGoogleOrChromium) {
1472 if (Style.PackConstructorInitializers == FormatStyle::PCIS_BinPack &&
1474 Style.PackConstructorInitializers = OnNextLine
1475 ? FormatStyle::PCIS_NextLine
1476 : FormatStyle::PCIS_CurrentLine;
1478 }
else if (Style.PackConstructorInitializers ==
1479 FormatStyle::PCIS_NextLine) {
1481 Style.PackConstructorInitializers = FormatStyle::PCIS_BinPack;
1482 else if (!OnNextLine)
1483 Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
1486 if (Style.LineEnding == FormatStyle::LE_DeriveLF) {
1487 if (!DeriveLineEnding)
1488 Style.LineEnding = UseCRLF ? FormatStyle::LE_CRLF : FormatStyle::LE_LF;
1490 Style.LineEnding = FormatStyle::LE_DeriveCRLF;
1495 if (SpaceInEmptyBlock &&
1496 Style.SpaceInEmptyBraces == FormatStyle::SIEB_Never) {
1497 Style.SpaceInEmptyBraces = FormatStyle::SIEB_Block;
1500 if (Style.SpacesInParens != FormatStyle::SIPO_Custom &&
1501 (SpacesInParentheses || SpaceInEmptyParentheses ||
1502 SpacesInConditionalStatement || SpacesInCStyleCastParentheses)) {
1503 if (SpacesInParentheses) {
1505 Style.SpacesInParensOptions.ExceptDoubleParentheses =
false;
1506 Style.SpacesInParensOptions.InConditionalStatements =
true;
1507 Style.SpacesInParensOptions.InCStyleCasts =
1508 SpacesInCStyleCastParentheses;
1509 Style.SpacesInParensOptions.InEmptyParentheses =
1510 SpaceInEmptyParentheses;
1511 Style.SpacesInParensOptions.Other =
true;
1513 Style.SpacesInParensOptions = {};
1514 Style.SpacesInParensOptions.InConditionalStatements =
1515 SpacesInConditionalStatement;
1516 Style.SpacesInParensOptions.InCStyleCasts =
1517 SpacesInCStyleCastParentheses;
1518 Style.SpacesInParensOptions.InEmptyParentheses =
1519 SpaceInEmptyParentheses;
1521 Style.SpacesInParens = FormatStyle::SIPO_Custom;
1531template <>
struct DocumentListTraits<
std::vector<FormatStyle>> {
1532 static size_t size(IO &IO, std::vector<FormatStyle> &Seq) {
1535 static FormatStyle &
element(IO &IO, std::vector<FormatStyle> &Seq,
1537 if (Index >= Seq.size()) {
1538 assert(Index == Seq.size());
1539 FormatStyle Template;
1540 if (!Seq.empty() && Seq[0].Language == FormatStyle::LK_None) {
1543 Template = *((
const FormatStyle *)IO.getContext());
1544 Template.Language = FormatStyle::LK_None;
1546 Seq.resize(Index + 1, Template);
1552template <>
struct ScalarEnumerationTraits<FormatStyle::IndentGotoLabelStyle> {
1554 IO.enumCase(
Value,
"NoIndent", FormatStyle::IGLS_NoIndent);
1555 IO.enumCase(
Value,
"OuterIndent", FormatStyle::IGLS_OuterIndent);
1556 IO.enumCase(
Value,
"InnerIndent", FormatStyle::IGLS_InnerIndent);
1557 IO.enumCase(
Value,
"HalfIndent", FormatStyle::IGLS_HalfIndent);
1560 IO.enumCase(
Value,
"false", FormatStyle::IGLS_NoIndent);
1561 IO.enumCase(
Value,
"true", FormatStyle::IGLS_OuterIndent);
1580 return llvm::make_error<llvm::StringError>(Message,
1581 llvm::inconvertibleErrorCode());
1585 return "clang-format.parse_error";
1593 return "Invalid argument";
1595 return "Unsuitable";
1597 return "trailing comma insertion cannot be used with bin packing";
1599 return "Invalid qualifier specified in QualifierOrder";
1601 return "Duplicate qualifier specified in QualifierOrder";
1603 return "Missing type in QualifierOrder";
1605 return "Missing QualifierOrder";
1607 llvm_unreachable(
"unexpected parse error");
1611 if (Expanded.BreakBeforeBraces == FormatStyle::BS_Custom)
1613 Expanded.BraceWrapping = {
false,
1615 FormatStyle::BWACS_Never,
1631 switch (Expanded.BreakBeforeBraces) {
1632 case FormatStyle::BS_Linux:
1633 Expanded.BraceWrapping.AfterClass =
true;
1634 Expanded.BraceWrapping.AfterFunction =
true;
1635 Expanded.BraceWrapping.AfterNamespace =
true;
1637 case FormatStyle::BS_Mozilla:
1638 Expanded.BraceWrapping.AfterClass =
true;
1639 Expanded.BraceWrapping.AfterEnum =
true;
1640 Expanded.BraceWrapping.AfterFunction =
true;
1641 Expanded.BraceWrapping.AfterStruct =
true;
1642 Expanded.BraceWrapping.AfterUnion =
true;
1643 Expanded.BraceWrapping.AfterExternBlock =
true;
1644 Expanded.BraceWrapping.SplitEmptyFunction =
true;
1645 Expanded.BraceWrapping.SplitEmptyRecord =
false;
1647 case FormatStyle::BS_Stroustrup:
1648 Expanded.BraceWrapping.AfterFunction =
true;
1649 Expanded.BraceWrapping.BeforeCatch =
true;
1650 Expanded.BraceWrapping.BeforeElse =
true;
1652 case FormatStyle::BS_Allman:
1653 Expanded.BraceWrapping.AfterCaseLabel =
true;
1654 Expanded.BraceWrapping.AfterClass =
true;
1655 Expanded.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_Always;
1656 Expanded.BraceWrapping.AfterEnum =
true;
1657 Expanded.BraceWrapping.AfterFunction =
true;
1658 Expanded.BraceWrapping.AfterNamespace =
true;
1659 Expanded.BraceWrapping.AfterObjCDeclaration =
true;
1660 Expanded.BraceWrapping.AfterStruct =
true;
1661 Expanded.BraceWrapping.AfterUnion =
true;
1662 Expanded.BraceWrapping.AfterExternBlock =
true;
1663 Expanded.BraceWrapping.BeforeCatch =
true;
1664 Expanded.BraceWrapping.BeforeElse =
true;
1665 Expanded.BraceWrapping.BeforeLambdaBody =
true;
1667 case FormatStyle::BS_Whitesmiths:
1668 Expanded.BraceWrapping.AfterCaseLabel =
true;
1669 Expanded.BraceWrapping.AfterClass =
true;
1670 Expanded.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_Always;
1671 Expanded.BraceWrapping.AfterEnum =
true;
1672 Expanded.BraceWrapping.AfterFunction =
true;
1673 Expanded.BraceWrapping.AfterNamespace =
true;
1674 Expanded.BraceWrapping.AfterObjCDeclaration =
true;
1675 Expanded.BraceWrapping.AfterStruct =
true;
1676 Expanded.BraceWrapping.AfterExternBlock =
true;
1677 Expanded.BraceWrapping.BeforeCatch =
true;
1678 Expanded.BraceWrapping.BeforeElse =
true;
1679 Expanded.BraceWrapping.BeforeLambdaBody =
true;
1681 case FormatStyle::BS_GNU:
1682 Expanded.BraceWrapping = {
1685 FormatStyle::BWACS_Always,
1702 case FormatStyle::BS_WebKit:
1703 Expanded.BraceWrapping.AfterFunction =
true;
1711 if (Expanded.SpaceBeforeParens == FormatStyle::SBPO_Custom)
1714 Expanded.SpaceBeforeParensOptions = {};
1715 Expanded.SpaceBeforeParensOptions.AfterPlacementOperator =
true;
1717 switch (Expanded.SpaceBeforeParens) {
1718 case FormatStyle::SBPO_ControlStatements:
1719 Expanded.SpaceBeforeParensOptions.AfterControlStatements =
true;
1720 Expanded.SpaceBeforeParensOptions.AfterForeachMacros =
true;
1721 Expanded.SpaceBeforeParensOptions.AfterIfMacros =
true;
1723 case FormatStyle::SBPO_ControlStatementsExceptControlMacros:
1724 Expanded.SpaceBeforeParensOptions.AfterControlStatements =
true;
1726 case FormatStyle::SBPO_NonEmptyParentheses:
1727 Expanded.SpaceBeforeParensOptions.BeforeNonEmptyParentheses =
true;
1735 if (Expanded.SpacesInParens == FormatStyle::SIPO_Custom)
1737 assert(Expanded.SpacesInParens == FormatStyle::SIPO_Never);
1739 Expanded.SpacesInParensOptions = {};
1743 FormatStyle LLVMStyle;
1744 LLVMStyle.AccessModifierOffset = -2;
1745 LLVMStyle.AlignAfterOpenBracket =
true;
1746 LLVMStyle.AlignArrayOfStructures = FormatStyle::AIAS_None;
1747 LLVMStyle.AlignConsecutiveAssignments = {};
1748 LLVMStyle.AlignConsecutiveAssignments.PadOperators =
true;
1749 LLVMStyle.AlignConsecutiveBitFields = {};
1750 LLVMStyle.AlignConsecutiveDeclarations = {};
1751 LLVMStyle.AlignConsecutiveDeclarations.AlignFunctionDeclarations =
true;
1752 LLVMStyle.AlignConsecutiveMacros = {};
1753 LLVMStyle.AlignConsecutiveShortCaseStatements = {};
1754 LLVMStyle.AlignConsecutiveTableGenBreakingDAGArgColons = {};
1755 LLVMStyle.AlignConsecutiveTableGenCondOperatorColons = {};
1756 LLVMStyle.AlignConsecutiveTableGenDefinitionColons = {};
1757 LLVMStyle.AlignEscapedNewlines = FormatStyle::ENAS_Right;
1758 LLVMStyle.AlignOperands = FormatStyle::OAS_Align;
1759 LLVMStyle.AlignTrailingComments = {};
1760 LLVMStyle.AlignTrailingComments.Kind = FormatStyle::TCAS_Always;
1761 LLVMStyle.AlignTrailingComments.OverEmptyLines = 0;
1762 LLVMStyle.AlignTrailingComments.AlignPPAndNotPP =
true;
1763 LLVMStyle.AllowAllArgumentsOnNextLine =
true;
1764 LLVMStyle.AllowAllParametersOfDeclarationOnNextLine =
true;
1765 LLVMStyle.AllowBreakBeforeNoexceptSpecifier = FormatStyle::BBNSS_Never;
1766 LLVMStyle.AllowBreakBeforeQtProperty =
false;
1767 LLVMStyle.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Never;
1768 LLVMStyle.AllowShortCaseExpressionOnASingleLine =
true;
1769 LLVMStyle.AllowShortCaseLabelsOnASingleLine =
false;
1770 LLVMStyle.AllowShortCompoundRequirementOnASingleLine =
true;
1771 LLVMStyle.AllowShortEnumsOnASingleLine =
true;
1772 LLVMStyle.AllowShortFunctionsOnASingleLine =
1773 FormatStyle::ShortFunctionStyle::setAll();
1774 LLVMStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
1775 LLVMStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_All;
1776 LLVMStyle.AllowShortLoopsOnASingleLine =
false;
1777 LLVMStyle.AllowShortNamespacesOnASingleLine =
false;
1778 LLVMStyle.AllowShortRecordOnASingleLine = FormatStyle::SRS_EmptyAndAttached;
1779 LLVMStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
1780 LLVMStyle.AlwaysBreakBeforeMultilineStrings =
false;
1781 LLVMStyle.AttributeMacros.push_back(
"__capability");
1782 LLVMStyle.BinPackArguments =
true;
1783 LLVMStyle.BinPackLongBracedList =
true;
1784 LLVMStyle.BinPackParameters = FormatStyle::BPPS_BinPack;
1785 LLVMStyle.BitFieldColonSpacing = FormatStyle::BFCS_Both;
1786 LLVMStyle.BracedInitializerIndentWidth = -1;
1787 LLVMStyle.BraceWrapping = {
false,
1789 FormatStyle::BWACS_Never,
1805 LLVMStyle.BreakAdjacentStringLiterals =
true;
1806 LLVMStyle.BreakAfterAttributes = FormatStyle::ABS_Leave;
1807 LLVMStyle.BreakAfterJavaFieldAnnotations =
false;
1808 LLVMStyle.BreakAfterOpenBracketBracedList =
false;
1809 LLVMStyle.BreakAfterOpenBracketFunction =
false;
1810 LLVMStyle.BreakAfterOpenBracketIf =
false;
1811 LLVMStyle.BreakAfterOpenBracketLoop =
false;
1812 LLVMStyle.BreakAfterOpenBracketSwitch =
false;
1813 LLVMStyle.BreakAfterReturnType = FormatStyle::RTBS_None;
1814 LLVMStyle.BreakArrays =
true;
1815 LLVMStyle.BreakBeforeBinaryOperators = FormatStyle::BOS_None;
1816 LLVMStyle.BreakBeforeBraces = FormatStyle::BS_Attach;
1817 LLVMStyle.BreakBeforeCloseBracketBracedList =
false;
1818 LLVMStyle.BreakBeforeCloseBracketFunction =
false;
1819 LLVMStyle.BreakBeforeCloseBracketIf =
false;
1820 LLVMStyle.BreakBeforeCloseBracketLoop =
false;
1821 LLVMStyle.BreakBeforeCloseBracketSwitch =
false;
1822 LLVMStyle.BreakBeforeConceptDeclarations = FormatStyle::BBCDS_Always;
1823 LLVMStyle.BreakBeforeInlineASMColon = FormatStyle::BBIAS_OnlyMultiline;
1824 LLVMStyle.BreakBeforeTemplateCloser =
false;
1825 LLVMStyle.BreakBeforeTernaryOperators =
true;
1826 LLVMStyle.BreakBinaryOperations = {FormatStyle::BBO_Never, {}};
1827 LLVMStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon;
1828 LLVMStyle.BreakFunctionDefinitionParameters =
false;
1829 LLVMStyle.BreakInheritanceList = FormatStyle::BILS_BeforeColon;
1830 LLVMStyle.BreakStringLiterals =
true;
1831 LLVMStyle.BreakTemplateDeclarations = FormatStyle::BTDS_MultiLine;
1832 LLVMStyle.ColumnLimit = 80;
1833 LLVMStyle.CommentPragmas =
"^ IWYU pragma:";
1834 LLVMStyle.CompactNamespaces =
false;
1835 LLVMStyle.ConstructorInitializerIndentWidth = 4;
1836 LLVMStyle.ContinuationIndentWidth = 4;
1837 LLVMStyle.Cpp11BracedListStyle = FormatStyle::BLS_AlignFirstComment;
1838 LLVMStyle.DerivePointerAlignment =
false;
1839 LLVMStyle.DisableFormat =
false;
1840 LLVMStyle.EmptyLineAfterAccessModifier = FormatStyle::ELAAMS_Never;
1841 LLVMStyle.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_LogicalBlock;
1842 LLVMStyle.EnumTrailingComma = FormatStyle::ETC_Leave;
1843 LLVMStyle.ExperimentalAutoDetectBinPacking =
false;
1844 LLVMStyle.FixNamespaceComments =
true;
1845 LLVMStyle.ForEachMacros.push_back(
"foreach");
1846 LLVMStyle.ForEachMacros.push_back(
"Q_FOREACH");
1847 LLVMStyle.ForEachMacros.push_back(
"BOOST_FOREACH");
1848 LLVMStyle.IfMacros.push_back(
"KJ_IF_MAYBE");
1850 LLVMStyle.IncludeStyle.IncludeCategories = {
1851 {
"^\"(llvm|llvm-c|clang|clang-c)/", 2, 0,
false},
1852 {
"^(<|\"(gtest|gmock|isl|json)/)", 3, 0,
false},
1853 {
".*", 1, 0,
false}};
1854 LLVMStyle.IncludeStyle.IncludeIsMainRegex =
"(Test)?$";
1855 LLVMStyle.IncludeStyle.MainIncludeChar = tooling::IncludeStyle::MICD_Quote;
1856 LLVMStyle.IndentAccessModifiers =
false;
1857 LLVMStyle.IndentCaseBlocks =
false;
1858 LLVMStyle.IndentCaseLabels =
false;
1859 LLVMStyle.IndentExportBlock =
true;
1860 LLVMStyle.IndentExternBlock = FormatStyle::IEBS_AfterExternBlock;
1861 LLVMStyle.IndentGotoLabels = FormatStyle::IGLS_OuterIndent;
1862 LLVMStyle.IndentPPDirectives = FormatStyle::PPDIS_None;
1863 LLVMStyle.IndentRequiresClause =
true;
1864 LLVMStyle.IndentWidth = 2;
1865 LLVMStyle.IndentWrappedFunctionNames =
false;
1866 LLVMStyle.InsertBraces =
false;
1867 LLVMStyle.InsertNewlineAtEOF =
false;
1868 LLVMStyle.InsertTrailingCommas = FormatStyle::TCS_None;
1869 LLVMStyle.IntegerLiteralSeparator = {};
1870 LLVMStyle.JavaScriptQuotes = FormatStyle::JSQS_Leave;
1871 LLVMStyle.JavaScriptWrapImports =
true;
1872 LLVMStyle.KeepEmptyLines = {
1877 LLVMStyle.KeepFormFeed =
false;
1878 LLVMStyle.LambdaBodyIndentation = FormatStyle::LBI_Signature;
1880 LLVMStyle.LineEnding = FormatStyle::LE_DeriveLF;
1881 LLVMStyle.MaxEmptyLinesToKeep = 1;
1882 LLVMStyle.NamespaceIndentation = FormatStyle::NI_None;
1883 LLVMStyle.NumericLiteralCase = {FormatStyle::NLCS_Leave,
1884 FormatStyle::NLCS_Leave,
1885 FormatStyle::NLCS_Leave,
1886 FormatStyle::NLCS_Leave};
1887 LLVMStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Auto;
1888 LLVMStyle.ObjCBlockIndentWidth = 2;
1889 LLVMStyle.ObjCBreakBeforeNestedBlockParam =
true;
1890 LLVMStyle.ObjCSpaceAfterMethodDeclarationPrefix =
true;
1891 LLVMStyle.ObjCSpaceAfterProperty =
false;
1892 LLVMStyle.ObjCSpaceBeforeProtocolList =
true;
1893 LLVMStyle.PackConstructorInitializers = FormatStyle::PCIS_BinPack;
1894 LLVMStyle.PointerAlignment = FormatStyle::PAS_Right;
1895 LLVMStyle.PPIndentWidth = -1;
1896 LLVMStyle.QualifierAlignment = FormatStyle::QAS_Leave;
1897 LLVMStyle.ReferenceAlignment = FormatStyle::RAS_Pointer;
1898 LLVMStyle.ReflowComments = FormatStyle::RCS_Always;
1899 LLVMStyle.RemoveBracesLLVM =
false;
1900 LLVMStyle.RemoveEmptyLinesInUnwrappedLines =
false;
1901 LLVMStyle.RemoveParentheses = FormatStyle::RPS_Leave;
1902 LLVMStyle.RemoveSemicolon =
false;
1903 LLVMStyle.RequiresClausePosition = FormatStyle::RCPS_OwnLine;
1904 LLVMStyle.RequiresExpressionIndentation = FormatStyle::REI_OuterScope;
1905 LLVMStyle.SeparateDefinitionBlocks = FormatStyle::SDS_Leave;
1906 LLVMStyle.ShortNamespaceLines = 1;
1907 LLVMStyle.SkipMacroDefinitionBody =
false;
1908 LLVMStyle.SortIncludes = {
true,
false,
1910 LLVMStyle.SortJavaStaticImport = FormatStyle::SJSIO_Before;
1911 LLVMStyle.SortUsingDeclarations = FormatStyle::SUD_LexicographicNumeric;
1912 LLVMStyle.SpaceAfterCStyleCast =
false;
1913 LLVMStyle.SpaceAfterLogicalNot =
false;
1914 LLVMStyle.SpaceAfterOperatorKeyword =
false;
1915 LLVMStyle.SpaceAfterTemplateKeyword =
true;
1916 LLVMStyle.SpaceAroundPointerQualifiers = FormatStyle::SAPQ_Default;
1917 LLVMStyle.SpaceBeforeAssignmentOperators =
true;
1918 LLVMStyle.SpaceBeforeCaseColon =
false;
1919 LLVMStyle.SpaceBeforeCpp11BracedList =
false;
1920 LLVMStyle.SpaceBeforeCtorInitializerColon =
true;
1921 LLVMStyle.SpaceBeforeInheritanceColon =
true;
1922 LLVMStyle.SpaceBeforeJsonColon =
false;
1923 LLVMStyle.SpaceBeforeParens = FormatStyle::SBPO_ControlStatements;
1924 LLVMStyle.SpaceBeforeParensOptions = {};
1925 LLVMStyle.SpaceBeforeParensOptions.AfterControlStatements =
true;
1926 LLVMStyle.SpaceBeforeParensOptions.AfterForeachMacros =
true;
1927 LLVMStyle.SpaceBeforeParensOptions.AfterIfMacros =
true;
1928 LLVMStyle.SpaceBeforeRangeBasedForLoopColon =
true;
1929 LLVMStyle.SpaceBeforeSquareBrackets =
false;
1930 LLVMStyle.SpaceInEmptyBraces = FormatStyle::SIEB_Never;
1931 LLVMStyle.SpacesBeforeTrailingComments = 1;
1932 LLVMStyle.SpacesInAngles = FormatStyle::SIAS_Never;
1933 LLVMStyle.SpacesInContainerLiterals =
true;
1934 LLVMStyle.SpacesInLineCommentPrefix = {
1935 1, std::numeric_limits<unsigned>::max()};
1936 LLVMStyle.SpacesInParens = FormatStyle::SIPO_Never;
1937 LLVMStyle.SpacesInSquareBrackets =
false;
1938 LLVMStyle.Standard = FormatStyle::LS_Latest;
1939 LLVMStyle.StatementAttributeLikeMacros.push_back(
"Q_EMIT");
1940 LLVMStyle.StatementMacros.push_back(
"Q_UNUSED");
1941 LLVMStyle.StatementMacros.push_back(
"QT_REQUIRE_VERSION");
1942 LLVMStyle.TableGenBreakingDAGArgOperators = {};
1943 LLVMStyle.TableGenBreakInsideDAGArg = FormatStyle::DAS_DontBreak;
1944 LLVMStyle.TabWidth = 8;
1945 LLVMStyle.UseTab = FormatStyle::UT_Never;
1946 LLVMStyle.VerilogBreakBetweenInstancePorts =
true;
1947 LLVMStyle.WhitespaceSensitiveMacros.push_back(
"BOOST_PP_STRINGIZE");
1948 LLVMStyle.WhitespaceSensitiveMacros.push_back(
"CF_SWIFT_NAME");
1949 LLVMStyle.WhitespaceSensitiveMacros.push_back(
"NS_SWIFT_NAME");
1950 LLVMStyle.WhitespaceSensitiveMacros.push_back(
"PP_STRINGIZE");
1951 LLVMStyle.WhitespaceSensitiveMacros.push_back(
"STRINGIZE");
1952 LLVMStyle.WrapNamespaceBodyWithEmptyLines = FormatStyle::WNBWELS_Leave;
1955 LLVMStyle.PenaltyBreakBeforeFirstCallParameter = 19;
1956 LLVMStyle.PenaltyBreakBeforeMemberAccess = 150;
1957 LLVMStyle.PenaltyBreakComment = 300;
1958 LLVMStyle.PenaltyBreakFirstLessLess = 120;
1959 LLVMStyle.PenaltyBreakOpenParenthesis = 0;
1960 LLVMStyle.PenaltyBreakScopeResolution = 500;
1961 LLVMStyle.PenaltyBreakString = 1000;
1963 LLVMStyle.PenaltyExcessCharacter = 1'000'000;
1964 LLVMStyle.PenaltyIndentedWhitespace = 0;
1965 LLVMStyle.PenaltyReturnTypeOnItsOwnLine = 60;
1969 case FormatStyle::LK_TableGen:
1970 LLVMStyle.SpacesInContainerLiterals =
false;
1972 case FormatStyle::LK_Json:
1973 LLVMStyle.ColumnLimit = 0;
1975 case FormatStyle::LK_Verilog:
1976 LLVMStyle.IndentCaseLabels =
true;
1977 LLVMStyle.SpacesInContainerLiterals =
false;
1987 if (
Language == FormatStyle::LK_TextProto) {
1989 GoogleStyle.Language = FormatStyle::LK_TextProto;
1996 GoogleStyle.AccessModifierOffset = -1;
1997 GoogleStyle.AlignEscapedNewlines = FormatStyle::ENAS_Left;
1998 GoogleStyle.AllowShortIfStatementsOnASingleLine =
1999 FormatStyle::SIS_WithoutElse;
2000 GoogleStyle.AllowShortLoopsOnASingleLine =
true;
2001 GoogleStyle.AlwaysBreakBeforeMultilineStrings =
true;
2003 GoogleStyle.AttributeMacros.push_back(
"absl_nonnull");
2004 GoogleStyle.AttributeMacros.push_back(
"absl_nullable");
2005 GoogleStyle.AttributeMacros.push_back(
"absl_nullability_unknown");
2006 GoogleStyle.BreakTemplateDeclarations = FormatStyle::BTDS_Yes;
2008 GoogleStyle.IncludeStyle.IncludeCategories = {{
"^<ext/.*\\.h>", 2, 0,
false},
2009 {
"^<.*\\.h>", 1, 0,
false},
2010 {
"^<.*", 2, 0,
false},
2011 {
".*", 3, 0,
false}};
2012 GoogleStyle.IncludeStyle.IncludeIsMainRegex =
"([-_](test|unittest))?$";
2013 GoogleStyle.IndentCaseLabels =
true;
2014 GoogleStyle.KeepEmptyLines.AtStartOfBlock =
false;
2015 GoogleStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Never;
2016 GoogleStyle.ObjCSpaceAfterProperty =
false;
2017 GoogleStyle.ObjCSpaceBeforeProtocolList =
true;
2018 GoogleStyle.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
2019 GoogleStyle.PointerAlignment = FormatStyle::PAS_Left;
2020 GoogleStyle.RawStringFormats = {
2022 FormatStyle::LK_Cpp,
2039 FormatStyle::LK_TextProto,
2051 "PARSE_PARTIAL_TEXT_PROTO",
2055 "ParseTextProtoOrDie",
2057 "ParsePartialTestProto",
2064 GoogleStyle.SpacesBeforeTrailingComments = 2;
2065 GoogleStyle.Standard = FormatStyle::LS_Auto;
2067 GoogleStyle.PenaltyBreakBeforeFirstCallParameter = 1;
2068 GoogleStyle.PenaltyReturnTypeOnItsOwnLine = 200;
2070 if (
Language == FormatStyle::LK_Java) {
2071 GoogleStyle.AlignAfterOpenBracket =
false;
2072 GoogleStyle.AlignOperands = FormatStyle::OAS_DontAlign;
2073 GoogleStyle.AlignTrailingComments = {};
2074 GoogleStyle.AlignTrailingComments.Kind = FormatStyle::TCAS_Never;
2075 GoogleStyle.AllowShortFunctionsOnASingleLine =
2076 FormatStyle::ShortFunctionStyle::setEmptyOnly();
2077 GoogleStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
2078 GoogleStyle.AlwaysBreakBeforeMultilineStrings =
false;
2079 GoogleStyle.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment;
2080 GoogleStyle.ColumnLimit = 100;
2081 GoogleStyle.SpaceAfterCStyleCast =
true;
2082 GoogleStyle.SpacesBeforeTrailingComments = 1;
2083 }
else if (
Language == FormatStyle::LK_JavaScript) {
2084 GoogleStyle.BreakAfterOpenBracketBracedList =
true;
2085 GoogleStyle.BreakAfterOpenBracketFunction =
true;
2086 GoogleStyle.BreakAfterOpenBracketIf =
true;
2087 GoogleStyle.AlignOperands = FormatStyle::OAS_DontAlign;
2088 GoogleStyle.AllowShortFunctionsOnASingleLine =
2089 FormatStyle::ShortFunctionStyle::setEmptyOnly();
2091 GoogleStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_Empty;
2092 GoogleStyle.AlwaysBreakBeforeMultilineStrings =
false;
2093 GoogleStyle.BreakBeforeTernaryOperators =
false;
2096 GoogleStyle.CommentPragmas =
"(taze:|^/[ \t]*<|tslint:|@see)";
2100 GoogleStyle.JavaScriptQuotes = FormatStyle::JSQS_Single;
2101 GoogleStyle.JavaScriptWrapImports =
false;
2102 GoogleStyle.MaxEmptyLinesToKeep = 3;
2103 GoogleStyle.NamespaceIndentation = FormatStyle::NI_All;
2104 GoogleStyle.SpacesInContainerLiterals =
false;
2105 }
else if (
Language == FormatStyle::LK_Proto) {
2106 GoogleStyle.AllowShortFunctionsOnASingleLine =
2107 FormatStyle::ShortFunctionStyle::setEmptyOnly();
2108 GoogleStyle.AlwaysBreakBeforeMultilineStrings =
false;
2114 GoogleStyle.BreakStringLiterals =
false;
2115 GoogleStyle.Cpp11BracedListStyle = FormatStyle::BLS_Block;
2116 GoogleStyle.SpacesInContainerLiterals =
false;
2117 }
else if (
Language == FormatStyle::LK_ObjC) {
2118 GoogleStyle.AlwaysBreakBeforeMultilineStrings =
false;
2119 GoogleStyle.ColumnLimit = 100;
2120 GoogleStyle.DerivePointerAlignment =
true;
2124 GoogleStyle.IncludeStyle.IncludeBlocks =
2126 }
else if (
Language == FormatStyle::LK_CSharp) {
2127 GoogleStyle.AllowShortFunctionsOnASingleLine =
2128 FormatStyle::ShortFunctionStyle::setEmptyOnly();
2129 GoogleStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
2130 GoogleStyle.BreakStringLiterals =
false;
2131 GoogleStyle.ColumnLimit = 100;
2132 GoogleStyle.NamespaceIndentation = FormatStyle::NI_All;
2158 ChromiumStyle.IncludeStyle.IncludeBlocks =
2161 if (
Language == FormatStyle::LK_Java) {
2162 ChromiumStyle.AllowShortIfStatementsOnASingleLine =
2163 FormatStyle::SIS_WithoutElse;
2164 ChromiumStyle.BreakAfterJavaFieldAnnotations =
true;
2165 ChromiumStyle.ContinuationIndentWidth = 8;
2166 ChromiumStyle.IndentWidth = 4;
2169 ChromiumStyle.JavaImportGroups = {
2176 "com.google.android.apps.chrome",
2181 }
else if (
Language == FormatStyle::LK_JavaScript) {
2182 ChromiumStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
2183 ChromiumStyle.AllowShortLoopsOnASingleLine =
false;
2185 ChromiumStyle.AllowAllParametersOfDeclarationOnNextLine =
false;
2186 ChromiumStyle.AllowShortFunctionsOnASingleLine =
2187 FormatStyle::ShortFunctionStyle::setEmptyAndInline();
2188 ChromiumStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
2189 ChromiumStyle.AllowShortLoopsOnASingleLine =
false;
2190 ChromiumStyle.BinPackParameters = FormatStyle::BPPS_OnePerLine;
2191 ChromiumStyle.DerivePointerAlignment =
false;
2192 if (
Language == FormatStyle::LK_ObjC)
2193 ChromiumStyle.ColumnLimit = 80;
2195 return ChromiumStyle;
2200 MozillaStyle.AllowAllParametersOfDeclarationOnNextLine =
false;
2201 MozillaStyle.AllowShortFunctionsOnASingleLine =
2202 FormatStyle::ShortFunctionStyle::setEmptyAndInline();
2203 MozillaStyle.AlwaysBreakAfterDefinitionReturnType =
2204 FormatStyle::DRTBS_TopLevel;
2205 MozillaStyle.BinPackArguments =
false;
2206 MozillaStyle.BinPackParameters = FormatStyle::BPPS_OnePerLine;
2207 MozillaStyle.BreakAfterReturnType = FormatStyle::RTBS_TopLevel;
2208 MozillaStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla;
2209 MozillaStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;
2210 MozillaStyle.BreakInheritanceList = FormatStyle::BILS_BeforeComma;
2211 MozillaStyle.BreakTemplateDeclarations = FormatStyle::BTDS_Yes;
2212 MozillaStyle.ConstructorInitializerIndentWidth = 2;
2213 MozillaStyle.ContinuationIndentWidth = 2;
2214 MozillaStyle.Cpp11BracedListStyle = FormatStyle::BLS_Block;
2215 MozillaStyle.FixNamespaceComments =
false;
2216 MozillaStyle.IndentCaseLabels =
true;
2217 MozillaStyle.ObjCSpaceAfterProperty =
true;
2218 MozillaStyle.ObjCSpaceBeforeProtocolList =
false;
2219 MozillaStyle.PenaltyReturnTypeOnItsOwnLine = 200;
2220 MozillaStyle.PointerAlignment = FormatStyle::PAS_Left;
2221 MozillaStyle.SpaceAfterTemplateKeyword =
false;
2222 return MozillaStyle;
2227 Style.AccessModifierOffset = -4;
2228 Style.AlignAfterOpenBracket =
false;
2229 Style.AlignOperands = FormatStyle::OAS_DontAlign;
2230 Style.AlignTrailingComments = {};
2231 Style.AlignTrailingComments.Kind = FormatStyle::TCAS_Never;
2232 Style.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Empty;
2233 Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
2234 Style.BreakBeforeBraces = FormatStyle::BS_WebKit;
2235 Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;
2236 Style.ColumnLimit = 0;
2237 Style.Cpp11BracedListStyle = FormatStyle::BLS_Block;
2238 Style.FixNamespaceComments =
false;
2239 Style.IndentWidth = 4;
2240 Style.NamespaceIndentation = FormatStyle::NI_Inner;
2241 Style.ObjCBlockIndentWidth = 4;
2242 Style.ObjCSpaceAfterProperty =
true;
2243 Style.PointerAlignment = FormatStyle::PAS_Left;
2244 Style.SpaceBeforeCpp11BracedList =
true;
2245 Style.SpaceInEmptyBraces = FormatStyle::SIEB_Always;
2251 Style.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_All;
2252 Style.BreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
2253 Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
2254 Style.BreakBeforeBraces = FormatStyle::BS_GNU;
2255 Style.BreakBeforeTernaryOperators =
true;
2256 Style.ColumnLimit = 79;
2257 Style.Cpp11BracedListStyle = FormatStyle::BLS_Block;
2258 Style.FixNamespaceComments =
false;
2259 Style.KeepFormFeed =
true;
2260 Style.SpaceBeforeParens = FormatStyle::SBPO_Always;
2266 Style.ColumnLimit = 120;
2268 Style.IndentWidth = 4;
2269 Style.UseTab = FormatStyle::UT_Never;
2270 Style.BreakBeforeBraces = FormatStyle::BS_Custom;
2271 Style.BraceWrapping.AfterClass =
true;
2272 Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_Always;
2273 Style.BraceWrapping.AfterEnum =
true;
2274 Style.BraceWrapping.AfterFunction =
true;
2275 Style.BraceWrapping.AfterNamespace =
true;
2276 Style.BraceWrapping.AfterObjCDeclaration =
true;
2277 Style.BraceWrapping.AfterStruct =
true;
2278 Style.BraceWrapping.AfterExternBlock =
true;
2279 Style.BraceWrapping.BeforeCatch =
true;
2280 Style.BraceWrapping.BeforeElse =
true;
2281 Style.BraceWrapping.BeforeWhile =
false;
2282 Style.PenaltyReturnTypeOnItsOwnLine = 1000;
2283 Style.AllowShortEnumsOnASingleLine =
false;
2284 Style.AllowShortFunctionsOnASingleLine = FormatStyle::ShortFunctionStyle();
2285 Style.AllowShortCaseLabelsOnASingleLine =
false;
2286 Style.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
2287 Style.AllowShortLoopsOnASingleLine =
false;
2288 Style.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
2289 Style.BreakAfterReturnType = FormatStyle::RTBS_None;
2295 Style.InsertBraces =
true;
2296 Style.InsertNewlineAtEOF =
true;
2297 Style.IntegerLiteralSeparator.Decimal = 3;
2298 Style.IntegerLiteralSeparator.DecimalMinDigitsInsert = 5;
2299 Style.LineEnding = FormatStyle::LE_LF;
2300 Style.RemoveBracesLLVM =
true;
2301 Style.RemoveEmptyLinesInUnwrappedLines =
true;
2302 Style.RemoveParentheses = FormatStyle::RPS_ReturnStatement;
2303 Style.RemoveSemicolon =
true;
2309 NoStyle.DisableFormat =
true;
2310 NoStyle.SortIncludes = {};
2311 NoStyle.SortUsingDeclarations = FormatStyle::SUD_Never;
2316 FormatStyle *Style) {
2317 constexpr StringRef Prefix(
"inheritparentconfig=");
2319 if (Name.equals_insensitive(
"llvm"))
2321 else if (Name.equals_insensitive(
"chromium"))
2323 else if (Name.equals_insensitive(
"mozilla"))
2325 else if (Name.equals_insensitive(
"google"))
2327 else if (Name.equals_insensitive(
"webkit"))
2329 else if (Name.equals_insensitive(
"gnu"))
2331 else if (Name.equals_insensitive(
"microsoft"))
2333 else if (Name.equals_insensitive(
"clang-format"))
2335 else if (Name.equals_insensitive(
"none"))
2337 else if (Name.equals_insensitive(Prefix.drop_back()))
2338 Style->InheritConfig =
"..";
2339 else if (Name.size() > Prefix.size() && Name.starts_with_insensitive(Prefix))
2340 Style->InheritConfig = Name.substr(Prefix.size());
2350 if (Style->QualifierOrder.empty())
2354 for (
const auto &Qualifier : Style->QualifierOrder) {
2355 if (Qualifier ==
"type")
2359 if (token == tok::identifier)
2364 std::set<std::string> UniqueQualifiers(Style->QualifierOrder.begin(),
2365 Style->QualifierOrder.end());
2366 if (Style->QualifierOrder.size() != UniqueQualifiers.size()) {
2367 LLVM_DEBUG(llvm::dbgs()
2368 <<
"Duplicate Qualifiers " << Style->QualifierOrder.size()
2369 <<
" vs " << UniqueQualifiers.size() <<
"\n");
2374 if (!llvm::is_contained(Style->QualifierOrder,
"type"))
2381 FormatStyle *Style,
bool AllowUnknownOptions,
2382 llvm::SourceMgr::DiagHandlerTy DiagHandler,
2383 void *DiagHandlerCtxt,
bool IsDotHFile) {
2385 FormatStyle::LanguageKind
Language = Style->Language;
2386 assert(
Language != FormatStyle::LK_None);
2387 if (Config.getBuffer().trim().empty())
2389 Style->StyleSet.Clear();
2390 std::vector<FormatStyle> Styles;
2391 llvm::yaml::Input Input(Config,
nullptr, DiagHandler,
2397 Input.setContext(Style);
2398 Input.setAllowUnknownKeys(AllowUnknownOptions);
2401 return Input.error();
2405 const auto StyleCount = Styles.size();
2408 for (
unsigned I = 1; I < StyleCount; ++I) {
2409 const auto Lang = Styles[I].Language;
2410 if (Lang == FormatStyle::LK_None)
2413 for (
unsigned J = 0; J < I; ++J) {
2415 LLVM_DEBUG(llvm::dbgs()
2416 <<
"Duplicate languages in the config file on positions "
2417 << J <<
" and " << I <<
'\n');
2423 int LanguagePos = -1;
2429 for (
unsigned I = 0; I < StyleCount; ++I) {
2430 const auto Lang = Styles[I].Language;
2435 if (Lang == FormatStyle::LK_Cpp)
2437 else if (Lang == FormatStyle::LK_C)
2444 if (LanguagePos < 0) {
2445 if (Styles[0].
Language == FormatStyle::LK_None)
2447 else if (IsDotHFile &&
Language == FormatStyle::LK_Cpp)
2449 else if (!IsDotHFile &&
Language == FormatStyle::LK_C)
2450 LanguagePos = CppPos;
2451 if (LanguagePos < 0)
2455 for (
const auto &S : llvm::reverse(llvm::drop_begin(Styles)))
2456 Style->StyleSet.Add(S);
2458 *Style = Styles[LanguagePos];
2460 if (LanguagePos == 0) {
2461 if (Style->Language == FormatStyle::LK_None)
2463 Style->StyleSet.Add(*Style);
2466 if (Style->InsertTrailingCommas != FormatStyle::TCS_None &&
2467 Style->BinPackArguments) {
2471 if (Style->QualifierAlignment != FormatStyle::QAS_Leave)
2478 llvm::raw_string_ostream Stream(
Text);
2479 llvm::yaml::Output Output(Stream);
2482 FormatStyle NonConstStyle = Style;
2486 Output << NonConstStyle;
2488 return Stream.str();
2491std::optional<FormatStyle>
2492FormatStyle::FormatStyleSet::Get(FormatStyle::LanguageKind
Language)
const {
2494 return std::nullopt;
2496 if (It == Styles->end())
2497 return std::nullopt;
2498 FormatStyle Style = It->second;
2499 Style.StyleSet = *
this;
2503void FormatStyle::FormatStyleSet::Add(FormatStyle Style) {
2504 assert(Style.Language !=
LK_None &&
2505 "Cannot add a style for LK_None to a StyleSet");
2507 !Style.StyleSet.Styles &&
2508 "Cannot add a style associated with an existing StyleSet to a StyleSet");
2510 Styles = std::make_shared<MapType>();
2511 (*Styles)[Style.Language] = std::move(Style);
2514void FormatStyle::FormatStyleSet::Clear() { Styles.reset(); }
2516std::optional<FormatStyle>
2517FormatStyle::GetLanguageStyle(FormatStyle::LanguageKind
Language)
const {
2524 const SourceManager &SourceMgr, tooling::Replacements &
Result,
2525 StringRef
Text =
"") {
2526 const auto &
Tok = Token.Tok;
2527 SourceLocation Start;
2529 Start =
Tok.getLocation();
2532 Start = Token.WhitespaceRange.getBegin();
2535 cantFail(
Result.add(tooling::Replacement(SourceMgr, Range,
Text)));
2540 ParensRemover(
const Environment &Env,
const FormatStyle &Style)
2541 : TokenAnalyzer(Env, Style) {}
2543 std::pair<tooling::Replacements, unsigned>
2544 analyze(TokenAnnotator &Annotator,
2545 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2546 FormatTokenLexer &Tokens)
override {
2547 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2548 tooling::Replacements
Result;
2549 removeParens(AnnotatedLines,
Result);
2554 void removeParens(SmallVectorImpl<AnnotatedLine *> &Lines,
2555 tooling::Replacements &
Result) {
2556 const auto &SourceMgr = Env.getSourceManager();
2557 for (
auto *
Line : Lines) {
2558 if (!
Line->Children.empty())
2560 if (!
Line->Affected)
2562 for (
const auto *Token =
Line->First; Token && !Token->Finalized;
2563 Token = Token->Next) {
2564 if (Token->Optional && Token->isOneOf(tok::l_paren, tok::r_paren))
2573 BracesInserter(
const Environment &Env,
const FormatStyle &Style)
2574 : TokenAnalyzer(Env, Style) {}
2576 std::pair<tooling::Replacements, unsigned>
2577 analyze(TokenAnnotator &Annotator,
2578 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2579 FormatTokenLexer &Tokens)
override {
2580 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2581 tooling::Replacements
Result;
2582 insertBraces(AnnotatedLines,
Result);
2587 void insertBraces(SmallVectorImpl<AnnotatedLine *> &Lines,
2588 tooling::Replacements &
Result) {
2589 const auto &SourceMgr = Env.getSourceManager();
2590 int OpeningBraceSurplus = 0;
2591 for (AnnotatedLine *
Line : Lines) {
2592 if (!
Line->Children.empty())
2594 if (!
Line->Affected && OpeningBraceSurplus == 0)
2597 Token = Token->Next) {
2604 if (!
Line->Affected)
2606 Brace = Token->is(tok::comment) ?
"\n{" :
"{";
2607 ++OpeningBraceSurplus;
2609 if (OpeningBraceSurplus == 0)
2616 Token->BraceCount = 0;
2617 const auto Start = Token->Tok.getEndLoc();
2618 cantFail(
Result.add(tooling::Replacement(SourceMgr, Start, 0,
Brace)));
2621 assert(OpeningBraceSurplus == 0);
2627 BracesRemover(
const Environment &Env,
const FormatStyle &Style)
2628 : TokenAnalyzer(Env, Style) {}
2630 std::pair<tooling::Replacements, unsigned>
2631 analyze(TokenAnnotator &Annotator,
2632 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2633 FormatTokenLexer &Tokens)
override {
2634 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2635 tooling::Replacements
Result;
2636 removeBraces(AnnotatedLines,
Result);
2641 void removeBraces(SmallVectorImpl<AnnotatedLine *> &Lines,
2642 tooling::Replacements &
Result) {
2643 const auto &SourceMgr = Env.getSourceManager();
2644 const auto *End = Lines.end();
2645 for (
const auto *I = Lines.begin(); I != End; ++I) {
2646 const auto &
Line = *I;
2647 if (!
Line->Children.empty())
2649 if (!
Line->Affected)
2651 const auto *NextLine = I + 1 == End ?
nullptr : I[1];
2652 for (
const auto *Token =
Line->First; Token && !Token->Finalized;
2653 Token = Token->Next) {
2654 if (!Token->Optional || Token->isNoneOf(tok::l_brace, tok::r_brace))
2656 auto *
Next = Token->Next;
2657 assert(
Next || Token ==
Line->Last);
2658 if (!
Next && NextLine)
2659 Next = NextLine->First;
2668 SemiRemover(
const Environment &Env,
const FormatStyle &Style)
2669 : TokenAnalyzer(Env, Style) {}
2671 std::pair<tooling::Replacements, unsigned>
2672 analyze(TokenAnnotator &Annotator,
2673 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2674 FormatTokenLexer &Tokens)
override {
2675 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2676 tooling::Replacements
Result;
2677 removeSemi(Annotator, AnnotatedLines,
Result);
2682 void removeSemi(TokenAnnotator &Annotator,
2683 SmallVectorImpl<AnnotatedLine *> &Lines,
2684 tooling::Replacements &
Result) {
2686 const auto *Prev =
Tok.Previous;
2687 if (!Prev || Prev->isNot(tok::r_brace))
2689 const auto *LBrace = Prev->MatchingParen;
2690 return LBrace && LBrace->is(TT_FunctionLBrace);
2692 const auto &SourceMgr = Env.getSourceManager();
2693 const auto *End = Lines.end();
2694 for (
const auto *I = Lines.begin(); I != End; ++I) {
2695 const auto &
Line = *I;
2696 if (!
Line->Children.empty())
2697 removeSemi(Annotator,
Line->Children,
Result);
2698 if (!
Line->Affected)
2700 Annotator.calculateFormattingInformation(*
Line);
2701 const auto *NextLine = I + 1 == End ?
nullptr : I[1];
2702 for (
const auto *Token =
Line->First; Token && !Token->Finalized;
2703 Token = Token->Next) {
2704 if (Token->isNot(tok::semi) ||
2705 (!Token->Optional && !PrecededByFunctionRBrace(*Token))) {
2708 auto *
Next = Token->Next;
2709 assert(
Next || Token ==
Line->Last);
2710 if (!
Next && NextLine)
2711 Next = NextLine->First;
2720 EnumTrailingCommaEditor(
const Environment &Env,
const FormatStyle &Style)
2721 : TokenAnalyzer(Env, Style) {}
2723 std::pair<tooling::Replacements, unsigned>
2724 analyze(TokenAnnotator &Annotator,
2725 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2726 FormatTokenLexer &Tokens)
override {
2727 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2728 tooling::Replacements
Result;
2729 editEnumTrailingComma(AnnotatedLines,
Result);
2734 void editEnumTrailingComma(SmallVectorImpl<AnnotatedLine *> &Lines,
2735 tooling::Replacements &
Result) {
2736 bool InEnumBraces =
false;
2738 const auto &SourceMgr = Env.getSourceManager();
2739 for (
auto *
Line : Lines) {
2740 if (!
Line->Children.empty())
2741 editEnumTrailingComma(
Line->Children,
Result);
2742 for (
const auto *Token =
Line->First; Token && !Token->Finalized;
2743 Token = Token->Next) {
2744 if (Token->isNot(TT_EnumRBrace)) {
2745 if (Token->is(TT_EnumLBrace))
2746 InEnumBraces =
true;
2747 else if (InEnumBraces && Token->isNot(tok::comment))
2748 BeforeRBrace =
Line->Affected ? Token :
nullptr;
2751 InEnumBraces =
false;
2754 if (BeforeRBrace->is(tok::comma)) {
2755 if (Style.EnumTrailingComma == FormatStyle::ETC_Remove)
2757 }
else if (Style.EnumTrailingComma == FormatStyle::ETC_Insert) {
2758 cantFail(
Result.add(tooling::Replacement(
2759 SourceMgr, BeforeRBrace->Tok.getEndLoc(), 0,
",")));
2761 BeforeRBrace =
nullptr;
2769 JavaScriptRequoter(
const Environment &Env,
const FormatStyle &Style)
2770 : TokenAnalyzer(Env, Style) {}
2772 std::pair<tooling::Replacements, unsigned>
2773 analyze(TokenAnnotator &Annotator,
2774 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2775 FormatTokenLexer &Tokens)
override {
2776 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2777 tooling::Replacements
Result;
2778 requoteJSStringLiteral(AnnotatedLines,
Result);
2785 void requoteJSStringLiteral(SmallVectorImpl<AnnotatedLine *> &Lines,
2786 tooling::Replacements &
Result) {
2787 for (AnnotatedLine *
Line : Lines) {
2788 requoteJSStringLiteral(
Line->Children,
Result);
2789 if (!
Line->Affected)
2792 FormatTok = FormatTok->Next) {
2793 StringRef Input = FormatTok->TokenText;
2794 if (FormatTok->Finalized || !FormatTok->isStringLiteral() ||
2797 (Style.JavaScriptQuotes == FormatStyle::JSQS_Single &&
2798 !Input.starts_with(
"\"")) ||
2799 (Style.JavaScriptQuotes == FormatStyle::JSQS_Double &&
2800 !Input.starts_with(
"\'"))) {
2805 bool IsSingle = Style.JavaScriptQuotes == FormatStyle::JSQS_Single;
2806 SourceLocation Start = FormatTok->Tok.getLocation();
2807 auto Replace = [&](SourceLocation Start,
unsigned Length,
2808 StringRef ReplacementText) {
2809 auto Err =
Result.add(tooling::Replacement(
2810 Env.getSourceManager(), Start, Length, ReplacementText));
2814 llvm::errs() <<
toString(std::move(Err)) <<
"\n";
2818 Replace(Start, 1, IsSingle ?
"'" :
"\"");
2819 Replace(FormatTok->Tok.getEndLoc().getLocWithOffset(-1), 1,
2820 IsSingle ?
"'" :
"\"");
2823 bool Escaped =
false;
2824 for (
size_t i = 1; i < Input.size() - 1; i++) {
2827 if (!Escaped && i + 1 < Input.size() &&
2828 ((IsSingle && Input[i + 1] ==
'"') ||
2829 (!IsSingle && Input[i + 1] ==
'\''))) {
2832 Replace(Start.getLocWithOffset(i), 1,
"");
2839 if (!Escaped && IsSingle == (Input[i] ==
'\'')) {
2841 Replace(Start.getLocWithOffset(i), 0,
"\\");
2857 Formatter(
const Environment &Env,
const FormatStyle &Style,
2858 FormattingAttemptStatus *Status)
2859 : TokenAnalyzer(Env, Style), Status(Status) {}
2861 std::pair<tooling::Replacements, unsigned>
2862 analyze(TokenAnnotator &Annotator,
2863 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2864 FormatTokenLexer &Tokens)
override {
2865 tooling::Replacements
Result;
2866 deriveLocalStyle(AnnotatedLines);
2867 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2868 for (AnnotatedLine *
Line : AnnotatedLines)
2869 Annotator.calculateFormattingInformation(*
Line);
2870 Annotator.setCommentLineLevels(AnnotatedLines);
2872 WhitespaceManager Whitespaces(
2873 Env.getSourceManager(), Style,
2874 Style.LineEnding > FormatStyle::LE_CRLF
2876 Env.getSourceManager().getBufferData(Env.getFileID()),
2877 Style.LineEnding == FormatStyle::LE_DeriveCRLF)
2878 : Style.LineEnding == FormatStyle::LE_CRLF);
2879 ContinuationIndenter Indenter(Style, Tokens.getKeywords(),
2880 Env.getSourceManager(), Whitespaces, Encoding,
2881 BinPackInconclusiveFunctions);
2883 UnwrappedLineFormatter(&Indenter, &Whitespaces, Style,
2884 Tokens.getKeywords(), Env.getSourceManager(),
2886 .format(AnnotatedLines,
false,
2889 Env.getFirstStartColumn(),
2890 Env.getNextStartColumn(),
2891 Env.getLastStartColumn());
2892 for (
const auto &R : Whitespaces.generateReplacements())
2894 return std::make_pair(
Result, 0);
2895 return std::make_pair(
Result, Penalty);
2900 hasCpp03IncompatibleFormat(
const SmallVectorImpl<AnnotatedLine *> &Lines) {
2901 for (
const AnnotatedLine *
Line : Lines) {
2902 if (hasCpp03IncompatibleFormat(
Line->Children))
2905 if (!
Tok->hasWhitespaceBefore()) {
2906 if (
Tok->is(tok::coloncolon) &&
Tok->Previous->is(TT_TemplateOpener))
2908 if (
Tok->is(TT_TemplateCloser) &&
2909 Tok->Previous->is(TT_TemplateCloser)) {
2918 int countVariableAlignments(
const SmallVectorImpl<AnnotatedLine *> &Lines) {
2919 int AlignmentDiff = 0;
2921 for (
const AnnotatedLine *
Line : Lines) {
2922 AlignmentDiff += countVariableAlignments(
Line->Children);
2925 if (
Tok->isNot(TT_PointerOrReference))
2928 const auto *Prev =
Tok->Previous;
2929 const bool PrecededByName = Prev && Prev->Tok.getIdentifierInfo();
2930 const bool SpaceBefore =
Tok->hasWhitespaceBefore();
2933 while (
Tok->Next &&
Tok->Next->is(TT_PointerOrReference))
2937 const bool FollowedByName =
Next &&
Next->Tok.getIdentifierInfo();
2938 const bool SpaceAfter =
Next &&
Next->hasWhitespaceBefore();
2940 if ((!PrecededByName && !FollowedByName) ||
2942 (PrecededByName && FollowedByName && SpaceBefore == SpaceAfter)) {
2946 if ((PrecededByName && SpaceBefore) ||
2947 (FollowedByName && !SpaceAfter)) {
2950 }
else if ((PrecededByName && !SpaceBefore) ||
2951 (FollowedByName && SpaceAfter)) {
2958 return AlignmentDiff;
2962 deriveLocalStyle(
const SmallVectorImpl<AnnotatedLine *> &AnnotatedLines) {
2963 bool HasBinPackedFunction =
false;
2964 bool HasOnePerLineFunction =
false;
2965 for (AnnotatedLine *
Line : AnnotatedLines) {
2966 if (!
Line->First->Next)
2971 HasBinPackedFunction =
true;
2973 HasOnePerLineFunction =
true;
2978 if (Style.DerivePointerAlignment) {
2979 const auto NetRightCount = countVariableAlignments(AnnotatedLines);
2980 if (NetRightCount > 0)
2981 Style.PointerAlignment = FormatStyle::PAS_Right;
2982 else if (NetRightCount < 0)
2983 Style.PointerAlignment = FormatStyle::PAS_Left;
2984 Style.ReferenceAlignment = FormatStyle::RAS_Pointer;
2986 if (Style.Standard == FormatStyle::LS_Auto) {
2987 Style.Standard = hasCpp03IncompatibleFormat(AnnotatedLines)
2988 ? FormatStyle::LS_Latest
2989 : FormatStyle::LS_Cpp03;
2991 BinPackInconclusiveFunctions =
2992 HasBinPackedFunction || !HasOnePerLineFunction;
2995 bool BinPackInconclusiveFunctions;
2996 FormattingAttemptStatus *Status;
3012 TrailingCommaInserter(
const Environment &Env,
const FormatStyle &Style)
3013 : TokenAnalyzer(Env, Style) {}
3015 std::pair<tooling::Replacements, unsigned>
3016 analyze(TokenAnnotator &Annotator,
3017 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
3018 FormatTokenLexer &Tokens)
override {
3019 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
3020 tooling::Replacements
Result;
3021 insertTrailingCommas(AnnotatedLines,
Result);
3028 void insertTrailingCommas(SmallVectorImpl<AnnotatedLine *> &Lines,
3029 tooling::Replacements &
Result) {
3030 for (AnnotatedLine *
Line : Lines) {
3031 insertTrailingCommas(
Line->Children,
Result);
3032 if (!
Line->Affected)
3035 FormatTok = FormatTok->Next) {
3036 if (FormatTok->NewlinesBefore == 0)
3039 if (!Matching || !FormatTok->getPreviousNonComment())
3041 if (!(FormatTok->is(tok::r_square) &&
3042 Matching->is(TT_ArrayInitializerLSquare)) &&
3043 !(FormatTok->is(tok::r_brace) && Matching->is(TT_DictLiteral))) {
3046 FormatToken *Prev = FormatTok->getPreviousNonComment();
3047 if (Prev->is(tok::comma) || Prev->is(tok::semi))
3051 SourceLocation Start =
3052 Prev->Tok.getLocation().getLocWithOffset(Prev->TokenText.size());
3056 unsigned ColumnNumber =
3057 Env.getSourceManager().getSpellingColumnNumber(Start);
3058 if (ColumnNumber > Style.ColumnLimit)
3063 tooling::Replacement(Env.getSourceManager(), Start, 0,
",")));
3073 Cleaner(
const Environment &Env,
const FormatStyle &Style)
3074 : TokenAnalyzer(Env, Style),
3075 DeletedTokens(FormatTokenLess(Env.getSourceManager())) {}
3078 std::pair<tooling::Replacements, unsigned>
3079 analyze(TokenAnnotator &Annotator,
3080 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
3081 FormatTokenLexer &Tokens)
override {
3089 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
3091 checkEmptyNamespace(AnnotatedLines);
3093 for (
auto *
Line : AnnotatedLines)
3096 return {generateFixes(), 0};
3100 void cleanupLine(AnnotatedLine *
Line) {
3101 for (
auto *Child :
Line->Children)
3104 if (
Line->Affected) {
3105 cleanupRight(
Line->First, tok::comma, tok::comma);
3106 cleanupRight(
Line->First, TT_CtorInitializerColon, tok::comma);
3107 cleanupRight(
Line->First, tok::l_paren, tok::comma);
3108 cleanupLeft(
Line->First, tok::comma, tok::r_paren);
3109 cleanupLeft(
Line->First, TT_CtorInitializerComma, tok::l_brace);
3110 cleanupLeft(
Line->First, TT_CtorInitializerColon, tok::l_brace);
3111 cleanupLeft(
Line->First, TT_CtorInitializerColon, tok::equal);
3115 bool containsOnlyComments(
const AnnotatedLine &
Line) {
3117 if (
Tok->isNot(tok::comment))
3123 void checkEmptyNamespace(SmallVectorImpl<AnnotatedLine *> &AnnotatedLines) {
3124 std::set<unsigned> DeletedLines;
3125 for (
unsigned i = 0, e = AnnotatedLines.size(); i != e; ++i) {
3126 auto &
Line = *AnnotatedLines[i];
3127 if (
Line.startsWithNamespace())
3128 checkEmptyNamespace(AnnotatedLines, i, i, DeletedLines);
3131 for (
auto Line : DeletedLines) {
3144 bool checkEmptyNamespace(SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
3145 unsigned CurrentLine,
unsigned &NewLine,
3146 std::set<unsigned> &DeletedLines) {
3147 unsigned InitLine = CurrentLine, End = AnnotatedLines.size();
3148 if (Style.BraceWrapping.AfterNamespace) {
3152 if (!AnnotatedLines[++CurrentLine]->startsWith(tok::l_brace)) {
3153 NewLine = CurrentLine;
3156 }
else if (!AnnotatedLines[CurrentLine]->endsWith(tok::l_brace)) {
3159 while (++CurrentLine < End) {
3160 if (AnnotatedLines[CurrentLine]->startsWith(tok::r_brace))
3163 if (AnnotatedLines[CurrentLine]->startsWithNamespace()) {
3164 if (!checkEmptyNamespace(AnnotatedLines, CurrentLine, NewLine,
3168 CurrentLine = NewLine;
3172 if (containsOnlyComments(*AnnotatedLines[CurrentLine]))
3177 NewLine = CurrentLine;
3181 NewLine = CurrentLine;
3182 if (CurrentLine >= End)
3187 AnnotatedLines[InitLine]->First->Tok.getLocation(),
3188 AnnotatedLines[CurrentLine]->Last->Tok.getEndLoc()))) {
3192 for (
unsigned i = InitLine; i <= CurrentLine; ++i)
3193 DeletedLines.insert(i);
3202 template <
typename LeftKind,
typename RightKind>
3203 void cleanupPair(
FormatToken *Start, LeftKind LK, RightKind RK,
3206 for (
auto *Res =
Tok.Next; Res; Res = Res->Next) {
3207 if (Res->isNot(tok::comment) &&
3208 DeletedTokens.find(Res) == DeletedTokens.end()) {
3214 for (
auto *Left = Start;
Left;) {
3215 auto *
Right = NextNotDeleted(*Left);
3219 deleteToken(DeleteLeft ? Left : Right);
3231 template <
typename LeftKind,
typename RightKind>
3232 void cleanupLeft(
FormatToken *Start, LeftKind LK, RightKind RK) {
3233 cleanupPair(Start, LK, RK,
true);
3236 template <
typename LeftKind,
typename RightKind>
3237 void cleanupRight(
FormatToken *Start, LeftKind LK, RightKind RK) {
3238 cleanupPair(Start, LK, RK,
false);
3244 DeletedTokens.insert(
Tok);
3247 tooling::Replacements generateFixes() {
3248 tooling::Replacements Fixes;
3249 SmallVector<FormatToken *> Tokens;
3250 std::copy(DeletedTokens.begin(), DeletedTokens.end(),
3251 std::back_inserter(Tokens));
3257 while (Idx < Tokens.size()) {
3258 unsigned St = Idx, End = Idx;
3259 while ((End + 1) < Tokens.size() && Tokens[End]->Next == Tokens[End + 1])
3262 Tokens[End]->Tok.getEndLoc());
3264 Fixes.add(tooling::Replacement(Env.getSourceManager(), SR,
""));
3268 llvm::errs() <<
toString(std::move(Err)) <<
"\n";
3269 assert(
false &&
"Fixes must not conflict!");
3280 struct FormatTokenLess {
3281 FormatTokenLess(
const SourceManager &SM) : SM(SM) {}
3284 return SM.isBeforeInTranslationUnit(LHS->Tok.getLocation(),
3285 RHS->Tok.getLocation());
3287 const SourceManager &SM;
3291 std::set<FormatToken *, FormatTokenLess> DeletedTokens;
3296 ObjCHeaderStyleGuesser(
const Environment &Env,
const FormatStyle &Style)
3297 : TokenAnalyzer(Env, Style), IsObjC(
false) {}
3299 std::pair<tooling::Replacements, unsigned>
3300 analyze(TokenAnnotator &Annotator,
3301 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
3302 FormatTokenLexer &Tokens)
override {
3303 assert(Style.Language == FormatStyle::LK_Cpp);
3304 IsObjC = guessIsObjC(Env.getSourceManager(), AnnotatedLines,
3305 Tokens.getKeywords());
3306 tooling::Replacements
Result;
3310 bool isObjC() {
return IsObjC; }
3314 guessIsObjC(
const SourceManager &SourceManager,
3315 const SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
3316 const AdditionalKeywords &Keywords) {
3318 static constexpr llvm::StringLiteral FoundationIdentifiers[] = {
3333 "FOUNDATION_EXPORT",
3334 "FOUNDATION_EXTERN",
3335 "NSAffineTransform",
3337 "NSAttributedString",
3356 "NSInvocationOperation",
3360 "NSMutableAttributedString",
3361 "NSMutableCharacterSet",
3363 "NSMutableDictionary",
3364 "NSMutableIndexSet",
3365 "NSMutableOrderedSet",
3369 "NSNumberFormatter",
3373 "NSOperationQueuePriority",
3377 "NSQualityOfService",
3380 "NSRegularExpression",
3391 "NS_ASSUME_NONNULL_BEGIN",
3395 assert(llvm::is_sorted(FoundationIdentifiers));
3397 for (
auto *
Line : AnnotatedLines) {
3398 if (
Line->First && (
Line->First->TokenText.starts_with(
"#") ||
3399 Line->First->TokenText ==
"__pragma" ||
3400 Line->First->TokenText ==
"_Pragma")) {
3404 FormatTok = FormatTok->Next) {
3405 if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&
3406 (FormatTok->isNot(tok::objc_not_keyword) ||
3407 FormatTok->isOneOf(tok::numeric_constant, tok::l_square,
3409 (FormatTok->Tok.isAnyIdentifier() &&
3410 llvm::binary_search(FoundationIdentifiers,
3411 FormatTok->TokenText)) ||
3412 FormatTok->is(TT_ObjCStringLiteral) ||
3413 FormatTok->isOneOf(Keywords.kw_NS_CLOSED_ENUM, Keywords.kw_NS_ENUM,
3414 Keywords.kw_NS_ERROR_ENUM,
3415 Keywords.kw_NS_OPTIONS, TT_ObjCBlockLBrace,
3416 TT_ObjCBlockLParen, TT_ObjCDecl, TT_ObjCForIn,
3417 TT_ObjCMethodExpr, TT_ObjCMethodSpecifier,
3418 TT_ObjCProperty, TT_ObjCSelector)) {
3419 LLVM_DEBUG(llvm::dbgs()
3420 <<
"Detected ObjC at location "
3421 << FormatTok->Tok.getLocation().printToString(
3423 <<
" token: " << FormatTok->TokenText <<
" token type: "
3428 if (guessIsObjC(SourceManager,
Line->Children, Keywords))
3437struct IncludeDirective {
3445struct JavaImportDirective {
3446 StringRef Identifier;
3449 SmallVector<StringRef> AssociatedCommentLines;
3458 for (
const auto &Range : Ranges) {
3459 if (Range.getOffset() < End &&
3460 Range.getOffset() + Range.getLength() > Start) {
3475static std::pair<unsigned, unsigned>
3478 unsigned CursorIndex = std::numeric_limits<unsigned>::max();
3479 unsigned OffsetToEOL = 0;
3480 for (
int i = 0, e = Includes.size(); i != e; ++i) {
3481 unsigned Start = Includes[Indices[i]].Offset;
3482 unsigned End = Start + Includes[Indices[i]].Text.size();
3483 if (!(Cursor >= Start && Cursor < End))
3485 CursorIndex = Indices[i];
3486 OffsetToEOL = End - Cursor;
3489 while (--i >= 0 && Includes[CursorIndex].
Text == Includes[Indices[i]].
Text)
3493 return std::make_pair(CursorIndex, OffsetToEOL);
3498 std::string NewCode;
3499 size_t Pos = 0, LastPos = 0;
3502 Pos = Code.find(
"\r\n", LastPos);
3503 if (Pos == LastPos) {
3507 if (Pos == std::string::npos) {
3508 NewCode += Code.substr(LastPos);
3511 NewCode += Code.substr(LastPos, Pos - LastPos) +
"\n";
3513 }
while (Pos != std::string::npos);
3531 const unsigned IncludesBeginOffset = Includes.front().Offset;
3532 const unsigned IncludesEndOffset =
3533 Includes.back().Offset + Includes.back().Text.size();
3534 const unsigned IncludesBlockSize = IncludesEndOffset - IncludesBeginOffset;
3535 if (!
affectsRange(Ranges, IncludesBeginOffset, IncludesEndOffset))
3538 llvm::to_vector<16>(llvm::seq<unsigned>(0, Includes.size()));
3540 if (Style.SortIncludes.Enabled) {
3541 stable_sort(Indices, [&](
unsigned LHSI,
unsigned RHSI) {
3543 if (Style.SortIncludes.IgnoreExtension) {
3544 LHSStem = Includes[LHSI].Filename;
3545 RHSStem = Includes[RHSI].Filename;
3546 llvm::sys::path::replace_extension(LHSStem,
"");
3547 llvm::sys::path::replace_extension(RHSStem,
"");
3549 std::string LHSStemLower, RHSStemLower;
3550 std::string LHSFilenameLower, RHSFilenameLower;
3551 if (Style.SortIncludes.IgnoreCase) {
3552 LHSStemLower = LHSStem.str().lower();
3553 RHSStemLower = RHSStem.str().lower();
3554 LHSFilenameLower = Includes[LHSI].Filename.lower();
3555 RHSFilenameLower = Includes[RHSI].Filename.lower();
3557 return std::tie(Includes[LHSI].Priority, LHSStemLower, LHSStem,
3558 LHSFilenameLower, Includes[LHSI].Filename) <
3559 std::tie(Includes[RHSI].Priority, RHSStemLower, RHSStem,
3560 RHSFilenameLower, Includes[RHSI].Filename);
3566 unsigned CursorIndex;
3568 unsigned CursorToEOLOffset;
3570 std::tie(CursorIndex, CursorToEOLOffset) =
3575 Indices.erase(llvm::unique(Indices,
3576 [&](
unsigned LHSI,
unsigned RHSI) {
3577 return Includes[LHSI].Text.trim() ==
3578 Includes[RHSI].Text.trim();
3582 int CurrentCategory = Includes.front().Category;
3590 if (Indices.size() == Includes.size() && is_sorted(Indices) &&
3595 const auto OldCursor = Cursor ? *Cursor : 0;
3597 for (
unsigned Index : Indices) {
3598 if (!result.empty()) {
3600 if (Style.IncludeStyle.IncludeBlocks ==
3602 CurrentCategory != Includes[Index].Category) {
3606 result += Includes[Index].Text;
3607 if (Cursor && CursorIndex == Index)
3608 *Cursor = IncludesBeginOffset + result.size() - CursorToEOLOffset;
3609 CurrentCategory = Includes[Index].Category;
3612 if (Cursor && *Cursor >= IncludesEndOffset)
3613 *Cursor += result.size() - IncludesBlockSize;
3618 IncludesBeginOffset, IncludesBlockSize)))) {
3620 *Cursor = OldCursor;
3625 FileName, Includes.front().Offset, IncludesBlockSize, result));
3629 llvm::errs() <<
toString(std::move(Err)) <<
"\n";
3639 unsigned Prev = llvm::StringSwitch<size_t>(Code)
3640 .StartsWith(
"\xEF\xBB\xBF", 3)
3642 unsigned SearchFrom = 0;
3654 bool FirstIncludeBlock =
true;
3655 bool MainIncludeFound =
false;
3656 bool FormattingOff =
false;
3659 llvm::Regex RawStringRegex(
3660 "R\"([][A-Za-z0-9_{}#<>%:;.?*+/^&\\$|~!=,'-]*)\\(");
3662 std::string RawStringTermination =
")\"";
3664 for (
const auto Size = Code.size(); SearchFrom < Size;) {
3665 size_t Pos = SearchFrom;
3666 if (Code[SearchFrom] !=
'\n') {
3669 Pos = Code.find(
'\n', Pos);
3670 }
while (Pos != StringRef::npos && Code[Pos - 1] ==
'\\');
3674 Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev);
3676 StringRef Trimmed =
Line.trim();
3681 if (RawStringRegex.match(Trimmed, &RawStringMatches)) {
3682 std::string CharSequence = RawStringMatches[1].str();
3683 RawStringTermination =
")" + CharSequence +
"\"";
3684 FormattingOff =
true;
3687 if (Trimmed.contains(RawStringTermination))
3688 FormattingOff =
false;
3690 bool IsBlockComment =
false;
3693 FormattingOff =
true;
3695 FormattingOff =
false;
3696 }
else if (Trimmed.starts_with(
"/*")) {
3697 IsBlockComment =
true;
3698 Pos = Code.find(
"*/", SearchFrom + 2);
3701 const bool EmptyLineSkipped =
3704 Style.IncludeStyle.IncludeBlocks ==
3707 bool MergeWithNextLine = Trimmed.ends_with(
"\\");
3708 if (!FormattingOff && !MergeWithNextLine) {
3709 if (!IsBlockComment &&
3711 StringRef IncludeName = Matches[2];
3712 if (Trimmed.contains(
"/*") && !Trimmed.contains(
"*/")) {
3717 Pos = Code.find(
"*/", SearchFrom);
3719 Prev, (Pos != StringRef::npos ? Pos + 2 : Code.size()) - Prev);
3723 !MainIncludeFound && FirstIncludeBlock);
3725 IncludeName, !MainIncludeFound && FirstIncludeBlock);
3727 MainIncludeFound =
true;
3728 IncludesInBlock.push_back(
3729 {IncludeName,
Line, Prev, Category, Priority});
3730 }
else if (!IncludesInBlock.empty() && !EmptyLineSkipped) {
3733 IncludesInBlock.clear();
3734 if (Trimmed.starts_with(
"#pragma hdrstop"))
3735 FirstIncludeBlock =
true;
3737 FirstIncludeBlock =
false;
3740 if (Pos == StringRef::npos || Pos + 1 == Code.size())
3743 if (!MergeWithNextLine)
3745 SearchFrom = Pos + 1;
3747 if (!IncludesInBlock.empty()) {
3758 StringRef ImportIdentifier) {
3759 unsigned LongestMatchIndex = std::numeric_limits<unsigned>::max();
3760 unsigned LongestMatchLength = 0;
3761 for (
unsigned I = 0; I < Style.JavaImportGroups.size(); I++) {
3762 const std::string &GroupPrefix = Style.JavaImportGroups[I];
3763 if (ImportIdentifier.starts_with(GroupPrefix) &&
3764 GroupPrefix.length() > LongestMatchLength) {
3765 LongestMatchIndex = I;
3766 LongestMatchLength = GroupPrefix.length();
3769 return LongestMatchIndex;
3781 unsigned ImportsBeginOffset = Imports.front().Offset;
3782 unsigned ImportsEndOffset =
3783 Imports.back().Offset + Imports.back().Text.size();
3784 unsigned ImportsBlockSize = ImportsEndOffset - ImportsBeginOffset;
3785 if (!
affectsRange(Ranges, ImportsBeginOffset, ImportsEndOffset))
3789 llvm::to_vector<16>(llvm::seq<unsigned>(0, Imports.size()));
3792 for (
const JavaImportDirective &Import : Imports)
3795 bool StaticImportAfterNormalImport =
3796 Style.SortJavaStaticImport == FormatStyle::SJSIO_After;
3797 sort(Indices, [&](
unsigned LHSI,
unsigned RHSI) {
3799 return std::make_tuple(!Imports[LHSI].IsStatic ^
3800 StaticImportAfterNormalImport,
3802 std::make_tuple(!Imports[RHSI].IsStatic ^
3803 StaticImportAfterNormalImport,
3808 Indices.erase(llvm::unique(Indices,
3809 [&](
unsigned LHSI,
unsigned RHSI) {
3810 return Imports[LHSI].Text == Imports[RHSI].Text;
3814 bool CurrentIsStatic = Imports[Indices.front()].IsStatic;
3818 for (
unsigned Index : Indices) {
3819 if (!result.empty()) {
3821 if (CurrentIsStatic != Imports[Index].IsStatic ||
3826 for (StringRef CommentLine : Imports[Index].AssociatedCommentLines) {
3827 result += CommentLine;
3830 result += Imports[Index].Text;
3831 CurrentIsStatic = Imports[Index].IsStatic;
3838 Imports.front().Offset, ImportsBlockSize)))) {
3843 ImportsBlockSize, result));
3847 llvm::errs() <<
toString(std::move(Err)) <<
"\n";
3855 JavaImportRegexPattern(
"^import[\t ]+(static[\t ]*)?([^\t ]*)[\t ]*;");
3857constexpr StringRef JavaPackageRegexPattern(
"^package[\t ]");
3866 bool HasImport =
false;
3867 llvm::Regex ImportRegex(JavaImportRegexPattern);
3868 llvm::Regex PackageRegex(JavaPackageRegexPattern);
3873 for (
bool FormattingOff =
false;;) {
3874 auto Pos = Code.find(
'\n', Prev);
3875 auto GetLine = [&] {
3876 return Code.substr(Prev,
3877 (Pos != StringRef::npos ? Pos : Code.size()) - Prev);
3879 StringRef
Line = GetLine();
3881 StringRef Trimmed =
Line.trim();
3882 if (Trimmed.empty() || PackageRegex.match(Trimmed)) {
3885 FormattingOff =
true;
3887 FormattingOff =
false;
3888 }
else if (Trimmed.starts_with(
"//")) {
3891 AssociatedCommentLines.push_back(
Line);
3892 }
else if (Trimmed.starts_with(
"/*")) {
3893 Pos = Code.find(
"*/", Pos + 2);
3894 if (Pos != StringRef::npos)
3895 Pos = Code.find(
'\n', Pos + 2);
3900 AssociatedCommentLines.push_back(
Line);
3902 }
else if (ImportRegex.match(Trimmed, &Matches)) {
3903 if (FormattingOff) {
3908 StringRef
Static = Matches[1];
3909 StringRef Identifier = Matches[2];
3910 bool IsStatic =
false;
3911 if (
Static.contains(
"static"))
3913 ImportsInBlock.push_back(
3914 {Identifier,
Line, Prev, AssociatedCommentLines, IsStatic});
3916 AssociatedCommentLines.clear();
3922 if (Pos == StringRef::npos || Pos + 1 == Code.size())
3935 return Code.size() > 188 && Code[0] == 0x47 && Code[188] == 0x47;
3938bool isLikelyXml(StringRef Code) {
return Code.ltrim().starts_with(
"<"); }
3942 StringRef
FileName,
unsigned *Cursor) {
3944 if (!Style.SortIncludes.Enabled || Style.DisableFormat)
3948 if (Style.isJavaScript()) {
3960template <
typename T>
3964 const FormatStyle &Style) {
3965 if (Replaces.
empty())
3968 auto NewCode = applyAllReplacements(Code, Replaces);
3970 return NewCode.takeError();
3975 ProcessFunc(Style, *NewCode, ChangedRanges,
FileName);
3977 return Replaces.
merge(FormatReplaces);
3982 const FormatStyle &Style) {
3985 auto SortIncludes = [](
const FormatStyle &Style, StringRef Code,
3986 std::vector<tooling::Range> Ranges,
3990 auto SortedReplaces =
3992 if (!SortedReplaces)
3993 return SortedReplaces.takeError();
3997 auto Reformat = [](
const FormatStyle &Style, StringRef Code,
3998 std::vector<tooling::Range> Ranges,
4008 return Replace.
getOffset() == std::numeric_limits<unsigned>::max() &&
4014inline bool isHeaderDeletion(
const tooling::Replacement &Replace) {
4015 return Replace.getOffset() == std::numeric_limits<unsigned>::max() &&
4016 Replace.getLength() == 1;
4020tooling::Replacements
4021fixCppIncludeInsertions(StringRef Code,
const tooling::Replacements &Replaces,
4022 const FormatStyle &Style) {
4026 tooling::Replacements HeaderInsertions;
4027 std::set<StringRef> HeadersToDelete;
4028 tooling::Replacements
Result;
4029 for (
const auto &R : Replaces) {
4030 if (isHeaderInsertion(R)) {
4033 consumeError(HeaderInsertions.add(R));
4034 }
else if (isHeaderDeletion(R)) {
4035 HeadersToDelete.insert(
R.getReplacementText());
4036 }
else if (
R.getOffset() == std::numeric_limits<unsigned>::max()) {
4037 llvm::errs() <<
"Insertions other than header #include insertion are "
4039 <<
R.getReplacementText() <<
"\n";
4041 consumeError(
Result.add(R));
4044 if (HeaderInsertions.empty() && HeadersToDelete.empty())
4047 StringRef
FileName = Replaces.begin()->getFilePath();
4048 tooling::HeaderIncludes Includes(
FileName, Code, Style.IncludeStyle);
4050 for (
const auto &Header : HeadersToDelete) {
4051 tooling::Replacements Replaces =
4052 Includes.remove(Header.trim(
"\"<>"), Header.starts_with(
"<"));
4053 for (
const auto &R : Replaces) {
4054 auto Err =
Result.add(R);
4057 llvm::errs() <<
"Failed to add header deletion replacement for "
4058 << Header <<
": " <<
toString(std::move(Err)) <<
"\n";
4064 for (
const auto &R : HeaderInsertions) {
4065 auto IncludeDirective =
R.getReplacementText();
4068 assert(Matched &&
"Header insertion replacement must have replacement text "
4071 auto IncludeName = Matches[2];
4073 Includes.insert(IncludeName.trim(
"\"<>"), IncludeName.starts_with(
"<"),
4076 auto Err =
Result.add(*Replace);
4078 consumeError(std::move(Err));
4079 unsigned NewOffset =
4080 Result.getShiftedCodePosition(Replace->getOffset());
4081 auto Shifted = tooling::Replacement(
FileName, NewOffset, 0,
4082 Replace->getReplacementText());
4094 const FormatStyle &Style) {
4097 auto Cleanup = [](
const FormatStyle &Style, StringRef Code,
4104 fixCppIncludeInsertions(Code, Replaces, Style);
4109std::pair<tooling::Replacements, unsigned>
4112 unsigned NextStartColumn,
unsigned LastStartColumn, StringRef
FileName,
4114 FormatStyle Expanded = Style;
4120 Expanded.InsertBraces =
false;
4121 Expanded.RemoveBracesLLVM =
false;
4122 Expanded.RemoveParentheses = FormatStyle::RPS_Leave;
4123 Expanded.RemoveSemicolon =
false;
4126 switch (Expanded.RequiresClausePosition) {
4127 case FormatStyle::RCPS_SingleLine:
4128 case FormatStyle::RCPS_WithPreceding:
4129 Expanded.IndentRequiresClause =
false;
4134 if (Expanded.BraceWrapping.AfterEnum)
4135 Expanded.AllowShortEnumsOnASingleLine =
false;
4137 if (Expanded.DisableFormat)
4141 if (Expanded.isJavaScript() &&
isMpegTS(Code))
4145 if (Style.isJson()) {
4146 std::vector<tooling::Range> Ranges(1,
tooling::Range(0, Code.size()));
4148 NextStartColumn, LastStartColumn);
4153 Formatter(*Env, Style, Status).process().first;
4155 if (Code.starts_with(
"x = ")) {
4156 Replaces = Replaces.
merge(
4160 if (applyAllReplacements(Code, Replaces))
4161 return {Replaces, 0};
4166 NextStartColumn, LastStartColumn);
4184 if (Style.isCpp()) {
4185 if (Style.QualifierAlignment != FormatStyle::QAS_Leave)
4188 if (Style.RemoveParentheses != FormatStyle::RPS_Leave) {
4189 FormatStyle S = Expanded;
4190 S.RemoveParentheses = Style.RemoveParentheses;
4191 Passes.emplace_back([&, S = std::move(S)](
const Environment &Env) {
4192 return ParensRemover(Env, S).process(
true);
4196 if (Style.InsertBraces) {
4197 FormatStyle S = Expanded;
4198 S.InsertBraces =
true;
4199 Passes.emplace_back([&, S = std::move(S)](
const Environment &Env) {
4200 return BracesInserter(Env, S).process(
true);
4204 if (Style.RemoveBracesLLVM) {
4205 FormatStyle S = Expanded;
4206 S.RemoveBracesLLVM =
true;
4207 Passes.emplace_back([&, S = std::move(S)](
const Environment &Env) {
4208 return BracesRemover(Env, S).process(
true);
4212 if (Style.RemoveSemicolon) {
4213 FormatStyle S = Expanded;
4214 S.RemoveSemicolon =
true;
4215 Passes.emplace_back([&, S = std::move(S)](
const Environment &Env) {
4216 return SemiRemover(Env, S).process();
4220 if (Style.EnumTrailingComma != FormatStyle::ETC_Leave) {
4222 return EnumTrailingCommaEditor(Env, Expanded)
4227 if (Style.FixNamespaceComments) {
4233 if (Style.SortUsingDeclarations != FormatStyle::SUD_Never) {
4240 if (Style.SeparateDefinitionBlocks != FormatStyle::SDS_Leave) {
4246 if (Style.Language == FormatStyle::LK_ObjC &&
4247 !Style.ObjCPropertyAttributeOrder.empty()) {
4253 if (Style.isJavaScript() &&
4254 Style.JavaScriptQuotes != FormatStyle::JSQS_Leave) {
4256 return JavaScriptRequoter(Env, Expanded).process(
true);
4261 return Formatter(Env, Expanded, Status).process();
4264 if (Style.isJavaScript() &&
4265 Style.InsertTrailingCommas == FormatStyle::TCS_Wrapped) {
4267 return TrailingCommaInserter(Env, Expanded).process();
4271 std::optional<std::string> CurrentCode;
4273 unsigned Penalty = 0;
4274 for (
size_t I = 0, E = Passes.size(); I < E; ++I) {
4275 std::pair<tooling::Replacements, unsigned> PassFixes = Passes[I](*Env);
4276 auto NewCode = applyAllReplacements(
4277 CurrentCode ? StringRef(*CurrentCode) : Code, PassFixes.first);
4279 Fixes = Fixes.
merge(PassFixes.first);
4280 Penalty += PassFixes.second;
4282 CurrentCode = std::move(*NewCode);
4286 FirstStartColumn, NextStartColumn, LastStartColumn);
4293 if (Style.QualifierAlignment != FormatStyle::QAS_Leave) {
4299 StringRef OriginalCode = Code.substr(Fix.getOffset(), Fix.getLength());
4300 if (OriginalCode != Fix.getReplacementText()) {
4301 auto Err = NonNoOpFixes.
add(Fix);
4303 llvm::errs() <<
"Error adding replacements : "
4304 <<
toString(std::move(Err)) <<
"\n";
4308 Fixes = std::move(NonNoOpFixes);
4311 return {Fixes, Penalty};
4330 if (Style.Language != FormatStyle::LK_Cpp)
4335 return Cleaner(*Env, Style).process().first;
4340 StringRef
FileName,
bool *IncompleteFormat) {
4343 if (!Status.FormatComplete)
4344 *IncompleteFormat =
true;
4371 auto LexingStd = Style.Standard;
4372 if (LexingStd == FormatStyle::LS_Auto || LexingStd == FormatStyle::LS_Latest)
4373 LexingStd = FormatStyle::LS_Cpp20;
4375 const bool SinceCpp11 = LexingStd >= FormatStyle::LS_Cpp11;
4376 const bool SinceCpp20 = LexingStd >= FormatStyle::LS_Cpp20;
4378 switch (Style.Language) {
4379 case FormatStyle::LK_C:
4383 case FormatStyle::LK_Cpp:
4384 case FormatStyle::LK_ObjC:
4385 LangOpts.CXXOperatorNames = 1;
4386 LangOpts.CPlusPlus11 = SinceCpp11;
4387 LangOpts.CPlusPlus14 = LexingStd >= FormatStyle::LS_Cpp14;
4388 LangOpts.CPlusPlus17 = LexingStd >= FormatStyle::LS_Cpp17;
4389 LangOpts.CPlusPlus20 = SinceCpp20;
4392 LangOpts.CPlusPlus = 1;
4395 LangOpts.Char8 = SinceCpp20;
4396 LangOpts.AllowLiteralDigitSeparator = LangOpts.CPlusPlus14 || LangOpts.C23;
4400 LangOpts.Digraphs = SinceCpp11;
4402 LangOpts.LineComment = 1;
4405 LangOpts.MicrosoftExt = 1;
4406 LangOpts.DeclSpecKeyword = 1;
4413 "Set coding style. <string> can be:\n"
4414 "1. A preset: LLVM, GNU, Google, Chromium, Microsoft,\n"
4415 " Mozilla, WebKit.\n"
4416 "2. 'file' to load style configuration from a\n"
4417 " .clang-format file in one of the parent directories\n"
4418 " of the source file (for stdin, see --assume-filename).\n"
4419 " If no .clang-format file is found, falls back to\n"
4420 " --fallback-style.\n"
4421 " --style=file is the default.\n"
4422 "3. 'file:<format_file_path>' to explicitly specify\n"
4423 " the configuration file.\n"
4424 "4. \"{key: value, ...}\" to set specific parameters, e.g.:\n"
4425 " --style=\"{BasedOnStyle: llvm, IndentWidth: 8}\"";
4429 return FormatStyle::LK_C;
4431 return FormatStyle::LK_Java;
4432 if (
FileName.ends_with_insensitive(
".js") ||
4433 FileName.ends_with_insensitive(
".mjs") ||
4434 FileName.ends_with_insensitive(
".cjs") ||
4435 FileName.ends_with_insensitive(
".ts")) {
4436 return FormatStyle::LK_JavaScript;
4439 return FormatStyle::LK_ObjC;
4440 if (
FileName.ends_with_insensitive(
".proto") ||
4441 FileName.ends_with_insensitive(
".protodevel")) {
4442 return FormatStyle::LK_Proto;
4447 if (
FileName.ends_with_insensitive(
".txtpb") ||
4448 FileName.ends_with_insensitive(
".textpb") ||
4449 FileName.ends_with_insensitive(
".pb.txt") ||
4450 FileName.ends_with_insensitive(
".textproto") ||
4451 FileName.ends_with_insensitive(
".asciipb")) {
4452 return FormatStyle::LK_TextProto;
4454 if (
FileName.ends_with_insensitive(
".td"))
4455 return FormatStyle::LK_TableGen;
4456 if (
FileName.ends_with_insensitive(
".cs"))
4457 return FormatStyle::LK_CSharp;
4458 if (
FileName.ends_with_insensitive(
".json") ||
4459 FileName.ends_with_insensitive(
".ipynb")) {
4460 return FormatStyle::LK_Json;
4462 if (
FileName.ends_with_insensitive(
".sv") ||
4463 FileName.ends_with_insensitive(
".svh") ||
4464 FileName.ends_with_insensitive(
".v") ||
4465 FileName.ends_with_insensitive(
".vh")) {
4466 return FormatStyle::LK_Verilog;
4468 return FormatStyle::LK_Cpp;
4476 LangOpts.CPlusPlus = 1;
4477 LangOpts.LineComment = 1;
4479 Lexer Lex(ID, SourceMgr.getBufferOrFake(ID), SourceMgr, LangOpts);
4483 auto Text = StringRef(SourceMgr.getCharacterData(
Tok.getLocation()),
4485 if (!
Text.consume_front(
"// clang-format Language:"))
4490 return FormatStyle::LK_C;
4492 return FormatStyle::LK_Cpp;
4494 return FormatStyle::LK_ObjC;
4497 return FormatStyle::LK_None;
4502 if (GuessedLanguage == FormatStyle::LK_Cpp) {
4503 auto Extension = llvm::sys::path::extension(
FileName);
4506 if (!Code.empty() && (Extension.empty() || Extension ==
".h")) {
4510 Language != FormatStyle::LK_None) {
4515 if (Guesser.isObjC())
4516 return FormatStyle::LK_ObjC;
4519 return GuessedLanguage;
4527llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
4529 FormatStyle *Style,
bool AllowUnknownOptions,
4530 llvm::SourceMgr::DiagHandlerTy DiagHandler,
4532 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
Text =
4533 FS->getBufferForFile(ConfigFile.str());
4534 if (
auto EC =
Text.getError())
4537 DiagHandler,
nullptr,
4545 StringRef FallbackStyleName, StringRef Code,
4546 llvm::vfs::FileSystem *FS,
4547 bool AllowUnknownOptions,
4548 llvm::SourceMgr::DiagHandlerTy DiagHandler) {
4556 if (StyleName.starts_with(
"{")) {
4558 StringRef Source =
"<command-line>";
4559 if (std::error_code ec =
4561 AllowUnknownOptions, DiagHandler)) {
4565 if (Style.InheritConfig.empty())
4568 ChildFormatTextToApply.emplace_back(
4569 llvm::MemoryBuffer::getMemBuffer(StyleName, Source,
false));
4573 FS = llvm::vfs::getRealFileSystem().get();
4576 const bool IsDotHFile =
FileName.ends_with(
".h");
4579 if (Style.InheritConfig.empty() &&
4580 StyleName.starts_with_insensitive(
"file:")) {
4581 auto ConfigFile = StyleName.substr(5);
4582 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
Text =
4584 DiagHandler, IsDotHFile);
4585 if (
auto EC =
Text.getError()) {
4590 LLVM_DEBUG(llvm::dbgs()
4591 <<
"Using configuration file " << ConfigFile <<
"\n");
4593 if (Style.InheritConfig.empty())
4599 ChildFormatTextToApply.emplace_back(std::move(*
Text));
4605 if (Style.InheritConfig.empty() && !StyleName.equals_insensitive(
"file")) {
4608 if (Style.InheritConfig.empty())
4612 using namespace llvm::sys::path;
4616 if (std::error_code EC = FS->makeAbsolute(Path))
4619 auto Normalize = [](String &Path) {
4620 Path = convert_to_slash(Path);
4621 remove_dots(Path,
true, Style::posix);
4627 Style.InheritConfig.clear();
4629 auto dropDiagnosticHandler = [](
const llvm::SMDiagnostic &,
void *) {};
4631 auto applyChildFormatTexts = [&](FormatStyle *Style) {
4632 for (
const auto &MemBuf : llvm::reverse(ChildFormatTextToApply)) {
4635 DiagHandler ? DiagHandler : dropDiagnosticHandler);
4638 static_cast<void>(EC);
4644 FilesToLookFor.push_back(
".clang-format");
4645 FilesToLookFor.push_back(
"_clang-format");
4647 llvm::StringSet<> Directories;
4648 bool Redirected =
false;
4649 String Dir, UnsuitableConfigFiles;
4650 for (StringRef Directory = Path; !Directory.empty();
4651 Directory = Redirected ? Dir.str() : parent_path(Directory)) {
4652 auto Status = FS->status(Directory);
4654 Status->getType() != llvm::sys::fs::file_type::directory_file) {
4661 for (
const auto &F : FilesToLookFor) {
4662 String ConfigFile(Directory);
4664 append(ConfigFile, F);
4665 LLVM_DEBUG(llvm::dbgs() <<
"Trying " << ConfigFile <<
"...\n");
4667 Status = FS->status(ConfigFile);
4669 Status->getType() != llvm::sys::fs::file_type::regular_file) {
4673 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
Text =
4675 DiagHandler, IsDotHFile);
4676 if (
auto EC =
Text.getError()) {
4681 if (!UnsuitableConfigFiles.empty())
4682 UnsuitableConfigFiles.append(
", ");
4683 UnsuitableConfigFiles.append(ConfigFile);
4687 LLVM_DEBUG(llvm::dbgs()
4688 <<
"Using configuration file " << ConfigFile <<
"\n");
4690 if (Style.InheritConfig.empty()) {
4691 if (!ChildFormatTextToApply.empty()) {
4692 LLVM_DEBUG(llvm::dbgs() <<
"Applying child configurations\n");
4693 applyChildFormatTexts(&Style);
4698 if (!Directories.insert(Directory).second) {
4700 "Loop detected when inheriting configuration file in " + Directory);
4703 LLVM_DEBUG(llvm::dbgs() <<
"Inherits parent configuration\n");
4705 if (Style.InheritConfig ==
"..") {
4710 llvm::sys::fs::expand_tilde(Style.InheritConfig, ExpandedDir);
4711 Normalize(ExpandedDir);
4712 if (is_absolute(ExpandedDir, Style::posix)) {
4715 Dir = Directory.str();
4716 append(Dir, Style::posix, ExpandedDir);
4721 Style.InheritConfig.clear();
4723 ChildFormatTextToApply.emplace_back(std::move(*
Text));
4733 if (!UnsuitableConfigFiles.empty()) {
4736 UnsuitableConfigFiles);
4739 if (!ChildFormatTextToApply.empty()) {
4740 LLVM_DEBUG(llvm::dbgs()
4741 <<
"Applying child configurations on fallback style\n");
4742 applyChildFormatTexts(&FallbackStyle);
4745 return FallbackStyle;
4749 if (Comment == (On ?
"/* clang-format on */" :
"/* clang-format off */"))
4752 static const char ClangFormatOn[] =
"// clang-format on";
4753 static const char ClangFormatOff[] =
"// clang-format off";
4754 const unsigned Size = (On ?
sizeof ClangFormatOn :
sizeof ClangFormatOff) - 1;
4756 return Comment.starts_with(On ? ClangFormatOn : ClangFormatOff) &&
4757 (Comment.size() == Size || Comment[Size] ==
':');
This file declares DefinitionBlockSeparator, a TokenAnalyzer that inserts or removes empty lines sepa...
This file declares IntegerLiteralSeparatorFixer that fixes C++ integer literal separators.
This file declares NumericLiteralCaseFixer that standardizes character case within numeric literals.
This file declares ObjCPropertyAttributeOrderFixer, a TokenAnalyzer that adjusts the order of attribu...
This file declares QualifierAlignmentFixer, a TokenAnalyzer that enforces either east or west const d...
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
This file implements a sorter for JavaScript ES6 imports.
This file declares UsingDeclarationsSorter, a TokenAnalyzer that sorts consecutive using declarations...
static CharSourceRange getCharRange(SourceRange R)
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens.
bool LexFromRawLexer(Token &Result)
LexFromRawLexer - Lex a token from a designated raw lexer (one with no associated preprocessor object...
void SetCommentRetentionState(bool Mode)
SetCommentRetentionMode - Change the comment retention mode of the lexer to the specified mode.
Token - This structure provides full information about a lexed token.
SmallVector< BoundNodes, 1 > match(MatcherT Matcher, const NodeT &Node, ASTContext &Context)
Returns the results of matching Matcher on Node.
bool isObjC(ID Id)
isObjC - Is this an "ObjC" input (Obj-C and Obj-C++ sources and headers).
const char * getTokenName(TokenKind Kind) LLVM_READNONE
Determines the name of a token as used within the front end.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
const char * getPunctuatorSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple punctuation tokens like '!
The JSON file list parser is used to communicate input to InstallAPI.
std::vector< std::string > JavaImportGroups
A vector of prefixes ordered by the desired groups for Java imports.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
Language
The language for the input, used to select and validate the language standard and possible actions.
@ Result
The result type of a method or function.
SortIncludesOptions SortIncludes
Controls if and how clang-format will sort #includes.
Diagnostic wrappers for TextAPI types for error reporting.
int const char * function
static void enumeration(IO &IO, BracketAlignmentStyle &Value)
static void enumeration(IO &IO, FormatStyle::IndentExternBlockStyle &Value)
static void enumeration(IO &IO, FormatStyle::LambdaBodyIndentationKind &Value)
static void enumeration(IO &IO, FormatStyle::WrapNamespaceBodyWithEmptyLinesStyle &Value)
static StringRef input(StringRef Scalar, void *, clang::tok::TokenKind &Value)
static QuotingType mustQuote(StringRef)
static void output(const clang::tok::TokenKind &Value, void *, llvm::raw_ostream &Out)