26#include "llvm/ADT/Sequence.h"
27#include "llvm/ADT/StringSet.h"
30#define DEBUG_TYPE "format-formatter"
32using clang::format::FormatStyle;
34LLVM_YAML_IS_SEQUENCE_VECTOR(FormatStyle::RawStringFormat)
35LLVM_YAML_IS_SEQUENCE_VECTOR(FormatStyle::BinaryOperationBreakRule)
48struct ScalarEnumerationTraits<FormatStyle::BreakBeforeNoexceptSpecifierStyle> {
51 IO.enumCase(
Value,
"Never", FormatStyle::BBNSS_Never);
52 IO.enumCase(
Value,
"OnlyWithParen", FormatStyle::BBNSS_OnlyWithParen);
53 IO.enumCase(
Value,
"Always", FormatStyle::BBNSS_Always);
57template <>
struct MappingTraits<FormatStyle::AlignConsecutiveStyle> {
59 IO.enumCase(
Value,
"None", FormatStyle::AlignConsecutiveStyle({}));
60 IO.enumCase(
Value,
"Consecutive",
61 FormatStyle::AlignConsecutiveStyle(
66 IO.enumCase(
Value,
"AcrossEmptyLines",
67 FormatStyle::AlignConsecutiveStyle(
72 IO.enumCase(
Value,
"AcrossComments",
73 FormatStyle::AlignConsecutiveStyle(
78 IO.enumCase(
Value,
"AcrossEmptyLinesAndComments",
79 FormatStyle::AlignConsecutiveStyle(
86 IO.enumCase(
Value,
"true",
87 FormatStyle::AlignConsecutiveStyle(
92 IO.enumCase(
Value,
"false", FormatStyle::AlignConsecutiveStyle({}));
95 static void mapping(IO &IO, FormatStyle::AlignConsecutiveStyle &
Value) {
96 IO.mapOptional(
"Enabled",
Value.Enabled);
97 IO.mapOptional(
"AcrossEmptyLines",
Value.AcrossEmptyLines);
98 IO.mapOptional(
"AcrossComments",
Value.AcrossComments);
99 IO.mapOptional(
"AlignCompound",
Value.AlignCompound);
100 IO.mapOptional(
"AlignFunctionDeclarations",
101 Value.AlignFunctionDeclarations);
102 IO.mapOptional(
"AlignFunctionPointers",
Value.AlignFunctionPointers);
103 IO.mapOptional(
"PadOperators",
Value.PadOperators);
108struct MappingTraits<FormatStyle::ShortCaseStatementsAlignmentStyle> {
110 FormatStyle::ShortCaseStatementsAlignmentStyle &
Value) {
111 IO.mapOptional(
"Enabled",
Value.Enabled);
112 IO.mapOptional(
"AcrossEmptyLines",
Value.AcrossEmptyLines);
113 IO.mapOptional(
"AcrossComments",
Value.AcrossComments);
114 IO.mapOptional(
"AlignCaseArrows",
Value.AlignCaseArrows);
115 IO.mapOptional(
"AlignCaseColons",
Value.AlignCaseColons);
120struct ScalarEnumerationTraits<FormatStyle::AttributeBreakingStyle> {
122 IO.enumCase(
Value,
"Always", FormatStyle::ABS_Always);
123 IO.enumCase(
Value,
"Leave", FormatStyle::ABS_Leave);
124 IO.enumCase(
Value,
"Never", FormatStyle::ABS_Never);
129struct ScalarEnumerationTraits<FormatStyle::ArrayInitializerAlignmentStyle> {
131 FormatStyle::ArrayInitializerAlignmentStyle &
Value) {
132 IO.enumCase(
Value,
"None", FormatStyle::AIAS_None);
133 IO.enumCase(
Value,
"Left", FormatStyle::AIAS_Left);
134 IO.enumCase(
Value,
"Right", FormatStyle::AIAS_Right);
138template <>
struct ScalarEnumerationTraits<FormatStyle::BinaryOperatorStyle> {
140 IO.enumCase(
Value,
"All", FormatStyle::BOS_All);
141 IO.enumCase(
Value,
"true", FormatStyle::BOS_All);
142 IO.enumCase(
Value,
"None", FormatStyle::BOS_None);
143 IO.enumCase(
Value,
"false", FormatStyle::BOS_None);
144 IO.enumCase(
Value,
"NonAssignment", FormatStyle::BOS_NonAssignment);
149struct ScalarEnumerationTraits<FormatStyle::BinPackParametersStyle> {
151 IO.enumCase(
Value,
"BinPack", FormatStyle::BPPS_BinPack);
152 IO.enumCase(
Value,
"OnePerLine", FormatStyle::BPPS_OnePerLine);
153 IO.enumCase(
Value,
"AlwaysOnePerLine", FormatStyle::BPPS_AlwaysOnePerLine);
156 IO.enumCase(
Value,
"true", FormatStyle::BPPS_BinPack);
157 IO.enumCase(
Value,
"false", FormatStyle::BPPS_OnePerLine);
161template <>
struct ScalarEnumerationTraits<FormatStyle::BinPackStyle> {
163 IO.enumCase(
Value,
"Auto", FormatStyle::BPS_Auto);
164 IO.enumCase(
Value,
"Always", FormatStyle::BPS_Always);
165 IO.enumCase(
Value,
"Never", FormatStyle::BPS_Never);
170struct ScalarEnumerationTraits<FormatStyle::BitFieldColonSpacingStyle> {
172 FormatStyle::BitFieldColonSpacingStyle &
Value) {
173 IO.enumCase(
Value,
"Both", FormatStyle::BFCS_Both);
174 IO.enumCase(
Value,
"None", FormatStyle::BFCS_None);
175 IO.enumCase(
Value,
"Before", FormatStyle::BFCS_Before);
176 IO.enumCase(
Value,
"After", FormatStyle::BFCS_After);
180template <>
struct ScalarEnumerationTraits<FormatStyle::BraceBreakingStyle> {
182 IO.enumCase(
Value,
"Attach", FormatStyle::BS_Attach);
183 IO.enumCase(
Value,
"Linux", FormatStyle::BS_Linux);
184 IO.enumCase(
Value,
"Mozilla", FormatStyle::BS_Mozilla);
185 IO.enumCase(
Value,
"Stroustrup", FormatStyle::BS_Stroustrup);
186 IO.enumCase(
Value,
"Allman", FormatStyle::BS_Allman);
187 IO.enumCase(
Value,
"Whitesmiths", FormatStyle::BS_Whitesmiths);
188 IO.enumCase(
Value,
"GNU", FormatStyle::BS_GNU);
189 IO.enumCase(
Value,
"WebKit", FormatStyle::BS_WebKit);
190 IO.enumCase(
Value,
"Custom", FormatStyle::BS_Custom);
194template <>
struct MappingTraits<FormatStyle::BraceWrappingFlags> {
195 static void mapping(IO &IO, FormatStyle::BraceWrappingFlags &Wrapping) {
196 IO.mapOptional(
"AfterCaseLabel", Wrapping.AfterCaseLabel);
197 IO.mapOptional(
"AfterClass", Wrapping.AfterClass);
198 IO.mapOptional(
"AfterControlStatement", Wrapping.AfterControlStatement);
199 IO.mapOptional(
"AfterEnum", Wrapping.AfterEnum);
200 IO.mapOptional(
"AfterExternBlock", Wrapping.AfterExternBlock);
201 IO.mapOptional(
"AfterFunction", Wrapping.AfterFunction);
202 IO.mapOptional(
"AfterNamespace", Wrapping.AfterNamespace);
203 IO.mapOptional(
"AfterObjCDeclaration", Wrapping.AfterObjCDeclaration);
204 IO.mapOptional(
"AfterStruct", Wrapping.AfterStruct);
205 IO.mapOptional(
"AfterUnion", Wrapping.AfterUnion);
206 IO.mapOptional(
"BeforeCatch", Wrapping.BeforeCatch);
207 IO.mapOptional(
"BeforeElse", Wrapping.BeforeElse);
208 IO.mapOptional(
"BeforeLambdaBody", Wrapping.BeforeLambdaBody);
209 IO.mapOptional(
"BeforeWhile", Wrapping.BeforeWhile);
210 IO.mapOptional(
"IndentBraces", Wrapping.IndentBraces);
211 IO.mapOptional(
"SplitEmptyFunction", Wrapping.SplitEmptyFunction);
212 IO.mapOptional(
"SplitEmptyRecord", Wrapping.SplitEmptyRecord);
213 IO.mapOptional(
"SplitEmptyNamespace", Wrapping.SplitEmptyNamespace);
231struct ScalarEnumerationTraits<
232 FormatStyle::BraceWrappingAfterControlStatementStyle> {
235 FormatStyle::BraceWrappingAfterControlStatementStyle &
Value) {
236 IO.enumCase(
Value,
"Never", FormatStyle::BWACS_Never);
237 IO.enumCase(
Value,
"MultiLine", FormatStyle::BWACS_MultiLine);
238 IO.enumCase(
Value,
"Always", FormatStyle::BWACS_Always);
241 IO.enumCase(
Value,
"false", FormatStyle::BWACS_Never);
242 IO.enumCase(
Value,
"true", FormatStyle::BWACS_Always);
247struct ScalarEnumerationTraits<
248 FormatStyle::BreakBeforeConceptDeclarationsStyle> {
251 IO.enumCase(
Value,
"Never", FormatStyle::BBCDS_Never);
252 IO.enumCase(
Value,
"Allowed", FormatStyle::BBCDS_Allowed);
253 IO.enumCase(
Value,
"Always", FormatStyle::BBCDS_Always);
256 IO.enumCase(
Value,
"true", FormatStyle::BBCDS_Always);
257 IO.enumCase(
Value,
"false", FormatStyle::BBCDS_Allowed);
262struct ScalarEnumerationTraits<FormatStyle::BreakBeforeInlineASMColonStyle> {
264 FormatStyle::BreakBeforeInlineASMColonStyle &
Value) {
265 IO.enumCase(
Value,
"Never", FormatStyle::BBIAS_Never);
266 IO.enumCase(
Value,
"OnlyMultiline", FormatStyle::BBIAS_OnlyMultiline);
267 IO.enumCase(
Value,
"Always", FormatStyle::BBIAS_Always);
272struct ScalarEnumerationTraits<FormatStyle::BreakBinaryOperationsStyle> {
274 FormatStyle::BreakBinaryOperationsStyle &
Value) {
275 IO.enumCase(
Value,
"Never", FormatStyle::BBO_Never);
276 IO.enumCase(
Value,
"OnePerLine", FormatStyle::BBO_OnePerLine);
277 IO.enumCase(
Value,
"RespectPrecedence", FormatStyle::BBO_RespectPrecedence);
281template <>
struct ScalarTraits<
clang::tok::TokenKind> {
283 llvm::raw_ostream &Out) {
290 static StringRef
input(StringRef Scalar,
void *,
293#define PUNCTUATOR(Name, Spelling) \
294 if (Scalar == Spelling) { \
295 Value = clang::tok::Name; \
298#include "clang/Basic/TokenKinds.def"
299 return "unknown operator";
302 static QuotingType
mustQuote(StringRef) {
return QuotingType::None; }
305template <>
struct MappingTraits<FormatStyle::BinaryOperationBreakRule> {
306 static void mapping(IO &IO, FormatStyle::BinaryOperationBreakRule &
Value) {
307 IO.mapOptional(
"Operators",
Value.Operators);
309 if (!IO.outputting())
310 Value.Style = FormatStyle::BBO_OnePerLine;
311 IO.mapOptional(
"Style",
Value.Style);
312 IO.mapOptional(
"MinChainLength",
Value.MinChainLength);
316template <>
struct MappingTraits<FormatStyle::BreakBinaryOperationsOptions> {
318 FormatStyle::BreakBinaryOperationsOptions &
Value) {
319 IO.enumCase(
Value,
"Never",
320 FormatStyle::BreakBinaryOperationsOptions(
321 {FormatStyle::BBO_Never, {}}));
322 IO.enumCase(
Value,
"OnePerLine",
323 FormatStyle::BreakBinaryOperationsOptions(
324 {FormatStyle::BBO_OnePerLine, {}}));
325 IO.enumCase(
Value,
"RespectPrecedence",
326 FormatStyle::BreakBinaryOperationsOptions(
327 {FormatStyle::BBO_RespectPrecedence, {}}));
331 FormatStyle::BreakBinaryOperationsOptions &
Value) {
332 IO.mapOptional(
"Default",
Value.Default);
333 IO.mapOptional(
"PerOperator",
Value.PerOperator);
338struct ScalarEnumerationTraits<FormatStyle::BreakConstructorInitializersStyle> {
341 IO.enumCase(
Value,
"BeforeColon", FormatStyle::BCIS_BeforeColon);
342 IO.enumCase(
Value,
"BeforeComma", FormatStyle::BCIS_BeforeComma);
343 IO.enumCase(
Value,
"AfterColon", FormatStyle::BCIS_AfterColon);
344 IO.enumCase(
Value,
"AfterComma", FormatStyle::BCIS_AfterComma);
349struct ScalarEnumerationTraits<FormatStyle::BreakInheritanceListStyle> {
351 FormatStyle::BreakInheritanceListStyle &
Value) {
352 IO.enumCase(
Value,
"BeforeColon", FormatStyle::BILS_BeforeColon);
353 IO.enumCase(
Value,
"BeforeComma", FormatStyle::BILS_BeforeComma);
354 IO.enumCase(
Value,
"AfterColon", FormatStyle::BILS_AfterColon);
355 IO.enumCase(
Value,
"AfterComma", FormatStyle::BILS_AfterComma);
360struct ScalarEnumerationTraits<FormatStyle::BreakTemplateDeclarationsStyle> {
362 FormatStyle::BreakTemplateDeclarationsStyle &
Value) {
363 IO.enumCase(
Value,
"Leave", FormatStyle::BTDS_Leave);
364 IO.enumCase(
Value,
"No", FormatStyle::BTDS_No);
365 IO.enumCase(
Value,
"MultiLine", FormatStyle::BTDS_MultiLine);
366 IO.enumCase(
Value,
"Yes", FormatStyle::BTDS_Yes);
369 IO.enumCase(
Value,
"false", FormatStyle::BTDS_MultiLine);
370 IO.enumCase(
Value,
"true", FormatStyle::BTDS_Yes);
374template <>
struct ScalarEnumerationTraits<FormatStyle::BracedListStyle> {
376 IO.enumCase(
Value,
"Block", FormatStyle::BLS_Block);
377 IO.enumCase(
Value,
"FunctionCall", FormatStyle::BLS_FunctionCall);
378 IO.enumCase(
Value,
"AlignFirstComment", FormatStyle::BLS_AlignFirstComment);
381 IO.enumCase(
Value,
"false", FormatStyle::BLS_Block);
382 IO.enumCase(
Value,
"true", FormatStyle::BLS_AlignFirstComment);
386template <>
struct ScalarEnumerationTraits<FormatStyle::DAGArgStyle> {
388 IO.enumCase(
Value,
"DontBreak", FormatStyle::DAS_DontBreak);
389 IO.enumCase(
Value,
"BreakElements", FormatStyle::DAS_BreakElements);
390 IO.enumCase(
Value,
"BreakAll", FormatStyle::DAS_BreakAll);
395struct ScalarEnumerationTraits<FormatStyle::DefinitionReturnTypeBreakingStyle> {
398 IO.enumCase(
Value,
"None", FormatStyle::DRTBS_None);
399 IO.enumCase(
Value,
"All", FormatStyle::DRTBS_All);
400 IO.enumCase(
Value,
"TopLevel", FormatStyle::DRTBS_TopLevel);
403 IO.enumCase(
Value,
"false", FormatStyle::DRTBS_None);
404 IO.enumCase(
Value,
"true", FormatStyle::DRTBS_All);
409struct ScalarEnumerationTraits<FormatStyle::EscapedNewlineAlignmentStyle> {
411 FormatStyle::EscapedNewlineAlignmentStyle &
Value) {
412 IO.enumCase(
Value,
"DontAlign", FormatStyle::ENAS_DontAlign);
413 IO.enumCase(
Value,
"Left", FormatStyle::ENAS_Left);
414 IO.enumCase(
Value,
"LeftWithLastLine", FormatStyle::ENAS_LeftWithLastLine);
415 IO.enumCase(
Value,
"Right", FormatStyle::ENAS_Right);
418 IO.enumCase(
Value,
"true", FormatStyle::ENAS_Left);
419 IO.enumCase(
Value,
"false", FormatStyle::ENAS_Right);
424struct ScalarEnumerationTraits<FormatStyle::EmptyLineAfterAccessModifierStyle> {
427 IO.enumCase(
Value,
"Never", FormatStyle::ELAAMS_Never);
428 IO.enumCase(
Value,
"Leave", FormatStyle::ELAAMS_Leave);
429 IO.enumCase(
Value,
"Always", FormatStyle::ELAAMS_Always);
434struct ScalarEnumerationTraits<
435 FormatStyle::EmptyLineBeforeAccessModifierStyle> {
438 IO.enumCase(
Value,
"Never", FormatStyle::ELBAMS_Never);
439 IO.enumCase(
Value,
"Leave", FormatStyle::ELBAMS_Leave);
440 IO.enumCase(
Value,
"LogicalBlock", FormatStyle::ELBAMS_LogicalBlock);
441 IO.enumCase(
Value,
"Always", FormatStyle::ELBAMS_Always);
446struct ScalarEnumerationTraits<FormatStyle::EnumTrailingCommaStyle> {
448 IO.enumCase(
Value,
"Leave", FormatStyle::ETC_Leave);
449 IO.enumCase(
Value,
"Insert", FormatStyle::ETC_Insert);
450 IO.enumCase(
Value,
"Remove", FormatStyle::ETC_Remove);
455struct ScalarEnumerationTraits<FormatStyle::IndentExternBlockStyle> {
457 IO.enumCase(
Value,
"AfterExternBlock", FormatStyle::IEBS_AfterExternBlock);
458 IO.enumCase(
Value,
"Indent", FormatStyle::IEBS_Indent);
459 IO.enumCase(
Value,
"NoIndent", FormatStyle::IEBS_NoIndent);
460 IO.enumCase(
Value,
"true", FormatStyle::IEBS_Indent);
461 IO.enumCase(
Value,
"false", FormatStyle::IEBS_NoIndent);
465template <>
struct MappingTraits<FormatStyle::IntegerLiteralSeparatorStyle> {
466 static void mapping(IO &IO, FormatStyle::IntegerLiteralSeparatorStyle &
Base) {
467 IO.mapOptional(
"Binary",
Base.Binary);
468 IO.mapOptional(
"BinaryMinDigitsInsert",
Base.BinaryMinDigitsInsert);
469 IO.mapOptional(
"BinaryMaxDigitsRemove",
Base.BinaryMaxDigitsRemove);
470 IO.mapOptional(
"Decimal",
Base.Decimal);
471 IO.mapOptional(
"DecimalMinDigitsInsert",
Base.DecimalMinDigitsInsert);
472 IO.mapOptional(
"DecimalMaxDigitsRemove",
Base.DecimalMaxDigitsRemove);
473 IO.mapOptional(
"Hex",
Base.Hex);
474 IO.mapOptional(
"HexMinDigitsInsert",
Base.HexMinDigitsInsert);
475 IO.mapOptional(
"HexMaxDigitsRemove",
Base.HexMaxDigitsRemove);
478 IO.mapOptional(
"BinaryMinDigits",
Base.BinaryMinDigitsInsert);
479 IO.mapOptional(
"DecimalMinDigits",
Base.DecimalMinDigitsInsert);
480 IO.mapOptional(
"HexMinDigits",
Base.HexMinDigitsInsert);
484template <>
struct ScalarEnumerationTraits<FormatStyle::JavaScriptQuoteStyle> {
486 IO.enumCase(
Value,
"Leave", FormatStyle::JSQS_Leave);
487 IO.enumCase(
Value,
"Single", FormatStyle::JSQS_Single);
488 IO.enumCase(
Value,
"Double", FormatStyle::JSQS_Double);
492template <>
struct MappingTraits<FormatStyle::KeepEmptyLinesStyle> {
494 IO.mapOptional(
"AtEndOfFile",
Value.AtEndOfFile);
495 IO.mapOptional(
"AtStartOfBlock",
Value.AtStartOfBlock);
496 IO.mapOptional(
"AtStartOfFile",
Value.AtStartOfFile);
500template <>
struct ScalarEnumerationTraits<FormatStyle::LanguageKind> {
502 IO.enumCase(
Value,
"C", FormatStyle::LK_C);
503 IO.enumCase(
Value,
"Cpp", FormatStyle::LK_Cpp);
504 IO.enumCase(
Value,
"Java", FormatStyle::LK_Java);
505 IO.enumCase(
Value,
"JavaScript", FormatStyle::LK_JavaScript);
506 IO.enumCase(
Value,
"ObjC", FormatStyle::LK_ObjC);
507 IO.enumCase(
Value,
"Proto", FormatStyle::LK_Proto);
508 IO.enumCase(
Value,
"TableGen", FormatStyle::LK_TableGen);
509 IO.enumCase(
Value,
"TextProto", FormatStyle::LK_TextProto);
510 IO.enumCase(
Value,
"CSharp", FormatStyle::LK_CSharp);
511 IO.enumCase(
Value,
"Json", FormatStyle::LK_Json);
512 IO.enumCase(
Value,
"Verilog", FormatStyle::LK_Verilog);
516template <>
struct ScalarEnumerationTraits<FormatStyle::LanguageStandard> {
518 IO.enumCase(
Value,
"c++03", FormatStyle::LS_Cpp03);
519 IO.enumCase(
Value,
"C++03", FormatStyle::LS_Cpp03);
520 IO.enumCase(
Value,
"Cpp03", FormatStyle::LS_Cpp03);
522 IO.enumCase(
Value,
"c++11", FormatStyle::LS_Cpp11);
523 IO.enumCase(
Value,
"C++11", FormatStyle::LS_Cpp11);
525 IO.enumCase(
Value,
"c++14", FormatStyle::LS_Cpp14);
526 IO.enumCase(
Value,
"c++17", FormatStyle::LS_Cpp17);
527 IO.enumCase(
Value,
"c++20", FormatStyle::LS_Cpp20);
529 IO.enumCase(
Value,
"Latest", FormatStyle::LS_Latest);
530 IO.enumCase(
Value,
"Cpp11", FormatStyle::LS_Latest);
531 IO.enumCase(
Value,
"Auto", FormatStyle::LS_Auto);
536struct ScalarEnumerationTraits<FormatStyle::LambdaBodyIndentationKind> {
538 FormatStyle::LambdaBodyIndentationKind &
Value) {
539 IO.enumCase(
Value,
"Signature", FormatStyle::LBI_Signature);
540 IO.enumCase(
Value,
"OuterScope", FormatStyle::LBI_OuterScope);
544template <>
struct ScalarEnumerationTraits<FormatStyle::LineEndingStyle> {
546 IO.enumCase(
Value,
"LF", FormatStyle::LE_LF);
547 IO.enumCase(
Value,
"CRLF", FormatStyle::LE_CRLF);
548 IO.enumCase(
Value,
"DeriveLF", FormatStyle::LE_DeriveLF);
549 IO.enumCase(
Value,
"DeriveCRLF", FormatStyle::LE_DeriveCRLF);
554struct ScalarEnumerationTraits<FormatStyle::NamespaceIndentationKind> {
556 FormatStyle::NamespaceIndentationKind &
Value) {
557 IO.enumCase(
Value,
"None", FormatStyle::NI_None);
558 IO.enumCase(
Value,
"Inner", FormatStyle::NI_Inner);
559 IO.enumCase(
Value,
"All", FormatStyle::NI_All);
564struct ScalarEnumerationTraits<FormatStyle::NumericLiteralComponentStyle> {
566 FormatStyle::NumericLiteralComponentStyle &
Value) {
567 IO.enumCase(
Value,
"Leave", FormatStyle::NLCS_Leave);
568 IO.enumCase(
Value,
"Upper", FormatStyle::NLCS_Upper);
569 IO.enumCase(
Value,
"Lower", FormatStyle::NLCS_Lower);
573template <>
struct MappingTraits<FormatStyle::NumericLiteralCaseStyle> {
574 static void mapping(IO &IO, FormatStyle::NumericLiteralCaseStyle &
Value) {
575 IO.mapOptional(
"ExponentLetter",
Value.ExponentLetter);
576 IO.mapOptional(
"HexDigit",
Value.HexDigit);
577 IO.mapOptional(
"Prefix",
Value.Prefix);
578 IO.mapOptional(
"Suffix",
Value.Suffix);
582template <>
struct ScalarEnumerationTraits<FormatStyle::OperandAlignmentStyle> {
584 IO.enumCase(
Value,
"DontAlign", FormatStyle::OAS_DontAlign);
585 IO.enumCase(
Value,
"Align", FormatStyle::OAS_Align);
586 IO.enumCase(
Value,
"AlignAfterOperator",
587 FormatStyle::OAS_AlignAfterOperator);
590 IO.enumCase(
Value,
"true", FormatStyle::OAS_Align);
591 IO.enumCase(
Value,
"false", FormatStyle::OAS_DontAlign);
596struct ScalarEnumerationTraits<FormatStyle::PackConstructorInitializersStyle> {
599 IO.enumCase(
Value,
"Never", FormatStyle::PCIS_Never);
600 IO.enumCase(
Value,
"BinPack", FormatStyle::PCIS_BinPack);
601 IO.enumCase(
Value,
"CurrentLine", FormatStyle::PCIS_CurrentLine);
602 IO.enumCase(
Value,
"NextLine", FormatStyle::PCIS_NextLine);
603 IO.enumCase(
Value,
"NextLineOnly", FormatStyle::PCIS_NextLineOnly);
607template <>
struct ScalarEnumerationTraits<FormatStyle::PointerAlignmentStyle> {
609 IO.enumCase(
Value,
"Middle", FormatStyle::PAS_Middle);
610 IO.enumCase(
Value,
"Left", FormatStyle::PAS_Left);
611 IO.enumCase(
Value,
"Right", FormatStyle::PAS_Right);
614 IO.enumCase(
Value,
"true", FormatStyle::PAS_Left);
615 IO.enumCase(
Value,
"false", FormatStyle::PAS_Right);
620struct ScalarEnumerationTraits<FormatStyle::PPDirectiveIndentStyle> {
622 IO.enumCase(
Value,
"None", FormatStyle::PPDIS_None);
623 IO.enumCase(
Value,
"AfterHash", FormatStyle::PPDIS_AfterHash);
624 IO.enumCase(
Value,
"BeforeHash", FormatStyle::PPDIS_BeforeHash);
625 IO.enumCase(
Value,
"Leave", FormatStyle::PPDIS_Leave);
630struct ScalarEnumerationTraits<FormatStyle::QualifierAlignmentStyle> {
632 IO.enumCase(
Value,
"Leave", FormatStyle::QAS_Leave);
633 IO.enumCase(
Value,
"Left", FormatStyle::QAS_Left);
634 IO.enumCase(
Value,
"Right", FormatStyle::QAS_Right);
635 IO.enumCase(
Value,
"Custom", FormatStyle::QAS_Custom);
639template <>
struct MappingTraits<FormatStyle::RawStringFormat> {
640 static void mapping(IO &IO, FormatStyle::RawStringFormat &Format) {
641 IO.mapOptional(
"Language", Format.Language);
642 IO.mapOptional(
"Delimiters", Format.Delimiters);
643 IO.mapOptional(
"EnclosingFunctions", Format.EnclosingFunctions);
644 IO.mapOptional(
"CanonicalDelimiter", Format.CanonicalDelimiter);
645 IO.mapOptional(
"BasedOnStyle", Format.BasedOnStyle);
649template <>
struct ScalarEnumerationTraits<FormatStyle::ReflowCommentsStyle> {
651 IO.enumCase(
Value,
"Never", FormatStyle::RCS_Never);
652 IO.enumCase(
Value,
"IndentOnly", FormatStyle::RCS_IndentOnly);
653 IO.enumCase(
Value,
"Always", FormatStyle::RCS_Always);
655 IO.enumCase(
Value,
"false", FormatStyle::RCS_Never);
656 IO.enumCase(
Value,
"true", FormatStyle::RCS_Always);
661struct ScalarEnumerationTraits<FormatStyle::ReferenceAlignmentStyle> {
663 IO.enumCase(
Value,
"Pointer", FormatStyle::RAS_Pointer);
664 IO.enumCase(
Value,
"Middle", FormatStyle::RAS_Middle);
665 IO.enumCase(
Value,
"Left", FormatStyle::RAS_Left);
666 IO.enumCase(
Value,
"Right", FormatStyle::RAS_Right);
671struct ScalarEnumerationTraits<FormatStyle::RemoveParenthesesStyle> {
673 IO.enumCase(
Value,
"Leave", FormatStyle::RPS_Leave);
674 IO.enumCase(
Value,
"MultipleParentheses",
675 FormatStyle::RPS_MultipleParentheses);
676 IO.enumCase(
Value,
"ReturnStatement", FormatStyle::RPS_ReturnStatement);
681struct ScalarEnumerationTraits<FormatStyle::RequiresClausePositionStyle> {
683 FormatStyle::RequiresClausePositionStyle &
Value) {
684 IO.enumCase(
Value,
"OwnLine", FormatStyle::RCPS_OwnLine);
685 IO.enumCase(
Value,
"OwnLineWithBrace", FormatStyle::RCPS_OwnLineWithBrace);
686 IO.enumCase(
Value,
"WithPreceding", FormatStyle::RCPS_WithPreceding);
687 IO.enumCase(
Value,
"WithFollowing", FormatStyle::RCPS_WithFollowing);
688 IO.enumCase(
Value,
"SingleLine", FormatStyle::RCPS_SingleLine);
693struct ScalarEnumerationTraits<FormatStyle::RequiresExpressionIndentationKind> {
696 IO.enumCase(
Value,
"Keyword", FormatStyle::REI_Keyword);
697 IO.enumCase(
Value,
"OuterScope", FormatStyle::REI_OuterScope);
702struct ScalarEnumerationTraits<FormatStyle::ReturnTypeBreakingStyle> {
704 IO.enumCase(
Value,
"None", FormatStyle::RTBS_None);
705 IO.enumCase(
Value,
"Automatic", FormatStyle::RTBS_Automatic);
706 IO.enumCase(
Value,
"ExceptShortType", FormatStyle::RTBS_ExceptShortType);
707 IO.enumCase(
Value,
"All", FormatStyle::RTBS_All);
708 IO.enumCase(
Value,
"TopLevel", FormatStyle::RTBS_TopLevel);
709 IO.enumCase(
Value,
"TopLevelDefinitions",
710 FormatStyle::RTBS_TopLevelDefinitions);
711 IO.enumCase(
Value,
"AllDefinitions", FormatStyle::RTBS_AllDefinitions);
716struct ScalarEnumerationTraits<FormatStyle::SeparateDefinitionStyle> {
718 IO.enumCase(
Value,
"Leave", FormatStyle::SDS_Leave);
719 IO.enumCase(
Value,
"Always", FormatStyle::SDS_Always);
720 IO.enumCase(
Value,
"Never", FormatStyle::SDS_Never);
724template <>
struct ScalarEnumerationTraits<FormatStyle::ShortBlockStyle> {
726 IO.enumCase(
Value,
"Never", FormatStyle::SBS_Never);
727 IO.enumCase(
Value,
"false", FormatStyle::SBS_Never);
728 IO.enumCase(
Value,
"Always", FormatStyle::SBS_Always);
729 IO.enumCase(
Value,
"true", FormatStyle::SBS_Always);
730 IO.enumCase(
Value,
"Empty", FormatStyle::SBS_Empty);
734template <>
struct ScalarEnumerationTraits<FormatStyle::ShortFunctionStyle> {
736 IO.enumCase(
Value,
"None", FormatStyle::SFS_None);
737 IO.enumCase(
Value,
"false", FormatStyle::SFS_None);
738 IO.enumCase(
Value,
"All", FormatStyle::SFS_All);
739 IO.enumCase(
Value,
"true", FormatStyle::SFS_All);
740 IO.enumCase(
Value,
"Inline", FormatStyle::SFS_Inline);
741 IO.enumCase(
Value,
"InlineOnly", FormatStyle::SFS_InlineOnly);
742 IO.enumCase(
Value,
"Empty", FormatStyle::SFS_Empty);
746template <>
struct ScalarEnumerationTraits<FormatStyle::ShortIfStyle> {
748 IO.enumCase(
Value,
"Never", FormatStyle::SIS_Never);
749 IO.enumCase(
Value,
"WithoutElse", FormatStyle::SIS_WithoutElse);
750 IO.enumCase(
Value,
"OnlyFirstIf", FormatStyle::SIS_OnlyFirstIf);
751 IO.enumCase(
Value,
"AllIfsAndElse", FormatStyle::SIS_AllIfsAndElse);
754 IO.enumCase(
Value,
"Always", FormatStyle::SIS_OnlyFirstIf);
755 IO.enumCase(
Value,
"false", FormatStyle::SIS_Never);
756 IO.enumCase(
Value,
"true", FormatStyle::SIS_WithoutElse);
760template <>
struct ScalarEnumerationTraits<FormatStyle::ShortLambdaStyle> {
762 IO.enumCase(
Value,
"None", FormatStyle::SLS_None);
763 IO.enumCase(
Value,
"false", FormatStyle::SLS_None);
764 IO.enumCase(
Value,
"Empty", FormatStyle::SLS_Empty);
765 IO.enumCase(
Value,
"Inline", FormatStyle::SLS_Inline);
766 IO.enumCase(
Value,
"All", FormatStyle::SLS_All);
767 IO.enumCase(
Value,
"true", FormatStyle::SLS_All);
771template <>
struct MappingTraits<FormatStyle::SortIncludesOptions> {
773 IO.enumCase(
Value,
"Never", FormatStyle::SortIncludesOptions({}));
774 IO.enumCase(
Value,
"CaseInsensitive",
775 FormatStyle::SortIncludesOptions({
true,
778 IO.enumCase(
Value,
"CaseSensitive",
779 FormatStyle::SortIncludesOptions({
true,
784 IO.enumCase(
Value,
"false", FormatStyle::SortIncludesOptions({}));
785 IO.enumCase(
Value,
"true",
786 FormatStyle::SortIncludesOptions({
true,
792 IO.mapOptional(
"Enabled",
Value.Enabled);
793 IO.mapOptional(
"IgnoreCase",
Value.IgnoreCase);
794 IO.mapOptional(
"IgnoreExtension",
Value.IgnoreExtension);
799struct ScalarEnumerationTraits<FormatStyle::SortJavaStaticImportOptions> {
801 FormatStyle::SortJavaStaticImportOptions &
Value) {
802 IO.enumCase(
Value,
"Before", FormatStyle::SJSIO_Before);
803 IO.enumCase(
Value,
"After", FormatStyle::SJSIO_After);
808struct ScalarEnumerationTraits<FormatStyle::SortUsingDeclarationsOptions> {
810 FormatStyle::SortUsingDeclarationsOptions &
Value) {
811 IO.enumCase(
Value,
"Never", FormatStyle::SUD_Never);
812 IO.enumCase(
Value,
"Lexicographic", FormatStyle::SUD_Lexicographic);
813 IO.enumCase(
Value,
"LexicographicNumeric",
814 FormatStyle::SUD_LexicographicNumeric);
817 IO.enumCase(
Value,
"false", FormatStyle::SUD_Never);
818 IO.enumCase(
Value,
"true", FormatStyle::SUD_LexicographicNumeric);
823struct ScalarEnumerationTraits<FormatStyle::SpaceAroundPointerQualifiersStyle> {
826 IO.enumCase(
Value,
"Default", FormatStyle::SAPQ_Default);
827 IO.enumCase(
Value,
"Before", FormatStyle::SAPQ_Before);
828 IO.enumCase(
Value,
"After", FormatStyle::SAPQ_After);
829 IO.enumCase(
Value,
"Both", FormatStyle::SAPQ_Both);
833template <>
struct MappingTraits<FormatStyle::SpaceBeforeParensCustom> {
834 static void mapping(IO &IO, FormatStyle::SpaceBeforeParensCustom &Spacing) {
835 IO.mapOptional(
"AfterControlStatements", Spacing.AfterControlStatements);
836 IO.mapOptional(
"AfterForeachMacros", Spacing.AfterForeachMacros);
837 IO.mapOptional(
"AfterFunctionDefinitionName",
838 Spacing.AfterFunctionDefinitionName);
839 IO.mapOptional(
"AfterFunctionDeclarationName",
840 Spacing.AfterFunctionDeclarationName);
841 IO.mapOptional(
"AfterIfMacros", Spacing.AfterIfMacros);
842 IO.mapOptional(
"AfterNot", Spacing.AfterNot);
843 IO.mapOptional(
"AfterOverloadedOperator", Spacing.AfterOverloadedOperator);
844 IO.mapOptional(
"AfterPlacementOperator", Spacing.AfterPlacementOperator);
845 IO.mapOptional(
"AfterRequiresInClause", Spacing.AfterRequiresInClause);
846 IO.mapOptional(
"AfterRequiresInExpression",
847 Spacing.AfterRequiresInExpression);
848 IO.mapOptional(
"BeforeNonEmptyParentheses",
849 Spacing.BeforeNonEmptyParentheses);
854struct ScalarEnumerationTraits<FormatStyle::SpaceBeforeParensStyle> {
856 IO.enumCase(
Value,
"Never", FormatStyle::SBPO_Never);
857 IO.enumCase(
Value,
"ControlStatements",
858 FormatStyle::SBPO_ControlStatements);
859 IO.enumCase(
Value,
"ControlStatementsExceptControlMacros",
860 FormatStyle::SBPO_ControlStatementsExceptControlMacros);
861 IO.enumCase(
Value,
"NonEmptyParentheses",
862 FormatStyle::SBPO_NonEmptyParentheses);
863 IO.enumCase(
Value,
"Always", FormatStyle::SBPO_Always);
864 IO.enumCase(
Value,
"Custom", FormatStyle::SBPO_Custom);
867 IO.enumCase(
Value,
"false", FormatStyle::SBPO_Never);
868 IO.enumCase(
Value,
"true", FormatStyle::SBPO_ControlStatements);
869 IO.enumCase(
Value,
"ControlStatementsExceptForEachMacros",
870 FormatStyle::SBPO_ControlStatementsExceptControlMacros);
875struct ScalarEnumerationTraits<FormatStyle::SpaceInEmptyBracesStyle> {
877 IO.enumCase(
Value,
"Always", FormatStyle::SIEB_Always);
878 IO.enumCase(
Value,
"Block", FormatStyle::SIEB_Block);
879 IO.enumCase(
Value,
"Never", FormatStyle::SIEB_Never);
883template <>
struct ScalarEnumerationTraits<FormatStyle::SpacesInAnglesStyle> {
885 IO.enumCase(
Value,
"Never", FormatStyle::SIAS_Never);
886 IO.enumCase(
Value,
"Always", FormatStyle::SIAS_Always);
887 IO.enumCase(
Value,
"Leave", FormatStyle::SIAS_Leave);
890 IO.enumCase(
Value,
"false", FormatStyle::SIAS_Never);
891 IO.enumCase(
Value,
"true", FormatStyle::SIAS_Always);
895template <>
struct MappingTraits<FormatStyle::SpacesInLineComment> {
896 static void mapping(IO &IO, FormatStyle::SpacesInLineComment &Space) {
898 int signedMaximum =
static_cast<int>(Space.Maximum);
899 IO.mapOptional(
"Minimum", Space.Minimum);
900 IO.mapOptional(
"Maximum", signedMaximum);
901 Space.Maximum =
static_cast<unsigned>(signedMaximum);
903 if (Space.Maximum < std::numeric_limits<unsigned>::max())
904 Space.Minimum = std::min(Space.Minimum, Space.Maximum);
908template <>
struct MappingTraits<FormatStyle::SpacesInParensCustom> {
909 static void mapping(IO &IO, FormatStyle::SpacesInParensCustom &Spaces) {
910 IO.mapOptional(
"ExceptDoubleParentheses", Spaces.ExceptDoubleParentheses);
911 IO.mapOptional(
"InCStyleCasts", Spaces.InCStyleCasts);
912 IO.mapOptional(
"InConditionalStatements", Spaces.InConditionalStatements);
913 IO.mapOptional(
"InEmptyParentheses", Spaces.InEmptyParentheses);
914 IO.mapOptional(
"Other", Spaces.Other);
918template <>
struct ScalarEnumerationTraits<FormatStyle::SpacesInParensStyle> {
920 IO.enumCase(
Value,
"Never", FormatStyle::SIPO_Never);
921 IO.enumCase(
Value,
"Custom", FormatStyle::SIPO_Custom);
925template <>
struct ScalarEnumerationTraits<FormatStyle::TrailingCommaStyle> {
927 IO.enumCase(
Value,
"None", FormatStyle::TCS_None);
928 IO.enumCase(
Value,
"Wrapped", FormatStyle::TCS_Wrapped);
933struct ScalarEnumerationTraits<FormatStyle::TrailingCommentsAlignmentKinds> {
935 FormatStyle::TrailingCommentsAlignmentKinds &
Value) {
936 IO.enumCase(
Value,
"Leave", FormatStyle::TCAS_Leave);
937 IO.enumCase(
Value,
"Always", FormatStyle::TCAS_Always);
938 IO.enumCase(
Value,
"Never", FormatStyle::TCAS_Never);
942template <>
struct MappingTraits<FormatStyle::TrailingCommentsAlignmentStyle> {
944 FormatStyle::TrailingCommentsAlignmentStyle &
Value) {
945 IO.enumCase(
Value,
"Leave",
946 FormatStyle::TrailingCommentsAlignmentStyle(
947 {FormatStyle::TCAS_Leave, 0,
true}));
949 IO.enumCase(
Value,
"Always",
950 FormatStyle::TrailingCommentsAlignmentStyle(
951 {FormatStyle::TCAS_Always, 0,
true}));
953 IO.enumCase(
Value,
"Never",
954 FormatStyle::TrailingCommentsAlignmentStyle(
955 {FormatStyle::TCAS_Never, 0,
true}));
958 IO.enumCase(
Value,
"true",
959 FormatStyle::TrailingCommentsAlignmentStyle(
960 {FormatStyle::TCAS_Always, 0,
true}));
961 IO.enumCase(
Value,
"false",
962 FormatStyle::TrailingCommentsAlignmentStyle(
963 {FormatStyle::TCAS_Never, 0,
true}));
967 FormatStyle::TrailingCommentsAlignmentStyle &
Value) {
968 IO.mapOptional(
"AlignPPAndNotPP",
Value.AlignPPAndNotPP);
969 IO.mapOptional(
"Kind",
Value.Kind);
970 IO.mapOptional(
"OverEmptyLines",
Value.OverEmptyLines);
974template <>
struct ScalarEnumerationTraits<FormatStyle::UseTabStyle> {
976 IO.enumCase(
Value,
"Never", FormatStyle::UT_Never);
977 IO.enumCase(
Value,
"false", FormatStyle::UT_Never);
978 IO.enumCase(
Value,
"Always", FormatStyle::UT_Always);
979 IO.enumCase(
Value,
"true", FormatStyle::UT_Always);
980 IO.enumCase(
Value,
"ForIndentation", FormatStyle::UT_ForIndentation);
981 IO.enumCase(
Value,
"ForContinuationAndIndentation",
982 FormatStyle::UT_ForContinuationAndIndentation);
983 IO.enumCase(
Value,
"AlignWithSpaces", FormatStyle::UT_AlignWithSpaces);
988struct ScalarEnumerationTraits<
989 FormatStyle::WrapNamespaceBodyWithEmptyLinesStyle> {
992 FormatStyle::WrapNamespaceBodyWithEmptyLinesStyle &
Value) {
993 IO.enumCase(
Value,
"Never", FormatStyle::WNBWELS_Never);
994 IO.enumCase(
Value,
"Always", FormatStyle::WNBWELS_Always);
995 IO.enumCase(
Value,
"Leave", FormatStyle::WNBWELS_Leave);
999template <>
struct MappingTraits<FormatStyle> {
1002 IO.mapOptional(
"Language", Style.Language);
1004 StringRef BasedOnStyle;
1005 if (IO.outputting()) {
1006 StringRef Styles[] = {
"LLVM",
"Google",
"Chromium",
"Mozilla",
1007 "WebKit",
"GNU",
"Microsoft",
"clang-format"};
1008 for (StringRef StyleName : Styles) {
1009 FormatStyle PredefinedStyle;
1011 Style == PredefinedStyle) {
1012 BasedOnStyle = StyleName;
1017 IO.mapOptional(
"BasedOnStyle", BasedOnStyle);
1018 if (!BasedOnStyle.empty()) {
1019 FormatStyle::LanguageKind OldLanguage = Style.Language;
1020 FormatStyle::LanguageKind Language =
1021 ((FormatStyle *)IO.getContext())->Language;
1023 IO.setError(Twine(
"Unknown value for BasedOnStyle: ", BasedOnStyle));
1026 Style.Language = OldLanguage;
1041 const bool IsGoogleOrChromium = BasedOnStyle.equals_insensitive(
"google") ||
1042 BasedOnStyle.equals_insensitive(
"chromium");
1043 bool OnCurrentLine = IsGoogleOrChromium;
1044 bool OnNextLine =
true;
1046 bool BreakBeforeInheritanceComma =
false;
1047 bool BreakConstructorInitializersBeforeComma =
false;
1049 bool DeriveLineEnding =
true;
1050 bool UseCRLF =
false;
1052 bool SpaceInEmptyBlock =
false;
1053 bool SpaceInEmptyParentheses =
false;
1054 bool SpacesInConditionalStatement =
false;
1055 bool SpacesInCStyleCastParentheses =
false;
1056 bool SpacesInParentheses =
false;
1058 if (IO.outputting()) {
1059 IO.mapOptional(
"AlignAfterOpenBracket", Style.AlignAfterOpenBracket);
1063 if (IsGoogleOrChromium) {
1064 FormatStyle::LanguageKind Language = Style.Language;
1065 if (Language == FormatStyle::LK_None)
1066 Language = ((FormatStyle *)IO.getContext())->Language;
1067 if (Language == FormatStyle::LK_JavaScript)
1069 else if (Language == FormatStyle::LK_Java)
1071 }
else if (BasedOnStyle.equals_insensitive(
"webkit")) {
1074 IO.mapOptional(
"AlignAfterOpenBracket", LocalBAS);
1075 Style.BreakAfterOpenBracketBracedList =
false;
1076 Style.BreakAfterOpenBracketFunction =
false;
1077 Style.BreakAfterOpenBracketIf =
false;
1078 Style.BreakAfterOpenBracketLoop =
false;
1079 Style.BreakAfterOpenBracketSwitch =
false;
1080 Style.BreakBeforeCloseBracketBracedList =
false;
1081 Style.BreakBeforeCloseBracketFunction =
false;
1082 Style.BreakBeforeCloseBracketIf =
false;
1083 Style.BreakBeforeCloseBracketLoop =
false;
1084 Style.BreakBeforeCloseBracketSwitch =
false;
1088 Style.AlignAfterOpenBracket =
false;
1091 Style.BreakBeforeCloseBracketBracedList =
true;
1092 Style.BreakBeforeCloseBracketFunction =
true;
1093 Style.BreakBeforeCloseBracketIf =
true;
1096 Style.BreakAfterOpenBracketBracedList =
true;
1097 Style.BreakAfterOpenBracketFunction =
true;
1098 Style.BreakAfterOpenBracketIf =
true;
1101 Style.AlignAfterOpenBracket =
true;
1107 if (!IO.outputting()) {
1108 IO.mapOptional(
"AlignEscapedNewlinesLeft", Style.AlignEscapedNewlines);
1109 IO.mapOptional(
"AllowAllConstructorInitializersOnNextLine", OnNextLine);
1110 IO.mapOptional(
"AlwaysBreakAfterReturnType", Style.BreakAfterReturnType);
1111 IO.mapOptional(
"AlwaysBreakTemplateDeclarations",
1112 Style.BreakTemplateDeclarations);
1113 IO.mapOptional(
"BreakBeforeInheritanceComma",
1114 BreakBeforeInheritanceComma);
1115 IO.mapOptional(
"BreakConstructorInitializersBeforeComma",
1116 BreakConstructorInitializersBeforeComma);
1117 IO.mapOptional(
"ConstructorInitializerAllOnOneLineOrOnePerLine",
1119 IO.mapOptional(
"DeriveLineEnding", DeriveLineEnding);
1120 IO.mapOptional(
"DerivePointerBinding", Style.DerivePointerAlignment);
1121 IO.mapOptional(
"KeepEmptyLinesAtEOF", Style.KeepEmptyLines.AtEndOfFile);
1122 IO.mapOptional(
"KeepEmptyLinesAtTheStartOfBlocks",
1123 Style.KeepEmptyLines.AtStartOfBlock);
1124 IO.mapOptional(
"IndentFunctionDeclarationAfterType",
1125 Style.IndentWrappedFunctionNames);
1126 IO.mapOptional(
"IndentRequires", Style.IndentRequiresClause);
1127 IO.mapOptional(
"PointerBindsToType", Style.PointerAlignment);
1128 IO.mapOptional(
"SpaceAfterControlStatementKeyword",
1129 Style.SpaceBeforeParens);
1130 IO.mapOptional(
"SpaceInEmptyBlock", SpaceInEmptyBlock);
1131 IO.mapOptional(
"SpaceInEmptyParentheses", SpaceInEmptyParentheses);
1132 IO.mapOptional(
"SpacesInConditionalStatement",
1133 SpacesInConditionalStatement);
1134 IO.mapOptional(
"SpacesInCStyleCastParentheses",
1135 SpacesInCStyleCastParentheses);
1136 IO.mapOptional(
"SpacesInParentheses", SpacesInParentheses);
1137 IO.mapOptional(
"UseCRLF", UseCRLF);
1140 IO.mapOptional(
"AccessModifierOffset", Style.AccessModifierOffset);
1141 IO.mapOptional(
"AlignArrayOfStructures", Style.AlignArrayOfStructures);
1142 IO.mapOptional(
"AlignConsecutiveAssignments",
1143 Style.AlignConsecutiveAssignments);
1144 IO.mapOptional(
"AlignConsecutiveBitFields",
1145 Style.AlignConsecutiveBitFields);
1146 IO.mapOptional(
"AlignConsecutiveDeclarations",
1147 Style.AlignConsecutiveDeclarations);
1148 IO.mapOptional(
"AlignConsecutiveMacros", Style.AlignConsecutiveMacros);
1149 IO.mapOptional(
"AlignConsecutiveShortCaseStatements",
1150 Style.AlignConsecutiveShortCaseStatements);
1151 IO.mapOptional(
"AlignConsecutiveTableGenBreakingDAGArgColons",
1152 Style.AlignConsecutiveTableGenBreakingDAGArgColons);
1153 IO.mapOptional(
"AlignConsecutiveTableGenCondOperatorColons",
1154 Style.AlignConsecutiveTableGenCondOperatorColons);
1155 IO.mapOptional(
"AlignConsecutiveTableGenDefinitionColons",
1156 Style.AlignConsecutiveTableGenDefinitionColons);
1157 IO.mapOptional(
"AlignEscapedNewlines", Style.AlignEscapedNewlines);
1158 IO.mapOptional(
"AlignOperands", Style.AlignOperands);
1159 IO.mapOptional(
"AlignTrailingComments", Style.AlignTrailingComments);
1160 IO.mapOptional(
"AllowAllArgumentsOnNextLine",
1161 Style.AllowAllArgumentsOnNextLine);
1162 IO.mapOptional(
"AllowAllParametersOfDeclarationOnNextLine",
1163 Style.AllowAllParametersOfDeclarationOnNextLine);
1164 IO.mapOptional(
"AllowBreakBeforeNoexceptSpecifier",
1165 Style.AllowBreakBeforeNoexceptSpecifier);
1166 IO.mapOptional(
"AllowBreakBeforeQtProperty",
1167 Style.AllowBreakBeforeQtProperty);
1168 IO.mapOptional(
"AllowShortBlocksOnASingleLine",
1169 Style.AllowShortBlocksOnASingleLine);
1170 IO.mapOptional(
"AllowShortCaseExpressionOnASingleLine",
1171 Style.AllowShortCaseExpressionOnASingleLine);
1172 IO.mapOptional(
"AllowShortCaseLabelsOnASingleLine",
1173 Style.AllowShortCaseLabelsOnASingleLine);
1174 IO.mapOptional(
"AllowShortCompoundRequirementOnASingleLine",
1175 Style.AllowShortCompoundRequirementOnASingleLine);
1176 IO.mapOptional(
"AllowShortEnumsOnASingleLine",
1177 Style.AllowShortEnumsOnASingleLine);
1178 IO.mapOptional(
"AllowShortFunctionsOnASingleLine",
1179 Style.AllowShortFunctionsOnASingleLine);
1180 IO.mapOptional(
"AllowShortIfStatementsOnASingleLine",
1181 Style.AllowShortIfStatementsOnASingleLine);
1182 IO.mapOptional(
"AllowShortLambdasOnASingleLine",
1183 Style.AllowShortLambdasOnASingleLine);
1184 IO.mapOptional(
"AllowShortLoopsOnASingleLine",
1185 Style.AllowShortLoopsOnASingleLine);
1186 IO.mapOptional(
"AllowShortNamespacesOnASingleLine",
1187 Style.AllowShortNamespacesOnASingleLine);
1188 IO.mapOptional(
"AlwaysBreakAfterDefinitionReturnType",
1189 Style.AlwaysBreakAfterDefinitionReturnType);
1190 IO.mapOptional(
"AlwaysBreakBeforeMultilineStrings",
1191 Style.AlwaysBreakBeforeMultilineStrings);
1192 IO.mapOptional(
"AttributeMacros", Style.AttributeMacros);
1193 IO.mapOptional(
"BinPackArguments", Style.BinPackArguments);
1194 IO.mapOptional(
"BinPackLongBracedList", Style.BinPackLongBracedList);
1195 IO.mapOptional(
"BinPackParameters", Style.BinPackParameters);
1196 IO.mapOptional(
"BitFieldColonSpacing", Style.BitFieldColonSpacing);
1197 IO.mapOptional(
"BracedInitializerIndentWidth",
1198 Style.BracedInitializerIndentWidth);
1199 IO.mapOptional(
"BraceWrapping", Style.BraceWrapping);
1200 IO.mapOptional(
"BreakAdjacentStringLiterals",
1201 Style.BreakAdjacentStringLiterals);
1202 IO.mapOptional(
"BreakAfterAttributes", Style.BreakAfterAttributes);
1203 IO.mapOptional(
"BreakAfterJavaFieldAnnotations",
1204 Style.BreakAfterJavaFieldAnnotations);
1205 IO.mapOptional(
"BreakAfterOpenBracketBracedList",
1206 Style.BreakAfterOpenBracketBracedList);
1207 IO.mapOptional(
"BreakAfterOpenBracketFunction",
1208 Style.BreakAfterOpenBracketFunction);
1209 IO.mapOptional(
"BreakAfterOpenBracketIf", Style.BreakAfterOpenBracketIf);
1210 IO.mapOptional(
"BreakAfterOpenBracketLoop",
1211 Style.BreakAfterOpenBracketLoop);
1212 IO.mapOptional(
"BreakAfterOpenBracketSwitch",
1213 Style.BreakAfterOpenBracketSwitch);
1214 IO.mapOptional(
"BreakAfterReturnType", Style.BreakAfterReturnType);
1215 IO.mapOptional(
"BreakArrays", Style.BreakArrays);
1216 IO.mapOptional(
"BreakBeforeBinaryOperators",
1217 Style.BreakBeforeBinaryOperators);
1218 IO.mapOptional(
"BreakBeforeCloseBracketBracedList",
1219 Style.BreakBeforeCloseBracketBracedList);
1220 IO.mapOptional(
"BreakBeforeCloseBracketFunction",
1221 Style.BreakBeforeCloseBracketFunction);
1222 IO.mapOptional(
"BreakBeforeCloseBracketIf",
1223 Style.BreakBeforeCloseBracketIf);
1224 IO.mapOptional(
"BreakBeforeCloseBracketLoop",
1225 Style.BreakBeforeCloseBracketLoop);
1226 IO.mapOptional(
"BreakBeforeCloseBracketSwitch",
1227 Style.BreakBeforeCloseBracketSwitch);
1228 IO.mapOptional(
"BreakBeforeConceptDeclarations",
1229 Style.BreakBeforeConceptDeclarations);
1230 IO.mapOptional(
"BreakBeforeBraces", Style.BreakBeforeBraces);
1231 IO.mapOptional(
"BreakBeforeInlineASMColon",
1232 Style.BreakBeforeInlineASMColon);
1233 IO.mapOptional(
"BreakBeforeTemplateCloser",
1234 Style.BreakBeforeTemplateCloser);
1235 IO.mapOptional(
"BreakBeforeTernaryOperators",
1236 Style.BreakBeforeTernaryOperators);
1237 IO.mapOptional(
"BreakBinaryOperations", Style.BreakBinaryOperations);
1238 IO.mapOptional(
"BreakConstructorInitializers",
1239 Style.BreakConstructorInitializers);
1240 IO.mapOptional(
"BreakFunctionDefinitionParameters",
1241 Style.BreakFunctionDefinitionParameters);
1242 IO.mapOptional(
"BreakInheritanceList", Style.BreakInheritanceList);
1243 IO.mapOptional(
"BreakStringLiterals", Style.BreakStringLiterals);
1244 IO.mapOptional(
"BreakTemplateDeclarations",
1245 Style.BreakTemplateDeclarations);
1246 IO.mapOptional(
"ColumnLimit", Style.ColumnLimit);
1247 IO.mapOptional(
"CommentPragmas", Style.CommentPragmas);
1248 IO.mapOptional(
"CompactNamespaces", Style.CompactNamespaces);
1249 IO.mapOptional(
"ConstructorInitializerIndentWidth",
1250 Style.ConstructorInitializerIndentWidth);
1251 IO.mapOptional(
"ContinuationIndentWidth", Style.ContinuationIndentWidth);
1252 IO.mapOptional(
"Cpp11BracedListStyle", Style.Cpp11BracedListStyle);
1253 IO.mapOptional(
"DerivePointerAlignment", Style.DerivePointerAlignment);
1254 IO.mapOptional(
"DisableFormat", Style.DisableFormat);
1255 IO.mapOptional(
"EmptyLineAfterAccessModifier",
1256 Style.EmptyLineAfterAccessModifier);
1257 IO.mapOptional(
"EmptyLineBeforeAccessModifier",
1258 Style.EmptyLineBeforeAccessModifier);
1259 IO.mapOptional(
"EnumTrailingComma", Style.EnumTrailingComma);
1260 IO.mapOptional(
"ExperimentalAutoDetectBinPacking",
1261 Style.ExperimentalAutoDetectBinPacking);
1262 IO.mapOptional(
"FixNamespaceComments", Style.FixNamespaceComments);
1263 IO.mapOptional(
"ForEachMacros", Style.ForEachMacros);
1264 IO.mapOptional(
"IfMacros", Style.IfMacros);
1265 IO.mapOptional(
"IncludeBlocks", Style.IncludeStyle.IncludeBlocks);
1266 IO.mapOptional(
"IncludeCategories", Style.IncludeStyle.IncludeCategories);
1267 IO.mapOptional(
"IncludeIsMainRegex", Style.IncludeStyle.IncludeIsMainRegex);
1268 IO.mapOptional(
"IncludeIsMainSourceRegex",
1269 Style.IncludeStyle.IncludeIsMainSourceRegex);
1270 IO.mapOptional(
"IndentAccessModifiers", Style.IndentAccessModifiers);
1271 IO.mapOptional(
"IndentCaseBlocks", Style.IndentCaseBlocks);
1272 IO.mapOptional(
"IndentCaseLabels", Style.IndentCaseLabels);
1273 IO.mapOptional(
"IndentExportBlock", Style.IndentExportBlock);
1274 IO.mapOptional(
"IndentExternBlock", Style.IndentExternBlock);
1275 IO.mapOptional(
"IndentGotoLabels", Style.IndentGotoLabels);
1276 IO.mapOptional(
"IndentPPDirectives", Style.IndentPPDirectives);
1277 IO.mapOptional(
"IndentRequiresClause", Style.IndentRequiresClause);
1278 IO.mapOptional(
"IndentWidth", Style.IndentWidth);
1279 IO.mapOptional(
"IndentWrappedFunctionNames",
1280 Style.IndentWrappedFunctionNames);
1281 IO.mapOptional(
"InsertBraces", Style.InsertBraces);
1282 IO.mapOptional(
"InsertNewlineAtEOF", Style.InsertNewlineAtEOF);
1283 IO.mapOptional(
"InsertTrailingCommas", Style.InsertTrailingCommas);
1284 IO.mapOptional(
"IntegerLiteralSeparator", Style.IntegerLiteralSeparator);
1285 IO.mapOptional(
"JavaImportGroups", Style.JavaImportGroups);
1286 IO.mapOptional(
"JavaScriptQuotes", Style.JavaScriptQuotes);
1287 IO.mapOptional(
"JavaScriptWrapImports", Style.JavaScriptWrapImports);
1288 IO.mapOptional(
"KeepEmptyLines", Style.KeepEmptyLines);
1289 IO.mapOptional(
"KeepFormFeed", Style.KeepFormFeed);
1290 IO.mapOptional(
"LambdaBodyIndentation", Style.LambdaBodyIndentation);
1291 IO.mapOptional(
"LineEnding", Style.LineEnding);
1292 IO.mapOptional(
"MacroBlockBegin", Style.MacroBlockBegin);
1293 IO.mapOptional(
"MacroBlockEnd", Style.MacroBlockEnd);
1294 IO.mapOptional(
"Macros", Style.Macros);
1295 IO.mapOptional(
"MacrosSkippedByRemoveParentheses",
1296 Style.MacrosSkippedByRemoveParentheses);
1297 IO.mapOptional(
"MainIncludeChar", Style.IncludeStyle.MainIncludeChar);
1298 IO.mapOptional(
"MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
1299 IO.mapOptional(
"NamespaceIndentation", Style.NamespaceIndentation);
1300 IO.mapOptional(
"NamespaceMacros", Style.NamespaceMacros);
1301 IO.mapOptional(
"NumericLiteralCase", Style.NumericLiteralCase);
1302 IO.mapOptional(
"ObjCBinPackProtocolList", Style.ObjCBinPackProtocolList);
1303 IO.mapOptional(
"ObjCBlockIndentWidth", Style.ObjCBlockIndentWidth);
1304 IO.mapOptional(
"ObjCBreakBeforeNestedBlockParam",
1305 Style.ObjCBreakBeforeNestedBlockParam);
1306 IO.mapOptional(
"ObjCPropertyAttributeOrder",
1307 Style.ObjCPropertyAttributeOrder);
1308 IO.mapOptional(
"ObjCSpaceAfterMethodDeclarationPrefix",
1309 Style.ObjCSpaceAfterMethodDeclarationPrefix);
1310 IO.mapOptional(
"ObjCSpaceAfterProperty", Style.ObjCSpaceAfterProperty);
1311 IO.mapOptional(
"ObjCSpaceBeforeProtocolList",
1312 Style.ObjCSpaceBeforeProtocolList);
1313 IO.mapOptional(
"OneLineFormatOffRegex", Style.OneLineFormatOffRegex);
1314 IO.mapOptional(
"PackConstructorInitializers",
1315 Style.PackConstructorInitializers);
1316 IO.mapOptional(
"PenaltyBreakAssignment", Style.PenaltyBreakAssignment);
1317 IO.mapOptional(
"PenaltyBreakBeforeFirstCallParameter",
1318 Style.PenaltyBreakBeforeFirstCallParameter);
1319 IO.mapOptional(
"PenaltyBreakBeforeMemberAccess",
1320 Style.PenaltyBreakBeforeMemberAccess);
1321 IO.mapOptional(
"PenaltyBreakComment", Style.PenaltyBreakComment);
1322 IO.mapOptional(
"PenaltyBreakFirstLessLess",
1323 Style.PenaltyBreakFirstLessLess);
1324 IO.mapOptional(
"PenaltyBreakOpenParenthesis",
1325 Style.PenaltyBreakOpenParenthesis);
1326 IO.mapOptional(
"PenaltyBreakScopeResolution",
1327 Style.PenaltyBreakScopeResolution);
1328 IO.mapOptional(
"PenaltyBreakString", Style.PenaltyBreakString);
1329 IO.mapOptional(
"PenaltyBreakTemplateDeclaration",
1330 Style.PenaltyBreakTemplateDeclaration);
1331 IO.mapOptional(
"PenaltyExcessCharacter", Style.PenaltyExcessCharacter);
1332 IO.mapOptional(
"PenaltyIndentedWhitespace",
1333 Style.PenaltyIndentedWhitespace);
1334 IO.mapOptional(
"PenaltyReturnTypeOnItsOwnLine",
1335 Style.PenaltyReturnTypeOnItsOwnLine);
1336 IO.mapOptional(
"PointerAlignment", Style.PointerAlignment);
1337 IO.mapOptional(
"PPIndentWidth", Style.PPIndentWidth);
1338 IO.mapOptional(
"QualifierAlignment", Style.QualifierAlignment);
1340 if (Style.QualifierAlignment == FormatStyle::QAS_Right)
1341 Style.QualifierOrder = {
"type",
"const",
"volatile"};
1342 else if (Style.QualifierAlignment == FormatStyle::QAS_Left)
1343 Style.QualifierOrder = {
"const",
"volatile",
"type"};
1344 else if (Style.QualifierAlignment == FormatStyle::QAS_Custom)
1345 IO.mapOptional(
"QualifierOrder", Style.QualifierOrder);
1346 IO.mapOptional(
"RawStringFormats", Style.RawStringFormats);
1347 IO.mapOptional(
"ReferenceAlignment", Style.ReferenceAlignment);
1348 IO.mapOptional(
"ReflowComments", Style.ReflowComments);
1349 IO.mapOptional(
"RemoveBracesLLVM", Style.RemoveBracesLLVM);
1350 IO.mapOptional(
"RemoveEmptyLinesInUnwrappedLines",
1351 Style.RemoveEmptyLinesInUnwrappedLines);
1352 IO.mapOptional(
"RemoveParentheses", Style.RemoveParentheses);
1353 IO.mapOptional(
"RemoveSemicolon", Style.RemoveSemicolon);
1354 IO.mapOptional(
"RequiresClausePosition", Style.RequiresClausePosition);
1355 IO.mapOptional(
"RequiresExpressionIndentation",
1356 Style.RequiresExpressionIndentation);
1357 IO.mapOptional(
"SeparateDefinitionBlocks", Style.SeparateDefinitionBlocks);
1358 IO.mapOptional(
"ShortNamespaceLines", Style.ShortNamespaceLines);
1359 IO.mapOptional(
"SkipMacroDefinitionBody", Style.SkipMacroDefinitionBody);
1360 IO.mapOptional(
"SortIncludes", Style.SortIncludes);
1361 IO.mapOptional(
"SortJavaStaticImport", Style.SortJavaStaticImport);
1362 IO.mapOptional(
"SortUsingDeclarations", Style.SortUsingDeclarations);
1363 IO.mapOptional(
"SpaceAfterCStyleCast", Style.SpaceAfterCStyleCast);
1364 IO.mapOptional(
"SpaceAfterLogicalNot", Style.SpaceAfterLogicalNot);
1365 IO.mapOptional(
"SpaceAfterOperatorKeyword",
1366 Style.SpaceAfterOperatorKeyword);
1367 IO.mapOptional(
"SpaceAfterTemplateKeyword",
1368 Style.SpaceAfterTemplateKeyword);
1369 IO.mapOptional(
"SpaceAroundPointerQualifiers",
1370 Style.SpaceAroundPointerQualifiers);
1371 IO.mapOptional(
"SpaceBeforeAssignmentOperators",
1372 Style.SpaceBeforeAssignmentOperators);
1373 IO.mapOptional(
"SpaceBeforeCaseColon", Style.SpaceBeforeCaseColon);
1374 IO.mapOptional(
"SpaceBeforeCpp11BracedList",
1375 Style.SpaceBeforeCpp11BracedList);
1376 IO.mapOptional(
"SpaceBeforeCtorInitializerColon",
1377 Style.SpaceBeforeCtorInitializerColon);
1378 IO.mapOptional(
"SpaceBeforeInheritanceColon",
1379 Style.SpaceBeforeInheritanceColon);
1380 IO.mapOptional(
"SpaceBeforeJsonColon", Style.SpaceBeforeJsonColon);
1381 IO.mapOptional(
"SpaceBeforeParens", Style.SpaceBeforeParens);
1382 IO.mapOptional(
"SpaceBeforeParensOptions", Style.SpaceBeforeParensOptions);
1383 IO.mapOptional(
"SpaceBeforeRangeBasedForLoopColon",
1384 Style.SpaceBeforeRangeBasedForLoopColon);
1385 IO.mapOptional(
"SpaceBeforeSquareBrackets",
1386 Style.SpaceBeforeSquareBrackets);
1387 IO.mapOptional(
"SpaceInEmptyBraces", Style.SpaceInEmptyBraces);
1388 IO.mapOptional(
"SpacesBeforeTrailingComments",
1389 Style.SpacesBeforeTrailingComments);
1390 IO.mapOptional(
"SpacesInAngles", Style.SpacesInAngles);
1391 IO.mapOptional(
"SpacesInContainerLiterals",
1392 Style.SpacesInContainerLiterals);
1393 IO.mapOptional(
"SpacesInLineCommentPrefix",
1394 Style.SpacesInLineCommentPrefix);
1395 IO.mapOptional(
"SpacesInParens", Style.SpacesInParens);
1396 IO.mapOptional(
"SpacesInParensOptions", Style.SpacesInParensOptions);
1397 IO.mapOptional(
"SpacesInSquareBrackets", Style.SpacesInSquareBrackets);
1398 IO.mapOptional(
"Standard", Style.Standard);
1399 IO.mapOptional(
"StatementAttributeLikeMacros",
1400 Style.StatementAttributeLikeMacros);
1401 IO.mapOptional(
"StatementMacros", Style.StatementMacros);
1402 IO.mapOptional(
"TableGenBreakingDAGArgOperators",
1403 Style.TableGenBreakingDAGArgOperators);
1404 IO.mapOptional(
"TableGenBreakInsideDAGArg",
1405 Style.TableGenBreakInsideDAGArg);
1406 IO.mapOptional(
"TabWidth", Style.TabWidth);
1407 IO.mapOptional(
"TemplateNames", Style.TemplateNames);
1408 IO.mapOptional(
"TypeNames", Style.TypeNames);
1409 IO.mapOptional(
"TypenameMacros", Style.TypenameMacros);
1410 IO.mapOptional(
"UseTab", Style.UseTab);
1411 IO.mapOptional(
"VariableTemplates", Style.VariableTemplates);
1412 IO.mapOptional(
"VerilogBreakBetweenInstancePorts",
1413 Style.VerilogBreakBetweenInstancePorts);
1414 IO.mapOptional(
"WhitespaceSensitiveMacros",
1415 Style.WhitespaceSensitiveMacros);
1416 IO.mapOptional(
"WrapNamespaceBodyWithEmptyLines",
1417 Style.WrapNamespaceBodyWithEmptyLines);
1422 if (Style.AlwaysBreakAfterDefinitionReturnType != FormatStyle::DRTBS_None &&
1423 Style.BreakAfterReturnType == FormatStyle::RTBS_None) {
1424 if (Style.AlwaysBreakAfterDefinitionReturnType ==
1425 FormatStyle::DRTBS_All) {
1426 Style.BreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
1427 }
else if (Style.AlwaysBreakAfterDefinitionReturnType ==
1428 FormatStyle::DRTBS_TopLevel) {
1429 Style.BreakAfterReturnType = FormatStyle::RTBS_TopLevelDefinitions;
1435 if (BreakBeforeInheritanceComma &&
1436 Style.BreakInheritanceList == FormatStyle::BILS_BeforeColon) {
1437 Style.BreakInheritanceList = FormatStyle::BILS_BeforeComma;
1443 if (BreakConstructorInitializersBeforeComma &&
1444 Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeColon) {
1445 Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;
1448 if (!IsGoogleOrChromium) {
1449 if (Style.PackConstructorInitializers == FormatStyle::PCIS_BinPack &&
1451 Style.PackConstructorInitializers = OnNextLine
1452 ? FormatStyle::PCIS_NextLine
1453 : FormatStyle::PCIS_CurrentLine;
1455 }
else if (Style.PackConstructorInitializers ==
1456 FormatStyle::PCIS_NextLine) {
1458 Style.PackConstructorInitializers = FormatStyle::PCIS_BinPack;
1459 else if (!OnNextLine)
1460 Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
1463 if (Style.LineEnding == FormatStyle::LE_DeriveLF) {
1464 if (!DeriveLineEnding)
1465 Style.LineEnding = UseCRLF ? FormatStyle::LE_CRLF : FormatStyle::LE_LF;
1467 Style.LineEnding = FormatStyle::LE_DeriveCRLF;
1472 if (SpaceInEmptyBlock &&
1473 Style.SpaceInEmptyBraces == FormatStyle::SIEB_Never) {
1474 Style.SpaceInEmptyBraces = FormatStyle::SIEB_Block;
1477 if (Style.SpacesInParens != FormatStyle::SIPO_Custom &&
1478 (SpacesInParentheses || SpaceInEmptyParentheses ||
1479 SpacesInConditionalStatement || SpacesInCStyleCastParentheses)) {
1480 if (SpacesInParentheses) {
1482 Style.SpacesInParensOptions.ExceptDoubleParentheses =
false;
1483 Style.SpacesInParensOptions.InConditionalStatements =
true;
1484 Style.SpacesInParensOptions.InCStyleCasts =
1485 SpacesInCStyleCastParentheses;
1486 Style.SpacesInParensOptions.InEmptyParentheses =
1487 SpaceInEmptyParentheses;
1488 Style.SpacesInParensOptions.Other =
true;
1490 Style.SpacesInParensOptions = {};
1491 Style.SpacesInParensOptions.InConditionalStatements =
1492 SpacesInConditionalStatement;
1493 Style.SpacesInParensOptions.InCStyleCasts =
1494 SpacesInCStyleCastParentheses;
1495 Style.SpacesInParensOptions.InEmptyParentheses =
1496 SpaceInEmptyParentheses;
1498 Style.SpacesInParens = FormatStyle::SIPO_Custom;
1508template <>
struct DocumentListTraits<
std::vector<FormatStyle>> {
1509 static size_t size(IO &IO, std::vector<FormatStyle> &Seq) {
1512 static FormatStyle &
element(IO &IO, std::vector<FormatStyle> &Seq,
1514 if (Index >= Seq.size()) {
1515 assert(Index == Seq.size());
1516 FormatStyle Template;
1517 if (!Seq.empty() && Seq[0].Language == FormatStyle::LK_None) {
1520 Template = *((
const FormatStyle *)IO.getContext());
1521 Template.Language = FormatStyle::LK_None;
1523 Seq.resize(Index + 1, Template);
1529template <>
struct ScalarEnumerationTraits<FormatStyle::IndentGotoLabelStyle> {
1531 IO.enumCase(
Value,
"NoIndent", FormatStyle::IGLS_NoIndent);
1532 IO.enumCase(
Value,
"OuterIndent", FormatStyle::IGLS_OuterIndent);
1533 IO.enumCase(
Value,
"InnerIndent", FormatStyle::IGLS_InnerIndent);
1534 IO.enumCase(
Value,
"HalfIndent", FormatStyle::IGLS_HalfIndent);
1537 IO.enumCase(
Value,
"false", FormatStyle::IGLS_NoIndent);
1538 IO.enumCase(
Value,
"true", FormatStyle::IGLS_OuterIndent);
1557 return llvm::make_error<llvm::StringError>(Message,
1558 llvm::inconvertibleErrorCode());
1562 return "clang-format.parse_error";
1570 return "Invalid argument";
1572 return "Unsuitable";
1574 return "trailing comma insertion cannot be used with bin packing";
1576 return "Invalid qualifier specified in QualifierOrder";
1578 return "Duplicate qualifier specified in QualifierOrder";
1580 return "Missing type in QualifierOrder";
1582 return "Missing QualifierOrder";
1584 llvm_unreachable(
"unexpected parse error");
1588 if (Expanded.BreakBeforeBraces == FormatStyle::BS_Custom)
1590 Expanded.BraceWrapping = {
false,
1592 FormatStyle::BWACS_Never,
1608 switch (Expanded.BreakBeforeBraces) {
1609 case FormatStyle::BS_Linux:
1610 Expanded.BraceWrapping.AfterClass =
true;
1611 Expanded.BraceWrapping.AfterFunction =
true;
1612 Expanded.BraceWrapping.AfterNamespace =
true;
1614 case FormatStyle::BS_Mozilla:
1615 Expanded.BraceWrapping.AfterClass =
true;
1616 Expanded.BraceWrapping.AfterEnum =
true;
1617 Expanded.BraceWrapping.AfterFunction =
true;
1618 Expanded.BraceWrapping.AfterStruct =
true;
1619 Expanded.BraceWrapping.AfterUnion =
true;
1620 Expanded.BraceWrapping.AfterExternBlock =
true;
1621 Expanded.BraceWrapping.SplitEmptyFunction =
true;
1622 Expanded.BraceWrapping.SplitEmptyRecord =
false;
1624 case FormatStyle::BS_Stroustrup:
1625 Expanded.BraceWrapping.AfterFunction =
true;
1626 Expanded.BraceWrapping.BeforeCatch =
true;
1627 Expanded.BraceWrapping.BeforeElse =
true;
1629 case FormatStyle::BS_Allman:
1630 Expanded.BraceWrapping.AfterCaseLabel =
true;
1631 Expanded.BraceWrapping.AfterClass =
true;
1632 Expanded.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_Always;
1633 Expanded.BraceWrapping.AfterEnum =
true;
1634 Expanded.BraceWrapping.AfterFunction =
true;
1635 Expanded.BraceWrapping.AfterNamespace =
true;
1636 Expanded.BraceWrapping.AfterObjCDeclaration =
true;
1637 Expanded.BraceWrapping.AfterStruct =
true;
1638 Expanded.BraceWrapping.AfterUnion =
true;
1639 Expanded.BraceWrapping.AfterExternBlock =
true;
1640 Expanded.BraceWrapping.BeforeCatch =
true;
1641 Expanded.BraceWrapping.BeforeElse =
true;
1642 Expanded.BraceWrapping.BeforeLambdaBody =
true;
1644 case FormatStyle::BS_Whitesmiths:
1645 Expanded.BraceWrapping.AfterCaseLabel =
true;
1646 Expanded.BraceWrapping.AfterClass =
true;
1647 Expanded.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_Always;
1648 Expanded.BraceWrapping.AfterEnum =
true;
1649 Expanded.BraceWrapping.AfterFunction =
true;
1650 Expanded.BraceWrapping.AfterNamespace =
true;
1651 Expanded.BraceWrapping.AfterObjCDeclaration =
true;
1652 Expanded.BraceWrapping.AfterStruct =
true;
1653 Expanded.BraceWrapping.AfterExternBlock =
true;
1654 Expanded.BraceWrapping.BeforeCatch =
true;
1655 Expanded.BraceWrapping.BeforeElse =
true;
1656 Expanded.BraceWrapping.BeforeLambdaBody =
true;
1658 case FormatStyle::BS_GNU:
1659 Expanded.BraceWrapping = {
1662 FormatStyle::BWACS_Always,
1679 case FormatStyle::BS_WebKit:
1680 Expanded.BraceWrapping.AfterFunction =
true;
1688 if (Expanded.SpaceBeforeParens == FormatStyle::SBPO_Custom)
1691 Expanded.SpaceBeforeParensOptions = {};
1692 Expanded.SpaceBeforeParensOptions.AfterPlacementOperator =
true;
1694 switch (Expanded.SpaceBeforeParens) {
1695 case FormatStyle::SBPO_ControlStatements:
1696 Expanded.SpaceBeforeParensOptions.AfterControlStatements =
true;
1697 Expanded.SpaceBeforeParensOptions.AfterForeachMacros =
true;
1698 Expanded.SpaceBeforeParensOptions.AfterIfMacros =
true;
1700 case FormatStyle::SBPO_ControlStatementsExceptControlMacros:
1701 Expanded.SpaceBeforeParensOptions.AfterControlStatements =
true;
1703 case FormatStyle::SBPO_NonEmptyParentheses:
1704 Expanded.SpaceBeforeParensOptions.BeforeNonEmptyParentheses =
true;
1712 if (Expanded.SpacesInParens == FormatStyle::SIPO_Custom)
1714 assert(Expanded.SpacesInParens == FormatStyle::SIPO_Never);
1716 Expanded.SpacesInParensOptions = {};
1720 FormatStyle LLVMStyle;
1721 LLVMStyle.AccessModifierOffset = -2;
1722 LLVMStyle.AlignAfterOpenBracket =
true;
1723 LLVMStyle.AlignArrayOfStructures = FormatStyle::AIAS_None;
1724 LLVMStyle.AlignConsecutiveAssignments = {};
1725 LLVMStyle.AlignConsecutiveAssignments.PadOperators =
true;
1726 LLVMStyle.AlignConsecutiveBitFields = {};
1727 LLVMStyle.AlignConsecutiveDeclarations = {};
1728 LLVMStyle.AlignConsecutiveDeclarations.AlignFunctionDeclarations =
true;
1729 LLVMStyle.AlignConsecutiveMacros = {};
1730 LLVMStyle.AlignConsecutiveShortCaseStatements = {};
1731 LLVMStyle.AlignConsecutiveTableGenBreakingDAGArgColons = {};
1732 LLVMStyle.AlignConsecutiveTableGenCondOperatorColons = {};
1733 LLVMStyle.AlignConsecutiveTableGenDefinitionColons = {};
1734 LLVMStyle.AlignEscapedNewlines = FormatStyle::ENAS_Right;
1735 LLVMStyle.AlignOperands = FormatStyle::OAS_Align;
1736 LLVMStyle.AlignTrailingComments = {};
1737 LLVMStyle.AlignTrailingComments.Kind = FormatStyle::TCAS_Always;
1738 LLVMStyle.AlignTrailingComments.OverEmptyLines = 0;
1739 LLVMStyle.AlignTrailingComments.AlignPPAndNotPP =
true;
1740 LLVMStyle.AllowAllArgumentsOnNextLine =
true;
1741 LLVMStyle.AllowAllParametersOfDeclarationOnNextLine =
true;
1742 LLVMStyle.AllowBreakBeforeNoexceptSpecifier = FormatStyle::BBNSS_Never;
1743 LLVMStyle.AllowBreakBeforeQtProperty =
false;
1744 LLVMStyle.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Never;
1745 LLVMStyle.AllowShortCaseExpressionOnASingleLine =
true;
1746 LLVMStyle.AllowShortCaseLabelsOnASingleLine =
false;
1747 LLVMStyle.AllowShortCompoundRequirementOnASingleLine =
true;
1748 LLVMStyle.AllowShortEnumsOnASingleLine =
true;
1749 LLVMStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All;
1750 LLVMStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
1751 LLVMStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_All;
1752 LLVMStyle.AllowShortLoopsOnASingleLine =
false;
1753 LLVMStyle.AllowShortNamespacesOnASingleLine =
false;
1754 LLVMStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
1755 LLVMStyle.AlwaysBreakBeforeMultilineStrings =
false;
1756 LLVMStyle.AttributeMacros.push_back(
"__capability");
1757 LLVMStyle.BinPackArguments =
true;
1758 LLVMStyle.BinPackLongBracedList =
true;
1759 LLVMStyle.BinPackParameters = FormatStyle::BPPS_BinPack;
1760 LLVMStyle.BitFieldColonSpacing = FormatStyle::BFCS_Both;
1761 LLVMStyle.BracedInitializerIndentWidth = -1;
1762 LLVMStyle.BraceWrapping = {
false,
1764 FormatStyle::BWACS_Never,
1780 LLVMStyle.BreakAdjacentStringLiterals =
true;
1781 LLVMStyle.BreakAfterAttributes = FormatStyle::ABS_Leave;
1782 LLVMStyle.BreakAfterJavaFieldAnnotations =
false;
1783 LLVMStyle.BreakAfterOpenBracketBracedList =
false;
1784 LLVMStyle.BreakAfterOpenBracketFunction =
false;
1785 LLVMStyle.BreakAfterOpenBracketIf =
false;
1786 LLVMStyle.BreakAfterOpenBracketLoop =
false;
1787 LLVMStyle.BreakAfterOpenBracketSwitch =
false;
1788 LLVMStyle.BreakAfterReturnType = FormatStyle::RTBS_None;
1789 LLVMStyle.BreakArrays =
true;
1790 LLVMStyle.BreakBeforeBinaryOperators = FormatStyle::BOS_None;
1791 LLVMStyle.BreakBeforeBraces = FormatStyle::BS_Attach;
1792 LLVMStyle.BreakBeforeCloseBracketBracedList =
false;
1793 LLVMStyle.BreakBeforeCloseBracketFunction =
false;
1794 LLVMStyle.BreakBeforeCloseBracketIf =
false;
1795 LLVMStyle.BreakBeforeCloseBracketLoop =
false;
1796 LLVMStyle.BreakBeforeCloseBracketSwitch =
false;
1797 LLVMStyle.BreakBeforeConceptDeclarations = FormatStyle::BBCDS_Always;
1798 LLVMStyle.BreakBeforeInlineASMColon = FormatStyle::BBIAS_OnlyMultiline;
1799 LLVMStyle.BreakBeforeTemplateCloser =
false;
1800 LLVMStyle.BreakBeforeTernaryOperators =
true;
1801 LLVMStyle.BreakBinaryOperations = {FormatStyle::BBO_Never, {}};
1802 LLVMStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon;
1803 LLVMStyle.BreakFunctionDefinitionParameters =
false;
1804 LLVMStyle.BreakInheritanceList = FormatStyle::BILS_BeforeColon;
1805 LLVMStyle.BreakStringLiterals =
true;
1806 LLVMStyle.BreakTemplateDeclarations = FormatStyle::BTDS_MultiLine;
1807 LLVMStyle.ColumnLimit = 80;
1808 LLVMStyle.CommentPragmas =
"^ IWYU pragma:";
1809 LLVMStyle.CompactNamespaces =
false;
1810 LLVMStyle.ConstructorInitializerIndentWidth = 4;
1811 LLVMStyle.ContinuationIndentWidth = 4;
1812 LLVMStyle.Cpp11BracedListStyle = FormatStyle::BLS_AlignFirstComment;
1813 LLVMStyle.DerivePointerAlignment =
false;
1814 LLVMStyle.DisableFormat =
false;
1815 LLVMStyle.EmptyLineAfterAccessModifier = FormatStyle::ELAAMS_Never;
1816 LLVMStyle.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_LogicalBlock;
1817 LLVMStyle.EnumTrailingComma = FormatStyle::ETC_Leave;
1818 LLVMStyle.ExperimentalAutoDetectBinPacking =
false;
1819 LLVMStyle.FixNamespaceComments =
true;
1820 LLVMStyle.ForEachMacros.push_back(
"foreach");
1821 LLVMStyle.ForEachMacros.push_back(
"Q_FOREACH");
1822 LLVMStyle.ForEachMacros.push_back(
"BOOST_FOREACH");
1823 LLVMStyle.IfMacros.push_back(
"KJ_IF_MAYBE");
1825 LLVMStyle.IncludeStyle.IncludeCategories = {
1826 {
"^\"(llvm|llvm-c|clang|clang-c)/", 2, 0,
false},
1827 {
"^(<|\"(gtest|gmock|isl|json)/)", 3, 0,
false},
1828 {
".*", 1, 0,
false}};
1829 LLVMStyle.IncludeStyle.IncludeIsMainRegex =
"(Test)?$";
1830 LLVMStyle.IncludeStyle.MainIncludeChar = tooling::IncludeStyle::MICD_Quote;
1831 LLVMStyle.IndentAccessModifiers =
false;
1832 LLVMStyle.IndentCaseBlocks =
false;
1833 LLVMStyle.IndentCaseLabels =
false;
1834 LLVMStyle.IndentExportBlock =
true;
1835 LLVMStyle.IndentExternBlock = FormatStyle::IEBS_AfterExternBlock;
1836 LLVMStyle.IndentGotoLabels = FormatStyle::IGLS_OuterIndent;
1837 LLVMStyle.IndentPPDirectives = FormatStyle::PPDIS_None;
1838 LLVMStyle.IndentRequiresClause =
true;
1839 LLVMStyle.IndentWidth = 2;
1840 LLVMStyle.IndentWrappedFunctionNames =
false;
1841 LLVMStyle.InsertBraces =
false;
1842 LLVMStyle.InsertNewlineAtEOF =
false;
1843 LLVMStyle.InsertTrailingCommas = FormatStyle::TCS_None;
1844 LLVMStyle.IntegerLiteralSeparator = {};
1845 LLVMStyle.JavaScriptQuotes = FormatStyle::JSQS_Leave;
1846 LLVMStyle.JavaScriptWrapImports =
true;
1847 LLVMStyle.KeepEmptyLines = {
1852 LLVMStyle.KeepFormFeed =
false;
1853 LLVMStyle.LambdaBodyIndentation = FormatStyle::LBI_Signature;
1855 LLVMStyle.LineEnding = FormatStyle::LE_DeriveLF;
1856 LLVMStyle.MaxEmptyLinesToKeep = 1;
1857 LLVMStyle.NamespaceIndentation = FormatStyle::NI_None;
1858 LLVMStyle.NumericLiteralCase = {FormatStyle::NLCS_Leave,
1859 FormatStyle::NLCS_Leave,
1860 FormatStyle::NLCS_Leave,
1861 FormatStyle::NLCS_Leave};
1862 LLVMStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Auto;
1863 LLVMStyle.ObjCBlockIndentWidth = 2;
1864 LLVMStyle.ObjCBreakBeforeNestedBlockParam =
true;
1865 LLVMStyle.ObjCSpaceAfterMethodDeclarationPrefix =
true;
1866 LLVMStyle.ObjCSpaceAfterProperty =
false;
1867 LLVMStyle.ObjCSpaceBeforeProtocolList =
true;
1868 LLVMStyle.PackConstructorInitializers = FormatStyle::PCIS_BinPack;
1869 LLVMStyle.PointerAlignment = FormatStyle::PAS_Right;
1870 LLVMStyle.PPIndentWidth = -1;
1871 LLVMStyle.QualifierAlignment = FormatStyle::QAS_Leave;
1872 LLVMStyle.ReferenceAlignment = FormatStyle::RAS_Pointer;
1873 LLVMStyle.ReflowComments = FormatStyle::RCS_Always;
1874 LLVMStyle.RemoveBracesLLVM =
false;
1875 LLVMStyle.RemoveEmptyLinesInUnwrappedLines =
false;
1876 LLVMStyle.RemoveParentheses = FormatStyle::RPS_Leave;
1877 LLVMStyle.RemoveSemicolon =
false;
1878 LLVMStyle.RequiresClausePosition = FormatStyle::RCPS_OwnLine;
1879 LLVMStyle.RequiresExpressionIndentation = FormatStyle::REI_OuterScope;
1880 LLVMStyle.SeparateDefinitionBlocks = FormatStyle::SDS_Leave;
1881 LLVMStyle.ShortNamespaceLines = 1;
1882 LLVMStyle.SkipMacroDefinitionBody =
false;
1883 LLVMStyle.SortIncludes = {
true,
false,
1885 LLVMStyle.SortJavaStaticImport = FormatStyle::SJSIO_Before;
1886 LLVMStyle.SortUsingDeclarations = FormatStyle::SUD_LexicographicNumeric;
1887 LLVMStyle.SpaceAfterCStyleCast =
false;
1888 LLVMStyle.SpaceAfterLogicalNot =
false;
1889 LLVMStyle.SpaceAfterOperatorKeyword =
false;
1890 LLVMStyle.SpaceAfterTemplateKeyword =
true;
1891 LLVMStyle.SpaceAroundPointerQualifiers = FormatStyle::SAPQ_Default;
1892 LLVMStyle.SpaceBeforeAssignmentOperators =
true;
1893 LLVMStyle.SpaceBeforeCaseColon =
false;
1894 LLVMStyle.SpaceBeforeCpp11BracedList =
false;
1895 LLVMStyle.SpaceBeforeCtorInitializerColon =
true;
1896 LLVMStyle.SpaceBeforeInheritanceColon =
true;
1897 LLVMStyle.SpaceBeforeJsonColon =
false;
1898 LLVMStyle.SpaceBeforeParens = FormatStyle::SBPO_ControlStatements;
1899 LLVMStyle.SpaceBeforeParensOptions = {};
1900 LLVMStyle.SpaceBeforeParensOptions.AfterControlStatements =
true;
1901 LLVMStyle.SpaceBeforeParensOptions.AfterForeachMacros =
true;
1902 LLVMStyle.SpaceBeforeParensOptions.AfterIfMacros =
true;
1903 LLVMStyle.SpaceBeforeRangeBasedForLoopColon =
true;
1904 LLVMStyle.SpaceBeforeSquareBrackets =
false;
1905 LLVMStyle.SpaceInEmptyBraces = FormatStyle::SIEB_Never;
1906 LLVMStyle.SpacesBeforeTrailingComments = 1;
1907 LLVMStyle.SpacesInAngles = FormatStyle::SIAS_Never;
1908 LLVMStyle.SpacesInContainerLiterals =
true;
1909 LLVMStyle.SpacesInLineCommentPrefix = {
1910 1, std::numeric_limits<unsigned>::max()};
1911 LLVMStyle.SpacesInParens = FormatStyle::SIPO_Never;
1912 LLVMStyle.SpacesInSquareBrackets =
false;
1913 LLVMStyle.Standard = FormatStyle::LS_Latest;
1914 LLVMStyle.StatementAttributeLikeMacros.push_back(
"Q_EMIT");
1915 LLVMStyle.StatementMacros.push_back(
"Q_UNUSED");
1916 LLVMStyle.StatementMacros.push_back(
"QT_REQUIRE_VERSION");
1917 LLVMStyle.TableGenBreakingDAGArgOperators = {};
1918 LLVMStyle.TableGenBreakInsideDAGArg = FormatStyle::DAS_DontBreak;
1919 LLVMStyle.TabWidth = 8;
1920 LLVMStyle.UseTab = FormatStyle::UT_Never;
1921 LLVMStyle.VerilogBreakBetweenInstancePorts =
true;
1922 LLVMStyle.WhitespaceSensitiveMacros.push_back(
"BOOST_PP_STRINGIZE");
1923 LLVMStyle.WhitespaceSensitiveMacros.push_back(
"CF_SWIFT_NAME");
1924 LLVMStyle.WhitespaceSensitiveMacros.push_back(
"NS_SWIFT_NAME");
1925 LLVMStyle.WhitespaceSensitiveMacros.push_back(
"PP_STRINGIZE");
1926 LLVMStyle.WhitespaceSensitiveMacros.push_back(
"STRINGIZE");
1927 LLVMStyle.WrapNamespaceBodyWithEmptyLines = FormatStyle::WNBWELS_Leave;
1930 LLVMStyle.PenaltyBreakBeforeFirstCallParameter = 19;
1931 LLVMStyle.PenaltyBreakBeforeMemberAccess = 150;
1932 LLVMStyle.PenaltyBreakComment = 300;
1933 LLVMStyle.PenaltyBreakFirstLessLess = 120;
1934 LLVMStyle.PenaltyBreakOpenParenthesis = 0;
1935 LLVMStyle.PenaltyBreakScopeResolution = 500;
1936 LLVMStyle.PenaltyBreakString = 1000;
1938 LLVMStyle.PenaltyExcessCharacter = 1'000'000;
1939 LLVMStyle.PenaltyIndentedWhitespace = 0;
1940 LLVMStyle.PenaltyReturnTypeOnItsOwnLine = 60;
1944 case FormatStyle::LK_TableGen:
1945 LLVMStyle.SpacesInContainerLiterals =
false;
1947 case FormatStyle::LK_Json:
1948 LLVMStyle.ColumnLimit = 0;
1950 case FormatStyle::LK_Verilog:
1951 LLVMStyle.IndentCaseLabels =
true;
1952 LLVMStyle.SpacesInContainerLiterals =
false;
1962 if (
Language == FormatStyle::LK_TextProto) {
1964 GoogleStyle.Language = FormatStyle::LK_TextProto;
1971 GoogleStyle.AccessModifierOffset = -1;
1972 GoogleStyle.AlignEscapedNewlines = FormatStyle::ENAS_Left;
1973 GoogleStyle.AllowShortIfStatementsOnASingleLine =
1974 FormatStyle::SIS_WithoutElse;
1975 GoogleStyle.AllowShortLoopsOnASingleLine =
true;
1976 GoogleStyle.AlwaysBreakBeforeMultilineStrings =
true;
1978 GoogleStyle.AttributeMacros.push_back(
"absl_nonnull");
1979 GoogleStyle.AttributeMacros.push_back(
"absl_nullable");
1980 GoogleStyle.AttributeMacros.push_back(
"absl_nullability_unknown");
1981 GoogleStyle.BreakTemplateDeclarations = FormatStyle::BTDS_Yes;
1983 GoogleStyle.IncludeStyle.IncludeCategories = {{
"^<ext/.*\\.h>", 2, 0,
false},
1984 {
"^<.*\\.h>", 1, 0,
false},
1985 {
"^<.*", 2, 0,
false},
1986 {
".*", 3, 0,
false}};
1987 GoogleStyle.IncludeStyle.IncludeIsMainRegex =
"([-_](test|unittest))?$";
1988 GoogleStyle.IndentCaseLabels =
true;
1989 GoogleStyle.KeepEmptyLines.AtStartOfBlock =
false;
1991 GoogleStyle.Macros.push_back(
"ASSIGN_OR_RETURN(a, b)=a = (b)");
1992 GoogleStyle.Macros.push_back(
1993 "ASSIGN_OR_RETURN(a, b, c)=a = (b); if (x) return c");
1995 GoogleStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Never;
1996 GoogleStyle.ObjCSpaceAfterProperty =
false;
1997 GoogleStyle.ObjCSpaceBeforeProtocolList =
true;
1998 GoogleStyle.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
1999 GoogleStyle.PointerAlignment = FormatStyle::PAS_Left;
2000 GoogleStyle.RawStringFormats = {
2002 FormatStyle::LK_Cpp,
2019 FormatStyle::LK_TextProto,
2031 "PARSE_PARTIAL_TEXT_PROTO",
2035 "ParseTextProtoOrDie",
2037 "ParsePartialTestProto",
2044 GoogleStyle.SpacesBeforeTrailingComments = 2;
2045 GoogleStyle.Standard = FormatStyle::LS_Auto;
2047 GoogleStyle.PenaltyBreakBeforeFirstCallParameter = 1;
2048 GoogleStyle.PenaltyReturnTypeOnItsOwnLine = 200;
2050 if (
Language == FormatStyle::LK_Java) {
2051 GoogleStyle.AlignAfterOpenBracket =
false;
2052 GoogleStyle.AlignOperands = FormatStyle::OAS_DontAlign;
2053 GoogleStyle.AlignTrailingComments = {};
2054 GoogleStyle.AlignTrailingComments.Kind = FormatStyle::TCAS_Never;
2055 GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty;
2056 GoogleStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
2057 GoogleStyle.AlwaysBreakBeforeMultilineStrings =
false;
2058 GoogleStyle.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment;
2059 GoogleStyle.ColumnLimit = 100;
2060 GoogleStyle.SpaceAfterCStyleCast =
true;
2061 GoogleStyle.SpacesBeforeTrailingComments = 1;
2062 }
else if (
Language == FormatStyle::LK_JavaScript) {
2063 GoogleStyle.BreakAfterOpenBracketBracedList =
true;
2064 GoogleStyle.BreakAfterOpenBracketFunction =
true;
2065 GoogleStyle.BreakAfterOpenBracketIf =
true;
2066 GoogleStyle.AlignOperands = FormatStyle::OAS_DontAlign;
2067 GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty;
2069 GoogleStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_Empty;
2070 GoogleStyle.AlwaysBreakBeforeMultilineStrings =
false;
2071 GoogleStyle.BreakBeforeTernaryOperators =
false;
2074 GoogleStyle.CommentPragmas =
"(taze:|^/[ \t]*<|tslint:|@see)";
2078 GoogleStyle.JavaScriptQuotes = FormatStyle::JSQS_Single;
2079 GoogleStyle.JavaScriptWrapImports =
false;
2080 GoogleStyle.MaxEmptyLinesToKeep = 3;
2081 GoogleStyle.NamespaceIndentation = FormatStyle::NI_All;
2082 GoogleStyle.SpacesInContainerLiterals =
false;
2083 }
else if (
Language == FormatStyle::LK_Proto) {
2084 GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty;
2085 GoogleStyle.AlwaysBreakBeforeMultilineStrings =
false;
2091 GoogleStyle.BreakStringLiterals =
false;
2092 GoogleStyle.Cpp11BracedListStyle = FormatStyle::BLS_Block;
2093 GoogleStyle.SpacesInContainerLiterals =
false;
2094 }
else if (
Language == FormatStyle::LK_ObjC) {
2095 GoogleStyle.AlwaysBreakBeforeMultilineStrings =
false;
2096 GoogleStyle.ColumnLimit = 100;
2097 GoogleStyle.DerivePointerAlignment =
true;
2101 GoogleStyle.IncludeStyle.IncludeBlocks =
2103 }
else if (
Language == FormatStyle::LK_CSharp) {
2104 GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty;
2105 GoogleStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
2106 GoogleStyle.BreakStringLiterals =
false;
2107 GoogleStyle.ColumnLimit = 100;
2108 GoogleStyle.NamespaceIndentation = FormatStyle::NI_All;
2134 ChromiumStyle.IncludeStyle.IncludeBlocks =
2137 if (
Language == FormatStyle::LK_Java) {
2138 ChromiumStyle.AllowShortIfStatementsOnASingleLine =
2139 FormatStyle::SIS_WithoutElse;
2140 ChromiumStyle.BreakAfterJavaFieldAnnotations =
true;
2141 ChromiumStyle.ContinuationIndentWidth = 8;
2142 ChromiumStyle.IndentWidth = 4;
2145 ChromiumStyle.JavaImportGroups = {
2152 "com.google.android.apps.chrome",
2157 }
else if (
Language == FormatStyle::LK_JavaScript) {
2158 ChromiumStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
2159 ChromiumStyle.AllowShortLoopsOnASingleLine =
false;
2161 ChromiumStyle.AllowAllParametersOfDeclarationOnNextLine =
false;
2162 ChromiumStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline;
2163 ChromiumStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
2164 ChromiumStyle.AllowShortLoopsOnASingleLine =
false;
2165 ChromiumStyle.BinPackParameters = FormatStyle::BPPS_OnePerLine;
2166 ChromiumStyle.DerivePointerAlignment =
false;
2167 if (
Language == FormatStyle::LK_ObjC)
2168 ChromiumStyle.ColumnLimit = 80;
2170 return ChromiumStyle;
2175 MozillaStyle.AllowAllParametersOfDeclarationOnNextLine =
false;
2176 MozillaStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline;
2177 MozillaStyle.AlwaysBreakAfterDefinitionReturnType =
2178 FormatStyle::DRTBS_TopLevel;
2179 MozillaStyle.BinPackArguments =
false;
2180 MozillaStyle.BinPackParameters = FormatStyle::BPPS_OnePerLine;
2181 MozillaStyle.BreakAfterReturnType = FormatStyle::RTBS_TopLevel;
2182 MozillaStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla;
2183 MozillaStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;
2184 MozillaStyle.BreakInheritanceList = FormatStyle::BILS_BeforeComma;
2185 MozillaStyle.BreakTemplateDeclarations = FormatStyle::BTDS_Yes;
2186 MozillaStyle.ConstructorInitializerIndentWidth = 2;
2187 MozillaStyle.ContinuationIndentWidth = 2;
2188 MozillaStyle.Cpp11BracedListStyle = FormatStyle::BLS_Block;
2189 MozillaStyle.FixNamespaceComments =
false;
2190 MozillaStyle.IndentCaseLabels =
true;
2191 MozillaStyle.ObjCSpaceAfterProperty =
true;
2192 MozillaStyle.ObjCSpaceBeforeProtocolList =
false;
2193 MozillaStyle.PenaltyReturnTypeOnItsOwnLine = 200;
2194 MozillaStyle.PointerAlignment = FormatStyle::PAS_Left;
2195 MozillaStyle.SpaceAfterTemplateKeyword =
false;
2196 return MozillaStyle;
2201 Style.AccessModifierOffset = -4;
2202 Style.AlignAfterOpenBracket =
false;
2203 Style.AlignOperands = FormatStyle::OAS_DontAlign;
2204 Style.AlignTrailingComments = {};
2205 Style.AlignTrailingComments.Kind = FormatStyle::TCAS_Never;
2206 Style.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Empty;
2207 Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
2208 Style.BreakBeforeBraces = FormatStyle::BS_WebKit;
2209 Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;
2210 Style.ColumnLimit = 0;
2211 Style.Cpp11BracedListStyle = FormatStyle::BLS_Block;
2212 Style.FixNamespaceComments =
false;
2213 Style.IndentWidth = 4;
2214 Style.NamespaceIndentation = FormatStyle::NI_Inner;
2215 Style.ObjCBlockIndentWidth = 4;
2216 Style.ObjCSpaceAfterProperty =
true;
2217 Style.PointerAlignment = FormatStyle::PAS_Left;
2218 Style.SpaceBeforeCpp11BracedList =
true;
2219 Style.SpaceInEmptyBraces = FormatStyle::SIEB_Always;
2225 Style.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_All;
2226 Style.BreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
2227 Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
2228 Style.BreakBeforeBraces = FormatStyle::BS_GNU;
2229 Style.BreakBeforeTernaryOperators =
true;
2230 Style.ColumnLimit = 79;
2231 Style.Cpp11BracedListStyle = FormatStyle::BLS_Block;
2232 Style.FixNamespaceComments =
false;
2233 Style.KeepFormFeed =
true;
2234 Style.SpaceBeforeParens = FormatStyle::SBPO_Always;
2240 Style.ColumnLimit = 120;
2242 Style.IndentWidth = 4;
2243 Style.UseTab = FormatStyle::UT_Never;
2244 Style.BreakBeforeBraces = FormatStyle::BS_Custom;
2245 Style.BraceWrapping.AfterClass =
true;
2246 Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_Always;
2247 Style.BraceWrapping.AfterEnum =
true;
2248 Style.BraceWrapping.AfterFunction =
true;
2249 Style.BraceWrapping.AfterNamespace =
true;
2250 Style.BraceWrapping.AfterObjCDeclaration =
true;
2251 Style.BraceWrapping.AfterStruct =
true;
2252 Style.BraceWrapping.AfterExternBlock =
true;
2253 Style.BraceWrapping.BeforeCatch =
true;
2254 Style.BraceWrapping.BeforeElse =
true;
2255 Style.BraceWrapping.BeforeWhile =
false;
2256 Style.PenaltyReturnTypeOnItsOwnLine = 1000;
2257 Style.AllowShortEnumsOnASingleLine =
false;
2258 Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
2259 Style.AllowShortCaseLabelsOnASingleLine =
false;
2260 Style.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
2261 Style.AllowShortLoopsOnASingleLine =
false;
2262 Style.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
2263 Style.BreakAfterReturnType = FormatStyle::RTBS_None;
2269 Style.InsertBraces =
true;
2270 Style.InsertNewlineAtEOF =
true;
2271 Style.IntegerLiteralSeparator.Decimal = 3;
2272 Style.IntegerLiteralSeparator.DecimalMinDigitsInsert = 5;
2273 Style.LineEnding = FormatStyle::LE_LF;
2274 Style.RemoveBracesLLVM =
true;
2275 Style.RemoveEmptyLinesInUnwrappedLines =
true;
2276 Style.RemoveParentheses = FormatStyle::RPS_ReturnStatement;
2277 Style.RemoveSemicolon =
true;
2283 NoStyle.DisableFormat =
true;
2284 NoStyle.SortIncludes = {};
2285 NoStyle.SortUsingDeclarations = FormatStyle::SUD_Never;
2290 FormatStyle *Style) {
2291 constexpr StringRef Prefix(
"inheritparentconfig=");
2293 if (Name.equals_insensitive(
"llvm"))
2295 else if (Name.equals_insensitive(
"chromium"))
2297 else if (Name.equals_insensitive(
"mozilla"))
2299 else if (Name.equals_insensitive(
"google"))
2301 else if (Name.equals_insensitive(
"webkit"))
2303 else if (Name.equals_insensitive(
"gnu"))
2305 else if (Name.equals_insensitive(
"microsoft"))
2307 else if (Name.equals_insensitive(
"clang-format"))
2309 else if (Name.equals_insensitive(
"none"))
2311 else if (Name.equals_insensitive(Prefix.drop_back()))
2312 Style->InheritConfig =
"..";
2313 else if (Name.size() > Prefix.size() && Name.starts_with_insensitive(Prefix))
2314 Style->InheritConfig = Name.substr(Prefix.size());
2324 if (Style->QualifierOrder.empty())
2328 for (
const auto &Qualifier : Style->QualifierOrder) {
2329 if (Qualifier ==
"type")
2333 if (token == tok::identifier)
2338 std::set<std::string> UniqueQualifiers(Style->QualifierOrder.begin(),
2339 Style->QualifierOrder.end());
2340 if (Style->QualifierOrder.size() != UniqueQualifiers.size()) {
2341 LLVM_DEBUG(llvm::dbgs()
2342 <<
"Duplicate Qualifiers " << Style->QualifierOrder.size()
2343 <<
" vs " << UniqueQualifiers.size() <<
"\n");
2348 if (!llvm::is_contained(Style->QualifierOrder,
"type"))
2355 FormatStyle *Style,
bool AllowUnknownOptions,
2356 llvm::SourceMgr::DiagHandlerTy DiagHandler,
2357 void *DiagHandlerCtxt,
bool IsDotHFile) {
2359 FormatStyle::LanguageKind
Language = Style->Language;
2360 assert(
Language != FormatStyle::LK_None);
2361 if (Config.getBuffer().trim().empty())
2363 Style->StyleSet.Clear();
2364 std::vector<FormatStyle> Styles;
2365 llvm::yaml::Input Input(Config,
nullptr, DiagHandler,
2371 Input.setContext(Style);
2372 Input.setAllowUnknownKeys(AllowUnknownOptions);
2375 return Input.error();
2379 const auto StyleCount = Styles.size();
2382 for (
unsigned I = 1; I < StyleCount; ++I) {
2383 const auto Lang = Styles[I].Language;
2384 if (Lang == FormatStyle::LK_None)
2387 for (
unsigned J = 0; J < I; ++J) {
2389 LLVM_DEBUG(llvm::dbgs()
2390 <<
"Duplicate languages in the config file on positions "
2391 << J <<
" and " << I <<
'\n');
2397 int LanguagePos = -1;
2403 for (
unsigned I = 0; I < StyleCount; ++I) {
2404 const auto Lang = Styles[I].Language;
2409 if (Lang == FormatStyle::LK_Cpp)
2411 else if (Lang == FormatStyle::LK_C)
2418 if (LanguagePos < 0) {
2419 if (Styles[0].
Language == FormatStyle::LK_None)
2421 else if (IsDotHFile &&
Language == FormatStyle::LK_Cpp)
2423 else if (!IsDotHFile &&
Language == FormatStyle::LK_C)
2424 LanguagePos = CppPos;
2425 if (LanguagePos < 0)
2429 for (
const auto &S : llvm::reverse(llvm::drop_begin(Styles)))
2430 Style->StyleSet.Add(S);
2432 *Style = Styles[LanguagePos];
2434 if (LanguagePos == 0) {
2435 if (Style->Language == FormatStyle::LK_None)
2437 Style->StyleSet.Add(*Style);
2440 if (Style->InsertTrailingCommas != FormatStyle::TCS_None &&
2441 Style->BinPackArguments) {
2445 if (Style->QualifierAlignment != FormatStyle::QAS_Leave)
2452 llvm::raw_string_ostream Stream(
Text);
2453 llvm::yaml::Output Output(Stream);
2456 FormatStyle NonConstStyle = Style;
2460 Output << NonConstStyle;
2462 return Stream.str();
2465std::optional<FormatStyle>
2466FormatStyle::FormatStyleSet::Get(FormatStyle::LanguageKind
Language)
const {
2468 return std::nullopt;
2470 if (It == Styles->end())
2471 return std::nullopt;
2472 FormatStyle Style = It->second;
2473 Style.StyleSet = *
this;
2477void FormatStyle::FormatStyleSet::Add(FormatStyle Style) {
2478 assert(Style.Language !=
LK_None &&
2479 "Cannot add a style for LK_None to a StyleSet");
2481 !Style.StyleSet.Styles &&
2482 "Cannot add a style associated with an existing StyleSet to a StyleSet");
2484 Styles = std::make_shared<MapType>();
2485 (*Styles)[Style.Language] = std::move(Style);
2488void FormatStyle::FormatStyleSet::Clear() { Styles.reset(); }
2490std::optional<FormatStyle>
2491FormatStyle::GetLanguageStyle(FormatStyle::LanguageKind
Language)
const {
2498 const SourceManager &SourceMgr, tooling::Replacements &
Result,
2499 StringRef
Text =
"") {
2500 const auto &
Tok = Token.Tok;
2501 SourceLocation Start;
2503 Start =
Tok.getLocation();
2506 Start = Token.WhitespaceRange.getBegin();
2509 cantFail(
Result.add(tooling::Replacement(SourceMgr, Range,
Text)));
2514 ParensRemover(
const Environment &Env,
const FormatStyle &Style)
2515 : TokenAnalyzer(Env, Style) {}
2517 std::pair<tooling::Replacements, unsigned>
2518 analyze(TokenAnnotator &Annotator,
2519 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2520 FormatTokenLexer &Tokens)
override {
2521 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2522 tooling::Replacements
Result;
2523 removeParens(AnnotatedLines,
Result);
2528 void removeParens(SmallVectorImpl<AnnotatedLine *> &Lines,
2529 tooling::Replacements &
Result) {
2530 const auto &SourceMgr = Env.getSourceManager();
2531 for (
auto *
Line : Lines) {
2532 if (!
Line->Children.empty())
2534 if (!
Line->Affected)
2536 for (
const auto *Token =
Line->First; Token && !Token->Finalized;
2537 Token = Token->Next) {
2538 if (Token->Optional && Token->isOneOf(tok::l_paren, tok::r_paren))
2547 BracesInserter(
const Environment &Env,
const FormatStyle &Style)
2548 : TokenAnalyzer(Env, Style) {}
2550 std::pair<tooling::Replacements, unsigned>
2551 analyze(TokenAnnotator &Annotator,
2552 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2553 FormatTokenLexer &Tokens)
override {
2554 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2555 tooling::Replacements
Result;
2556 insertBraces(AnnotatedLines,
Result);
2561 void insertBraces(SmallVectorImpl<AnnotatedLine *> &Lines,
2562 tooling::Replacements &
Result) {
2563 const auto &SourceMgr = Env.getSourceManager();
2564 int OpeningBraceSurplus = 0;
2565 for (AnnotatedLine *
Line : Lines) {
2566 if (!
Line->Children.empty())
2568 if (!
Line->Affected && OpeningBraceSurplus == 0)
2571 Token = Token->Next) {
2578 if (!
Line->Affected)
2580 Brace = Token->is(tok::comment) ?
"\n{" :
"{";
2581 ++OpeningBraceSurplus;
2583 if (OpeningBraceSurplus == 0)
2590 Token->BraceCount = 0;
2591 const auto Start = Token->Tok.getEndLoc();
2592 cantFail(
Result.add(tooling::Replacement(SourceMgr, Start, 0,
Brace)));
2595 assert(OpeningBraceSurplus == 0);
2601 BracesRemover(
const Environment &Env,
const FormatStyle &Style)
2602 : TokenAnalyzer(Env, Style) {}
2604 std::pair<tooling::Replacements, unsigned>
2605 analyze(TokenAnnotator &Annotator,
2606 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2607 FormatTokenLexer &Tokens)
override {
2608 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2609 tooling::Replacements
Result;
2610 removeBraces(AnnotatedLines,
Result);
2615 void removeBraces(SmallVectorImpl<AnnotatedLine *> &Lines,
2616 tooling::Replacements &
Result) {
2617 const auto &SourceMgr = Env.getSourceManager();
2618 const auto *End = Lines.end();
2619 for (
const auto *I = Lines.begin(); I != End; ++I) {
2620 const auto &
Line = *I;
2621 if (!
Line->Children.empty())
2623 if (!
Line->Affected)
2625 const auto *NextLine = I + 1 == End ?
nullptr : I[1];
2626 for (
const auto *Token =
Line->First; Token && !Token->Finalized;
2627 Token = Token->Next) {
2628 if (!Token->Optional || Token->isNoneOf(tok::l_brace, tok::r_brace))
2630 auto *
Next = Token->Next;
2631 assert(
Next || Token ==
Line->Last);
2632 if (!
Next && NextLine)
2633 Next = NextLine->First;
2642 SemiRemover(
const Environment &Env,
const FormatStyle &Style)
2643 : TokenAnalyzer(Env, Style) {}
2645 std::pair<tooling::Replacements, unsigned>
2646 analyze(TokenAnnotator &Annotator,
2647 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2648 FormatTokenLexer &Tokens)
override {
2649 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2650 tooling::Replacements
Result;
2651 removeSemi(Annotator, AnnotatedLines,
Result);
2656 void removeSemi(TokenAnnotator &Annotator,
2657 SmallVectorImpl<AnnotatedLine *> &Lines,
2658 tooling::Replacements &
Result) {
2660 const auto *Prev =
Tok.Previous;
2661 if (!Prev || Prev->isNot(tok::r_brace))
2663 const auto *LBrace = Prev->MatchingParen;
2664 return LBrace && LBrace->is(TT_FunctionLBrace);
2666 const auto &SourceMgr = Env.getSourceManager();
2667 const auto *End = Lines.end();
2668 for (
const auto *I = Lines.begin(); I != End; ++I) {
2669 const auto &
Line = *I;
2670 if (!
Line->Children.empty())
2671 removeSemi(Annotator,
Line->Children,
Result);
2672 if (!
Line->Affected)
2674 Annotator.calculateFormattingInformation(*
Line);
2675 const auto *NextLine = I + 1 == End ?
nullptr : I[1];
2676 for (
const auto *Token =
Line->First; Token && !Token->Finalized;
2677 Token = Token->Next) {
2678 if (Token->isNot(tok::semi) ||
2679 (!Token->Optional && !PrecededByFunctionRBrace(*Token))) {
2682 auto *
Next = Token->Next;
2683 assert(
Next || Token ==
Line->Last);
2684 if (!
Next && NextLine)
2685 Next = NextLine->First;
2694 EnumTrailingCommaEditor(
const Environment &Env,
const FormatStyle &Style)
2695 : TokenAnalyzer(Env, Style) {}
2697 std::pair<tooling::Replacements, unsigned>
2698 analyze(TokenAnnotator &Annotator,
2699 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2700 FormatTokenLexer &Tokens)
override {
2701 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2702 tooling::Replacements
Result;
2703 editEnumTrailingComma(AnnotatedLines,
Result);
2708 void editEnumTrailingComma(SmallVectorImpl<AnnotatedLine *> &Lines,
2709 tooling::Replacements &
Result) {
2710 bool InEnumBraces =
false;
2712 const auto &SourceMgr = Env.getSourceManager();
2713 for (
auto *
Line : Lines) {
2714 if (!
Line->Children.empty())
2715 editEnumTrailingComma(
Line->Children,
Result);
2716 for (
const auto *Token =
Line->First; Token && !Token->Finalized;
2717 Token = Token->Next) {
2718 if (Token->isNot(TT_EnumRBrace)) {
2719 if (Token->is(TT_EnumLBrace))
2720 InEnumBraces =
true;
2721 else if (InEnumBraces && Token->isNot(tok::comment))
2722 BeforeRBrace =
Line->Affected ? Token :
nullptr;
2725 InEnumBraces =
false;
2728 if (BeforeRBrace->is(tok::comma)) {
2729 if (Style.EnumTrailingComma == FormatStyle::ETC_Remove)
2731 }
else if (Style.EnumTrailingComma == FormatStyle::ETC_Insert) {
2732 cantFail(
Result.add(tooling::Replacement(
2733 SourceMgr, BeforeRBrace->Tok.getEndLoc(), 0,
",")));
2735 BeforeRBrace =
nullptr;
2743 JavaScriptRequoter(
const Environment &Env,
const FormatStyle &Style)
2744 : TokenAnalyzer(Env, Style) {}
2746 std::pair<tooling::Replacements, unsigned>
2747 analyze(TokenAnnotator &Annotator,
2748 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2749 FormatTokenLexer &Tokens)
override {
2750 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2751 tooling::Replacements
Result;
2752 requoteJSStringLiteral(AnnotatedLines,
Result);
2759 void requoteJSStringLiteral(SmallVectorImpl<AnnotatedLine *> &Lines,
2760 tooling::Replacements &
Result) {
2761 for (AnnotatedLine *
Line : Lines) {
2762 requoteJSStringLiteral(
Line->Children,
Result);
2763 if (!
Line->Affected)
2766 FormatTok = FormatTok->Next) {
2767 StringRef Input = FormatTok->TokenText;
2768 if (FormatTok->Finalized || !FormatTok->isStringLiteral() ||
2771 (Style.JavaScriptQuotes == FormatStyle::JSQS_Single &&
2772 !Input.starts_with(
"\"")) ||
2773 (Style.JavaScriptQuotes == FormatStyle::JSQS_Double &&
2774 !Input.starts_with(
"\'"))) {
2779 bool IsSingle = Style.JavaScriptQuotes == FormatStyle::JSQS_Single;
2780 SourceLocation Start = FormatTok->Tok.getLocation();
2781 auto Replace = [&](SourceLocation Start,
unsigned Length,
2782 StringRef ReplacementText) {
2783 auto Err =
Result.add(tooling::Replacement(
2784 Env.getSourceManager(), Start, Length, ReplacementText));
2788 llvm::errs() <<
toString(std::move(Err)) <<
"\n";
2792 Replace(Start, 1, IsSingle ?
"'" :
"\"");
2793 Replace(FormatTok->Tok.getEndLoc().getLocWithOffset(-1), 1,
2794 IsSingle ?
"'" :
"\"");
2797 bool Escaped =
false;
2798 for (
size_t i = 1; i < Input.size() - 1; i++) {
2801 if (!Escaped && i + 1 < Input.size() &&
2802 ((IsSingle && Input[i + 1] ==
'"') ||
2803 (!IsSingle && Input[i + 1] ==
'\''))) {
2806 Replace(Start.getLocWithOffset(i), 1,
"");
2813 if (!Escaped && IsSingle == (Input[i] ==
'\'')) {
2815 Replace(Start.getLocWithOffset(i), 0,
"\\");
2831 Formatter(
const Environment &Env,
const FormatStyle &Style,
2832 FormattingAttemptStatus *Status)
2833 : TokenAnalyzer(Env, Style), Status(Status) {}
2835 std::pair<tooling::Replacements, unsigned>
2836 analyze(TokenAnnotator &Annotator,
2837 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2838 FormatTokenLexer &Tokens)
override {
2839 tooling::Replacements
Result;
2840 deriveLocalStyle(AnnotatedLines);
2841 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2842 for (AnnotatedLine *
Line : AnnotatedLines)
2843 Annotator.calculateFormattingInformation(*
Line);
2844 Annotator.setCommentLineLevels(AnnotatedLines);
2846 WhitespaceManager Whitespaces(
2847 Env.getSourceManager(), Style,
2848 Style.LineEnding > FormatStyle::LE_CRLF
2850 Env.getSourceManager().getBufferData(Env.getFileID()),
2851 Style.LineEnding == FormatStyle::LE_DeriveCRLF)
2852 : Style.LineEnding == FormatStyle::LE_CRLF);
2853 ContinuationIndenter Indenter(Style, Tokens.getKeywords(),
2854 Env.getSourceManager(), Whitespaces, Encoding,
2855 BinPackInconclusiveFunctions);
2857 UnwrappedLineFormatter(&Indenter, &Whitespaces, Style,
2858 Tokens.getKeywords(), Env.getSourceManager(),
2860 .format(AnnotatedLines,
false,
2863 Env.getFirstStartColumn(),
2864 Env.getNextStartColumn(),
2865 Env.getLastStartColumn());
2866 for (
const auto &R : Whitespaces.generateReplacements())
2868 return std::make_pair(
Result, 0);
2869 return std::make_pair(
Result, Penalty);
2874 hasCpp03IncompatibleFormat(
const SmallVectorImpl<AnnotatedLine *> &Lines) {
2875 for (
const AnnotatedLine *
Line : Lines) {
2876 if (hasCpp03IncompatibleFormat(
Line->Children))
2879 if (!
Tok->hasWhitespaceBefore()) {
2880 if (
Tok->is(tok::coloncolon) &&
Tok->Previous->is(TT_TemplateOpener))
2882 if (
Tok->is(TT_TemplateCloser) &&
2883 Tok->Previous->is(TT_TemplateCloser)) {
2892 int countVariableAlignments(
const SmallVectorImpl<AnnotatedLine *> &Lines) {
2893 int AlignmentDiff = 0;
2895 for (
const AnnotatedLine *
Line : Lines) {
2896 AlignmentDiff += countVariableAlignments(
Line->Children);
2899 if (
Tok->isNot(TT_PointerOrReference))
2902 const auto *Prev =
Tok->Previous;
2903 const bool PrecededByName = Prev && Prev->Tok.getIdentifierInfo();
2904 const bool SpaceBefore =
Tok->hasWhitespaceBefore();
2907 while (
Tok->Next &&
Tok->Next->is(TT_PointerOrReference))
2911 const bool FollowedByName =
Next &&
Next->Tok.getIdentifierInfo();
2912 const bool SpaceAfter =
Next &&
Next->hasWhitespaceBefore();
2914 if ((!PrecededByName && !FollowedByName) ||
2916 (PrecededByName && FollowedByName && SpaceBefore == SpaceAfter)) {
2920 if ((PrecededByName && SpaceBefore) ||
2921 (FollowedByName && !SpaceAfter)) {
2924 }
else if ((PrecededByName && !SpaceBefore) ||
2925 (FollowedByName && SpaceAfter)) {
2932 return AlignmentDiff;
2936 deriveLocalStyle(
const SmallVectorImpl<AnnotatedLine *> &AnnotatedLines) {
2937 bool HasBinPackedFunction =
false;
2938 bool HasOnePerLineFunction =
false;
2939 for (AnnotatedLine *
Line : AnnotatedLines) {
2940 if (!
Line->First->Next)
2945 HasBinPackedFunction =
true;
2947 HasOnePerLineFunction =
true;
2952 if (Style.DerivePointerAlignment) {
2953 const auto NetRightCount = countVariableAlignments(AnnotatedLines);
2954 if (NetRightCount > 0)
2955 Style.PointerAlignment = FormatStyle::PAS_Right;
2956 else if (NetRightCount < 0)
2957 Style.PointerAlignment = FormatStyle::PAS_Left;
2958 Style.ReferenceAlignment = FormatStyle::RAS_Pointer;
2960 if (Style.Standard == FormatStyle::LS_Auto) {
2961 Style.Standard = hasCpp03IncompatibleFormat(AnnotatedLines)
2962 ? FormatStyle::LS_Latest
2963 : FormatStyle::LS_Cpp03;
2965 BinPackInconclusiveFunctions =
2966 HasBinPackedFunction || !HasOnePerLineFunction;
2969 bool BinPackInconclusiveFunctions;
2970 FormattingAttemptStatus *Status;
2986 TrailingCommaInserter(
const Environment &Env,
const FormatStyle &Style)
2987 : TokenAnalyzer(Env, Style) {}
2989 std::pair<tooling::Replacements, unsigned>
2990 analyze(TokenAnnotator &Annotator,
2991 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2992 FormatTokenLexer &Tokens)
override {
2993 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2994 tooling::Replacements
Result;
2995 insertTrailingCommas(AnnotatedLines,
Result);
3002 void insertTrailingCommas(SmallVectorImpl<AnnotatedLine *> &Lines,
3003 tooling::Replacements &
Result) {
3004 for (AnnotatedLine *
Line : Lines) {
3005 insertTrailingCommas(
Line->Children,
Result);
3006 if (!
Line->Affected)
3009 FormatTok = FormatTok->Next) {
3010 if (FormatTok->NewlinesBefore == 0)
3013 if (!Matching || !FormatTok->getPreviousNonComment())
3015 if (!(FormatTok->is(tok::r_square) &&
3016 Matching->is(TT_ArrayInitializerLSquare)) &&
3017 !(FormatTok->is(tok::r_brace) && Matching->is(TT_DictLiteral))) {
3020 FormatToken *Prev = FormatTok->getPreviousNonComment();
3021 if (Prev->is(tok::comma) || Prev->is(tok::semi))
3025 SourceLocation Start =
3026 Prev->Tok.getLocation().getLocWithOffset(Prev->TokenText.size());
3030 unsigned ColumnNumber =
3031 Env.getSourceManager().getSpellingColumnNumber(Start);
3032 if (ColumnNumber > Style.ColumnLimit)
3037 tooling::Replacement(Env.getSourceManager(), Start, 0,
",")));
3047 Cleaner(
const Environment &Env,
const FormatStyle &Style)
3048 : TokenAnalyzer(Env, Style),
3049 DeletedTokens(FormatTokenLess(Env.getSourceManager())) {}
3052 std::pair<tooling::Replacements, unsigned>
3053 analyze(TokenAnnotator &Annotator,
3054 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
3055 FormatTokenLexer &Tokens)
override {
3063 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
3065 checkEmptyNamespace(AnnotatedLines);
3067 for (
auto *
Line : AnnotatedLines)
3070 return {generateFixes(), 0};
3074 void cleanupLine(AnnotatedLine *
Line) {
3075 for (
auto *Child :
Line->Children)
3078 if (
Line->Affected) {
3079 cleanupRight(
Line->First, tok::comma, tok::comma);
3080 cleanupRight(
Line->First, TT_CtorInitializerColon, tok::comma);
3081 cleanupRight(
Line->First, tok::l_paren, tok::comma);
3082 cleanupLeft(
Line->First, tok::comma, tok::r_paren);
3083 cleanupLeft(
Line->First, TT_CtorInitializerComma, tok::l_brace);
3084 cleanupLeft(
Line->First, TT_CtorInitializerColon, tok::l_brace);
3085 cleanupLeft(
Line->First, TT_CtorInitializerColon, tok::equal);
3089 bool containsOnlyComments(
const AnnotatedLine &
Line) {
3091 if (
Tok->isNot(tok::comment))
3097 void checkEmptyNamespace(SmallVectorImpl<AnnotatedLine *> &AnnotatedLines) {
3098 std::set<unsigned> DeletedLines;
3099 for (
unsigned i = 0, e = AnnotatedLines.size(); i != e; ++i) {
3100 auto &
Line = *AnnotatedLines[i];
3101 if (
Line.startsWithNamespace())
3102 checkEmptyNamespace(AnnotatedLines, i, i, DeletedLines);
3105 for (
auto Line : DeletedLines) {
3118 bool checkEmptyNamespace(SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
3119 unsigned CurrentLine,
unsigned &NewLine,
3120 std::set<unsigned> &DeletedLines) {
3121 unsigned InitLine = CurrentLine, End = AnnotatedLines.size();
3122 if (Style.BraceWrapping.AfterNamespace) {
3126 if (!AnnotatedLines[++CurrentLine]->startsWith(tok::l_brace)) {
3127 NewLine = CurrentLine;
3130 }
else if (!AnnotatedLines[CurrentLine]->endsWith(tok::l_brace)) {
3133 while (++CurrentLine < End) {
3134 if (AnnotatedLines[CurrentLine]->startsWith(tok::r_brace))
3137 if (AnnotatedLines[CurrentLine]->startsWithNamespace()) {
3138 if (!checkEmptyNamespace(AnnotatedLines, CurrentLine, NewLine,
3142 CurrentLine = NewLine;
3146 if (containsOnlyComments(*AnnotatedLines[CurrentLine]))
3151 NewLine = CurrentLine;
3155 NewLine = CurrentLine;
3156 if (CurrentLine >= End)
3161 AnnotatedLines[InitLine]->First->Tok.getLocation(),
3162 AnnotatedLines[CurrentLine]->Last->Tok.getEndLoc()))) {
3166 for (
unsigned i = InitLine; i <= CurrentLine; ++i)
3167 DeletedLines.insert(i);
3176 template <
typename LeftKind,
typename RightKind>
3177 void cleanupPair(
FormatToken *Start, LeftKind LK, RightKind RK,
3180 for (
auto *Res =
Tok.Next; Res; Res = Res->Next) {
3181 if (Res->isNot(tok::comment) &&
3182 DeletedTokens.find(Res) == DeletedTokens.end()) {
3188 for (
auto *Left = Start;
Left;) {
3189 auto *
Right = NextNotDeleted(*Left);
3193 deleteToken(DeleteLeft ? Left : Right);
3205 template <
typename LeftKind,
typename RightKind>
3206 void cleanupLeft(
FormatToken *Start, LeftKind LK, RightKind RK) {
3207 cleanupPair(Start, LK, RK,
true);
3210 template <
typename LeftKind,
typename RightKind>
3211 void cleanupRight(
FormatToken *Start, LeftKind LK, RightKind RK) {
3212 cleanupPair(Start, LK, RK,
false);
3218 DeletedTokens.insert(
Tok);
3221 tooling::Replacements generateFixes() {
3222 tooling::Replacements Fixes;
3223 SmallVector<FormatToken *> Tokens;
3224 std::copy(DeletedTokens.begin(), DeletedTokens.end(),
3225 std::back_inserter(Tokens));
3231 while (Idx < Tokens.size()) {
3232 unsigned St = Idx, End = Idx;
3233 while ((End + 1) < Tokens.size() && Tokens[End]->Next == Tokens[End + 1])
3236 Tokens[End]->Tok.getEndLoc());
3238 Fixes.add(tooling::Replacement(Env.getSourceManager(), SR,
""));
3242 llvm::errs() <<
toString(std::move(Err)) <<
"\n";
3243 assert(
false &&
"Fixes must not conflict!");
3254 struct FormatTokenLess {
3255 FormatTokenLess(
const SourceManager &SM) : SM(SM) {}
3258 return SM.isBeforeInTranslationUnit(LHS->Tok.getLocation(),
3259 RHS->Tok.getLocation());
3261 const SourceManager &SM;
3265 std::set<FormatToken *, FormatTokenLess> DeletedTokens;
3270 ObjCHeaderStyleGuesser(
const Environment &Env,
const FormatStyle &Style)
3271 : TokenAnalyzer(Env, Style), IsObjC(
false) {}
3273 std::pair<tooling::Replacements, unsigned>
3274 analyze(TokenAnnotator &Annotator,
3275 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
3276 FormatTokenLexer &Tokens)
override {
3277 assert(Style.Language == FormatStyle::LK_Cpp);
3278 IsObjC = guessIsObjC(Env.getSourceManager(), AnnotatedLines,
3279 Tokens.getKeywords());
3280 tooling::Replacements
Result;
3284 bool isObjC() {
return IsObjC; }
3288 guessIsObjC(
const SourceManager &SourceManager,
3289 const SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
3290 const AdditionalKeywords &Keywords) {
3292 static constexpr llvm::StringLiteral FoundationIdentifiers[] = {
3307 "FOUNDATION_EXPORT",
3308 "FOUNDATION_EXTERN",
3309 "NSAffineTransform",
3311 "NSAttributedString",
3330 "NSInvocationOperation",
3334 "NSMutableAttributedString",
3335 "NSMutableCharacterSet",
3337 "NSMutableDictionary",
3338 "NSMutableIndexSet",
3339 "NSMutableOrderedSet",
3343 "NSNumberFormatter",
3347 "NSOperationQueuePriority",
3351 "NSQualityOfService",
3354 "NSRegularExpression",
3365 "NS_ASSUME_NONNULL_BEGIN",
3369 assert(llvm::is_sorted(FoundationIdentifiers));
3371 for (
auto *
Line : AnnotatedLines) {
3372 if (
Line->First && (
Line->First->TokenText.starts_with(
"#") ||
3373 Line->First->TokenText ==
"__pragma" ||
3374 Line->First->TokenText ==
"_Pragma")) {
3378 FormatTok = FormatTok->Next) {
3379 if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&
3380 (FormatTok->isNot(tok::objc_not_keyword) ||
3381 FormatTok->isOneOf(tok::numeric_constant, tok::l_square,
3383 (FormatTok->Tok.isAnyIdentifier() &&
3384 llvm::binary_search(FoundationIdentifiers,
3385 FormatTok->TokenText)) ||
3386 FormatTok->is(TT_ObjCStringLiteral) ||
3387 FormatTok->isOneOf(Keywords.kw_NS_CLOSED_ENUM, Keywords.kw_NS_ENUM,
3388 Keywords.kw_NS_ERROR_ENUM,
3389 Keywords.kw_NS_OPTIONS, TT_ObjCBlockLBrace,
3390 TT_ObjCBlockLParen, TT_ObjCDecl, TT_ObjCForIn,
3391 TT_ObjCMethodExpr, TT_ObjCMethodSpecifier,
3392 TT_ObjCProperty, TT_ObjCSelector)) {
3393 LLVM_DEBUG(llvm::dbgs()
3394 <<
"Detected ObjC at location "
3395 << FormatTok->Tok.getLocation().printToString(
3397 <<
" token: " << FormatTok->TokenText <<
" token type: "
3402 if (guessIsObjC(SourceManager,
Line->Children, Keywords))
3411struct IncludeDirective {
3419struct JavaImportDirective {
3420 StringRef Identifier;
3423 SmallVector<StringRef> AssociatedCommentLines;
3432 for (
const auto &Range : Ranges) {
3433 if (Range.getOffset() < End &&
3434 Range.getOffset() + Range.getLength() > Start) {
3449static std::pair<unsigned, unsigned>
3452 unsigned CursorIndex = std::numeric_limits<unsigned>::max();
3453 unsigned OffsetToEOL = 0;
3454 for (
int i = 0, e = Includes.size(); i != e; ++i) {
3455 unsigned Start = Includes[Indices[i]].Offset;
3456 unsigned End = Start + Includes[Indices[i]].Text.size();
3457 if (!(Cursor >= Start && Cursor < End))
3459 CursorIndex = Indices[i];
3460 OffsetToEOL = End - Cursor;
3463 while (--i >= 0 && Includes[CursorIndex].
Text == Includes[Indices[i]].
Text)
3467 return std::make_pair(CursorIndex, OffsetToEOL);
3472 std::string NewCode;
3473 size_t Pos = 0, LastPos = 0;
3476 Pos = Code.find(
"\r\n", LastPos);
3477 if (Pos == LastPos) {
3481 if (Pos == std::string::npos) {
3482 NewCode += Code.substr(LastPos);
3485 NewCode += Code.substr(LastPos, Pos - LastPos) +
"\n";
3487 }
while (Pos != std::string::npos);
3505 const unsigned IncludesBeginOffset = Includes.front().Offset;
3506 const unsigned IncludesEndOffset =
3507 Includes.back().Offset + Includes.back().Text.size();
3508 const unsigned IncludesBlockSize = IncludesEndOffset - IncludesBeginOffset;
3509 if (!
affectsRange(Ranges, IncludesBeginOffset, IncludesEndOffset))
3512 llvm::to_vector<16>(llvm::seq<unsigned>(0, Includes.size()));
3514 if (Style.SortIncludes.Enabled) {
3515 stable_sort(Indices, [&](
unsigned LHSI,
unsigned RHSI) {
3517 if (Style.SortIncludes.IgnoreExtension) {
3518 LHSStem = Includes[LHSI].Filename;
3519 RHSStem = Includes[RHSI].Filename;
3520 llvm::sys::path::replace_extension(LHSStem,
"");
3521 llvm::sys::path::replace_extension(RHSStem,
"");
3523 std::string LHSStemLower, RHSStemLower;
3524 std::string LHSFilenameLower, RHSFilenameLower;
3525 if (Style.SortIncludes.IgnoreCase) {
3526 LHSStemLower = LHSStem.str().lower();
3527 RHSStemLower = RHSStem.str().lower();
3528 LHSFilenameLower = Includes[LHSI].Filename.lower();
3529 RHSFilenameLower = Includes[RHSI].Filename.lower();
3531 return std::tie(Includes[LHSI].Priority, LHSStemLower, LHSStem,
3532 LHSFilenameLower, Includes[LHSI].Filename) <
3533 std::tie(Includes[RHSI].Priority, RHSStemLower, RHSStem,
3534 RHSFilenameLower, Includes[RHSI].Filename);
3540 unsigned CursorIndex;
3542 unsigned CursorToEOLOffset;
3544 std::tie(CursorIndex, CursorToEOLOffset) =
3549 Indices.erase(llvm::unique(Indices,
3550 [&](
unsigned LHSI,
unsigned RHSI) {
3551 return Includes[LHSI].Text.trim() ==
3552 Includes[RHSI].Text.trim();
3556 int CurrentCategory = Includes.front().Category;
3564 if (Indices.size() == Includes.size() && is_sorted(Indices) &&
3569 const auto OldCursor = Cursor ? *Cursor : 0;
3571 for (
unsigned Index : Indices) {
3572 if (!result.empty()) {
3574 if (Style.IncludeStyle.IncludeBlocks ==
3576 CurrentCategory != Includes[Index].Category) {
3580 result += Includes[Index].Text;
3581 if (Cursor && CursorIndex == Index)
3582 *Cursor = IncludesBeginOffset + result.size() - CursorToEOLOffset;
3583 CurrentCategory = Includes[Index].Category;
3586 if (Cursor && *Cursor >= IncludesEndOffset)
3587 *Cursor += result.size() - IncludesBlockSize;
3592 IncludesBeginOffset, IncludesBlockSize)))) {
3594 *Cursor = OldCursor;
3599 FileName, Includes.front().Offset, IncludesBlockSize, result));
3603 llvm::errs() <<
toString(std::move(Err)) <<
"\n";
3613 unsigned Prev = llvm::StringSwitch<size_t>(Code)
3614 .StartsWith(
"\xEF\xBB\xBF", 3)
3616 unsigned SearchFrom = 0;
3628 bool FirstIncludeBlock =
true;
3629 bool MainIncludeFound =
false;
3630 bool FormattingOff =
false;
3633 llvm::Regex RawStringRegex(
3634 "R\"([][A-Za-z0-9_{}#<>%:;.?*+/^&\\$|~!=,'-]*)\\(");
3636 std::string RawStringTermination =
")\"";
3638 for (
const auto Size = Code.size(); SearchFrom < Size;) {
3639 size_t Pos = SearchFrom;
3640 if (Code[SearchFrom] !=
'\n') {
3643 Pos = Code.find(
'\n', Pos);
3644 }
while (Pos != StringRef::npos && Code[Pos - 1] ==
'\\');
3648 Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev);
3650 StringRef Trimmed =
Line.trim();
3655 if (RawStringRegex.match(Trimmed, &RawStringMatches)) {
3656 std::string CharSequence = RawStringMatches[1].str();
3657 RawStringTermination =
")" + CharSequence +
"\"";
3658 FormattingOff =
true;
3661 if (Trimmed.contains(RawStringTermination))
3662 FormattingOff =
false;
3664 bool IsBlockComment =
false;
3667 FormattingOff =
true;
3669 FormattingOff =
false;
3670 }
else if (Trimmed.starts_with(
"/*")) {
3671 IsBlockComment =
true;
3672 Pos = Code.find(
"*/", SearchFrom + 2);
3675 const bool EmptyLineSkipped =
3678 Style.IncludeStyle.IncludeBlocks ==
3681 bool MergeWithNextLine = Trimmed.ends_with(
"\\");
3682 if (!FormattingOff && !MergeWithNextLine) {
3683 if (!IsBlockComment &&
3685 StringRef IncludeName = Matches[2];
3686 if (Trimmed.contains(
"/*") && !Trimmed.contains(
"*/")) {
3691 Pos = Code.find(
"*/", SearchFrom);
3693 Prev, (Pos != StringRef::npos ? Pos + 2 : Code.size()) - Prev);
3697 !MainIncludeFound && FirstIncludeBlock);
3699 IncludeName, !MainIncludeFound && FirstIncludeBlock);
3701 MainIncludeFound =
true;
3702 IncludesInBlock.push_back(
3703 {IncludeName,
Line, Prev, Category, Priority});
3704 }
else if (!IncludesInBlock.empty() && !EmptyLineSkipped) {
3707 IncludesInBlock.clear();
3708 if (Trimmed.starts_with(
"#pragma hdrstop"))
3709 FirstIncludeBlock =
true;
3711 FirstIncludeBlock =
false;
3714 if (Pos == StringRef::npos || Pos + 1 == Code.size())
3717 if (!MergeWithNextLine)
3719 SearchFrom = Pos + 1;
3721 if (!IncludesInBlock.empty()) {
3732 StringRef ImportIdentifier) {
3733 unsigned LongestMatchIndex = std::numeric_limits<unsigned>::max();
3734 unsigned LongestMatchLength = 0;
3735 for (
unsigned I = 0; I < Style.JavaImportGroups.size(); I++) {
3736 const std::string &GroupPrefix = Style.JavaImportGroups[I];
3737 if (ImportIdentifier.starts_with(GroupPrefix) &&
3738 GroupPrefix.length() > LongestMatchLength) {
3739 LongestMatchIndex = I;
3740 LongestMatchLength = GroupPrefix.length();
3743 return LongestMatchIndex;
3755 unsigned ImportsBeginOffset = Imports.front().Offset;
3756 unsigned ImportsEndOffset =
3757 Imports.back().Offset + Imports.back().Text.size();
3758 unsigned ImportsBlockSize = ImportsEndOffset - ImportsBeginOffset;
3759 if (!
affectsRange(Ranges, ImportsBeginOffset, ImportsEndOffset))
3763 llvm::to_vector<16>(llvm::seq<unsigned>(0, Imports.size()));
3766 for (
const JavaImportDirective &Import : Imports)
3769 bool StaticImportAfterNormalImport =
3770 Style.SortJavaStaticImport == FormatStyle::SJSIO_After;
3771 sort(Indices, [&](
unsigned LHSI,
unsigned RHSI) {
3773 return std::make_tuple(!Imports[LHSI].IsStatic ^
3774 StaticImportAfterNormalImport,
3776 std::make_tuple(!Imports[RHSI].IsStatic ^
3777 StaticImportAfterNormalImport,
3782 Indices.erase(llvm::unique(Indices,
3783 [&](
unsigned LHSI,
unsigned RHSI) {
3784 return Imports[LHSI].Text == Imports[RHSI].Text;
3788 bool CurrentIsStatic = Imports[Indices.front()].IsStatic;
3792 for (
unsigned Index : Indices) {
3793 if (!result.empty()) {
3795 if (CurrentIsStatic != Imports[Index].IsStatic ||
3800 for (StringRef CommentLine : Imports[Index].AssociatedCommentLines) {
3801 result += CommentLine;
3804 result += Imports[Index].Text;
3805 CurrentIsStatic = Imports[Index].IsStatic;
3812 Imports.front().Offset, ImportsBlockSize)))) {
3817 ImportsBlockSize, result));
3821 llvm::errs() <<
toString(std::move(Err)) <<
"\n";
3828const char JavaImportRegexPattern[] =
3829 "^[\t ]*import[\t ]+(static[\t ]*)?([^\t ]*)[\t ]*;";
3838 unsigned SearchFrom = 0;
3839 llvm::Regex ImportRegex(JavaImportRegexPattern);
3844 bool FormattingOff =
false;
3847 auto Pos = Code.find(
'\n', SearchFrom);
3849 Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev);
3851 StringRef Trimmed =
Line.trim();
3853 FormattingOff =
true;
3855 FormattingOff =
false;
3857 if (ImportRegex.match(
Line, &Matches)) {
3858 if (FormattingOff) {
3863 StringRef
Static = Matches[1];
3864 StringRef Identifier = Matches[2];
3865 bool IsStatic =
false;
3866 if (
Static.contains(
"static"))
3868 ImportsInBlock.push_back(
3869 {Identifier,
Line, Prev, AssociatedCommentLines, IsStatic});
3870 AssociatedCommentLines.clear();
3871 }
else if (!Trimmed.empty() && !ImportsInBlock.empty()) {
3873 AssociatedCommentLines.push_back(
Line);
3876 if (Pos == StringRef::npos || Pos + 1 == Code.size())
3878 SearchFrom = Pos + 1;
3880 if (!ImportsInBlock.empty())
3889 return Code.size() > 188 && Code[0] == 0x47 && Code[188] == 0x47;
3892bool isLikelyXml(StringRef Code) {
return Code.ltrim().starts_with(
"<"); }
3896 StringRef
FileName,
unsigned *Cursor) {
3898 if (!Style.SortIncludes.Enabled || Style.DisableFormat)
3902 if (Style.isJavaScript()) {
3914template <
typename T>
3918 const FormatStyle &Style) {
3919 if (Replaces.
empty())
3922 auto NewCode = applyAllReplacements(Code, Replaces);
3924 return NewCode.takeError();
3929 ProcessFunc(Style, *NewCode, ChangedRanges,
FileName);
3931 return Replaces.
merge(FormatReplaces);
3936 const FormatStyle &Style) {
3939 auto SortIncludes = [](
const FormatStyle &Style, StringRef Code,
3940 std::vector<tooling::Range> Ranges,
3944 auto SortedReplaces =
3946 if (!SortedReplaces)
3947 return SortedReplaces.takeError();
3951 auto Reformat = [](
const FormatStyle &Style, StringRef Code,
3952 std::vector<tooling::Range> Ranges,
3962 return Replace.
getOffset() == std::numeric_limits<unsigned>::max() &&
3968inline bool isHeaderDeletion(
const tooling::Replacement &Replace) {
3969 return Replace.getOffset() == std::numeric_limits<unsigned>::max() &&
3970 Replace.getLength() == 1;
3974tooling::Replacements
3975fixCppIncludeInsertions(StringRef Code,
const tooling::Replacements &Replaces,
3976 const FormatStyle &Style) {
3980 tooling::Replacements HeaderInsertions;
3981 std::set<StringRef> HeadersToDelete;
3982 tooling::Replacements
Result;
3983 for (
const auto &R : Replaces) {
3984 if (isHeaderInsertion(R)) {
3987 consumeError(HeaderInsertions.add(R));
3988 }
else if (isHeaderDeletion(R)) {
3989 HeadersToDelete.insert(R.getReplacementText());
3990 }
else if (R.getOffset() == std::numeric_limits<unsigned>::max()) {
3991 llvm::errs() <<
"Insertions other than header #include insertion are "
3993 << R.getReplacementText() <<
"\n";
3995 consumeError(
Result.add(R));
3998 if (HeaderInsertions.empty() && HeadersToDelete.empty())
4001 StringRef
FileName = Replaces.begin()->getFilePath();
4002 tooling::HeaderIncludes Includes(
FileName, Code, Style.IncludeStyle);
4004 for (
const auto &Header : HeadersToDelete) {
4005 tooling::Replacements Replaces =
4006 Includes.remove(Header.trim(
"\"<>"), Header.starts_with(
"<"));
4007 for (
const auto &R : Replaces) {
4008 auto Err =
Result.add(R);
4011 llvm::errs() <<
"Failed to add header deletion replacement for "
4012 << Header <<
": " <<
toString(std::move(Err)) <<
"\n";
4018 for (
const auto &R : HeaderInsertions) {
4019 auto IncludeDirective = R.getReplacementText();
4022 assert(Matched &&
"Header insertion replacement must have replacement text "
4025 auto IncludeName = Matches[2];
4027 Includes.insert(IncludeName.trim(
"\"<>"), IncludeName.starts_with(
"<"),
4030 auto Err =
Result.add(*Replace);
4032 consumeError(std::move(Err));
4033 unsigned NewOffset =
4034 Result.getShiftedCodePosition(Replace->getOffset());
4035 auto Shifted = tooling::Replacement(
FileName, NewOffset, 0,
4036 Replace->getReplacementText());
4048 const FormatStyle &Style) {
4051 auto Cleanup = [](
const FormatStyle &Style, StringRef Code,
4058 fixCppIncludeInsertions(Code, Replaces, Style);
4063std::pair<tooling::Replacements, unsigned>
4066 unsigned NextStartColumn,
unsigned LastStartColumn, StringRef
FileName,
4068 FormatStyle Expanded = Style;
4072 Expanded.InsertBraces =
false;
4073 Expanded.RemoveBracesLLVM =
false;
4074 Expanded.RemoveParentheses = FormatStyle::RPS_Leave;
4075 Expanded.RemoveSemicolon =
false;
4076 switch (Expanded.RequiresClausePosition) {
4077 case FormatStyle::RCPS_SingleLine:
4078 case FormatStyle::RCPS_WithPreceding:
4079 Expanded.IndentRequiresClause =
false;
4085 if (Expanded.DisableFormat)
4089 if (Expanded.isJavaScript() &&
isMpegTS(Code))
4093 if (Style.isJson()) {
4094 std::vector<tooling::Range> Ranges(1,
tooling::Range(0, Code.size()));
4096 NextStartColumn, LastStartColumn);
4101 Formatter(*Env, Style, Status).process().first;
4103 if (Code.starts_with(
"x = ")) {
4104 Replaces = Replaces.
merge(
4108 if (applyAllReplacements(Code, Replaces))
4109 return {Replaces, 0};
4114 NextStartColumn, LastStartColumn);
4132 if (Style.isCpp()) {
4133 if (Style.QualifierAlignment != FormatStyle::QAS_Leave)
4136 if (Style.RemoveParentheses != FormatStyle::RPS_Leave) {
4137 FormatStyle S = Expanded;
4138 S.RemoveParentheses = Style.RemoveParentheses;
4139 Passes.emplace_back([&, S = std::move(S)](
const Environment &Env) {
4140 return ParensRemover(Env, S).process(
true);
4144 if (Style.InsertBraces) {
4145 FormatStyle S = Expanded;
4146 S.InsertBraces =
true;
4147 Passes.emplace_back([&, S = std::move(S)](
const Environment &Env) {
4148 return BracesInserter(Env, S).process(
true);
4152 if (Style.RemoveBracesLLVM) {
4153 FormatStyle S = Expanded;
4154 S.RemoveBracesLLVM =
true;
4155 Passes.emplace_back([&, S = std::move(S)](
const Environment &Env) {
4156 return BracesRemover(Env, S).process(
true);
4160 if (Style.RemoveSemicolon) {
4161 FormatStyle S = Expanded;
4162 S.RemoveSemicolon =
true;
4163 Passes.emplace_back([&, S = std::move(S)](
const Environment &Env) {
4164 return SemiRemover(Env, S).process();
4168 if (Style.EnumTrailingComma != FormatStyle::ETC_Leave) {
4170 return EnumTrailingCommaEditor(Env, Expanded)
4175 if (Style.FixNamespaceComments) {
4181 if (Style.SortUsingDeclarations != FormatStyle::SUD_Never) {
4188 if (Style.SeparateDefinitionBlocks != FormatStyle::SDS_Leave) {
4194 if (Style.Language == FormatStyle::LK_ObjC &&
4195 !Style.ObjCPropertyAttributeOrder.empty()) {
4201 if (Style.isJavaScript() &&
4202 Style.JavaScriptQuotes != FormatStyle::JSQS_Leave) {
4204 return JavaScriptRequoter(Env, Expanded).process(
true);
4209 return Formatter(Env, Expanded, Status).process();
4212 if (Style.isJavaScript() &&
4213 Style.InsertTrailingCommas == FormatStyle::TCS_Wrapped) {
4215 return TrailingCommaInserter(Env, Expanded).process();
4219 std::optional<std::string> CurrentCode;
4221 unsigned Penalty = 0;
4222 for (
size_t I = 0, E = Passes.size(); I < E; ++I) {
4223 std::pair<tooling::Replacements, unsigned> PassFixes = Passes[I](*Env);
4224 auto NewCode = applyAllReplacements(
4225 CurrentCode ? StringRef(*CurrentCode) : Code, PassFixes.first);
4227 Fixes = Fixes.
merge(PassFixes.first);
4228 Penalty += PassFixes.second;
4230 CurrentCode = std::move(*NewCode);
4234 FirstStartColumn, NextStartColumn, LastStartColumn);
4241 if (Style.QualifierAlignment != FormatStyle::QAS_Leave) {
4247 StringRef OriginalCode = Code.substr(Fix.getOffset(), Fix.getLength());
4248 if (OriginalCode != Fix.getReplacementText()) {
4249 auto Err = NonNoOpFixes.
add(Fix);
4251 llvm::errs() <<
"Error adding replacements : "
4252 <<
toString(std::move(Err)) <<
"\n";
4256 Fixes = std::move(NonNoOpFixes);
4259 return {Fixes, Penalty};
4278 if (Style.Language != FormatStyle::LK_Cpp)
4283 return Cleaner(*Env, Style).process().first;
4288 StringRef
FileName,
bool *IncompleteFormat) {
4291 if (!Status.FormatComplete)
4292 *IncompleteFormat =
true;
4319 auto LexingStd = Style.Standard;
4320 if (LexingStd == FormatStyle::LS_Auto || LexingStd == FormatStyle::LS_Latest)
4321 LexingStd = FormatStyle::LS_Cpp20;
4323 const bool SinceCpp11 = LexingStd >= FormatStyle::LS_Cpp11;
4324 const bool SinceCpp20 = LexingStd >= FormatStyle::LS_Cpp20;
4326 switch (Style.Language) {
4327 case FormatStyle::LK_C:
4331 case FormatStyle::LK_Cpp:
4332 case FormatStyle::LK_ObjC:
4333 LangOpts.CXXOperatorNames = 1;
4334 LangOpts.CPlusPlus11 = SinceCpp11;
4335 LangOpts.CPlusPlus14 = LexingStd >= FormatStyle::LS_Cpp14;
4336 LangOpts.CPlusPlus17 = LexingStd >= FormatStyle::LS_Cpp17;
4337 LangOpts.CPlusPlus20 = SinceCpp20;
4340 LangOpts.CPlusPlus = 1;
4343 LangOpts.Char8 = SinceCpp20;
4344 LangOpts.AllowLiteralDigitSeparator = LangOpts.CPlusPlus14 || LangOpts.C23;
4348 LangOpts.Digraphs = SinceCpp11;
4350 LangOpts.LineComment = 1;
4353 LangOpts.MicrosoftExt = 1;
4354 LangOpts.DeclSpecKeyword = 1;
4361 "Set coding style. <string> can be:\n"
4362 "1. A preset: LLVM, GNU, Google, Chromium, Microsoft,\n"
4363 " Mozilla, WebKit.\n"
4364 "2. 'file' to load style configuration from a\n"
4365 " .clang-format file in one of the parent directories\n"
4366 " of the source file (for stdin, see --assume-filename).\n"
4367 " If no .clang-format file is found, falls back to\n"
4368 " --fallback-style.\n"
4369 " --style=file is the default.\n"
4370 "3. 'file:<format_file_path>' to explicitly specify\n"
4371 " the configuration file.\n"
4372 "4. \"{key: value, ...}\" to set specific parameters, e.g.:\n"
4373 " --style=\"{BasedOnStyle: llvm, IndentWidth: 8}\"";
4377 return FormatStyle::LK_C;
4379 return FormatStyle::LK_Java;
4380 if (
FileName.ends_with_insensitive(
".js") ||
4381 FileName.ends_with_insensitive(
".mjs") ||
4382 FileName.ends_with_insensitive(
".cjs") ||
4383 FileName.ends_with_insensitive(
".ts")) {
4384 return FormatStyle::LK_JavaScript;
4387 return FormatStyle::LK_ObjC;
4388 if (
FileName.ends_with_insensitive(
".proto") ||
4389 FileName.ends_with_insensitive(
".protodevel")) {
4390 return FormatStyle::LK_Proto;
4395 if (
FileName.ends_with_insensitive(
".txtpb") ||
4396 FileName.ends_with_insensitive(
".textpb") ||
4397 FileName.ends_with_insensitive(
".pb.txt") ||
4398 FileName.ends_with_insensitive(
".textproto") ||
4399 FileName.ends_with_insensitive(
".asciipb")) {
4400 return FormatStyle::LK_TextProto;
4402 if (
FileName.ends_with_insensitive(
".td"))
4403 return FormatStyle::LK_TableGen;
4404 if (
FileName.ends_with_insensitive(
".cs"))
4405 return FormatStyle::LK_CSharp;
4406 if (
FileName.ends_with_insensitive(
".json") ||
4407 FileName.ends_with_insensitive(
".ipynb")) {
4408 return FormatStyle::LK_Json;
4410 if (
FileName.ends_with_insensitive(
".sv") ||
4411 FileName.ends_with_insensitive(
".svh") ||
4412 FileName.ends_with_insensitive(
".v") ||
4413 FileName.ends_with_insensitive(
".vh")) {
4414 return FormatStyle::LK_Verilog;
4416 return FormatStyle::LK_Cpp;
4424 LangOpts.CPlusPlus = 1;
4425 LangOpts.LineComment = 1;
4427 Lexer Lex(ID, SourceMgr.getBufferOrFake(ID), SourceMgr, LangOpts);
4431 auto Text = StringRef(SourceMgr.getCharacterData(
Tok.getLocation()),
4433 if (!
Text.consume_front(
"// clang-format Language:"))
4438 return FormatStyle::LK_C;
4440 return FormatStyle::LK_Cpp;
4442 return FormatStyle::LK_ObjC;
4445 return FormatStyle::LK_None;
4450 if (GuessedLanguage == FormatStyle::LK_Cpp) {
4451 auto Extension = llvm::sys::path::extension(
FileName);
4454 if (!Code.empty() && (Extension.empty() || Extension ==
".h")) {
4458 Language != FormatStyle::LK_None) {
4463 if (Guesser.isObjC())
4464 return FormatStyle::LK_ObjC;
4467 return GuessedLanguage;
4475llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
4477 FormatStyle *Style,
bool AllowUnknownOptions,
4478 llvm::SourceMgr::DiagHandlerTy DiagHandler,
4480 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
Text =
4481 FS->getBufferForFile(ConfigFile.str());
4482 if (
auto EC =
Text.getError())
4485 DiagHandler,
nullptr,
4493 StringRef FallbackStyleName, StringRef Code,
4494 llvm::vfs::FileSystem *FS,
4495 bool AllowUnknownOptions,
4496 llvm::SourceMgr::DiagHandlerTy DiagHandler) {
4504 if (StyleName.starts_with(
"{")) {
4506 StringRef Source =
"<command-line>";
4507 if (std::error_code ec =
4509 AllowUnknownOptions, DiagHandler)) {
4513 if (Style.InheritConfig.empty())
4516 ChildFormatTextToApply.emplace_back(
4517 llvm::MemoryBuffer::getMemBuffer(StyleName, Source,
false));
4521 FS = llvm::vfs::getRealFileSystem().get();
4524 const bool IsDotHFile =
FileName.ends_with(
".h");
4527 if (Style.InheritConfig.empty() &&
4528 StyleName.starts_with_insensitive(
"file:")) {
4529 auto ConfigFile = StyleName.substr(5);
4530 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
Text =
4532 DiagHandler, IsDotHFile);
4533 if (
auto EC =
Text.getError()) {
4538 LLVM_DEBUG(llvm::dbgs()
4539 <<
"Using configuration file " << ConfigFile <<
"\n");
4541 if (Style.InheritConfig.empty())
4547 ChildFormatTextToApply.emplace_back(std::move(*
Text));
4553 if (Style.InheritConfig.empty() && !StyleName.equals_insensitive(
"file")) {
4556 if (Style.InheritConfig.empty())
4560 using namespace llvm::sys::path;
4564 if (std::error_code EC = FS->makeAbsolute(Path))
4567 auto Normalize = [](String &Path) {
4568 Path = convert_to_slash(Path);
4569 remove_dots(Path,
true, Style::posix);
4575 Style.InheritConfig.clear();
4577 auto dropDiagnosticHandler = [](
const llvm::SMDiagnostic &,
void *) {};
4579 auto applyChildFormatTexts = [&](FormatStyle *Style) {
4580 for (
const auto &MemBuf : llvm::reverse(ChildFormatTextToApply)) {
4583 DiagHandler ? DiagHandler : dropDiagnosticHandler);
4586 static_cast<void>(EC);
4592 FilesToLookFor.push_back(
".clang-format");
4593 FilesToLookFor.push_back(
"_clang-format");
4595 llvm::StringSet<> Directories;
4596 bool Redirected =
false;
4597 String Dir, UnsuitableConfigFiles;
4598 for (StringRef Directory = Path; !Directory.empty();
4599 Directory = Redirected ? Dir.str() : parent_path(Directory)) {
4600 auto Status = FS->status(Directory);
4602 Status->getType() != llvm::sys::fs::file_type::directory_file) {
4609 for (
const auto &F : FilesToLookFor) {
4610 String ConfigFile(Directory);
4612 append(ConfigFile, F);
4613 LLVM_DEBUG(llvm::dbgs() <<
"Trying " << ConfigFile <<
"...\n");
4615 Status = FS->status(ConfigFile);
4617 Status->getType() != llvm::sys::fs::file_type::regular_file) {
4621 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
Text =
4623 DiagHandler, IsDotHFile);
4624 if (
auto EC =
Text.getError()) {
4629 if (!UnsuitableConfigFiles.empty())
4630 UnsuitableConfigFiles.append(
", ");
4631 UnsuitableConfigFiles.append(ConfigFile);
4635 LLVM_DEBUG(llvm::dbgs()
4636 <<
"Using configuration file " << ConfigFile <<
"\n");
4638 if (Style.InheritConfig.empty()) {
4639 if (!ChildFormatTextToApply.empty()) {
4640 LLVM_DEBUG(llvm::dbgs() <<
"Applying child configurations\n");
4641 applyChildFormatTexts(&Style);
4646 if (!Directories.insert(Directory).second) {
4648 "Loop detected when inheriting configuration file in " + Directory);
4651 LLVM_DEBUG(llvm::dbgs() <<
"Inherits parent configuration\n");
4653 if (Style.InheritConfig ==
"..") {
4658 llvm::sys::fs::expand_tilde(Style.InheritConfig, ExpandedDir);
4659 Normalize(ExpandedDir);
4660 if (is_absolute(ExpandedDir, Style::posix)) {
4663 Dir = Directory.str();
4664 append(Dir, Style::posix, ExpandedDir);
4669 Style.InheritConfig.clear();
4671 ChildFormatTextToApply.emplace_back(std::move(*
Text));
4681 if (!UnsuitableConfigFiles.empty()) {
4684 UnsuitableConfigFiles);
4687 if (!ChildFormatTextToApply.empty()) {
4688 LLVM_DEBUG(llvm::dbgs()
4689 <<
"Applying child configurations on fallback style\n");
4690 applyChildFormatTexts(&FallbackStyle);
4693 return FallbackStyle;
4697 if (Comment == (On ?
"/* clang-format on */" :
"/* clang-format off */"))
4700 static const char ClangFormatOn[] =
"// clang-format on";
4701 static const char ClangFormatOff[] =
"// clang-format off";
4702 const unsigned Size = (On ?
sizeof ClangFormatOn :
sizeof ClangFormatOff) - 1;
4704 return Comment.starts_with(On ? ClangFormatOn : ClangFormatOff) &&
4705 (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)