25#include "llvm/ADT/Sequence.h"
27#define DEBUG_TYPE "format-formatter"
31LLVM_YAML_IS_SEQUENCE_VECTOR(FormatStyle::RawStringFormat)
36struct ScalarEnumerationTraits<
FormatStyle::BreakBeforeNoexceptSpecifierStyle> {
39 IO.enumCase(
Value,
"Never", FormatStyle::BBNSS_Never);
40 IO.enumCase(
Value,
"OnlyWithParen", FormatStyle::BBNSS_OnlyWithParen);
41 IO.enumCase(
Value,
"Always", FormatStyle::BBNSS_Always);
45template <>
struct MappingTraits<
FormatStyle::AlignConsecutiveStyle> {
47 IO.enumCase(
Value,
"None",
48 FormatStyle::AlignConsecutiveStyle(
52 IO.enumCase(
Value,
"Consecutive",
53 FormatStyle::AlignConsecutiveStyle(
57 IO.enumCase(
Value,
"AcrossEmptyLines",
58 FormatStyle::AlignConsecutiveStyle(
62 IO.enumCase(
Value,
"AcrossComments",
63 FormatStyle::AlignConsecutiveStyle(
67 IO.enumCase(
Value,
"AcrossEmptyLinesAndComments",
68 FormatStyle::AlignConsecutiveStyle(
74 IO.enumCase(
Value,
"true",
75 FormatStyle::AlignConsecutiveStyle(
79 IO.enumCase(
Value,
"false",
80 FormatStyle::AlignConsecutiveStyle(
86 static void mapping(IO &IO, FormatStyle::AlignConsecutiveStyle &
Value) {
87 IO.mapOptional(
"Enabled",
Value.Enabled);
88 IO.mapOptional(
"AcrossEmptyLines",
Value.AcrossEmptyLines);
89 IO.mapOptional(
"AcrossComments",
Value.AcrossComments);
90 IO.mapOptional(
"AlignCompound",
Value.AlignCompound);
91 IO.mapOptional(
"AlignFunctionPointers",
Value.AlignFunctionPointers);
92 IO.mapOptional(
"PadOperators",
Value.PadOperators);
97struct MappingTraits<
FormatStyle::ShortCaseStatementsAlignmentStyle> {
99 FormatStyle::ShortCaseStatementsAlignmentStyle &
Value) {
100 IO.mapOptional(
"Enabled",
Value.Enabled);
101 IO.mapOptional(
"AcrossEmptyLines",
Value.AcrossEmptyLines);
102 IO.mapOptional(
"AcrossComments",
Value.AcrossComments);
103 IO.mapOptional(
"AlignCaseArrows",
Value.AlignCaseArrows);
104 IO.mapOptional(
"AlignCaseColons",
Value.AlignCaseColons);
109struct ScalarEnumerationTraits<
FormatStyle::AttributeBreakingStyle> {
111 IO.enumCase(
Value,
"Always", FormatStyle::ABS_Always);
112 IO.enumCase(
Value,
"Leave", FormatStyle::ABS_Leave);
113 IO.enumCase(
Value,
"Never", FormatStyle::ABS_Never);
118struct ScalarEnumerationTraits<
FormatStyle::ArrayInitializerAlignmentStyle> {
120 FormatStyle::ArrayInitializerAlignmentStyle &
Value) {
121 IO.enumCase(
Value,
"None", FormatStyle::AIAS_None);
122 IO.enumCase(
Value,
"Left", FormatStyle::AIAS_Left);
123 IO.enumCase(
Value,
"Right", FormatStyle::AIAS_Right);
127template <>
struct ScalarEnumerationTraits<
FormatStyle::BinaryOperatorStyle> {
129 IO.enumCase(
Value,
"All", FormatStyle::BOS_All);
130 IO.enumCase(
Value,
"true", FormatStyle::BOS_All);
131 IO.enumCase(
Value,
"None", FormatStyle::BOS_None);
132 IO.enumCase(
Value,
"false", FormatStyle::BOS_None);
133 IO.enumCase(
Value,
"NonAssignment", FormatStyle::BOS_NonAssignment);
137template <>
struct ScalarEnumerationTraits<
FormatStyle::BinPackStyle> {
139 IO.enumCase(
Value,
"Auto", FormatStyle::BPS_Auto);
140 IO.enumCase(
Value,
"Always", FormatStyle::BPS_Always);
141 IO.enumCase(
Value,
"Never", FormatStyle::BPS_Never);
146struct ScalarEnumerationTraits<
FormatStyle::BitFieldColonSpacingStyle> {
148 FormatStyle::BitFieldColonSpacingStyle &
Value) {
149 IO.enumCase(
Value,
"Both", FormatStyle::BFCS_Both);
150 IO.enumCase(
Value,
"None", FormatStyle::BFCS_None);
151 IO.enumCase(
Value,
"Before", FormatStyle::BFCS_Before);
152 IO.enumCase(
Value,
"After", FormatStyle::BFCS_After);
156template <>
struct ScalarEnumerationTraits<
FormatStyle::BraceBreakingStyle> {
158 IO.enumCase(
Value,
"Attach", FormatStyle::BS_Attach);
159 IO.enumCase(
Value,
"Linux", FormatStyle::BS_Linux);
160 IO.enumCase(
Value,
"Mozilla", FormatStyle::BS_Mozilla);
161 IO.enumCase(
Value,
"Stroustrup", FormatStyle::BS_Stroustrup);
162 IO.enumCase(
Value,
"Allman", FormatStyle::BS_Allman);
163 IO.enumCase(
Value,
"Whitesmiths", FormatStyle::BS_Whitesmiths);
164 IO.enumCase(
Value,
"GNU", FormatStyle::BS_GNU);
165 IO.enumCase(
Value,
"WebKit", FormatStyle::BS_WebKit);
166 IO.enumCase(
Value,
"Custom", FormatStyle::BS_Custom);
170template <>
struct MappingTraits<
FormatStyle::BraceWrappingFlags> {
171 static void mapping(IO &IO, FormatStyle::BraceWrappingFlags &Wrapping) {
172 IO.mapOptional(
"AfterCaseLabel", Wrapping.AfterCaseLabel);
173 IO.mapOptional(
"AfterClass", Wrapping.AfterClass);
174 IO.mapOptional(
"AfterControlStatement", Wrapping.AfterControlStatement);
175 IO.mapOptional(
"AfterEnum", Wrapping.AfterEnum);
176 IO.mapOptional(
"AfterExternBlock", Wrapping.AfterExternBlock);
177 IO.mapOptional(
"AfterFunction", Wrapping.AfterFunction);
178 IO.mapOptional(
"AfterNamespace", Wrapping.AfterNamespace);
179 IO.mapOptional(
"AfterObjCDeclaration", Wrapping.AfterObjCDeclaration);
180 IO.mapOptional(
"AfterStruct", Wrapping.AfterStruct);
181 IO.mapOptional(
"AfterUnion", Wrapping.AfterUnion);
182 IO.mapOptional(
"BeforeCatch", Wrapping.BeforeCatch);
183 IO.mapOptional(
"BeforeElse", Wrapping.BeforeElse);
184 IO.mapOptional(
"BeforeLambdaBody", Wrapping.BeforeLambdaBody);
185 IO.mapOptional(
"BeforeWhile", Wrapping.BeforeWhile);
186 IO.mapOptional(
"IndentBraces", Wrapping.IndentBraces);
187 IO.mapOptional(
"SplitEmptyFunction", Wrapping.SplitEmptyFunction);
188 IO.mapOptional(
"SplitEmptyRecord", Wrapping.SplitEmptyRecord);
189 IO.mapOptional(
"SplitEmptyNamespace", Wrapping.SplitEmptyNamespace);
193template <>
struct ScalarEnumerationTraits<
FormatStyle::BracketAlignmentStyle> {
195 IO.enumCase(
Value,
"Align", FormatStyle::BAS_Align);
196 IO.enumCase(
Value,
"DontAlign", FormatStyle::BAS_DontAlign);
197 IO.enumCase(
Value,
"AlwaysBreak", FormatStyle::BAS_AlwaysBreak);
198 IO.enumCase(
Value,
"BlockIndent", FormatStyle::BAS_BlockIndent);
201 IO.enumCase(
Value,
"true", FormatStyle::BAS_Align);
202 IO.enumCase(
Value,
"false", FormatStyle::BAS_DontAlign);
207struct ScalarEnumerationTraits<
208 FormatStyle::BraceWrappingAfterControlStatementStyle> {
211 FormatStyle::BraceWrappingAfterControlStatementStyle &
Value) {
212 IO.enumCase(
Value,
"Never", FormatStyle::BWACS_Never);
213 IO.enumCase(
Value,
"MultiLine", FormatStyle::BWACS_MultiLine);
214 IO.enumCase(
Value,
"Always", FormatStyle::BWACS_Always);
217 IO.enumCase(
Value,
"false", FormatStyle::BWACS_Never);
218 IO.enumCase(
Value,
"true", FormatStyle::BWACS_Always);
223struct ScalarEnumerationTraits<
224 FormatStyle::BreakBeforeConceptDeclarationsStyle> {
227 IO.enumCase(
Value,
"Never", FormatStyle::BBCDS_Never);
228 IO.enumCase(
Value,
"Allowed", FormatStyle::BBCDS_Allowed);
229 IO.enumCase(
Value,
"Always", FormatStyle::BBCDS_Always);
232 IO.enumCase(
Value,
"true", FormatStyle::BBCDS_Always);
233 IO.enumCase(
Value,
"false", FormatStyle::BBCDS_Allowed);
238struct ScalarEnumerationTraits<
FormatStyle::BreakBeforeInlineASMColonStyle> {
240 FormatStyle::BreakBeforeInlineASMColonStyle &
Value) {
241 IO.enumCase(
Value,
"Never", FormatStyle::BBIAS_Never);
242 IO.enumCase(
Value,
"OnlyMultiline", FormatStyle::BBIAS_OnlyMultiline);
243 IO.enumCase(
Value,
"Always", FormatStyle::BBIAS_Always);
248struct ScalarEnumerationTraits<
FormatStyle::BreakBinaryOperationsStyle> {
250 FormatStyle::BreakBinaryOperationsStyle &
Value) {
251 IO.enumCase(
Value,
"Never", FormatStyle::BBO_Never);
252 IO.enumCase(
Value,
"OnePerLine", FormatStyle::BBO_OnePerLine);
253 IO.enumCase(
Value,
"RespectPrecedence", FormatStyle::BBO_RespectPrecedence);
258struct ScalarEnumerationTraits<
FormatStyle::BreakConstructorInitializersStyle> {
261 IO.enumCase(
Value,
"BeforeColon", FormatStyle::BCIS_BeforeColon);
262 IO.enumCase(
Value,
"BeforeComma", FormatStyle::BCIS_BeforeComma);
263 IO.enumCase(
Value,
"AfterColon", FormatStyle::BCIS_AfterColon);
268struct ScalarEnumerationTraits<
FormatStyle::BreakInheritanceListStyle> {
270 FormatStyle::BreakInheritanceListStyle &
Value) {
271 IO.enumCase(
Value,
"BeforeColon", FormatStyle::BILS_BeforeColon);
272 IO.enumCase(
Value,
"BeforeComma", FormatStyle::BILS_BeforeComma);
273 IO.enumCase(
Value,
"AfterColon", FormatStyle::BILS_AfterColon);
274 IO.enumCase(
Value,
"AfterComma", FormatStyle::BILS_AfterComma);
279struct ScalarEnumerationTraits<
FormatStyle::BreakTemplateDeclarationsStyle> {
281 FormatStyle::BreakTemplateDeclarationsStyle &
Value) {
282 IO.enumCase(
Value,
"Leave", FormatStyle::BTDS_Leave);
283 IO.enumCase(
Value,
"No", FormatStyle::BTDS_No);
284 IO.enumCase(
Value,
"MultiLine", FormatStyle::BTDS_MultiLine);
285 IO.enumCase(
Value,
"Yes", FormatStyle::BTDS_Yes);
288 IO.enumCase(
Value,
"false", FormatStyle::BTDS_MultiLine);
289 IO.enumCase(
Value,
"true", FormatStyle::BTDS_Yes);
293template <>
struct ScalarEnumerationTraits<
FormatStyle::DAGArgStyle> {
295 IO.enumCase(
Value,
"DontBreak", FormatStyle::DAS_DontBreak);
296 IO.enumCase(
Value,
"BreakElements", FormatStyle::DAS_BreakElements);
297 IO.enumCase(
Value,
"BreakAll", FormatStyle::DAS_BreakAll);
302struct ScalarEnumerationTraits<
FormatStyle::DefinitionReturnTypeBreakingStyle> {
305 IO.enumCase(
Value,
"None", FormatStyle::DRTBS_None);
306 IO.enumCase(
Value,
"All", FormatStyle::DRTBS_All);
307 IO.enumCase(
Value,
"TopLevel", FormatStyle::DRTBS_TopLevel);
310 IO.enumCase(
Value,
"false", FormatStyle::DRTBS_None);
311 IO.enumCase(
Value,
"true", FormatStyle::DRTBS_All);
316struct ScalarEnumerationTraits<
FormatStyle::EscapedNewlineAlignmentStyle> {
318 FormatStyle::EscapedNewlineAlignmentStyle &
Value) {
319 IO.enumCase(
Value,
"DontAlign", FormatStyle::ENAS_DontAlign);
320 IO.enumCase(
Value,
"Left", FormatStyle::ENAS_Left);
321 IO.enumCase(
Value,
"LeftWithLastLine", FormatStyle::ENAS_LeftWithLastLine);
322 IO.enumCase(
Value,
"Right", FormatStyle::ENAS_Right);
325 IO.enumCase(
Value,
"true", FormatStyle::ENAS_Left);
326 IO.enumCase(
Value,
"false", FormatStyle::ENAS_Right);
331struct ScalarEnumerationTraits<
FormatStyle::EmptyLineAfterAccessModifierStyle> {
334 IO.enumCase(
Value,
"Never", FormatStyle::ELAAMS_Never);
335 IO.enumCase(
Value,
"Leave", FormatStyle::ELAAMS_Leave);
336 IO.enumCase(
Value,
"Always", FormatStyle::ELAAMS_Always);
341struct ScalarEnumerationTraits<
345 IO.enumCase(
Value,
"Never", FormatStyle::ELBAMS_Never);
346 IO.enumCase(
Value,
"Leave", FormatStyle::ELBAMS_Leave);
347 IO.enumCase(
Value,
"LogicalBlock", FormatStyle::ELBAMS_LogicalBlock);
348 IO.enumCase(
Value,
"Always", FormatStyle::ELBAMS_Always);
353struct ScalarEnumerationTraits<
FormatStyle::IndentExternBlockStyle> {
355 IO.enumCase(
Value,
"AfterExternBlock", FormatStyle::IEBS_AfterExternBlock);
356 IO.enumCase(
Value,
"Indent", FormatStyle::IEBS_Indent);
357 IO.enumCase(
Value,
"NoIndent", FormatStyle::IEBS_NoIndent);
358 IO.enumCase(
Value,
"true", FormatStyle::IEBS_Indent);
359 IO.enumCase(
Value,
"false", FormatStyle::IEBS_NoIndent);
363template <>
struct MappingTraits<
FormatStyle::IntegerLiteralSeparatorStyle> {
364 static void mapping(IO &IO, FormatStyle::IntegerLiteralSeparatorStyle &
Base) {
365 IO.mapOptional(
"Binary",
Base.Binary);
366 IO.mapOptional(
"BinaryMinDigits",
Base.BinaryMinDigits);
367 IO.mapOptional(
"Decimal",
Base.Decimal);
368 IO.mapOptional(
"DecimalMinDigits",
Base.DecimalMinDigits);
369 IO.mapOptional(
"Hex",
Base.Hex);
370 IO.mapOptional(
"HexMinDigits",
Base.HexMinDigits);
374template <>
struct ScalarEnumerationTraits<
FormatStyle::JavaScriptQuoteStyle> {
376 IO.enumCase(
Value,
"Leave", FormatStyle::JSQS_Leave);
377 IO.enumCase(
Value,
"Single", FormatStyle::JSQS_Single);
378 IO.enumCase(
Value,
"Double", FormatStyle::JSQS_Double);
382template <>
struct MappingTraits<
FormatStyle::KeepEmptyLinesStyle> {
384 IO.mapOptional(
"AtEndOfFile",
Value.AtEndOfFile);
385 IO.mapOptional(
"AtStartOfBlock",
Value.AtStartOfBlock);
386 IO.mapOptional(
"AtStartOfFile",
Value.AtStartOfFile);
390template <>
struct ScalarEnumerationTraits<
FormatStyle::LanguageKind> {
392 IO.enumCase(
Value,
"Cpp", FormatStyle::LK_Cpp);
393 IO.enumCase(
Value,
"Java", FormatStyle::LK_Java);
394 IO.enumCase(
Value,
"JavaScript", FormatStyle::LK_JavaScript);
395 IO.enumCase(
Value,
"ObjC", FormatStyle::LK_ObjC);
396 IO.enumCase(
Value,
"Proto", FormatStyle::LK_Proto);
397 IO.enumCase(
Value,
"TableGen", FormatStyle::LK_TableGen);
398 IO.enumCase(
Value,
"TextProto", FormatStyle::LK_TextProto);
399 IO.enumCase(
Value,
"CSharp", FormatStyle::LK_CSharp);
400 IO.enumCase(
Value,
"Json", FormatStyle::LK_Json);
401 IO.enumCase(
Value,
"Verilog", FormatStyle::LK_Verilog);
405template <>
struct ScalarEnumerationTraits<
FormatStyle::LanguageStandard> {
407 IO.enumCase(
Value,
"c++03", FormatStyle::LS_Cpp03);
408 IO.enumCase(
Value,
"C++03", FormatStyle::LS_Cpp03);
409 IO.enumCase(
Value,
"Cpp03", FormatStyle::LS_Cpp03);
411 IO.enumCase(
Value,
"c++11", FormatStyle::LS_Cpp11);
412 IO.enumCase(
Value,
"C++11", FormatStyle::LS_Cpp11);
414 IO.enumCase(
Value,
"c++14", FormatStyle::LS_Cpp14);
415 IO.enumCase(
Value,
"c++17", FormatStyle::LS_Cpp17);
416 IO.enumCase(
Value,
"c++20", FormatStyle::LS_Cpp20);
418 IO.enumCase(
Value,
"Latest", FormatStyle::LS_Latest);
419 IO.enumCase(
Value,
"Cpp11", FormatStyle::LS_Latest);
420 IO.enumCase(
Value,
"Auto", FormatStyle::LS_Auto);
425struct ScalarEnumerationTraits<
FormatStyle::LambdaBodyIndentationKind> {
427 FormatStyle::LambdaBodyIndentationKind &
Value) {
428 IO.enumCase(
Value,
"Signature", FormatStyle::LBI_Signature);
429 IO.enumCase(
Value,
"OuterScope", FormatStyle::LBI_OuterScope);
433template <>
struct ScalarEnumerationTraits<
FormatStyle::LineEndingStyle> {
435 IO.enumCase(
Value,
"LF", FormatStyle::LE_LF);
436 IO.enumCase(
Value,
"CRLF", FormatStyle::LE_CRLF);
437 IO.enumCase(
Value,
"DeriveLF", FormatStyle::LE_DeriveLF);
438 IO.enumCase(
Value,
"DeriveCRLF", FormatStyle::LE_DeriveCRLF);
443struct ScalarEnumerationTraits<
FormatStyle::NamespaceIndentationKind> {
445 FormatStyle::NamespaceIndentationKind &
Value) {
446 IO.enumCase(
Value,
"None", FormatStyle::NI_None);
447 IO.enumCase(
Value,
"Inner", FormatStyle::NI_Inner);
448 IO.enumCase(
Value,
"All", FormatStyle::NI_All);
452template <>
struct ScalarEnumerationTraits<
FormatStyle::OperandAlignmentStyle> {
454 IO.enumCase(
Value,
"DontAlign", FormatStyle::OAS_DontAlign);
455 IO.enumCase(
Value,
"Align", FormatStyle::OAS_Align);
456 IO.enumCase(
Value,
"AlignAfterOperator",
457 FormatStyle::OAS_AlignAfterOperator);
460 IO.enumCase(
Value,
"true", FormatStyle::OAS_Align);
461 IO.enumCase(
Value,
"false", FormatStyle::OAS_DontAlign);
466struct ScalarEnumerationTraits<
FormatStyle::PackConstructorInitializersStyle> {
469 IO.enumCase(
Value,
"Never", FormatStyle::PCIS_Never);
470 IO.enumCase(
Value,
"BinPack", FormatStyle::PCIS_BinPack);
471 IO.enumCase(
Value,
"CurrentLine", FormatStyle::PCIS_CurrentLine);
472 IO.enumCase(
Value,
"NextLine", FormatStyle::PCIS_NextLine);
473 IO.enumCase(
Value,
"NextLineOnly", FormatStyle::PCIS_NextLineOnly);
477template <>
struct ScalarEnumerationTraits<
FormatStyle::PointerAlignmentStyle> {
479 IO.enumCase(
Value,
"Middle", FormatStyle::PAS_Middle);
480 IO.enumCase(
Value,
"Left", FormatStyle::PAS_Left);
481 IO.enumCase(
Value,
"Right", FormatStyle::PAS_Right);
484 IO.enumCase(
Value,
"true", FormatStyle::PAS_Left);
485 IO.enumCase(
Value,
"false", FormatStyle::PAS_Right);
490struct ScalarEnumerationTraits<
FormatStyle::PPDirectiveIndentStyle> {
492 IO.enumCase(
Value,
"None", FormatStyle::PPDIS_None);
493 IO.enumCase(
Value,
"AfterHash", FormatStyle::PPDIS_AfterHash);
494 IO.enumCase(
Value,
"BeforeHash", FormatStyle::PPDIS_BeforeHash);
499struct ScalarEnumerationTraits<
FormatStyle::QualifierAlignmentStyle> {
501 IO.enumCase(
Value,
"Leave", FormatStyle::QAS_Leave);
502 IO.enumCase(
Value,
"Left", FormatStyle::QAS_Left);
503 IO.enumCase(
Value,
"Right", FormatStyle::QAS_Right);
504 IO.enumCase(
Value,
"Custom", FormatStyle::QAS_Custom);
509 static void mapping(IO &IO, FormatStyle::RawStringFormat &Format) {
510 IO.mapOptional(
"Language", Format.Language);
511 IO.mapOptional(
"Delimiters", Format.Delimiters);
512 IO.mapOptional(
"EnclosingFunctions", Format.EnclosingFunctions);
513 IO.mapOptional(
"CanonicalDelimiter", Format.CanonicalDelimiter);
514 IO.mapOptional(
"BasedOnStyle", Format.BasedOnStyle);
519struct ScalarEnumerationTraits<
FormatStyle::ReferenceAlignmentStyle> {
521 IO.enumCase(
Value,
"Pointer", FormatStyle::RAS_Pointer);
522 IO.enumCase(
Value,
"Middle", FormatStyle::RAS_Middle);
523 IO.enumCase(
Value,
"Left", FormatStyle::RAS_Left);
524 IO.enumCase(
Value,
"Right", FormatStyle::RAS_Right);
529struct ScalarEnumerationTraits<
FormatStyle::RemoveParenthesesStyle> {
531 IO.enumCase(
Value,
"Leave", FormatStyle::RPS_Leave);
532 IO.enumCase(
Value,
"MultipleParentheses",
533 FormatStyle::RPS_MultipleParentheses);
534 IO.enumCase(
Value,
"ReturnStatement", FormatStyle::RPS_ReturnStatement);
539struct ScalarEnumerationTraits<
FormatStyle::RequiresClausePositionStyle> {
541 FormatStyle::RequiresClausePositionStyle &
Value) {
542 IO.enumCase(
Value,
"OwnLine", FormatStyle::RCPS_OwnLine);
543 IO.enumCase(
Value,
"OwnLineWithBrace", FormatStyle::RCPS_OwnLineWithBrace);
544 IO.enumCase(
Value,
"WithPreceding", FormatStyle::RCPS_WithPreceding);
545 IO.enumCase(
Value,
"WithFollowing", FormatStyle::RCPS_WithFollowing);
546 IO.enumCase(
Value,
"SingleLine", FormatStyle::RCPS_SingleLine);
551struct ScalarEnumerationTraits<
FormatStyle::RequiresExpressionIndentationKind> {
554 IO.enumCase(
Value,
"Keyword", FormatStyle::REI_Keyword);
555 IO.enumCase(
Value,
"OuterScope", FormatStyle::REI_OuterScope);
560struct ScalarEnumerationTraits<
FormatStyle::ReturnTypeBreakingStyle> {
562 IO.enumCase(
Value,
"None", FormatStyle::RTBS_None);
563 IO.enumCase(
Value,
"Automatic", FormatStyle::RTBS_Automatic);
564 IO.enumCase(
Value,
"ExceptShortType", FormatStyle::RTBS_ExceptShortType);
565 IO.enumCase(
Value,
"All", FormatStyle::RTBS_All);
566 IO.enumCase(
Value,
"TopLevel", FormatStyle::RTBS_TopLevel);
567 IO.enumCase(
Value,
"TopLevelDefinitions",
568 FormatStyle::RTBS_TopLevelDefinitions);
569 IO.enumCase(
Value,
"AllDefinitions", FormatStyle::RTBS_AllDefinitions);
574struct ScalarEnumerationTraits<
FormatStyle::SeparateDefinitionStyle> {
576 IO.enumCase(
Value,
"Leave", FormatStyle::SDS_Leave);
577 IO.enumCase(
Value,
"Always", FormatStyle::SDS_Always);
578 IO.enumCase(
Value,
"Never", FormatStyle::SDS_Never);
582template <>
struct ScalarEnumerationTraits<
FormatStyle::ShortBlockStyle> {
584 IO.enumCase(
Value,
"Never", FormatStyle::SBS_Never);
585 IO.enumCase(
Value,
"false", FormatStyle::SBS_Never);
586 IO.enumCase(
Value,
"Always", FormatStyle::SBS_Always);
587 IO.enumCase(
Value,
"true", FormatStyle::SBS_Always);
588 IO.enumCase(
Value,
"Empty", FormatStyle::SBS_Empty);
592template <>
struct ScalarEnumerationTraits<
FormatStyle::ShortFunctionStyle> {
594 IO.enumCase(
Value,
"None", FormatStyle::SFS_None);
595 IO.enumCase(
Value,
"false", FormatStyle::SFS_None);
596 IO.enumCase(
Value,
"All", FormatStyle::SFS_All);
597 IO.enumCase(
Value,
"true", FormatStyle::SFS_All);
598 IO.enumCase(
Value,
"Inline", FormatStyle::SFS_Inline);
599 IO.enumCase(
Value,
"InlineOnly", FormatStyle::SFS_InlineOnly);
600 IO.enumCase(
Value,
"Empty", FormatStyle::SFS_Empty);
604template <>
struct ScalarEnumerationTraits<
FormatStyle::ShortIfStyle> {
606 IO.enumCase(
Value,
"Never", FormatStyle::SIS_Never);
607 IO.enumCase(
Value,
"WithoutElse", FormatStyle::SIS_WithoutElse);
608 IO.enumCase(
Value,
"OnlyFirstIf", FormatStyle::SIS_OnlyFirstIf);
609 IO.enumCase(
Value,
"AllIfsAndElse", FormatStyle::SIS_AllIfsAndElse);
612 IO.enumCase(
Value,
"Always", FormatStyle::SIS_OnlyFirstIf);
613 IO.enumCase(
Value,
"false", FormatStyle::SIS_Never);
614 IO.enumCase(
Value,
"true", FormatStyle::SIS_WithoutElse);
618template <>
struct ScalarEnumerationTraits<
FormatStyle::ShortLambdaStyle> {
620 IO.enumCase(
Value,
"None", FormatStyle::SLS_None);
621 IO.enumCase(
Value,
"false", FormatStyle::SLS_None);
622 IO.enumCase(
Value,
"Empty", FormatStyle::SLS_Empty);
623 IO.enumCase(
Value,
"Inline", FormatStyle::SLS_Inline);
624 IO.enumCase(
Value,
"All", FormatStyle::SLS_All);
625 IO.enumCase(
Value,
"true", FormatStyle::SLS_All);
629template <>
struct ScalarEnumerationTraits<
FormatStyle::SortIncludesOptions> {
631 IO.enumCase(
Value,
"Never", FormatStyle::SI_Never);
632 IO.enumCase(
Value,
"CaseInsensitive", FormatStyle::SI_CaseInsensitive);
633 IO.enumCase(
Value,
"CaseSensitive", FormatStyle::SI_CaseSensitive);
636 IO.enumCase(
Value,
"false", FormatStyle::SI_Never);
637 IO.enumCase(
Value,
"true", FormatStyle::SI_CaseSensitive);
642struct ScalarEnumerationTraits<
FormatStyle::SortJavaStaticImportOptions> {
644 FormatStyle::SortJavaStaticImportOptions &
Value) {
645 IO.enumCase(
Value,
"Before", FormatStyle::SJSIO_Before);
646 IO.enumCase(
Value,
"After", FormatStyle::SJSIO_After);
651struct ScalarEnumerationTraits<
FormatStyle::SortUsingDeclarationsOptions> {
653 FormatStyle::SortUsingDeclarationsOptions &
Value) {
654 IO.enumCase(
Value,
"Never", FormatStyle::SUD_Never);
655 IO.enumCase(
Value,
"Lexicographic", FormatStyle::SUD_Lexicographic);
656 IO.enumCase(
Value,
"LexicographicNumeric",
657 FormatStyle::SUD_LexicographicNumeric);
660 IO.enumCase(
Value,
"false", FormatStyle::SUD_Never);
661 IO.enumCase(
Value,
"true", FormatStyle::SUD_LexicographicNumeric);
666struct ScalarEnumerationTraits<
FormatStyle::SpaceAroundPointerQualifiersStyle> {
669 IO.enumCase(
Value,
"Default", FormatStyle::SAPQ_Default);
670 IO.enumCase(
Value,
"Before", FormatStyle::SAPQ_Before);
671 IO.enumCase(
Value,
"After", FormatStyle::SAPQ_After);
672 IO.enumCase(
Value,
"Both", FormatStyle::SAPQ_Both);
676template <>
struct MappingTraits<
FormatStyle::SpaceBeforeParensCustom> {
677 static void mapping(IO &IO, FormatStyle::SpaceBeforeParensCustom &Spacing) {
678 IO.mapOptional(
"AfterControlStatements", Spacing.AfterControlStatements);
679 IO.mapOptional(
"AfterForeachMacros", Spacing.AfterForeachMacros);
680 IO.mapOptional(
"AfterFunctionDefinitionName",
681 Spacing.AfterFunctionDefinitionName);
682 IO.mapOptional(
"AfterFunctionDeclarationName",
683 Spacing.AfterFunctionDeclarationName);
684 IO.mapOptional(
"AfterIfMacros", Spacing.AfterIfMacros);
685 IO.mapOptional(
"AfterOverloadedOperator", Spacing.AfterOverloadedOperator);
686 IO.mapOptional(
"AfterPlacementOperator", Spacing.AfterPlacementOperator);
687 IO.mapOptional(
"AfterRequiresInClause", Spacing.AfterRequiresInClause);
688 IO.mapOptional(
"AfterRequiresInExpression",
689 Spacing.AfterRequiresInExpression);
690 IO.mapOptional(
"BeforeNonEmptyParentheses",
691 Spacing.BeforeNonEmptyParentheses);
696struct ScalarEnumerationTraits<
FormatStyle::SpaceBeforeParensStyle> {
698 IO.enumCase(
Value,
"Never", FormatStyle::SBPO_Never);
699 IO.enumCase(
Value,
"ControlStatements",
700 FormatStyle::SBPO_ControlStatements);
701 IO.enumCase(
Value,
"ControlStatementsExceptControlMacros",
702 FormatStyle::SBPO_ControlStatementsExceptControlMacros);
703 IO.enumCase(
Value,
"NonEmptyParentheses",
704 FormatStyle::SBPO_NonEmptyParentheses);
705 IO.enumCase(
Value,
"Always", FormatStyle::SBPO_Always);
706 IO.enumCase(
Value,
"Custom", FormatStyle::SBPO_Custom);
709 IO.enumCase(
Value,
"false", FormatStyle::SBPO_Never);
710 IO.enumCase(
Value,
"true", FormatStyle::SBPO_ControlStatements);
711 IO.enumCase(
Value,
"ControlStatementsExceptForEachMacros",
712 FormatStyle::SBPO_ControlStatementsExceptControlMacros);
716template <>
struct ScalarEnumerationTraits<
FormatStyle::SpacesInAnglesStyle> {
718 IO.enumCase(
Value,
"Never", FormatStyle::SIAS_Never);
719 IO.enumCase(
Value,
"Always", FormatStyle::SIAS_Always);
720 IO.enumCase(
Value,
"Leave", FormatStyle::SIAS_Leave);
723 IO.enumCase(
Value,
"false", FormatStyle::SIAS_Never);
724 IO.enumCase(
Value,
"true", FormatStyle::SIAS_Always);
728template <>
struct MappingTraits<
FormatStyle::SpacesInLineComment> {
729 static void mapping(IO &IO, FormatStyle::SpacesInLineComment &Space) {
731 int signedMaximum =
static_cast<int>(Space.Maximum);
732 IO.mapOptional(
"Minimum", Space.Minimum);
733 IO.mapOptional(
"Maximum", signedMaximum);
734 Space.Maximum =
static_cast<unsigned>(signedMaximum);
736 if (Space.Maximum != -1u)
737 Space.Minimum = std::min(Space.Minimum, Space.Maximum);
741template <>
struct MappingTraits<
FormatStyle::SpacesInParensCustom> {
742 static void mapping(IO &IO, FormatStyle::SpacesInParensCustom &Spaces) {
743 IO.mapOptional(
"ExceptDoubleParentheses", Spaces.ExceptDoubleParentheses);
744 IO.mapOptional(
"InCStyleCasts", Spaces.InCStyleCasts);
745 IO.mapOptional(
"InConditionalStatements", Spaces.InConditionalStatements);
746 IO.mapOptional(
"InEmptyParentheses", Spaces.InEmptyParentheses);
747 IO.mapOptional(
"Other", Spaces.Other);
751template <>
struct ScalarEnumerationTraits<
FormatStyle::SpacesInParensStyle> {
753 IO.enumCase(
Value,
"Never", FormatStyle::SIPO_Never);
754 IO.enumCase(
Value,
"Custom", FormatStyle::SIPO_Custom);
758template <>
struct ScalarEnumerationTraits<
FormatStyle::TrailingCommaStyle> {
760 IO.enumCase(
Value,
"None", FormatStyle::TCS_None);
761 IO.enumCase(
Value,
"Wrapped", FormatStyle::TCS_Wrapped);
766struct ScalarEnumerationTraits<
FormatStyle::TrailingCommentsAlignmentKinds> {
768 FormatStyle::TrailingCommentsAlignmentKinds &
Value) {
769 IO.enumCase(
Value,
"Leave", FormatStyle::TCAS_Leave);
770 IO.enumCase(
Value,
"Always", FormatStyle::TCAS_Always);
771 IO.enumCase(
Value,
"Never", FormatStyle::TCAS_Never);
775template <>
struct MappingTraits<
FormatStyle::TrailingCommentsAlignmentStyle> {
777 FormatStyle::TrailingCommentsAlignmentStyle &
Value) {
778 IO.enumCase(
Value,
"Leave",
779 FormatStyle::TrailingCommentsAlignmentStyle(
780 {FormatStyle::TCAS_Leave, 0}));
782 IO.enumCase(
Value,
"Always",
783 FormatStyle::TrailingCommentsAlignmentStyle(
784 {FormatStyle::TCAS_Always, 0}));
786 IO.enumCase(
Value,
"Never",
787 FormatStyle::TrailingCommentsAlignmentStyle(
788 {FormatStyle::TCAS_Never, 0}));
791 IO.enumCase(
Value,
"true",
792 FormatStyle::TrailingCommentsAlignmentStyle(
793 {FormatStyle::TCAS_Always, 0}));
794 IO.enumCase(
Value,
"false",
795 FormatStyle::TrailingCommentsAlignmentStyle(
796 {FormatStyle::TCAS_Never, 0}));
800 FormatStyle::TrailingCommentsAlignmentStyle &
Value) {
801 IO.mapOptional(
"Kind",
Value.Kind);
802 IO.mapOptional(
"OverEmptyLines",
Value.OverEmptyLines);
806template <>
struct ScalarEnumerationTraits<
FormatStyle::UseTabStyle> {
808 IO.enumCase(
Value,
"Never", FormatStyle::UT_Never);
809 IO.enumCase(
Value,
"false", FormatStyle::UT_Never);
810 IO.enumCase(
Value,
"Always", FormatStyle::UT_Always);
811 IO.enumCase(
Value,
"true", FormatStyle::UT_Always);
812 IO.enumCase(
Value,
"ForIndentation", FormatStyle::UT_ForIndentation);
813 IO.enumCase(
Value,
"ForContinuationAndIndentation",
814 FormatStyle::UT_ForContinuationAndIndentation);
815 IO.enumCase(
Value,
"AlignWithSpaces", FormatStyle::UT_AlignWithSpaces);
822 IO.mapOptional(
"Language", Style.
Language);
824 StringRef BasedOnStyle;
825 if (IO.outputting()) {
826 StringRef Styles[] = {
"LLVM",
"Google",
"Chromium",
"Mozilla",
827 "WebKit",
"GNU",
"Microsoft",
"clang-format"};
828 for (StringRef StyleName : Styles) {
830 if (getPredefinedStyle(StyleName, Style.
Language, &PredefinedStyle) &&
831 Style == PredefinedStyle) {
832 BasedOnStyle = StyleName;
837 IO.mapOptional(
"BasedOnStyle", BasedOnStyle);
838 if (!BasedOnStyle.empty()) {
839 FormatStyle::LanguageKind OldLanguage = Style.
Language;
840 FormatStyle::LanguageKind Language =
842 if (!getPredefinedStyle(BasedOnStyle, Language, &Style)) {
843 IO.setError(Twine(
"Unknown value for BasedOnStyle: ", BasedOnStyle));
861 const bool IsGoogleOrChromium = BasedOnStyle.equals_insensitive(
"google") ||
862 BasedOnStyle.equals_insensitive(
"chromium");
863 bool OnCurrentLine = IsGoogleOrChromium;
864 bool OnNextLine =
true;
866 bool BreakBeforeInheritanceComma =
false;
867 bool BreakConstructorInitializersBeforeComma =
false;
869 bool DeriveLineEnding =
true;
870 bool UseCRLF =
false;
872 bool SpaceInEmptyParentheses =
false;
873 bool SpacesInConditionalStatement =
false;
874 bool SpacesInCStyleCastParentheses =
false;
875 bool SpacesInParentheses =
false;
878 if (!IO.outputting()) {
880 IO.mapOptional(
"AllowAllConstructorInitializersOnNextLine", OnNextLine);
882 IO.mapOptional(
"AlwaysBreakTemplateDeclarations",
884 IO.mapOptional(
"BreakBeforeInheritanceComma",
885 BreakBeforeInheritanceComma);
886 IO.mapOptional(
"BreakConstructorInitializersBeforeComma",
887 BreakConstructorInitializersBeforeComma);
888 IO.mapOptional(
"ConstructorInitializerAllOnOneLineOrOnePerLine",
890 IO.mapOptional(
"DeriveLineEnding", DeriveLineEnding);
893 IO.mapOptional(
"KeepEmptyLinesAtTheStartOfBlocks",
895 IO.mapOptional(
"IndentFunctionDeclarationAfterType",
899 IO.mapOptional(
"SpaceAfterControlStatementKeyword",
901 IO.mapOptional(
"SpaceInEmptyParentheses", SpaceInEmptyParentheses);
902 IO.mapOptional(
"SpacesInConditionalStatement",
903 SpacesInConditionalStatement);
904 IO.mapOptional(
"SpacesInCStyleCastParentheses",
905 SpacesInCStyleCastParentheses);
906 IO.mapOptional(
"SpacesInParentheses", SpacesInParentheses);
907 IO.mapOptional(
"UseCRLF", UseCRLF);
913 IO.mapOptional(
"AlignConsecutiveAssignments",
915 IO.mapOptional(
"AlignConsecutiveBitFields",
917 IO.mapOptional(
"AlignConsecutiveDeclarations",
920 IO.mapOptional(
"AlignConsecutiveShortCaseStatements",
922 IO.mapOptional(
"AlignConsecutiveTableGenBreakingDAGArgColons",
924 IO.mapOptional(
"AlignConsecutiveTableGenCondOperatorColons",
926 IO.mapOptional(
"AlignConsecutiveTableGenDefinitionColons",
931 IO.mapOptional(
"AllowAllArgumentsOnNextLine",
933 IO.mapOptional(
"AllowAllParametersOfDeclarationOnNextLine",
935 IO.mapOptional(
"AllowBreakBeforeNoexceptSpecifier",
937 IO.mapOptional(
"AllowShortBlocksOnASingleLine",
939 IO.mapOptional(
"AllowShortCaseExpressionOnASingleLine",
941 IO.mapOptional(
"AllowShortCaseLabelsOnASingleLine",
943 IO.mapOptional(
"AllowShortCompoundRequirementOnASingleLine",
945 IO.mapOptional(
"AllowShortEnumsOnASingleLine",
947 IO.mapOptional(
"AllowShortFunctionsOnASingleLine",
949 IO.mapOptional(
"AllowShortIfStatementsOnASingleLine",
951 IO.mapOptional(
"AllowShortLambdasOnASingleLine",
953 IO.mapOptional(
"AllowShortLoopsOnASingleLine",
955 IO.mapOptional(
"AlwaysBreakAfterDefinitionReturnType",
957 IO.mapOptional(
"AlwaysBreakBeforeMultilineStrings",
963 IO.mapOptional(
"BracedInitializerIndentWidth",
966 IO.mapOptional(
"BreakAdjacentStringLiterals",
969 IO.mapOptional(
"BreakAfterJavaFieldAnnotations",
973 IO.mapOptional(
"BreakBeforeBinaryOperators",
975 IO.mapOptional(
"BreakBeforeConceptDeclarations",
978 IO.mapOptional(
"BreakBeforeInlineASMColon",
980 IO.mapOptional(
"BreakBeforeTernaryOperators",
983 IO.mapOptional(
"BreakConstructorInitializers",
985 IO.mapOptional(
"BreakFunctionDefinitionParameters",
989 IO.mapOptional(
"BreakTemplateDeclarations",
994 IO.mapOptional(
"ConstructorInitializerIndentWidth",
1000 IO.mapOptional(
"EmptyLineAfterAccessModifier",
1002 IO.mapOptional(
"EmptyLineBeforeAccessModifier",
1004 IO.mapOptional(
"ExperimentalAutoDetectBinPacking",
1008 IO.mapOptional(
"IfMacros", Style.
IfMacros);
1012 IO.mapOptional(
"IncludeIsMainSourceRegex",
1022 IO.mapOptional(
"IndentWrappedFunctionNames",
1033 IO.mapOptional(
"LineEnding", Style.
LineEnding);
1036 IO.mapOptional(
"Macros", Style.
Macros);
1043 IO.mapOptional(
"ObjCBreakBeforeNestedBlockParam",
1045 IO.mapOptional(
"ObjCPropertyAttributeOrder",
1048 IO.mapOptional(
"ObjCSpaceBeforeProtocolList",
1050 IO.mapOptional(
"PackConstructorInitializers",
1053 IO.mapOptional(
"PenaltyBreakBeforeFirstCallParameter",
1056 IO.mapOptional(
"PenaltyBreakFirstLessLess",
1058 IO.mapOptional(
"PenaltyBreakOpenParenthesis",
1060 IO.mapOptional(
"PenaltyBreakScopeResolution",
1063 IO.mapOptional(
"PenaltyBreakTemplateDeclaration",
1066 IO.mapOptional(
"PenaltyIndentedWhitespace",
1068 IO.mapOptional(
"PenaltyReturnTypeOnItsOwnLine",
1087 IO.mapOptional(
"RequiresExpressionIndentation",
1097 IO.mapOptional(
"SpaceAfterTemplateKeyword",
1099 IO.mapOptional(
"SpaceAroundPointerQualifiers",
1101 IO.mapOptional(
"SpaceBeforeAssignmentOperators",
1104 IO.mapOptional(
"SpaceBeforeCpp11BracedList",
1106 IO.mapOptional(
"SpaceBeforeCtorInitializerColon",
1108 IO.mapOptional(
"SpaceBeforeInheritanceColon",
1113 IO.mapOptional(
"SpaceBeforeRangeBasedForLoopColon",
1115 IO.mapOptional(
"SpaceBeforeSquareBrackets",
1118 IO.mapOptional(
"SpacesBeforeTrailingComments",
1121 IO.mapOptional(
"SpacesInContainerLiterals",
1123 IO.mapOptional(
"SpacesInLineCommentPrefix",
1128 IO.mapOptional(
"Standard", Style.
Standard);
1129 IO.mapOptional(
"StatementAttributeLikeMacros",
1132 IO.mapOptional(
"TableGenBreakingDAGArgOperators",
1134 IO.mapOptional(
"TableGenBreakInsideDAGArg",
1136 IO.mapOptional(
"TabWidth", Style.
TabWidth);
1137 IO.mapOptional(
"TypeNames", Style.
TypeNames);
1139 IO.mapOptional(
"UseTab", Style.
UseTab);
1140 IO.mapOptional(
"VerilogBreakBetweenInstancePorts",
1142 IO.mapOptional(
"WhitespaceSensitiveMacros",
1151 FormatStyle::DRTBS_All) {
1154 FormatStyle::DRTBS_TopLevel) {
1161 if (BreakBeforeInheritanceComma &&
1169 if (BreakConstructorInitializersBeforeComma &&
1174 if (!IsGoogleOrChromium) {
1178 ? FormatStyle::PCIS_NextLine
1179 : FormatStyle::PCIS_CurrentLine;
1182 FormatStyle::PCIS_NextLine) {
1185 else if (!OnNextLine)
1189 if (Style.
LineEnding == FormatStyle::LE_DeriveLF) {
1190 if (!DeriveLineEnding)
1191 Style.
LineEnding = UseCRLF ? FormatStyle::LE_CRLF : FormatStyle::LE_LF;
1193 Style.
LineEnding = FormatStyle::LE_DeriveCRLF;
1197 (SpacesInParentheses || SpaceInEmptyParentheses ||
1198 SpacesInConditionalStatement || SpacesInCStyleCastParentheses)) {
1199 if (SpacesInParentheses) {
1204 SpacesInCStyleCastParentheses;
1206 SpaceInEmptyParentheses;
1211 SpacesInConditionalStatement;
1213 SpacesInCStyleCastParentheses;
1215 SpaceInEmptyParentheses;
1227template <>
struct DocumentListTraits<
std::vector<FormatStyle>> {
1228 static size_t size(IO &IO, std::vector<FormatStyle> &Seq) {
1233 if (Index >= Seq.size()) {
1234 assert(Index == Seq.size());
1236 if (!Seq.empty() && Seq[0].Language == FormatStyle::LK_None) {
1239 Template = *((
const FormatStyle *)IO.getContext());
1240 Template.
Language = FormatStyle::LK_None;
1242 Seq.resize(Index + 1, Template);
1262 return llvm::make_error<llvm::StringError>(Message,
1263 llvm::inconvertibleErrorCode());
1267 return "clang-format.parse_error";
1275 return "Invalid argument";
1277 return "Unsuitable";
1279 return "trailing comma insertion cannot be used with bin packing";
1281 return "Invalid qualifier specified in QualifierOrder";
1283 return "Duplicate qualifier specified in QualifierOrder";
1285 return "Missing type in QualifierOrder";
1287 return "Missing QualifierOrder";
1289 llvm_unreachable(
"unexpected parse error");
1516 LLVMStyle.
IfMacros.push_back(
"KJ_IF_MAYBE");
1519 {
"^\"(llvm|llvm-c|clang|clang-c)/", 2, 0,
false},
1520 {
"^(<|\"(gtest|gmock|isl|json)/)", 3, 0,
false},
1521 {
".*", 1, 0,
false}};
1665 {
"^<.*\\.h>", 1, 0,
false},
1666 {
"^<.*", 2, 0,
false},
1667 {
".*", 3, 0,
false}};
1707 "PARSE_PARTIAL_TEXT_PROTO",
1711 "ParseTextProtoOrDie",
1713 "ParsePartialTestProto",
1825 "com.google.android.apps.chrome",
1844 return ChromiumStyle;
1870 return MozillaStyle;
1963 if (Name.equals_insensitive(
"llvm"))
1965 else if (Name.equals_insensitive(
"chromium"))
1967 else if (Name.equals_insensitive(
"mozilla"))
1969 else if (Name.equals_insensitive(
"google"))
1971 else if (Name.equals_insensitive(
"webkit"))
1973 else if (Name.equals_insensitive(
"gnu"))
1975 else if (Name.equals_insensitive(
"microsoft"))
1977 else if (Name.equals_insensitive(
"clang-format"))
1979 else if (Name.equals_insensitive(
"none"))
1981 else if (Name.equals_insensitive(
"inheritparentconfig"))
1997 if (Qualifier ==
"type")
2001 if (token == tok::identifier)
2006 std::set<std::string> UniqueQualifiers(Style->
QualifierOrder.begin(),
2009 LLVM_DEBUG(llvm::dbgs()
2011 <<
" vs " << UniqueQualifiers.size() <<
"\n");
2024 llvm::SourceMgr::DiagHandlerTy DiagHandler,
2025 void *DiagHandlerCtxt) {
2029 if (Config.getBuffer().trim().empty())
2031 Style->StyleSet.
Clear();
2032 std::vector<FormatStyle> Styles;
2033 llvm::yaml::Input Input(Config,
nullptr, DiagHandler,
2039 Input.setContext(Style);
2040 Input.setAllowUnknownKeys(AllowUnknownOptions);
2043 return Input.error();
2045 for (
unsigned i = 0; i < Styles.size(); ++i) {
2050 for (
unsigned j = 0; j < i; ++j) {
2052 LLVM_DEBUG(llvm::dbgs()
2053 <<
"Duplicate languages in the config file on positions "
2054 << j <<
" and " << i <<
"\n");
2063 bool LanguageFound =
false;
2064 for (
const FormatStyle &Style : llvm::reverse(Styles)) {
2066 StyleSet.
Add(Style);
2068 LanguageFound =
true;
2070 if (!LanguageFound) {
2075 StyleSet.
Add(std::move(DefaultStyle));
2090 llvm::raw_string_ostream Stream(
Text);
2091 llvm::yaml::Output Output(Stream);
2098 Output << NonConstStyle;
2100 return Stream.str();
2103std::optional<FormatStyle>
2106 return std::nullopt;
2108 if (It == Styles->end())
2109 return std::nullopt;
2111 Style.StyleSet = *
this;
2117 "Cannot add a style for LK_None to a StyleSet");
2119 !Style.StyleSet.Styles &&
2120 "Cannot add a style associated with an existing StyleSet to a StyleSet");
2122 Styles = std::make_shared<MapType>();
2123 (*Styles)[Style.
Language] = std::move(Style);
2128std::optional<FormatStyle>
2140 std::pair<tooling::Replacements, unsigned>
2141 analyze(TokenAnnotator &Annotator,
2143 FormatTokenLexer &Tokens)
override {
2144 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2146 removeParens(AnnotatedLines, Result);
2151 void removeParens(SmallVectorImpl<AnnotatedLine *> &Lines,
2152 tooling::Replacements &Result) {
2153 const auto &SourceMgr =
Env.getSourceManager();
2154 for (
auto *Line : Lines) {
2155 removeParens(Line->Children, Result);
2156 if (!Line->Affected)
2158 for (
const auto *Token = Line->First; Token && !Token->Finalized;
2159 Token = Token->Next) {
2160 if (!Token->Optional || !Token->isOneOf(tok::l_paren, tok::r_paren))
2162 auto *Next = Token->Next;
2163 assert(Next && Next->isNot(tok::eof));
2164 SourceLocation Start;
2165 if (Next->NewlinesBefore == 0) {
2166 Start = Token->Tok.getLocation();
2167 Next->WhitespaceRange = Token->WhitespaceRange;
2169 Start = Token->WhitespaceRange.getBegin();
2172 CharSourceRange::getCharRange(Start, Token->Tok.getEndLoc());
2173 cantFail(Result.add(tooling::Replacement(SourceMgr,
Range,
" ")));
2179class BracesInserter :
public TokenAnalyzer {
2182 : TokenAnalyzer(
Env, Style) {}
2184 std::pair<tooling::Replacements, unsigned>
2185 analyze(TokenAnnotator &Annotator,
2186 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2187 FormatTokenLexer &Tokens)
override {
2188 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2189 tooling::Replacements Result;
2190 insertBraces(AnnotatedLines, Result);
2195 void insertBraces(SmallVectorImpl<AnnotatedLine *> &Lines,
2196 tooling::Replacements &Result) {
2197 const auto &SourceMgr =
Env.getSourceManager();
2198 int OpeningBraceSurplus = 0;
2199 for (AnnotatedLine *Line : Lines) {
2200 insertBraces(Line->Children, Result);
2201 if (!Line->Affected && OpeningBraceSurplus == 0)
2203 for (FormatToken *Token = Line->First; Token && !Token->Finalized;
2204 Token = Token->Next) {
2205 int BraceCount = Token->BraceCount;
2206 if (BraceCount == 0)
2209 if (BraceCount < 0) {
2210 assert(BraceCount == -1);
2211 if (!Line->Affected)
2213 Brace = Token->is(tok::comment) ?
"\n{" :
"{";
2214 ++OpeningBraceSurplus;
2216 if (OpeningBraceSurplus == 0)
2218 if (OpeningBraceSurplus < BraceCount)
2219 BraceCount = OpeningBraceSurplus;
2220 Brace =
'\n' + std::string(BraceCount,
'}');
2221 OpeningBraceSurplus -= BraceCount;
2223 Token->BraceCount = 0;
2224 const auto Start = Token->Tok.getEndLoc();
2225 cantFail(Result.add(tooling::Replacement(SourceMgr, Start, 0,
Brace)));
2228 assert(OpeningBraceSurplus == 0);
2232class BracesRemover :
public TokenAnalyzer {
2235 : TokenAnalyzer(
Env, Style) {}
2237 std::pair<tooling::Replacements, unsigned>
2238 analyze(TokenAnnotator &Annotator,
2239 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2240 FormatTokenLexer &Tokens)
override {
2241 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2242 tooling::Replacements Result;
2243 removeBraces(AnnotatedLines, Result);
2248 void removeBraces(SmallVectorImpl<AnnotatedLine *> &Lines,
2249 tooling::Replacements &Result) {
2250 const auto &SourceMgr =
Env.getSourceManager();
2251 const auto End = Lines.end();
2252 for (
auto I = Lines.begin(); I != End; ++I) {
2253 const auto Line = *I;
2254 removeBraces(Line->Children, Result);
2255 if (!Line->Affected)
2257 const auto NextLine = I + 1 == End ? nullptr : I[1];
2258 for (
auto Token = Line->First; Token && !Token->Finalized;
2259 Token = Token->Next) {
2260 if (!Token->Optional)
2262 if (!Token->isOneOf(tok::l_brace, tok::r_brace))
2264 auto Next = Token->Next;
2265 assert(Next || Token == Line->Last);
2266 if (!Next && NextLine)
2267 Next = NextLine->First;
2268 SourceLocation Start;
2269 if (Next && Next->NewlinesBefore == 0 && Next->isNot(tok::eof)) {
2270 Start = Token->Tok.getLocation();
2271 Next->WhitespaceRange = Token->WhitespaceRange;
2273 Start = Token->WhitespaceRange.getBegin();
2276 CharSourceRange::getCharRange(Start, Token->Tok.getEndLoc());
2277 cantFail(Result.add(tooling::Replacement(SourceMgr,
Range,
"")));
2283class SemiRemover :
public TokenAnalyzer {
2286 : TokenAnalyzer(
Env, Style) {}
2288 std::pair<tooling::Replacements, unsigned>
2289 analyze(TokenAnnotator &Annotator,
2290 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2291 FormatTokenLexer &Tokens)
override {
2292 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2293 tooling::Replacements Result;
2294 removeSemi(Annotator, AnnotatedLines, Result);
2299 void removeSemi(TokenAnnotator &Annotator,
2300 SmallVectorImpl<AnnotatedLine *> &Lines,
2301 tooling::Replacements &Result) {
2302 auto PrecededByFunctionRBrace = [](
const FormatToken &Tok) {
2303 const auto *Prev = Tok.Previous;
2304 if (!Prev || Prev->isNot(tok::r_brace))
2306 const auto *LBrace = Prev->MatchingParen;
2307 return LBrace && LBrace->is(TT_FunctionLBrace);
2309 const auto &SourceMgr =
Env.getSourceManager();
2310 const auto End = Lines.end();
2311 for (
auto I = Lines.begin(); I != End; ++I) {
2312 const auto Line = *I;
2313 removeSemi(Annotator, Line->Children, Result);
2314 if (!Line->Affected)
2316 Annotator.calculateFormattingInformation(*Line);
2317 const auto NextLine = I + 1 == End ? nullptr : I[1];
2318 for (
auto Token = Line->First; Token && !Token->Finalized;
2319 Token = Token->Next) {
2320 if (Token->isNot(tok::semi) ||
2321 (!Token->Optional && !PrecededByFunctionRBrace(*Token))) {
2324 auto Next = Token->Next;
2325 assert(Next || Token == Line->Last);
2326 if (!Next && NextLine)
2327 Next = NextLine->First;
2328 SourceLocation Start;
2329 if (Next && Next->NewlinesBefore == 0 && Next->isNot(tok::eof)) {
2330 Start = Token->Tok.getLocation();
2331 Next->WhitespaceRange = Token->WhitespaceRange;
2333 Start = Token->WhitespaceRange.getBegin();
2336 CharSourceRange::getCharRange(Start, Token->Tok.getEndLoc());
2337 cantFail(Result.add(tooling::Replacement(SourceMgr,
Range,
"")));
2343class JavaScriptRequoter :
public TokenAnalyzer {
2345 JavaScriptRequoter(
const Environment &
Env,
const FormatStyle &Style)
2346 : TokenAnalyzer(
Env, Style) {}
2348 std::pair<tooling::Replacements, unsigned>
2349 analyze(TokenAnnotator &Annotator,
2350 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2351 FormatTokenLexer &Tokens)
override {
2352 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2353 tooling::Replacements Result;
2354 requoteJSStringLiteral(AnnotatedLines, Result);
2361 void requoteJSStringLiteral(SmallVectorImpl<AnnotatedLine *> &Lines,
2362 tooling::Replacements &Result) {
2363 for (AnnotatedLine *Line : Lines) {
2364 requoteJSStringLiteral(Line->Children, Result);
2365 if (!Line->Affected)
2367 for (FormatToken *FormatTok = Line->First; FormatTok;
2368 FormatTok = FormatTok->Next) {
2369 StringRef Input = FormatTok->TokenText;
2370 if (FormatTok->Finalized || !FormatTok->isStringLiteral() ||
2374 !Input.starts_with(
"\"")) ||
2376 !Input.starts_with(
"\'"))) {
2382 SourceLocation Start = FormatTok->Tok.getLocation();
2383 auto Replace = [&](SourceLocation Start,
unsigned Length,
2384 StringRef ReplacementText) {
2385 auto Err = Result.add(tooling::Replacement(
2386 Env.getSourceManager(), Start, Length, ReplacementText));
2390 llvm::errs() <<
toString(std::move(Err)) <<
"\n";
2394 Replace(Start, 1, IsSingle ?
"'" :
"\"");
2395 Replace(FormatTok->Tok.getEndLoc().getLocWithOffset(-1), 1,
2396 IsSingle ?
"'" :
"\"");
2399 bool Escaped =
false;
2400 for (
size_t i = 1; i < Input.size() - 1; i++) {
2403 if (!Escaped && i + 1 < Input.size() &&
2404 ((IsSingle && Input[i + 1] ==
'"') ||
2405 (!IsSingle && Input[i + 1] ==
'\''))) {
2408 Replace(Start.getLocWithOffset(i), 1,
"");
2415 if (!Escaped && IsSingle == (Input[i] ==
'\'')) {
2417 Replace(Start.getLocWithOffset(i), 0,
"\\");
2431class Formatter :
public TokenAnalyzer {
2434 FormattingAttemptStatus *Status)
2435 : TokenAnalyzer(
Env, Style), Status(Status) {}
2437 std::pair<tooling::Replacements, unsigned>
2438 analyze(TokenAnnotator &Annotator,
2439 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2440 FormatTokenLexer &Tokens)
override {
2441 tooling::Replacements Result;
2442 deriveLocalStyle(AnnotatedLines);
2443 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2444 for (AnnotatedLine *Line : AnnotatedLines)
2445 Annotator.calculateFormattingInformation(*Line);
2446 Annotator.setCommentLineLevels(AnnotatedLines);
2448 WhitespaceManager Whitespaces(
2449 Env.getSourceManager(), Style,
2451 ? WhitespaceManager::inputUsesCRLF(
2452 Env.getSourceManager().getBufferData(
Env.getFileID()),
2453 Style.
LineEnding == FormatStyle::LE_DeriveCRLF)
2455 ContinuationIndenter
Indenter(Style, Tokens.getKeywords(),
2456 Env.getSourceManager(), Whitespaces, Encoding,
2457 BinPackInconclusiveFunctions);
2459 UnwrappedLineFormatter(&
Indenter, &Whitespaces, Style,
2460 Tokens.getKeywords(),
Env.getSourceManager(),
2462 .format(AnnotatedLines,
false,
2465 Env.getFirstStartColumn(),
2466 Env.getNextStartColumn(),
2467 Env.getLastStartColumn());
2468 for (
const auto &R : Whitespaces.generateReplacements())
2470 return std::make_pair(Result, 0);
2471 return std::make_pair(Result, Penalty);
2476 hasCpp03IncompatibleFormat(
const SmallVectorImpl<AnnotatedLine *> &Lines) {
2477 for (
const AnnotatedLine *Line : Lines) {
2478 if (hasCpp03IncompatibleFormat(Line->Children))
2480 for (FormatToken *Tok = Line->First->Next; Tok; Tok = Tok->Next) {
2481 if (!Tok->hasWhitespaceBefore()) {
2482 if (Tok->is(tok::coloncolon) && Tok->Previous->is(TT_TemplateOpener))
2484 if (Tok->is(TT_TemplateCloser) &&
2485 Tok->Previous->is(TT_TemplateCloser)) {
2494 int countVariableAlignments(
const SmallVectorImpl<AnnotatedLine *> &Lines) {
2495 int AlignmentDiff = 0;
2496 for (
const AnnotatedLine *Line : Lines) {
2497 AlignmentDiff += countVariableAlignments(Line->Children);
2498 for (FormatToken *Tok = Line->First; Tok && Tok->Next; Tok = Tok->Next) {
2499 if (Tok->isNot(TT_PointerOrReference))
2502 if (
const auto *Prev = Tok->getPreviousNonComment()) {
2503 if (Prev->is(tok::r_paren) && Prev->MatchingParen) {
2504 if (
const auto *Func =
2505 Prev->MatchingParen->getPreviousNonComment()) {
2506 if (
Func->isOneOf(TT_FunctionDeclarationName, TT_StartOfName,
2507 TT_OverloadedOperator)) {
2513 bool SpaceBefore = Tok->hasWhitespaceBefore();
2514 bool SpaceAfter = Tok->Next->hasWhitespaceBefore();
2515 if (SpaceBefore && !SpaceAfter)
2517 if (!SpaceBefore && SpaceAfter)
2521 return AlignmentDiff;
2525 deriveLocalStyle(
const SmallVectorImpl<AnnotatedLine *> &AnnotatedLines) {
2526 bool HasBinPackedFunction =
false;
2527 bool HasOnePerLineFunction =
false;
2528 for (AnnotatedLine *Line : AnnotatedLines) {
2529 if (!Line->First->Next)
2531 FormatToken *Tok = Line->First->Next;
2533 if (Tok->is(PPK_BinPacked))
2534 HasBinPackedFunction =
true;
2535 if (Tok->is(PPK_OnePerLine))
2536 HasOnePerLineFunction =
true;
2542 const auto NetRightCount = countVariableAlignments(AnnotatedLines);
2543 if (NetRightCount > 0)
2545 else if (NetRightCount < 0)
2549 if (Style.
Standard == FormatStyle::LS_Auto) {
2550 Style.
Standard = hasCpp03IncompatibleFormat(AnnotatedLines)
2551 ? FormatStyle::LS_Latest
2552 : FormatStyle::LS_Cpp03;
2554 BinPackInconclusiveFunctions =
2555 HasBinPackedFunction || !HasOnePerLineFunction;
2558 bool BinPackInconclusiveFunctions;
2559 FormattingAttemptStatus *Status;
2573class TrailingCommaInserter :
public TokenAnalyzer {
2575 TrailingCommaInserter(
const Environment &
Env,
const FormatStyle &Style)
2576 : TokenAnalyzer(
Env, Style) {}
2578 std::pair<tooling::Replacements, unsigned>
2579 analyze(TokenAnnotator &Annotator,
2580 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2581 FormatTokenLexer &Tokens)
override {
2582 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2583 tooling::Replacements Result;
2584 insertTrailingCommas(AnnotatedLines, Result);
2591 void insertTrailingCommas(SmallVectorImpl<AnnotatedLine *> &Lines,
2592 tooling::Replacements &Result) {
2593 for (AnnotatedLine *Line : Lines) {
2594 insertTrailingCommas(Line->Children, Result);
2595 if (!Line->Affected)
2597 for (FormatToken *FormatTok = Line->First; FormatTok;
2598 FormatTok = FormatTok->Next) {
2599 if (FormatTok->NewlinesBefore == 0)
2601 FormatToken *Matching = FormatTok->MatchingParen;
2602 if (!Matching || !FormatTok->getPreviousNonComment())
2604 if (!(FormatTok->is(tok::r_square) &&
2605 Matching->is(TT_ArrayInitializerLSquare)) &&
2606 !(FormatTok->is(tok::r_brace) && Matching->is(TT_DictLiteral))) {
2609 FormatToken *Prev = FormatTok->getPreviousNonComment();
2610 if (Prev->is(tok::comma) || Prev->is(tok::semi))
2614 SourceLocation Start =
2615 Prev->Tok.getLocation().getLocWithOffset(Prev->TokenText.size());
2619 unsigned ColumnNumber =
2620 Env.getSourceManager().getSpellingColumnNumber(Start);
2625 cantFail(Result.add(
2626 tooling::Replacement(
Env.getSourceManager(), Start, 0,
",")));
2634class Cleaner :
public TokenAnalyzer {
2637 : TokenAnalyzer(
Env, Style),
2638 DeletedTokens(FormatTokenLess(
Env.getSourceManager())) {}
2641 std::pair<tooling::Replacements, unsigned>
2642 analyze(TokenAnnotator &Annotator,
2643 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2644 FormatTokenLexer &Tokens)
override {
2652 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2654 checkEmptyNamespace(AnnotatedLines);
2656 for (
auto *Line : AnnotatedLines)
2659 return {generateFixes(), 0};
2663 void cleanupLine(AnnotatedLine *Line) {
2664 for (
auto *Child : Line->Children)
2667 if (Line->Affected) {
2668 cleanupRight(Line->First, tok::comma, tok::comma);
2669 cleanupRight(Line->First, TT_CtorInitializerColon, tok::comma);
2670 cleanupRight(Line->First, tok::l_paren, tok::comma);
2671 cleanupLeft(Line->First, tok::comma, tok::r_paren);
2672 cleanupLeft(Line->First, TT_CtorInitializerComma, tok::l_brace);
2673 cleanupLeft(Line->First, TT_CtorInitializerColon, tok::l_brace);
2674 cleanupLeft(Line->First, TT_CtorInitializerColon, tok::equal);
2678 bool containsOnlyComments(
const AnnotatedLine &Line) {
2679 for (FormatToken *Tok = Line.First; Tok; Tok = Tok->Next)
2680 if (Tok->isNot(tok::comment))
2686 void checkEmptyNamespace(SmallVectorImpl<AnnotatedLine *> &AnnotatedLines) {
2687 std::set<unsigned> DeletedLines;
2688 for (
unsigned i = 0, e = AnnotatedLines.size(); i != e; ++i) {
2689 auto &Line = *AnnotatedLines[i];
2690 if (Line.startsWithNamespace())
2691 checkEmptyNamespace(AnnotatedLines, i, i, DeletedLines);
2694 for (
auto Line : DeletedLines) {
2695 FormatToken *Tok = AnnotatedLines[Line]->First;
2707 bool checkEmptyNamespace(SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2708 unsigned CurrentLine,
unsigned &
NewLine,
2709 std::set<unsigned> &DeletedLines) {
2710 unsigned InitLine = CurrentLine, End = AnnotatedLines.size();
2715 if (!AnnotatedLines[++CurrentLine]->startsWith(tok::l_brace)) {
2719 }
else if (!AnnotatedLines[CurrentLine]->endsWith(tok::l_brace)) {
2722 while (++CurrentLine < End) {
2723 if (AnnotatedLines[CurrentLine]->startsWith(tok::r_brace))
2726 if (AnnotatedLines[CurrentLine]->startsWithNamespace()) {
2727 if (!checkEmptyNamespace(AnnotatedLines, CurrentLine,
NewLine,
2735 if (containsOnlyComments(*AnnotatedLines[CurrentLine]))
2745 if (CurrentLine >= End)
2749 if (!AffectedRangeMgr.affectsCharSourceRange(CharSourceRange::getCharRange(
2750 AnnotatedLines[InitLine]->First->Tok.getLocation(),
2751 AnnotatedLines[CurrentLine]->Last->Tok.getEndLoc()))) {
2755 for (
unsigned i = InitLine; i <= CurrentLine; ++i)
2756 DeletedLines.insert(i);
2765 template <
typename LeftKind,
typename RightKind>
2766 void cleanupPair(FormatToken *Start, LeftKind LK, RightKind RK,
2768 auto NextNotDeleted = [
this](
const FormatToken &Tok) -> FormatToken * {
2769 for (
auto *Res = Tok.Next; Res; Res = Res->Next) {
2770 if (Res->isNot(tok::comment) &&
2771 DeletedTokens.find(Res) == DeletedTokens.end()) {
2777 for (
auto *Left = Start;
Left;) {
2778 auto *
Right = NextNotDeleted(*Left);
2782 deleteToken(DeleteLeft ? Left : Right);
2783 for (
auto *Tok =
Left->Next; Tok && Tok != Right; Tok = Tok->Next)
2794 template <
typename LeftKind,
typename RightKind>
2795 void cleanupLeft(FormatToken *Start, LeftKind LK, RightKind RK) {
2796 cleanupPair(Start, LK, RK,
true);
2799 template <
typename LeftKind,
typename RightKind>
2800 void cleanupRight(FormatToken *Start, LeftKind LK, RightKind RK) {
2801 cleanupPair(Start, LK, RK,
false);
2805 inline void deleteToken(FormatToken *Tok) {
2807 DeletedTokens.insert(Tok);
2810 tooling::Replacements generateFixes() {
2811 tooling::Replacements Fixes;
2812 SmallVector<FormatToken *> Tokens;
2813 std::copy(DeletedTokens.begin(), DeletedTokens.end(),
2814 std::back_inserter(Tokens));
2820 while (Idx < Tokens.size()) {
2821 unsigned St = Idx, End = Idx;
2822 while ((End + 1) < Tokens.size() && Tokens[End]->Next == Tokens[End + 1])
2824 auto SR = CharSourceRange::getCharRange(Tokens[St]->Tok.getLocation(),
2825 Tokens[End]->Tok.getEndLoc());
2827 Fixes.add(tooling::Replacement(
Env.getSourceManager(), SR,
""));
2831 llvm::errs() <<
toString(std::move(Err)) <<
"\n";
2832 assert(
false &&
"Fixes must not conflict!");
2843 struct FormatTokenLess {
2844 FormatTokenLess(
const SourceManager &
SM) :
SM(
SM) {}
2846 bool operator()(
const FormatToken *LHS,
const FormatToken *RHS)
const {
2847 return SM.isBeforeInTranslationUnit(LHS->Tok.getLocation(),
2848 RHS->Tok.getLocation());
2854 std::set<FormatToken *, FormatTokenLess> DeletedTokens;
2857class ObjCHeaderStyleGuesser :
public TokenAnalyzer {
2859 ObjCHeaderStyleGuesser(
const Environment &
Env,
const FormatStyle &Style)
2860 : TokenAnalyzer(
Env, Style), IsObjC(
false) {}
2862 std::pair<tooling::Replacements, unsigned>
2863 analyze(TokenAnnotator &Annotator,
2864 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2865 FormatTokenLexer &Tokens)
override {
2866 assert(Style.
Language == FormatStyle::LK_Cpp);
2867 IsObjC = guessIsObjC(
Env.getSourceManager(), AnnotatedLines,
2868 Tokens.getKeywords());
2869 tooling::Replacements Result;
2873 bool isObjC() {
return IsObjC; }
2877 guessIsObjC(
const SourceManager &SourceManager,
2878 const SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2879 const AdditionalKeywords &Keywords) {
2881 static constexpr llvm::StringLiteral FoundationIdentifiers[] = {
2896 "FOUNDATION_EXPORT",
2897 "FOUNDATION_EXTERN",
2898 "NSAffineTransform",
2900 "NSAttributedString",
2919 "NSInvocationOperation",
2923 "NSMutableAttributedString",
2924 "NSMutableCharacterSet",
2926 "NSMutableDictionary",
2927 "NSMutableIndexSet",
2928 "NSMutableOrderedSet",
2932 "NSNumberFormatter",
2936 "NSOperationQueuePriority",
2940 "NSQualityOfService",
2943 "NSRegularExpression",
2954 "NS_ASSUME_NONNULL_BEGIN",
2959 for (
auto *Line : AnnotatedLines) {
2960 if (Line->First && (Line->First->TokenText.starts_with(
"#") ||
2961 Line->First->TokenText ==
"__pragma" ||
2962 Line->First->TokenText ==
"_Pragma")) {
2965 for (
const FormatToken *FormatTok = Line->First; FormatTok;
2966 FormatTok = FormatTok->Next) {
2967 if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&
2968 (FormatTok->Tok.getObjCKeywordID() != tok::objc_not_keyword ||
2969 FormatTok->isOneOf(tok::numeric_constant, tok::l_square,
2971 (FormatTok->Tok.isAnyIdentifier() &&
2972 std::binary_search(std::begin(FoundationIdentifiers),
2973 std::end(FoundationIdentifiers),
2974 FormatTok->TokenText)) ||
2975 FormatTok->is(TT_ObjCStringLiteral) ||
2976 FormatTok->isOneOf(Keywords.kw_NS_CLOSED_ENUM, Keywords.kw_NS_ENUM,
2977 Keywords.kw_NS_ERROR_ENUM,
2978 Keywords.kw_NS_OPTIONS, TT_ObjCBlockLBrace,
2979 TT_ObjCBlockLParen, TT_ObjCDecl, TT_ObjCForIn,
2980 TT_ObjCMethodExpr, TT_ObjCMethodSpecifier,
2982 LLVM_DEBUG(llvm::dbgs()
2983 <<
"Detected ObjC at location "
2984 << FormatTok->Tok.getLocation().printToString(
2986 <<
" token: " << FormatTok->TokenText <<
" token type: "
2991 if (guessIsObjC(SourceManager, Line->Children, Keywords))
3008struct JavaImportDirective {
3021 for (
const auto &
Range : Ranges) {
3022 if (
Range.getOffset() < End &&
3023 Range.getOffset() +
Range.getLength() > Start) {
3037static std::pair<unsigned, unsigned>
3041 unsigned OffsetToEOL = 0;
3042 for (
int i = 0, e = Includes.size(); i != e; ++i) {
3043 unsigned Start = Includes[Indices[i]].Offset;
3044 unsigned End = Start + Includes[Indices[i]].Text.size();
3045 if (!(Cursor >= Start && Cursor < End))
3047 CursorIndex = Indices[i];
3048 OffsetToEOL = End - Cursor;
3051 while (--i >= 0 && Includes[CursorIndex].
Text == Includes[Indices[i]].
Text)
3055 return std::make_pair(CursorIndex, OffsetToEOL);
3060 std::string NewCode;
3061 size_t Pos = 0, LastPos = 0;
3064 Pos = Code.find(
"\r\n", LastPos);
3065 if (Pos == LastPos) {
3069 if (Pos == std::string::npos) {
3070 NewCode += Code.substr(LastPos);
3073 NewCode += Code.substr(LastPos, Pos - LastPos) +
"\n";
3075 }
while (Pos != std::string::npos);
3093 const unsigned IncludesBeginOffset = Includes.front().Offset;
3094 const unsigned IncludesEndOffset =
3095 Includes.back().Offset + Includes.back().Text.size();
3096 const unsigned IncludesBlockSize = IncludesEndOffset - IncludesBeginOffset;
3097 if (!
affectsRange(Ranges, IncludesBeginOffset, IncludesEndOffset))
3100 llvm::to_vector<16>(llvm::seq<unsigned>(0, Includes.size()));
3103 stable_sort(Indices, [&](
unsigned LHSI,
unsigned RHSI) {
3104 const auto LHSFilenameLower = Includes[LHSI].Filename.lower();
3105 const auto RHSFilenameLower = Includes[RHSI].Filename.lower();
3106 return std::tie(Includes[LHSI].
Priority, LHSFilenameLower,
3108 std::tie(Includes[RHSI].
Priority, RHSFilenameLower,
3112 stable_sort(Indices, [&](
unsigned LHSI,
unsigned RHSI) {
3120 unsigned CursorIndex;
3122 unsigned CursorToEOLOffset;
3124 std::tie(CursorIndex, CursorToEOLOffset) =
3129 Indices.erase(std::unique(Indices.begin(), Indices.end(),
3130 [&](
unsigned LHSI,
unsigned RHSI) {
3131 return Includes[LHSI].Text.trim() ==
3132 Includes[RHSI].Text.trim();
3136 int CurrentCategory = Includes.front().Category;
3144 if (Indices.size() == Includes.size() && is_sorted(Indices) &&
3149 const auto OldCursor = Cursor ? *Cursor : 0;
3151 for (
unsigned Index : Indices) {
3152 if (!result.empty()) {
3156 CurrentCategory != Includes[Index].Category) {
3160 result += Includes[Index].Text;
3161 if (Cursor && CursorIndex == Index)
3162 *Cursor = IncludesBeginOffset + result.size() - CursorToEOLOffset;
3163 CurrentCategory = Includes[Index].Category;
3166 if (Cursor && *Cursor >= IncludesEndOffset)
3167 *Cursor += result.size() - IncludesBlockSize;
3172 IncludesBeginOffset, IncludesBlockSize)))) {
3174 *Cursor = OldCursor;
3179 FileName, Includes.front().Offset, IncludesBlockSize, result));
3183 llvm::errs() <<
toString(std::move(Err)) <<
"\n";
3193 unsigned Prev = llvm::StringSwitch<size_t>(Code)
3194 .StartsWith(
"\xEF\xBB\xBF", 3)
3196 unsigned SearchFrom = 0;
3208 bool FirstIncludeBlock =
true;
3209 bool MainIncludeFound =
false;
3210 bool FormattingOff =
false;
3213 llvm::Regex RawStringRegex(
3214 "R\"([][A-Za-z0-9_{}#<>%:;.?*+/^&\\$|~!=,'-]*)\\(");
3216 std::string RawStringTermination =
")\"";
3219 auto Pos = Code.find(
'\n', SearchFrom);
3221 Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev);
3223 StringRef Trimmed =
Line.trim();
3228 if (RawStringRegex.match(Trimmed, &RawStringMatches)) {
3229 std::string CharSequence = RawStringMatches[1].str();
3230 RawStringTermination =
")" + CharSequence +
"\"";
3231 FormattingOff =
true;
3234 if (Trimmed.contains(RawStringTermination))
3235 FormattingOff =
false;
3237 bool IsBlockComment =
false;
3240 FormattingOff =
true;
3242 FormattingOff =
false;
3243 }
else if (Trimmed.starts_with(
"/*")) {
3244 IsBlockComment =
true;
3245 Pos = Code.find(
"*/", SearchFrom + 2);
3248 const bool EmptyLineSkipped =
3254 bool MergeWithNextLine = Trimmed.ends_with(
"\\");
3255 if (!FormattingOff && !MergeWithNextLine) {
3256 if (!IsBlockComment &&
3258 StringRef IncludeName = Matches[2];
3259 if (Trimmed.contains(
"/*") && !Trimmed.contains(
"*/")) {
3264 Pos = Code.find(
"*/", SearchFrom);
3266 Prev, (Pos != StringRef::npos ? Pos + 2 : Code.size()) - Prev);
3270 !MainIncludeFound && FirstIncludeBlock);
3272 IncludeName, !MainIncludeFound && FirstIncludeBlock);
3274 MainIncludeFound =
true;
3275 IncludesInBlock.push_back(
3277 }
else if (!IncludesInBlock.empty() && !EmptyLineSkipped) {
3280 IncludesInBlock.clear();
3281 if (Trimmed.starts_with(
"#pragma hdrstop"))
3282 FirstIncludeBlock =
true;
3284 FirstIncludeBlock =
false;
3287 if (Pos == StringRef::npos || Pos + 1 == Code.size())
3290 if (!MergeWithNextLine)
3292 SearchFrom = Pos + 1;
3294 if (!IncludesInBlock.empty()) {
3304 StringRef ImportIdentifier) {
3305 unsigned LongestMatchIndex =
UINT_MAX;
3306 unsigned LongestMatchLength = 0;
3309 if (ImportIdentifier.starts_with(GroupPrefix) &&
3310 GroupPrefix.length() > LongestMatchLength) {
3311 LongestMatchIndex = I;
3312 LongestMatchLength = GroupPrefix.length();
3315 return LongestMatchIndex;
3327 unsigned ImportsBeginOffset = Imports.front().Offset;
3328 unsigned ImportsEndOffset =
3329 Imports.back().Offset + Imports.back().Text.size();
3330 unsigned ImportsBlockSize = ImportsEndOffset - ImportsBeginOffset;
3331 if (!
affectsRange(Ranges, ImportsBeginOffset, ImportsEndOffset))
3335 llvm::to_vector<16>(llvm::seq<unsigned>(0, Imports.size()));
3338 for (
const JavaImportDirective &Import : Imports)
3341 bool StaticImportAfterNormalImport =
3343 sort(Indices, [&](
unsigned LHSI,
unsigned RHSI) {
3345 return std::make_tuple(!Imports[LHSI].
IsStatic ^
3346 StaticImportAfterNormalImport,
3348 std::make_tuple(!Imports[RHSI].
IsStatic ^
3349 StaticImportAfterNormalImport,
3354 Indices.erase(std::unique(Indices.begin(), Indices.end(),
3355 [&](
unsigned LHSI,
unsigned RHSI) {
3356 return Imports[LHSI].Text == Imports[RHSI].Text;
3360 bool CurrentIsStatic = Imports[Indices.front()].IsStatic;
3364 for (
unsigned Index : Indices) {
3365 if (!result.empty()) {
3367 if (CurrentIsStatic != Imports[Index].
IsStatic ||
3373 result += CommentLine;
3376 result += Imports[Index].Text;
3377 CurrentIsStatic = Imports[Index].IsStatic;
3384 Imports.front().Offset, ImportsBlockSize)))) {
3389 ImportsBlockSize, result));
3393 llvm::errs() <<
toString(std::move(Err)) <<
"\n";
3400const char JavaImportRegexPattern[] =
3401 "^[\t ]*import[\t ]+(static[\t ]*)?([^\t ]*)[\t ]*;";
3410 unsigned SearchFrom = 0;
3411 llvm::Regex ImportRegex(JavaImportRegexPattern);
3416 bool FormattingOff =
false;
3419 auto Pos = Code.find(
'\n', SearchFrom);
3421 Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev);
3423 StringRef Trimmed =
Line.trim();
3425 FormattingOff =
true;
3427 FormattingOff =
false;
3429 if (ImportRegex.match(
Line, &Matches)) {
3430 if (FormattingOff) {
3435 StringRef
Static = Matches[1];
3438 if (
Static.contains(
"static"))
3440 ImportsInBlock.push_back(
3443 }
else if (Trimmed.size() > 0 && !ImportsInBlock.empty()) {
3448 if (Pos == StringRef::npos || Pos + 1 == Code.size())
3450 SearchFrom = Pos + 1;
3452 if (!ImportsInBlock.empty())
3461 return Code.size() > 188 && Code[0] == 0x47 && Code[188] == 0x47;
3464bool isLikelyXml(StringRef Code) {
return Code.ltrim().starts_with(
"<"); }
3468 StringRef
FileName,
unsigned *Cursor) {
3486template <
typename T>
3491 if (Replaces.
empty())
3494 auto NewCode = applyAllReplacements(Code, Replaces);
3496 return NewCode.takeError();
3501 ProcessFunc(Style, *NewCode, ChangedRanges,
FileName);
3503 return Replaces.
merge(FormatReplaces);
3512 std::vector<tooling::Range> Ranges,
3516 auto SortedReplaces =
3518 if (!SortedReplaces)
3519 return SortedReplaces.takeError();
3523 auto Reformat = [](
const FormatStyle &Style, StringRef Code,
3524 std::vector<tooling::Range> Ranges,
3539inline bool isHeaderDeletion(
const tooling::Replacement &Replace) {
3540 return Replace.getOffset() ==
UINT_MAX && Replace.getLength() == 1;
3544tooling::Replacements
3545fixCppIncludeInsertions(StringRef Code,
const tooling::Replacements &Replaces,
3550 tooling::Replacements HeaderInsertions;
3551 std::set<StringRef> HeadersToDelete;
3552 tooling::Replacements
Result;
3553 for (
const auto &R : Replaces) {
3554 if (isHeaderInsertion(R)) {
3557 consumeError(HeaderInsertions.add(R));
3558 }
else if (isHeaderDeletion(R)) {
3559 HeadersToDelete.insert(R.getReplacementText());
3560 }
else if (R.getOffset() ==
UINT_MAX) {
3561 llvm::errs() <<
"Insertions other than header #include insertion are "
3563 << R.getReplacementText() <<
"\n";
3565 consumeError(
Result.add(R));
3568 if (HeaderInsertions.empty() && HeadersToDelete.empty())
3571 StringRef
FileName = Replaces.begin()->getFilePath();
3574 for (
const auto &Header : HeadersToDelete) {
3575 tooling::Replacements Replaces =
3576 Includes.remove(Header.trim(
"\"<>"), Header.starts_with(
"<"));
3577 for (
const auto &R : Replaces) {
3578 auto Err =
Result.add(R);
3581 llvm::errs() <<
"Failed to add header deletion replacement for "
3582 << Header <<
": " <<
toString(std::move(Err)) <<
"\n";
3587 SmallVector<StringRef, 4> Matches;
3588 for (
const auto &R : HeaderInsertions) {
3592 assert(Matched &&
"Header insertion replacement must have replacement text "
3595 auto IncludeName = Matches[2];
3597 Includes.insert(IncludeName.trim(
"\"<>"), IncludeName.starts_with(
"<"),
3600 auto Err =
Result.add(*Replace);
3602 consumeError(std::move(Err));
3603 unsigned NewOffset =
3604 Result.getShiftedCodePosition(Replace->getOffset());
3605 auto Shifted = tooling::Replacement(
FileName, NewOffset, 0,
3606 Replace->getReplacementText());
3616Expected<tooling::Replacements>
3621 auto Cleanup = [](
const FormatStyle &Style, StringRef Code,
3628 fixCppIncludeInsertions(Code, Replaces, Style);
3633std::pair<tooling::Replacements, unsigned>
3636 unsigned NextStartColumn,
unsigned LastStartColumn, StringRef FileName,
3647 case FormatStyle::RCPS_SingleLine:
3648 case FormatStyle::RCPS_WithPreceding:
3664 std::vector<tooling::Range> Ranges(1,
tooling::Range(0, Code.size()));
3665 auto Env = Environment::make(Code,
FileName, Ranges, FirstStartColumn,
3666 NextStartColumn, LastStartColumn);
3671 Formatter(*
Env, Style, Status).process().first;
3673 Replaces = Replaces.
merge(
3676 if (applyAllReplacements(Code, Replaces))
3677 return {Replaces, 0};
3681 auto Env = Environment::make(Code,
FileName, Ranges, FirstStartColumn,
3682 NextStartColumn, LastStartColumn);
3686 typedef std::function<std::pair<tooling::Replacements, unsigned>(
3696 if (Style.
isCpp()) {
3703 Passes.emplace_back([&, S = std::move(S)](
const Environment &
Env) {
3704 return ParensRemover(
Env, S).process(
true);
3710 S.InsertBraces =
true;
3711 Passes.emplace_back([&, S = std::move(S)](
const Environment &
Env) {
3712 return BracesInserter(
Env, S).process(
true);
3718 S.RemoveBracesLLVM =
true;
3719 Passes.emplace_back([&, S = std::move(S)](
const Environment &
Env) {
3720 return BracesRemover(
Env, S).process(
true);
3726 S.RemoveSemicolon =
true;
3727 Passes.emplace_back([&, S = std::move(S)](
const Environment &
Env) {
3728 return SemiRemover(
Env, S).process();
3751 if (Style.
Language == FormatStyle::LK_ObjC &&
3761 return JavaScriptRequoter(
Env, Expanded).process(
true);
3766 return Formatter(
Env, Expanded, Status).process();
3772 return TrailingCommaInserter(
Env, Expanded).process();
3776 std::optional<std::string> CurrentCode;
3778 unsigned Penalty = 0;
3779 for (
size_t I = 0,
E = Passes.size(); I <
E; ++I) {
3780 std::pair<tooling::Replacements, unsigned> PassFixes = Passes[I](*Env);
3781 auto NewCode = applyAllReplacements(
3782 CurrentCode ? StringRef(*CurrentCode) : Code, PassFixes.first);
3784 Fixes = Fixes.
merge(PassFixes.first);
3785 Penalty += PassFixes.second;
3787 CurrentCode = std::move(*NewCode);
3788 Env = Environment::make(
3790 tooling::calculateRangesAfterReplacements(Fixes, Ranges),
3791 FirstStartColumn, NextStartColumn, LastStartColumn);
3804 StringRef OriginalCode = Code.substr(Fix.getOffset(), Fix.getLength());
3805 if (OriginalCode != Fix.getReplacementText()) {
3806 auto Err = NonNoOpFixes.
add(Fix);
3808 llvm::errs() <<
"Error adding replacements : "
3809 <<
toString(std::move(Err)) <<
"\n";
3813 Fixes = std::move(NonNoOpFixes);
3816 return {Fixes, Penalty};
3840 return Cleaner(*
Env, Style).process().first;
3845 StringRef
FileName,
bool *IncompleteFormat) {
3848 if (!Status.FormatComplete)
3849 *IncompleteFormat =
true;
3881 LangOpts.CPlusPlus = 1;
3892 LangOpts.LineComment = 1;
3893 LangOpts.CXXOperatorNames = Style.
isCpp();
3896 LangOpts.MicrosoftExt = 1;
3897 LangOpts.DeclSpecKeyword = 1;
3903 "Set coding style. <string> can be:\n"
3904 "1. A preset: LLVM, GNU, Google, Chromium, Microsoft,\n"
3905 " Mozilla, WebKit.\n"
3906 "2. 'file' to load style configuration from a\n"
3907 " .clang-format file in one of the parent directories\n"
3908 " of the source file (for stdin, see --assume-filename).\n"
3909 " If no .clang-format file is found, falls back to\n"
3910 " --fallback-style.\n"
3911 " --style=file is the default.\n"
3912 "3. 'file:<format_file_path>' to explicitly specify\n"
3913 " the configuration file.\n"
3914 "4. \"{key: value, ...}\" to set specific parameters, e.g.:\n"
3915 " --style=\"{BasedOnStyle: llvm, IndentWidth: 8}\"";
3920 if (
FileName.ends_with_insensitive(
".js") ||
3921 FileName.ends_with_insensitive(
".mjs") ||
3922 FileName.ends_with_insensitive(
".ts")) {
3927 if (
FileName.ends_with_insensitive(
".proto") ||
3928 FileName.ends_with_insensitive(
".protodevel")) {
3934 if (
FileName.ends_with_insensitive(
".txtpb") ||
3935 FileName.ends_with_insensitive(
".textpb") ||
3936 FileName.ends_with_insensitive(
".pb.txt") ||
3937 FileName.ends_with_insensitive(
".textproto") ||
3938 FileName.ends_with_insensitive(
".asciipb")) {
3941 if (
FileName.ends_with_insensitive(
".td"))
3943 if (
FileName.ends_with_insensitive(
".cs"))
3945 if (
FileName.ends_with_insensitive(
".json"))
3947 if (
FileName.ends_with_insensitive(
".sv") ||
3948 FileName.ends_with_insensitive(
".svh") ||
3949 FileName.ends_with_insensitive(
".v") ||
3950 FileName.ends_with_insensitive(
".vh")) {
3959 auto Extension = llvm::sys::path::extension(
FileName);
3962 if (!Code.empty() && (Extension.empty() || Extension ==
".h")) {
3967 if (Guesser.isObjC())
3971 return GuessedLanguage;
3979llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
3982 llvm::SourceMgr::DiagHandlerTy DiagHandler) {
3983 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
Text =
3984 FS->getBufferForFile(ConfigFile.str());
3985 if (
auto EC =
Text.getError())
3995 StringRef FallbackStyleName, StringRef Code,
3996 llvm::vfs::FileSystem *FS,
3997 bool AllowUnknownOptions,
3998 llvm::SourceMgr::DiagHandlerTy DiagHandler) {
4006 if (StyleName.starts_with(
"{")) {
4008 StringRef Source =
"<command-line>";
4009 if (std::error_code ec =
4011 AllowUnknownOptions, DiagHandler)) {
4018 ChildFormatTextToApply.emplace_back(
4019 llvm::MemoryBuffer::getMemBuffer(StyleName, Source,
false));
4023 FS = llvm::vfs::getRealFileSystem().get();
4028 StyleName.starts_with_insensitive(
"file:")) {
4029 auto ConfigFile = StyleName.substr(5);
4030 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
Text =
4033 if (
auto EC =
Text.getError()) {
4038 LLVM_DEBUG(llvm::dbgs()
4039 <<
"Using configuration file " << ConfigFile <<
"\n");
4047 ChildFormatTextToApply.emplace_back(std::move(*
Text));
4061 if (std::error_code EC = FS->makeAbsolute(
Path))
4067 auto dropDiagnosticHandler = [](
const llvm::SMDiagnostic &,
void *) {};
4069 auto applyChildFormatTexts = [&](
FormatStyle *Style) {
4070 for (
const auto &MemBuf : llvm::reverse(ChildFormatTextToApply)) {
4073 DiagHandler ? DiagHandler : dropDiagnosticHandler);
4076 static_cast<void>(EC);
4082 FilesToLookFor.push_back(
".clang-format");
4083 FilesToLookFor.push_back(
"_clang-format");
4086 for (StringRef Directory =
Path; !Directory.empty();
4087 Directory = llvm::sys::path::parent_path(Directory)) {
4088 auto Status = FS->status(Directory);
4090 Status->getType() != llvm::sys::fs::file_type::directory_file) {
4094 for (
const auto &F : FilesToLookFor) {
4097 llvm::sys::path::append(ConfigFile, F);
4098 LLVM_DEBUG(llvm::dbgs() <<
"Trying " << ConfigFile <<
"...\n");
4100 Status = FS->status(ConfigFile);
4102 Status->getType() != llvm::sys::fs::file_type::regular_file) {
4106 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
Text =
4109 if (
auto EC =
Text.getError()) {
4114 if (!UnsuitableConfigFiles.empty())
4115 UnsuitableConfigFiles.append(
", ");
4116 UnsuitableConfigFiles.append(ConfigFile);
4120 LLVM_DEBUG(llvm::dbgs()
4121 <<
"Using configuration file " << ConfigFile <<
"\n");
4124 if (!ChildFormatTextToApply.empty()) {
4125 LLVM_DEBUG(llvm::dbgs() <<
"Applying child configurations\n");
4126 applyChildFormatTexts(&Style);
4131 LLVM_DEBUG(llvm::dbgs() <<
"Inherits parent configuration\n");
4136 ChildFormatTextToApply.emplace_back(std::move(*
Text));
4146 if (!UnsuitableConfigFiles.empty()) {
4149 UnsuitableConfigFiles);
4152 if (!ChildFormatTextToApply.empty()) {
4153 LLVM_DEBUG(llvm::dbgs()
4154 <<
"Applying child configurations on fallback style\n");
4155 applyChildFormatTexts(&FallbackStyle);
4158 return FallbackStyle;
4162 if (Comment == (On ?
"/* clang-format on */" :
"/* clang-format off */"))
4165 static const char ClangFormatOn[] =
"// clang-format on";
4166 static const char ClangFormatOff[] =
"// clang-format off";
4167 const unsigned Size = (On ?
sizeof ClangFormatOn :
sizeof ClangFormatOff) - 1;
4169 return Comment.starts_with(On ? ClangFormatOn : ClangFormatOff) &&
4170 (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 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...
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
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).
The JSON file list parser is used to communicate input to InstallAPI.
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.
const FunctionProtoType * T
Diagnostic wrappers for TextAPI types for error reporting.
static void enumeration(IO &IO, FormatStyle::IndentExternBlockStyle &Value)
static void enumeration(IO &IO, FormatStyle::LambdaBodyIndentationKind &Value)