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::BreakConstructorInitializersStyle> {
251 IO.enumCase(
Value,
"BeforeColon", FormatStyle::BCIS_BeforeColon);
252 IO.enumCase(
Value,
"BeforeComma", FormatStyle::BCIS_BeforeComma);
253 IO.enumCase(
Value,
"AfterColon", FormatStyle::BCIS_AfterColon);
258struct ScalarEnumerationTraits<
FormatStyle::BreakInheritanceListStyle> {
260 FormatStyle::BreakInheritanceListStyle &
Value) {
261 IO.enumCase(
Value,
"BeforeColon", FormatStyle::BILS_BeforeColon);
262 IO.enumCase(
Value,
"BeforeComma", FormatStyle::BILS_BeforeComma);
263 IO.enumCase(
Value,
"AfterColon", FormatStyle::BILS_AfterColon);
264 IO.enumCase(
Value,
"AfterComma", FormatStyle::BILS_AfterComma);
269struct ScalarEnumerationTraits<
FormatStyle::BreakTemplateDeclarationsStyle> {
271 FormatStyle::BreakTemplateDeclarationsStyle &
Value) {
272 IO.enumCase(
Value,
"Leave", FormatStyle::BTDS_Leave);
273 IO.enumCase(
Value,
"No", FormatStyle::BTDS_No);
274 IO.enumCase(
Value,
"MultiLine", FormatStyle::BTDS_MultiLine);
275 IO.enumCase(
Value,
"Yes", FormatStyle::BTDS_Yes);
278 IO.enumCase(
Value,
"false", FormatStyle::BTDS_MultiLine);
279 IO.enumCase(
Value,
"true", FormatStyle::BTDS_Yes);
283template <>
struct ScalarEnumerationTraits<
FormatStyle::DAGArgStyle> {
285 IO.enumCase(
Value,
"DontBreak", FormatStyle::DAS_DontBreak);
286 IO.enumCase(
Value,
"BreakElements", FormatStyle::DAS_BreakElements);
287 IO.enumCase(
Value,
"BreakAll", FormatStyle::DAS_BreakAll);
292struct ScalarEnumerationTraits<
FormatStyle::DefinitionReturnTypeBreakingStyle> {
295 IO.enumCase(
Value,
"None", FormatStyle::DRTBS_None);
296 IO.enumCase(
Value,
"All", FormatStyle::DRTBS_All);
297 IO.enumCase(
Value,
"TopLevel", FormatStyle::DRTBS_TopLevel);
300 IO.enumCase(
Value,
"false", FormatStyle::DRTBS_None);
301 IO.enumCase(
Value,
"true", FormatStyle::DRTBS_All);
306struct ScalarEnumerationTraits<
FormatStyle::EscapedNewlineAlignmentStyle> {
308 FormatStyle::EscapedNewlineAlignmentStyle &
Value) {
309 IO.enumCase(
Value,
"DontAlign", FormatStyle::ENAS_DontAlign);
310 IO.enumCase(
Value,
"Left", FormatStyle::ENAS_Left);
311 IO.enumCase(
Value,
"LeftWithLastLine", FormatStyle::ENAS_LeftWithLastLine);
312 IO.enumCase(
Value,
"Right", FormatStyle::ENAS_Right);
315 IO.enumCase(
Value,
"true", FormatStyle::ENAS_Left);
316 IO.enumCase(
Value,
"false", FormatStyle::ENAS_Right);
321struct ScalarEnumerationTraits<
FormatStyle::EmptyLineAfterAccessModifierStyle> {
324 IO.enumCase(
Value,
"Never", FormatStyle::ELAAMS_Never);
325 IO.enumCase(
Value,
"Leave", FormatStyle::ELAAMS_Leave);
326 IO.enumCase(
Value,
"Always", FormatStyle::ELAAMS_Always);
331struct ScalarEnumerationTraits<
335 IO.enumCase(
Value,
"Never", FormatStyle::ELBAMS_Never);
336 IO.enumCase(
Value,
"Leave", FormatStyle::ELBAMS_Leave);
337 IO.enumCase(
Value,
"LogicalBlock", FormatStyle::ELBAMS_LogicalBlock);
338 IO.enumCase(
Value,
"Always", FormatStyle::ELBAMS_Always);
343struct ScalarEnumerationTraits<
FormatStyle::IndentExternBlockStyle> {
345 IO.enumCase(
Value,
"AfterExternBlock", FormatStyle::IEBS_AfterExternBlock);
346 IO.enumCase(
Value,
"Indent", FormatStyle::IEBS_Indent);
347 IO.enumCase(
Value,
"NoIndent", FormatStyle::IEBS_NoIndent);
348 IO.enumCase(
Value,
"true", FormatStyle::IEBS_Indent);
349 IO.enumCase(
Value,
"false", FormatStyle::IEBS_NoIndent);
353template <>
struct MappingTraits<
FormatStyle::IntegerLiteralSeparatorStyle> {
354 static void mapping(IO &IO, FormatStyle::IntegerLiteralSeparatorStyle &
Base) {
355 IO.mapOptional(
"Binary",
Base.Binary);
356 IO.mapOptional(
"BinaryMinDigits",
Base.BinaryMinDigits);
357 IO.mapOptional(
"Decimal",
Base.Decimal);
358 IO.mapOptional(
"DecimalMinDigits",
Base.DecimalMinDigits);
359 IO.mapOptional(
"Hex",
Base.Hex);
360 IO.mapOptional(
"HexMinDigits",
Base.HexMinDigits);
364template <>
struct ScalarEnumerationTraits<
FormatStyle::JavaScriptQuoteStyle> {
366 IO.enumCase(
Value,
"Leave", FormatStyle::JSQS_Leave);
367 IO.enumCase(
Value,
"Single", FormatStyle::JSQS_Single);
368 IO.enumCase(
Value,
"Double", FormatStyle::JSQS_Double);
372template <>
struct MappingTraits<
FormatStyle::KeepEmptyLinesStyle> {
374 IO.mapOptional(
"AtEndOfFile",
Value.AtEndOfFile);
375 IO.mapOptional(
"AtStartOfBlock",
Value.AtStartOfBlock);
376 IO.mapOptional(
"AtStartOfFile",
Value.AtStartOfFile);
380template <>
struct ScalarEnumerationTraits<
FormatStyle::LanguageKind> {
382 IO.enumCase(
Value,
"Cpp", FormatStyle::LK_Cpp);
383 IO.enumCase(
Value,
"Java", FormatStyle::LK_Java);
384 IO.enumCase(
Value,
"JavaScript", FormatStyle::LK_JavaScript);
385 IO.enumCase(
Value,
"ObjC", FormatStyle::LK_ObjC);
386 IO.enumCase(
Value,
"Proto", FormatStyle::LK_Proto);
387 IO.enumCase(
Value,
"TableGen", FormatStyle::LK_TableGen);
388 IO.enumCase(
Value,
"TextProto", FormatStyle::LK_TextProto);
389 IO.enumCase(
Value,
"CSharp", FormatStyle::LK_CSharp);
390 IO.enumCase(
Value,
"Json", FormatStyle::LK_Json);
391 IO.enumCase(
Value,
"Verilog", FormatStyle::LK_Verilog);
395template <>
struct ScalarEnumerationTraits<
FormatStyle::LanguageStandard> {
397 IO.enumCase(
Value,
"c++03", FormatStyle::LS_Cpp03);
398 IO.enumCase(
Value,
"C++03", FormatStyle::LS_Cpp03);
399 IO.enumCase(
Value,
"Cpp03", FormatStyle::LS_Cpp03);
401 IO.enumCase(
Value,
"c++11", FormatStyle::LS_Cpp11);
402 IO.enumCase(
Value,
"C++11", FormatStyle::LS_Cpp11);
404 IO.enumCase(
Value,
"c++14", FormatStyle::LS_Cpp14);
405 IO.enumCase(
Value,
"c++17", FormatStyle::LS_Cpp17);
406 IO.enumCase(
Value,
"c++20", FormatStyle::LS_Cpp20);
408 IO.enumCase(
Value,
"Latest", FormatStyle::LS_Latest);
409 IO.enumCase(
Value,
"Cpp11", FormatStyle::LS_Latest);
410 IO.enumCase(
Value,
"Auto", FormatStyle::LS_Auto);
415struct ScalarEnumerationTraits<
FormatStyle::LambdaBodyIndentationKind> {
417 FormatStyle::LambdaBodyIndentationKind &
Value) {
418 IO.enumCase(
Value,
"Signature", FormatStyle::LBI_Signature);
419 IO.enumCase(
Value,
"OuterScope", FormatStyle::LBI_OuterScope);
423template <>
struct ScalarEnumerationTraits<
FormatStyle::LineEndingStyle> {
425 IO.enumCase(
Value,
"LF", FormatStyle::LE_LF);
426 IO.enumCase(
Value,
"CRLF", FormatStyle::LE_CRLF);
427 IO.enumCase(
Value,
"DeriveLF", FormatStyle::LE_DeriveLF);
428 IO.enumCase(
Value,
"DeriveCRLF", FormatStyle::LE_DeriveCRLF);
433struct ScalarEnumerationTraits<
FormatStyle::NamespaceIndentationKind> {
435 FormatStyle::NamespaceIndentationKind &
Value) {
436 IO.enumCase(
Value,
"None", FormatStyle::NI_None);
437 IO.enumCase(
Value,
"Inner", FormatStyle::NI_Inner);
438 IO.enumCase(
Value,
"All", FormatStyle::NI_All);
442template <>
struct ScalarEnumerationTraits<
FormatStyle::OperandAlignmentStyle> {
444 IO.enumCase(
Value,
"DontAlign", FormatStyle::OAS_DontAlign);
445 IO.enumCase(
Value,
"Align", FormatStyle::OAS_Align);
446 IO.enumCase(
Value,
"AlignAfterOperator",
447 FormatStyle::OAS_AlignAfterOperator);
450 IO.enumCase(
Value,
"true", FormatStyle::OAS_Align);
451 IO.enumCase(
Value,
"false", FormatStyle::OAS_DontAlign);
456struct ScalarEnumerationTraits<
FormatStyle::PackConstructorInitializersStyle> {
459 IO.enumCase(
Value,
"Never", FormatStyle::PCIS_Never);
460 IO.enumCase(
Value,
"BinPack", FormatStyle::PCIS_BinPack);
461 IO.enumCase(
Value,
"CurrentLine", FormatStyle::PCIS_CurrentLine);
462 IO.enumCase(
Value,
"NextLine", FormatStyle::PCIS_NextLine);
463 IO.enumCase(
Value,
"NextLineOnly", FormatStyle::PCIS_NextLineOnly);
467template <>
struct ScalarEnumerationTraits<
FormatStyle::PointerAlignmentStyle> {
469 IO.enumCase(
Value,
"Middle", FormatStyle::PAS_Middle);
470 IO.enumCase(
Value,
"Left", FormatStyle::PAS_Left);
471 IO.enumCase(
Value,
"Right", FormatStyle::PAS_Right);
474 IO.enumCase(
Value,
"true", FormatStyle::PAS_Left);
475 IO.enumCase(
Value,
"false", FormatStyle::PAS_Right);
480struct ScalarEnumerationTraits<
FormatStyle::PPDirectiveIndentStyle> {
482 IO.enumCase(
Value,
"None", FormatStyle::PPDIS_None);
483 IO.enumCase(
Value,
"AfterHash", FormatStyle::PPDIS_AfterHash);
484 IO.enumCase(
Value,
"BeforeHash", FormatStyle::PPDIS_BeforeHash);
489struct ScalarEnumerationTraits<
FormatStyle::QualifierAlignmentStyle> {
491 IO.enumCase(
Value,
"Leave", FormatStyle::QAS_Leave);
492 IO.enumCase(
Value,
"Left", FormatStyle::QAS_Left);
493 IO.enumCase(
Value,
"Right", FormatStyle::QAS_Right);
494 IO.enumCase(
Value,
"Custom", FormatStyle::QAS_Custom);
499 static void mapping(IO &IO, FormatStyle::RawStringFormat &Format) {
500 IO.mapOptional(
"Language", Format.Language);
501 IO.mapOptional(
"Delimiters", Format.Delimiters);
502 IO.mapOptional(
"EnclosingFunctions", Format.EnclosingFunctions);
503 IO.mapOptional(
"CanonicalDelimiter", Format.CanonicalDelimiter);
504 IO.mapOptional(
"BasedOnStyle", Format.BasedOnStyle);
509struct ScalarEnumerationTraits<
FormatStyle::ReferenceAlignmentStyle> {
511 IO.enumCase(
Value,
"Pointer", FormatStyle::RAS_Pointer);
512 IO.enumCase(
Value,
"Middle", FormatStyle::RAS_Middle);
513 IO.enumCase(
Value,
"Left", FormatStyle::RAS_Left);
514 IO.enumCase(
Value,
"Right", FormatStyle::RAS_Right);
519struct ScalarEnumerationTraits<
FormatStyle::RemoveParenthesesStyle> {
521 IO.enumCase(
Value,
"Leave", FormatStyle::RPS_Leave);
522 IO.enumCase(
Value,
"MultipleParentheses",
523 FormatStyle::RPS_MultipleParentheses);
524 IO.enumCase(
Value,
"ReturnStatement", FormatStyle::RPS_ReturnStatement);
529struct ScalarEnumerationTraits<
FormatStyle::RequiresClausePositionStyle> {
531 FormatStyle::RequiresClausePositionStyle &
Value) {
532 IO.enumCase(
Value,
"OwnLine", FormatStyle::RCPS_OwnLine);
533 IO.enumCase(
Value,
"WithPreceding", FormatStyle::RCPS_WithPreceding);
534 IO.enumCase(
Value,
"WithFollowing", FormatStyle::RCPS_WithFollowing);
535 IO.enumCase(
Value,
"SingleLine", FormatStyle::RCPS_SingleLine);
540struct ScalarEnumerationTraits<
FormatStyle::RequiresExpressionIndentationKind> {
543 IO.enumCase(
Value,
"Keyword", FormatStyle::REI_Keyword);
544 IO.enumCase(
Value,
"OuterScope", FormatStyle::REI_OuterScope);
549struct ScalarEnumerationTraits<
FormatStyle::ReturnTypeBreakingStyle> {
551 IO.enumCase(
Value,
"None", FormatStyle::RTBS_None);
552 IO.enumCase(
Value,
"Automatic", FormatStyle::RTBS_Automatic);
553 IO.enumCase(
Value,
"ExceptShortType", FormatStyle::RTBS_ExceptShortType);
554 IO.enumCase(
Value,
"All", FormatStyle::RTBS_All);
555 IO.enumCase(
Value,
"TopLevel", FormatStyle::RTBS_TopLevel);
556 IO.enumCase(
Value,
"TopLevelDefinitions",
557 FormatStyle::RTBS_TopLevelDefinitions);
558 IO.enumCase(
Value,
"AllDefinitions", FormatStyle::RTBS_AllDefinitions);
563struct ScalarEnumerationTraits<
FormatStyle::SeparateDefinitionStyle> {
565 IO.enumCase(
Value,
"Leave", FormatStyle::SDS_Leave);
566 IO.enumCase(
Value,
"Always", FormatStyle::SDS_Always);
567 IO.enumCase(
Value,
"Never", FormatStyle::SDS_Never);
571template <>
struct ScalarEnumerationTraits<
FormatStyle::ShortBlockStyle> {
573 IO.enumCase(
Value,
"Never", FormatStyle::SBS_Never);
574 IO.enumCase(
Value,
"false", FormatStyle::SBS_Never);
575 IO.enumCase(
Value,
"Always", FormatStyle::SBS_Always);
576 IO.enumCase(
Value,
"true", FormatStyle::SBS_Always);
577 IO.enumCase(
Value,
"Empty", FormatStyle::SBS_Empty);
581template <>
struct ScalarEnumerationTraits<
FormatStyle::ShortFunctionStyle> {
583 IO.enumCase(
Value,
"None", FormatStyle::SFS_None);
584 IO.enumCase(
Value,
"false", FormatStyle::SFS_None);
585 IO.enumCase(
Value,
"All", FormatStyle::SFS_All);
586 IO.enumCase(
Value,
"true", FormatStyle::SFS_All);
587 IO.enumCase(
Value,
"Inline", FormatStyle::SFS_Inline);
588 IO.enumCase(
Value,
"InlineOnly", FormatStyle::SFS_InlineOnly);
589 IO.enumCase(
Value,
"Empty", FormatStyle::SFS_Empty);
593template <>
struct ScalarEnumerationTraits<
FormatStyle::ShortIfStyle> {
595 IO.enumCase(
Value,
"Never", FormatStyle::SIS_Never);
596 IO.enumCase(
Value,
"WithoutElse", FormatStyle::SIS_WithoutElse);
597 IO.enumCase(
Value,
"OnlyFirstIf", FormatStyle::SIS_OnlyFirstIf);
598 IO.enumCase(
Value,
"AllIfsAndElse", FormatStyle::SIS_AllIfsAndElse);
601 IO.enumCase(
Value,
"Always", FormatStyle::SIS_OnlyFirstIf);
602 IO.enumCase(
Value,
"false", FormatStyle::SIS_Never);
603 IO.enumCase(
Value,
"true", FormatStyle::SIS_WithoutElse);
607template <>
struct ScalarEnumerationTraits<
FormatStyle::ShortLambdaStyle> {
609 IO.enumCase(
Value,
"None", FormatStyle::SLS_None);
610 IO.enumCase(
Value,
"false", FormatStyle::SLS_None);
611 IO.enumCase(
Value,
"Empty", FormatStyle::SLS_Empty);
612 IO.enumCase(
Value,
"Inline", FormatStyle::SLS_Inline);
613 IO.enumCase(
Value,
"All", FormatStyle::SLS_All);
614 IO.enumCase(
Value,
"true", FormatStyle::SLS_All);
618template <>
struct ScalarEnumerationTraits<
FormatStyle::SortIncludesOptions> {
620 IO.enumCase(
Value,
"Never", FormatStyle::SI_Never);
621 IO.enumCase(
Value,
"CaseInsensitive", FormatStyle::SI_CaseInsensitive);
622 IO.enumCase(
Value,
"CaseSensitive", FormatStyle::SI_CaseSensitive);
625 IO.enumCase(
Value,
"false", FormatStyle::SI_Never);
626 IO.enumCase(
Value,
"true", FormatStyle::SI_CaseSensitive);
631struct ScalarEnumerationTraits<
FormatStyle::SortJavaStaticImportOptions> {
633 FormatStyle::SortJavaStaticImportOptions &
Value) {
634 IO.enumCase(
Value,
"Before", FormatStyle::SJSIO_Before);
635 IO.enumCase(
Value,
"After", FormatStyle::SJSIO_After);
640struct ScalarEnumerationTraits<
FormatStyle::SortUsingDeclarationsOptions> {
642 FormatStyle::SortUsingDeclarationsOptions &
Value) {
643 IO.enumCase(
Value,
"Never", FormatStyle::SUD_Never);
644 IO.enumCase(
Value,
"Lexicographic", FormatStyle::SUD_Lexicographic);
645 IO.enumCase(
Value,
"LexicographicNumeric",
646 FormatStyle::SUD_LexicographicNumeric);
649 IO.enumCase(
Value,
"false", FormatStyle::SUD_Never);
650 IO.enumCase(
Value,
"true", FormatStyle::SUD_LexicographicNumeric);
655struct ScalarEnumerationTraits<
FormatStyle::SpaceAroundPointerQualifiersStyle> {
658 IO.enumCase(
Value,
"Default", FormatStyle::SAPQ_Default);
659 IO.enumCase(
Value,
"Before", FormatStyle::SAPQ_Before);
660 IO.enumCase(
Value,
"After", FormatStyle::SAPQ_After);
661 IO.enumCase(
Value,
"Both", FormatStyle::SAPQ_Both);
665template <>
struct MappingTraits<
FormatStyle::SpaceBeforeParensCustom> {
666 static void mapping(IO &IO, FormatStyle::SpaceBeforeParensCustom &Spacing) {
667 IO.mapOptional(
"AfterControlStatements", Spacing.AfterControlStatements);
668 IO.mapOptional(
"AfterForeachMacros", Spacing.AfterForeachMacros);
669 IO.mapOptional(
"AfterFunctionDefinitionName",
670 Spacing.AfterFunctionDefinitionName);
671 IO.mapOptional(
"AfterFunctionDeclarationName",
672 Spacing.AfterFunctionDeclarationName);
673 IO.mapOptional(
"AfterIfMacros", Spacing.AfterIfMacros);
674 IO.mapOptional(
"AfterOverloadedOperator", Spacing.AfterOverloadedOperator);
675 IO.mapOptional(
"AfterPlacementOperator", Spacing.AfterPlacementOperator);
676 IO.mapOptional(
"AfterRequiresInClause", Spacing.AfterRequiresInClause);
677 IO.mapOptional(
"AfterRequiresInExpression",
678 Spacing.AfterRequiresInExpression);
679 IO.mapOptional(
"BeforeNonEmptyParentheses",
680 Spacing.BeforeNonEmptyParentheses);
685struct ScalarEnumerationTraits<
FormatStyle::SpaceBeforeParensStyle> {
687 IO.enumCase(
Value,
"Never", FormatStyle::SBPO_Never);
688 IO.enumCase(
Value,
"ControlStatements",
689 FormatStyle::SBPO_ControlStatements);
690 IO.enumCase(
Value,
"ControlStatementsExceptControlMacros",
691 FormatStyle::SBPO_ControlStatementsExceptControlMacros);
692 IO.enumCase(
Value,
"NonEmptyParentheses",
693 FormatStyle::SBPO_NonEmptyParentheses);
694 IO.enumCase(
Value,
"Always", FormatStyle::SBPO_Always);
695 IO.enumCase(
Value,
"Custom", FormatStyle::SBPO_Custom);
698 IO.enumCase(
Value,
"false", FormatStyle::SBPO_Never);
699 IO.enumCase(
Value,
"true", FormatStyle::SBPO_ControlStatements);
700 IO.enumCase(
Value,
"ControlStatementsExceptForEachMacros",
701 FormatStyle::SBPO_ControlStatementsExceptControlMacros);
705template <>
struct ScalarEnumerationTraits<
FormatStyle::SpacesInAnglesStyle> {
707 IO.enumCase(
Value,
"Never", FormatStyle::SIAS_Never);
708 IO.enumCase(
Value,
"Always", FormatStyle::SIAS_Always);
709 IO.enumCase(
Value,
"Leave", FormatStyle::SIAS_Leave);
712 IO.enumCase(
Value,
"false", FormatStyle::SIAS_Never);
713 IO.enumCase(
Value,
"true", FormatStyle::SIAS_Always);
717template <>
struct MappingTraits<
FormatStyle::SpacesInLineComment> {
718 static void mapping(IO &IO, FormatStyle::SpacesInLineComment &Space) {
720 int signedMaximum =
static_cast<int>(Space.Maximum);
721 IO.mapOptional(
"Minimum", Space.Minimum);
722 IO.mapOptional(
"Maximum", signedMaximum);
723 Space.Maximum =
static_cast<unsigned>(signedMaximum);
725 if (Space.Maximum != -1u)
726 Space.Minimum = std::min(Space.Minimum, Space.Maximum);
730template <>
struct MappingTraits<
FormatStyle::SpacesInParensCustom> {
731 static void mapping(IO &IO, FormatStyle::SpacesInParensCustom &Spaces) {
732 IO.mapOptional(
"ExceptDoubleParentheses", Spaces.ExceptDoubleParentheses);
733 IO.mapOptional(
"InCStyleCasts", Spaces.InCStyleCasts);
734 IO.mapOptional(
"InConditionalStatements", Spaces.InConditionalStatements);
735 IO.mapOptional(
"InEmptyParentheses", Spaces.InEmptyParentheses);
736 IO.mapOptional(
"Other", Spaces.Other);
740template <>
struct ScalarEnumerationTraits<
FormatStyle::SpacesInParensStyle> {
742 IO.enumCase(
Value,
"Never", FormatStyle::SIPO_Never);
743 IO.enumCase(
Value,
"Custom", FormatStyle::SIPO_Custom);
747template <>
struct ScalarEnumerationTraits<
FormatStyle::TrailingCommaStyle> {
749 IO.enumCase(
Value,
"None", FormatStyle::TCS_None);
750 IO.enumCase(
Value,
"Wrapped", FormatStyle::TCS_Wrapped);
755struct ScalarEnumerationTraits<
FormatStyle::TrailingCommentsAlignmentKinds> {
757 FormatStyle::TrailingCommentsAlignmentKinds &
Value) {
758 IO.enumCase(
Value,
"Leave", FormatStyle::TCAS_Leave);
759 IO.enumCase(
Value,
"Always", FormatStyle::TCAS_Always);
760 IO.enumCase(
Value,
"Never", FormatStyle::TCAS_Never);
764template <>
struct MappingTraits<
FormatStyle::TrailingCommentsAlignmentStyle> {
766 FormatStyle::TrailingCommentsAlignmentStyle &
Value) {
767 IO.enumCase(
Value,
"Leave",
768 FormatStyle::TrailingCommentsAlignmentStyle(
769 {FormatStyle::TCAS_Leave, 0}));
771 IO.enumCase(
Value,
"Always",
772 FormatStyle::TrailingCommentsAlignmentStyle(
773 {FormatStyle::TCAS_Always, 0}));
775 IO.enumCase(
Value,
"Never",
776 FormatStyle::TrailingCommentsAlignmentStyle(
777 {FormatStyle::TCAS_Never, 0}));
780 IO.enumCase(
Value,
"true",
781 FormatStyle::TrailingCommentsAlignmentStyle(
782 {FormatStyle::TCAS_Always, 0}));
783 IO.enumCase(
Value,
"false",
784 FormatStyle::TrailingCommentsAlignmentStyle(
785 {FormatStyle::TCAS_Never, 0}));
789 FormatStyle::TrailingCommentsAlignmentStyle &
Value) {
790 IO.mapOptional(
"Kind",
Value.Kind);
791 IO.mapOptional(
"OverEmptyLines",
Value.OverEmptyLines);
795template <>
struct ScalarEnumerationTraits<
FormatStyle::UseTabStyle> {
797 IO.enumCase(
Value,
"Never", FormatStyle::UT_Never);
798 IO.enumCase(
Value,
"false", FormatStyle::UT_Never);
799 IO.enumCase(
Value,
"Always", FormatStyle::UT_Always);
800 IO.enumCase(
Value,
"true", FormatStyle::UT_Always);
801 IO.enumCase(
Value,
"ForIndentation", FormatStyle::UT_ForIndentation);
802 IO.enumCase(
Value,
"ForContinuationAndIndentation",
803 FormatStyle::UT_ForContinuationAndIndentation);
804 IO.enumCase(
Value,
"AlignWithSpaces", FormatStyle::UT_AlignWithSpaces);
811 IO.mapOptional(
"Language", Style.
Language);
813 StringRef BasedOnStyle;
814 if (IO.outputting()) {
815 StringRef Styles[] = {
"LLVM",
"Google",
"Chromium",
"Mozilla",
816 "WebKit",
"GNU",
"Microsoft",
"clang-format"};
817 for (StringRef StyleName : Styles) {
819 if (getPredefinedStyle(StyleName, Style.
Language, &PredefinedStyle) &&
820 Style == PredefinedStyle) {
821 BasedOnStyle = StyleName;
826 IO.mapOptional(
"BasedOnStyle", BasedOnStyle);
827 if (!BasedOnStyle.empty()) {
828 FormatStyle::LanguageKind OldLanguage = Style.
Language;
829 FormatStyle::LanguageKind Language =
831 if (!getPredefinedStyle(BasedOnStyle, Language, &Style)) {
832 IO.setError(Twine(
"Unknown value for BasedOnStyle: ", BasedOnStyle));
850 const bool IsGoogleOrChromium = BasedOnStyle.equals_insensitive(
"google") ||
851 BasedOnStyle.equals_insensitive(
"chromium");
852 bool OnCurrentLine = IsGoogleOrChromium;
853 bool OnNextLine =
true;
855 bool BreakBeforeInheritanceComma =
false;
856 bool BreakConstructorInitializersBeforeComma =
false;
858 bool DeriveLineEnding =
true;
859 bool UseCRLF =
false;
861 bool SpaceInEmptyParentheses =
false;
862 bool SpacesInConditionalStatement =
false;
863 bool SpacesInCStyleCastParentheses =
false;
864 bool SpacesInParentheses =
false;
867 if (!IO.outputting()) {
869 IO.mapOptional(
"AllowAllConstructorInitializersOnNextLine", OnNextLine);
871 IO.mapOptional(
"AlwaysBreakTemplateDeclarations",
873 IO.mapOptional(
"BreakBeforeInheritanceComma",
874 BreakBeforeInheritanceComma);
875 IO.mapOptional(
"BreakConstructorInitializersBeforeComma",
876 BreakConstructorInitializersBeforeComma);
877 IO.mapOptional(
"ConstructorInitializerAllOnOneLineOrOnePerLine",
879 IO.mapOptional(
"DeriveLineEnding", DeriveLineEnding);
882 IO.mapOptional(
"KeepEmptyLinesAtTheStartOfBlocks",
884 IO.mapOptional(
"IndentFunctionDeclarationAfterType",
888 IO.mapOptional(
"SpaceAfterControlStatementKeyword",
890 IO.mapOptional(
"SpaceInEmptyParentheses", SpaceInEmptyParentheses);
891 IO.mapOptional(
"SpacesInConditionalStatement",
892 SpacesInConditionalStatement);
893 IO.mapOptional(
"SpacesInCStyleCastParentheses",
894 SpacesInCStyleCastParentheses);
895 IO.mapOptional(
"SpacesInParentheses", SpacesInParentheses);
896 IO.mapOptional(
"UseCRLF", UseCRLF);
902 IO.mapOptional(
"AlignConsecutiveAssignments",
904 IO.mapOptional(
"AlignConsecutiveBitFields",
906 IO.mapOptional(
"AlignConsecutiveDeclarations",
909 IO.mapOptional(
"AlignConsecutiveShortCaseStatements",
911 IO.mapOptional(
"AlignConsecutiveTableGenBreakingDAGArgColons",
913 IO.mapOptional(
"AlignConsecutiveTableGenCondOperatorColons",
915 IO.mapOptional(
"AlignConsecutiveTableGenDefinitionColons",
920 IO.mapOptional(
"AllowAllArgumentsOnNextLine",
922 IO.mapOptional(
"AllowAllParametersOfDeclarationOnNextLine",
924 IO.mapOptional(
"AllowBreakBeforeNoexceptSpecifier",
926 IO.mapOptional(
"AllowShortBlocksOnASingleLine",
928 IO.mapOptional(
"AllowShortCaseExpressionOnASingleLine",
930 IO.mapOptional(
"AllowShortCaseLabelsOnASingleLine",
932 IO.mapOptional(
"AllowShortCompoundRequirementOnASingleLine",
934 IO.mapOptional(
"AllowShortEnumsOnASingleLine",
936 IO.mapOptional(
"AllowShortFunctionsOnASingleLine",
938 IO.mapOptional(
"AllowShortIfStatementsOnASingleLine",
940 IO.mapOptional(
"AllowShortLambdasOnASingleLine",
942 IO.mapOptional(
"AllowShortLoopsOnASingleLine",
944 IO.mapOptional(
"AlwaysBreakAfterDefinitionReturnType",
946 IO.mapOptional(
"AlwaysBreakBeforeMultilineStrings",
952 IO.mapOptional(
"BracedInitializerIndentWidth",
955 IO.mapOptional(
"BreakAdjacentStringLiterals",
958 IO.mapOptional(
"BreakAfterJavaFieldAnnotations",
962 IO.mapOptional(
"BreakBeforeBinaryOperators",
964 IO.mapOptional(
"BreakBeforeConceptDeclarations",
967 IO.mapOptional(
"BreakBeforeInlineASMColon",
969 IO.mapOptional(
"BreakBeforeTernaryOperators",
971 IO.mapOptional(
"BreakConstructorInitializers",
973 IO.mapOptional(
"BreakFunctionDefinitionParameters",
977 IO.mapOptional(
"BreakTemplateDeclarations",
982 IO.mapOptional(
"ConstructorInitializerIndentWidth",
988 IO.mapOptional(
"EmptyLineAfterAccessModifier",
990 IO.mapOptional(
"EmptyLineBeforeAccessModifier",
992 IO.mapOptional(
"ExperimentalAutoDetectBinPacking",
996 IO.mapOptional(
"IfMacros", Style.
IfMacros);
1000 IO.mapOptional(
"IncludeIsMainSourceRegex",
1010 IO.mapOptional(
"IndentWrappedFunctionNames",
1021 IO.mapOptional(
"LineEnding", Style.
LineEnding);
1024 IO.mapOptional(
"Macros", Style.
Macros);
1031 IO.mapOptional(
"ObjCBreakBeforeNestedBlockParam",
1033 IO.mapOptional(
"ObjCPropertyAttributeOrder",
1036 IO.mapOptional(
"ObjCSpaceBeforeProtocolList",
1038 IO.mapOptional(
"PackConstructorInitializers",
1041 IO.mapOptional(
"PenaltyBreakBeforeFirstCallParameter",
1044 IO.mapOptional(
"PenaltyBreakFirstLessLess",
1046 IO.mapOptional(
"PenaltyBreakOpenParenthesis",
1048 IO.mapOptional(
"PenaltyBreakScopeResolution",
1051 IO.mapOptional(
"PenaltyBreakTemplateDeclaration",
1054 IO.mapOptional(
"PenaltyIndentedWhitespace",
1056 IO.mapOptional(
"PenaltyReturnTypeOnItsOwnLine",
1075 IO.mapOptional(
"RequiresExpressionIndentation",
1085 IO.mapOptional(
"SpaceAfterTemplateKeyword",
1087 IO.mapOptional(
"SpaceAroundPointerQualifiers",
1089 IO.mapOptional(
"SpaceBeforeAssignmentOperators",
1092 IO.mapOptional(
"SpaceBeforeCpp11BracedList",
1094 IO.mapOptional(
"SpaceBeforeCtorInitializerColon",
1096 IO.mapOptional(
"SpaceBeforeInheritanceColon",
1101 IO.mapOptional(
"SpaceBeforeRangeBasedForLoopColon",
1103 IO.mapOptional(
"SpaceBeforeSquareBrackets",
1106 IO.mapOptional(
"SpacesBeforeTrailingComments",
1109 IO.mapOptional(
"SpacesInContainerLiterals",
1111 IO.mapOptional(
"SpacesInLineCommentPrefix",
1116 IO.mapOptional(
"Standard", Style.
Standard);
1117 IO.mapOptional(
"StatementAttributeLikeMacros",
1120 IO.mapOptional(
"TableGenBreakingDAGArgOperators",
1122 IO.mapOptional(
"TableGenBreakInsideDAGArg",
1124 IO.mapOptional(
"TabWidth", Style.
TabWidth);
1125 IO.mapOptional(
"TypeNames", Style.
TypeNames);
1127 IO.mapOptional(
"UseTab", Style.
UseTab);
1128 IO.mapOptional(
"VerilogBreakBetweenInstancePorts",
1130 IO.mapOptional(
"WhitespaceSensitiveMacros",
1139 FormatStyle::DRTBS_All) {
1142 FormatStyle::DRTBS_TopLevel) {
1149 if (BreakBeforeInheritanceComma &&
1157 if (BreakConstructorInitializersBeforeComma &&
1162 if (!IsGoogleOrChromium) {
1166 ? FormatStyle::PCIS_NextLine
1167 : FormatStyle::PCIS_CurrentLine;
1170 FormatStyle::PCIS_NextLine) {
1173 else if (!OnNextLine)
1177 if (Style.
LineEnding == FormatStyle::LE_DeriveLF) {
1178 if (!DeriveLineEnding)
1179 Style.
LineEnding = UseCRLF ? FormatStyle::LE_CRLF : FormatStyle::LE_LF;
1181 Style.
LineEnding = FormatStyle::LE_DeriveCRLF;
1185 (SpacesInParentheses || SpaceInEmptyParentheses ||
1186 SpacesInConditionalStatement || SpacesInCStyleCastParentheses)) {
1187 if (SpacesInParentheses) {
1192 SpacesInCStyleCastParentheses;
1194 SpaceInEmptyParentheses;
1199 SpacesInConditionalStatement;
1201 SpacesInCStyleCastParentheses;
1203 SpaceInEmptyParentheses;
1215template <>
struct DocumentListTraits<
std::vector<FormatStyle>> {
1216 static size_t size(IO &IO, std::vector<FormatStyle> &Seq) {
1221 if (Index >= Seq.size()) {
1222 assert(Index == Seq.size());
1224 if (!Seq.empty() && Seq[0].Language == FormatStyle::LK_None) {
1227 Template = *((
const FormatStyle *)IO.getContext());
1228 Template.
Language = FormatStyle::LK_None;
1230 Seq.resize(Index + 1, Template);
1250 return llvm::make_error<llvm::StringError>(Message,
1251 llvm::inconvertibleErrorCode());
1255 return "clang-format.parse_error";
1263 return "Invalid argument";
1265 return "Unsuitable";
1267 return "trailing comma insertion cannot be used with bin packing";
1269 return "Invalid qualifier specified in QualifierOrder";
1271 return "Duplicate qualifier specified in QualifierOrder";
1273 return "Missing type in QualifierOrder";
1275 return "Missing QualifierOrder";
1277 llvm_unreachable(
"unexpected parse error");
1503 LLVMStyle.
IfMacros.push_back(
"KJ_IF_MAYBE");
1506 {
"^\"(llvm|llvm-c|clang|clang-c)/", 2, 0,
false},
1507 {
"^(<|\"(gtest|gmock|isl|json)/)", 3, 0,
false},
1508 {
".*", 1, 0,
false}};
1652 {
"^<.*\\.h>", 1, 0,
false},
1653 {
"^<.*", 2, 0,
false},
1654 {
".*", 3, 0,
false}};
1694 "PARSE_PARTIAL_TEXT_PROTO",
1698 "ParseTextProtoOrDie",
1700 "ParsePartialTestProto",
1812 "com.google.android.apps.chrome",
1831 return ChromiumStyle;
1857 return MozillaStyle;
1951 if (Name.equals_insensitive(
"llvm"))
1953 else if (Name.equals_insensitive(
"chromium"))
1955 else if (Name.equals_insensitive(
"mozilla"))
1957 else if (Name.equals_insensitive(
"google"))
1959 else if (Name.equals_insensitive(
"webkit"))
1961 else if (Name.equals_insensitive(
"gnu"))
1963 else if (Name.equals_insensitive(
"microsoft"))
1965 else if (Name.equals_insensitive(
"clang-format"))
1967 else if (Name.equals_insensitive(
"none"))
1969 else if (Name.equals_insensitive(
"inheritparentconfig"))
1985 if (Qualifier ==
"type")
1989 if (token == tok::identifier)
1994 std::set<std::string> UniqueQualifiers(Style->
QualifierOrder.begin(),
1997 LLVM_DEBUG(llvm::dbgs()
1999 <<
" vs " << UniqueQualifiers.size() <<
"\n");
2012 llvm::SourceMgr::DiagHandlerTy DiagHandler,
2013 void *DiagHandlerCtxt) {
2017 if (Config.getBuffer().trim().empty())
2019 Style->StyleSet.
Clear();
2020 std::vector<FormatStyle> Styles;
2021 llvm::yaml::Input Input(Config,
nullptr, DiagHandler,
2027 Input.setContext(Style);
2028 Input.setAllowUnknownKeys(AllowUnknownOptions);
2031 return Input.error();
2033 for (
unsigned i = 0; i < Styles.size(); ++i) {
2038 for (
unsigned j = 0; j < i; ++j) {
2040 LLVM_DEBUG(llvm::dbgs()
2041 <<
"Duplicate languages in the config file on positions "
2042 << j <<
" and " << i <<
"\n");
2051 bool LanguageFound =
false;
2052 for (
const FormatStyle &Style : llvm::reverse(Styles)) {
2054 StyleSet.
Add(Style);
2056 LanguageFound =
true;
2058 if (!LanguageFound) {
2063 StyleSet.
Add(std::move(DefaultStyle));
2078 llvm::raw_string_ostream Stream(
Text);
2079 llvm::yaml::Output Output(Stream);
2086 Output << NonConstStyle;
2088 return Stream.str();
2091std::optional<FormatStyle>
2094 return std::nullopt;
2096 if (It == Styles->end())
2097 return std::nullopt;
2099 Style.StyleSet = *
this;
2105 "Cannot add a style for LK_None to a StyleSet");
2107 !Style.StyleSet.Styles &&
2108 "Cannot add a style associated with an existing StyleSet to a StyleSet");
2110 Styles = std::make_shared<MapType>();
2111 (*Styles)[Style.
Language] = std::move(Style);
2116std::optional<FormatStyle>
2128 std::pair<tooling::Replacements, unsigned>
2129 analyze(TokenAnnotator &Annotator,
2131 FormatTokenLexer &Tokens)
override {
2132 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2134 removeParens(AnnotatedLines, Result);
2139 void removeParens(SmallVectorImpl<AnnotatedLine *> &Lines,
2140 tooling::Replacements &Result) {
2141 const auto &SourceMgr =
Env.getSourceManager();
2142 for (
auto *Line : Lines) {
2143 removeParens(Line->Children, Result);
2144 if (!Line->Affected)
2146 for (
const auto *Token = Line->First; Token && !Token->Finalized;
2147 Token = Token->Next) {
2148 if (!Token->Optional || !Token->isOneOf(tok::l_paren, tok::r_paren))
2150 auto *Next = Token->Next;
2151 assert(Next && Next->isNot(tok::eof));
2152 SourceLocation Start;
2153 if (Next->NewlinesBefore == 0) {
2154 Start = Token->Tok.getLocation();
2155 Next->WhitespaceRange = Token->WhitespaceRange;
2157 Start = Token->WhitespaceRange.getBegin();
2160 CharSourceRange::getCharRange(Start, Token->Tok.getEndLoc());
2161 cantFail(Result.add(tooling::Replacement(SourceMgr,
Range,
" ")));
2167class BracesInserter :
public TokenAnalyzer {
2170 : TokenAnalyzer(
Env, Style) {}
2172 std::pair<tooling::Replacements, unsigned>
2173 analyze(TokenAnnotator &Annotator,
2174 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2175 FormatTokenLexer &Tokens)
override {
2176 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2177 tooling::Replacements Result;
2178 insertBraces(AnnotatedLines, Result);
2183 void insertBraces(SmallVectorImpl<AnnotatedLine *> &Lines,
2184 tooling::Replacements &Result) {
2185 const auto &SourceMgr =
Env.getSourceManager();
2186 int OpeningBraceSurplus = 0;
2187 for (AnnotatedLine *Line : Lines) {
2188 insertBraces(Line->Children, Result);
2189 if (!Line->Affected && OpeningBraceSurplus == 0)
2191 for (FormatToken *Token = Line->First; Token && !Token->Finalized;
2192 Token = Token->Next) {
2193 int BraceCount = Token->BraceCount;
2194 if (BraceCount == 0)
2197 if (BraceCount < 0) {
2198 assert(BraceCount == -1);
2199 if (!Line->Affected)
2201 Brace = Token->is(tok::comment) ?
"\n{" :
"{";
2202 ++OpeningBraceSurplus;
2204 if (OpeningBraceSurplus == 0)
2206 if (OpeningBraceSurplus < BraceCount)
2207 BraceCount = OpeningBraceSurplus;
2208 Brace =
'\n' + std::string(BraceCount,
'}');
2209 OpeningBraceSurplus -= BraceCount;
2211 Token->BraceCount = 0;
2212 const auto Start = Token->Tok.getEndLoc();
2213 cantFail(Result.add(tooling::Replacement(SourceMgr, Start, 0,
Brace)));
2216 assert(OpeningBraceSurplus == 0);
2220class BracesRemover :
public TokenAnalyzer {
2223 : TokenAnalyzer(
Env, Style) {}
2225 std::pair<tooling::Replacements, unsigned>
2226 analyze(TokenAnnotator &Annotator,
2227 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2228 FormatTokenLexer &Tokens)
override {
2229 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2230 tooling::Replacements Result;
2231 removeBraces(AnnotatedLines, Result);
2236 void removeBraces(SmallVectorImpl<AnnotatedLine *> &Lines,
2237 tooling::Replacements &Result) {
2238 const auto &SourceMgr =
Env.getSourceManager();
2239 const auto End = Lines.end();
2240 for (
auto I = Lines.begin(); I != End; ++I) {
2241 const auto Line = *I;
2242 removeBraces(Line->Children, Result);
2243 if (!Line->Affected)
2245 const auto NextLine = I + 1 == End ? nullptr : I[1];
2246 for (
auto Token = Line->First; Token && !Token->Finalized;
2247 Token = Token->Next) {
2248 if (!Token->Optional)
2250 if (!Token->isOneOf(tok::l_brace, tok::r_brace))
2252 auto Next = Token->Next;
2253 assert(Next || Token == Line->Last);
2254 if (!Next && NextLine)
2255 Next = NextLine->First;
2256 SourceLocation Start;
2257 if (Next && Next->NewlinesBefore == 0 && Next->isNot(tok::eof)) {
2258 Start = Token->Tok.getLocation();
2259 Next->WhitespaceRange = Token->WhitespaceRange;
2261 Start = Token->WhitespaceRange.getBegin();
2264 CharSourceRange::getCharRange(Start, Token->Tok.getEndLoc());
2265 cantFail(Result.add(tooling::Replacement(SourceMgr,
Range,
"")));
2271class SemiRemover :
public TokenAnalyzer {
2274 : TokenAnalyzer(
Env, Style) {}
2276 std::pair<tooling::Replacements, unsigned>
2277 analyze(TokenAnnotator &Annotator,
2278 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2279 FormatTokenLexer &Tokens)
override {
2280 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2281 tooling::Replacements Result;
2282 removeSemi(Annotator, AnnotatedLines, Result);
2287 void removeSemi(TokenAnnotator &Annotator,
2288 SmallVectorImpl<AnnotatedLine *> &Lines,
2289 tooling::Replacements &Result) {
2290 auto PrecededByFunctionRBrace = [](
const FormatToken &Tok) {
2291 const auto *Prev = Tok.Previous;
2292 if (!Prev || Prev->isNot(tok::r_brace))
2294 const auto *LBrace = Prev->MatchingParen;
2295 return LBrace && LBrace->is(TT_FunctionLBrace);
2297 const auto &SourceMgr =
Env.getSourceManager();
2298 const auto End = Lines.end();
2299 for (
auto I = Lines.begin(); I != End; ++I) {
2300 const auto Line = *I;
2301 removeSemi(Annotator, Line->Children, Result);
2302 if (!Line->Affected)
2304 Annotator.calculateFormattingInformation(*Line);
2305 const auto NextLine = I + 1 == End ? nullptr : I[1];
2306 for (
auto Token = Line->First; Token && !Token->Finalized;
2307 Token = Token->Next) {
2308 if (Token->isNot(tok::semi) ||
2309 (!Token->Optional && !PrecededByFunctionRBrace(*Token))) {
2312 auto Next = Token->Next;
2313 assert(Next || Token == Line->Last);
2314 if (!Next && NextLine)
2315 Next = NextLine->First;
2316 SourceLocation Start;
2317 if (Next && Next->NewlinesBefore == 0 && Next->isNot(tok::eof)) {
2318 Start = Token->Tok.getLocation();
2319 Next->WhitespaceRange = Token->WhitespaceRange;
2321 Start = Token->WhitespaceRange.getBegin();
2324 CharSourceRange::getCharRange(Start, Token->Tok.getEndLoc());
2325 cantFail(Result.add(tooling::Replacement(SourceMgr,
Range,
"")));
2331class JavaScriptRequoter :
public TokenAnalyzer {
2333 JavaScriptRequoter(
const Environment &
Env,
const FormatStyle &Style)
2334 : TokenAnalyzer(
Env, Style) {}
2336 std::pair<tooling::Replacements, unsigned>
2337 analyze(TokenAnnotator &Annotator,
2338 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2339 FormatTokenLexer &Tokens)
override {
2340 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2341 tooling::Replacements Result;
2342 requoteJSStringLiteral(AnnotatedLines, Result);
2349 void requoteJSStringLiteral(SmallVectorImpl<AnnotatedLine *> &Lines,
2350 tooling::Replacements &Result) {
2351 for (AnnotatedLine *Line : Lines) {
2352 requoteJSStringLiteral(Line->Children, Result);
2353 if (!Line->Affected)
2355 for (FormatToken *FormatTok = Line->First; FormatTok;
2356 FormatTok = FormatTok->Next) {
2357 StringRef Input = FormatTok->TokenText;
2358 if (FormatTok->Finalized || !FormatTok->isStringLiteral() ||
2362 !Input.starts_with(
"\"")) ||
2364 !Input.starts_with(
"\'"))) {
2370 SourceLocation Start = FormatTok->Tok.getLocation();
2371 auto Replace = [&](SourceLocation Start,
unsigned Length,
2372 StringRef ReplacementText) {
2373 auto Err = Result.add(tooling::Replacement(
2374 Env.getSourceManager(), Start, Length, ReplacementText));
2378 llvm::errs() <<
toString(std::move(Err)) <<
"\n";
2382 Replace(Start, 1, IsSingle ?
"'" :
"\"");
2383 Replace(FormatTok->Tok.getEndLoc().getLocWithOffset(-1), 1,
2384 IsSingle ?
"'" :
"\"");
2387 bool Escaped =
false;
2388 for (
size_t i = 1; i < Input.size() - 1; i++) {
2391 if (!Escaped && i + 1 < Input.size() &&
2392 ((IsSingle && Input[i + 1] ==
'"') ||
2393 (!IsSingle && Input[i + 1] ==
'\''))) {
2396 Replace(Start.getLocWithOffset(i), 1,
"");
2403 if (!Escaped && IsSingle == (Input[i] ==
'\'')) {
2405 Replace(Start.getLocWithOffset(i), 0,
"\\");
2419class Formatter :
public TokenAnalyzer {
2422 FormattingAttemptStatus *Status)
2423 : TokenAnalyzer(
Env, Style), Status(Status) {}
2425 std::pair<tooling::Replacements, unsigned>
2426 analyze(TokenAnnotator &Annotator,
2427 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2428 FormatTokenLexer &Tokens)
override {
2429 tooling::Replacements Result;
2430 deriveLocalStyle(AnnotatedLines);
2431 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2432 for (AnnotatedLine *Line : AnnotatedLines)
2433 Annotator.calculateFormattingInformation(*Line);
2434 Annotator.setCommentLineLevels(AnnotatedLines);
2436 WhitespaceManager Whitespaces(
2437 Env.getSourceManager(), Style,
2439 ? WhitespaceManager::inputUsesCRLF(
2440 Env.getSourceManager().getBufferData(
Env.getFileID()),
2441 Style.
LineEnding == FormatStyle::LE_DeriveCRLF)
2443 ContinuationIndenter
Indenter(Style, Tokens.getKeywords(),
2444 Env.getSourceManager(), Whitespaces, Encoding,
2445 BinPackInconclusiveFunctions);
2447 UnwrappedLineFormatter(&
Indenter, &Whitespaces, Style,
2448 Tokens.getKeywords(),
Env.getSourceManager(),
2450 .format(AnnotatedLines,
false,
2453 Env.getFirstStartColumn(),
2454 Env.getNextStartColumn(),
2455 Env.getLastStartColumn());
2456 for (
const auto &R : Whitespaces.generateReplacements())
2458 return std::make_pair(Result, 0);
2459 return std::make_pair(Result, Penalty);
2464 hasCpp03IncompatibleFormat(
const SmallVectorImpl<AnnotatedLine *> &Lines) {
2465 for (
const AnnotatedLine *Line : Lines) {
2466 if (hasCpp03IncompatibleFormat(Line->Children))
2468 for (FormatToken *Tok = Line->First->Next; Tok; Tok = Tok->Next) {
2469 if (!Tok->hasWhitespaceBefore()) {
2470 if (Tok->is(tok::coloncolon) && Tok->Previous->is(TT_TemplateOpener))
2472 if (Tok->is(TT_TemplateCloser) &&
2473 Tok->Previous->is(TT_TemplateCloser)) {
2482 int countVariableAlignments(
const SmallVectorImpl<AnnotatedLine *> &Lines) {
2483 int AlignmentDiff = 0;
2484 for (
const AnnotatedLine *Line : Lines) {
2485 AlignmentDiff += countVariableAlignments(Line->Children);
2486 for (FormatToken *Tok = Line->First; Tok && Tok->Next; Tok = Tok->Next) {
2487 if (Tok->isNot(TT_PointerOrReference))
2490 if (
const auto *Prev = Tok->getPreviousNonComment()) {
2491 if (Prev->is(tok::r_paren) && Prev->MatchingParen) {
2492 if (
const auto *Func =
2493 Prev->MatchingParen->getPreviousNonComment()) {
2494 if (
Func->isOneOf(TT_FunctionDeclarationName, TT_StartOfName,
2495 TT_OverloadedOperator)) {
2501 bool SpaceBefore = Tok->hasWhitespaceBefore();
2502 bool SpaceAfter = Tok->Next->hasWhitespaceBefore();
2503 if (SpaceBefore && !SpaceAfter)
2505 if (!SpaceBefore && SpaceAfter)
2509 return AlignmentDiff;
2513 deriveLocalStyle(
const SmallVectorImpl<AnnotatedLine *> &AnnotatedLines) {
2514 bool HasBinPackedFunction =
false;
2515 bool HasOnePerLineFunction =
false;
2516 for (AnnotatedLine *Line : AnnotatedLines) {
2517 if (!Line->First->Next)
2519 FormatToken *Tok = Line->First->Next;
2521 if (Tok->is(PPK_BinPacked))
2522 HasBinPackedFunction =
true;
2523 if (Tok->is(PPK_OnePerLine))
2524 HasOnePerLineFunction =
true;
2530 const auto NetRightCount = countVariableAlignments(AnnotatedLines);
2531 if (NetRightCount > 0)
2533 else if (NetRightCount < 0)
2537 if (Style.
Standard == FormatStyle::LS_Auto) {
2538 Style.
Standard = hasCpp03IncompatibleFormat(AnnotatedLines)
2539 ? FormatStyle::LS_Latest
2540 : FormatStyle::LS_Cpp03;
2542 BinPackInconclusiveFunctions =
2543 HasBinPackedFunction || !HasOnePerLineFunction;
2546 bool BinPackInconclusiveFunctions;
2547 FormattingAttemptStatus *Status;
2561class TrailingCommaInserter :
public TokenAnalyzer {
2563 TrailingCommaInserter(
const Environment &
Env,
const FormatStyle &Style)
2564 : TokenAnalyzer(
Env, Style) {}
2566 std::pair<tooling::Replacements, unsigned>
2567 analyze(TokenAnnotator &Annotator,
2568 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2569 FormatTokenLexer &Tokens)
override {
2570 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2571 tooling::Replacements Result;
2572 insertTrailingCommas(AnnotatedLines, Result);
2579 void insertTrailingCommas(SmallVectorImpl<AnnotatedLine *> &Lines,
2580 tooling::Replacements &Result) {
2581 for (AnnotatedLine *Line : Lines) {
2582 insertTrailingCommas(Line->Children, Result);
2583 if (!Line->Affected)
2585 for (FormatToken *FormatTok = Line->First; FormatTok;
2586 FormatTok = FormatTok->Next) {
2587 if (FormatTok->NewlinesBefore == 0)
2589 FormatToken *Matching = FormatTok->MatchingParen;
2590 if (!Matching || !FormatTok->getPreviousNonComment())
2592 if (!(FormatTok->is(tok::r_square) &&
2593 Matching->is(TT_ArrayInitializerLSquare)) &&
2594 !(FormatTok->is(tok::r_brace) && Matching->is(TT_DictLiteral))) {
2597 FormatToken *Prev = FormatTok->getPreviousNonComment();
2598 if (Prev->is(tok::comma) || Prev->is(tok::semi))
2602 SourceLocation Start =
2603 Prev->Tok.getLocation().getLocWithOffset(Prev->TokenText.size());
2607 unsigned ColumnNumber =
2608 Env.getSourceManager().getSpellingColumnNumber(Start);
2613 cantFail(Result.add(
2614 tooling::Replacement(
Env.getSourceManager(), Start, 0,
",")));
2622class Cleaner :
public TokenAnalyzer {
2625 : TokenAnalyzer(
Env, Style),
2626 DeletedTokens(FormatTokenLess(
Env.getSourceManager())) {}
2629 std::pair<tooling::Replacements, unsigned>
2630 analyze(TokenAnnotator &Annotator,
2631 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2632 FormatTokenLexer &Tokens)
override {
2640 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2642 checkEmptyNamespace(AnnotatedLines);
2644 for (
auto *Line : AnnotatedLines)
2647 return {generateFixes(), 0};
2651 void cleanupLine(AnnotatedLine *Line) {
2652 for (
auto *Child : Line->Children)
2655 if (Line->Affected) {
2656 cleanupRight(Line->First, tok::comma, tok::comma);
2657 cleanupRight(Line->First, TT_CtorInitializerColon, tok::comma);
2658 cleanupRight(Line->First, tok::l_paren, tok::comma);
2659 cleanupLeft(Line->First, tok::comma, tok::r_paren);
2660 cleanupLeft(Line->First, TT_CtorInitializerComma, tok::l_brace);
2661 cleanupLeft(Line->First, TT_CtorInitializerColon, tok::l_brace);
2662 cleanupLeft(Line->First, TT_CtorInitializerColon, tok::equal);
2666 bool containsOnlyComments(
const AnnotatedLine &Line) {
2667 for (FormatToken *Tok = Line.First; Tok; Tok = Tok->Next)
2668 if (Tok->isNot(tok::comment))
2674 void checkEmptyNamespace(SmallVectorImpl<AnnotatedLine *> &AnnotatedLines) {
2675 std::set<unsigned> DeletedLines;
2676 for (
unsigned i = 0, e = AnnotatedLines.size(); i != e; ++i) {
2677 auto &Line = *AnnotatedLines[i];
2678 if (Line.startsWithNamespace())
2679 checkEmptyNamespace(AnnotatedLines, i, i, DeletedLines);
2682 for (
auto Line : DeletedLines) {
2683 FormatToken *Tok = AnnotatedLines[Line]->First;
2695 bool checkEmptyNamespace(SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2696 unsigned CurrentLine,
unsigned &
NewLine,
2697 std::set<unsigned> &DeletedLines) {
2698 unsigned InitLine = CurrentLine, End = AnnotatedLines.size();
2703 if (!AnnotatedLines[++CurrentLine]->startsWith(tok::l_brace)) {
2707 }
else if (!AnnotatedLines[CurrentLine]->endsWith(tok::l_brace)) {
2710 while (++CurrentLine < End) {
2711 if (AnnotatedLines[CurrentLine]->startsWith(tok::r_brace))
2714 if (AnnotatedLines[CurrentLine]->startsWithNamespace()) {
2715 if (!checkEmptyNamespace(AnnotatedLines, CurrentLine,
NewLine,
2723 if (containsOnlyComments(*AnnotatedLines[CurrentLine]))
2733 if (CurrentLine >= End)
2737 if (!AffectedRangeMgr.affectsCharSourceRange(CharSourceRange::getCharRange(
2738 AnnotatedLines[InitLine]->First->Tok.getLocation(),
2739 AnnotatedLines[CurrentLine]->Last->Tok.getEndLoc()))) {
2743 for (
unsigned i = InitLine; i <= CurrentLine; ++i)
2744 DeletedLines.insert(i);
2753 template <
typename LeftKind,
typename RightKind>
2754 void cleanupPair(FormatToken *Start, LeftKind LK, RightKind RK,
2756 auto NextNotDeleted = [
this](
const FormatToken &Tok) -> FormatToken * {
2757 for (
auto *Res = Tok.Next; Res; Res = Res->Next) {
2758 if (Res->isNot(tok::comment) &&
2759 DeletedTokens.find(Res) == DeletedTokens.end()) {
2765 for (
auto *Left = Start;
Left;) {
2766 auto *
Right = NextNotDeleted(*Left);
2770 deleteToken(DeleteLeft ? Left : Right);
2771 for (
auto *Tok =
Left->Next; Tok && Tok != Right; Tok = Tok->Next)
2782 template <
typename LeftKind,
typename RightKind>
2783 void cleanupLeft(FormatToken *Start, LeftKind LK, RightKind RK) {
2784 cleanupPair(Start, LK, RK,
true);
2787 template <
typename LeftKind,
typename RightKind>
2788 void cleanupRight(FormatToken *Start, LeftKind LK, RightKind RK) {
2789 cleanupPair(Start, LK, RK,
false);
2793 inline void deleteToken(FormatToken *Tok) {
2795 DeletedTokens.insert(Tok);
2798 tooling::Replacements generateFixes() {
2799 tooling::Replacements Fixes;
2800 SmallVector<FormatToken *> Tokens;
2801 std::copy(DeletedTokens.begin(), DeletedTokens.end(),
2802 std::back_inserter(Tokens));
2808 while (Idx < Tokens.size()) {
2809 unsigned St = Idx, End = Idx;
2810 while ((End + 1) < Tokens.size() && Tokens[End]->Next == Tokens[End + 1])
2812 auto SR = CharSourceRange::getCharRange(Tokens[St]->Tok.getLocation(),
2813 Tokens[End]->Tok.getEndLoc());
2815 Fixes.add(tooling::Replacement(
Env.getSourceManager(), SR,
""));
2819 llvm::errs() <<
toString(std::move(Err)) <<
"\n";
2820 assert(
false &&
"Fixes must not conflict!");
2831 struct FormatTokenLess {
2832 FormatTokenLess(
const SourceManager &
SM) :
SM(
SM) {}
2834 bool operator()(
const FormatToken *LHS,
const FormatToken *RHS)
const {
2835 return SM.isBeforeInTranslationUnit(LHS->Tok.getLocation(),
2836 RHS->Tok.getLocation());
2842 std::set<FormatToken *, FormatTokenLess> DeletedTokens;
2845class ObjCHeaderStyleGuesser :
public TokenAnalyzer {
2847 ObjCHeaderStyleGuesser(
const Environment &
Env,
const FormatStyle &Style)
2848 : TokenAnalyzer(
Env, Style), IsObjC(
false) {}
2850 std::pair<tooling::Replacements, unsigned>
2851 analyze(TokenAnnotator &Annotator,
2852 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2853 FormatTokenLexer &Tokens)
override {
2854 assert(Style.
Language == FormatStyle::LK_Cpp);
2855 IsObjC = guessIsObjC(
Env.getSourceManager(), AnnotatedLines,
2856 Tokens.getKeywords());
2857 tooling::Replacements Result;
2861 bool isObjC() {
return IsObjC; }
2865 guessIsObjC(
const SourceManager &SourceManager,
2866 const SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2867 const AdditionalKeywords &Keywords) {
2869 static constexpr llvm::StringLiteral FoundationIdentifiers[] = {
2884 "FOUNDATION_EXPORT",
2885 "FOUNDATION_EXTERN",
2886 "NSAffineTransform",
2888 "NSAttributedString",
2907 "NSInvocationOperation",
2911 "NSMutableAttributedString",
2912 "NSMutableCharacterSet",
2914 "NSMutableDictionary",
2915 "NSMutableIndexSet",
2916 "NSMutableOrderedSet",
2920 "NSNumberFormatter",
2924 "NSOperationQueuePriority",
2928 "NSQualityOfService",
2931 "NSRegularExpression",
2942 "NS_ASSUME_NONNULL_BEGIN",
2947 for (
auto *Line : AnnotatedLines) {
2948 if (Line->First && (Line->First->TokenText.starts_with(
"#") ||
2949 Line->First->TokenText ==
"__pragma" ||
2950 Line->First->TokenText ==
"_Pragma")) {
2953 for (
const FormatToken *FormatTok = Line->First; FormatTok;
2954 FormatTok = FormatTok->Next) {
2955 if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&
2956 (FormatTok->Tok.getObjCKeywordID() != tok::objc_not_keyword ||
2957 FormatTok->isOneOf(tok::numeric_constant, tok::l_square,
2959 (FormatTok->Tok.isAnyIdentifier() &&
2960 std::binary_search(std::begin(FoundationIdentifiers),
2961 std::end(FoundationIdentifiers),
2962 FormatTok->TokenText)) ||
2963 FormatTok->is(TT_ObjCStringLiteral) ||
2964 FormatTok->isOneOf(Keywords.kw_NS_CLOSED_ENUM, Keywords.kw_NS_ENUM,
2965 Keywords.kw_NS_ERROR_ENUM,
2966 Keywords.kw_NS_OPTIONS, TT_ObjCBlockLBrace,
2967 TT_ObjCBlockLParen, TT_ObjCDecl, TT_ObjCForIn,
2968 TT_ObjCMethodExpr, TT_ObjCMethodSpecifier,
2970 LLVM_DEBUG(llvm::dbgs()
2971 <<
"Detected ObjC at location "
2972 << FormatTok->Tok.getLocation().printToString(
2974 <<
" token: " << FormatTok->TokenText <<
" token type: "
2979 if (guessIsObjC(SourceManager, Line->Children, Keywords))
2996struct JavaImportDirective {
3009 for (
const auto &
Range : Ranges) {
3010 if (
Range.getOffset() < End &&
3011 Range.getOffset() +
Range.getLength() > Start) {
3025static std::pair<unsigned, unsigned>
3029 unsigned OffsetToEOL = 0;
3030 for (
int i = 0, e = Includes.size(); i != e; ++i) {
3031 unsigned Start = Includes[Indices[i]].Offset;
3032 unsigned End = Start + Includes[Indices[i]].Text.size();
3033 if (!(Cursor >= Start && Cursor < End))
3035 CursorIndex = Indices[i];
3036 OffsetToEOL = End - Cursor;
3039 while (--i >= 0 && Includes[CursorIndex].
Text == Includes[Indices[i]].
Text)
3043 return std::make_pair(CursorIndex, OffsetToEOL);
3048 std::string NewCode;
3049 size_t Pos = 0, LastPos = 0;
3052 Pos = Code.find(
"\r\n", LastPos);
3053 if (Pos == LastPos) {
3057 if (Pos == std::string::npos) {
3058 NewCode += Code.substr(LastPos);
3061 NewCode += Code.substr(LastPos, Pos - LastPos) +
"\n";
3063 }
while (Pos != std::string::npos);
3081 const unsigned IncludesBeginOffset = Includes.front().Offset;
3082 const unsigned IncludesEndOffset =
3083 Includes.back().Offset + Includes.back().Text.size();
3084 const unsigned IncludesBlockSize = IncludesEndOffset - IncludesBeginOffset;
3085 if (!
affectsRange(Ranges, IncludesBeginOffset, IncludesEndOffset))
3088 llvm::to_vector<16>(llvm::seq<unsigned>(0, Includes.size()));
3091 stable_sort(Indices, [&](
unsigned LHSI,
unsigned RHSI) {
3092 const auto LHSFilenameLower = Includes[LHSI].Filename.lower();
3093 const auto RHSFilenameLower = Includes[RHSI].Filename.lower();
3094 return std::tie(Includes[LHSI].
Priority, LHSFilenameLower,
3096 std::tie(Includes[RHSI].
Priority, RHSFilenameLower,
3100 stable_sort(Indices, [&](
unsigned LHSI,
unsigned RHSI) {
3108 unsigned CursorIndex;
3110 unsigned CursorToEOLOffset;
3112 std::tie(CursorIndex, CursorToEOLOffset) =
3117 Indices.erase(std::unique(Indices.begin(), Indices.end(),
3118 [&](
unsigned LHSI,
unsigned RHSI) {
3119 return Includes[LHSI].Text.trim() ==
3120 Includes[RHSI].Text.trim();
3124 int CurrentCategory = Includes.front().Category;
3132 if (Indices.size() == Includes.size() && is_sorted(Indices) &&
3137 const auto OldCursor = Cursor ? *Cursor : 0;
3139 for (
unsigned Index : Indices) {
3140 if (!result.empty()) {
3144 CurrentCategory != Includes[Index].Category) {
3148 result += Includes[Index].Text;
3149 if (Cursor && CursorIndex == Index)
3150 *Cursor = IncludesBeginOffset + result.size() - CursorToEOLOffset;
3151 CurrentCategory = Includes[Index].Category;
3154 if (Cursor && *Cursor >= IncludesEndOffset)
3155 *Cursor += result.size() - IncludesBlockSize;
3160 IncludesBeginOffset, IncludesBlockSize)))) {
3162 *Cursor = OldCursor;
3167 FileName, Includes.front().Offset, IncludesBlockSize, result));
3171 llvm::errs() <<
toString(std::move(Err)) <<
"\n";
3181 unsigned Prev = llvm::StringSwitch<size_t>(Code)
3182 .StartsWith(
"\xEF\xBB\xBF", 3)
3184 unsigned SearchFrom = 0;
3196 bool FirstIncludeBlock =
true;
3197 bool MainIncludeFound =
false;
3198 bool FormattingOff =
false;
3201 llvm::Regex RawStringRegex(
3202 "R\"([][A-Za-z0-9_{}#<>%:;.?*+/^&\\$|~!=,'-]*)\\(");
3204 std::string RawStringTermination =
")\"";
3207 auto Pos = Code.find(
'\n', SearchFrom);
3209 Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev);
3211 StringRef Trimmed =
Line.trim();
3216 if (RawStringRegex.match(Trimmed, &RawStringMatches)) {
3217 std::string CharSequence = RawStringMatches[1].str();
3218 RawStringTermination =
")" + CharSequence +
"\"";
3219 FormattingOff =
true;
3222 if (Trimmed.contains(RawStringTermination))
3223 FormattingOff =
false;
3225 bool IsBlockComment =
false;
3228 FormattingOff =
true;
3230 FormattingOff =
false;
3231 }
else if (Trimmed.starts_with(
"/*")) {
3232 IsBlockComment =
true;
3233 Pos = Code.find(
"*/", SearchFrom + 2);
3236 const bool EmptyLineSkipped =
3242 bool MergeWithNextLine = Trimmed.ends_with(
"\\");
3243 if (!FormattingOff && !MergeWithNextLine) {
3244 if (!IsBlockComment &&
3246 StringRef IncludeName = Matches[2];
3247 if (Trimmed.contains(
"/*") && !Trimmed.contains(
"*/")) {
3252 Pos = Code.find(
"*/", SearchFrom);
3254 Prev, (Pos != StringRef::npos ? Pos + 2 : Code.size()) - Prev);
3258 !MainIncludeFound && FirstIncludeBlock);
3260 IncludeName, !MainIncludeFound && FirstIncludeBlock);
3262 MainIncludeFound =
true;
3263 IncludesInBlock.push_back(
3265 }
else if (!IncludesInBlock.empty() && !EmptyLineSkipped) {
3268 IncludesInBlock.clear();
3269 if (Trimmed.starts_with(
"#pragma hdrstop"))
3270 FirstIncludeBlock =
true;
3272 FirstIncludeBlock =
false;
3275 if (Pos == StringRef::npos || Pos + 1 == Code.size())
3278 if (!MergeWithNextLine)
3280 SearchFrom = Pos + 1;
3282 if (!IncludesInBlock.empty()) {
3292 StringRef ImportIdentifier) {
3293 unsigned LongestMatchIndex =
UINT_MAX;
3294 unsigned LongestMatchLength = 0;
3297 if (ImportIdentifier.starts_with(GroupPrefix) &&
3298 GroupPrefix.length() > LongestMatchLength) {
3299 LongestMatchIndex = I;
3300 LongestMatchLength = GroupPrefix.length();
3303 return LongestMatchIndex;
3315 unsigned ImportsBeginOffset = Imports.front().Offset;
3316 unsigned ImportsEndOffset =
3317 Imports.back().Offset + Imports.back().Text.size();
3318 unsigned ImportsBlockSize = ImportsEndOffset - ImportsBeginOffset;
3319 if (!
affectsRange(Ranges, ImportsBeginOffset, ImportsEndOffset))
3323 llvm::to_vector<16>(llvm::seq<unsigned>(0, Imports.size()));
3326 for (
const JavaImportDirective &Import : Imports)
3329 bool StaticImportAfterNormalImport =
3331 sort(Indices, [&](
unsigned LHSI,
unsigned RHSI) {
3333 return std::make_tuple(!Imports[LHSI].
IsStatic ^
3334 StaticImportAfterNormalImport,
3336 std::make_tuple(!Imports[RHSI].
IsStatic ^
3337 StaticImportAfterNormalImport,
3342 Indices.erase(std::unique(Indices.begin(), Indices.end(),
3343 [&](
unsigned LHSI,
unsigned RHSI) {
3344 return Imports[LHSI].Text == Imports[RHSI].Text;
3348 bool CurrentIsStatic = Imports[Indices.front()].IsStatic;
3352 for (
unsigned Index : Indices) {
3353 if (!result.empty()) {
3355 if (CurrentIsStatic != Imports[Index].
IsStatic ||
3361 result += CommentLine;
3364 result += Imports[Index].Text;
3365 CurrentIsStatic = Imports[Index].IsStatic;
3372 Imports.front().Offset, ImportsBlockSize)))) {
3377 ImportsBlockSize, result));
3381 llvm::errs() <<
toString(std::move(Err)) <<
"\n";
3388const char JavaImportRegexPattern[] =
3389 "^[\t ]*import[\t ]+(static[\t ]*)?([^\t ]*)[\t ]*;";
3398 unsigned SearchFrom = 0;
3399 llvm::Regex ImportRegex(JavaImportRegexPattern);
3404 bool FormattingOff =
false;
3407 auto Pos = Code.find(
'\n', SearchFrom);
3409 Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev);
3411 StringRef Trimmed =
Line.trim();
3413 FormattingOff =
true;
3415 FormattingOff =
false;
3417 if (ImportRegex.match(
Line, &Matches)) {
3418 if (FormattingOff) {
3423 StringRef
Static = Matches[1];
3426 if (
Static.contains(
"static"))
3428 ImportsInBlock.push_back(
3431 }
else if (Trimmed.size() > 0 && !ImportsInBlock.empty()) {
3436 if (Pos == StringRef::npos || Pos + 1 == Code.size())
3438 SearchFrom = Pos + 1;
3440 if (!ImportsInBlock.empty())
3449 return Code.size() > 188 && Code[0] == 0x47 && Code[188] == 0x47;
3452bool isLikelyXml(StringRef Code) {
return Code.ltrim().starts_with(
"<"); }
3456 StringRef
FileName,
unsigned *Cursor) {
3474template <
typename T>
3479 if (Replaces.
empty())
3482 auto NewCode = applyAllReplacements(Code, Replaces);
3484 return NewCode.takeError();
3489 ProcessFunc(Style, *NewCode, ChangedRanges,
FileName);
3491 return Replaces.
merge(FormatReplaces);
3500 std::vector<tooling::Range> Ranges,
3504 auto SortedReplaces =
3506 if (!SortedReplaces)
3507 return SortedReplaces.takeError();
3511 auto Reformat = [](
const FormatStyle &Style, StringRef Code,
3512 std::vector<tooling::Range> Ranges,
3527inline bool isHeaderDeletion(
const tooling::Replacement &Replace) {
3528 return Replace.getOffset() ==
UINT_MAX && Replace.getLength() == 1;
3532tooling::Replacements
3533fixCppIncludeInsertions(StringRef Code,
const tooling::Replacements &Replaces,
3538 tooling::Replacements HeaderInsertions;
3539 std::set<StringRef> HeadersToDelete;
3540 tooling::Replacements
Result;
3541 for (
const auto &R : Replaces) {
3542 if (isHeaderInsertion(R)) {
3545 consumeError(HeaderInsertions.add(R));
3546 }
else if (isHeaderDeletion(R)) {
3547 HeadersToDelete.insert(R.getReplacementText());
3548 }
else if (R.getOffset() ==
UINT_MAX) {
3549 llvm::errs() <<
"Insertions other than header #include insertion are "
3551 << R.getReplacementText() <<
"\n";
3553 consumeError(
Result.add(R));
3556 if (HeaderInsertions.empty() && HeadersToDelete.empty())
3559 StringRef
FileName = Replaces.begin()->getFilePath();
3562 for (
const auto &Header : HeadersToDelete) {
3563 tooling::Replacements Replaces =
3564 Includes.remove(Header.trim(
"\"<>"), Header.starts_with(
"<"));
3565 for (
const auto &R : Replaces) {
3566 auto Err =
Result.add(R);
3569 llvm::errs() <<
"Failed to add header deletion replacement for "
3570 << Header <<
": " <<
toString(std::move(Err)) <<
"\n";
3575 SmallVector<StringRef, 4> Matches;
3576 for (
const auto &R : HeaderInsertions) {
3580 assert(Matched &&
"Header insertion replacement must have replacement text "
3583 auto IncludeName = Matches[2];
3585 Includes.insert(IncludeName.trim(
"\"<>"), IncludeName.starts_with(
"<"),
3588 auto Err =
Result.add(*Replace);
3590 consumeError(std::move(Err));
3591 unsigned NewOffset =
3592 Result.getShiftedCodePosition(Replace->getOffset());
3593 auto Shifted = tooling::Replacement(
FileName, NewOffset, 0,
3594 Replace->getReplacementText());
3604Expected<tooling::Replacements>
3609 auto Cleanup = [](
const FormatStyle &Style, StringRef Code,
3616 fixCppIncludeInsertions(Code, Replaces, Style);
3621std::pair<tooling::Replacements, unsigned>
3624 unsigned NextStartColumn,
unsigned LastStartColumn, StringRef FileName,
3635 case FormatStyle::RCPS_SingleLine:
3636 case FormatStyle::RCPS_WithPreceding:
3652 std::vector<tooling::Range> Ranges(1,
tooling::Range(0, Code.size()));
3653 auto Env = Environment::make(Code,
FileName, Ranges, FirstStartColumn,
3654 NextStartColumn, LastStartColumn);
3659 Formatter(*
Env, Style, Status).process().first;
3661 Replaces = Replaces.
merge(
3664 if (applyAllReplacements(Code, Replaces))
3665 return {Replaces, 0};
3669 auto Env = Environment::make(Code,
FileName, Ranges, FirstStartColumn,
3670 NextStartColumn, LastStartColumn);
3674 typedef std::function<std::pair<tooling::Replacements, unsigned>(
3684 if (Style.
isCpp()) {
3691 Passes.emplace_back([&, S = std::move(S)](
const Environment &
Env) {
3692 return ParensRemover(
Env, S).process(
true);
3698 S.InsertBraces =
true;
3699 Passes.emplace_back([&, S = std::move(S)](
const Environment &
Env) {
3700 return BracesInserter(
Env, S).process(
true);
3706 S.RemoveBracesLLVM =
true;
3707 Passes.emplace_back([&, S = std::move(S)](
const Environment &
Env) {
3708 return BracesRemover(
Env, S).process(
true);
3714 S.RemoveSemicolon =
true;
3715 Passes.emplace_back([&, S = std::move(S)](
const Environment &
Env) {
3716 return SemiRemover(
Env, S).process();
3739 if (Style.
Language == FormatStyle::LK_ObjC &&
3749 return JavaScriptRequoter(
Env, Expanded).process(
true);
3754 return Formatter(
Env, Expanded, Status).process();
3760 return TrailingCommaInserter(
Env, Expanded).process();
3764 std::optional<std::string> CurrentCode;
3766 unsigned Penalty = 0;
3767 for (
size_t I = 0,
E = Passes.size(); I <
E; ++I) {
3768 std::pair<tooling::Replacements, unsigned> PassFixes = Passes[I](*Env);
3769 auto NewCode = applyAllReplacements(
3770 CurrentCode ? StringRef(*CurrentCode) : Code, PassFixes.first);
3772 Fixes = Fixes.
merge(PassFixes.first);
3773 Penalty += PassFixes.second;
3775 CurrentCode = std::move(*NewCode);
3776 Env = Environment::make(
3778 tooling::calculateRangesAfterReplacements(Fixes, Ranges),
3779 FirstStartColumn, NextStartColumn, LastStartColumn);
3792 StringRef OriginalCode = Code.substr(Fix.getOffset(), Fix.getLength());
3793 if (OriginalCode != Fix.getReplacementText()) {
3794 auto Err = NonNoOpFixes.
add(Fix);
3796 llvm::errs() <<
"Error adding replacements : "
3797 <<
toString(std::move(Err)) <<
"\n";
3801 Fixes = std::move(NonNoOpFixes);
3804 return {Fixes, Penalty};
3828 return Cleaner(*
Env, Style).process().first;
3833 StringRef
FileName,
bool *IncompleteFormat) {
3836 if (!Status.FormatComplete)
3837 *IncompleteFormat =
true;
3869 LangOpts.CPlusPlus = 1;
3880 LangOpts.LineComment = 1;
3881 LangOpts.CXXOperatorNames = Style.
isCpp();
3884 LangOpts.MicrosoftExt = 1;
3885 LangOpts.DeclSpecKeyword = 1;
3891 "Set coding style. <string> can be:\n"
3892 "1. A preset: LLVM, GNU, Google, Chromium, Microsoft,\n"
3893 " Mozilla, WebKit.\n"
3894 "2. 'file' to load style configuration from a\n"
3895 " .clang-format file in one of the parent directories\n"
3896 " of the source file (for stdin, see --assume-filename).\n"
3897 " If no .clang-format file is found, falls back to\n"
3898 " --fallback-style.\n"
3899 " --style=file is the default.\n"
3900 "3. 'file:<format_file_path>' to explicitly specify\n"
3901 " the configuration file.\n"
3902 "4. \"{key: value, ...}\" to set specific parameters, e.g.:\n"
3903 " --style=\"{BasedOnStyle: llvm, IndentWidth: 8}\"";
3908 if (
FileName.ends_with_insensitive(
".js") ||
3909 FileName.ends_with_insensitive(
".mjs") ||
3910 FileName.ends_with_insensitive(
".ts")) {
3915 if (
FileName.ends_with_insensitive(
".proto") ||
3916 FileName.ends_with_insensitive(
".protodevel")) {
3922 if (
FileName.ends_with_insensitive(
".txtpb") ||
3923 FileName.ends_with_insensitive(
".textpb") ||
3924 FileName.ends_with_insensitive(
".pb.txt") ||
3925 FileName.ends_with_insensitive(
".textproto") ||
3926 FileName.ends_with_insensitive(
".asciipb")) {
3929 if (
FileName.ends_with_insensitive(
".td"))
3931 if (
FileName.ends_with_insensitive(
".cs"))
3933 if (
FileName.ends_with_insensitive(
".json"))
3935 if (
FileName.ends_with_insensitive(
".sv") ||
3936 FileName.ends_with_insensitive(
".svh") ||
3937 FileName.ends_with_insensitive(
".v") ||
3938 FileName.ends_with_insensitive(
".vh")) {
3947 auto Extension = llvm::sys::path::extension(
FileName);
3950 if (!Code.empty() && (Extension.empty() || Extension ==
".h")) {
3955 if (Guesser.isObjC())
3959 return GuessedLanguage;
3967llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
3970 llvm::SourceMgr::DiagHandlerTy DiagHandler) {
3971 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
Text =
3972 FS->getBufferForFile(ConfigFile.str());
3973 if (
auto EC =
Text.getError())
3983 StringRef FallbackStyleName, StringRef Code,
3984 llvm::vfs::FileSystem *FS,
3985 bool AllowUnknownOptions,
3986 llvm::SourceMgr::DiagHandlerTy DiagHandler) {
3994 if (StyleName.starts_with(
"{")) {
3996 StringRef Source =
"<command-line>";
3997 if (std::error_code ec =
3999 AllowUnknownOptions, DiagHandler)) {
4006 ChildFormatTextToApply.emplace_back(
4007 llvm::MemoryBuffer::getMemBuffer(StyleName, Source,
false));
4011 FS = llvm::vfs::getRealFileSystem().get();
4016 StyleName.starts_with_insensitive(
"file:")) {
4017 auto ConfigFile = StyleName.substr(5);
4018 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
Text =
4021 if (
auto EC =
Text.getError()) {
4026 LLVM_DEBUG(llvm::dbgs()
4027 <<
"Using configuration file " << ConfigFile <<
"\n");
4035 ChildFormatTextToApply.emplace_back(std::move(*
Text));
4049 if (std::error_code EC = FS->makeAbsolute(
Path))
4055 auto dropDiagnosticHandler = [](
const llvm::SMDiagnostic &,
void *) {};
4057 auto applyChildFormatTexts = [&](
FormatStyle *Style) {
4058 for (
const auto &MemBuf : llvm::reverse(ChildFormatTextToApply)) {
4061 DiagHandler ? DiagHandler : dropDiagnosticHandler);
4064 static_cast<void>(EC);
4070 FilesToLookFor.push_back(
".clang-format");
4071 FilesToLookFor.push_back(
"_clang-format");
4074 for (StringRef Directory =
Path; !Directory.empty();
4075 Directory = llvm::sys::path::parent_path(Directory)) {
4076 auto Status = FS->status(Directory);
4078 Status->getType() != llvm::sys::fs::file_type::directory_file) {
4082 for (
const auto &F : FilesToLookFor) {
4085 llvm::sys::path::append(ConfigFile, F);
4086 LLVM_DEBUG(llvm::dbgs() <<
"Trying " << ConfigFile <<
"...\n");
4088 Status = FS->status(ConfigFile);
4090 Status->getType() != llvm::sys::fs::file_type::regular_file) {
4094 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
Text =
4097 if (
auto EC =
Text.getError()) {
4102 if (!UnsuitableConfigFiles.empty())
4103 UnsuitableConfigFiles.append(
", ");
4104 UnsuitableConfigFiles.append(ConfigFile);
4108 LLVM_DEBUG(llvm::dbgs()
4109 <<
"Using configuration file " << ConfigFile <<
"\n");
4112 if (!ChildFormatTextToApply.empty()) {
4113 LLVM_DEBUG(llvm::dbgs() <<
"Applying child configurations\n");
4114 applyChildFormatTexts(&Style);
4119 LLVM_DEBUG(llvm::dbgs() <<
"Inherits parent configuration\n");
4124 ChildFormatTextToApply.emplace_back(std::move(*
Text));
4134 if (!UnsuitableConfigFiles.empty()) {
4137 UnsuitableConfigFiles);
4140 if (!ChildFormatTextToApply.empty()) {
4141 LLVM_DEBUG(llvm::dbgs()
4142 <<
"Applying child configurations on fallback style\n");
4143 applyChildFormatTexts(&FallbackStyle);
4146 return FallbackStyle;
4150 if (Comment == (On ?
"/* clang-format on */" :
"/* clang-format off */"))
4153 static const char ClangFormatOn[] =
"// clang-format on";
4154 static const char ClangFormatOff[] =
"// clang-format off";
4155 const unsigned Size = (On ?
sizeof ClangFormatOn :
sizeof ClangFormatOff) - 1;
4157 return Comment.starts_with(On ? ClangFormatOn : ClangFormatOff) &&
4158 (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)