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)
49struct ScalarEnumerationTraits<FormatStyle::BreakBeforeNoexceptSpecifierStyle> {
52 IO.enumCase(
Value,
"Never", FormatStyle::BBNSS_Never);
53 IO.enumCase(
Value,
"OnlyWithParen", FormatStyle::BBNSS_OnlyWithParen);
54 IO.enumCase(
Value,
"Always", FormatStyle::BBNSS_Always);
58template <>
struct MappingTraits<FormatStyle::AlignConsecutiveStyle> {
60 IO.enumCase(
Value,
"None", FormatStyle::AlignConsecutiveStyle{});
61 IO.enumCase(
Value,
"Consecutive",
62 FormatStyle::AlignConsecutiveStyle(
68 IO.enumCase(
Value,
"AcrossEmptyLines",
69 FormatStyle::AlignConsecutiveStyle(
75 IO.enumCase(
Value,
"AcrossComments",
76 FormatStyle::AlignConsecutiveStyle(
82 IO.enumCase(
Value,
"AcrossEmptyLinesAndComments",
83 FormatStyle::AlignConsecutiveStyle(
91 IO.enumCase(
Value,
"true",
92 FormatStyle::AlignConsecutiveStyle(
98 IO.enumCase(
Value,
"false", FormatStyle::AlignConsecutiveStyle{});
101 static void mapping(IO &IO, FormatStyle::AlignConsecutiveStyle &
Value) {
102 IO.mapOptional(
"Enabled",
Value.Enabled);
103 IO.mapOptional(
"AcrossEmptyLines",
Value.AcrossEmptyLines);
104 IO.mapOptional(
"AcrossComments",
Value.AcrossComments);
105 IO.mapOptional(
"AlignCompound",
Value.AlignCompound);
106 IO.mapOptional(
"AlignFunctionDeclarations",
107 Value.AlignFunctionDeclarations);
108 IO.mapOptional(
"AlignFunctionPointers",
Value.AlignFunctionPointers);
109 IO.mapOptional(
"EnumAssignments",
Value.EnumAssignments);
110 IO.mapOptional(
"PadOperators",
Value.PadOperators);
115struct MappingTraits<FormatStyle::ShortCaseStatementsAlignmentStyle> {
117 FormatStyle::ShortCaseStatementsAlignmentStyle &
Value) {
118 IO.mapOptional(
"Enabled",
Value.Enabled);
119 IO.mapOptional(
"AcrossEmptyLines",
Value.AcrossEmptyLines);
120 IO.mapOptional(
"AcrossComments",
Value.AcrossComments);
121 IO.mapOptional(
"AlignCaseArrows",
Value.AlignCaseArrows);
122 IO.mapOptional(
"AlignCaseColons",
Value.AlignCaseColons);
127struct ScalarEnumerationTraits<FormatStyle::AttributeBreakingStyle> {
129 IO.enumCase(
Value,
"Always", FormatStyle::ABS_Always);
130 IO.enumCase(
Value,
"Leave", FormatStyle::ABS_Leave);
131 IO.enumCase(
Value,
"LeaveAll", FormatStyle::ABS_LeaveAll);
132 IO.enumCase(
Value,
"Never", FormatStyle::ABS_Never);
137struct ScalarEnumerationTraits<FormatStyle::ArrayInitializerAlignmentStyle> {
139 FormatStyle::ArrayInitializerAlignmentStyle &
Value) {
140 IO.enumCase(
Value,
"None", FormatStyle::AIAS_None);
141 IO.enumCase(
Value,
"Left", FormatStyle::AIAS_Left);
142 IO.enumCase(
Value,
"Right", FormatStyle::AIAS_Right);
146template <>
struct ScalarEnumerationTraits<FormatStyle::BinaryOperatorStyle> {
148 IO.enumCase(
Value,
"All", FormatStyle::BOS_All);
149 IO.enumCase(
Value,
"true", FormatStyle::BOS_All);
150 IO.enumCase(
Value,
"None", FormatStyle::BOS_None);
151 IO.enumCase(
Value,
"false", FormatStyle::BOS_None);
152 IO.enumCase(
Value,
"NonAssignment", FormatStyle::BOS_NonAssignment);
156template <>
struct ScalarEnumerationTraits<FormatStyle::BinPackArgumentsStyle> {
158 IO.enumCase(
Value,
"BinPack", FormatStyle::BPAS_BinPack);
159 IO.enumCase(
Value,
"OnePerLine", FormatStyle::BPAS_OnePerLine);
160 IO.enumCase(
Value,
"UseBreakAfter", FormatStyle::BPAS_UseBreakAfter);
163 IO.enumCase(
Value,
"true", FormatStyle::BPAS_BinPack);
164 IO.enumCase(
Value,
"false", FormatStyle::BPAS_OnePerLine);
169struct ScalarEnumerationTraits<FormatStyle::BinPackParametersStyle> {
171 IO.enumCase(
Value,
"BinPack", FormatStyle::BPPS_BinPack);
172 IO.enumCase(
Value,
"OnePerLine", FormatStyle::BPPS_OnePerLine);
173 IO.enumCase(
Value,
"AlwaysOnePerLine", FormatStyle::BPPS_AlwaysOnePerLine);
174 IO.enumCase(
Value,
"UseBreakAfter", FormatStyle::BPPS_UseBreakAfter);
177 IO.enumCase(
Value,
"true", FormatStyle::BPPS_BinPack);
178 IO.enumCase(
Value,
"false", FormatStyle::BPPS_OnePerLine);
182template <>
struct ScalarEnumerationTraits<FormatStyle::BinPackStyle> {
184 IO.enumCase(
Value,
"Auto", FormatStyle::BPS_Auto);
185 IO.enumCase(
Value,
"Always", FormatStyle::BPS_Always);
186 IO.enumCase(
Value,
"Never", FormatStyle::BPS_Never);
191struct ScalarEnumerationTraits<FormatStyle::BitFieldColonSpacingStyle> {
193 FormatStyle::BitFieldColonSpacingStyle &
Value) {
194 IO.enumCase(
Value,
"Both", FormatStyle::BFCS_Both);
195 IO.enumCase(
Value,
"None", FormatStyle::BFCS_None);
196 IO.enumCase(
Value,
"Before", FormatStyle::BFCS_Before);
197 IO.enumCase(
Value,
"After", FormatStyle::BFCS_After);
201template <>
struct ScalarEnumerationTraits<FormatStyle::BraceBreakingStyle> {
203 IO.enumCase(
Value,
"Attach", FormatStyle::BS_Attach);
204 IO.enumCase(
Value,
"Linux", FormatStyle::BS_Linux);
205 IO.enumCase(
Value,
"Mozilla", FormatStyle::BS_Mozilla);
206 IO.enumCase(
Value,
"Stroustrup", FormatStyle::BS_Stroustrup);
207 IO.enumCase(
Value,
"Allman", FormatStyle::BS_Allman);
208 IO.enumCase(
Value,
"Whitesmiths", FormatStyle::BS_Whitesmiths);
209 IO.enumCase(
Value,
"GNU", FormatStyle::BS_GNU);
210 IO.enumCase(
Value,
"WebKit", FormatStyle::BS_WebKit);
211 IO.enumCase(
Value,
"Custom", FormatStyle::BS_Custom);
215template <>
struct MappingTraits<FormatStyle::BraceWrappingFlags> {
216 static void mapping(IO &IO, FormatStyle::BraceWrappingFlags &Wrapping) {
217 IO.mapOptional(
"AfterCaseLabel", Wrapping.AfterCaseLabel);
218 IO.mapOptional(
"AfterClass", Wrapping.AfterClass);
219 IO.mapOptional(
"AfterControlStatement", Wrapping.AfterControlStatement);
220 IO.mapOptional(
"AfterEnum", Wrapping.AfterEnum);
221 IO.mapOptional(
"AfterExternBlock", Wrapping.AfterExternBlock);
222 IO.mapOptional(
"AfterFunction", Wrapping.AfterFunction);
223 IO.mapOptional(
"AfterNamespace", Wrapping.AfterNamespace);
224 IO.mapOptional(
"AfterObjCDeclaration", Wrapping.AfterObjCDeclaration);
225 IO.mapOptional(
"AfterStruct", Wrapping.AfterStruct);
226 IO.mapOptional(
"AfterUnion", Wrapping.AfterUnion);
227 IO.mapOptional(
"BeforeCatch", Wrapping.BeforeCatch);
228 IO.mapOptional(
"BeforeElse", Wrapping.BeforeElse);
229 IO.mapOptional(
"BeforeLambdaBody", Wrapping.BeforeLambdaBody);
230 IO.mapOptional(
"BeforeWhile", Wrapping.BeforeWhile);
231 IO.mapOptional(
"IndentBraces", Wrapping.IndentBraces);
232 IO.mapOptional(
"SplitEmptyFunction", Wrapping.SplitEmptyFunction);
233 IO.mapOptional(
"SplitEmptyRecord", Wrapping.SplitEmptyRecord);
234 IO.mapOptional(
"SplitEmptyNamespace", Wrapping.SplitEmptyNamespace);
252struct ScalarEnumerationTraits<
253 FormatStyle::BraceWrappingAfterControlStatementStyle> {
256 FormatStyle::BraceWrappingAfterControlStatementStyle &
Value) {
257 IO.enumCase(
Value,
"Never", FormatStyle::BWACS_Never);
258 IO.enumCase(
Value,
"MultiLine", FormatStyle::BWACS_MultiLine);
259 IO.enumCase(
Value,
"Always", FormatStyle::BWACS_Always);
262 IO.enumCase(
Value,
"false", FormatStyle::BWACS_Never);
263 IO.enumCase(
Value,
"true", FormatStyle::BWACS_Always);
268struct ScalarEnumerationTraits<
269 FormatStyle::BreakBeforeConceptDeclarationsStyle> {
272 IO.enumCase(
Value,
"Never", FormatStyle::BBCDS_Never);
273 IO.enumCase(
Value,
"Allowed", FormatStyle::BBCDS_Allowed);
274 IO.enumCase(
Value,
"Always", FormatStyle::BBCDS_Always);
277 IO.enumCase(
Value,
"true", FormatStyle::BBCDS_Always);
278 IO.enumCase(
Value,
"false", FormatStyle::BBCDS_Allowed);
283struct ScalarEnumerationTraits<FormatStyle::BreakBeforeInlineASMColonStyle> {
285 FormatStyle::BreakBeforeInlineASMColonStyle &
Value) {
286 IO.enumCase(
Value,
"Never", FormatStyle::BBIAS_Never);
287 IO.enumCase(
Value,
"OnlyMultiline", FormatStyle::BBIAS_OnlyMultiline);
288 IO.enumCase(
Value,
"Always", FormatStyle::BBIAS_Always);
293struct ScalarEnumerationTraits<FormatStyle::BreakBinaryOperationsStyle> {
295 FormatStyle::BreakBinaryOperationsStyle &
Value) {
296 IO.enumCase(
Value,
"Never", FormatStyle::BBO_Never);
297 IO.enumCase(
Value,
"OnePerLine", FormatStyle::BBO_OnePerLine);
298 IO.enumCase(
Value,
"RespectPrecedence", FormatStyle::BBO_RespectPrecedence);
302template <>
struct ScalarTraits<
clang::tok::TokenKind> {
304 llvm::raw_ostream &Out) {
311 static StringRef
input(StringRef Scalar,
void *,
314#define PUNCTUATOR(Name, Spelling) \
315 if (Scalar == Spelling) { \
316 Value = clang::tok::Name; \
319#include "clang/Basic/TokenKinds.def"
320 return "unknown operator";
323 static QuotingType
mustQuote(StringRef) {
return QuotingType::None; }
326template <>
struct MappingTraits<FormatStyle::BinaryOperationBreakRule> {
327 static void mapping(IO &IO, FormatStyle::BinaryOperationBreakRule &
Value) {
328 IO.mapOptional(
"Operators",
Value.Operators);
330 if (!IO.outputting())
331 Value.Style = FormatStyle::BBO_OnePerLine;
332 IO.mapOptional(
"Style",
Value.Style);
333 IO.mapOptional(
"MinChainLength",
Value.MinChainLength);
337template <>
struct MappingTraits<FormatStyle::BreakBinaryOperationsOptions> {
339 FormatStyle::BreakBinaryOperationsOptions &
Value) {
340 IO.enumCase(
Value,
"Never",
341 FormatStyle::BreakBinaryOperationsOptions(
342 {FormatStyle::BBO_Never, {}}));
343 IO.enumCase(
Value,
"OnePerLine",
344 FormatStyle::BreakBinaryOperationsOptions(
345 {FormatStyle::BBO_OnePerLine, {}}));
346 IO.enumCase(
Value,
"RespectPrecedence",
347 FormatStyle::BreakBinaryOperationsOptions(
348 {FormatStyle::BBO_RespectPrecedence, {}}));
352 FormatStyle::BreakBinaryOperationsOptions &
Value) {
353 IO.mapOptional(
"Default",
Value.Default);
354 IO.mapOptional(
"PerOperator",
Value.PerOperator);
359struct ScalarEnumerationTraits<FormatStyle::BreakConstructorInitializersStyle> {
362 IO.enumCase(
Value,
"BeforeColon", FormatStyle::BCIS_BeforeColon);
363 IO.enumCase(
Value,
"BeforeComma", FormatStyle::BCIS_BeforeComma);
364 IO.enumCase(
Value,
"AfterColon", FormatStyle::BCIS_AfterColon);
365 IO.enumCase(
Value,
"AfterComma", FormatStyle::BCIS_AfterComma);
370struct ScalarEnumerationTraits<FormatStyle::BreakInheritanceListStyle> {
372 FormatStyle::BreakInheritanceListStyle &
Value) {
373 IO.enumCase(
Value,
"BeforeColon", FormatStyle::BILS_BeforeColon);
374 IO.enumCase(
Value,
"BeforeComma", FormatStyle::BILS_BeforeComma);
375 IO.enumCase(
Value,
"AfterColon", FormatStyle::BILS_AfterColon);
376 IO.enumCase(
Value,
"AfterComma", FormatStyle::BILS_AfterComma);
381struct ScalarEnumerationTraits<FormatStyle::BreakTemplateDeclarationsStyle> {
383 FormatStyle::BreakTemplateDeclarationsStyle &
Value) {
384 IO.enumCase(
Value,
"Leave", FormatStyle::BTDS_Leave);
385 IO.enumCase(
Value,
"No", FormatStyle::BTDS_No);
386 IO.enumCase(
Value,
"MultiLine", FormatStyle::BTDS_MultiLine);
387 IO.enumCase(
Value,
"Yes", FormatStyle::BTDS_Yes);
390 IO.enumCase(
Value,
"false", FormatStyle::BTDS_MultiLine);
391 IO.enumCase(
Value,
"true", FormatStyle::BTDS_Yes);
395template <>
struct ScalarEnumerationTraits<FormatStyle::BracedListStyle> {
397 IO.enumCase(
Value,
"Block", FormatStyle::BLS_Block);
398 IO.enumCase(
Value,
"FunctionCall", FormatStyle::BLS_FunctionCall);
399 IO.enumCase(
Value,
"AlignFirstComment", FormatStyle::BLS_AlignFirstComment);
402 IO.enumCase(
Value,
"false", FormatStyle::BLS_Block);
403 IO.enumCase(
Value,
"true", FormatStyle::BLS_AlignFirstComment);
407template <>
struct ScalarEnumerationTraits<FormatStyle::DAGArgStyle> {
409 IO.enumCase(
Value,
"DontBreak", FormatStyle::DAS_DontBreak);
410 IO.enumCase(
Value,
"BreakElements", FormatStyle::DAS_BreakElements);
411 IO.enumCase(
Value,
"BreakAll", FormatStyle::DAS_BreakAll);
416struct ScalarEnumerationTraits<FormatStyle::DefinitionReturnTypeBreakingStyle> {
419 IO.enumCase(
Value,
"None", FormatStyle::DRTBS_None);
420 IO.enumCase(
Value,
"All", FormatStyle::DRTBS_All);
421 IO.enumCase(
Value,
"TopLevel", FormatStyle::DRTBS_TopLevel);
424 IO.enumCase(
Value,
"false", FormatStyle::DRTBS_None);
425 IO.enumCase(
Value,
"true", FormatStyle::DRTBS_All);
430struct ScalarEnumerationTraits<FormatStyle::EscapedNewlineAlignmentStyle> {
432 FormatStyle::EscapedNewlineAlignmentStyle &
Value) {
433 IO.enumCase(
Value,
"DontAlign", FormatStyle::ENAS_DontAlign);
434 IO.enumCase(
Value,
"Left", FormatStyle::ENAS_Left);
435 IO.enumCase(
Value,
"LeftWithLastLine", FormatStyle::ENAS_LeftWithLastLine);
436 IO.enumCase(
Value,
"Right", FormatStyle::ENAS_Right);
439 IO.enumCase(
Value,
"true", FormatStyle::ENAS_Left);
440 IO.enumCase(
Value,
"false", FormatStyle::ENAS_Right);
445struct ScalarEnumerationTraits<FormatStyle::EmptyLineAfterAccessModifierStyle> {
448 IO.enumCase(
Value,
"Never", FormatStyle::ELAAMS_Never);
449 IO.enumCase(
Value,
"Leave", FormatStyle::ELAAMS_Leave);
450 IO.enumCase(
Value,
"Always", FormatStyle::ELAAMS_Always);
455struct ScalarEnumerationTraits<
456 FormatStyle::EmptyLineBeforeAccessModifierStyle> {
459 IO.enumCase(
Value,
"Never", FormatStyle::ELBAMS_Never);
460 IO.enumCase(
Value,
"Leave", FormatStyle::ELBAMS_Leave);
461 IO.enumCase(
Value,
"LogicalBlock", FormatStyle::ELBAMS_LogicalBlock);
462 IO.enumCase(
Value,
"Always", FormatStyle::ELBAMS_Always);
467struct ScalarEnumerationTraits<FormatStyle::EnumTrailingCommaStyle> {
469 IO.enumCase(
Value,
"Leave", FormatStyle::ETC_Leave);
470 IO.enumCase(
Value,
"Insert", FormatStyle::ETC_Insert);
471 IO.enumCase(
Value,
"Remove", FormatStyle::ETC_Remove);
476struct ScalarEnumerationTraits<FormatStyle::IndentExternBlockStyle> {
478 IO.enumCase(
Value,
"AfterExternBlock", FormatStyle::IEBS_AfterExternBlock);
479 IO.enumCase(
Value,
"Indent", FormatStyle::IEBS_Indent);
480 IO.enumCase(
Value,
"NoIndent", FormatStyle::IEBS_NoIndent);
481 IO.enumCase(
Value,
"true", FormatStyle::IEBS_Indent);
482 IO.enumCase(
Value,
"false", FormatStyle::IEBS_NoIndent);
486template <>
struct MappingTraits<FormatStyle::IntegerLiteralSeparatorStyle> {
487 static void mapping(IO &IO, FormatStyle::IntegerLiteralSeparatorStyle &
Base) {
488 IO.mapOptional(
"Binary",
Base.Binary);
489 IO.mapOptional(
"BinaryMinDigitsInsert",
Base.BinaryMinDigitsInsert);
490 IO.mapOptional(
"BinaryMaxDigitsRemove",
Base.BinaryMaxDigitsRemove);
491 IO.mapOptional(
"Decimal",
Base.Decimal);
492 IO.mapOptional(
"DecimalMinDigitsInsert",
Base.DecimalMinDigitsInsert);
493 IO.mapOptional(
"DecimalMaxDigitsRemove",
Base.DecimalMaxDigitsRemove);
494 IO.mapOptional(
"Hex",
Base.Hex);
495 IO.mapOptional(
"HexMinDigitsInsert",
Base.HexMinDigitsInsert);
496 IO.mapOptional(
"HexMaxDigitsRemove",
Base.HexMaxDigitsRemove);
499 IO.mapOptional(
"BinaryMinDigits",
Base.BinaryMinDigitsInsert);
500 IO.mapOptional(
"DecimalMinDigits",
Base.DecimalMinDigitsInsert);
501 IO.mapOptional(
"HexMinDigits",
Base.HexMinDigitsInsert);
505template <>
struct ScalarEnumerationTraits<FormatStyle::JavaScriptQuoteStyle> {
507 IO.enumCase(
Value,
"Leave", FormatStyle::JSQS_Leave);
508 IO.enumCase(
Value,
"Single", FormatStyle::JSQS_Single);
509 IO.enumCase(
Value,
"Double", FormatStyle::JSQS_Double);
513template <>
struct MappingTraits<FormatStyle::KeepEmptyLinesStyle> {
515 IO.mapOptional(
"AtEndOfFile",
Value.AtEndOfFile);
516 IO.mapOptional(
"AtStartOfBlock",
Value.AtStartOfBlock);
517 IO.mapOptional(
"AtStartOfFile",
Value.AtStartOfFile);
521template <>
struct ScalarEnumerationTraits<FormatStyle::LanguageKind> {
523 IO.enumCase(
Value,
"C", FormatStyle::LK_C);
524 IO.enumCase(
Value,
"Cpp", FormatStyle::LK_Cpp);
525 IO.enumCase(
Value,
"Java", FormatStyle::LK_Java);
526 IO.enumCase(
Value,
"JavaScript", FormatStyle::LK_JavaScript);
527 IO.enumCase(
Value,
"ObjC", FormatStyle::LK_ObjC);
528 IO.enumCase(
Value,
"Proto", FormatStyle::LK_Proto);
529 IO.enumCase(
Value,
"TableGen", FormatStyle::LK_TableGen);
530 IO.enumCase(
Value,
"TextProto", FormatStyle::LK_TextProto);
531 IO.enumCase(
Value,
"CSharp", FormatStyle::LK_CSharp);
532 IO.enumCase(
Value,
"Json", FormatStyle::LK_Json);
533 IO.enumCase(
Value,
"Verilog", FormatStyle::LK_Verilog);
537template <>
struct ScalarEnumerationTraits<FormatStyle::LanguageStandard> {
539 IO.enumCase(
Value,
"c++03", FormatStyle::LS_Cpp03);
540 IO.enumCase(
Value,
"C++03", FormatStyle::LS_Cpp03);
541 IO.enumCase(
Value,
"Cpp03", FormatStyle::LS_Cpp03);
543 IO.enumCase(
Value,
"c++11", FormatStyle::LS_Cpp11);
544 IO.enumCase(
Value,
"C++11", FormatStyle::LS_Cpp11);
546 IO.enumCase(
Value,
"c++14", FormatStyle::LS_Cpp14);
547 IO.enumCase(
Value,
"c++17", FormatStyle::LS_Cpp17);
548 IO.enumCase(
Value,
"c++20", FormatStyle::LS_Cpp20);
549 IO.enumCase(
Value,
"c++23", FormatStyle::LS_Cpp23);
550 IO.enumCase(
Value,
"c++26", FormatStyle::LS_Cpp26);
552 IO.enumCase(
Value,
"Latest", FormatStyle::LS_Latest);
553 IO.enumCase(
Value,
"Cpp11", FormatStyle::LS_Latest);
554 IO.enumCase(
Value,
"Auto", FormatStyle::LS_Auto);
559struct ScalarEnumerationTraits<FormatStyle::LambdaBodyIndentationKind> {
561 FormatStyle::LambdaBodyIndentationKind &
Value) {
562 IO.enumCase(
Value,
"Signature", FormatStyle::LBI_Signature);
563 IO.enumCase(
Value,
"OuterScope", FormatStyle::LBI_OuterScope);
567template <>
struct ScalarEnumerationTraits<FormatStyle::LineEndingStyle> {
569 IO.enumCase(
Value,
"LF", FormatStyle::LE_LF);
570 IO.enumCase(
Value,
"CRLF", FormatStyle::LE_CRLF);
571 IO.enumCase(
Value,
"DeriveLF", FormatStyle::LE_DeriveLF);
572 IO.enumCase(
Value,
"DeriveCRLF", FormatStyle::LE_DeriveCRLF);
577struct ScalarEnumerationTraits<FormatStyle::NamespaceIndentationKind> {
579 FormatStyle::NamespaceIndentationKind &
Value) {
580 IO.enumCase(
Value,
"None", FormatStyle::NI_None);
581 IO.enumCase(
Value,
"Inner", FormatStyle::NI_Inner);
582 IO.enumCase(
Value,
"All", FormatStyle::NI_All);
587struct ScalarEnumerationTraits<FormatStyle::NumericLiteralComponentStyle> {
589 FormatStyle::NumericLiteralComponentStyle &
Value) {
590 IO.enumCase(
Value,
"Leave", FormatStyle::NLCS_Leave);
591 IO.enumCase(
Value,
"Upper", FormatStyle::NLCS_Upper);
592 IO.enumCase(
Value,
"Lower", FormatStyle::NLCS_Lower);
596template <>
struct MappingTraits<FormatStyle::NumericLiteralCaseStyle> {
597 static void mapping(IO &IO, FormatStyle::NumericLiteralCaseStyle &
Value) {
598 IO.mapOptional(
"ExponentLetter",
Value.ExponentLetter);
599 IO.mapOptional(
"HexDigit",
Value.HexDigit);
600 IO.mapOptional(
"Prefix",
Value.Prefix);
601 IO.mapOptional(
"Suffix",
Value.Suffix);
605template <>
struct ScalarEnumerationTraits<FormatStyle::OperandAlignmentStyle> {
607 IO.enumCase(
Value,
"DontAlign", FormatStyle::OAS_DontAlign);
608 IO.enumCase(
Value,
"Align", FormatStyle::OAS_Align);
609 IO.enumCase(
Value,
"AlignAfterOperator",
610 FormatStyle::OAS_AlignAfterOperator);
613 IO.enumCase(
Value,
"true", FormatStyle::OAS_Align);
614 IO.enumCase(
Value,
"false", FormatStyle::OAS_DontAlign);
618template <>
struct MappingTraits<FormatStyle::PackParametersStyle> {
620 IO.mapOptional(
"BinPack",
Value.BinPack);
621 IO.mapOptional(
"BreakAfter",
Value.BreakAfter);
626struct ScalarEnumerationTraits<FormatStyle::PackConstructorInitializersStyle> {
629 IO.enumCase(
Value,
"Never", FormatStyle::PCIS_Never);
630 IO.enumCase(
Value,
"BinPack", FormatStyle::PCIS_BinPack);
631 IO.enumCase(
Value,
"CurrentLine", FormatStyle::PCIS_CurrentLine);
632 IO.enumCase(
Value,
"NextLine", FormatStyle::PCIS_NextLine);
633 IO.enumCase(
Value,
"NextLineOnly", FormatStyle::PCIS_NextLineOnly);
637template <>
struct MappingTraits<FormatStyle::PackArgumentsStyle> {
639 IO.mapOptional(
"BinPack",
Value.BinPack);
640 IO.mapOptional(
"BreakAfter",
Value.BreakAfter);
644template <>
struct ScalarEnumerationTraits<FormatStyle::PointerAlignmentStyle> {
646 IO.enumCase(
Value,
"Middle", FormatStyle::PAS_Middle);
647 IO.enumCase(
Value,
"Left", FormatStyle::PAS_Left);
648 IO.enumCase(
Value,
"Right", FormatStyle::PAS_Right);
651 IO.enumCase(
Value,
"true", FormatStyle::PAS_Left);
652 IO.enumCase(
Value,
"false", FormatStyle::PAS_Right);
657struct ScalarEnumerationTraits<FormatStyle::PPDirectiveIndentStyle> {
659 IO.enumCase(
Value,
"None", FormatStyle::PPDIS_None);
660 IO.enumCase(
Value,
"AfterHash", FormatStyle::PPDIS_AfterHash);
661 IO.enumCase(
Value,
"BeforeHash", FormatStyle::PPDIS_BeforeHash);
662 IO.enumCase(
Value,
"Leave", FormatStyle::PPDIS_Leave);
667struct ScalarEnumerationTraits<FormatStyle::QualifierAlignmentStyle> {
669 IO.enumCase(
Value,
"Leave", FormatStyle::QAS_Leave);
670 IO.enumCase(
Value,
"Left", FormatStyle::QAS_Left);
671 IO.enumCase(
Value,
"Right", FormatStyle::QAS_Right);
672 IO.enumCase(
Value,
"Custom", FormatStyle::QAS_Custom);
676template <>
struct MappingTraits<FormatStyle::RawStringFormat> {
677 static void mapping(IO &IO, FormatStyle::RawStringFormat &Format) {
678 IO.mapOptional(
"Language", Format.Language);
679 IO.mapOptional(
"Delimiters", Format.Delimiters);
680 IO.mapOptional(
"EnclosingFunctions", Format.EnclosingFunctions);
681 IO.mapOptional(
"CanonicalDelimiter", Format.CanonicalDelimiter);
682 IO.mapOptional(
"BasedOnStyle", Format.BasedOnStyle);
686template <>
struct ScalarEnumerationTraits<FormatStyle::ReflowCommentsStyle> {
688 IO.enumCase(
Value,
"Never", FormatStyle::RCS_Never);
689 IO.enumCase(
Value,
"IndentOnly", FormatStyle::RCS_IndentOnly);
690 IO.enumCase(
Value,
"Always", FormatStyle::RCS_Always);
692 IO.enumCase(
Value,
"false", FormatStyle::RCS_Never);
693 IO.enumCase(
Value,
"true", FormatStyle::RCS_Always);
698struct ScalarEnumerationTraits<FormatStyle::ReferenceAlignmentStyle> {
700 IO.enumCase(
Value,
"Pointer", FormatStyle::RAS_Pointer);
701 IO.enumCase(
Value,
"Middle", FormatStyle::RAS_Middle);
702 IO.enumCase(
Value,
"Left", FormatStyle::RAS_Left);
703 IO.enumCase(
Value,
"Right", FormatStyle::RAS_Right);
708struct ScalarEnumerationTraits<FormatStyle::RemoveParenthesesStyle> {
710 IO.enumCase(
Value,
"Leave", FormatStyle::RPS_Leave);
711 IO.enumCase(
Value,
"MultipleParentheses",
712 FormatStyle::RPS_MultipleParentheses);
713 IO.enumCase(
Value,
"ReturnStatement", FormatStyle::RPS_ReturnStatement);
718struct ScalarEnumerationTraits<FormatStyle::RequiresClausePositionStyle> {
720 FormatStyle::RequiresClausePositionStyle &
Value) {
721 IO.enumCase(
Value,
"OwnLine", FormatStyle::RCPS_OwnLine);
722 IO.enumCase(
Value,
"OwnLineWithBrace", FormatStyle::RCPS_OwnLineWithBrace);
723 IO.enumCase(
Value,
"WithPreceding", FormatStyle::RCPS_WithPreceding);
724 IO.enumCase(
Value,
"WithFollowing", FormatStyle::RCPS_WithFollowing);
725 IO.enumCase(
Value,
"SingleLine", FormatStyle::RCPS_SingleLine);
730struct ScalarEnumerationTraits<FormatStyle::RequiresExpressionIndentationKind> {
733 IO.enumCase(
Value,
"Keyword", FormatStyle::REI_Keyword);
734 IO.enumCase(
Value,
"OuterScope", FormatStyle::REI_OuterScope);
739struct ScalarEnumerationTraits<FormatStyle::ReturnTypeBreakingStyle> {
741 IO.enumCase(
Value,
"None", FormatStyle::RTBS_None);
742 IO.enumCase(
Value,
"Automatic", FormatStyle::RTBS_Automatic);
743 IO.enumCase(
Value,
"ExceptShortType", FormatStyle::RTBS_ExceptShortType);
744 IO.enumCase(
Value,
"All", FormatStyle::RTBS_All);
745 IO.enumCase(
Value,
"TopLevel", FormatStyle::RTBS_TopLevel);
746 IO.enumCase(
Value,
"TopLevelDefinitions",
747 FormatStyle::RTBS_TopLevelDefinitions);
748 IO.enumCase(
Value,
"AllDefinitions", FormatStyle::RTBS_AllDefinitions);
753struct ScalarEnumerationTraits<FormatStyle::BreakBeforeReturnTypeStyle> {
755 FormatStyle::BreakBeforeReturnTypeStyle &
Value) {
756 IO.enumCase(
Value,
"None", FormatStyle::BBRTS_None);
757 IO.enumCase(
Value,
"All", FormatStyle::BBRTS_All);
758 IO.enumCase(
Value,
"TopLevel", FormatStyle::BBRTS_TopLevel);
759 IO.enumCase(
Value,
"AllDefinitions", FormatStyle::BBRTS_AllDefinitions);
760 IO.enumCase(
Value,
"TopLevelDefinitions",
761 FormatStyle::BBRTS_TopLevelDefinitions);
766struct ScalarEnumerationTraits<FormatStyle::SeparateDefinitionStyle> {
768 IO.enumCase(
Value,
"Leave", FormatStyle::SDS_Leave);
769 IO.enumCase(
Value,
"Always", FormatStyle::SDS_Always);
770 IO.enumCase(
Value,
"Never", FormatStyle::SDS_Never);
774template <>
struct ScalarEnumerationTraits<FormatStyle::ShortBlockStyle> {
776 IO.enumCase(
Value,
"Never", FormatStyle::SBS_Never);
777 IO.enumCase(
Value,
"false", FormatStyle::SBS_Never);
778 IO.enumCase(
Value,
"Always", FormatStyle::SBS_Always);
779 IO.enumCase(
Value,
"true", FormatStyle::SBS_Always);
780 IO.enumCase(
Value,
"Empty", FormatStyle::SBS_Empty);
784template <>
struct MappingTraits<FormatStyle::ShortFunctionStyle> {
786 IO.enumCase(
Value,
"None", FormatStyle::ShortFunctionStyle());
787 IO.enumCase(
Value,
"Empty",
788 FormatStyle::ShortFunctionStyle::setEmptyOnly());
789 IO.enumCase(
Value,
"Inline",
790 FormatStyle::ShortFunctionStyle::setEmptyAndInline());
791 IO.enumCase(
Value,
"InlineOnly",
792 FormatStyle::ShortFunctionStyle::setInlineOnly());
793 IO.enumCase(
Value,
"All", FormatStyle::ShortFunctionStyle::setAll());
796 IO.enumCase(
Value,
"true", FormatStyle::ShortFunctionStyle::setAll());
797 IO.enumCase(
Value,
"false", FormatStyle::ShortFunctionStyle());
801 IO.mapOptional(
"Empty",
Value.Empty);
802 IO.mapOptional(
"Inline",
Value.Inline);
803 IO.mapOptional(
"Other",
Value.Other);
807template <>
struct ScalarEnumerationTraits<FormatStyle::ShortIfStyle> {
809 IO.enumCase(
Value,
"Never", FormatStyle::SIS_Never);
810 IO.enumCase(
Value,
"WithoutElse", FormatStyle::SIS_WithoutElse);
811 IO.enumCase(
Value,
"OnlyFirstIf", FormatStyle::SIS_OnlyFirstIf);
812 IO.enumCase(
Value,
"AllIfsAndElse", FormatStyle::SIS_AllIfsAndElse);
815 IO.enumCase(
Value,
"Always", FormatStyle::SIS_OnlyFirstIf);
816 IO.enumCase(
Value,
"false", FormatStyle::SIS_Never);
817 IO.enumCase(
Value,
"true", FormatStyle::SIS_WithoutElse);
821template <>
struct ScalarEnumerationTraits<FormatStyle::ShortLambdaStyle> {
823 IO.enumCase(
Value,
"None", FormatStyle::SLS_None);
824 IO.enumCase(
Value,
"false", FormatStyle::SLS_None);
825 IO.enumCase(
Value,
"Empty", FormatStyle::SLS_Empty);
826 IO.enumCase(
Value,
"Inline", FormatStyle::SLS_Inline);
827 IO.enumCase(
Value,
"All", FormatStyle::SLS_All);
828 IO.enumCase(
Value,
"true", FormatStyle::SLS_All);
832template <>
struct ScalarEnumerationTraits<FormatStyle::ShortRecordStyle> {
834 IO.enumCase(
Value,
"Never", FormatStyle::SRS_Never);
835 IO.enumCase(
Value,
"EmptyAndAttached", FormatStyle::SRS_EmptyAndAttached);
836 IO.enumCase(
Value,
"Empty", FormatStyle::SRS_Empty);
837 IO.enumCase(
Value,
"Always", FormatStyle::SRS_Always);
841template <>
struct MappingTraits<FormatStyle::SortIncludesOptions> {
843 IO.enumCase(
Value,
"Never", FormatStyle::SortIncludesOptions{});
844 IO.enumCase(
Value,
"CaseInsensitive",
845 FormatStyle::SortIncludesOptions{
true,
848 IO.enumCase(
Value,
"CaseSensitive",
849 FormatStyle::SortIncludesOptions{
true,
854 IO.enumCase(
Value,
"false", FormatStyle::SortIncludesOptions{});
855 IO.enumCase(
Value,
"true",
856 FormatStyle::SortIncludesOptions{
true,
862 IO.mapOptional(
"Enabled",
Value.Enabled);
863 IO.mapOptional(
"IgnoreCase",
Value.IgnoreCase);
864 IO.mapOptional(
"IgnoreExtension",
Value.IgnoreExtension);
869struct ScalarEnumerationTraits<FormatStyle::SortJavaStaticImportOptions> {
871 FormatStyle::SortJavaStaticImportOptions &
Value) {
872 IO.enumCase(
Value,
"Before", FormatStyle::SJSIO_Before);
873 IO.enumCase(
Value,
"After", FormatStyle::SJSIO_After);
878struct ScalarEnumerationTraits<FormatStyle::SortUsingDeclarationsOptions> {
880 FormatStyle::SortUsingDeclarationsOptions &
Value) {
881 IO.enumCase(
Value,
"Never", FormatStyle::SUD_Never);
882 IO.enumCase(
Value,
"Lexicographic", FormatStyle::SUD_Lexicographic);
883 IO.enumCase(
Value,
"LexicographicNumeric",
884 FormatStyle::SUD_LexicographicNumeric);
887 IO.enumCase(
Value,
"false", FormatStyle::SUD_Never);
888 IO.enumCase(
Value,
"true", FormatStyle::SUD_LexicographicNumeric);
893struct ScalarEnumerationTraits<FormatStyle::SpaceAroundPointerQualifiersStyle> {
896 IO.enumCase(
Value,
"Default", FormatStyle::SAPQ_Default);
897 IO.enumCase(
Value,
"Before", FormatStyle::SAPQ_Before);
898 IO.enumCase(
Value,
"After", FormatStyle::SAPQ_After);
899 IO.enumCase(
Value,
"Both", FormatStyle::SAPQ_Both);
903template <>
struct MappingTraits<FormatStyle::SpaceBeforeParensCustom> {
904 static void mapping(IO &IO, FormatStyle::SpaceBeforeParensCustom &Spacing) {
905 IO.mapOptional(
"AfterControlStatements", Spacing.AfterControlStatements);
906 IO.mapOptional(
"AfterForeachMacros", Spacing.AfterForeachMacros);
907 IO.mapOptional(
"AfterFunctionDefinitionName",
908 Spacing.AfterFunctionDefinitionName);
909 IO.mapOptional(
"AfterFunctionDeclarationName",
910 Spacing.AfterFunctionDeclarationName);
911 IO.mapOptional(
"AfterIfMacros", Spacing.AfterIfMacros);
912 IO.mapOptional(
"AfterNot", Spacing.AfterNot);
913 IO.mapOptional(
"AfterOverloadedOperator", Spacing.AfterOverloadedOperator);
914 IO.mapOptional(
"AfterPlacementOperator", Spacing.AfterPlacementOperator);
915 IO.mapOptional(
"AfterRequiresInClause", Spacing.AfterRequiresInClause);
916 IO.mapOptional(
"AfterRequiresInExpression",
917 Spacing.AfterRequiresInExpression);
918 IO.mapOptional(
"BeforeNonEmptyParentheses",
919 Spacing.BeforeNonEmptyParentheses);
924struct ScalarEnumerationTraits<FormatStyle::SpaceBeforeParensStyle> {
926 IO.enumCase(
Value,
"Never", FormatStyle::SBPO_Never);
927 IO.enumCase(
Value,
"ControlStatements",
928 FormatStyle::SBPO_ControlStatements);
929 IO.enumCase(
Value,
"ControlStatementsExceptControlMacros",
930 FormatStyle::SBPO_ControlStatementsExceptControlMacros);
931 IO.enumCase(
Value,
"NonEmptyParentheses",
932 FormatStyle::SBPO_NonEmptyParentheses);
933 IO.enumCase(
Value,
"Always", FormatStyle::SBPO_Always);
934 IO.enumCase(
Value,
"Custom", FormatStyle::SBPO_Custom);
937 IO.enumCase(
Value,
"false", FormatStyle::SBPO_Never);
938 IO.enumCase(
Value,
"true", FormatStyle::SBPO_ControlStatements);
939 IO.enumCase(
Value,
"ControlStatementsExceptForEachMacros",
940 FormatStyle::SBPO_ControlStatementsExceptControlMacros);
945struct ScalarEnumerationTraits<FormatStyle::SpaceInEmptyBracesStyle> {
947 IO.enumCase(
Value,
"Always", FormatStyle::SIEB_Always);
948 IO.enumCase(
Value,
"Block", FormatStyle::SIEB_Block);
949 IO.enumCase(
Value,
"Never", FormatStyle::SIEB_Never);
953template <>
struct ScalarEnumerationTraits<FormatStyle::SpacesInAnglesStyle> {
955 IO.enumCase(
Value,
"Never", FormatStyle::SIAS_Never);
956 IO.enumCase(
Value,
"Always", FormatStyle::SIAS_Always);
957 IO.enumCase(
Value,
"Leave", FormatStyle::SIAS_Leave);
960 IO.enumCase(
Value,
"false", FormatStyle::SIAS_Never);
961 IO.enumCase(
Value,
"true", FormatStyle::SIAS_Always);
965template <>
struct MappingTraits<FormatStyle::SpacesInLineComment> {
966 static void mapping(IO &IO, FormatStyle::SpacesInLineComment &Space) {
968 int signedMaximum =
static_cast<int>(Space.Maximum);
969 IO.mapOptional(
"Minimum", Space.Minimum);
970 IO.mapOptional(
"Maximum", signedMaximum);
971 Space.Maximum =
static_cast<unsigned>(signedMaximum);
973 if (Space.Maximum < std::numeric_limits<unsigned>::max())
974 Space.Minimum = std::min(Space.Minimum, Space.Maximum);
978template <>
struct MappingTraits<FormatStyle::SpacesInParensCustom> {
979 static void mapping(IO &IO, FormatStyle::SpacesInParensCustom &Spaces) {
980 IO.mapOptional(
"ExceptDoubleParentheses", Spaces.ExceptDoubleParentheses);
981 IO.mapOptional(
"InCStyleCasts", Spaces.InCStyleCasts);
982 IO.mapOptional(
"InConditionalStatements", Spaces.InConditionalStatements);
983 IO.mapOptional(
"InEmptyParentheses", Spaces.InEmptyParentheses);
984 IO.mapOptional(
"Other", Spaces.Other);
988template <>
struct ScalarEnumerationTraits<FormatStyle::SpacesInParensStyle> {
990 IO.enumCase(
Value,
"Never", FormatStyle::SIPO_Never);
991 IO.enumCase(
Value,
"Custom", FormatStyle::SIPO_Custom);
995template <>
struct ScalarEnumerationTraits<FormatStyle::TrailingCommaStyle> {
997 IO.enumCase(
Value,
"None", FormatStyle::TCS_None);
998 IO.enumCase(
Value,
"Wrapped", FormatStyle::TCS_Wrapped);
1003struct ScalarEnumerationTraits<FormatStyle::TrailingCommentsAlignmentKinds> {
1005 FormatStyle::TrailingCommentsAlignmentKinds &
Value) {
1006 IO.enumCase(
Value,
"Leave", FormatStyle::TCAS_Leave);
1007 IO.enumCase(
Value,
"Always", FormatStyle::TCAS_Always);
1008 IO.enumCase(
Value,
"Never", FormatStyle::TCAS_Never);
1012template <>
struct MappingTraits<FormatStyle::TrailingCommentsAlignmentStyle> {
1014 FormatStyle::TrailingCommentsAlignmentStyle &
Value) {
1015 IO.enumCase(
Value,
"Leave",
1016 FormatStyle::TrailingCommentsAlignmentStyle(
1017 {FormatStyle::TCAS_Leave, 0,
true}));
1019 IO.enumCase(
Value,
"Always",
1020 FormatStyle::TrailingCommentsAlignmentStyle(
1021 {FormatStyle::TCAS_Always, 0,
true}));
1023 IO.enumCase(
Value,
"Never",
1024 FormatStyle::TrailingCommentsAlignmentStyle(
1025 {FormatStyle::TCAS_Never, 0,
true}));
1028 IO.enumCase(
Value,
"true",
1029 FormatStyle::TrailingCommentsAlignmentStyle(
1030 {FormatStyle::TCAS_Always, 0,
true}));
1031 IO.enumCase(
Value,
"false",
1032 FormatStyle::TrailingCommentsAlignmentStyle(
1033 {FormatStyle::TCAS_Never, 0,
true}));
1037 FormatStyle::TrailingCommentsAlignmentStyle &
Value) {
1038 IO.mapOptional(
"AlignPPAndNotPP",
Value.AlignPPAndNotPP);
1039 IO.mapOptional(
"Kind",
Value.Kind);
1040 IO.mapOptional(
"OverEmptyLines",
Value.OverEmptyLines);
1044template <>
struct ScalarEnumerationTraits<FormatStyle::UseTabStyle> {
1046 IO.enumCase(
Value,
"Never", FormatStyle::UT_Never);
1047 IO.enumCase(
Value,
"false", FormatStyle::UT_Never);
1048 IO.enumCase(
Value,
"Always", FormatStyle::UT_Always);
1049 IO.enumCase(
Value,
"true", FormatStyle::UT_Always);
1050 IO.enumCase(
Value,
"ForIndentation", FormatStyle::UT_ForIndentation);
1051 IO.enumCase(
Value,
"ForContinuationAndIndentation",
1052 FormatStyle::UT_ForContinuationAndIndentation);
1053 IO.enumCase(
Value,
"AlignWithSpaces", FormatStyle::UT_AlignWithSpaces);
1058struct ScalarEnumerationTraits<
1059 FormatStyle::WrapNamespaceBodyWithEmptyLinesStyle> {
1062 FormatStyle::WrapNamespaceBodyWithEmptyLinesStyle &
Value) {
1063 IO.enumCase(
Value,
"Never", FormatStyle::WNBWELS_Never);
1064 IO.enumCase(
Value,
"Always", FormatStyle::WNBWELS_Always);
1065 IO.enumCase(
Value,
"Leave", FormatStyle::WNBWELS_Leave);
1069template <>
struct MappingTraits<FormatStyle> {
1072 IO.mapOptional(
"Language", Style.Language);
1074 StringRef BasedOnStyle;
1075 if (IO.outputting()) {
1076 StringRef Styles[] = {
"LLVM",
"Google",
"Chromium",
"Mozilla",
1077 "WebKit",
"GNU",
"Microsoft",
"clang-format"};
1078 for (StringRef StyleName : Styles) {
1079 FormatStyle PredefinedStyle;
1081 Style == PredefinedStyle) {
1082 BasedOnStyle = StyleName;
1087 IO.mapOptional(
"BasedOnStyle", BasedOnStyle);
1088 if (!BasedOnStyle.empty()) {
1089 FormatStyle::LanguageKind OldLanguage = Style.Language;
1090 FormatStyle::LanguageKind Language =
1091 ((FormatStyle *)IO.getContext())->Language;
1093 IO.setError(Twine(
"Unknown value for BasedOnStyle: ", BasedOnStyle));
1096 Style.Language = OldLanguage;
1111 const bool IsGoogleOrChromium = BasedOnStyle.equals_insensitive(
"google") ||
1112 BasedOnStyle.equals_insensitive(
"chromium");
1113 bool OnCurrentLine = IsGoogleOrChromium;
1114 bool OnNextLine =
true;
1116 bool BreakBeforeInheritanceComma =
false;
1117 bool BreakConstructorInitializersBeforeComma =
false;
1119 bool DeriveLineEnding =
true;
1120 bool UseCRLF =
false;
1122 bool SpaceInEmptyBlock =
false;
1123 bool SpaceInEmptyParentheses =
false;
1124 bool SpacesInConditionalStatement =
false;
1125 bool SpacesInCStyleCastParentheses =
false;
1126 bool SpacesInParentheses =
false;
1128 if (IO.outputting()) {
1129 IO.mapOptional(
"AlignAfterOpenBracket", Style.AlignAfterOpenBracket);
1133 if (IsGoogleOrChromium) {
1134 FormatStyle::LanguageKind Language = Style.Language;
1135 if (Language == FormatStyle::LK_None)
1136 Language = ((FormatStyle *)IO.getContext())->Language;
1137 if (Language == FormatStyle::LK_JavaScript)
1139 else if (Language == FormatStyle::LK_Java)
1141 }
else if (BasedOnStyle.equals_insensitive(
"webkit")) {
1144 IO.mapOptional(
"AlignAfterOpenBracket", LocalBAS);
1148 Style.AlignAfterOpenBracket =
false;
1149 Style.BreakAfterOpenBracketBracedList =
false;
1150 Style.BreakAfterOpenBracketFunction =
false;
1151 Style.BreakAfterOpenBracketIf =
false;
1152 Style.BreakAfterOpenBracketLoop =
false;
1153 Style.BreakAfterOpenBracketSwitch =
false;
1154 Style.BreakBeforeCloseBracketBracedList =
false;
1155 Style.BreakBeforeCloseBracketFunction =
false;
1156 Style.BreakBeforeCloseBracketIf =
false;
1157 Style.BreakBeforeCloseBracketLoop =
false;
1158 Style.BreakBeforeCloseBracketSwitch =
false;
1161 Style.AlignAfterOpenBracket =
true;
1162 Style.BreakBeforeCloseBracketBracedList =
true;
1163 Style.BreakBeforeCloseBracketFunction =
true;
1164 Style.BreakBeforeCloseBracketIf =
true;
1165 Style.BreakAfterOpenBracketLoop =
false;
1166 Style.BreakAfterOpenBracketSwitch =
false;
1167 Style.BreakBeforeCloseBracketBracedList =
false;
1168 Style.BreakBeforeCloseBracketFunction =
false;
1169 Style.BreakBeforeCloseBracketIf =
false;
1170 Style.BreakBeforeCloseBracketLoop =
false;
1171 Style.BreakBeforeCloseBracketSwitch =
false;
1174 Style.AlignAfterOpenBracket =
true;
1175 Style.BreakAfterOpenBracketBracedList =
true;
1176 Style.BreakAfterOpenBracketFunction =
true;
1177 Style.BreakAfterOpenBracketIf =
true;
1178 Style.BreakAfterOpenBracketLoop =
false;
1179 Style.BreakAfterOpenBracketSwitch =
false;
1180 Style.BreakBeforeCloseBracketBracedList =
false;
1181 Style.BreakBeforeCloseBracketFunction =
false;
1182 Style.BreakBeforeCloseBracketIf =
false;
1183 Style.BreakBeforeCloseBracketLoop =
false;
1184 Style.BreakBeforeCloseBracketSwitch =
false;
1187 Style.AlignAfterOpenBracket =
true;
1188 Style.BreakAfterOpenBracketBracedList =
false;
1189 Style.BreakAfterOpenBracketFunction =
false;
1190 Style.BreakAfterOpenBracketIf =
false;
1191 Style.BreakAfterOpenBracketLoop =
false;
1192 Style.BreakAfterOpenBracketSwitch =
false;
1193 Style.BreakBeforeCloseBracketBracedList =
false;
1194 Style.BreakBeforeCloseBracketFunction =
false;
1195 Style.BreakBeforeCloseBracketIf =
false;
1196 Style.BreakBeforeCloseBracketLoop =
false;
1197 Style.BreakBeforeCloseBracketSwitch =
false;
1205 if (!IO.outputting()) {
1206 IO.mapOptional(
"AlignEscapedNewlinesLeft", Style.AlignEscapedNewlines);
1207 IO.mapOptional(
"AllowAllConstructorInitializersOnNextLine", OnNextLine);
1208 IO.mapOptional(
"AlwaysBreakAfterReturnType", Style.BreakAfterReturnType);
1209 IO.mapOptional(
"AlwaysBreakTemplateDeclarations",
1210 Style.BreakTemplateDeclarations);
1211 IO.mapOptional(
"BinPackArguments", Style.PackArguments.BinPack);
1212 IO.mapOptional(
"BinPackParameters", Style.PackParameters.BinPack);
1213 IO.mapOptional(
"BreakBeforeInheritanceComma",
1214 BreakBeforeInheritanceComma);
1215 IO.mapOptional(
"BreakConstructorInitializersBeforeComma",
1216 BreakConstructorInitializersBeforeComma);
1217 IO.mapOptional(
"ConstructorInitializerAllOnOneLineOrOnePerLine",
1219 IO.mapOptional(
"DeriveLineEnding", DeriveLineEnding);
1220 IO.mapOptional(
"DerivePointerBinding", Style.DerivePointerAlignment);
1221 IO.mapOptional(
"KeepEmptyLinesAtEOF", Style.KeepEmptyLines.AtEndOfFile);
1222 IO.mapOptional(
"KeepEmptyLinesAtTheStartOfBlocks",
1223 Style.KeepEmptyLines.AtStartOfBlock);
1224 IO.mapOptional(
"IndentFunctionDeclarationAfterType",
1225 Style.IndentWrappedFunctionNames);
1226 IO.mapOptional(
"IndentRequires", Style.IndentRequiresClause);
1227 IO.mapOptional(
"PointerBindsToType", Style.PointerAlignment);
1228 IO.mapOptional(
"SpaceAfterControlStatementKeyword",
1229 Style.SpaceBeforeParens);
1230 IO.mapOptional(
"SpaceInEmptyBlock", SpaceInEmptyBlock);
1231 IO.mapOptional(
"SpaceInEmptyParentheses", SpaceInEmptyParentheses);
1232 IO.mapOptional(
"SpacesInConditionalStatement",
1233 SpacesInConditionalStatement);
1234 IO.mapOptional(
"SpacesInCStyleCastParentheses",
1235 SpacesInCStyleCastParentheses);
1236 IO.mapOptional(
"SpacesInParentheses", SpacesInParentheses);
1237 IO.mapOptional(
"UseCRLF", UseCRLF);
1240 IO.mapOptional(
"AccessModifierOffset", Style.AccessModifierOffset);
1241 IO.mapOptional(
"AlignArrayOfStructures", Style.AlignArrayOfStructures);
1242 IO.mapOptional(
"AlignConsecutiveAssignments",
1243 Style.AlignConsecutiveAssignments);
1244 IO.mapOptional(
"AlignConsecutiveBitFields",
1245 Style.AlignConsecutiveBitFields);
1246 IO.mapOptional(
"AlignConsecutiveDeclarations",
1247 Style.AlignConsecutiveDeclarations);
1248 IO.mapOptional(
"AlignConsecutiveMacros", Style.AlignConsecutiveMacros);
1249 IO.mapOptional(
"AlignConsecutiveShortCaseStatements",
1250 Style.AlignConsecutiveShortCaseStatements);
1251 IO.mapOptional(
"AlignConsecutiveTableGenBreakingDAGArgColons",
1252 Style.AlignConsecutiveTableGenBreakingDAGArgColons);
1253 IO.mapOptional(
"AlignConsecutiveTableGenCondOperatorColons",
1254 Style.AlignConsecutiveTableGenCondOperatorColons);
1255 IO.mapOptional(
"AlignConsecutiveTableGenDefinitionColons",
1256 Style.AlignConsecutiveTableGenDefinitionColons);
1257 IO.mapOptional(
"AlignEscapedNewlines", Style.AlignEscapedNewlines);
1258 IO.mapOptional(
"AlignOperands", Style.AlignOperands);
1259 IO.mapOptional(
"AlignTrailingComments", Style.AlignTrailingComments);
1260 IO.mapOptional(
"AllowAllArgumentsOnNextLine",
1261 Style.AllowAllArgumentsOnNextLine);
1262 IO.mapOptional(
"AllowAllParametersOfDeclarationOnNextLine",
1263 Style.AllowAllParametersOfDeclarationOnNextLine);
1264 IO.mapOptional(
"AllowBreakBeforeNoexceptSpecifier",
1265 Style.AllowBreakBeforeNoexceptSpecifier);
1266 IO.mapOptional(
"AllowBreakBeforeQtProperty",
1267 Style.AllowBreakBeforeQtProperty);
1268 IO.mapOptional(
"AllowShortBlocksOnASingleLine",
1269 Style.AllowShortBlocksOnASingleLine);
1270 IO.mapOptional(
"AllowShortCaseExpressionOnASingleLine",
1271 Style.AllowShortCaseExpressionOnASingleLine);
1272 IO.mapOptional(
"AllowShortCaseLabelsOnASingleLine",
1273 Style.AllowShortCaseLabelsOnASingleLine);
1274 IO.mapOptional(
"AllowShortCompoundRequirementOnASingleLine",
1275 Style.AllowShortCompoundRequirementOnASingleLine);
1276 IO.mapOptional(
"AllowShortEnumsOnASingleLine",
1277 Style.AllowShortEnumsOnASingleLine);
1278 IO.mapOptional(
"AllowShortFunctionsOnASingleLine",
1279 Style.AllowShortFunctionsOnASingleLine);
1280 IO.mapOptional(
"AllowShortIfStatementsOnASingleLine",
1281 Style.AllowShortIfStatementsOnASingleLine);
1282 IO.mapOptional(
"AllowShortLambdasOnASingleLine",
1283 Style.AllowShortLambdasOnASingleLine);
1284 IO.mapOptional(
"AllowShortLoopsOnASingleLine",
1285 Style.AllowShortLoopsOnASingleLine);
1286 IO.mapOptional(
"AllowShortNamespacesOnASingleLine",
1287 Style.AllowShortNamespacesOnASingleLine);
1288 IO.mapOptional(
"AllowShortRecordOnASingleLine",
1289 Style.AllowShortRecordOnASingleLine);
1290 IO.mapOptional(
"AlwaysBreakAfterDefinitionReturnType",
1291 Style.AlwaysBreakAfterDefinitionReturnType);
1292 IO.mapOptional(
"AlwaysBreakBeforeMultilineStrings",
1293 Style.AlwaysBreakBeforeMultilineStrings);
1294 IO.mapOptional(
"AttributeMacros", Style.AttributeMacros);
1295 IO.mapOptional(
"BinPackLongBracedList", Style.BinPackLongBracedList);
1296 IO.mapOptional(
"BitFieldColonSpacing", Style.BitFieldColonSpacing);
1297 IO.mapOptional(
"BracedInitializerIndentWidth",
1298 Style.BracedInitializerIndentWidth);
1299 IO.mapOptional(
"BraceWrapping", Style.BraceWrapping);
1300 IO.mapOptional(
"BreakAdjacentStringLiterals",
1301 Style.BreakAdjacentStringLiterals);
1302 IO.mapOptional(
"BreakAfterAttributes", Style.BreakAfterAttributes);
1303 IO.mapOptional(
"BreakAfterJavaFieldAnnotations",
1304 Style.BreakAfterJavaFieldAnnotations);
1305 IO.mapOptional(
"BreakAfterOpenBracketBracedList",
1306 Style.BreakAfterOpenBracketBracedList);
1307 IO.mapOptional(
"BreakAfterOpenBracketFunction",
1308 Style.BreakAfterOpenBracketFunction);
1309 IO.mapOptional(
"BreakAfterOpenBracketIf", Style.BreakAfterOpenBracketIf);
1310 IO.mapOptional(
"BreakAfterOpenBracketLoop",
1311 Style.BreakAfterOpenBracketLoop);
1312 IO.mapOptional(
"BreakAfterOpenBracketSwitch",
1313 Style.BreakAfterOpenBracketSwitch);
1314 IO.mapOptional(
"BreakAfterReturnType", Style.BreakAfterReturnType);
1315 IO.mapOptional(
"BreakArrays", Style.BreakArrays);
1316 IO.mapOptional(
"BreakBeforeBinaryOperators",
1317 Style.BreakBeforeBinaryOperators);
1318 IO.mapOptional(
"BreakBeforeCloseBracketBracedList",
1319 Style.BreakBeforeCloseBracketBracedList);
1320 IO.mapOptional(
"BreakBeforeCloseBracketFunction",
1321 Style.BreakBeforeCloseBracketFunction);
1322 IO.mapOptional(
"BreakBeforeCloseBracketIf",
1323 Style.BreakBeforeCloseBracketIf);
1324 IO.mapOptional(
"BreakBeforeCloseBracketLoop",
1325 Style.BreakBeforeCloseBracketLoop);
1326 IO.mapOptional(
"BreakBeforeCloseBracketSwitch",
1327 Style.BreakBeforeCloseBracketSwitch);
1328 IO.mapOptional(
"BreakBeforeConceptDeclarations",
1329 Style.BreakBeforeConceptDeclarations);
1330 IO.mapOptional(
"BreakBeforeBraces", Style.BreakBeforeBraces);
1331 IO.mapOptional(
"BreakBeforeInlineASMColon",
1332 Style.BreakBeforeInlineASMColon);
1333 IO.mapOptional(
"BreakBeforeReturnType", Style.BreakBeforeReturnType);
1334 IO.mapOptional(
"BreakBeforeTemplateCloser",
1335 Style.BreakBeforeTemplateCloser);
1336 IO.mapOptional(
"BreakBeforeTernaryOperators",
1337 Style.BreakBeforeTernaryOperators);
1338 IO.mapOptional(
"BreakBinaryOperations", Style.BreakBinaryOperations);
1339 IO.mapOptional(
"BreakConstructorInitializers",
1340 Style.BreakConstructorInitializers);
1341 IO.mapOptional(
"BreakFunctionDeclarationParameters",
1342 Style.BreakFunctionDeclarationParameters);
1343 IO.mapOptional(
"BreakFunctionDefinitionParameters",
1344 Style.BreakFunctionDefinitionParameters);
1345 IO.mapOptional(
"BreakInheritanceList", Style.BreakInheritanceList);
1346 IO.mapOptional(
"BreakStringLiterals", Style.BreakStringLiterals);
1347 IO.mapOptional(
"BreakTemplateDeclarations",
1348 Style.BreakTemplateDeclarations);
1349 IO.mapOptional(
"ColumnLimit", Style.ColumnLimit);
1350 IO.mapOptional(
"CommentPragmas", Style.CommentPragmas);
1351 IO.mapOptional(
"CompactNamespaces", Style.CompactNamespaces);
1352 IO.mapOptional(
"ConstructorInitializerIndentWidth",
1353 Style.ConstructorInitializerIndentWidth);
1354 IO.mapOptional(
"ContinuationIndentWidth", Style.ContinuationIndentWidth);
1355 IO.mapOptional(
"Cpp11BracedListStyle", Style.Cpp11BracedListStyle);
1356 IO.mapOptional(
"DerivePointerAlignment", Style.DerivePointerAlignment);
1357 IO.mapOptional(
"DisableFormat", Style.DisableFormat);
1358 IO.mapOptional(
"EmptyLineAfterAccessModifier",
1359 Style.EmptyLineAfterAccessModifier);
1360 IO.mapOptional(
"EmptyLineBeforeAccessModifier",
1361 Style.EmptyLineBeforeAccessModifier);
1362 IO.mapOptional(
"EnumTrailingComma", Style.EnumTrailingComma);
1363 IO.mapOptional(
"ExperimentalAutoDetectBinPacking",
1364 Style.ExperimentalAutoDetectBinPacking);
1365 IO.mapOptional(
"FixNamespaceComments", Style.FixNamespaceComments);
1366 IO.mapOptional(
"ForEachMacros", Style.ForEachMacros);
1367 IO.mapOptional(
"IfMacros", Style.IfMacros);
1368 IO.mapOptional(
"IncludeBlocks", Style.IncludeStyle.IncludeBlocks);
1369 IO.mapOptional(
"IncludeCategories", Style.IncludeStyle.IncludeCategories);
1370 IO.mapOptional(
"IncludeIsMainRegex", Style.IncludeStyle.IncludeIsMainRegex);
1371 IO.mapOptional(
"IncludeIsMainSourceRegex",
1372 Style.IncludeStyle.IncludeIsMainSourceRegex);
1373 IO.mapOptional(
"IndentAccessModifiers", Style.IndentAccessModifiers);
1374 IO.mapOptional(
"IndentCaseBlocks", Style.IndentCaseBlocks);
1375 IO.mapOptional(
"IndentCaseLabels", Style.IndentCaseLabels);
1376 IO.mapOptional(
"IndentExportBlock", Style.IndentExportBlock);
1377 IO.mapOptional(
"IndentExternBlock", Style.IndentExternBlock);
1378 IO.mapOptional(
"IndentGotoLabels", Style.IndentGotoLabels);
1379 IO.mapOptional(
"IndentPPDirectives", Style.IndentPPDirectives);
1380 IO.mapOptional(
"IndentRequiresClause", Style.IndentRequiresClause);
1381 IO.mapOptional(
"IndentWidth", Style.IndentWidth);
1382 IO.mapOptional(
"IndentWrappedFunctionNames",
1383 Style.IndentWrappedFunctionNames);
1384 IO.mapOptional(
"InsertBraces", Style.InsertBraces);
1385 IO.mapOptional(
"InsertNewlineAtEOF", Style.InsertNewlineAtEOF);
1386 IO.mapOptional(
"InsertTrailingCommas", Style.InsertTrailingCommas);
1387 IO.mapOptional(
"IntegerLiteralSeparator", Style.IntegerLiteralSeparator);
1388 IO.mapOptional(
"JavaImportGroups", Style.JavaImportGroups);
1389 IO.mapOptional(
"JavaScriptQuotes", Style.JavaScriptQuotes);
1390 IO.mapOptional(
"JavaScriptWrapImports", Style.JavaScriptWrapImports);
1391 IO.mapOptional(
"KeepEmptyLines", Style.KeepEmptyLines);
1392 IO.mapOptional(
"KeepFormFeed", Style.KeepFormFeed);
1393 IO.mapOptional(
"LambdaBodyIndentation", Style.LambdaBodyIndentation);
1394 IO.mapOptional(
"LineEnding", Style.LineEnding);
1395 IO.mapOptional(
"MacroBlockBegin", Style.MacroBlockBegin);
1396 IO.mapOptional(
"MacroBlockEnd", Style.MacroBlockEnd);
1397 IO.mapOptional(
"Macros", Style.Macros);
1398 IO.mapOptional(
"MacrosSkippedByRemoveParentheses",
1399 Style.MacrosSkippedByRemoveParentheses);
1400 IO.mapOptional(
"MainIncludeChar", Style.IncludeStyle.MainIncludeChar);
1401 IO.mapOptional(
"MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
1402 IO.mapOptional(
"NamespaceIndentation", Style.NamespaceIndentation);
1403 IO.mapOptional(
"NamespaceMacros", Style.NamespaceMacros);
1404 IO.mapOptional(
"NumericLiteralCase", Style.NumericLiteralCase);
1405 IO.mapOptional(
"ObjCBinPackProtocolList", Style.ObjCBinPackProtocolList);
1406 IO.mapOptional(
"ObjCBlockIndentWidth", Style.ObjCBlockIndentWidth);
1407 IO.mapOptional(
"ObjCBreakBeforeNestedBlockParam",
1408 Style.ObjCBreakBeforeNestedBlockParam);
1409 IO.mapOptional(
"ObjCPropertyAttributeOrder",
1410 Style.ObjCPropertyAttributeOrder);
1411 IO.mapOptional(
"ObjCSpaceAfterMethodDeclarationPrefix",
1412 Style.ObjCSpaceAfterMethodDeclarationPrefix);
1413 IO.mapOptional(
"ObjCSpaceAfterProperty", Style.ObjCSpaceAfterProperty);
1414 IO.mapOptional(
"ObjCSpaceBeforeProtocolList",
1415 Style.ObjCSpaceBeforeProtocolList);
1416 IO.mapOptional(
"OneLineFormatOffRegex", Style.OneLineFormatOffRegex);
1417 IO.mapOptional(
"PackArguments", Style.PackArguments);
1418 IO.mapOptional(
"PackConstructorInitializers",
1419 Style.PackConstructorInitializers);
1420 IO.mapOptional(
"PackParameters", Style.PackParameters);
1421 IO.mapOptional(
"PenaltyBreakAssignment", Style.PenaltyBreakAssignment);
1422 IO.mapOptional(
"PenaltyBreakBeforeFirstCallParameter",
1423 Style.PenaltyBreakBeforeFirstCallParameter);
1424 IO.mapOptional(
"PenaltyBreakBeforeMemberAccess",
1425 Style.PenaltyBreakBeforeMemberAccess);
1426 IO.mapOptional(
"PenaltyBreakComment", Style.PenaltyBreakComment);
1427 IO.mapOptional(
"PenaltyBreakFirstLessLess",
1428 Style.PenaltyBreakFirstLessLess);
1429 IO.mapOptional(
"PenaltyBreakOpenParenthesis",
1430 Style.PenaltyBreakOpenParenthesis);
1431 IO.mapOptional(
"PenaltyBreakScopeResolution",
1432 Style.PenaltyBreakScopeResolution);
1433 IO.mapOptional(
"PenaltyBreakString", Style.PenaltyBreakString);
1434 IO.mapOptional(
"PenaltyBreakTemplateDeclaration",
1435 Style.PenaltyBreakTemplateDeclaration);
1436 IO.mapOptional(
"PenaltyExcessCharacter", Style.PenaltyExcessCharacter);
1437 IO.mapOptional(
"PenaltyIndentedWhitespace",
1438 Style.PenaltyIndentedWhitespace);
1439 IO.mapOptional(
"PenaltyReturnTypeOnItsOwnLine",
1440 Style.PenaltyReturnTypeOnItsOwnLine);
1441 IO.mapOptional(
"PointerAlignment", Style.PointerAlignment);
1442 IO.mapOptional(
"PPIndentWidth", Style.PPIndentWidth);
1443 IO.mapOptional(
"QualifierAlignment", Style.QualifierAlignment);
1445 if (Style.QualifierAlignment == FormatStyle::QAS_Right)
1446 Style.QualifierOrder = {
"type",
"const",
"volatile"};
1447 else if (Style.QualifierAlignment == FormatStyle::QAS_Left)
1448 Style.QualifierOrder = {
"const",
"volatile",
"type"};
1449 else if (Style.QualifierAlignment == FormatStyle::QAS_Custom)
1450 IO.mapOptional(
"QualifierOrder", Style.QualifierOrder);
1451 IO.mapOptional(
"RawStringFormats", Style.RawStringFormats);
1452 IO.mapOptional(
"ReferenceAlignment", Style.ReferenceAlignment);
1453 IO.mapOptional(
"ReflowComments", Style.ReflowComments);
1454 IO.mapOptional(
"RemoveBracesLLVM", Style.RemoveBracesLLVM);
1455 IO.mapOptional(
"RemoveEmptyLinesInUnwrappedLines",
1456 Style.RemoveEmptyLinesInUnwrappedLines);
1457 IO.mapOptional(
"RemoveParentheses", Style.RemoveParentheses);
1458 IO.mapOptional(
"RemoveSemicolon", Style.RemoveSemicolon);
1459 IO.mapOptional(
"RequiresClausePosition", Style.RequiresClausePosition);
1460 IO.mapOptional(
"RequiresExpressionIndentation",
1461 Style.RequiresExpressionIndentation);
1462 IO.mapOptional(
"SeparateDefinitionBlocks", Style.SeparateDefinitionBlocks);
1463 IO.mapOptional(
"ShortNamespaceLines", Style.ShortNamespaceLines);
1464 IO.mapOptional(
"SkipMacroDefinitionBody", Style.SkipMacroDefinitionBody);
1465 IO.mapOptional(
"SortIncludes", Style.SortIncludes);
1466 IO.mapOptional(
"SortJavaStaticImport", Style.SortJavaStaticImport);
1467 IO.mapOptional(
"SortUsingDeclarations", Style.SortUsingDeclarations);
1468 IO.mapOptional(
"SpaceAfterCStyleCast", Style.SpaceAfterCStyleCast);
1469 IO.mapOptional(
"SpaceAfterLogicalNot", Style.SpaceAfterLogicalNot);
1470 IO.mapOptional(
"SpaceAfterOperatorKeyword",
1471 Style.SpaceAfterOperatorKeyword);
1472 IO.mapOptional(
"SpaceAfterTemplateKeyword",
1473 Style.SpaceAfterTemplateKeyword);
1474 IO.mapOptional(
"SpaceAroundPointerQualifiers",
1475 Style.SpaceAroundPointerQualifiers);
1476 IO.mapOptional(
"SpaceBeforeAssignmentOperators",
1477 Style.SpaceBeforeAssignmentOperators);
1478 IO.mapOptional(
"SpaceBeforeCaseColon", Style.SpaceBeforeCaseColon);
1479 IO.mapOptional(
"SpaceBeforeCpp11BracedList",
1480 Style.SpaceBeforeCpp11BracedList);
1481 IO.mapOptional(
"SpaceBeforeCtorInitializerColon",
1482 Style.SpaceBeforeCtorInitializerColon);
1483 IO.mapOptional(
"SpaceBeforeEnumUnderlyingTypeColon",
1484 Style.SpaceBeforeEnumUnderlyingTypeColon);
1485 IO.mapOptional(
"SpaceBeforeInheritanceColon",
1486 Style.SpaceBeforeInheritanceColon);
1487 IO.mapOptional(
"SpaceBeforeJsonColon", Style.SpaceBeforeJsonColon);
1488 IO.mapOptional(
"SpaceBeforeParens", Style.SpaceBeforeParens);
1489 IO.mapOptional(
"SpaceBeforeParensOptions", Style.SpaceBeforeParensOptions);
1490 IO.mapOptional(
"SpaceBeforeRangeBasedForLoopColon",
1491 Style.SpaceBeforeRangeBasedForLoopColon);
1492 IO.mapOptional(
"SpaceBeforeSquareBrackets",
1493 Style.SpaceBeforeSquareBrackets);
1494 IO.mapOptional(
"SpaceInEmptyBraces", Style.SpaceInEmptyBraces);
1495 IO.mapOptional(
"SpacesBeforeTrailingComments",
1496 Style.SpacesBeforeTrailingComments);
1497 IO.mapOptional(
"SpacesInAngles", Style.SpacesInAngles);
1498 IO.mapOptional(
"SpacesInContainerLiterals",
1499 Style.SpacesInContainerLiterals);
1500 IO.mapOptional(
"SpacesInLineCommentPrefix",
1501 Style.SpacesInLineCommentPrefix);
1502 IO.mapOptional(
"SpacesInParens", Style.SpacesInParens);
1503 IO.mapOptional(
"SpacesInParensOptions", Style.SpacesInParensOptions);
1504 IO.mapOptional(
"SpacesInSquareBrackets", Style.SpacesInSquareBrackets);
1505 IO.mapOptional(
"Standard", Style.Standard);
1506 IO.mapOptional(
"StatementAttributeLikeMacros",
1507 Style.StatementAttributeLikeMacros);
1508 IO.mapOptional(
"StatementMacros", Style.StatementMacros);
1509 IO.mapOptional(
"TableGenBreakingDAGArgOperators",
1510 Style.TableGenBreakingDAGArgOperators);
1511 IO.mapOptional(
"TableGenBreakInsideDAGArg",
1512 Style.TableGenBreakInsideDAGArg);
1513 IO.mapOptional(
"TabWidth", Style.TabWidth);
1514 IO.mapOptional(
"TemplateNames", Style.TemplateNames);
1515 IO.mapOptional(
"TypeNames", Style.TypeNames);
1516 IO.mapOptional(
"TypenameMacros", Style.TypenameMacros);
1517 IO.mapOptional(
"UseTab", Style.UseTab);
1518 IO.mapOptional(
"VariableTemplates", Style.VariableTemplates);
1519 IO.mapOptional(
"VerilogBreakBetweenInstancePorts",
1520 Style.VerilogBreakBetweenInstancePorts);
1521 IO.mapOptional(
"WhitespaceSensitiveMacros",
1522 Style.WhitespaceSensitiveMacros);
1523 IO.mapOptional(
"WrapNamespaceBodyWithEmptyLines",
1524 Style.WrapNamespaceBodyWithEmptyLines);
1529 if (Style.AlwaysBreakAfterDefinitionReturnType != FormatStyle::DRTBS_None &&
1530 Style.BreakAfterReturnType == FormatStyle::RTBS_None) {
1531 if (Style.AlwaysBreakAfterDefinitionReturnType ==
1532 FormatStyle::DRTBS_All) {
1533 Style.BreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
1534 }
else if (Style.AlwaysBreakAfterDefinitionReturnType ==
1535 FormatStyle::DRTBS_TopLevel) {
1536 Style.BreakAfterReturnType = FormatStyle::RTBS_TopLevelDefinitions;
1542 if (BreakBeforeInheritanceComma &&
1543 Style.BreakInheritanceList == FormatStyle::BILS_BeforeColon) {
1544 Style.BreakInheritanceList = FormatStyle::BILS_BeforeComma;
1550 if (BreakConstructorInitializersBeforeComma &&
1551 Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeColon) {
1552 Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;
1555 if (!IsGoogleOrChromium) {
1556 if (Style.PackConstructorInitializers == FormatStyle::PCIS_BinPack &&
1558 Style.PackConstructorInitializers = OnNextLine
1559 ? FormatStyle::PCIS_NextLine
1560 : FormatStyle::PCIS_CurrentLine;
1562 }
else if (Style.PackConstructorInitializers ==
1563 FormatStyle::PCIS_NextLine) {
1565 Style.PackConstructorInitializers = FormatStyle::PCIS_BinPack;
1566 else if (!OnNextLine)
1567 Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
1570 if (Style.LineEnding == FormatStyle::LE_DeriveLF) {
1571 if (!DeriveLineEnding)
1572 Style.LineEnding = UseCRLF ? FormatStyle::LE_CRLF : FormatStyle::LE_LF;
1574 Style.LineEnding = FormatStyle::LE_DeriveCRLF;
1579 if (SpaceInEmptyBlock &&
1580 Style.SpaceInEmptyBraces == FormatStyle::SIEB_Never) {
1581 Style.SpaceInEmptyBraces = FormatStyle::SIEB_Block;
1584 if (Style.SpacesInParens != FormatStyle::SIPO_Custom &&
1585 (SpacesInParentheses || SpaceInEmptyParentheses ||
1586 SpacesInConditionalStatement || SpacesInCStyleCastParentheses)) {
1587 if (SpacesInParentheses) {
1589 Style.SpacesInParensOptions.ExceptDoubleParentheses =
false;
1590 Style.SpacesInParensOptions.InConditionalStatements =
true;
1591 Style.SpacesInParensOptions.InCStyleCasts =
1592 SpacesInCStyleCastParentheses;
1593 Style.SpacesInParensOptions.InEmptyParentheses =
1594 SpaceInEmptyParentheses;
1595 Style.SpacesInParensOptions.Other =
true;
1597 Style.SpacesInParensOptions = {};
1598 Style.SpacesInParensOptions.InConditionalStatements =
1599 SpacesInConditionalStatement;
1600 Style.SpacesInParensOptions.InCStyleCasts =
1601 SpacesInCStyleCastParentheses;
1602 Style.SpacesInParensOptions.InEmptyParentheses =
1603 SpaceInEmptyParentheses;
1605 Style.SpacesInParens = FormatStyle::SIPO_Custom;
1615template <>
struct DocumentListTraits<
std::vector<FormatStyle>> {
1616 static size_t size(IO &IO, std::vector<FormatStyle> &Seq) {
1619 static FormatStyle &
element(IO &IO, std::vector<FormatStyle> &Seq,
1621 if (Index >= Seq.size()) {
1622 assert(Index == Seq.size());
1623 FormatStyle Template;
1624 if (!Seq.empty() && Seq[0].Language == FormatStyle::LK_None) {
1627 Template = *((
const FormatStyle *)IO.getContext());
1628 Template.Language = FormatStyle::LK_None;
1630 Seq.resize(Index + 1, Template);
1636template <>
struct ScalarEnumerationTraits<FormatStyle::IndentGotoLabelStyle> {
1638 IO.enumCase(
Value,
"NoIndent", FormatStyle::IGLS_NoIndent);
1639 IO.enumCase(
Value,
"OuterIndent", FormatStyle::IGLS_OuterIndent);
1640 IO.enumCase(
Value,
"InnerIndent", FormatStyle::IGLS_InnerIndent);
1641 IO.enumCase(
Value,
"HalfIndent", FormatStyle::IGLS_HalfIndent);
1644 IO.enumCase(
Value,
"false", FormatStyle::IGLS_NoIndent);
1645 IO.enumCase(
Value,
"true", FormatStyle::IGLS_OuterIndent);
1664 return llvm::make_error<llvm::StringError>(Message,
1665 llvm::inconvertibleErrorCode());
1669 return "clang-format.parse_error";
1677 return "Invalid argument";
1679 return "Unsuitable";
1681 return "trailing comma insertion cannot be used with bin packing";
1683 return "Invalid qualifier specified in QualifierOrder";
1685 return "Duplicate qualifier specified in QualifierOrder";
1687 return "Missing type in QualifierOrder";
1689 return "Missing QualifierOrder";
1691 llvm_unreachable(
"unexpected parse error");
1695 if (Expanded.BreakBeforeBraces == FormatStyle::BS_Custom)
1697 Expanded.BraceWrapping = {
false,
1699 FormatStyle::BWACS_Never,
1715 switch (Expanded.BreakBeforeBraces) {
1716 case FormatStyle::BS_Linux:
1717 Expanded.BraceWrapping.AfterClass =
true;
1718 Expanded.BraceWrapping.AfterFunction =
true;
1719 Expanded.BraceWrapping.AfterNamespace =
true;
1721 case FormatStyle::BS_Mozilla:
1722 Expanded.BraceWrapping.AfterClass =
true;
1723 Expanded.BraceWrapping.AfterEnum =
true;
1724 Expanded.BraceWrapping.AfterFunction =
true;
1725 Expanded.BraceWrapping.AfterStruct =
true;
1726 Expanded.BraceWrapping.AfterUnion =
true;
1727 Expanded.BraceWrapping.AfterExternBlock =
true;
1728 Expanded.BraceWrapping.SplitEmptyFunction =
true;
1729 Expanded.BraceWrapping.SplitEmptyRecord =
false;
1731 case FormatStyle::BS_Stroustrup:
1732 Expanded.BraceWrapping.AfterFunction =
true;
1733 Expanded.BraceWrapping.BeforeCatch =
true;
1734 Expanded.BraceWrapping.BeforeElse =
true;
1736 case FormatStyle::BS_Allman:
1737 Expanded.BraceWrapping.AfterCaseLabel =
true;
1738 Expanded.BraceWrapping.AfterClass =
true;
1739 Expanded.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_Always;
1740 Expanded.BraceWrapping.AfterEnum =
true;
1741 Expanded.BraceWrapping.AfterFunction =
true;
1742 Expanded.BraceWrapping.AfterNamespace =
true;
1743 Expanded.BraceWrapping.AfterObjCDeclaration =
true;
1744 Expanded.BraceWrapping.AfterStruct =
true;
1745 Expanded.BraceWrapping.AfterUnion =
true;
1746 Expanded.BraceWrapping.AfterExternBlock =
true;
1747 Expanded.BraceWrapping.BeforeCatch =
true;
1748 Expanded.BraceWrapping.BeforeElse =
true;
1749 Expanded.BraceWrapping.BeforeLambdaBody =
true;
1751 case FormatStyle::BS_Whitesmiths:
1752 Expanded.BraceWrapping.AfterCaseLabel =
true;
1753 Expanded.BraceWrapping.AfterClass =
true;
1754 Expanded.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_Always;
1755 Expanded.BraceWrapping.AfterEnum =
true;
1756 Expanded.BraceWrapping.AfterFunction =
true;
1757 Expanded.BraceWrapping.AfterNamespace =
true;
1758 Expanded.BraceWrapping.AfterObjCDeclaration =
true;
1759 Expanded.BraceWrapping.AfterStruct =
true;
1760 Expanded.BraceWrapping.AfterExternBlock =
true;
1761 Expanded.BraceWrapping.BeforeCatch =
true;
1762 Expanded.BraceWrapping.BeforeElse =
true;
1763 Expanded.BraceWrapping.BeforeLambdaBody =
true;
1765 case FormatStyle::BS_GNU:
1766 Expanded.BraceWrapping = {
1769 FormatStyle::BWACS_Always,
1786 case FormatStyle::BS_WebKit:
1787 Expanded.BraceWrapping.AfterFunction =
true;
1795 if (Expanded.SpaceBeforeParens == FormatStyle::SBPO_Custom)
1798 Expanded.SpaceBeforeParensOptions = {};
1799 Expanded.SpaceBeforeParensOptions.AfterPlacementOperator =
true;
1801 switch (Expanded.SpaceBeforeParens) {
1802 case FormatStyle::SBPO_ControlStatements:
1803 Expanded.SpaceBeforeParensOptions.AfterControlStatements =
true;
1804 Expanded.SpaceBeforeParensOptions.AfterForeachMacros =
true;
1805 Expanded.SpaceBeforeParensOptions.AfterIfMacros =
true;
1807 case FormatStyle::SBPO_ControlStatementsExceptControlMacros:
1808 Expanded.SpaceBeforeParensOptions.AfterControlStatements =
true;
1810 case FormatStyle::SBPO_NonEmptyParentheses:
1811 Expanded.SpaceBeforeParensOptions.BeforeNonEmptyParentheses =
true;
1819 if (Expanded.SpacesInParens == FormatStyle::SIPO_Custom)
1821 assert(Expanded.SpacesInParens == FormatStyle::SIPO_Never);
1823 Expanded.SpacesInParensOptions = {};
1827 FormatStyle LLVMStyle;
1828 LLVMStyle.AccessModifierOffset = -2;
1829 LLVMStyle.AlignAfterOpenBracket =
true;
1830 LLVMStyle.AlignArrayOfStructures = FormatStyle::AIAS_None;
1831 LLVMStyle.AlignConsecutiveAssignments = {};
1832 LLVMStyle.AlignConsecutiveAssignments.PadOperators =
true;
1833 LLVMStyle.AlignConsecutiveBitFields = {};
1834 LLVMStyle.AlignConsecutiveDeclarations = {};
1835 LLVMStyle.AlignConsecutiveDeclarations.AlignFunctionDeclarations =
true;
1836 LLVMStyle.AlignConsecutiveMacros = {};
1837 LLVMStyle.AlignConsecutiveShortCaseStatements = {};
1838 LLVMStyle.AlignConsecutiveTableGenBreakingDAGArgColons = {};
1839 LLVMStyle.AlignConsecutiveTableGenCondOperatorColons = {};
1840 LLVMStyle.AlignConsecutiveTableGenDefinitionColons = {};
1841 LLVMStyle.AlignEscapedNewlines = FormatStyle::ENAS_Right;
1842 LLVMStyle.AlignOperands = FormatStyle::OAS_Align;
1843 LLVMStyle.AlignTrailingComments = {};
1844 LLVMStyle.AlignTrailingComments.Kind = FormatStyle::TCAS_Always;
1845 LLVMStyle.AlignTrailingComments.OverEmptyLines = 0;
1846 LLVMStyle.AlignTrailingComments.AlignPPAndNotPP =
true;
1847 LLVMStyle.AllowAllArgumentsOnNextLine =
true;
1848 LLVMStyle.AllowAllParametersOfDeclarationOnNextLine =
true;
1849 LLVMStyle.AllowBreakBeforeNoexceptSpecifier = FormatStyle::BBNSS_Never;
1850 LLVMStyle.AllowBreakBeforeQtProperty =
false;
1851 LLVMStyle.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Never;
1852 LLVMStyle.AllowShortCaseExpressionOnASingleLine =
true;
1853 LLVMStyle.AllowShortCaseLabelsOnASingleLine =
false;
1854 LLVMStyle.AllowShortCompoundRequirementOnASingleLine =
true;
1855 LLVMStyle.AllowShortEnumsOnASingleLine =
true;
1856 LLVMStyle.AllowShortFunctionsOnASingleLine =
1857 FormatStyle::ShortFunctionStyle::setAll();
1858 LLVMStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
1859 LLVMStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_All;
1860 LLVMStyle.AllowShortLoopsOnASingleLine =
false;
1861 LLVMStyle.AllowShortNamespacesOnASingleLine =
false;
1862 LLVMStyle.AllowShortRecordOnASingleLine = FormatStyle::SRS_EmptyAndAttached;
1863 LLVMStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
1864 LLVMStyle.AlwaysBreakBeforeMultilineStrings =
false;
1865 LLVMStyle.AttributeMacros.push_back(
"__capability");
1866 LLVMStyle.BinPackLongBracedList =
true;
1867 LLVMStyle.BitFieldColonSpacing = FormatStyle::BFCS_Both;
1868 LLVMStyle.BracedInitializerIndentWidth = -1;
1869 LLVMStyle.BraceWrapping = {
false,
1871 FormatStyle::BWACS_Never,
1887 LLVMStyle.BreakAdjacentStringLiterals =
true;
1888 LLVMStyle.BreakAfterAttributes = FormatStyle::ABS_Leave;
1889 LLVMStyle.BreakAfterJavaFieldAnnotations =
false;
1890 LLVMStyle.BreakAfterOpenBracketBracedList =
false;
1891 LLVMStyle.BreakAfterOpenBracketFunction =
false;
1892 LLVMStyle.BreakAfterOpenBracketIf =
false;
1893 LLVMStyle.BreakAfterOpenBracketLoop =
false;
1894 LLVMStyle.BreakAfterOpenBracketSwitch =
false;
1895 LLVMStyle.BreakAfterReturnType = FormatStyle::RTBS_None;
1896 LLVMStyle.BreakArrays =
true;
1897 LLVMStyle.BreakBeforeBinaryOperators = FormatStyle::BOS_None;
1898 LLVMStyle.BreakBeforeBraces = FormatStyle::BS_Attach;
1899 LLVMStyle.BreakBeforeCloseBracketBracedList =
false;
1900 LLVMStyle.BreakBeforeCloseBracketFunction =
false;
1901 LLVMStyle.BreakBeforeCloseBracketIf =
false;
1902 LLVMStyle.BreakBeforeCloseBracketLoop =
false;
1903 LLVMStyle.BreakBeforeCloseBracketSwitch =
false;
1904 LLVMStyle.BreakBeforeConceptDeclarations = FormatStyle::BBCDS_Always;
1905 LLVMStyle.BreakBeforeInlineASMColon = FormatStyle::BBIAS_OnlyMultiline;
1906 LLVMStyle.BreakBeforeReturnType = FormatStyle::BBRTS_None;
1907 LLVMStyle.BreakBeforeTemplateCloser =
false;
1908 LLVMStyle.BreakBeforeTernaryOperators =
true;
1909 LLVMStyle.BreakBinaryOperations = {FormatStyle::BBO_Never, {}};
1910 LLVMStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon;
1911 LLVMStyle.BreakFunctionDeclarationParameters =
false;
1912 LLVMStyle.BreakFunctionDefinitionParameters =
false;
1913 LLVMStyle.BreakInheritanceList = FormatStyle::BILS_BeforeColon;
1914 LLVMStyle.BreakStringLiterals =
true;
1915 LLVMStyle.BreakTemplateDeclarations = FormatStyle::BTDS_MultiLine;
1916 LLVMStyle.ColumnLimit = 80;
1917 LLVMStyle.CommentPragmas =
"^ IWYU pragma:";
1918 LLVMStyle.CompactNamespaces =
false;
1919 LLVMStyle.ConstructorInitializerIndentWidth = 4;
1920 LLVMStyle.ContinuationIndentWidth = 4;
1921 LLVMStyle.Cpp11BracedListStyle = FormatStyle::BLS_AlignFirstComment;
1922 LLVMStyle.DerivePointerAlignment =
false;
1923 LLVMStyle.DisableFormat =
false;
1924 LLVMStyle.EmptyLineAfterAccessModifier = FormatStyle::ELAAMS_Never;
1925 LLVMStyle.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_LogicalBlock;
1926 LLVMStyle.EnumTrailingComma = FormatStyle::ETC_Leave;
1927 LLVMStyle.ExperimentalAutoDetectBinPacking =
false;
1928 LLVMStyle.FixNamespaceComments =
true;
1929 LLVMStyle.ForEachMacros.push_back(
"foreach");
1930 LLVMStyle.ForEachMacros.push_back(
"Q_FOREACH");
1931 LLVMStyle.ForEachMacros.push_back(
"BOOST_FOREACH");
1932 LLVMStyle.IfMacros.push_back(
"KJ_IF_MAYBE");
1934 LLVMStyle.IncludeStyle.IncludeCategories = {
1935 {
"^\"(llvm|llvm-c|clang|clang-c)/", 2, 0,
false},
1936 {
"^(<|\"(gtest|gmock|isl|json)/)", 3, 0,
false},
1937 {
".*", 1, 0,
false}};
1938 LLVMStyle.IncludeStyle.IncludeIsMainRegex =
"(Test)?$";
1939 LLVMStyle.IncludeStyle.MainIncludeChar = tooling::IncludeStyle::MICD_Quote;
1940 LLVMStyle.IndentAccessModifiers =
false;
1941 LLVMStyle.IndentCaseBlocks =
false;
1942 LLVMStyle.IndentCaseLabels =
false;
1943 LLVMStyle.IndentExportBlock =
true;
1944 LLVMStyle.IndentExternBlock = FormatStyle::IEBS_AfterExternBlock;
1945 LLVMStyle.IndentGotoLabels = FormatStyle::IGLS_OuterIndent;
1946 LLVMStyle.IndentPPDirectives = FormatStyle::PPDIS_None;
1947 LLVMStyle.IndentRequiresClause =
true;
1948 LLVMStyle.IndentWidth = 2;
1949 LLVMStyle.IndentWrappedFunctionNames =
false;
1950 LLVMStyle.InsertBraces =
false;
1951 LLVMStyle.InsertNewlineAtEOF =
false;
1952 LLVMStyle.InsertTrailingCommas = FormatStyle::TCS_None;
1953 LLVMStyle.IntegerLiteralSeparator = {};
1954 LLVMStyle.JavaScriptQuotes = FormatStyle::JSQS_Leave;
1955 LLVMStyle.JavaScriptWrapImports =
true;
1956 LLVMStyle.KeepEmptyLines = {
1961 LLVMStyle.KeepFormFeed =
false;
1962 LLVMStyle.LambdaBodyIndentation = FormatStyle::LBI_Signature;
1964 LLVMStyle.LineEnding = FormatStyle::LE_DeriveLF;
1965 LLVMStyle.MaxEmptyLinesToKeep = 1;
1966 LLVMStyle.NamespaceIndentation = FormatStyle::NI_None;
1967 LLVMStyle.NumericLiteralCase = {FormatStyle::NLCS_Leave,
1968 FormatStyle::NLCS_Leave,
1969 FormatStyle::NLCS_Leave,
1970 FormatStyle::NLCS_Leave};
1971 LLVMStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Auto;
1972 LLVMStyle.ObjCBlockIndentWidth = 2;
1973 LLVMStyle.ObjCBreakBeforeNestedBlockParam =
true;
1974 LLVMStyle.ObjCSpaceAfterMethodDeclarationPrefix =
true;
1975 LLVMStyle.ObjCSpaceAfterProperty =
false;
1976 LLVMStyle.ObjCSpaceBeforeProtocolList =
true;
1977 LLVMStyle.PackArguments = {FormatStyle::BPAS_BinPack,
1979 LLVMStyle.PackConstructorInitializers = FormatStyle::PCIS_BinPack;
1980 LLVMStyle.PackParameters = {FormatStyle::BPPS_BinPack,
1982 LLVMStyle.PointerAlignment = FormatStyle::PAS_Right;
1983 LLVMStyle.PPIndentWidth = -1;
1984 LLVMStyle.QualifierAlignment = FormatStyle::QAS_Leave;
1985 LLVMStyle.ReferenceAlignment = FormatStyle::RAS_Pointer;
1986 LLVMStyle.ReflowComments = FormatStyle::RCS_Always;
1987 LLVMStyle.RemoveBracesLLVM =
false;
1988 LLVMStyle.RemoveEmptyLinesInUnwrappedLines =
false;
1989 LLVMStyle.RemoveParentheses = FormatStyle::RPS_Leave;
1990 LLVMStyle.RemoveSemicolon =
false;
1991 LLVMStyle.RequiresClausePosition = FormatStyle::RCPS_OwnLine;
1992 LLVMStyle.RequiresExpressionIndentation = FormatStyle::REI_OuterScope;
1993 LLVMStyle.SeparateDefinitionBlocks = FormatStyle::SDS_Leave;
1994 LLVMStyle.ShortNamespaceLines = 1;
1995 LLVMStyle.SkipMacroDefinitionBody =
false;
1996 LLVMStyle.SortIncludes = {
true,
false,
1998 LLVMStyle.SortJavaStaticImport = FormatStyle::SJSIO_Before;
1999 LLVMStyle.SortUsingDeclarations = FormatStyle::SUD_LexicographicNumeric;
2000 LLVMStyle.SpaceAfterCStyleCast =
false;
2001 LLVMStyle.SpaceAfterLogicalNot =
false;
2002 LLVMStyle.SpaceAfterOperatorKeyword =
false;
2003 LLVMStyle.SpaceAfterTemplateKeyword =
true;
2004 LLVMStyle.SpaceAroundPointerQualifiers = FormatStyle::SAPQ_Default;
2005 LLVMStyle.SpaceBeforeAssignmentOperators =
true;
2006 LLVMStyle.SpaceBeforeCaseColon =
false;
2007 LLVMStyle.SpaceBeforeCpp11BracedList =
false;
2008 LLVMStyle.SpaceBeforeCtorInitializerColon =
true;
2009 LLVMStyle.SpaceBeforeEnumUnderlyingTypeColon =
true;
2010 LLVMStyle.SpaceBeforeInheritanceColon =
true;
2011 LLVMStyle.SpaceBeforeJsonColon =
false;
2012 LLVMStyle.SpaceBeforeParens = FormatStyle::SBPO_ControlStatements;
2013 LLVMStyle.SpaceBeforeParensOptions = {};
2014 LLVMStyle.SpaceBeforeParensOptions.AfterControlStatements =
true;
2015 LLVMStyle.SpaceBeforeParensOptions.AfterForeachMacros =
true;
2016 LLVMStyle.SpaceBeforeParensOptions.AfterIfMacros =
true;
2017 LLVMStyle.SpaceBeforeRangeBasedForLoopColon =
true;
2018 LLVMStyle.SpaceBeforeSquareBrackets =
false;
2019 LLVMStyle.SpaceInEmptyBraces = FormatStyle::SIEB_Never;
2020 LLVMStyle.SpacesBeforeTrailingComments = 1;
2021 LLVMStyle.SpacesInAngles = FormatStyle::SIAS_Never;
2022 LLVMStyle.SpacesInContainerLiterals =
true;
2023 LLVMStyle.SpacesInLineCommentPrefix = {
2024 1, std::numeric_limits<unsigned>::max()};
2025 LLVMStyle.SpacesInParens = FormatStyle::SIPO_Never;
2026 LLVMStyle.SpacesInSquareBrackets =
false;
2027 LLVMStyle.Standard = FormatStyle::LS_Latest;
2028 LLVMStyle.StatementAttributeLikeMacros.push_back(
"Q_EMIT");
2029 LLVMStyle.StatementMacros.push_back(
"Q_UNUSED");
2030 LLVMStyle.StatementMacros.push_back(
"QT_REQUIRE_VERSION");
2031 LLVMStyle.TableGenBreakingDAGArgOperators = {};
2032 LLVMStyle.TableGenBreakInsideDAGArg = FormatStyle::DAS_DontBreak;
2033 LLVMStyle.TabWidth = 8;
2034 LLVMStyle.UseTab = FormatStyle::UT_Never;
2035 LLVMStyle.VerilogBreakBetweenInstancePorts =
true;
2036 LLVMStyle.WhitespaceSensitiveMacros.push_back(
"BOOST_PP_STRINGIZE");
2037 LLVMStyle.WhitespaceSensitiveMacros.push_back(
"CF_SWIFT_NAME");
2038 LLVMStyle.WhitespaceSensitiveMacros.push_back(
"NS_SWIFT_NAME");
2039 LLVMStyle.WhitespaceSensitiveMacros.push_back(
"PP_STRINGIZE");
2040 LLVMStyle.WhitespaceSensitiveMacros.push_back(
"STRINGIZE");
2041 LLVMStyle.WrapNamespaceBodyWithEmptyLines = FormatStyle::WNBWELS_Leave;
2044 LLVMStyle.PenaltyBreakBeforeFirstCallParameter = 19;
2045 LLVMStyle.PenaltyBreakBeforeMemberAccess = 150;
2046 LLVMStyle.PenaltyBreakComment = 300;
2047 LLVMStyle.PenaltyBreakFirstLessLess = 120;
2048 LLVMStyle.PenaltyBreakOpenParenthesis = 0;
2049 LLVMStyle.PenaltyBreakScopeResolution = 500;
2050 LLVMStyle.PenaltyBreakString = 1000;
2052 LLVMStyle.PenaltyExcessCharacter = 1'000'000;
2053 LLVMStyle.PenaltyIndentedWhitespace = 0;
2054 LLVMStyle.PenaltyReturnTypeOnItsOwnLine = 60;
2058 case FormatStyle::LK_TableGen:
2059 LLVMStyle.SpacesInContainerLiterals =
false;
2061 case FormatStyle::LK_Json:
2062 LLVMStyle.ColumnLimit = 0;
2064 case FormatStyle::LK_Verilog:
2065 LLVMStyle.IndentCaseLabels =
true;
2066 LLVMStyle.SpacesInContainerLiterals =
false;
2076 if (
Language == FormatStyle::LK_TextProto) {
2078 GoogleStyle.Language = FormatStyle::LK_TextProto;
2085 GoogleStyle.AccessModifierOffset = -1;
2086 GoogleStyle.AlignEscapedNewlines = FormatStyle::ENAS_Left;
2087 GoogleStyle.AllowShortIfStatementsOnASingleLine =
2088 FormatStyle::SIS_WithoutElse;
2089 GoogleStyle.AllowShortLoopsOnASingleLine =
true;
2090 GoogleStyle.AlwaysBreakBeforeMultilineStrings =
true;
2092 GoogleStyle.AttributeMacros.push_back(
"absl_nonnull");
2093 GoogleStyle.AttributeMacros.push_back(
"absl_nullable");
2094 GoogleStyle.AttributeMacros.push_back(
"absl_nullability_unknown");
2095 GoogleStyle.BreakTemplateDeclarations = FormatStyle::BTDS_Yes;
2097 GoogleStyle.IncludeStyle.IncludeCategories = {{
"^<ext/.*\\.h>", 2, 0,
false},
2098 {
"^<.*\\.h>", 1, 0,
false},
2099 {
"^<.*", 2, 0,
false},
2100 {
".*", 3, 0,
false}};
2101 GoogleStyle.IncludeStyle.IncludeIsMainRegex =
"([-_](test|unittest))?$";
2102 GoogleStyle.IndentCaseLabels =
true;
2103 GoogleStyle.KeepEmptyLines.AtStartOfBlock =
false;
2104 GoogleStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Never;
2105 GoogleStyle.ObjCSpaceAfterProperty =
false;
2106 GoogleStyle.ObjCSpaceBeforeProtocolList =
true;
2107 GoogleStyle.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
2108 GoogleStyle.PointerAlignment = FormatStyle::PAS_Left;
2109 GoogleStyle.RawStringFormats = {
2111 FormatStyle::LK_Cpp,
2128 FormatStyle::LK_TextProto,
2140 "PARSE_PARTIAL_TEXT_PROTO",
2144 "ParseTextProtoOrDie",
2146 "ParsePartialTestProto",
2153 GoogleStyle.SpacesBeforeTrailingComments = 2;
2154 GoogleStyle.Standard = FormatStyle::LS_Auto;
2156 GoogleStyle.PenaltyBreakBeforeFirstCallParameter = 1;
2157 GoogleStyle.PenaltyReturnTypeOnItsOwnLine = 200;
2159 if (
Language == FormatStyle::LK_Java) {
2160 GoogleStyle.AlignAfterOpenBracket =
false;
2161 GoogleStyle.AlignOperands = FormatStyle::OAS_DontAlign;
2162 GoogleStyle.AlignTrailingComments = {};
2163 GoogleStyle.AlignTrailingComments.Kind = FormatStyle::TCAS_Never;
2164 GoogleStyle.AllowShortFunctionsOnASingleLine =
2165 FormatStyle::ShortFunctionStyle::setEmptyOnly();
2166 GoogleStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
2167 GoogleStyle.AlwaysBreakBeforeMultilineStrings =
false;
2168 GoogleStyle.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment;
2169 GoogleStyle.ColumnLimit = 100;
2170 GoogleStyle.SpaceAfterCStyleCast =
true;
2171 GoogleStyle.SpacesBeforeTrailingComments = 1;
2172 }
else if (
Language == FormatStyle::LK_JavaScript) {
2173 GoogleStyle.BreakAfterOpenBracketBracedList =
true;
2174 GoogleStyle.BreakAfterOpenBracketFunction =
true;
2175 GoogleStyle.BreakAfterOpenBracketIf =
true;
2176 GoogleStyle.AlignOperands = FormatStyle::OAS_DontAlign;
2177 GoogleStyle.AllowShortFunctionsOnASingleLine =
2178 FormatStyle::ShortFunctionStyle::setEmptyOnly();
2180 GoogleStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_Empty;
2181 GoogleStyle.AlwaysBreakBeforeMultilineStrings =
false;
2182 GoogleStyle.BreakBeforeTernaryOperators =
false;
2185 GoogleStyle.CommentPragmas =
"(taze:|^/[ \t]*<|tslint:|@see)";
2189 GoogleStyle.JavaScriptQuotes = FormatStyle::JSQS_Single;
2190 GoogleStyle.JavaScriptWrapImports =
false;
2191 GoogleStyle.MaxEmptyLinesToKeep = 3;
2192 GoogleStyle.NamespaceIndentation = FormatStyle::NI_All;
2193 GoogleStyle.SpacesInContainerLiterals =
false;
2194 }
else if (
Language == FormatStyle::LK_Proto) {
2195 GoogleStyle.AllowShortFunctionsOnASingleLine =
2196 FormatStyle::ShortFunctionStyle::setEmptyOnly();
2197 GoogleStyle.AlwaysBreakBeforeMultilineStrings =
false;
2203 GoogleStyle.BreakStringLiterals =
false;
2204 GoogleStyle.Cpp11BracedListStyle = FormatStyle::BLS_Block;
2205 GoogleStyle.SpacesInContainerLiterals =
false;
2206 }
else if (
Language == FormatStyle::LK_ObjC) {
2207 GoogleStyle.AlwaysBreakBeforeMultilineStrings =
false;
2208 GoogleStyle.ColumnLimit = 100;
2209 GoogleStyle.DerivePointerAlignment =
true;
2213 GoogleStyle.IncludeStyle.IncludeBlocks =
2215 }
else if (
Language == FormatStyle::LK_CSharp) {
2216 GoogleStyle.AllowShortFunctionsOnASingleLine =
2217 FormatStyle::ShortFunctionStyle::setEmptyOnly();
2218 GoogleStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
2219 GoogleStyle.BreakStringLiterals =
false;
2220 GoogleStyle.ColumnLimit = 100;
2221 GoogleStyle.NamespaceIndentation = FormatStyle::NI_All;
2247 ChromiumStyle.IncludeStyle.IncludeBlocks =
2250 if (
Language == FormatStyle::LK_Java) {
2251 ChromiumStyle.AllowShortIfStatementsOnASingleLine =
2252 FormatStyle::SIS_WithoutElse;
2253 ChromiumStyle.BreakAfterJavaFieldAnnotations =
true;
2254 ChromiumStyle.ContinuationIndentWidth = 8;
2255 ChromiumStyle.IndentWidth = 4;
2258 ChromiumStyle.JavaImportGroups = {
2265 "com.google.android.apps.chrome",
2270 }
else if (
Language == FormatStyle::LK_JavaScript) {
2271 ChromiumStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
2272 ChromiumStyle.AllowShortLoopsOnASingleLine =
false;
2274 ChromiumStyle.AllowAllParametersOfDeclarationOnNextLine =
false;
2275 ChromiumStyle.AllowShortFunctionsOnASingleLine =
2276 FormatStyle::ShortFunctionStyle::setEmptyAndInline();
2277 ChromiumStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
2278 ChromiumStyle.AllowShortLoopsOnASingleLine =
false;
2279 ChromiumStyle.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
2280 ChromiumStyle.DerivePointerAlignment =
false;
2281 if (
Language == FormatStyle::LK_ObjC)
2282 ChromiumStyle.ColumnLimit = 80;
2284 return ChromiumStyle;
2289 MozillaStyle.AllowAllParametersOfDeclarationOnNextLine =
false;
2290 MozillaStyle.AllowShortFunctionsOnASingleLine =
2291 FormatStyle::ShortFunctionStyle::setEmptyAndInline();
2292 MozillaStyle.AlwaysBreakAfterDefinitionReturnType =
2293 FormatStyle::DRTBS_TopLevel;
2294 MozillaStyle.PackArguments.BinPack = FormatStyle::BPAS_OnePerLine;
2295 MozillaStyle.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
2296 MozillaStyle.BreakAfterReturnType = FormatStyle::RTBS_TopLevel;
2297 MozillaStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla;
2298 MozillaStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;
2299 MozillaStyle.BreakInheritanceList = FormatStyle::BILS_BeforeComma;
2300 MozillaStyle.BreakTemplateDeclarations = FormatStyle::BTDS_Yes;
2301 MozillaStyle.ConstructorInitializerIndentWidth = 2;
2302 MozillaStyle.ContinuationIndentWidth = 2;
2303 MozillaStyle.Cpp11BracedListStyle = FormatStyle::BLS_Block;
2304 MozillaStyle.FixNamespaceComments =
false;
2305 MozillaStyle.IndentCaseLabels =
true;
2306 MozillaStyle.ObjCSpaceAfterProperty =
true;
2307 MozillaStyle.ObjCSpaceBeforeProtocolList =
false;
2308 MozillaStyle.PenaltyReturnTypeOnItsOwnLine = 200;
2309 MozillaStyle.PointerAlignment = FormatStyle::PAS_Left;
2310 MozillaStyle.SpaceAfterTemplateKeyword =
false;
2311 return MozillaStyle;
2316 Style.AccessModifierOffset = -4;
2317 Style.AlignAfterOpenBracket =
false;
2318 Style.AlignOperands = FormatStyle::OAS_DontAlign;
2319 Style.AlignTrailingComments = {};
2320 Style.AlignTrailingComments.Kind = FormatStyle::TCAS_Never;
2321 Style.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Empty;
2322 Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
2323 Style.BreakBeforeBraces = FormatStyle::BS_WebKit;
2324 Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;
2325 Style.ColumnLimit = 0;
2326 Style.Cpp11BracedListStyle = FormatStyle::BLS_Block;
2327 Style.FixNamespaceComments =
false;
2328 Style.IndentWidth = 4;
2329 Style.NamespaceIndentation = FormatStyle::NI_Inner;
2330 Style.ObjCBlockIndentWidth = 4;
2331 Style.ObjCSpaceAfterProperty =
true;
2332 Style.PointerAlignment = FormatStyle::PAS_Left;
2333 Style.SpaceBeforeCpp11BracedList =
true;
2334 Style.SpaceInEmptyBraces = FormatStyle::SIEB_Always;
2340 Style.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_All;
2341 Style.BreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
2342 Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
2343 Style.BreakBeforeBraces = FormatStyle::BS_GNU;
2344 Style.BreakBeforeTernaryOperators =
true;
2345 Style.ColumnLimit = 79;
2346 Style.Cpp11BracedListStyle = FormatStyle::BLS_Block;
2347 Style.FixNamespaceComments =
false;
2348 Style.KeepFormFeed =
true;
2349 Style.SpaceBeforeParens = FormatStyle::SBPO_Always;
2355 Style.ColumnLimit = 120;
2357 Style.IndentWidth = 4;
2358 Style.UseTab = FormatStyle::UT_Never;
2359 Style.BreakBeforeBraces = FormatStyle::BS_Custom;
2360 Style.BraceWrapping.AfterClass =
true;
2361 Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_Always;
2362 Style.BraceWrapping.AfterEnum =
true;
2363 Style.BraceWrapping.AfterFunction =
true;
2364 Style.BraceWrapping.AfterNamespace =
true;
2365 Style.BraceWrapping.AfterObjCDeclaration =
true;
2366 Style.BraceWrapping.AfterStruct =
true;
2367 Style.BraceWrapping.AfterExternBlock =
true;
2368 Style.BraceWrapping.BeforeCatch =
true;
2369 Style.BraceWrapping.BeforeElse =
true;
2370 Style.BraceWrapping.BeforeWhile =
false;
2371 Style.PenaltyReturnTypeOnItsOwnLine = 1000;
2372 Style.AllowShortEnumsOnASingleLine =
false;
2373 Style.AllowShortFunctionsOnASingleLine = FormatStyle::ShortFunctionStyle();
2374 Style.AllowShortCaseLabelsOnASingleLine =
false;
2375 Style.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
2376 Style.AllowShortLoopsOnASingleLine =
false;
2377 Style.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
2378 Style.BreakAfterReturnType = FormatStyle::RTBS_None;
2384 Style.InsertBraces =
true;
2385 Style.InsertNewlineAtEOF =
true;
2386 Style.IntegerLiteralSeparator.Decimal = 3;
2387 Style.IntegerLiteralSeparator.DecimalMinDigitsInsert = 5;
2388 Style.LineEnding = FormatStyle::LE_LF;
2389 Style.RemoveBracesLLVM =
true;
2390 Style.RemoveEmptyLinesInUnwrappedLines =
true;
2391 Style.RemoveParentheses = FormatStyle::RPS_ReturnStatement;
2392 Style.RemoveSemicolon =
true;
2398 NoStyle.DisableFormat =
true;
2399 NoStyle.SortIncludes = {};
2400 NoStyle.SortUsingDeclarations = FormatStyle::SUD_Never;
2405 FormatStyle *Style) {
2406 constexpr StringRef Prefix(
"inheritparentconfig=");
2408 if (Name.equals_insensitive(
"llvm"))
2410 else if (Name.equals_insensitive(
"chromium"))
2412 else if (Name.equals_insensitive(
"mozilla"))
2414 else if (Name.equals_insensitive(
"google"))
2416 else if (Name.equals_insensitive(
"webkit"))
2418 else if (Name.equals_insensitive(
"gnu"))
2420 else if (Name.equals_insensitive(
"microsoft"))
2422 else if (Name.equals_insensitive(
"clang-format"))
2424 else if (Name.equals_insensitive(
"none"))
2426 else if (Name.equals_insensitive(Prefix.drop_back()))
2427 Style->InheritConfig =
"..";
2428 else if (Name.size() > Prefix.size() && Name.starts_with_insensitive(Prefix))
2429 Style->InheritConfig = Name.substr(Prefix.size());
2439 if (Style->QualifierOrder.empty())
2443 for (
const auto &Qualifier : Style->QualifierOrder) {
2444 if (Qualifier ==
"type")
2448 if (token == tok::identifier)
2453 std::set<std::string> UniqueQualifiers(Style->QualifierOrder.begin(),
2454 Style->QualifierOrder.end());
2455 if (Style->QualifierOrder.size() != UniqueQualifiers.size()) {
2456 LLVM_DEBUG(llvm::dbgs()
2457 <<
"Duplicate Qualifiers " << Style->QualifierOrder.size()
2458 <<
" vs " << UniqueQualifiers.size() <<
"\n");
2463 if (!llvm::is_contained(Style->QualifierOrder,
"type"))
2470 FormatStyle *Style,
bool AllowUnknownOptions,
2471 llvm::SourceMgr::DiagHandlerTy DiagHandler,
2472 void *DiagHandlerCtxt,
bool IsDotHFile) {
2474 FormatStyle::LanguageKind
Language = Style->Language;
2475 assert(
Language != FormatStyle::LK_None);
2476 if (Config.getBuffer().trim().empty())
2478 Style->StyleSet.Clear();
2479 std::vector<FormatStyle> Styles;
2480 llvm::yaml::Input Input(Config,
nullptr, DiagHandler,
2486 Input.setContext(Style);
2487 Input.setAllowUnknownKeys(AllowUnknownOptions);
2490 return Input.error();
2494 const auto StyleCount = Styles.size();
2497 for (
unsigned I = 1; I < StyleCount; ++I) {
2498 const auto Lang = Styles[I].Language;
2499 if (Lang == FormatStyle::LK_None)
2502 for (
unsigned J = 0; J < I; ++J) {
2504 LLVM_DEBUG(llvm::dbgs()
2505 <<
"Duplicate languages in the config file on positions "
2506 << J <<
" and " << I <<
'\n');
2512 int LanguagePos = -1;
2518 for (
unsigned I = 0; I < StyleCount; ++I) {
2519 const auto Lang = Styles[I].Language;
2524 if (Lang == FormatStyle::LK_Cpp)
2526 else if (Lang == FormatStyle::LK_C)
2533 if (LanguagePos < 0) {
2534 if (Styles[0].
Language == FormatStyle::LK_None)
2536 else if (IsDotHFile &&
Language == FormatStyle::LK_Cpp)
2538 else if (!IsDotHFile &&
Language == FormatStyle::LK_C)
2539 LanguagePos = CppPos;
2540 if (LanguagePos < 0)
2544 for (
const auto &S : llvm::reverse(llvm::drop_begin(Styles)))
2545 Style->StyleSet.Add(S);
2547 *Style = Styles[LanguagePos];
2549 if (LanguagePos == 0) {
2550 if (Style->Language == FormatStyle::LK_None)
2552 Style->StyleSet.Add(*Style);
2555 if (Style->InsertTrailingCommas != FormatStyle::TCS_None &&
2556 (Style->PackArguments.BinPack == FormatStyle::BPAS_BinPack ||
2557 Style->PackArguments.BinPack == FormatStyle::BPAS_UseBreakAfter)) {
2561 if (Style->QualifierAlignment != FormatStyle::QAS_Leave)
2568 llvm::raw_string_ostream Stream(
Text);
2569 llvm::yaml::Output Output(Stream);
2572 FormatStyle NonConstStyle = Style;
2576 Output << NonConstStyle;
2578 return Stream.str();
2581std::optional<FormatStyle>
2582FormatStyle::FormatStyleSet::Get(FormatStyle::LanguageKind
Language)
const {
2584 return std::nullopt;
2586 if (It == Styles->end())
2587 return std::nullopt;
2588 FormatStyle Style = It->second;
2589 Style.StyleSet = *
this;
2593void FormatStyle::FormatStyleSet::Add(FormatStyle Style) {
2594 assert(Style.Language !=
LK_None &&
2595 "Cannot add a style for LK_None to a StyleSet");
2597 !Style.StyleSet.Styles &&
2598 "Cannot add a style associated with an existing StyleSet to a StyleSet");
2600 Styles = std::make_shared<MapType>();
2601 (*Styles)[Style.Language] = std::move(Style);
2604void FormatStyle::FormatStyleSet::Clear() { Styles.reset(); }
2606std::optional<FormatStyle>
2607FormatStyle::GetLanguageStyle(FormatStyle::LanguageKind
Language)
const {
2614 const SourceManager &SourceMgr, tooling::Replacements &
Result,
2615 StringRef
Text =
"") {
2616 const auto &
Tok = Token.Tok;
2617 SourceLocation Start;
2619 Start =
Tok.getLocation();
2622 Start = Token.WhitespaceRange.getBegin();
2625 cantFail(
Result.add(tooling::Replacement(SourceMgr, Range,
Text)));
2630 ParensRemover(
const Environment &Env,
const FormatStyle &Style)
2631 : TokenAnalyzer(Env, Style) {}
2633 std::pair<tooling::Replacements, unsigned>
2634 analyze(TokenAnnotator &Annotator,
2635 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2636 FormatTokenLexer &Tokens)
override {
2637 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2638 tooling::Replacements
Result;
2639 removeParens(AnnotatedLines,
Result);
2644 void removeParens(SmallVectorImpl<AnnotatedLine *> &Lines,
2645 tooling::Replacements &
Result) {
2646 const auto &SourceMgr = Env.getSourceManager();
2647 for (
auto *
Line : Lines) {
2648 if (!
Line->Children.empty())
2650 if (!
Line->Affected)
2652 for (
const auto *Token =
Line->First; Token && !Token->Finalized;
2653 Token = Token->Next) {
2654 if (Token->Optional && Token->isOneOf(tok::l_paren, tok::r_paren))
2663 BracesInserter(
const Environment &Env,
const FormatStyle &Style)
2664 : TokenAnalyzer(Env, Style) {}
2666 std::pair<tooling::Replacements, unsigned>
2667 analyze(TokenAnnotator &Annotator,
2668 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2669 FormatTokenLexer &Tokens)
override {
2670 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2671 tooling::Replacements
Result;
2672 insertBraces(AnnotatedLines,
Result);
2677 void insertBraces(SmallVectorImpl<AnnotatedLine *> &Lines,
2678 tooling::Replacements &
Result) {
2679 const auto &SourceMgr = Env.getSourceManager();
2680 int OpeningBraceSurplus = 0;
2681 for (AnnotatedLine *
Line : Lines) {
2682 if (!
Line->Children.empty())
2684 if (!
Line->Affected && OpeningBraceSurplus == 0)
2687 Token = Token->Next) {
2694 if (!
Line->Affected)
2696 Brace = Token->is(tok::comment) ?
"\n{" :
"{";
2697 ++OpeningBraceSurplus;
2699 if (OpeningBraceSurplus == 0)
2706 Token->BraceCount = 0;
2707 const auto Start = Token->Tok.getEndLoc();
2708 cantFail(
Result.add(tooling::Replacement(SourceMgr, Start, 0,
Brace)));
2711 assert(OpeningBraceSurplus == 0);
2717 BracesRemover(
const Environment &Env,
const FormatStyle &Style)
2718 : TokenAnalyzer(Env, Style) {}
2720 std::pair<tooling::Replacements, unsigned>
2721 analyze(TokenAnnotator &Annotator,
2722 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2723 FormatTokenLexer &Tokens)
override {
2724 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2725 tooling::Replacements
Result;
2726 removeBraces(AnnotatedLines,
Result);
2731 void removeBraces(SmallVectorImpl<AnnotatedLine *> &Lines,
2732 tooling::Replacements &
Result) {
2733 const auto &SourceMgr = Env.getSourceManager();
2734 const auto *End = Lines.end();
2735 for (
const auto *I = Lines.begin(); I != End; ++I) {
2736 const auto &
Line = *I;
2737 if (!
Line->Children.empty())
2739 if (!
Line->Affected)
2741 const auto *NextLine = I + 1 == End ?
nullptr : I[1];
2742 for (
const auto *Token =
Line->First; Token && !Token->Finalized;
2743 Token = Token->Next) {
2744 if (!Token->Optional || Token->isNoneOf(tok::l_brace, tok::r_brace))
2746 auto *
Next = Token->Next;
2747 assert(
Next || Token ==
Line->Last);
2748 if (!
Next && NextLine)
2749 Next = NextLine->First;
2758 SemiRemover(
const Environment &Env,
const FormatStyle &Style)
2759 : TokenAnalyzer(Env, Style) {}
2761 std::pair<tooling::Replacements, unsigned>
2762 analyze(TokenAnnotator &Annotator,
2763 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2764 FormatTokenLexer &Tokens)
override {
2765 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2766 tooling::Replacements
Result;
2767 removeSemi(Annotator, AnnotatedLines,
Result);
2772 void removeSemi(TokenAnnotator &Annotator,
2773 SmallVectorImpl<AnnotatedLine *> &Lines,
2774 tooling::Replacements &
Result) {
2776 const auto *Prev =
Tok.Previous;
2777 if (!Prev || Prev->isNot(tok::r_brace))
2779 const auto *LBrace = Prev->MatchingParen;
2780 return LBrace && LBrace->is(TT_FunctionLBrace);
2782 const auto &SourceMgr = Env.getSourceManager();
2783 const auto *End = Lines.end();
2784 for (
const auto *I = Lines.begin(); I != End; ++I) {
2785 const auto &
Line = *I;
2786 if (!
Line->Children.empty())
2787 removeSemi(Annotator,
Line->Children,
Result);
2788 if (!
Line->Affected)
2790 Annotator.calculateFormattingInformation(*
Line);
2791 const auto *NextLine = I + 1 == End ?
nullptr : I[1];
2792 for (
const auto *Token =
Line->First; Token && !Token->Finalized;
2793 Token = Token->Next) {
2794 if (Token->isNot(tok::semi) ||
2795 (!Token->Optional && !PrecededByFunctionRBrace(*Token))) {
2798 auto *
Next = Token->Next;
2799 assert(
Next || Token ==
Line->Last);
2800 if (!
Next && NextLine)
2801 Next = NextLine->First;
2810 EnumTrailingCommaEditor(
const Environment &Env,
const FormatStyle &Style)
2811 : TokenAnalyzer(Env, Style) {}
2813 std::pair<tooling::Replacements, unsigned>
2814 analyze(TokenAnnotator &Annotator,
2815 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2816 FormatTokenLexer &Tokens)
override {
2817 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2818 tooling::Replacements
Result;
2819 editEnumTrailingComma(AnnotatedLines,
Result);
2824 void editEnumTrailingComma(SmallVectorImpl<AnnotatedLine *> &Lines,
2825 tooling::Replacements &
Result) {
2826 bool InEnumBraces =
false;
2828 const auto &SourceMgr = Env.getSourceManager();
2829 for (
auto *
Line : Lines) {
2830 if (!
Line->Children.empty())
2831 editEnumTrailingComma(
Line->Children,
Result);
2832 for (
const auto *Token =
Line->First; Token && !Token->Finalized;
2833 Token = Token->Next) {
2834 if (Token->isNot(TT_EnumRBrace)) {
2835 if (Token->is(TT_EnumLBrace))
2836 InEnumBraces =
true;
2837 else if (InEnumBraces && Token->isNot(tok::comment))
2838 BeforeRBrace =
Line->Affected ? Token :
nullptr;
2841 InEnumBraces =
false;
2844 if (BeforeRBrace->is(tok::comma)) {
2845 if (Style.EnumTrailingComma == FormatStyle::ETC_Remove)
2847 }
else if (Style.EnumTrailingComma == FormatStyle::ETC_Insert) {
2848 cantFail(
Result.add(tooling::Replacement(
2849 SourceMgr, BeforeRBrace->Tok.getEndLoc(), 0,
",")));
2851 BeforeRBrace =
nullptr;
2859 JavaScriptRequoter(
const Environment &Env,
const FormatStyle &Style)
2860 : TokenAnalyzer(Env, Style) {}
2862 std::pair<tooling::Replacements, unsigned>
2863 analyze(TokenAnnotator &Annotator,
2864 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2865 FormatTokenLexer &Tokens)
override {
2866 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2867 tooling::Replacements
Result;
2868 requoteJSStringLiteral(AnnotatedLines,
Result);
2875 void requoteJSStringLiteral(SmallVectorImpl<AnnotatedLine *> &Lines,
2876 tooling::Replacements &
Result) {
2877 for (AnnotatedLine *
Line : Lines) {
2878 requoteJSStringLiteral(
Line->Children,
Result);
2879 if (!
Line->Affected)
2882 FormatTok = FormatTok->Next) {
2883 StringRef Input = FormatTok->TokenText;
2884 if (FormatTok->Finalized || !FormatTok->isStringLiteral() ||
2887 (Style.JavaScriptQuotes == FormatStyle::JSQS_Single &&
2888 !Input.starts_with(
"\"")) ||
2889 (Style.JavaScriptQuotes == FormatStyle::JSQS_Double &&
2890 !Input.starts_with(
"\'"))) {
2895 bool IsSingle = Style.JavaScriptQuotes == FormatStyle::JSQS_Single;
2896 SourceLocation Start = FormatTok->Tok.getLocation();
2897 auto Replace = [&](SourceLocation Start,
unsigned Length,
2898 StringRef ReplacementText) {
2899 auto Err =
Result.add(tooling::Replacement(
2900 Env.getSourceManager(), Start, Length, ReplacementText));
2904 llvm::errs() <<
toString(std::move(Err)) <<
"\n";
2908 Replace(Start, 1, IsSingle ?
"'" :
"\"");
2909 Replace(FormatTok->Tok.getEndLoc().getLocWithOffset(-1), 1,
2910 IsSingle ?
"'" :
"\"");
2913 bool Escaped =
false;
2914 for (
size_t i = 1; i < Input.size() - 1; i++) {
2917 if (!Escaped && i + 1 < Input.size() &&
2918 ((IsSingle && Input[i + 1] ==
'"') ||
2919 (!IsSingle && Input[i + 1] ==
'\''))) {
2922 Replace(Start.getLocWithOffset(i), 1,
"");
2929 if (!Escaped && IsSingle == (Input[i] ==
'\'')) {
2931 Replace(Start.getLocWithOffset(i), 0,
"\\");
2947 Formatter(
const Environment &Env,
const FormatStyle &Style,
2948 FormattingAttemptStatus *Status)
2949 : TokenAnalyzer(Env, Style), Status(Status) {}
2951 std::pair<tooling::Replacements, unsigned>
2952 analyze(TokenAnnotator &Annotator,
2953 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2954 FormatTokenLexer &Tokens)
override {
2955 tooling::Replacements
Result;
2956 deriveLocalStyle(AnnotatedLines);
2957 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2958 for (AnnotatedLine *
Line : AnnotatedLines)
2959 Annotator.calculateFormattingInformation(*
Line);
2960 Annotator.setCommentLineLevels(AnnotatedLines);
2962 WhitespaceManager Whitespaces(
2963 Env.getSourceManager(), Style,
2964 Style.LineEnding > FormatStyle::LE_CRLF
2966 Env.getSourceManager().getBufferData(Env.getFileID()),
2967 Style.LineEnding == FormatStyle::LE_DeriveCRLF)
2968 : Style.LineEnding == FormatStyle::LE_CRLF);
2969 ContinuationIndenter Indenter(Style, Tokens.getKeywords(),
2970 Env.getSourceManager(), Whitespaces, Encoding,
2971 BinPackInconclusiveFunctions);
2973 UnwrappedLineFormatter(&Indenter, &Whitespaces, Style,
2974 Tokens.getKeywords(), Env.getSourceManager(),
2976 .format(AnnotatedLines,
false,
2979 Env.getFirstStartColumn(),
2980 Env.getNextStartColumn(),
2981 Env.getLastStartColumn());
2982 for (
const auto &R : Whitespaces.generateReplacements())
2984 return std::make_pair(
Result, 0);
2985 return std::make_pair(
Result, Penalty);
2990 hasCpp03IncompatibleFormat(
const SmallVectorImpl<AnnotatedLine *> &Lines) {
2991 for (
const AnnotatedLine *
Line : Lines) {
2992 if (hasCpp03IncompatibleFormat(
Line->Children))
2995 if (!
Tok->hasWhitespaceBefore()) {
2996 if (
Tok->is(tok::coloncolon) &&
Tok->Previous->is(TT_TemplateOpener))
2998 if (
Tok->is(TT_TemplateCloser) &&
2999 Tok->Previous->is(TT_TemplateCloser)) {
3008 int countVariableAlignments(
const SmallVectorImpl<AnnotatedLine *> &Lines) {
3009 int AlignmentDiff = 0;
3011 for (
const AnnotatedLine *
Line : Lines) {
3012 AlignmentDiff += countVariableAlignments(
Line->Children);
3015 if (
Tok->isNot(TT_PointerOrReference))
3018 const auto *Prev =
Tok->Previous;
3019 const bool PrecededByName = Prev && Prev->Tok.getIdentifierInfo();
3020 const bool SpaceBefore =
Tok->hasWhitespaceBefore();
3023 while (
Tok->Next &&
Tok->Next->is(TT_PointerOrReference))
3027 const bool FollowedByName =
Next &&
Next->Tok.getIdentifierInfo();
3028 const bool SpaceAfter =
Next &&
Next->hasWhitespaceBefore();
3030 if ((!PrecededByName && !FollowedByName) ||
3032 (PrecededByName && FollowedByName && SpaceBefore == SpaceAfter)) {
3036 if ((PrecededByName && SpaceBefore) ||
3037 (FollowedByName && !SpaceAfter)) {
3040 }
else if ((PrecededByName && !SpaceBefore) ||
3041 (FollowedByName && SpaceAfter)) {
3048 return AlignmentDiff;
3052 deriveLocalStyle(
const SmallVectorImpl<AnnotatedLine *> &AnnotatedLines) {
3053 bool HasBinPackedFunction =
false;
3054 bool HasOnePerLineFunction =
false;
3055 for (AnnotatedLine *
Line : AnnotatedLines) {
3056 if (!
Line->First->Next)
3061 HasBinPackedFunction =
true;
3063 HasOnePerLineFunction =
true;
3068 if (Style.DerivePointerAlignment) {
3069 const auto NetRightCount = countVariableAlignments(AnnotatedLines);
3070 if (NetRightCount > 0)
3071 Style.PointerAlignment = FormatStyle::PAS_Right;
3072 else if (NetRightCount < 0)
3073 Style.PointerAlignment = FormatStyle::PAS_Left;
3074 Style.ReferenceAlignment = FormatStyle::RAS_Pointer;
3076 if (Style.Standard == FormatStyle::LS_Auto) {
3077 Style.Standard = hasCpp03IncompatibleFormat(AnnotatedLines)
3078 ? FormatStyle::LS_Latest
3079 : FormatStyle::LS_Cpp03;
3081 BinPackInconclusiveFunctions =
3082 HasBinPackedFunction || !HasOnePerLineFunction;
3085 bool BinPackInconclusiveFunctions;
3086 FormattingAttemptStatus *Status;
3102 TrailingCommaInserter(
const Environment &Env,
const FormatStyle &Style)
3103 : TokenAnalyzer(Env, Style) {}
3105 std::pair<tooling::Replacements, unsigned>
3106 analyze(TokenAnnotator &Annotator,
3107 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
3108 FormatTokenLexer &Tokens)
override {
3109 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
3110 tooling::Replacements
Result;
3111 insertTrailingCommas(AnnotatedLines,
Result);
3118 void insertTrailingCommas(SmallVectorImpl<AnnotatedLine *> &Lines,
3119 tooling::Replacements &
Result) {
3120 for (AnnotatedLine *
Line : Lines) {
3121 insertTrailingCommas(
Line->Children,
Result);
3122 if (!
Line->Affected)
3125 FormatTok = FormatTok->Next) {
3126 if (FormatTok->NewlinesBefore == 0)
3129 if (!Matching || !FormatTok->getPreviousNonComment())
3131 if (!(FormatTok->is(tok::r_square) &&
3132 Matching->is(TT_ArrayInitializerLSquare)) &&
3133 !(FormatTok->is(tok::r_brace) && Matching->is(TT_DictLiteral))) {
3136 FormatToken *Prev = FormatTok->getPreviousNonComment();
3137 if (Prev->is(tok::comma) || Prev->is(tok::semi))
3141 SourceLocation Start =
3142 Prev->Tok.getLocation().getLocWithOffset(Prev->TokenText.size());
3146 unsigned ColumnNumber =
3147 Env.getSourceManager().getSpellingColumnNumber(Start);
3148 if (ColumnNumber > Style.ColumnLimit)
3153 tooling::Replacement(Env.getSourceManager(), Start, 0,
",")));
3163 Cleaner(
const Environment &Env,
const FormatStyle &Style)
3164 : TokenAnalyzer(Env, Style),
3165 DeletedTokens(FormatTokenLess(Env.getSourceManager())) {}
3168 std::pair<tooling::Replacements, unsigned>
3169 analyze(TokenAnnotator &Annotator,
3170 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
3171 FormatTokenLexer &Tokens)
override {
3179 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
3181 checkEmptyNamespace(AnnotatedLines);
3183 for (
auto *
Line : AnnotatedLines)
3186 return {generateFixes(), 0};
3190 void cleanupLine(AnnotatedLine *
Line) {
3191 for (
auto *Child :
Line->Children)
3194 if (
Line->Affected) {
3195 cleanupRight(
Line->First, tok::comma, tok::comma);
3196 cleanupRight(
Line->First, TT_CtorInitializerColon, tok::comma);
3197 cleanupRight(
Line->First, tok::l_paren, tok::comma);
3198 cleanupLeft(
Line->First, tok::comma, tok::r_paren);
3199 cleanupLeft(
Line->First, TT_CtorInitializerComma, tok::l_brace);
3200 cleanupLeft(
Line->First, TT_CtorInitializerColon, tok::l_brace);
3201 cleanupLeft(
Line->First, TT_CtorInitializerColon, tok::equal);
3205 bool containsOnlyComments(
const AnnotatedLine &
Line) {
3207 if (
Tok->isNot(tok::comment))
3213 void checkEmptyNamespace(SmallVectorImpl<AnnotatedLine *> &AnnotatedLines) {
3214 std::set<unsigned> DeletedLines;
3215 for (
unsigned i = 0, e = AnnotatedLines.size(); i != e; ++i) {
3216 auto &
Line = *AnnotatedLines[i];
3217 if (
Line.startsWithNamespace())
3218 checkEmptyNamespace(AnnotatedLines, i, i, DeletedLines);
3221 for (
auto Line : DeletedLines) {
3234 bool checkEmptyNamespace(SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
3235 unsigned CurrentLine,
unsigned &NewLine,
3236 std::set<unsigned> &DeletedLines) {
3237 unsigned InitLine = CurrentLine, End = AnnotatedLines.size();
3238 if (Style.BraceWrapping.AfterNamespace) {
3242 if (!AnnotatedLines[++CurrentLine]->startsWith(tok::l_brace)) {
3243 NewLine = CurrentLine;
3246 }
else if (!AnnotatedLines[CurrentLine]->endsWith(tok::l_brace)) {
3249 while (++CurrentLine < End) {
3250 if (AnnotatedLines[CurrentLine]->startsWith(tok::r_brace))
3253 if (AnnotatedLines[CurrentLine]->startsWithNamespace()) {
3254 if (!checkEmptyNamespace(AnnotatedLines, CurrentLine, NewLine,
3258 CurrentLine = NewLine;
3262 if (containsOnlyComments(*AnnotatedLines[CurrentLine]))
3267 NewLine = CurrentLine;
3271 NewLine = CurrentLine;
3272 if (CurrentLine >= End)
3277 AnnotatedLines[InitLine]->First->Tok.getLocation(),
3278 AnnotatedLines[CurrentLine]->Last->Tok.getEndLoc()))) {
3282 for (
unsigned i = InitLine; i <= CurrentLine; ++i)
3283 DeletedLines.insert(i);
3292 template <
typename LeftKind,
typename RightKind>
3293 void cleanupPair(
FormatToken *Start, LeftKind LK, RightKind RK,
3296 for (
auto *Res =
Tok.Next; Res; Res = Res->Next) {
3297 if (Res->isNot(tok::comment) &&
3298 DeletedTokens.find(Res) == DeletedTokens.end()) {
3304 for (
auto *Left = Start;
Left;) {
3305 auto *
Right = NextNotDeleted(*Left);
3309 deleteToken(DeleteLeft ? Left : Right);
3321 template <
typename LeftKind,
typename RightKind>
3322 void cleanupLeft(
FormatToken *Start, LeftKind LK, RightKind RK) {
3323 cleanupPair(Start, LK, RK,
true);
3326 template <
typename LeftKind,
typename RightKind>
3327 void cleanupRight(
FormatToken *Start, LeftKind LK, RightKind RK) {
3328 cleanupPair(Start, LK, RK,
false);
3334 DeletedTokens.insert(
Tok);
3337 tooling::Replacements generateFixes() {
3338 tooling::Replacements Fixes;
3339 SmallVector<FormatToken *> Tokens;
3340 std::copy(DeletedTokens.begin(), DeletedTokens.end(),
3341 std::back_inserter(Tokens));
3347 while (Idx < Tokens.size()) {
3348 unsigned St = Idx, End = Idx;
3349 while ((End + 1) < Tokens.size() && Tokens[End]->Next == Tokens[End + 1])
3352 Tokens[End]->Tok.getEndLoc());
3354 Fixes.add(tooling::Replacement(Env.getSourceManager(), SR,
""));
3358 llvm::errs() <<
toString(std::move(Err)) <<
"\n";
3359 assert(
false &&
"Fixes must not conflict!");
3370 struct FormatTokenLess {
3371 FormatTokenLess(
const SourceManager &SM) : SM(SM) {}
3374 return SM.isBeforeInTranslationUnit(LHS->Tok.getLocation(),
3375 RHS->Tok.getLocation());
3377 const SourceManager &SM;
3381 std::set<FormatToken *, FormatTokenLess> DeletedTokens;
3386 ObjCHeaderStyleGuesser(
const Environment &Env,
const FormatStyle &Style)
3387 : TokenAnalyzer(Env, Style), IsObjC(
false) {}
3389 std::pair<tooling::Replacements, unsigned>
3390 analyze(TokenAnnotator &Annotator,
3391 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
3392 FormatTokenLexer &Tokens)
override {
3393 assert(Style.Language == FormatStyle::LK_Cpp);
3394 IsObjC = guessIsObjC(Env.getSourceManager(), AnnotatedLines,
3395 Tokens.getKeywords());
3396 tooling::Replacements
Result;
3400 bool isObjC() {
return IsObjC; }
3404 guessIsObjC(
const SourceManager &SourceManager,
3405 const SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
3406 const AdditionalKeywords &Keywords) {
3408 static constexpr llvm::StringLiteral FoundationIdentifiers[] = {
3423 "FOUNDATION_EXPORT",
3424 "FOUNDATION_EXTERN",
3425 "NSAffineTransform",
3427 "NSAttributedString",
3446 "NSInvocationOperation",
3450 "NSMutableAttributedString",
3451 "NSMutableCharacterSet",
3453 "NSMutableDictionary",
3454 "NSMutableIndexSet",
3455 "NSMutableOrderedSet",
3459 "NSNumberFormatter",
3463 "NSOperationQueuePriority",
3467 "NSQualityOfService",
3470 "NSRegularExpression",
3481 "NS_ASSUME_NONNULL_BEGIN",
3485 assert(llvm::is_sorted(FoundationIdentifiers));
3487 for (
auto *
Line : AnnotatedLines) {
3488 if (
Line->First && (
Line->First->TokenText.starts_with(
"#") ||
3489 Line->First->TokenText ==
"__pragma" ||
3490 Line->First->TokenText ==
"_Pragma")) {
3494 FormatTok = FormatTok->Next) {
3495 if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&
3496 (FormatTok->isNot(tok::objc_not_keyword) ||
3497 FormatTok->isOneOf(tok::numeric_constant, tok::l_square,
3499 (FormatTok->Tok.isAnyIdentifier() &&
3500 llvm::binary_search(FoundationIdentifiers,
3501 FormatTok->TokenText)) ||
3502 FormatTok->is(TT_ObjCStringLiteral) ||
3503 FormatTok->isOneOf(Keywords.kw_NS_CLOSED_ENUM, Keywords.kw_NS_ENUM,
3504 Keywords.kw_NS_ERROR_ENUM,
3505 Keywords.kw_NS_OPTIONS, TT_ObjCBlockLBrace,
3506 TT_ObjCBlockLParen, TT_ObjCDecl, TT_ObjCForIn,
3507 TT_ObjCMethodExpr, TT_ObjCMethodSpecifier,
3508 TT_ObjCProperty, TT_ObjCSelector)) {
3509 LLVM_DEBUG(llvm::dbgs()
3510 <<
"Detected ObjC at location "
3511 << FormatTok->Tok.getLocation().printToString(
3513 <<
" token: " << FormatTok->TokenText <<
" token type: "
3518 if (guessIsObjC(SourceManager,
Line->Children, Keywords))
3527struct IncludeDirective {
3535struct JavaImportDirective {
3536 StringRef Identifier;
3539 SmallVector<StringRef> AssociatedCommentLines;
3548 for (
const auto &Range : Ranges) {
3549 if (Range.getOffset() < End &&
3550 Range.getOffset() + Range.getLength() > Start) {
3565static std::pair<unsigned, unsigned>
3568 unsigned CursorIndex = std::numeric_limits<unsigned>::max();
3569 unsigned OffsetToEOL = 0;
3570 for (
int i = 0, e = Includes.size(); i != e; ++i) {
3571 unsigned Start = Includes[Indices[i]].Offset;
3572 unsigned End = Start + Includes[Indices[i]].Text.size();
3573 if (!(Cursor >= Start && Cursor < End))
3575 CursorIndex = Indices[i];
3576 OffsetToEOL = End - Cursor;
3579 while (--i >= 0 && Includes[CursorIndex].
Text == Includes[Indices[i]].
Text)
3583 return std::make_pair(CursorIndex, OffsetToEOL);
3588 std::string NewCode;
3589 size_t Pos = 0, LastPos = 0;
3592 Pos = Code.find(
"\r\n", LastPos);
3593 if (Pos == LastPos) {
3597 if (Pos == std::string::npos) {
3598 NewCode += Code.substr(LastPos);
3601 NewCode += Code.substr(LastPos, Pos - LastPos) +
"\n";
3603 }
while (Pos != std::string::npos);
3621 const unsigned IncludesBeginOffset = Includes.front().Offset;
3622 const unsigned IncludesEndOffset =
3623 Includes.back().Offset + Includes.back().Text.size();
3624 const unsigned IncludesBlockSize = IncludesEndOffset - IncludesBeginOffset;
3625 if (!
affectsRange(Ranges, IncludesBeginOffset, IncludesEndOffset))
3628 llvm::to_vector<16>(llvm::seq<unsigned>(0, Includes.size()));
3630 if (Style.SortIncludes.Enabled) {
3631 stable_sort(Indices, [&](
unsigned LHSI,
unsigned RHSI) {
3633 if (Style.SortIncludes.IgnoreExtension) {
3634 LHSStem = Includes[LHSI].Filename;
3635 RHSStem = Includes[RHSI].Filename;
3636 llvm::sys::path::replace_extension(LHSStem,
"");
3637 llvm::sys::path::replace_extension(RHSStem,
"");
3639 std::string LHSStemLower, RHSStemLower;
3640 std::string LHSFilenameLower, RHSFilenameLower;
3641 if (Style.SortIncludes.IgnoreCase) {
3642 LHSStemLower = LHSStem.str().lower();
3643 RHSStemLower = RHSStem.str().lower();
3644 LHSFilenameLower = Includes[LHSI].Filename.lower();
3645 RHSFilenameLower = Includes[RHSI].Filename.lower();
3647 return std::tie(Includes[LHSI].Priority, LHSStemLower, LHSStem,
3648 LHSFilenameLower, Includes[LHSI].Filename) <
3649 std::tie(Includes[RHSI].Priority, RHSStemLower, RHSStem,
3650 RHSFilenameLower, Includes[RHSI].Filename);
3656 unsigned CursorIndex;
3658 unsigned CursorToEOLOffset;
3660 std::tie(CursorIndex, CursorToEOLOffset) =
3665 Indices.erase(llvm::unique(Indices,
3666 [&](
unsigned LHSI,
unsigned RHSI) {
3667 return Includes[LHSI].Text.trim() ==
3668 Includes[RHSI].Text.trim();
3672 int CurrentCategory = Includes.front().Category;
3680 if (Indices.size() == Includes.size() && is_sorted(Indices) &&
3685 const auto OldCursor = Cursor ? *Cursor : 0;
3687 for (
unsigned Index : Indices) {
3688 if (!result.empty()) {
3690 if (Style.IncludeStyle.IncludeBlocks ==
3692 CurrentCategory != Includes[Index].Category) {
3696 result += Includes[Index].Text;
3697 if (Cursor && CursorIndex == Index)
3698 *Cursor = IncludesBeginOffset + result.size() - CursorToEOLOffset;
3699 CurrentCategory = Includes[Index].Category;
3702 if (Cursor && *Cursor >= IncludesEndOffset)
3703 *Cursor += result.size() - IncludesBlockSize;
3708 IncludesBeginOffset, IncludesBlockSize)))) {
3710 *Cursor = OldCursor;
3715 FileName, Includes.front().Offset, IncludesBlockSize, result));
3719 llvm::errs() <<
toString(std::move(Err)) <<
"\n";
3729 unsigned Prev = llvm::StringSwitch<size_t>(Code)
3730 .StartsWith(
"\xEF\xBB\xBF", 3)
3732 unsigned SearchFrom = 0;
3744 bool FirstIncludeBlock =
true;
3745 bool MainIncludeFound =
false;
3746 bool FormattingOff =
false;
3749 llvm::Regex RawStringRegex(
3750 "R\"([][A-Za-z0-9_{}#<>%:;.?*+/^&\\$|~!=,'-]*)\\(");
3752 std::string RawStringTermination =
")\"";
3754 for (
const auto Size = Code.size(); SearchFrom < Size;) {
3755 size_t Pos = SearchFrom;
3756 if (Code[SearchFrom] !=
'\n') {
3759 Pos = Code.find(
'\n', Pos);
3760 }
while (Pos != StringRef::npos && Code[Pos - 1] ==
'\\');
3764 Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev);
3766 StringRef Trimmed =
Line.trim();
3771 if (RawStringRegex.match(Trimmed, &RawStringMatches)) {
3772 std::string CharSequence = RawStringMatches[1].str();
3773 RawStringTermination =
")" + CharSequence +
"\"";
3774 FormattingOff =
true;
3777 if (Trimmed.contains(RawStringTermination))
3778 FormattingOff =
false;
3780 bool IsBlockComment =
false;
3783 FormattingOff =
true;
3785 FormattingOff =
false;
3786 }
else if (Trimmed.starts_with(
"/*")) {
3787 IsBlockComment =
true;
3788 Pos = Code.find(
"*/", SearchFrom + 2);
3791 const bool EmptyLineSkipped =
3794 Style.IncludeStyle.IncludeBlocks ==
3797 bool MergeWithNextLine = Trimmed.ends_with(
"\\");
3798 if (!FormattingOff && !MergeWithNextLine) {
3799 if (!IsBlockComment &&
3801 StringRef IncludeName = Matches[2];
3802 if (Trimmed.contains(
"/*") && !Trimmed.contains(
"*/")) {
3807 Pos = Code.find(
"*/", SearchFrom);
3809 Prev, (Pos != StringRef::npos ? Pos + 2 : Code.size()) - Prev);
3813 !MainIncludeFound && FirstIncludeBlock);
3815 IncludeName, !MainIncludeFound && FirstIncludeBlock);
3817 MainIncludeFound =
true;
3818 IncludesInBlock.push_back(
3819 {IncludeName,
Line, Prev, Category, Priority});
3820 }
else if (!IncludesInBlock.empty() && !EmptyLineSkipped) {
3823 IncludesInBlock.clear();
3824 if (Trimmed.starts_with(
"#pragma hdrstop"))
3825 FirstIncludeBlock =
true;
3827 FirstIncludeBlock =
false;
3830 if (Pos == StringRef::npos || Pos + 1 == Code.size())
3833 if (!MergeWithNextLine)
3835 SearchFrom = Pos + 1;
3837 if (!IncludesInBlock.empty()) {
3848 StringRef ImportIdentifier) {
3849 unsigned LongestMatchIndex = std::numeric_limits<unsigned>::max();
3850 unsigned LongestMatchLength = 0;
3851 for (
unsigned I = 0; I < Style.JavaImportGroups.size(); I++) {
3852 const std::string &GroupPrefix = Style.JavaImportGroups[I];
3853 if (ImportIdentifier.starts_with(GroupPrefix) &&
3854 GroupPrefix.length() > LongestMatchLength) {
3855 LongestMatchIndex = I;
3856 LongestMatchLength = GroupPrefix.length();
3859 return LongestMatchIndex;
3871 unsigned ImportsBeginOffset = Imports.front().Offset;
3872 unsigned ImportsEndOffset =
3873 Imports.back().Offset + Imports.back().Text.size();
3874 unsigned ImportsBlockSize = ImportsEndOffset - ImportsBeginOffset;
3875 if (!
affectsRange(Ranges, ImportsBeginOffset, ImportsEndOffset))
3879 llvm::to_vector<16>(llvm::seq<unsigned>(0, Imports.size()));
3882 for (
const JavaImportDirective &Import : Imports)
3885 bool StaticImportAfterNormalImport =
3886 Style.SortJavaStaticImport == FormatStyle::SJSIO_After;
3887 sort(Indices, [&](
unsigned LHSI,
unsigned RHSI) {
3889 return std::make_tuple(!Imports[LHSI].IsStatic ^
3890 StaticImportAfterNormalImport,
3892 std::make_tuple(!Imports[RHSI].IsStatic ^
3893 StaticImportAfterNormalImport,
3898 Indices.erase(llvm::unique(Indices,
3899 [&](
unsigned LHSI,
unsigned RHSI) {
3900 return Imports[LHSI].Text == Imports[RHSI].Text;
3904 bool CurrentIsStatic = Imports[Indices.front()].IsStatic;
3908 for (
unsigned Index : Indices) {
3909 if (!result.empty()) {
3911 if (CurrentIsStatic != Imports[Index].IsStatic ||
3916 for (StringRef CommentLine : Imports[Index].AssociatedCommentLines) {
3917 result += CommentLine;
3920 result += Imports[Index].Text;
3921 CurrentIsStatic = Imports[Index].IsStatic;
3928 Imports.front().Offset, ImportsBlockSize)))) {
3933 ImportsBlockSize, result));
3937 llvm::errs() <<
toString(std::move(Err)) <<
"\n";
3945 JavaImportRegexPattern(
"^import[\t ]+(static[\t ]*)?([^\t ]*)[\t ]*;");
3947constexpr StringRef JavaPackageRegexPattern(
"^package[\t ]");
3956 bool HasImport =
false;
3957 llvm::Regex ImportRegex(JavaImportRegexPattern);
3958 llvm::Regex PackageRegex(JavaPackageRegexPattern);
3963 for (
bool FormattingOff =
false;;) {
3964 auto Pos = Code.find(
'\n', Prev);
3965 auto GetLine = [&] {
3966 return Code.substr(Prev,
3967 (Pos != StringRef::npos ? Pos : Code.size()) - Prev);
3969 StringRef
Line = GetLine();
3971 StringRef Trimmed =
Line.trim();
3972 if (Trimmed.empty() || PackageRegex.match(Trimmed)) {
3975 FormattingOff =
true;
3977 FormattingOff =
false;
3978 }
else if (Trimmed.starts_with(
"//")) {
3981 AssociatedCommentLines.push_back(
Line);
3982 }
else if (Trimmed.starts_with(
"/*")) {
3983 Pos = Code.find(
"*/", Pos + 2);
3984 if (Pos != StringRef::npos)
3985 Pos = Code.find(
'\n', Pos + 2);
3990 AssociatedCommentLines.push_back(
Line);
3992 }
else if (ImportRegex.match(Trimmed, &Matches)) {
3993 if (FormattingOff) {
3998 StringRef
Static = Matches[1];
3999 StringRef Identifier = Matches[2];
4000 bool IsStatic =
false;
4001 if (
Static.contains(
"static"))
4003 ImportsInBlock.push_back(
4004 {Identifier,
Line, Prev, AssociatedCommentLines, IsStatic});
4006 AssociatedCommentLines.clear();
4012 if (Pos == StringRef::npos || Pos + 1 == Code.size())
4025 return Code.size() > 188 && Code[0] == 0x47 && Code[188] == 0x47;
4028bool isLikelyXml(StringRef Code) {
return Code.ltrim().starts_with(
"<"); }
4032 StringRef
FileName,
unsigned *Cursor) {
4034 if (!Style.SortIncludes.Enabled || Style.DisableFormat)
4038 if (Style.isJavaScript()) {
4050template <
typename T>
4054 const FormatStyle &Style) {
4055 if (Replaces.
empty())
4058 auto NewCode = applyAllReplacements(Code, Replaces);
4060 return NewCode.takeError();
4065 ProcessFunc(Style, *NewCode, ChangedRanges,
FileName);
4067 return Replaces.
merge(FormatReplaces);
4072 const FormatStyle &Style) {
4075 auto SortIncludes = [](
const FormatStyle &Style, StringRef Code,
4076 std::vector<tooling::Range> Ranges,
4080 auto SortedReplaces =
4082 if (!SortedReplaces)
4083 return SortedReplaces.takeError();
4087 auto Reformat = [](
const FormatStyle &Style, StringRef Code,
4088 std::vector<tooling::Range> Ranges,
4098 return Replace.
getOffset() == std::numeric_limits<unsigned>::max() &&
4104inline bool isHeaderDeletion(
const tooling::Replacement &Replace) {
4105 return Replace.getOffset() == std::numeric_limits<unsigned>::max() &&
4106 Replace.getLength() == 1;
4110tooling::Replacements
4111fixCppIncludeInsertions(StringRef Code,
const tooling::Replacements &Replaces,
4112 const FormatStyle &Style) {
4116 tooling::Replacements HeaderInsertions;
4117 std::set<StringRef> HeadersToDelete;
4118 tooling::Replacements
Result;
4119 for (
const auto &R : Replaces) {
4120 if (isHeaderInsertion(R)) {
4123 consumeError(HeaderInsertions.add(R));
4124 }
else if (isHeaderDeletion(R)) {
4125 HeadersToDelete.insert(
R.getReplacementText());
4126 }
else if (
R.getOffset() == std::numeric_limits<unsigned>::max()) {
4127 llvm::errs() <<
"Insertions other than header #include insertion are "
4129 <<
R.getReplacementText() <<
"\n";
4131 consumeError(
Result.add(R));
4134 if (HeaderInsertions.empty() && HeadersToDelete.empty())
4137 StringRef
FileName = Replaces.begin()->getFilePath();
4138 tooling::HeaderIncludes Includes(
FileName, Code, Style.IncludeStyle);
4140 for (
const auto &Header : HeadersToDelete) {
4141 tooling::Replacements Replaces =
4142 Includes.remove(Header.trim(
"\"<>"), Header.starts_with(
"<"));
4143 for (
const auto &R : Replaces) {
4144 auto Err =
Result.add(R);
4147 llvm::errs() <<
"Failed to add header deletion replacement for "
4148 << Header <<
": " <<
toString(std::move(Err)) <<
"\n";
4154 for (
const auto &R : HeaderInsertions) {
4155 auto IncludeDirective =
R.getReplacementText();
4158 assert(Matched &&
"Header insertion replacement must have replacement text "
4161 auto IncludeName = Matches[2];
4163 Includes.insert(IncludeName.trim(
"\"<>"), IncludeName.starts_with(
"<"),
4166 auto Err =
Result.add(*Replace);
4168 consumeError(std::move(Err));
4169 unsigned NewOffset =
4170 Result.getShiftedCodePosition(Replace->getOffset());
4171 auto Shifted = tooling::Replacement(
FileName, NewOffset, 0,
4172 Replace->getReplacementText());
4184 const FormatStyle &Style) {
4187 auto Cleanup = [](
const FormatStyle &Style, StringRef Code,
4194 fixCppIncludeInsertions(Code, Replaces, Style);
4199std::pair<tooling::Replacements, unsigned>
4202 unsigned NextStartColumn,
unsigned LastStartColumn, StringRef
FileName,
4204 FormatStyle Expanded = Style;
4210 Expanded.InsertBraces =
false;
4211 Expanded.RemoveBracesLLVM =
false;
4212 Expanded.RemoveParentheses = FormatStyle::RPS_Leave;
4213 Expanded.RemoveSemicolon =
false;
4216 switch (Expanded.RequiresClausePosition) {
4217 case FormatStyle::RCPS_SingleLine:
4218 case FormatStyle::RCPS_WithPreceding:
4219 Expanded.IndentRequiresClause =
false;
4224 if (Expanded.BraceWrapping.AfterEnum)
4225 Expanded.AllowShortEnumsOnASingleLine =
false;
4227 if (Expanded.DisableFormat)
4231 if (Expanded.isJavaScript() &&
isMpegTS(Code))
4235 if (Style.isJson()) {
4236 std::vector<tooling::Range> Ranges(1,
tooling::Range(0, Code.size()));
4238 NextStartColumn, LastStartColumn);
4243 Formatter(*Env, Style, Status).process().first;
4245 if (Code.starts_with(
"x = ")) {
4246 Replaces = Replaces.
merge(
4250 if (applyAllReplacements(Code, Replaces))
4251 return {Replaces, 0};
4256 NextStartColumn, LastStartColumn);
4274 if (Style.isCpp()) {
4275 if (Style.QualifierAlignment != FormatStyle::QAS_Leave)
4278 if (Style.RemoveParentheses != FormatStyle::RPS_Leave) {
4279 FormatStyle S = Expanded;
4280 S.RemoveParentheses = Style.RemoveParentheses;
4281 Passes.emplace_back([&, S = std::move(S)](
const Environment &Env) {
4282 return ParensRemover(Env, S).process(
true);
4286 if (Style.InsertBraces) {
4287 FormatStyle S = Expanded;
4288 S.InsertBraces =
true;
4289 Passes.emplace_back([&, S = std::move(S)](
const Environment &Env) {
4290 return BracesInserter(Env, S).process(
true);
4294 if (Style.RemoveBracesLLVM) {
4295 FormatStyle S = Expanded;
4296 S.RemoveBracesLLVM =
true;
4297 Passes.emplace_back([&, S = std::move(S)](
const Environment &Env) {
4298 return BracesRemover(Env, S).process(
true);
4302 if (Style.RemoveSemicolon) {
4303 FormatStyle S = Expanded;
4304 S.RemoveSemicolon =
true;
4305 Passes.emplace_back([&, S = std::move(S)](
const Environment &Env) {
4306 return SemiRemover(Env, S).process();
4310 if (Style.EnumTrailingComma != FormatStyle::ETC_Leave) {
4312 return EnumTrailingCommaEditor(Env, Expanded)
4317 if (Style.FixNamespaceComments) {
4323 if (Style.SortUsingDeclarations != FormatStyle::SUD_Never) {
4330 if (Style.SeparateDefinitionBlocks != FormatStyle::SDS_Leave) {
4336 if (Style.Language == FormatStyle::LK_ObjC &&
4337 !Style.ObjCPropertyAttributeOrder.empty()) {
4343 if (Style.isJavaScript() &&
4344 Style.JavaScriptQuotes != FormatStyle::JSQS_Leave) {
4346 return JavaScriptRequoter(Env, Expanded).process(
true);
4351 return Formatter(Env, Expanded, Status).process();
4354 if (Style.isJavaScript() &&
4355 Style.InsertTrailingCommas == FormatStyle::TCS_Wrapped) {
4357 return TrailingCommaInserter(Env, Expanded).process();
4361 std::optional<std::string> CurrentCode;
4363 unsigned Penalty = 0;
4364 for (
size_t I = 0, E = Passes.size(); I < E; ++I) {
4365 std::pair<tooling::Replacements, unsigned> PassFixes = Passes[I](*Env);
4366 auto NewCode = applyAllReplacements(
4367 CurrentCode ? StringRef(*CurrentCode) : Code, PassFixes.first);
4369 Fixes = Fixes.
merge(PassFixes.first);
4370 Penalty += PassFixes.second;
4372 CurrentCode = std::move(*NewCode);
4376 FirstStartColumn, NextStartColumn, LastStartColumn);
4383 if (Style.QualifierAlignment != FormatStyle::QAS_Leave) {
4389 StringRef OriginalCode = Code.substr(Fix.getOffset(), Fix.getLength());
4390 if (OriginalCode != Fix.getReplacementText()) {
4391 auto Err = NonNoOpFixes.
add(Fix);
4393 llvm::errs() <<
"Error adding replacements : "
4394 <<
toString(std::move(Err)) <<
"\n";
4398 Fixes = std::move(NonNoOpFixes);
4401 return {Fixes, Penalty};
4420 if (Style.Language != FormatStyle::LK_Cpp)
4425 return Cleaner(*Env, Style).process().first;
4430 StringRef
FileName,
bool *IncompleteFormat) {
4433 if (!Status.FormatComplete)
4434 *IncompleteFormat =
true;
4461 auto LexingStd = Style.Standard;
4462 if (LexingStd == FormatStyle::LS_Auto || LexingStd == FormatStyle::LS_Latest)
4463 LexingStd = FormatStyle::LS_Cpp20;
4465 const bool SinceCpp11 = LexingStd >= FormatStyle::LS_Cpp11;
4466 const bool SinceCpp20 = LexingStd >= FormatStyle::LS_Cpp20;
4468 switch (Style.Language) {
4469 case FormatStyle::LK_C:
4473 case FormatStyle::LK_Cpp:
4474 case FormatStyle::LK_ObjC:
4475 LangOpts.CXXOperatorNames = 1;
4476 LangOpts.CPlusPlus11 = SinceCpp11;
4477 LangOpts.CPlusPlus14 = LexingStd >= FormatStyle::LS_Cpp14;
4478 LangOpts.CPlusPlus17 = LexingStd >= FormatStyle::LS_Cpp17;
4479 LangOpts.CPlusPlus20 = SinceCpp20;
4480 LangOpts.CPlusPlus23 = LexingStd >= FormatStyle::LS_Cpp23;
4481 LangOpts.CPlusPlus26 = LexingStd >= FormatStyle::LS_Cpp26;
4484 LangOpts.CPlusPlus = 1;
4487 LangOpts.Char8 = SinceCpp20;
4488 LangOpts.AllowLiteralDigitSeparator = LangOpts.CPlusPlus14 || LangOpts.C23;
4492 LangOpts.Digraphs = SinceCpp11;
4494 LangOpts.LineComment = 1;
4497 LangOpts.MicrosoftExt = 1;
4498 LangOpts.DeclSpecKeyword = 1;
4505 "Set coding style. <string> can be:\n"
4506 "1. A preset: LLVM, GNU, Google, Chromium, Microsoft,\n"
4507 " Mozilla, WebKit.\n"
4508 "2. 'file' to load style configuration from a\n"
4509 " .clang-format file in one of the parent directories\n"
4510 " of the source file (for stdin, see --assume-filename).\n"
4511 " If no .clang-format file is found, falls back to\n"
4512 " --fallback-style.\n"
4513 " --style=file is the default.\n"
4514 "3. 'file:<format_file_path>' to explicitly specify\n"
4515 " the configuration file.\n"
4516 "4. \"{key: value, ...}\" to set specific parameters, e.g.:\n"
4517 " --style=\"{BasedOnStyle: llvm, IndentWidth: 8}\"";
4520 static constexpr std::array<llvm::StringLiteral, 2> TemplateSuffixes{
4524 for (
auto Suffix : TemplateSuffixes)
4529 return FormatStyle::LK_C;
4531 return FormatStyle::LK_Java;
4532 if (
FileName.ends_with_insensitive(
".js") ||
4533 FileName.ends_with_insensitive(
".mjs") ||
4534 FileName.ends_with_insensitive(
".cjs") ||
4535 FileName.ends_with_insensitive(
".ts")) {
4536 return FormatStyle::LK_JavaScript;
4539 return FormatStyle::LK_ObjC;
4540 if (
FileName.ends_with_insensitive(
".proto") ||
4541 FileName.ends_with_insensitive(
".protodevel")) {
4542 return FormatStyle::LK_Proto;
4547 if (
FileName.ends_with_insensitive(
".txtpb") ||
4548 FileName.ends_with_insensitive(
".textpb") ||
4549 FileName.ends_with_insensitive(
".pb.txt") ||
4550 FileName.ends_with_insensitive(
".textproto") ||
4551 FileName.ends_with_insensitive(
".asciipb")) {
4552 return FormatStyle::LK_TextProto;
4554 if (
FileName.ends_with_insensitive(
".td"))
4555 return FormatStyle::LK_TableGen;
4556 if (
FileName.ends_with_insensitive(
".cs"))
4557 return FormatStyle::LK_CSharp;
4558 if (
FileName.ends_with_insensitive(
".json") ||
4559 FileName.ends_with_insensitive(
".ipynb")) {
4560 return FormatStyle::LK_Json;
4562 if (
FileName.ends_with_insensitive(
".sv") ||
4563 FileName.ends_with_insensitive(
".svh") ||
4564 FileName.ends_with_insensitive(
".v") ||
4565 FileName.ends_with_insensitive(
".vh")) {
4566 return FormatStyle::LK_Verilog;
4568 return FormatStyle::LK_Cpp;
4576 LangOpts.CPlusPlus = 1;
4577 LangOpts.LineComment = 1;
4579 Lexer Lex(ID, SourceMgr.getBufferOrFake(ID), SourceMgr, LangOpts);
4583 auto Text = StringRef(SourceMgr.getCharacterData(
Tok.getLocation()),
4585 if (!
Text.consume_front(
"// clang-format Language:"))
4590 return FormatStyle::LK_C;
4592 return FormatStyle::LK_Cpp;
4594 return FormatStyle::LK_ObjC;
4597 return FormatStyle::LK_None;
4602 if (GuessedLanguage == FormatStyle::LK_Cpp) {
4603 auto Extension = llvm::sys::path::extension(
FileName);
4606 if (!Code.empty() && (Extension.empty() || Extension ==
".h")) {
4610 Language != FormatStyle::LK_None) {
4615 if (Guesser.isObjC())
4616 return FormatStyle::LK_ObjC;
4619 return GuessedLanguage;
4627llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
4629 FormatStyle *Style,
bool AllowUnknownOptions,
4630 llvm::SourceMgr::DiagHandlerTy DiagHandler,
4632 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
Text =
4633 FS->getBufferForFile(ConfigFile.str());
4634 if (
auto EC =
Text.getError())
4637 DiagHandler,
nullptr,
4645 StringRef FallbackStyleName, StringRef Code,
4646 llvm::vfs::FileSystem *FS,
4647 bool AllowUnknownOptions,
4648 llvm::SourceMgr::DiagHandlerTy DiagHandler) {
4656 if (StyleName.starts_with(
"{")) {
4658 StringRef Source =
"<command-line>";
4659 if (std::error_code ec =
4661 AllowUnknownOptions, DiagHandler)) {
4665 if (Style.InheritConfig.empty())
4668 ChildFormatTextToApply.emplace_back(
4669 llvm::MemoryBuffer::getMemBuffer(StyleName, Source,
false));
4673 FS = llvm::vfs::getRealFileSystem().get();
4676 const bool IsDotHFile =
FileName.ends_with(
".h");
4679 if (Style.InheritConfig.empty() &&
4680 StyleName.starts_with_insensitive(
"file:")) {
4681 auto ConfigFile = StyleName.substr(5);
4682 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
Text =
4684 DiagHandler, IsDotHFile);
4685 if (
auto EC =
Text.getError()) {
4690 LLVM_DEBUG(llvm::dbgs()
4691 <<
"Using configuration file " << ConfigFile <<
"\n");
4693 if (Style.InheritConfig.empty())
4699 ChildFormatTextToApply.emplace_back(std::move(*
Text));
4705 if (Style.InheritConfig.empty() && !StyleName.equals_insensitive(
"file")) {
4708 if (Style.InheritConfig.empty())
4712 using namespace llvm::sys::path;
4716 if (std::error_code EC = FS->makeAbsolute(Path))
4719 auto Normalize = [](String &Path) {
4720 Path = convert_to_slash(Path);
4721 remove_dots(Path,
true, Style::posix);
4727 Style.InheritConfig.clear();
4729 auto dropDiagnosticHandler = [](
const llvm::SMDiagnostic &,
void *) {};
4731 auto applyChildFormatTexts = [&](FormatStyle *Style) {
4732 for (
const auto &MemBuf : llvm::reverse(ChildFormatTextToApply)) {
4735 DiagHandler ? DiagHandler : dropDiagnosticHandler);
4738 static_cast<void>(EC);
4744 FilesToLookFor.push_back(
".clang-format");
4745 FilesToLookFor.push_back(
"_clang-format");
4747 llvm::StringSet<> Directories;
4748 bool Redirected =
false;
4749 String Dir, UnsuitableConfigFiles;
4750 for (StringRef Directory = Path; !Directory.empty();
4751 Directory = Redirected ? Dir.str() : parent_path(Directory)) {
4752 auto Status = FS->status(Directory);
4754 Status->getType() != llvm::sys::fs::file_type::directory_file) {
4761 for (
const auto &F : FilesToLookFor) {
4762 String ConfigFile(Directory);
4764 append(ConfigFile, F);
4765 LLVM_DEBUG(llvm::dbgs() <<
"Trying " << ConfigFile <<
"...\n");
4767 Status = FS->status(ConfigFile);
4769 Status->getType() != llvm::sys::fs::file_type::regular_file) {
4773 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
Text =
4775 DiagHandler, IsDotHFile);
4776 if (
auto EC =
Text.getError()) {
4781 if (!UnsuitableConfigFiles.empty())
4782 UnsuitableConfigFiles.append(
", ");
4783 UnsuitableConfigFiles.append(ConfigFile);
4787 LLVM_DEBUG(llvm::dbgs()
4788 <<
"Using configuration file " << ConfigFile <<
"\n");
4790 if (Style.InheritConfig.empty()) {
4791 if (!ChildFormatTextToApply.empty()) {
4792 LLVM_DEBUG(llvm::dbgs() <<
"Applying child configurations\n");
4793 applyChildFormatTexts(&Style);
4798 if (!Directories.insert(Directory).second) {
4800 "Loop detected when inheriting configuration file in " + Directory);
4803 LLVM_DEBUG(llvm::dbgs() <<
"Inherits parent configuration\n");
4805 if (Style.InheritConfig ==
"..") {
4810 llvm::sys::fs::expand_tilde(Style.InheritConfig, ExpandedDir);
4811 Normalize(ExpandedDir);
4812 if (is_absolute(ExpandedDir, Style::posix)) {
4815 Dir = Directory.str();
4816 append(Dir, Style::posix, ExpandedDir);
4821 Style.InheritConfig.clear();
4823 ChildFormatTextToApply.emplace_back(std::move(*
Text));
4833 if (!UnsuitableConfigFiles.empty()) {
4836 UnsuitableConfigFiles);
4839 if (!ChildFormatTextToApply.empty()) {
4840 LLVM_DEBUG(llvm::dbgs()
4841 <<
"Applying child configurations on fallback style\n");
4842 applyChildFormatTexts(&FallbackStyle);
4845 return FallbackStyle;
4849 if (Comment == (On ?
"/* clang-format on */" :
"/* clang-format off */"))
4852 static const char ClangFormatOn[] =
"// clang-format on";
4853 static const char ClangFormatOff[] =
"// clang-format off";
4854 const unsigned Size = (On ?
sizeof ClangFormatOn :
sizeof ClangFormatOff) - 1;
4856 return Comment.starts_with(On ? ClangFormatOn : ClangFormatOff) &&
4857 (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)