LLVM_YAML_IS_SEQUENCE_VECTOR(FormatStyle::RawStringFormat)
36structScalarEnumerationTraits<
FormatStyle::BreakBeforeNoexceptSpecifierStyle> {
39IO.enumCase(
Value,
"Never", FormatStyle::BBNSS_Never);
40IO.enumCase(
Value,
"OnlyWithParen", FormatStyle::BBNSS_OnlyWithParen);
41IO.enumCase(
Value,
"Always", FormatStyle::BBNSS_Always);
45template<>
structMappingTraits<
FormatStyle::AlignConsecutiveStyle> {
46 static void enumInput(IO &IO, FormatStyle::AlignConsecutiveStyle &
Value) {
47IO.enumCase(
Value,
"None", FormatStyle::AlignConsecutiveStyle({}));
48IO.enumCase(
Value,
"Consecutive",
49FormatStyle::AlignConsecutiveStyle(
54IO.enumCase(
Value,
"AcrossEmptyLines",
55FormatStyle::AlignConsecutiveStyle(
60IO.enumCase(
Value,
"AcrossComments",
61FormatStyle::AlignConsecutiveStyle(
66IO.enumCase(
Value,
"AcrossEmptyLinesAndComments",
67FormatStyle::AlignConsecutiveStyle(
74IO.enumCase(
Value,
"true",
75FormatStyle::AlignConsecutiveStyle(
80IO.enumCase(
Value,
"false", FormatStyle::AlignConsecutiveStyle({}));
83 static void mapping(IO &IO, FormatStyle::AlignConsecutiveStyle &
Value) {
84IO.mapOptional(
"Enabled",
Value.Enabled);
85IO.mapOptional(
"AcrossEmptyLines",
Value.AcrossEmptyLines);
86IO.mapOptional(
"AcrossComments",
Value.AcrossComments);
87IO.mapOptional(
"AlignCompound",
Value.AlignCompound);
88IO.mapOptional(
"AlignFunctionDeclarations",
89 Value.AlignFunctionDeclarations);
90IO.mapOptional(
"AlignFunctionPointers",
Value.AlignFunctionPointers);
91IO.mapOptional(
"PadOperators",
Value.PadOperators);
96structMappingTraits<
FormatStyle::ShortCaseStatementsAlignmentStyle> {
98FormatStyle::ShortCaseStatementsAlignmentStyle &
Value) {
99IO.mapOptional(
"Enabled",
Value.Enabled);
100IO.mapOptional(
"AcrossEmptyLines",
Value.AcrossEmptyLines);
101IO.mapOptional(
"AcrossComments",
Value.AcrossComments);
102IO.mapOptional(
"AlignCaseArrows",
Value.AlignCaseArrows);
103IO.mapOptional(
"AlignCaseColons",
Value.AlignCaseColons);
108structScalarEnumerationTraits<
FormatStyle::AttributeBreakingStyle> {
110IO.enumCase(
Value,
"Always", FormatStyle::ABS_Always);
111IO.enumCase(
Value,
"Leave", FormatStyle::ABS_Leave);
112IO.enumCase(
Value,
"Never", FormatStyle::ABS_Never);
117structScalarEnumerationTraits<
FormatStyle::ArrayInitializerAlignmentStyle> {
119FormatStyle::ArrayInitializerAlignmentStyle &
Value) {
120IO.enumCase(
Value,
"None", FormatStyle::AIAS_None);
121IO.enumCase(
Value,
"Left", FormatStyle::AIAS_Left);
122IO.enumCase(
Value,
"Right", FormatStyle::AIAS_Right);
126template<>
structScalarEnumerationTraits<
FormatStyle::BinaryOperatorStyle> {
128IO.enumCase(
Value,
"All", FormatStyle::BOS_All);
129IO.enumCase(
Value,
"true", FormatStyle::BOS_All);
130IO.enumCase(
Value,
"None", FormatStyle::BOS_None);
131IO.enumCase(
Value,
"false", FormatStyle::BOS_None);
132IO.enumCase(
Value,
"NonAssignment", FormatStyle::BOS_NonAssignment);
137structScalarEnumerationTraits<
FormatStyle::BinPackParametersStyle> {
139IO.enumCase(
Value,
"BinPack", FormatStyle::BPPS_BinPack);
140IO.enumCase(
Value,
"OnePerLine", FormatStyle::BPPS_OnePerLine);
141IO.enumCase(
Value,
"AlwaysOnePerLine", FormatStyle::BPPS_AlwaysOnePerLine);
144IO.enumCase(
Value,
"true", FormatStyle::BPPS_BinPack);
145IO.enumCase(
Value,
"false", FormatStyle::BPPS_OnePerLine);
149template<>
structScalarEnumerationTraits<
FormatStyle::BinPackStyle> {
151IO.enumCase(
Value,
"Auto", FormatStyle::BPS_Auto);
152IO.enumCase(
Value,
"Always", FormatStyle::BPS_Always);
153IO.enumCase(
Value,
"Never", FormatStyle::BPS_Never);
158structScalarEnumerationTraits<
FormatStyle::BitFieldColonSpacingStyle> {
160FormatStyle::BitFieldColonSpacingStyle &
Value) {
161IO.enumCase(
Value,
"Both", FormatStyle::BFCS_Both);
162IO.enumCase(
Value,
"None", FormatStyle::BFCS_None);
163IO.enumCase(
Value,
"Before", FormatStyle::BFCS_Before);
164IO.enumCase(
Value,
"After", FormatStyle::BFCS_After);
168template<>
structScalarEnumerationTraits<
FormatStyle::BraceBreakingStyle> {
170IO.enumCase(
Value,
"Attach", FormatStyle::BS_Attach);
171IO.enumCase(
Value,
"Linux", FormatStyle::BS_Linux);
172IO.enumCase(
Value,
"Mozilla", FormatStyle::BS_Mozilla);
173IO.enumCase(
Value,
"Stroustrup", FormatStyle::BS_Stroustrup);
174IO.enumCase(
Value,
"Allman", FormatStyle::BS_Allman);
175IO.enumCase(
Value,
"Whitesmiths", FormatStyle::BS_Whitesmiths);
176IO.enumCase(
Value,
"GNU", FormatStyle::BS_GNU);
177IO.enumCase(
Value,
"WebKit", FormatStyle::BS_WebKit);
178IO.enumCase(
Value,
"Custom", FormatStyle::BS_Custom);
182template<>
structMappingTraits<
FormatStyle::BraceWrappingFlags> {
183 static void mapping(IO &IO, FormatStyle::BraceWrappingFlags &Wrapping) {
184IO.mapOptional(
"AfterCaseLabel", Wrapping.AfterCaseLabel);
185IO.mapOptional(
"AfterClass", Wrapping.AfterClass);
186IO.mapOptional(
"AfterControlStatement", Wrapping.AfterControlStatement);
187IO.mapOptional(
"AfterEnum", Wrapping.AfterEnum);
188IO.mapOptional(
"AfterExternBlock", Wrapping.AfterExternBlock);
189IO.mapOptional(
"AfterFunction", Wrapping.AfterFunction);
190IO.mapOptional(
"AfterNamespace", Wrapping.AfterNamespace);
191IO.mapOptional(
"AfterObjCDeclaration", Wrapping.AfterObjCDeclaration);
192IO.mapOptional(
"AfterStruct", Wrapping.AfterStruct);
193IO.mapOptional(
"AfterUnion", Wrapping.AfterUnion);
194IO.mapOptional(
"BeforeCatch", Wrapping.BeforeCatch);
195IO.mapOptional(
"BeforeElse", Wrapping.BeforeElse);
196IO.mapOptional(
"BeforeLambdaBody", Wrapping.BeforeLambdaBody);
197IO.mapOptional(
"BeforeWhile", Wrapping.BeforeWhile);
198IO.mapOptional(
"IndentBraces", Wrapping.IndentBraces);
199IO.mapOptional(
"SplitEmptyFunction", Wrapping.SplitEmptyFunction);
200IO.mapOptional(
"SplitEmptyRecord", Wrapping.SplitEmptyRecord);
201IO.mapOptional(
"SplitEmptyNamespace", Wrapping.SplitEmptyNamespace);
205template<>
structScalarEnumerationTraits<
FormatStyle::BracketAlignmentStyle> {
207IO.enumCase(
Value,
"Align", FormatStyle::BAS_Align);
208IO.enumCase(
Value,
"DontAlign", FormatStyle::BAS_DontAlign);
209IO.enumCase(
Value,
"AlwaysBreak", FormatStyle::BAS_AlwaysBreak);
210IO.enumCase(
Value,
"BlockIndent", FormatStyle::BAS_BlockIndent);
213IO.enumCase(
Value,
"true", FormatStyle::BAS_Align);
214IO.enumCase(
Value,
"false", FormatStyle::BAS_DontAlign);
219structScalarEnumerationTraits<
220 FormatStyle::BraceWrappingAfterControlStatementStyle> {
223FormatStyle::BraceWrappingAfterControlStatementStyle &
Value) {
224IO.enumCase(
Value,
"Never", FormatStyle::BWACS_Never);
225IO.enumCase(
Value,
"MultiLine", FormatStyle::BWACS_MultiLine);
226IO.enumCase(
Value,
"Always", FormatStyle::BWACS_Always);
229IO.enumCase(
Value,
"false", FormatStyle::BWACS_Never);
230IO.enumCase(
Value,
"true", FormatStyle::BWACS_Always);
235structScalarEnumerationTraits<
236 FormatStyle::BreakBeforeConceptDeclarationsStyle> {
239IO.enumCase(
Value,
"Never", FormatStyle::BBCDS_Never);
240IO.enumCase(
Value,
"Allowed", FormatStyle::BBCDS_Allowed);
241IO.enumCase(
Value,
"Always", FormatStyle::BBCDS_Always);
244IO.enumCase(
Value,
"true", FormatStyle::BBCDS_Always);
245IO.enumCase(
Value,
"false", FormatStyle::BBCDS_Allowed);
250structScalarEnumerationTraits<
FormatStyle::BreakBeforeInlineASMColonStyle> {
252FormatStyle::BreakBeforeInlineASMColonStyle &
Value) {
253IO.enumCase(
Value,
"Never", FormatStyle::BBIAS_Never);
254IO.enumCase(
Value,
"OnlyMultiline", FormatStyle::BBIAS_OnlyMultiline);
255IO.enumCase(
Value,
"Always", FormatStyle::BBIAS_Always);
260structScalarEnumerationTraits<
FormatStyle::BreakBinaryOperationsStyle> {
262FormatStyle::BreakBinaryOperationsStyle &
Value) {
263IO.enumCase(
Value,
"Never", FormatStyle::BBO_Never);
264IO.enumCase(
Value,
"OnePerLine", FormatStyle::BBO_OnePerLine);
265IO.enumCase(
Value,
"RespectPrecedence", FormatStyle::BBO_RespectPrecedence);
270structScalarEnumerationTraits<
FormatStyle::BreakConstructorInitializersStyle> {
273IO.enumCase(
Value,
"BeforeColon", FormatStyle::BCIS_BeforeColon);
274IO.enumCase(
Value,
"BeforeComma", FormatStyle::BCIS_BeforeComma);
275IO.enumCase(
Value,
"AfterColon", FormatStyle::BCIS_AfterColon);
280structScalarEnumerationTraits<
FormatStyle::BreakInheritanceListStyle> {
282FormatStyle::BreakInheritanceListStyle &
Value) {
283IO.enumCase(
Value,
"BeforeColon", FormatStyle::BILS_BeforeColon);
284IO.enumCase(
Value,
"BeforeComma", FormatStyle::BILS_BeforeComma);
285IO.enumCase(
Value,
"AfterColon", FormatStyle::BILS_AfterColon);
286IO.enumCase(
Value,
"AfterComma", FormatStyle::BILS_AfterComma);
291structScalarEnumerationTraits<
FormatStyle::BreakTemplateDeclarationsStyle> {
293FormatStyle::BreakTemplateDeclarationsStyle &
Value) {
294IO.enumCase(
Value,
"Leave", FormatStyle::BTDS_Leave);
295IO.enumCase(
Value,
"No", FormatStyle::BTDS_No);
296IO.enumCase(
Value,
"MultiLine", FormatStyle::BTDS_MultiLine);
297IO.enumCase(
Value,
"Yes", FormatStyle::BTDS_Yes);
300IO.enumCase(
Value,
"false", FormatStyle::BTDS_MultiLine);
301IO.enumCase(
Value,
"true", FormatStyle::BTDS_Yes);
305template<>
structScalarEnumerationTraits<
FormatStyle::DAGArgStyle> {
307IO.enumCase(
Value,
"DontBreak", FormatStyle::DAS_DontBreak);
308IO.enumCase(
Value,
"BreakElements", FormatStyle::DAS_BreakElements);
309IO.enumCase(
Value,
"BreakAll", FormatStyle::DAS_BreakAll);
314structScalarEnumerationTraits<
FormatStyle::DefinitionReturnTypeBreakingStyle> {
317IO.enumCase(
Value,
"None", FormatStyle::DRTBS_None);
318IO.enumCase(
Value,
"All", FormatStyle::DRTBS_All);
319IO.enumCase(
Value,
"TopLevel", FormatStyle::DRTBS_TopLevel);
322IO.enumCase(
Value,
"false", FormatStyle::DRTBS_None);
323IO.enumCase(
Value,
"true", FormatStyle::DRTBS_All);
328structScalarEnumerationTraits<
FormatStyle::EscapedNewlineAlignmentStyle> {
330FormatStyle::EscapedNewlineAlignmentStyle &
Value) {
331IO.enumCase(
Value,
"DontAlign", FormatStyle::ENAS_DontAlign);
332IO.enumCase(
Value,
"Left", FormatStyle::ENAS_Left);
333IO.enumCase(
Value,
"LeftWithLastLine", FormatStyle::ENAS_LeftWithLastLine);
334IO.enumCase(
Value,
"Right", FormatStyle::ENAS_Right);
337IO.enumCase(
Value,
"true", FormatStyle::ENAS_Left);
338IO.enumCase(
Value,
"false", FormatStyle::ENAS_Right);
343structScalarEnumerationTraits<
FormatStyle::EmptyLineAfterAccessModifierStyle> {
346IO.enumCase(
Value,
"Never", FormatStyle::ELAAMS_Never);
347IO.enumCase(
Value,
"Leave", FormatStyle::ELAAMS_Leave);
348IO.enumCase(
Value,
"Always", FormatStyle::ELAAMS_Always);
353structScalarEnumerationTraits<
354 FormatStyle::EmptyLineBeforeAccessModifierStyle> {
357IO.enumCase(
Value,
"Never", FormatStyle::ELBAMS_Never);
358IO.enumCase(
Value,
"Leave", FormatStyle::ELBAMS_Leave);
359IO.enumCase(
Value,
"LogicalBlock", FormatStyle::ELBAMS_LogicalBlock);
360IO.enumCase(
Value,
"Always", FormatStyle::ELBAMS_Always);
365structScalarEnumerationTraits<
FormatStyle::IndentExternBlockStyle> {
367IO.enumCase(
Value,
"AfterExternBlock", FormatStyle::IEBS_AfterExternBlock);
368IO.enumCase(
Value,
"Indent", FormatStyle::IEBS_Indent);
369IO.enumCase(
Value,
"NoIndent", FormatStyle::IEBS_NoIndent);
370IO.enumCase(
Value,
"true", FormatStyle::IEBS_Indent);
371IO.enumCase(
Value,
"false", FormatStyle::IEBS_NoIndent);
375template<>
structMappingTraits<
FormatStyle::IntegerLiteralSeparatorStyle> {
376 static void mapping(IO &IO, FormatStyle::IntegerLiteralSeparatorStyle &
Base) {
377IO.mapOptional(
"Binary",
Base.Binary);
378IO.mapOptional(
"BinaryMinDigits",
Base.BinaryMinDigits);
379IO.mapOptional(
"Decimal",
Base.Decimal);
380IO.mapOptional(
"DecimalMinDigits",
Base.DecimalMinDigits);
381IO.mapOptional(
"Hex",
Base.Hex);
382IO.mapOptional(
"HexMinDigits",
Base.HexMinDigits);
386template<>
structScalarEnumerationTraits<
FormatStyle::JavaScriptQuoteStyle> {
388IO.enumCase(
Value,
"Leave", FormatStyle::JSQS_Leave);
389IO.enumCase(
Value,
"Single", FormatStyle::JSQS_Single);
390IO.enumCase(
Value,
"Double", FormatStyle::JSQS_Double);
394template<>
structMappingTraits<
FormatStyle::KeepEmptyLinesStyle> {
395 static void mapping(IO &IO, FormatStyle::KeepEmptyLinesStyle &
Value) {
396IO.mapOptional(
"AtEndOfFile",
Value.AtEndOfFile);
397IO.mapOptional(
"AtStartOfBlock",
Value.AtStartOfBlock);
398IO.mapOptional(
"AtStartOfFile",
Value.AtStartOfFile);
402template<>
structScalarEnumerationTraits<
FormatStyle::LanguageKind> {
404IO.enumCase(
Value,
"Cpp", FormatStyle::LK_Cpp);
405IO.enumCase(
Value,
"Java", FormatStyle::LK_Java);
406IO.enumCase(
Value,
"JavaScript", FormatStyle::LK_JavaScript);
407IO.enumCase(
Value,
"ObjC", FormatStyle::LK_ObjC);
408IO.enumCase(
Value,
"Proto", FormatStyle::LK_Proto);
409IO.enumCase(
Value,
"TableGen", FormatStyle::LK_TableGen);
410IO.enumCase(
Value,
"TextProto", FormatStyle::LK_TextProto);
411IO.enumCase(
Value,
"CSharp", FormatStyle::LK_CSharp);
412IO.enumCase(
Value,
"Json", FormatStyle::LK_Json);
413IO.enumCase(
Value,
"Verilog", FormatStyle::LK_Verilog);
417template<>
structScalarEnumerationTraits<
FormatStyle::LanguageStandard> {
419IO.enumCase(
Value,
"c++03", FormatStyle::LS_Cpp03);
420IO.enumCase(
Value,
"C++03", FormatStyle::LS_Cpp03);
421IO.enumCase(
Value,
"Cpp03", FormatStyle::LS_Cpp03);
423IO.enumCase(
Value,
"c++11", FormatStyle::LS_Cpp11);
424IO.enumCase(
Value,
"C++11", FormatStyle::LS_Cpp11);
426IO.enumCase(
Value,
"c++14", FormatStyle::LS_Cpp14);
427IO.enumCase(
Value,
"c++17", FormatStyle::LS_Cpp17);
428IO.enumCase(
Value,
"c++20", FormatStyle::LS_Cpp20);
430IO.enumCase(
Value,
"Latest", FormatStyle::LS_Latest);
431IO.enumCase(
Value,
"Cpp11", FormatStyle::LS_Latest);
432IO.enumCase(
Value,
"Auto", FormatStyle::LS_Auto);
437structScalarEnumerationTraits<
FormatStyle::LambdaBodyIndentationKind> {
439FormatStyle::LambdaBodyIndentationKind &
Value) {
440IO.enumCase(
Value,
"Signature", FormatStyle::LBI_Signature);
441IO.enumCase(
Value,
"OuterScope", FormatStyle::LBI_OuterScope);
445template<>
structScalarEnumerationTraits<
FormatStyle::LineEndingStyle> {
447IO.enumCase(
Value,
"LF", FormatStyle::LE_LF);
448IO.enumCase(
Value,
"CRLF", FormatStyle::LE_CRLF);
449IO.enumCase(
Value,
"DeriveLF", FormatStyle::LE_DeriveLF);
450IO.enumCase(
Value,
"DeriveCRLF", FormatStyle::LE_DeriveCRLF);
455structScalarEnumerationTraits<
FormatStyle::NamespaceIndentationKind> {
457FormatStyle::NamespaceIndentationKind &
Value) {
458IO.enumCase(
Value,
"None", FormatStyle::NI_None);
459IO.enumCase(
Value,
"Inner", FormatStyle::NI_Inner);
460IO.enumCase(
Value,
"All", FormatStyle::NI_All);
464template<>
structScalarEnumerationTraits<
FormatStyle::OperandAlignmentStyle> {
466IO.enumCase(
Value,
"DontAlign", FormatStyle::OAS_DontAlign);
467IO.enumCase(
Value,
"Align", FormatStyle::OAS_Align);
468IO.enumCase(
Value,
"AlignAfterOperator",
469FormatStyle::OAS_AlignAfterOperator);
472IO.enumCase(
Value,
"true", FormatStyle::OAS_Align);
473IO.enumCase(
Value,
"false", FormatStyle::OAS_DontAlign);
478structScalarEnumerationTraits<
FormatStyle::PackConstructorInitializersStyle> {
481IO.enumCase(
Value,
"Never", FormatStyle::PCIS_Never);
482IO.enumCase(
Value,
"BinPack", FormatStyle::PCIS_BinPack);
483IO.enumCase(
Value,
"CurrentLine", FormatStyle::PCIS_CurrentLine);
484IO.enumCase(
Value,
"NextLine", FormatStyle::PCIS_NextLine);
485IO.enumCase(
Value,
"NextLineOnly", FormatStyle::PCIS_NextLineOnly);
489template<>
structScalarEnumerationTraits<
FormatStyle::PointerAlignmentStyle> {
491IO.enumCase(
Value,
"Middle", FormatStyle::PAS_Middle);
492IO.enumCase(
Value,
"Left", FormatStyle::PAS_Left);
493IO.enumCase(
Value,
"Right", FormatStyle::PAS_Right);
496IO.enumCase(
Value,
"true", FormatStyle::PAS_Left);
497IO.enumCase(
Value,
"false", FormatStyle::PAS_Right);
502structScalarEnumerationTraits<
FormatStyle::PPDirectiveIndentStyle> {
504IO.enumCase(
Value,
"None", FormatStyle::PPDIS_None);
505IO.enumCase(
Value,
"AfterHash", FormatStyle::PPDIS_AfterHash);
506IO.enumCase(
Value,
"BeforeHash", FormatStyle::PPDIS_BeforeHash);
511structScalarEnumerationTraits<
FormatStyle::QualifierAlignmentStyle> {
513IO.enumCase(
Value,
"Leave", FormatStyle::QAS_Leave);
514IO.enumCase(
Value,
"Left", FormatStyle::QAS_Left);
515IO.enumCase(
Value,
"Right", FormatStyle::QAS_Right);
516IO.enumCase(
Value,
"Custom", FormatStyle::QAS_Custom);
521 static void mapping(IO &IO, FormatStyle::RawStringFormat &Format) {
522IO.mapOptional(
"Language", Format.Language);
523IO.mapOptional(
"Delimiters", Format.Delimiters);
524IO.mapOptional(
"EnclosingFunctions", Format.EnclosingFunctions);
525IO.mapOptional(
"CanonicalDelimiter", Format.CanonicalDelimiter);
526IO.mapOptional(
"BasedOnStyle", Format.BasedOnStyle);
530template<>
structScalarEnumerationTraits<
FormatStyle::ReflowCommentsStyle> {
532IO.enumCase(
Value,
"Never", FormatStyle::RCS_Never);
533IO.enumCase(
Value,
"IndentOnly", FormatStyle::RCS_IndentOnly);
534IO.enumCase(
Value,
"Always", FormatStyle::RCS_Always);
536IO.enumCase(
Value,
"false", FormatStyle::RCS_Never);
537IO.enumCase(
Value,
"true", FormatStyle::RCS_Always);
542structScalarEnumerationTraits<
FormatStyle::ReferenceAlignmentStyle> {
544IO.enumCase(
Value,
"Pointer", FormatStyle::RAS_Pointer);
545IO.enumCase(
Value,
"Middle", FormatStyle::RAS_Middle);
546IO.enumCase(
Value,
"Left", FormatStyle::RAS_Left);
547IO.enumCase(
Value,
"Right", FormatStyle::RAS_Right);
552structScalarEnumerationTraits<
FormatStyle::RemoveParenthesesStyle> {
554IO.enumCase(
Value,
"Leave", FormatStyle::RPS_Leave);
555IO.enumCase(
Value,
"MultipleParentheses",
556FormatStyle::RPS_MultipleParentheses);
557IO.enumCase(
Value,
"ReturnStatement", FormatStyle::RPS_ReturnStatement);
562structScalarEnumerationTraits<
FormatStyle::RequiresClausePositionStyle> {
564FormatStyle::RequiresClausePositionStyle &
Value) {
565IO.enumCase(
Value,
"OwnLine", FormatStyle::RCPS_OwnLine);
566IO.enumCase(
Value,
"OwnLineWithBrace", FormatStyle::RCPS_OwnLineWithBrace);
567IO.enumCase(
Value,
"WithPreceding", FormatStyle::RCPS_WithPreceding);
568IO.enumCase(
Value,
"WithFollowing", FormatStyle::RCPS_WithFollowing);
569IO.enumCase(
Value,
"SingleLine", FormatStyle::RCPS_SingleLine);
574structScalarEnumerationTraits<
FormatStyle::RequiresExpressionIndentationKind> {
577IO.enumCase(
Value,
"Keyword", FormatStyle::REI_Keyword);
578IO.enumCase(
Value,
"OuterScope", FormatStyle::REI_OuterScope);
583structScalarEnumerationTraits<
FormatStyle::ReturnTypeBreakingStyle> {
585IO.enumCase(
Value,
"None", FormatStyle::RTBS_None);
586IO.enumCase(
Value,
"Automatic", FormatStyle::RTBS_Automatic);
587IO.enumCase(
Value,
"ExceptShortType", FormatStyle::RTBS_ExceptShortType);
588IO.enumCase(
Value,
"All", FormatStyle::RTBS_All);
589IO.enumCase(
Value,
"TopLevel", FormatStyle::RTBS_TopLevel);
590IO.enumCase(
Value,
"TopLevelDefinitions",
591FormatStyle::RTBS_TopLevelDefinitions);
592IO.enumCase(
Value,
"AllDefinitions", FormatStyle::RTBS_AllDefinitions);
597structScalarEnumerationTraits<
FormatStyle::SeparateDefinitionStyle> {
599IO.enumCase(
Value,
"Leave", FormatStyle::SDS_Leave);
600IO.enumCase(
Value,
"Always", FormatStyle::SDS_Always);
601IO.enumCase(
Value,
"Never", FormatStyle::SDS_Never);
605template<>
structScalarEnumerationTraits<
FormatStyle::ShortBlockStyle> {
607IO.enumCase(
Value,
"Never", FormatStyle::SBS_Never);
608IO.enumCase(
Value,
"false", FormatStyle::SBS_Never);
609IO.enumCase(
Value,
"Always", FormatStyle::SBS_Always);
610IO.enumCase(
Value,
"true", FormatStyle::SBS_Always);
611IO.enumCase(
Value,
"Empty", FormatStyle::SBS_Empty);
615template<>
structScalarEnumerationTraits<
FormatStyle::ShortFunctionStyle> {
617IO.enumCase(
Value,
"None", FormatStyle::SFS_None);
618IO.enumCase(
Value,
"false", FormatStyle::SFS_None);
619IO.enumCase(
Value,
"All", FormatStyle::SFS_All);
620IO.enumCase(
Value,
"true", FormatStyle::SFS_All);
621IO.enumCase(
Value,
"Inline", FormatStyle::SFS_Inline);
622IO.enumCase(
Value,
"InlineOnly", FormatStyle::SFS_InlineOnly);
623IO.enumCase(
Value,
"Empty", FormatStyle::SFS_Empty);
627template<>
structScalarEnumerationTraits<
FormatStyle::ShortIfStyle> {
629IO.enumCase(
Value,
"Never", FormatStyle::SIS_Never);
630IO.enumCase(
Value,
"WithoutElse", FormatStyle::SIS_WithoutElse);
631IO.enumCase(
Value,
"OnlyFirstIf", FormatStyle::SIS_OnlyFirstIf);
632IO.enumCase(
Value,
"AllIfsAndElse", FormatStyle::SIS_AllIfsAndElse);
635IO.enumCase(
Value,
"Always", FormatStyle::SIS_OnlyFirstIf);
636IO.enumCase(
Value,
"false", FormatStyle::SIS_Never);
637IO.enumCase(
Value,
"true", FormatStyle::SIS_WithoutElse);
641template<>
structScalarEnumerationTraits<
FormatStyle::ShortLambdaStyle> {
643IO.enumCase(
Value,
"None", FormatStyle::SLS_None);
644IO.enumCase(
Value,
"false", FormatStyle::SLS_None);
645IO.enumCase(
Value,
"Empty", FormatStyle::SLS_Empty);
646IO.enumCase(
Value,
"Inline", FormatStyle::SLS_Inline);
647IO.enumCase(
Value,
"All", FormatStyle::SLS_All);
648IO.enumCase(
Value,
"true", FormatStyle::SLS_All);
652template<>
structScalarEnumerationTraits<
FormatStyle::SortIncludesOptions> {
654IO.enumCase(
Value,
"Never", FormatStyle::SI_Never);
655IO.enumCase(
Value,
"CaseInsensitive", FormatStyle::SI_CaseInsensitive);
656IO.enumCase(
Value,
"CaseSensitive", FormatStyle::SI_CaseSensitive);
659IO.enumCase(
Value,
"false", FormatStyle::SI_Never);
660IO.enumCase(
Value,
"true", FormatStyle::SI_CaseSensitive);
665structScalarEnumerationTraits<
FormatStyle::SortJavaStaticImportOptions> {
667FormatStyle::SortJavaStaticImportOptions &
Value) {
668IO.enumCase(
Value,
"Before", FormatStyle::SJSIO_Before);
669IO.enumCase(
Value,
"After", FormatStyle::SJSIO_After);
674structScalarEnumerationTraits<
FormatStyle::SortUsingDeclarationsOptions> {
676FormatStyle::SortUsingDeclarationsOptions &
Value) {
677IO.enumCase(
Value,
"Never", FormatStyle::SUD_Never);
678IO.enumCase(
Value,
"Lexicographic", FormatStyle::SUD_Lexicographic);
679IO.enumCase(
Value,
"LexicographicNumeric",
680FormatStyle::SUD_LexicographicNumeric);
683IO.enumCase(
Value,
"false", FormatStyle::SUD_Never);
684IO.enumCase(
Value,
"true", FormatStyle::SUD_LexicographicNumeric);
689structScalarEnumerationTraits<
FormatStyle::SpaceAroundPointerQualifiersStyle> {
692IO.enumCase(
Value,
"Default", FormatStyle::SAPQ_Default);
693IO.enumCase(
Value,
"Before", FormatStyle::SAPQ_Before);
694IO.enumCase(
Value,
"After", FormatStyle::SAPQ_After);
695IO.enumCase(
Value,
"Both", FormatStyle::SAPQ_Both);
699template<>
structMappingTraits<
FormatStyle::SpaceBeforeParensCustom> {
700 static void mapping(IO &IO, FormatStyle::SpaceBeforeParensCustom &Spacing) {
701IO.mapOptional(
"AfterControlStatements", Spacing.AfterControlStatements);
702IO.mapOptional(
"AfterForeachMacros", Spacing.AfterForeachMacros);
703IO.mapOptional(
"AfterFunctionDefinitionName",
704Spacing.AfterFunctionDefinitionName);
705IO.mapOptional(
"AfterFunctionDeclarationName",
706Spacing.AfterFunctionDeclarationName);
707IO.mapOptional(
"AfterIfMacros", Spacing.AfterIfMacros);
708IO.mapOptional(
"AfterOverloadedOperator", Spacing.AfterOverloadedOperator);
709IO.mapOptional(
"AfterPlacementOperator", Spacing.AfterPlacementOperator);
710IO.mapOptional(
"AfterRequiresInClause", Spacing.AfterRequiresInClause);
711IO.mapOptional(
"AfterRequiresInExpression",
712Spacing.AfterRequiresInExpression);
713IO.mapOptional(
"BeforeNonEmptyParentheses",
714Spacing.BeforeNonEmptyParentheses);
719structScalarEnumerationTraits<
FormatStyle::SpaceBeforeParensStyle> {
721IO.enumCase(
Value,
"Never", FormatStyle::SBPO_Never);
722IO.enumCase(
Value,
"ControlStatements",
723FormatStyle::SBPO_ControlStatements);
724IO.enumCase(
Value,
"ControlStatementsExceptControlMacros",
725FormatStyle::SBPO_ControlStatementsExceptControlMacros);
726IO.enumCase(
Value,
"NonEmptyParentheses",
727FormatStyle::SBPO_NonEmptyParentheses);
728IO.enumCase(
Value,
"Always", FormatStyle::SBPO_Always);
729IO.enumCase(
Value,
"Custom", FormatStyle::SBPO_Custom);
732IO.enumCase(
Value,
"false", FormatStyle::SBPO_Never);
733IO.enumCase(
Value,
"true", FormatStyle::SBPO_ControlStatements);
734IO.enumCase(
Value,
"ControlStatementsExceptForEachMacros",
735FormatStyle::SBPO_ControlStatementsExceptControlMacros);
739template<>
structScalarEnumerationTraits<
FormatStyle::SpacesInAnglesStyle> {
741IO.enumCase(
Value,
"Never", FormatStyle::SIAS_Never);
742IO.enumCase(
Value,
"Always", FormatStyle::SIAS_Always);
743IO.enumCase(
Value,
"Leave", FormatStyle::SIAS_Leave);
746IO.enumCase(
Value,
"false", FormatStyle::SIAS_Never);
747IO.enumCase(
Value,
"true", FormatStyle::SIAS_Always);
751template<>
structMappingTraits<
FormatStyle::SpacesInLineComment> {
752 static void mapping(IO &IO, FormatStyle::SpacesInLineComment &Space) {
754 intsignedMaximum =
static_cast<int>(Space.Maximum);
755IO.mapOptional(
"Minimum", Space.Minimum);
756IO.mapOptional(
"Maximum", signedMaximum);
757Space.Maximum =
static_cast<unsigned>(signedMaximum);
759 if(Space.Maximum != -1u)
760Space.Minimum = std::min(Space.Minimum, Space.Maximum);
764template<>
structMappingTraits<
FormatStyle::SpacesInParensCustom> {
765 static void mapping(IO &IO, FormatStyle::SpacesInParensCustom &Spaces) {
766IO.mapOptional(
"ExceptDoubleParentheses", Spaces.ExceptDoubleParentheses);
767IO.mapOptional(
"InCStyleCasts", Spaces.InCStyleCasts);
768IO.mapOptional(
"InConditionalStatements", Spaces.InConditionalStatements);
769IO.mapOptional(
"InEmptyParentheses", Spaces.InEmptyParentheses);
770IO.mapOptional(
"Other", Spaces.Other);
774template<>
structScalarEnumerationTraits<
FormatStyle::SpacesInParensStyle> {
776IO.enumCase(
Value,
"Never", FormatStyle::SIPO_Never);
777IO.enumCase(
Value,
"Custom", FormatStyle::SIPO_Custom);
781template<>
structScalarEnumerationTraits<
FormatStyle::TrailingCommaStyle> {
783IO.enumCase(
Value,
"None", FormatStyle::TCS_None);
784IO.enumCase(
Value,
"Wrapped", FormatStyle::TCS_Wrapped);
789structScalarEnumerationTraits<
FormatStyle::TrailingCommentsAlignmentKinds> {
791FormatStyle::TrailingCommentsAlignmentKinds &
Value) {
792IO.enumCase(
Value,
"Leave", FormatStyle::TCAS_Leave);
793IO.enumCase(
Value,
"Always", FormatStyle::TCAS_Always);
794IO.enumCase(
Value,
"Never", FormatStyle::TCAS_Never);
798template<>
structMappingTraits<
FormatStyle::TrailingCommentsAlignmentStyle> {
800FormatStyle::TrailingCommentsAlignmentStyle &
Value) {
801IO.enumCase(
Value,
"Leave",
802FormatStyle::TrailingCommentsAlignmentStyle(
803{FormatStyle::TCAS_Leave, 0}));
805IO.enumCase(
Value,
"Always",
806FormatStyle::TrailingCommentsAlignmentStyle(
807{FormatStyle::TCAS_Always, 0}));
809IO.enumCase(
Value,
"Never",
810FormatStyle::TrailingCommentsAlignmentStyle(
811{FormatStyle::TCAS_Never, 0}));
814IO.enumCase(
Value,
"true",
815FormatStyle::TrailingCommentsAlignmentStyle(
816{FormatStyle::TCAS_Always, 0}));
817IO.enumCase(
Value,
"false",
818FormatStyle::TrailingCommentsAlignmentStyle(
819{FormatStyle::TCAS_Never, 0}));
823FormatStyle::TrailingCommentsAlignmentStyle &
Value) {
824IO.mapOptional(
"Kind",
Value.Kind);
825IO.mapOptional(
"OverEmptyLines",
Value.OverEmptyLines);
829template<>
structScalarEnumerationTraits<
FormatStyle::UseTabStyle> {
831IO.enumCase(
Value,
"Never", FormatStyle::UT_Never);
832IO.enumCase(
Value,
"false", FormatStyle::UT_Never);
833IO.enumCase(
Value,
"Always", FormatStyle::UT_Always);
834IO.enumCase(
Value,
"true", FormatStyle::UT_Always);
835IO.enumCase(
Value,
"ForIndentation", FormatStyle::UT_ForIndentation);
836IO.enumCase(
Value,
"ForContinuationAndIndentation",
837FormatStyle::UT_ForContinuationAndIndentation);
838IO.enumCase(
Value,
"AlignWithSpaces", FormatStyle::UT_AlignWithSpaces);
843structScalarEnumerationTraits<
844 FormatStyle::WrapNamespaceBodyWithEmptyLinesStyle> {
847FormatStyle::WrapNamespaceBodyWithEmptyLinesStyle &
Value) {
848IO.enumCase(
Value,
"Never", FormatStyle::WNBWELS_Never);
849IO.enumCase(
Value,
"Always", FormatStyle::WNBWELS_Always);
850IO.enumCase(
Value,
"Leave", FormatStyle::WNBWELS_Leave);
857IO.mapOptional(
"Language", Style.
Language);
859StringRef BasedOnStyle;
860 if(IO.outputting()) {
861StringRef Styles[] = {
"LLVM",
"Google",
"Chromium",
"Mozilla",
862 "WebKit",
"GNU",
"Microsoft",
"clang-format"};
863 for(StringRef StyleName : Styles) {
865 if(getPredefinedStyle(StyleName, Style.
Language, &PredefinedStyle) &&
866Style == PredefinedStyle) {
867BasedOnStyle = StyleName;
872IO.mapOptional(
"BasedOnStyle", BasedOnStyle);
873 if(!BasedOnStyle.empty()) {
874FormatStyle::LanguageKind OldLanguage = Style.
Language;
875FormatStyle::LanguageKind Language =
877 if(!getPredefinedStyle(BasedOnStyle, Language, &Style)) {
878IO.setError(Twine(
"Unknown value for BasedOnStyle: ", BasedOnStyle));
896 const boolIsGoogleOrChromium = BasedOnStyle.equals_insensitive(
"google") ||
897BasedOnStyle.equals_insensitive(
"chromium");
898 boolOnCurrentLine = IsGoogleOrChromium;
899 boolOnNextLine =
true;
901 boolBreakBeforeInheritanceComma =
false;
902 boolBreakConstructorInitializersBeforeComma =
false;
904 boolDeriveLineEnding =
true;
905 boolUseCRLF =
false;
907 boolSpaceInEmptyParentheses =
false;
908 boolSpacesInConditionalStatement =
false;
909 boolSpacesInCStyleCastParentheses =
false;
910 boolSpacesInParentheses =
false;
913 if(!IO.outputting()) {
915IO.mapOptional(
"AllowAllConstructorInitializersOnNextLine", OnNextLine);
917IO.mapOptional(
"AlwaysBreakTemplateDeclarations",
919IO.mapOptional(
"BreakBeforeInheritanceComma",
920BreakBeforeInheritanceComma);
921IO.mapOptional(
"BreakConstructorInitializersBeforeComma",
922BreakConstructorInitializersBeforeComma);
923IO.mapOptional(
"ConstructorInitializerAllOnOneLineOrOnePerLine",
925IO.mapOptional(
"DeriveLineEnding", DeriveLineEnding);
928IO.mapOptional(
"KeepEmptyLinesAtTheStartOfBlocks",
930IO.mapOptional(
"IndentFunctionDeclarationAfterType",
934IO.mapOptional(
"SpaceAfterControlStatementKeyword",
936IO.mapOptional(
"SpaceInEmptyParentheses", SpaceInEmptyParentheses);
937IO.mapOptional(
"SpacesInConditionalStatement",
938SpacesInConditionalStatement);
939IO.mapOptional(
"SpacesInCStyleCastParentheses",
940SpacesInCStyleCastParentheses);
941IO.mapOptional(
"SpacesInParentheses", SpacesInParentheses);
942IO.mapOptional(
"UseCRLF", UseCRLF);
948IO.mapOptional(
"AlignConsecutiveAssignments",
950IO.mapOptional(
"AlignConsecutiveBitFields",
952IO.mapOptional(
"AlignConsecutiveDeclarations",
955IO.mapOptional(
"AlignConsecutiveShortCaseStatements",
957IO.mapOptional(
"AlignConsecutiveTableGenBreakingDAGArgColons",
959IO.mapOptional(
"AlignConsecutiveTableGenCondOperatorColons",
961IO.mapOptional(
"AlignConsecutiveTableGenDefinitionColons",
966IO.mapOptional(
"AllowAllArgumentsOnNextLine",
968IO.mapOptional(
"AllowAllParametersOfDeclarationOnNextLine",
970IO.mapOptional(
"AllowBreakBeforeNoexceptSpecifier",
972IO.mapOptional(
"AllowShortBlocksOnASingleLine",
974IO.mapOptional(
"AllowShortCaseExpressionOnASingleLine",
976IO.mapOptional(
"AllowShortCaseLabelsOnASingleLine",
978IO.mapOptional(
"AllowShortCompoundRequirementOnASingleLine",
980IO.mapOptional(
"AllowShortEnumsOnASingleLine",
982IO.mapOptional(
"AllowShortFunctionsOnASingleLine",
984IO.mapOptional(
"AllowShortIfStatementsOnASingleLine",
986IO.mapOptional(
"AllowShortLambdasOnASingleLine",
988IO.mapOptional(
"AllowShortLoopsOnASingleLine",
990IO.mapOptional(
"AllowShortNamespacesOnASingleLine",
992IO.mapOptional(
"AlwaysBreakAfterDefinitionReturnType",
994IO.mapOptional(
"AlwaysBreakBeforeMultilineStrings",
1000IO.mapOptional(
"BracedInitializerIndentWidth",
1003IO.mapOptional(
"BreakAdjacentStringLiterals",
1006IO.mapOptional(
"BreakAfterJavaFieldAnnotations",
1009IO.mapOptional(
"BreakArrays", Style.
BreakArrays);
1010IO.mapOptional(
"BreakBeforeBinaryOperators",
1012IO.mapOptional(
"BreakBeforeConceptDeclarations",
1015IO.mapOptional(
"BreakBeforeInlineASMColon",
1017IO.mapOptional(
"BreakBeforeTernaryOperators",
1020IO.mapOptional(
"BreakConstructorInitializers",
1022IO.mapOptional(
"BreakFunctionDefinitionParameters",
1026IO.mapOptional(
"BreakTemplateDeclarations",
1028IO.mapOptional(
"ColumnLimit", Style.
ColumnLimit);
1031IO.mapOptional(
"ConstructorInitializerIndentWidth",
1037IO.mapOptional(
"EmptyLineAfterAccessModifier",
1039IO.mapOptional(
"EmptyLineBeforeAccessModifier",
1041IO.mapOptional(
"ExperimentalAutoDetectBinPacking",
1045IO.mapOptional(
"IfMacros", Style.
IfMacros);
1049IO.mapOptional(
"IncludeIsMainSourceRegex",
1059IO.mapOptional(
"IndentWidth", Style.
IndentWidth);
1060IO.mapOptional(
"IndentWrappedFunctionNames",
1062IO.mapOptional(
"InsertBraces", Style.
InsertBraces);
1070IO.mapOptional(
"KeepFormFeed", Style.
KeepFormFeed);
1072IO.mapOptional(
"LineEnding", Style.
LineEnding);
1075IO.mapOptional(
"Macros", Style.
Macros);
1082IO.mapOptional(
"ObjCBreakBeforeNestedBlockParam",
1084IO.mapOptional(
"ObjCPropertyAttributeOrder",
1087IO.mapOptional(
"ObjCSpaceBeforeProtocolList",
1089IO.mapOptional(
"PackConstructorInitializers",
1092IO.mapOptional(
"PenaltyBreakBeforeFirstCallParameter",
1094IO.mapOptional(
"PenaltyBreakBeforeMemberAccess",
1097IO.mapOptional(
"PenaltyBreakFirstLessLess",
1099IO.mapOptional(
"PenaltyBreakOpenParenthesis",
1101IO.mapOptional(
"PenaltyBreakScopeResolution",
1104IO.mapOptional(
"PenaltyBreakTemplateDeclaration",
1107IO.mapOptional(
"PenaltyIndentedWhitespace",
1109IO.mapOptional(
"PenaltyReturnTypeOnItsOwnLine",
1125IO.mapOptional(
"RemoveEmptyLinesInUnwrappedLines",
1130IO.mapOptional(
"RequiresExpressionIndentation",
1135IO.mapOptional(
"SortIncludes", Style.
SortIncludes);
1140IO.mapOptional(
"SpaceAfterTemplateKeyword",
1142IO.mapOptional(
"SpaceAroundPointerQualifiers",
1144IO.mapOptional(
"SpaceBeforeAssignmentOperators",
1147IO.mapOptional(
"SpaceBeforeCpp11BracedList",
1149IO.mapOptional(
"SpaceBeforeCtorInitializerColon",
1151IO.mapOptional(
"SpaceBeforeInheritanceColon",
1156IO.mapOptional(
"SpaceBeforeRangeBasedForLoopColon",
1158IO.mapOptional(
"SpaceBeforeSquareBrackets",
1161IO.mapOptional(
"SpacesBeforeTrailingComments",
1164IO.mapOptional(
"SpacesInContainerLiterals",
1166IO.mapOptional(
"SpacesInLineCommentPrefix",
1171IO.mapOptional(
"Standard", Style.
Standard);
1172IO.mapOptional(
"StatementAttributeLikeMacros",
1175IO.mapOptional(
"TableGenBreakingDAGArgOperators",
1177IO.mapOptional(
"TableGenBreakInsideDAGArg",
1179IO.mapOptional(
"TabWidth", Style.
TabWidth);
1181IO.mapOptional(
"TypeNames", Style.
TypeNames);
1183IO.mapOptional(
"UseTab", Style.
UseTab);
1185IO.mapOptional(
"VerilogBreakBetweenInstancePorts",
1187IO.mapOptional(
"WhitespaceSensitiveMacros",
1189IO.mapOptional(
"WrapNamespaceBodyWithEmptyLines",
1198FormatStyle::DRTBS_All) {
1201FormatStyle::DRTBS_TopLevel) {
1208 if(BreakBeforeInheritanceComma &&
1216 if(BreakConstructorInitializersBeforeComma &&
1221 if(!IsGoogleOrChromium) {
1225? FormatStyle::PCIS_NextLine
1226: FormatStyle::PCIS_CurrentLine;
1229FormatStyle::PCIS_NextLine) {
1232 else if(!OnNextLine)
1236 if(Style.
LineEnding== FormatStyle::LE_DeriveLF) {
1237 if(!DeriveLineEnding)
1238Style.
LineEnding= UseCRLF ? FormatStyle::LE_CRLF : FormatStyle::LE_LF;
1240Style.
LineEnding= FormatStyle::LE_DeriveCRLF;
1244(SpacesInParentheses || SpaceInEmptyParentheses ||
1245SpacesInConditionalStatement || SpacesInCStyleCastParentheses)) {
1246 if(SpacesInParentheses) {
1251SpacesInCStyleCastParentheses;
1253SpaceInEmptyParentheses;
1258SpacesInConditionalStatement;
1260SpacesInCStyleCastParentheses;
1262SpaceInEmptyParentheses;
1274template<>
structDocumentListTraits<
std::vector<FormatStyle>> {
1275 static size_t size(IO &IO, std::vector<FormatStyle> &Seq) {
1280 if(Index >= Seq.size()) {
1281assert(Index == Seq.size());
1283 if(!Seq.empty() && Seq[0].Language == FormatStyle::LK_None) {
1286Template = *((
const FormatStyle*)IO.getContext());
1287Template.
Language= FormatStyle::LK_None;
1289Seq.resize(Index + 1, Template);
1309 returnllvm::make_error<llvm::StringError>(Message,
1310llvm::inconvertibleErrorCode());
1314 return "clang-format.parse_error";
1322 return "Invalid argument";
1324 return "Unsuitable";
1326 return "trailing comma insertion cannot be used with bin packing";
1328 return "Invalid qualifier specified in QualifierOrder";
1330 return "Duplicate qualifier specified in QualifierOrder";
1332 return "Missing type in QualifierOrder";
1334 return "Missing QualifierOrder";
1336llvm_unreachable(
"unexpected parse error");
1560LLVMStyle.
IfMacros.push_back(
"KJ_IF_MAYBE");
1563{
"^\"(llvm|llvm-c|clang|clang-c)/", 2, 0,
false},
1564{
"^(<|\"(gtest|gmock|isl|json)/)", 3, 0,
false},
1565{
".*", 1, 0,
false}};
1714{
"^<.*\\.h>", 1, 0,
false},
1715{
"^<.*", 2, 0,
false},
1716{
".*", 3, 0,
false}};
1756 "PARSE_PARTIAL_TEXT_PROTO",
1757 "PARSE_TEST_PROTO",
1758 "PARSE_TEXT_PROTO",
1760 "ParseTextProtoOrDie",
1762 "ParsePartialTestProto",
1874 "com.google.android.apps.chrome",
1893 returnChromiumStyle;
1919 returnMozillaStyle;
2014 if(Name.equals_insensitive(
"llvm"))
2016 else if(Name.equals_insensitive(
"chromium"))
2018 else if(Name.equals_insensitive(
"mozilla"))
2020 else if(Name.equals_insensitive(
"google"))
2022 else if(Name.equals_insensitive(
"webkit"))
2024 else if(Name.equals_insensitive(
"gnu"))
2026 else if(Name.equals_insensitive(
"microsoft"))
2028 else if(Name.equals_insensitive(
"clang-format"))
2030 else if(Name.equals_insensitive(
"none"))
2032 else if(Name.equals_insensitive(
"inheritparentconfig"))
2048 if(Qualifier ==
"type")
2052 if(token == tok::identifier)
2057std::set<std::string> UniqueQualifiers(Style->
QualifierOrder.begin(),
2060LLVM_DEBUG(llvm::dbgs()
2062<<
" vs "<< UniqueQualifiers.size() <<
"\n");
2075llvm::SourceMgr::DiagHandlerTy DiagHandler,
2076 void*DiagHandlerCtxt) {
2080 if(Config.getBuffer().trim().empty())
2082Style->StyleSet.
Clear();
2083std::vector<FormatStyle> Styles;
2084llvm::yaml::Input Input(Config,
nullptr, DiagHandler,
2090Input.setContext(Style);
2091Input.setAllowUnknownKeys(AllowUnknownOptions);
2094 returnInput.error();
2096 for(
unsignedi = 0; i < Styles.size(); ++i) {
2101 for(
unsignedj = 0; j < i; ++j) {
2103LLVM_DEBUG(llvm::dbgs()
2104<<
"Duplicate languages in the config file on positions " 2105<< j <<
" and "<< i <<
"\n");
2114 boolLanguageFound =
false;
2115 for(
const FormatStyle&Style : llvm::reverse(Styles)) {
2117StyleSet.
Add(Style);
2119LanguageFound =
true;
2121 if(!LanguageFound) {
2126StyleSet.
Add(std::move(DefaultStyle));
2141llvm::raw_string_ostream Stream(
Text);
2142llvm::yaml::Output Output(Stream);
2149Output << NonConstStyle;
2151 returnStream.str();
2154std::optional<FormatStyle>
2157 returnstd::nullopt;
2158 autoIt = Styles->find(
Language);
2159 if(It == Styles->end())
2160 returnstd::nullopt;
2162Style.StyleSet = *
this;
2168 "Cannot add a style for LK_None to a StyleSet");
2170!Style.StyleSet.Styles &&
2171 "Cannot add a style associated with an existing StyleSet to a StyleSet");
2173Styles = std::make_shared<MapType>();
2174(*Styles)[Style.
Language] = std::move(Style);
2179std::optional<FormatStyle>
2191std::pair<tooling::Replacements, unsigned>
2192analyze(TokenAnnotator &Annotator,
2194FormatTokenLexer &Tokens)
override{
2195AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2197removeParens(AnnotatedLines, Result);
2202 voidremoveParens(SmallVectorImpl<AnnotatedLine *> &Lines,
2203tooling::Replacements &Result) {
2204 const auto&SourceMgr =
Env.getSourceManager();
2205 for(
auto*Line : Lines) {
2206 if(!Line->Children.empty())
2207removeParens(Line->Children, Result);
2208 if(!Line->Affected)
2210 for(
const auto*Token = Line->First; Token && !Token->Finalized;
2211Token = Token->Next) {
2212 if(!Token->Optional || !Token->isOneOf(tok::l_paren, tok::r_paren))
2214 auto*Next = Token->Next;
2215assert(Next && Next->isNot(tok::eof));
2216SourceLocation Start;
2217 if(Next->NewlinesBefore == 0) {
2218Start = Token->Tok.getLocation();
2219Next->WhitespaceRange = Token->WhitespaceRange;
2221Start = Token->WhitespaceRange.getBegin();
2223 const auto&
Range=
2224CharSourceRange::getCharRange(Start, Token->Tok.getEndLoc());
2225cantFail(Result.add(tooling::Replacement(SourceMgr,
Range,
" ")));
2231classBracesInserter :
publicTokenAnalyzer {
2233BracesInserter(
constEnvironment &
Env,
const FormatStyle&Style)
2234: TokenAnalyzer(
Env, Style) {}
2236std::pair<tooling::Replacements, unsigned>
2237analyze(TokenAnnotator &Annotator,
2238SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2239FormatTokenLexer &Tokens)
override{
2240AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2241tooling::Replacements Result;
2242insertBraces(AnnotatedLines, Result);
2247 voidinsertBraces(SmallVectorImpl<AnnotatedLine *> &Lines,
2248tooling::Replacements &Result) {
2249 const auto&SourceMgr =
Env.getSourceManager();
2250 intOpeningBraceSurplus = 0;
2251 for(AnnotatedLine *Line : Lines) {
2252 if(!Line->Children.empty())
2253insertBraces(Line->Children, Result);
2254 if(!Line->Affected && OpeningBraceSurplus == 0)
2256 for(FormatToken *Token = Line->First; Token && !Token->Finalized;
2257Token = Token->Next) {
2258 intBraceCount = Token->BraceCount;
2259 if(BraceCount == 0)
2262 if(BraceCount < 0) {
2263assert(BraceCount == -1);
2264 if(!Line->Affected)
2266 Brace= Token->is(tok::comment) ?
"\n{":
"{";
2267++OpeningBraceSurplus;
2269 if(OpeningBraceSurplus == 0)
2271 if(OpeningBraceSurplus < BraceCount)
2272BraceCount = OpeningBraceSurplus;
2273 Brace=
'\n'+ std::string(BraceCount,
'}');
2274OpeningBraceSurplus -= BraceCount;
2276Token->BraceCount = 0;
2277 const autoStart = Token->Tok.getEndLoc();
2278cantFail(Result.add(tooling::Replacement(SourceMgr, Start, 0,
Brace)));
2281assert(OpeningBraceSurplus == 0);
2285classBracesRemover :
publicTokenAnalyzer {
2287BracesRemover(
constEnvironment &
Env,
const FormatStyle&Style)
2288: TokenAnalyzer(
Env, Style) {}
2290std::pair<tooling::Replacements, unsigned>
2291analyze(TokenAnnotator &Annotator,
2292SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2293FormatTokenLexer &Tokens)
override{
2294AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2295tooling::Replacements Result;
2296removeBraces(AnnotatedLines, Result);
2301 voidremoveBraces(SmallVectorImpl<AnnotatedLine *> &Lines,
2302tooling::Replacements &Result) {
2303 const auto&SourceMgr =
Env.getSourceManager();
2304 const auto*End = Lines.end();
2305 for(
const auto*I = Lines.begin(); I != End; ++I) {
2306 const auto&Line = *I;
2307 if(!Line->Children.empty())
2308removeBraces(Line->Children, Result);
2309 if(!Line->Affected)
2311 const auto*NextLine = I + 1 == End ? nullptr : I[1];
2312 for(
const auto*Token = Line->First; Token && !Token->Finalized;
2313Token = Token->Next) {
2314 if(!Token->Optional)
2316 if(!Token->isOneOf(tok::l_brace, tok::r_brace))
2318 auto*Next = Token->Next;
2319assert(Next || Token == Line->Last);
2320 if(!Next && NextLine)
2321Next = NextLine->First;
2322SourceLocation Start;
2323 if(Next && Next->NewlinesBefore == 0 && Next->isNot(tok::eof)) {
2324Start = Token->Tok.getLocation();
2325Next->WhitespaceRange = Token->WhitespaceRange;
2327Start = Token->WhitespaceRange.getBegin();
2329 const auto&
Range=
2330CharSourceRange::getCharRange(Start, Token->Tok.getEndLoc());
2331cantFail(Result.add(tooling::Replacement(SourceMgr,
Range,
"")));
2337classSemiRemover :
publicTokenAnalyzer {
2340: TokenAnalyzer(
Env, Style) {}
2342std::pair<tooling::Replacements, unsigned>
2343analyze(TokenAnnotator &Annotator,
2344SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2345FormatTokenLexer &Tokens)
override{
2346AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2347tooling::Replacements Result;
2348removeSemi(Annotator, AnnotatedLines, Result);
2353 voidremoveSemi(TokenAnnotator &Annotator,
2354SmallVectorImpl<AnnotatedLine *> &Lines,
2355tooling::Replacements &Result) {
2356 autoPrecededByFunctionRBrace = [](
constFormatToken &Tok) {
2357 const auto*Prev = Tok.Previous;
2358 if(!Prev || Prev->isNot(tok::r_brace))
2360 const auto*LBrace = Prev->MatchingParen;
2361 returnLBrace && LBrace->is(TT_FunctionLBrace);
2363 const auto&SourceMgr =
Env.getSourceManager();
2364 const auto*End = Lines.end();
2365 for(
const auto*I = Lines.begin(); I != End; ++I) {
2366 const auto&Line = *I;
2367 if(!Line->Children.empty())
2368removeSemi(Annotator, Line->Children, Result);
2369 if(!Line->Affected)
2371Annotator.calculateFormattingInformation(*Line);
2372 const auto*NextLine = I + 1 == End ? nullptr : I[1];
2373 for(
const auto*Token = Line->First; Token && !Token->Finalized;
2374Token = Token->Next) {
2375 if(Token->isNot(tok::semi) ||
2376(!Token->Optional && !PrecededByFunctionRBrace(*Token))) {
2379 auto*Next = Token->Next;
2380assert(Next || Token == Line->Last);
2381 if(!Next && NextLine)
2382Next = NextLine->First;
2383SourceLocation Start;
2384 if(Next && Next->NewlinesBefore == 0 && Next->isNot(tok::eof)) {
2385Start = Token->Tok.getLocation();
2386Next->WhitespaceRange = Token->WhitespaceRange;
2388Start = Token->WhitespaceRange.getBegin();
2390 const auto&
Range=
2391CharSourceRange::getCharRange(Start, Token->Tok.getEndLoc());
2392cantFail(Result.add(tooling::Replacement(SourceMgr,
Range,
"")));
2398classJavaScriptRequoter :
publicTokenAnalyzer {
2400JavaScriptRequoter(
constEnvironment &
Env,
const FormatStyle&Style)
2401: TokenAnalyzer(
Env, Style) {}
2403std::pair<tooling::Replacements, unsigned>
2404analyze(TokenAnnotator &Annotator,
2405SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2406FormatTokenLexer &Tokens)
override{
2407AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2408tooling::Replacements Result;
2409requoteJSStringLiteral(AnnotatedLines, Result);
2416 voidrequoteJSStringLiteral(SmallVectorImpl<AnnotatedLine *> &Lines,
2417tooling::Replacements &Result) {
2418 for(AnnotatedLine *Line : Lines) {
2419requoteJSStringLiteral(Line->Children, Result);
2420 if(!Line->Affected)
2422 for(FormatToken *FormatTok = Line->First; FormatTok;
2423FormatTok = FormatTok->Next) {
2424StringRef Input = FormatTok->TokenText;
2425 if(FormatTok->Finalized || !FormatTok->isStringLiteral() ||
2429!Input.starts_with(
"\"")) ||
2431!Input.starts_with(
"\'"))) {
2437SourceLocation Start = FormatTok->Tok.getLocation();
2438 autoReplace = [&](SourceLocation Start,
unsignedLength,
2439StringRef ReplacementText) {
2440 autoErr = Result.add(tooling::Replacement(
2441 Env.getSourceManager(), Start, Length, ReplacementText));
2445llvm::errs() <<
toString(std::move(Err)) <<
"\n";
2449Replace(Start, 1, IsSingle ?
"'":
"\"");
2450Replace(FormatTok->Tok.getEndLoc().getLocWithOffset(-1), 1,
2451IsSingle ?
"'":
"\"");
2454 boolEscaped =
false;
2455 for(
size_ti = 1; i < Input.size() - 1; i++) {
2458 if(!Escaped && i + 1 < Input.size() &&
2459((IsSingle && Input[i + 1] ==
'"') ||
2460(!IsSingle && Input[i + 1] ==
'\''))) {
2463Replace(Start.getLocWithOffset(i), 1,
"");
2470 if(!Escaped && IsSingle == (Input[i] ==
'\'')) {
2472Replace(Start.getLocWithOffset(i), 0,
"\\");
2486classFormatter :
publicTokenAnalyzer {
2489FormattingAttemptStatus *Status)
2490: TokenAnalyzer(
Env, Style), Status(Status) {}
2492std::pair<tooling::Replacements, unsigned>
2493analyze(TokenAnnotator &Annotator,
2494SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2495FormatTokenLexer &Tokens)
override{
2496tooling::Replacements Result;
2497deriveLocalStyle(AnnotatedLines);
2498AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2499 for(AnnotatedLine *Line : AnnotatedLines)
2500Annotator.calculateFormattingInformation(*Line);
2501Annotator.setCommentLineLevels(AnnotatedLines);
2503WhitespaceManager Whitespaces(
2504 Env.getSourceManager(), Style,
2506? WhitespaceManager::inputUsesCRLF(
2507 Env.getSourceManager().getBufferData(
Env.getFileID()),
2508Style.
LineEnding== FormatStyle::LE_DeriveCRLF)
2509: Style.
LineEnding== FormatStyle::LE_CRLF);
2510ContinuationIndenter
Indenter(Style, Tokens.getKeywords(),
2511 Env.getSourceManager(), Whitespaces, Encoding,
2512BinPackInconclusiveFunctions);
2514UnwrappedLineFormatter(&
Indenter, &Whitespaces, Style,
2515Tokens.getKeywords(),
Env.getSourceManager(),
2517.format(AnnotatedLines,
false,
2520 Env.getFirstStartColumn(),
2521 Env.getNextStartColumn(),
2522 Env.getLastStartColumn());
2523 for(
const auto&R : Whitespaces.generateReplacements())
2525 returnstd::make_pair(Result, 0);
2526 returnstd::make_pair(Result, Penalty);
2531hasCpp03IncompatibleFormat(
constSmallVectorImpl<AnnotatedLine *> &Lines) {
2532 for(
constAnnotatedLine *Line : Lines) {
2533 if(hasCpp03IncompatibleFormat(Line->Children))
2535 for(FormatToken *Tok = Line->First->Next; Tok; Tok = Tok->Next) {
2536 if(!Tok->hasWhitespaceBefore()) {
2537 if(Tok->is(tok::coloncolon) && Tok->Previous->is(TT_TemplateOpener))
2539 if(Tok->is(TT_TemplateCloser) &&
2540Tok->Previous->is(TT_TemplateCloser)) {
2549 intcountVariableAlignments(
constSmallVectorImpl<AnnotatedLine *> &Lines) {
2550 intAlignmentDiff = 0;
2551 for(
constAnnotatedLine *Line : Lines) {
2552AlignmentDiff += countVariableAlignments(Line->Children);
2553 for(FormatToken *Tok = Line->First; Tok && Tok->Next; Tok = Tok->Next) {
2554 if(Tok->isNot(TT_PointerOrReference))
2557 if(
const auto*Prev = Tok->getPreviousNonComment()) {
2558 if(Prev->is(tok::r_paren) && Prev->MatchingParen) {
2559 if(
const auto*Func =
2560Prev->MatchingParen->getPreviousNonComment()) {
2561 if(
Func->isOneOf(TT_FunctionDeclarationName, TT_StartOfName,
2562TT_OverloadedOperator)) {
2568 boolSpaceBefore = Tok->hasWhitespaceBefore();
2569 boolSpaceAfter = Tok->Next->hasWhitespaceBefore();
2570 if(SpaceBefore && !SpaceAfter)
2572 if(!SpaceBefore && SpaceAfter)
2576 returnAlignmentDiff;
2580deriveLocalStyle(
constSmallVectorImpl<AnnotatedLine *> &AnnotatedLines) {
2581 boolHasBinPackedFunction =
false;
2582 boolHasOnePerLineFunction =
false;
2583 for(AnnotatedLine *Line : AnnotatedLines) {
2584 if(!Line->First->Next)
2586FormatToken *Tok = Line->First->Next;
2588 if(Tok->is(PPK_BinPacked))
2589HasBinPackedFunction =
true;
2590 if(Tok->is(PPK_OnePerLine))
2591HasOnePerLineFunction =
true;
2597 const autoNetRightCount = countVariableAlignments(AnnotatedLines);
2598 if(NetRightCount > 0)
2600 else if(NetRightCount < 0)
2604 if(Style.
Standard== FormatStyle::LS_Auto) {
2605Style.
Standard= hasCpp03IncompatibleFormat(AnnotatedLines)
2606? FormatStyle::LS_Latest
2607: FormatStyle::LS_Cpp03;
2609BinPackInconclusiveFunctions =
2610HasBinPackedFunction || !HasOnePerLineFunction;
2613 boolBinPackInconclusiveFunctions;
2614FormattingAttemptStatus *Status;
2628classTrailingCommaInserter :
publicTokenAnalyzer {
2630TrailingCommaInserter(
constEnvironment &
Env,
const FormatStyle&Style)
2631: TokenAnalyzer(
Env, Style) {}
2633std::pair<tooling::Replacements, unsigned>
2634analyze(TokenAnnotator &Annotator,
2635SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2636FormatTokenLexer &Tokens)
override{
2637AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2638tooling::Replacements Result;
2639insertTrailingCommas(AnnotatedLines, Result);
2646 voidinsertTrailingCommas(SmallVectorImpl<AnnotatedLine *> &Lines,
2647tooling::Replacements &Result) {
2648 for(AnnotatedLine *Line : Lines) {
2649insertTrailingCommas(Line->Children, Result);
2650 if(!Line->Affected)
2652 for(FormatToken *FormatTok = Line->First; FormatTok;
2653FormatTok = FormatTok->Next) {
2654 if(FormatTok->NewlinesBefore == 0)
2656FormatToken *Matching = FormatTok->MatchingParen;
2657 if(!Matching || !FormatTok->getPreviousNonComment())
2659 if(!(FormatTok->is(tok::r_square) &&
2660Matching->is(TT_ArrayInitializerLSquare)) &&
2661!(FormatTok->is(tok::r_brace) && Matching->is(TT_DictLiteral))) {
2664FormatToken *Prev = FormatTok->getPreviousNonComment();
2665 if(Prev->is(tok::comma) || Prev->is(tok::semi))
2669SourceLocation Start =
2670Prev->Tok.getLocation().getLocWithOffset(Prev->TokenText.size());
2674 unsignedColumnNumber =
2675 Env.getSourceManager().getSpellingColumnNumber(Start);
2680cantFail(Result.add(
2681tooling::Replacement(
Env.getSourceManager(), Start, 0,
",")));
2689classCleaner :
publicTokenAnalyzer {
2692: TokenAnalyzer(
Env, Style),
2693DeletedTokens(FormatTokenLess(
Env.getSourceManager())) {}
2696std::pair<tooling::Replacements, unsigned>
2697analyze(TokenAnnotator &Annotator,
2698SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2699FormatTokenLexer &Tokens)
override{
2707AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
2709checkEmptyNamespace(AnnotatedLines);
2711 for(
auto*Line : AnnotatedLines)
2714 return{generateFixes(), 0};
2718 voidcleanupLine(AnnotatedLine *Line) {
2719 for(
auto*Child : Line->Children)
2722 if(Line->Affected) {
2723cleanupRight(Line->First, tok::comma, tok::comma);
2724cleanupRight(Line->First, TT_CtorInitializerColon, tok::comma);
2725cleanupRight(Line->First, tok::l_paren, tok::comma);
2726cleanupLeft(Line->First, tok::comma, tok::r_paren);
2727cleanupLeft(Line->First, TT_CtorInitializerComma, tok::l_brace);
2728cleanupLeft(Line->First, TT_CtorInitializerColon, tok::l_brace);
2729cleanupLeft(Line->First, TT_CtorInitializerColon, tok::equal);
2733 boolcontainsOnlyComments(
constAnnotatedLine &Line) {
2734 for(FormatToken *Tok = Line.First; Tok; Tok = Tok->Next)
2735 if(Tok->isNot(tok::comment))
2741 voidcheckEmptyNamespace(SmallVectorImpl<AnnotatedLine *> &AnnotatedLines) {
2742std::set<unsigned> DeletedLines;
2743 for(
unsignedi = 0, e = AnnotatedLines.size(); i != e; ++i) {
2744 auto&Line = *AnnotatedLines[i];
2745 if(Line.startsWithNamespace())
2746checkEmptyNamespace(AnnotatedLines, i, i, DeletedLines);
2749 for(
autoLine : DeletedLines) {
2750FormatToken *Tok = AnnotatedLines[Line]->First;
2762 boolcheckEmptyNamespace(SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2763 unsignedCurrentLine,
unsigned&
NewLine,
2764std::set<unsigned> &DeletedLines) {
2765 unsignedInitLine = CurrentLine, End = AnnotatedLines.size();
2770 if(!AnnotatedLines[++CurrentLine]->startsWith(tok::l_brace)) {
2774}
else if(!AnnotatedLines[CurrentLine]->endsWith(tok::l_brace)) {
2777 while(++CurrentLine < End) {
2778 if(AnnotatedLines[CurrentLine]->startsWith(tok::r_brace))
2781 if(AnnotatedLines[CurrentLine]->startsWithNamespace()) {
2782 if(!checkEmptyNamespace(AnnotatedLines, CurrentLine,
NewLine,
2790 if(containsOnlyComments(*AnnotatedLines[CurrentLine]))
2800 if(CurrentLine >= End)
2804 if(!AffectedRangeMgr.affectsCharSourceRange(CharSourceRange::getCharRange(
2805AnnotatedLines[InitLine]->First->Tok.getLocation(),
2806AnnotatedLines[CurrentLine]->Last->Tok.getEndLoc()))) {
2810 for(
unsignedi = InitLine; i <= CurrentLine; ++i)
2811DeletedLines.insert(i);
2820 template<
typenameLeftKind,
typenameRightKind>
2821 voidcleanupPair(FormatToken *Start, LeftKind LK, RightKind RK,
2823 autoNextNotDeleted = [
this](
constFormatToken &Tok) -> FormatToken * {
2824 for(
auto*Res = Tok.Next; Res; Res = Res->Next) {
2825 if(Res->isNot(tok::comment) &&
2826DeletedTokens.find(Res) == DeletedTokens.end()) {
2832 for(
auto*Left = Start;
Left;) {
2833 auto*
Right= NextNotDeleted(*Left);
2837deleteToken(DeleteLeft ? Left : Right);
2838 for(
auto*Tok =
Left->Next; Tok && Tok != Right; Tok = Tok->Next)
2849 template<
typenameLeftKind,
typenameRightKind>
2850 voidcleanupLeft(FormatToken *Start, LeftKind LK, RightKind RK) {
2851cleanupPair(Start, LK, RK,
true);
2854 template<
typenameLeftKind,
typenameRightKind>
2855 voidcleanupRight(FormatToken *Start, LeftKind LK, RightKind RK) {
2856cleanupPair(Start, LK, RK,
false);
2860 inline voiddeleteToken(FormatToken *Tok) {
2862DeletedTokens.insert(Tok);
2865tooling::Replacements generateFixes() {
2866tooling::Replacements Fixes;
2867SmallVector<FormatToken *> Tokens;
2868std::copy(DeletedTokens.begin(), DeletedTokens.end(),
2869std::back_inserter(Tokens));
2875 while(Idx < Tokens.size()) {
2876 unsignedSt = Idx, End = Idx;
2877 while((End + 1) < Tokens.size() && Tokens[End]->Next == Tokens[End + 1])
2879 autoSR = CharSourceRange::getCharRange(Tokens[St]->Tok.getLocation(),
2880Tokens[End]->Tok.getEndLoc());
2882Fixes.add(tooling::Replacement(
Env.getSourceManager(), SR,
""));
2886llvm::errs() <<
toString(std::move(Err)) <<
"\n";
2887assert(
false&&
"Fixes must not conflict!");
2898 structFormatTokenLess {
2899FormatTokenLess(
constSourceManager &
SM) :
SM(
SM) {}
2901 booloperator()(
constFormatToken *LHS,
constFormatToken *RHS)
const{
2902 return SM.isBeforeInTranslationUnit(LHS->Tok.getLocation(),
2903RHS->Tok.getLocation());
2905 constSourceManager &
SM;
2909std::set<FormatToken *, FormatTokenLess> DeletedTokens;
2912classObjCHeaderStyleGuesser :
publicTokenAnalyzer {
2914ObjCHeaderStyleGuesser(
constEnvironment &
Env,
const FormatStyle&Style)
2915: TokenAnalyzer(
Env, Style), IsObjC(
false) {}
2917std::pair<tooling::Replacements, unsigned>
2918analyze(TokenAnnotator &Annotator,
2919SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2920FormatTokenLexer &Tokens)
override{
2921assert(Style.
Language== FormatStyle::LK_Cpp);
2922IsObjC = guessIsObjC(
Env.getSourceManager(), AnnotatedLines,
2923Tokens.getKeywords());
2924tooling::Replacements Result;
2928 bool isObjC() {
returnIsObjC; }
2932guessIsObjC(
constSourceManager &SourceManager,
2933 constSmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
2934 constAdditionalKeywords &Keywords) {
2936 static constexprllvm::StringLiteral FoundationIdentifiers[] = {
2951 "FOUNDATION_EXPORT",
2952 "FOUNDATION_EXTERN",
2953 "NSAffineTransform",
2955 "NSAttributedString",
2956 "NSBlockOperation",
2974 "NSInvocationOperation",
2978 "NSMutableAttributedString",
2979 "NSMutableCharacterSet",
2981 "NSMutableDictionary",
2982 "NSMutableIndexSet",
2983 "NSMutableOrderedSet",
2987 "NSNumberFormatter",
2990 "NSOperationQueue",
2991 "NSOperationQueuePriority",
2995 "NSQualityOfService",
2998 "NSRegularExpression",
3009 "NS_ASSUME_NONNULL_BEGIN",
3014 for(
auto*Line : AnnotatedLines) {
3015 if(Line->First && (Line->First->TokenText.starts_with(
"#") ||
3016Line->First->TokenText ==
"__pragma"||
3017Line->First->TokenText ==
"_Pragma")) {
3020 for(
constFormatToken *FormatTok = Line->First; FormatTok;
3021FormatTok = FormatTok->Next) {
3022 if((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&
3023(FormatTok->Tok.getObjCKeywordID() != tok::objc_not_keyword ||
3024FormatTok->isOneOf(tok::numeric_constant, tok::l_square,
3026(FormatTok->Tok.isAnyIdentifier() &&
3027std::binary_search(std::begin(FoundationIdentifiers),
3028std::end(FoundationIdentifiers),
3029FormatTok->TokenText)) ||
3030FormatTok->is(TT_ObjCStringLiteral) ||
3031FormatTok->isOneOf(Keywords.kw_NS_CLOSED_ENUM, Keywords.kw_NS_ENUM,
3032Keywords.kw_NS_ERROR_ENUM,
3033Keywords.kw_NS_OPTIONS, TT_ObjCBlockLBrace,
3034TT_ObjCBlockLParen, TT_ObjCDecl, TT_ObjCForIn,
3035TT_ObjCMethodExpr, TT_ObjCMethodSpecifier,
3037LLVM_DEBUG(llvm::dbgs()
3038<<
"Detected ObjC at location " 3039<< FormatTok->Tok.getLocation().printToString(
3041<<
" token: "<< FormatTok->TokenText <<
" token type: " 3046 if(guessIsObjC(SourceManager, Line->Children, Keywords))
3063structJavaImportDirective {
3076 for(
const auto&
Range: Ranges) {
3077 if(
Range.getOffset() < End &&
3078 Range.getOffset() +
Range.getLength() > Start) {
3092staticstd::pair<unsigned, unsigned>
3096 unsignedOffsetToEOL = 0;
3097 for(
inti = 0, e = Includes.size(); i != e; ++i) {
3098 unsignedStart = Includes[Indices[i]].Offset;
3099 unsignedEnd = Start + Includes[Indices[i]].Text.size();
3100 if(!(Cursor >= Start && Cursor < End))
3102CursorIndex = Indices[i];
3103OffsetToEOL = End - Cursor;
3106 while(--i >= 0 && Includes[CursorIndex].
Text== Includes[Indices[i]].
Text)
3110 returnstd::make_pair(CursorIndex, OffsetToEOL);
3115std::string NewCode;
3116 size_tPos = 0, LastPos = 0;
3119Pos = Code.find(
"\r\n", LastPos);
3120 if(Pos == LastPos) {
3124 if(Pos == std::string::npos) {
3125NewCode += Code.substr(LastPos);
3128NewCode += Code.substr(LastPos, Pos - LastPos) +
"\n";
3130}
while(Pos != std::string::npos);
3148 const unsignedIncludesBeginOffset = Includes.front().Offset;
3149 const unsignedIncludesEndOffset =
3150Includes.back().Offset + Includes.back().Text.size();
3151 const unsignedIncludesBlockSize = IncludesEndOffset - IncludesBeginOffset;
3152 if(!
affectsRange(Ranges, IncludesBeginOffset, IncludesEndOffset))
3155llvm::to_vector<16>(llvm::seq<unsigned>(0, Includes.size()));
3158stable_sort(Indices, [&](
unsignedLHSI,
unsignedRHSI) {
3159 const autoLHSFilenameLower = Includes[LHSI].Filename.lower();
3160 const autoRHSFilenameLower = Includes[RHSI].Filename.lower();
3161 returnstd::tie(Includes[LHSI].
Priority, LHSFilenameLower,
3163std::tie(Includes[RHSI].
Priority, RHSFilenameLower,
3167stable_sort(Indices, [&](
unsignedLHSI,
unsignedRHSI) {
3175 unsignedCursorIndex;
3177 unsignedCursorToEOLOffset;
3179std::tie(CursorIndex, CursorToEOLOffset) =
3184Indices.erase(std::unique(Indices.begin(), Indices.end(),
3185[&](
unsignedLHSI,
unsignedRHSI) {
3186return Includes[LHSI].Text.trim() ==
3187Includes[RHSI].Text.trim();
3191 intCurrentCategory = Includes.front().Category;
3199 if(Indices.size() == Includes.size() && is_sorted(Indices) &&
3204 const autoOldCursor = Cursor ? *Cursor : 0;
3206 for(
unsignedIndex : Indices) {
3207 if(!result.empty()) {
3211CurrentCategory != Includes[Index].Category) {
3215result += Includes[Index].Text;
3216 if(Cursor && CursorIndex == Index)
3217*Cursor = IncludesBeginOffset + result.size() - CursorToEOLOffset;
3218CurrentCategory = Includes[Index].Category;
3221 if(Cursor && *Cursor >= IncludesEndOffset)
3222*Cursor += result.size() - IncludesBlockSize;
3227IncludesBeginOffset, IncludesBlockSize)))) {
3229*Cursor = OldCursor;
3234 FileName, Includes.front().Offset, IncludesBlockSize, result));
3238llvm::errs() <<
toString(std::move(Err)) <<
"\n";
3248 unsignedPrev = llvm::StringSwitch<size_t>(Code)
3249.StartsWith(
"\xEF\xBB\xBF", 3)
3251 unsignedSearchFrom = 0;
3263 boolFirstIncludeBlock =
true;
3264 boolMainIncludeFound =
false;
3265 boolFormattingOff =
false;
3268llvm::Regex RawStringRegex(
3269 "R\"([][A-Za-z0-9_{}#<>%:;.?*+/^&\\$|~!=,'-]*)\\(");
3271std::string RawStringTermination =
")\"";
3273 for(
const autoSize = Code.size(); SearchFrom < Size;) {
3274 size_tPos = SearchFrom;
3275 if(Code[SearchFrom] !=
'\n') {
3278Pos = Code.find(
'\n', Pos);
3279}
while(Pos != StringRef::npos && Code[Pos - 1] ==
'\\');
3283Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev);
3285StringRef Trimmed =
Line.trim();
3290 if(RawStringRegex.match(Trimmed, &RawStringMatches)) {
3291std::string CharSequence = RawStringMatches[1].str();
3292RawStringTermination =
")"+ CharSequence +
"\"";
3293FormattingOff =
true;
3296 if(Trimmed.contains(RawStringTermination))
3297FormattingOff =
false;
3299 boolIsBlockComment =
false;
3302FormattingOff =
true;
3304FormattingOff =
false;
3305}
else if(Trimmed.starts_with(
"/*")) {
3306IsBlockComment =
true;
3307Pos = Code.find(
"*/", SearchFrom + 2);
3310 const boolEmptyLineSkipped =
3316 boolMergeWithNextLine = Trimmed.ends_with(
"\\");
3317 if(!FormattingOff && !MergeWithNextLine) {
3318 if(!IsBlockComment &&
3320StringRef IncludeName = Matches[2];
3321 if(Trimmed.contains(
"/*") && !Trimmed.contains(
"*/")) {
3326Pos = Code.find(
"*/", SearchFrom);
3328Prev, (Pos != StringRef::npos ? Pos + 2 : Code.size()) - Prev);
3332!MainIncludeFound && FirstIncludeBlock);
3334IncludeName, !MainIncludeFound && FirstIncludeBlock);
3336MainIncludeFound =
true;
3337IncludesInBlock.push_back(
3339}
else if(!IncludesInBlock.empty() && !EmptyLineSkipped) {
3342IncludesInBlock.clear();
3343 if(Trimmed.starts_with(
"#pragma hdrstop"))
3344FirstIncludeBlock =
true;
3346FirstIncludeBlock =
false;
3349 if(Pos == StringRef::npos || Pos + 1 == Code.size())
3352 if(!MergeWithNextLine)
3354SearchFrom = Pos + 1;
3356 if(!IncludesInBlock.empty()) {
3366StringRef ImportIdentifier) {
3367 unsignedLongestMatchIndex =
UINT_MAX;
3368 unsignedLongestMatchLength = 0;
3371 if(ImportIdentifier.starts_with(GroupPrefix) &&
3372GroupPrefix.length() > LongestMatchLength) {
3373LongestMatchIndex = I;
3374LongestMatchLength = GroupPrefix.length();
3377 returnLongestMatchIndex;
3389 unsignedImportsBeginOffset = Imports.front().Offset;
3390 unsignedImportsEndOffset =
3391Imports.back().Offset + Imports.back().Text.size();
3392 unsignedImportsBlockSize = ImportsEndOffset - ImportsBeginOffset;
3393 if(!
affectsRange(Ranges, ImportsBeginOffset, ImportsEndOffset))
3397llvm::to_vector<16>(llvm::seq<unsigned>(0, Imports.size()));
3400 for(
constJavaImportDirective &Import : Imports)
3403 boolStaticImportAfterNormalImport =
3405sort(Indices, [&](
unsignedLHSI,
unsignedRHSI) {
3407 returnstd::make_tuple(!Imports[LHSI].
IsStatic^
3408StaticImportAfterNormalImport,
3410std::make_tuple(!Imports[RHSI].
IsStatic^
3411StaticImportAfterNormalImport,
3416Indices.erase(std::unique(Indices.begin(), Indices.end(),
3417[&](
unsignedLHSI,
unsignedRHSI) {
3418return Imports[LHSI].Text == Imports[RHSI].Text;
3422 boolCurrentIsStatic = Imports[Indices.front()].IsStatic;
3426 for(
unsignedIndex : Indices) {
3427 if(!result.empty()) {
3429 if(CurrentIsStatic != Imports[Index].
IsStatic||
3435result += CommentLine;
3438result += Imports[Index].Text;
3439CurrentIsStatic = Imports[Index].IsStatic;
3446Imports.front().Offset, ImportsBlockSize)))) {
3451ImportsBlockSize, result));
3455llvm::errs() <<
toString(std::move(Err)) <<
"\n";
3462const charJavaImportRegexPattern[] =
3463 "^[\t ]*import[\t ]+(static[\t ]*)?([^\t ]*)[\t ]*;";
3472 unsignedSearchFrom = 0;
3473llvm::Regex ImportRegex(JavaImportRegexPattern);
3478 boolFormattingOff =
false;
3481 autoPos = Code.find(
'\n', SearchFrom);
3483Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev);
3485StringRef Trimmed =
Line.trim();
3487FormattingOff =
true;
3489FormattingOff =
false;
3491 if(ImportRegex.match(
Line, &Matches)) {
3492 if(FormattingOff) {
3497StringRef
Static= Matches[1];
3500 if(
Static.contains(
"static"))
3502ImportsInBlock.push_back(
3505}
else if(Trimmed.size() > 0 && !ImportsInBlock.empty()) {
3510 if(Pos == StringRef::npos || Pos + 1 == Code.size())
3512SearchFrom = Pos + 1;
3514 if(!ImportsInBlock.empty())
3523 returnCode.size() > 188 && Code[0] == 0x47 && Code[188] == 0x47;
3526bool isLikelyXml(StringRef Code) {
returnCode.ltrim().starts_with(
"<"); }
3530StringRef
FileName,
unsigned*Cursor) {
3548template<
typenameT>
3553 if(Replaces.
empty())
3556 autoNewCode = applyAllReplacements(Code, Replaces);
3558 returnNewCode.takeError();
3563ProcessFunc(Style, *NewCode, ChangedRanges,
FileName);
3565 returnReplaces.
merge(FormatReplaces);
3574std::vector<tooling::Range> Ranges,
3578 autoSortedReplaces =
3580 if(!SortedReplaces)
3581 returnSortedReplaces.takeError();
3585 autoReformat = [](
const FormatStyle&Style, StringRef Code,
3586std::vector<tooling::Range> Ranges,
3601inline boolisHeaderDeletion(
consttooling::Replacement &Replace) {
3602 returnReplace.getOffset() ==
UINT_MAX&& Replace.getLength() == 1;
3606tooling::Replacements
3607fixCppIncludeInsertions(StringRef Code,
consttooling::Replacements &Replaces,
3609 if(!Style.
isCpp())
3612tooling::Replacements HeaderInsertions;
3613std::set<StringRef> HeadersToDelete;
3614tooling::Replacements
Result;
3615 for(
const auto&R : Replaces) {
3616 if(isHeaderInsertion(R)) {
3619consumeError(HeaderInsertions.add(R));
3620}
else if(isHeaderDeletion(R)) {
3621HeadersToDelete.insert(R.getReplacementText());
3622}
else if(R.getOffset() ==
UINT_MAX) {
3623llvm::errs() <<
"Insertions other than header #include insertion are " 3625<< R.getReplacementText() <<
"\n";
3627consumeError(
Result.add(R));
3630 if(HeaderInsertions.empty() && HeadersToDelete.empty())
3633StringRef
FileName= Replaces.begin()->getFilePath();
3636 for(
const auto&Header : HeadersToDelete) {
3637tooling::Replacements Replaces =
3638Includes.remove(Header.trim(
"\"<>"), Header.starts_with(
"<"));
3639 for(
const auto&R : Replaces) {
3640 autoErr =
Result.add(R);
3643llvm::errs() <<
"Failed to add header deletion replacement for " 3644<< Header <<
": "<<
toString(std::move(Err)) <<
"\n";
3649SmallVector<StringRef, 4> Matches;
3650 for(
const auto&R : HeaderInsertions) {
3654assert(Matched &&
"Header insertion replacement must have replacement text " 3657 autoIncludeName = Matches[2];
3659Includes.insert(IncludeName.trim(
"\"<>"), IncludeName.starts_with(
"<"),
3662 autoErr =
Result.add(*Replace);
3664consumeError(std::move(Err));
3665 unsignedNewOffset =
3666 Result.getShiftedCodePosition(Replace->getOffset());
3667 autoShifted = tooling::Replacement(
FileName, NewOffset, 0,
3668Replace->getReplacementText());
3669 Result=
Result.merge(tooling::Replacements(Shifted));
3678Expected<tooling::Replacements>
3683 autoCleanup = [](
const FormatStyle&Style, StringRef Code,
3690fixCppIncludeInsertions(Code, Replaces, Style);
3695std::pair<tooling::Replacements, unsigned>
3698 unsignedNextStartColumn,
unsignedLastStartColumn, StringRef FileName,
3709 caseFormatStyle::RCPS_SingleLine:
3710 caseFormatStyle::RCPS_WithPreceding:
3726std::vector<tooling::Range> Ranges(1,
tooling::Range(0, Code.size()));
3727 auto Env= Environment::make(Code,
FileName, Ranges, FirstStartColumn,
3728NextStartColumn, LastStartColumn);
3733Formatter(*
Env, Style, Status).process().first;
3735Replaces = Replaces.
merge(
3738 if(applyAllReplacements(Code, Replaces))
3739 return{Replaces, 0};
3743 auto Env= Environment::make(Code,
FileName, Ranges, FirstStartColumn,
3744NextStartColumn, LastStartColumn);
3748 typedefstd::function<std::pair<tooling::Replacements, unsigned>(
3758 if(Style.
isCpp()) {
3765Passes.emplace_back([&, S = std::move(S)](
const Environment&
Env) {
3766 returnParensRemover(
Env, S).process(
true);
3772S.InsertBraces =
true;
3773Passes.emplace_back([&, S = std::move(S)](
const Environment&
Env) {
3774 returnBracesInserter(
Env, S).process(
true);
3780S.RemoveBracesLLVM =
true;
3781Passes.emplace_back([&, S = std::move(S)](
const Environment&
Env) {
3782 returnBracesRemover(
Env, S).process(
true);
3788S.RemoveSemicolon =
true;
3789Passes.emplace_back([&, S = std::move(S)](
const Environment&
Env) {
3790 returnSemiRemover(
Env, S).process();
3813 if(Style.
Language== FormatStyle::LK_ObjC &&
3823 returnJavaScriptRequoter(
Env, Expanded).process(
true);
3828 returnFormatter(
Env, Expanded, Status).process();
3834 returnTrailingCommaInserter(
Env, Expanded).process();
3838std::optional<std::string> CurrentCode;
3840 unsignedPenalty = 0;
3841 for(
size_tI = 0,
E= Passes.size(); I <
E; ++I) {
3842std::pair<tooling::Replacements, unsigned> PassFixes = Passes[I](*Env);
3843 autoNewCode = applyAllReplacements(
3844CurrentCode ? StringRef(*CurrentCode) : Code, PassFixes.first);
3846Fixes = Fixes.
merge(PassFixes.first);
3847Penalty += PassFixes.second;
3849CurrentCode = std::move(*NewCode);
3850 Env= Environment::make(
3852tooling::calculateRangesAfterReplacements(Fixes, Ranges),
3853FirstStartColumn, NextStartColumn, LastStartColumn);
3866StringRef OriginalCode = Code.substr(Fix.getOffset(), Fix.getLength());
3867 if(OriginalCode != Fix.getReplacementText()) {
3868 autoErr = NonNoOpFixes.
add(Fix);
3870llvm::errs() <<
"Error adding replacements : " 3871<<
toString(std::move(Err)) <<
"\n";
3875Fixes = std::move(NonNoOpFixes);
3878 return{Fixes, Penalty};
3902 returnCleaner(*
Env, Style).process().first;
3907StringRef
FileName,
bool*IncompleteFormat) {
3910 if(!Status.FormatComplete)
3911*IncompleteFormat =
true;
3943LangOpts.CPlusPlus = 1;
3954LangOpts.LineComment = 1;
3955LangOpts.CXXOperatorNames = Style.
isCpp();
3958LangOpts.MicrosoftExt = 1;
3959LangOpts.DeclSpecKeyword = 1;
3965 "Set coding style. <string> can be:\n" 3966 "1. A preset: LLVM, GNU, Google, Chromium, Microsoft,\n" 3967 " Mozilla, WebKit.\n" 3968 "2. 'file' to load style configuration from a\n" 3969 " .clang-format file in one of the parent directories\n" 3970 " of the source file (for stdin, see --assume-filename).\n" 3971 " If no .clang-format file is found, falls back to\n" 3972 " --fallback-style.\n" 3973 " --style=file is the default.\n" 3974 "3. 'file:<format_file_path>' to explicitly specify\n" 3975 " the configuration file.\n" 3976 "4. \"{key: value, ...}\" to set specific parameters, e.g.:\n" 3977 " --style=\"{BasedOnStyle: llvm, IndentWidth: 8}\"";
3980 if(
FileName.ends_with(
".java"))
3982 if(
FileName.ends_with_insensitive(
".js") ||
3983 FileName.ends_with_insensitive(
".mjs") ||
3984 FileName.ends_with_insensitive(
".cjs") ||
3985 FileName.ends_with_insensitive(
".ts")) {
3990 if(
FileName.ends_with_insensitive(
".proto") ||
3991 FileName.ends_with_insensitive(
".protodevel")) {
3997 if(
FileName.ends_with_insensitive(
".txtpb") ||
3998 FileName.ends_with_insensitive(
".textpb") ||
3999 FileName.ends_with_insensitive(
".pb.txt") ||
4000 FileName.ends_with_insensitive(
".textproto") ||
4001 FileName.ends_with_insensitive(
".asciipb")) {
4004 if(
FileName.ends_with_insensitive(
".td"))
4006 if(
FileName.ends_with_insensitive(
".cs"))
4008 if(
FileName.ends_with_insensitive(
".json"))
4010 if(
FileName.ends_with_insensitive(
".sv") ||
4011 FileName.ends_with_insensitive(
".svh") ||
4012 FileName.ends_with_insensitive(
".v") ||
4013 FileName.ends_with_insensitive(
".vh")) {
4022 autoExtension = llvm::sys::path::extension(
FileName);
4025 if(!Code.empty() && (Extension.empty() || Extension ==
".h")) {
4030 if(Guesser.isObjC())
4034 returnGuessedLanguage;
4042llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
4045llvm::SourceMgr::DiagHandlerTy DiagHandler) {
4046llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
Text=
4047FS->getBufferForFile(ConfigFile.str());
4048 if(
autoEC =
Text.getError())
4058StringRef FallbackStyleName, StringRef Code,
4059llvm::vfs::FileSystem *FS,
4060 boolAllowUnknownOptions,
4061llvm::SourceMgr::DiagHandlerTy DiagHandler) {
4069 if(StyleName.starts_with(
"{")) {
4071StringRef Source =
"<command-line>";
4072 if(std::error_code ec =
4074AllowUnknownOptions, DiagHandler)) {
4081ChildFormatTextToApply.emplace_back(
4082llvm::MemoryBuffer::getMemBuffer(StyleName, Source,
false));
4086FS = llvm::vfs::getRealFileSystem().get();
4091StyleName.starts_with_insensitive(
"file:")) {
4092 autoConfigFile = StyleName.substr(5);
4093llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
Text=
4096 if(
autoEC =
Text.getError()) {
4101LLVM_DEBUG(llvm::dbgs()
4102<<
"Using configuration file "<< ConfigFile <<
"\n");
4110ChildFormatTextToApply.emplace_back(std::move(*
Text));
4124 if(std::error_code EC = FS->makeAbsolute(
Path))
4130 autodropDiagnosticHandler = [](
constllvm::SMDiagnostic &,
void*) {};
4132 autoapplyChildFormatTexts = [&](
FormatStyle*Style) {
4133 for(
const auto&MemBuf : llvm::reverse(ChildFormatTextToApply)) {
4136DiagHandler ? DiagHandler : dropDiagnosticHandler);
4139 static_cast<void>(EC);
4145FilesToLookFor.push_back(
".clang-format");
4146FilesToLookFor.push_back(
"_clang-format");
4149 for(StringRef Directory =
Path; !Directory.empty();
4150Directory = llvm::sys::path::parent_path(Directory)) {
4151 autoStatus = FS->status(Directory);
4153Status->getType() != llvm::sys::fs::file_type::directory_file) {
4157 for(
const auto&F : FilesToLookFor) {
4160llvm::sys::path::append(ConfigFile, F);
4161LLVM_DEBUG(llvm::dbgs() <<
"Trying "<< ConfigFile <<
"...\n");
4163Status = FS->status(ConfigFile);
4165Status->getType() != llvm::sys::fs::file_type::regular_file) {
4169llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
Text=
4172 if(
autoEC =
Text.getError()) {
4177 if(!UnsuitableConfigFiles.empty())
4178UnsuitableConfigFiles.append(
", ");
4179UnsuitableConfigFiles.append(ConfigFile);
4183LLVM_DEBUG(llvm::dbgs()
4184<<
"Using configuration file "<< ConfigFile <<
"\n");
4187 if(!ChildFormatTextToApply.empty()) {
4188LLVM_DEBUG(llvm::dbgs() <<
"Applying child configurations\n");
4189applyChildFormatTexts(&Style);
4194LLVM_DEBUG(llvm::dbgs() <<
"Inherits parent configuration\n");
4199ChildFormatTextToApply.emplace_back(std::move(*
Text));
4209 if(!UnsuitableConfigFiles.empty()) {
4212UnsuitableConfigFiles);
4215 if(!ChildFormatTextToApply.empty()) {
4216LLVM_DEBUG(llvm::dbgs()
4217<<
"Applying child configurations on fallback style\n");
4218applyChildFormatTexts(&FallbackStyle);
4221 returnFallbackStyle;
4225 if(Comment == (On ?
"/* clang-format on */":
"/* clang-format off */"))
4228 static const charClangFormatOn[] =
"// clang-format on";
4229 static const charClangFormatOff[] =
"// clang-format off";
4230 const unsignedSize = (On ?
sizeofClangFormatOn :
sizeofClangFormatOff) - 1;
4232 returnComment.starts_with(On ? ClangFormatOn : ClangFormatOff) &&
4233(Comment.size() == Size || Comment[Size] ==
':');
This file declares DefinitionBlockSeparator, a TokenAnalyzer that inserts or removes empty lines sepa...
SmallVector< StringRef > AssociatedCommentLines
Various functions to configurably format source code.
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.
ContinuationIndenter * Indenter
Implements a combinatorial exploration of all the different linebreaks unwrapped lines can be formatt...
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...
static std::unique_ptr< Environment > make(StringRef Code, StringRef FileName, ArrayRef< tooling::Range > Ranges, unsigned FirstStartColumn=0, unsigned NextStartColumn=0, unsigned LastStartColumn=0)
std::pair< tooling::Replacements, unsigned > process(const Environment &Env, const FormatStyle &Style)
static tok::TokenKind getTokenFromQualifier(const std::string &Qualifier)
const char * name() const noexcept override
std::string message(int EV) const override
std::pair< tooling::Replacements, unsigned > process(bool SkipAnnotation=false)
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).
std::pair< tooling::Replacements, unsigned > reformat(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, unsigned FirstStartColumn, unsigned NextStartColumn, unsigned LastStartColumn, StringRef FileName, FormattingAttemptStatus *Status)
Reformats the given Ranges in the code fragment Code.
const char * StyleOptionHelpDescription
Description to be used for help text for a llvm::cl option for specifying format style.
void addQualifierAlignmentFixerPasses(const FormatStyle &Style, SmallVectorImpl< AnalyzerPass > &Passes)
static void expandPresetsSpaceBeforeParens(FormatStyle &Expanded)
const char * DefaultFallbackStyle
The suggested predefined style to use as the fallback style in getStyle.
static bool affectsRange(ArrayRef< tooling::Range > Ranges, unsigned Start, unsigned End)
const char * getTokenTypeName(TokenType Type)
Determines the name of a token type.
FormatStyle getWebKitStyle()
Returns a format style complying with Webkit's style guide: http://www.webkit.org/coding/coding-style...
bool isLikelyXml(StringRef Code)
static FormatStyle::LanguageKind getLanguageByFileName(StringRef FileName)
static unsigned findJavaImportGroup(const FormatStyle &Style, StringRef ImportIdentifier)
std::string replaceCRLF(const std::string &Code)
std::error_code make_error_code(ParseError e)
FormatStyle getClangFormatStyle()
std::function< std::pair< tooling::Replacements, unsigned >(const Environment &)> AnalyzerPass
FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language=FormatStyle::LanguageKind::LK_Cpp)
Returns a format style complying with the LLVM coding standards: http://llvm.org/docs/CodingStandards...
FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language)
Returns a format style complying with one of Google's style guides: http://google-styleguide....
std::string configurationAsText(const FormatStyle &Style)
Gets configuration in a YAML string.
FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind Language)
Returns a format style complying with Microsoft style guide: https://docs.microsoft....
std::error_code parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style, bool AllowUnknownOptions=false, llvm::SourceMgr::DiagHandlerTy DiagHandler=nullptr, void *DiagHandlerCtx=nullptr)
Parse configuration from YAML-formatted text.
const std::error_category & getParseCategory()
tooling::Replacements fixNamespaceEndComments(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName="<stdin>")
Fix namespace end comments in the given Ranges in Code.
FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code)
Expected< FormatStyle > getStyle(StringRef StyleName, StringRef FileName, StringRef FallbackStyle, StringRef Code="", llvm::vfs::FileSystem *FS=nullptr, bool AllowUnknownOptions=false, llvm::SourceMgr::DiagHandlerTy DiagHandler=nullptr)
Construct a FormatStyle based on StyleName.
bool isMpegTS(StringRef Code)
@ DuplicateQualifierSpecified
@ BinPackTrailingCommaConflict
@ InvalidQualifierSpecified
static std::pair< unsigned, unsigned > FindCursorIndex(const ArrayRef< IncludeDirective > &Includes, const ArrayRef< unsigned > &Indices, unsigned Cursor)
const char * DefaultFormatStyle
The suggested format style to use by default.
FormatStyle getGNUStyle()
Returns a format style complying with GNU Coding Standards: http://www.gnu.org/prep/standards/standar...
bool isClangFormatOff(StringRef Comment)
LangOptions getFormattingLangOpts(const FormatStyle &Style=getLLVMStyle())
Returns the LangOpts that the formatter expects you to set.
static bool isClangFormatOnOff(StringRef Comment, bool On)
tooling::Replacements sortJavaScriptImports(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName)
static void sortJavaImports(const FormatStyle &Style, const ArrayRef< JavaImportDirective > &Imports, ArrayRef< tooling::Range > Ranges, StringRef FileName, StringRef Code, tooling::Replacements &Replaces)
FormatStyle getMozillaStyle()
Returns a format style complying with Mozilla's style guide: https://firefox-source-docs....
bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language, FormatStyle *Style)
Gets a predefined style for the specified language by name.
Expected< tooling::Replacements > cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces, const FormatStyle &Style)
Returns the replacements corresponding to applying Replaces and cleaning up the code after that on su...
static void expandPresetsBraceWrapping(FormatStyle &Expanded)
static void sortCppIncludes(const FormatStyle &Style, const ArrayRef< IncludeDirective > &Includes, ArrayRef< tooling::Range > Ranges, StringRef FileName, StringRef Code, tooling::Replacements &Replaces, unsigned *Cursor)
tooling::Replacements reformat(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName="<stdin>", FormattingAttemptStatus *Status=nullptr)
Reformats the given Ranges in Code.
bool isClangFormatOn(StringRef Comment)
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > loadAndParseConfigFile(StringRef ConfigFile, llvm::vfs::FileSystem *FS, FormatStyle *Style, bool AllowUnknownOptions, llvm::SourceMgr::DiagHandlerTy DiagHandler)
tooling::Replacements sortUsingDeclarations(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName="<stdin>")
Sort consecutive using declarations in the given Ranges in Code.
llvm::Error make_string_error(const Twine &Message)
ParseError validateQualifierOrder(FormatStyle *Style)
FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language)
Returns a format style complying with Chromium's style guide: http://www.chromium....
static void expandPresetsSpacesInParens(FormatStyle &Expanded)
tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName="<stdin>")
Clean up any erroneous/redundant code in the given Ranges in Code.
Expected< tooling::Replacements > formatReplacements(StringRef Code, const tooling::Replacements &Replaces, const FormatStyle &Style)
Returns the replacements corresponding to applying and formatting Replaces on success; otheriwse,...
FormatStyle getNoStyle()
Returns style indicating formatting should be not applied at all.
tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName, unsigned *Cursor=nullptr)
Returns the replacements necessary to sort all #include blocks that are affected by Ranges.
static Expected< tooling::Replacements > processReplacements(T ProcessFunc, StringRef Code, const tooling::Replacements &Replaces, const FormatStyle &Style)
StringRef getLanguageName(FormatStyle::LanguageKind Language)
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.
bool PadOperators
Only for AlignConsecutiveAssignments.
bool AlignFunctionDeclarations
Only for AlignConsecutiveDeclarations.
bool SplitEmptyRecord
If false, empty record (e.g.
bool AfterClass
Wrap class definitions.
bool AfterCaseLabel
Wrap case labels.
bool AfterStruct
Wrap struct definitions.
bool BeforeLambdaBody
Wrap lambda block.
bool AfterUnion
Wrap union definitions.
bool AfterEnum
Wrap enum definitions.
bool AfterObjCDeclaration
Wrap ObjC definitions (interfaces, implementations...).
bool BeforeElse
Wrap before else.
bool AfterNamespace
Wrap namespace definitions.
bool BeforeWhile
Wrap before while.
BraceWrappingAfterControlStatementStyle AfterControlStatement
Wrap control statements (if/for/while/switch/..).
bool AfterFunction
Wrap function definitions.
bool BeforeCatch
Wrap before catch.
bool SplitEmptyFunction
If false, empty function body can be put on a single line.
bool AfterExternBlock
Wrap extern blocks.
void Add(FormatStyle Style)
std::optional< FormatStyle > Get(FormatStyle::LanguageKind Language) const
int8_t DecimalMinDigits
Format separators in decimal literals with a minimum number of digits.
int8_t Decimal
Format separators in decimal literals.
bool AtEndOfFile
Keep empty lines at end of file.
bool AtStartOfBlock
Keep empty lines at start of a block.
bool AfterControlStatements
If true, put space between control statement keywords (for/if/while...) and opening parentheses.
bool AfterForeachMacros
If true, put space between foreach macros and opening parentheses.
bool BeforeNonEmptyParentheses
If true, put a space before opening parentheses only if the parentheses are not empty.
bool AfterIfMacros
If true, put space between if macros and opening parentheses.
bool AfterPlacementOperator
If true, put a space between operator new/delete and opening parenthesis.
bool ExceptDoubleParentheses
Override any of the following options to prevent addition of space when both opening and closing pare...
bool Other
Put a space in parentheses not covered by preceding options.
bool InEmptyParentheses
Insert a space in empty parentheses, i.e.
bool InCStyleCasts
Put a space in C style casts.
bool InConditionalStatements
Put a space in parentheses only inside conditional statements (for/if/while/switch....
The FormatStyle is used to configure the formatting to follow specific guidelines.
@ UT_Never
Never use tab.
bool SpaceBeforeInheritanceColon
If false, spaces will be removed before inheritance colon.
unsigned ContinuationIndentWidth
Indent width for line continuations.
bool AlwaysBreakBeforeMultilineStrings
This option is renamed to BreakAfterReturnType.
LanguageStandard Standard
Parse and format C++ constructs compatible with this standard.
bool BreakAdjacentStringLiterals
Break between adjacent string literals.
ReturnTypeBreakingStyle BreakAfterReturnType
The function declaration return type breaking style to use.
LanguageKind
Supported languages.
@ LK_CSharp
Should be used for C#.
@ LK_Java
Should be used for Java.
@ LK_Cpp
Should be used for C, C++.
@ LK_JavaScript
Should be used for JavaScript.
@ LK_ObjC
Should be used for Objective-C, Objective-C++.
@ LK_Verilog
Should be used for Verilog and SystemVerilog.
@ LK_TableGen
Should be used for TableGen code.
@ LK_Proto
Should be used for Protocol Buffers (https://developers.google.com/protocol-buffers/).
@ LK_Json
Should be used for JSON.
@ LK_TextProto
Should be used for Protocol Buffer messages in text format (https://developers.google....
bool Cpp11BracedListStyle
If true, format braced lists as best suited for C++11 braced lists.
SortIncludesOptions SortIncludes
Controls if and how clang-format will sort #includes.
BreakInheritanceListStyle BreakInheritanceList
The inheritance list style to use.
unsigned IndentWidth
The number of columns to use for indentation.
std::vector< std::string > AttributeMacros
This option is renamed to BreakTemplateDeclarations.
@ SLS_All
Merge all lambdas fitting on a single line.
@ SLS_Empty
Only merge empty lambdas.
@ SDS_Leave
Leave definition blocks as they are.
bool IndentRequiresClause
Indent the requires clause in a template.
SpacesInAnglesStyle SpacesInAngles
The SpacesInAnglesStyle to use for template argument lists.
bool KeepFormFeed
This option is deprecated.
bool IndentCaseLabels
Indent case labels one level from the switch statement.
std::vector< RawStringFormat > RawStringFormats
Defines hints for detecting supported languages code blocks in raw strings.
std::vector< std::string > VariableTemplates
A vector of non-keyword identifiers that should be interpreted as variable template names.
@ SJSIO_Before
Static imports are placed before non-static imports.
@ SJSIO_After
Static imports are placed after non-static imports.
PPDirectiveIndentStyle IndentPPDirectives
The preprocessor directive indenting style to use.
bool RemoveSemicolon
Remove semicolons after the closing braces of functions and constructors/destructors.
std::vector< std::string > Macros
A list of macros of the form <definition>=<expansion> .
bool SpaceBeforeJsonColon
If true, a space will be added before a JSON colon.
@ TCS_None
Do not insert trailing commas.
unsigned PenaltyBreakBeforeFirstCallParameter
The penalty for breaking a function call after call(.
bool SpaceBeforeCtorInitializerColon
If false, spaces will be removed before constructor initializer colon.
@ BPPS_OnePerLine
Put all parameters on the current line if they fit.
@ BPPS_BinPack
Bin-pack parameters.
BinaryOperatorStyle BreakBeforeBinaryOperators
The way to wrap binary operators.
@ SI_Never
Includes are never sorted.
@ SI_CaseSensitive
Includes are sorted in an ASCIIbetical or case sensitive fashion.
@ SI_CaseInsensitive
Includes are sorted in an alphabetical or case insensitive fashion.
bool IndentExportBlock
If true, clang-format will indent the body of an export { ... } block.
@ BPS_Never
Never bin-pack parameters.
@ BPS_Auto
Automatically determine parameter bin-packing behavior.
BitFieldColonSpacingStyle BitFieldColonSpacing
The BitFieldColonSpacingStyle to use for bitfields.
@ RCS_Always
Apply indentation rules and reflow long comments into new lines, trying to obey the ColumnLimit.
@ ELBAMS_LogicalBlock
Add empty line only when access modifier starts a new logical block.
unsigned SpacesBeforeTrailingComments
If true, spaces may be inserted into ().
@ BCIS_BeforeColon
Break constructor initializers before the colon and after the commas.
@ BCIS_BeforeComma
Break constructor initializers before the colon and commas, and align the commas with the colon.
@ IEBS_AfterExternBlock
Backwards compatible with AfterExternBlock's indenting.
bool IndentCaseBlocks
Indent case label blocks one level from the case label.
bool InsertBraces
Insert braces after control statements (if, else, for, do, and while) in C++ unless the control state...
BreakBeforeConceptDeclarationsStyle BreakBeforeConceptDeclarations
The concept declaration style to use.
BreakTemplateDeclarationsStyle BreakTemplateDeclarations
The template declaration breaking style to use.
bool DerivePointerAlignment
This option is deprecated.
@ BOS_All
Break before operators.
@ BOS_None
Break after operators.
@ BOS_NonAssignment
Break before operators that aren't assignments.
@ LE_DeriveLF
Use \n unless the input has more lines ending in \r\n.
bool SpacesInSquareBrackets
If true, spaces will be inserted after [ and before ].
bool IndentWrappedFunctionNames
Indent if a function definition or declaration is wrapped after the type.
AlignConsecutiveStyle AlignConsecutiveTableGenBreakingDAGArgColons
Style of aligning consecutive TableGen DAGArg operator colons.
WrapNamespaceBodyWithEmptyLinesStyle WrapNamespaceBodyWithEmptyLines
Wrap namespace body with empty lines.
bool FixNamespaceComments
If true, clang-format adds missing namespace end comments for namespaces and fixes invalid existing o...
bool ObjCSpaceBeforeProtocolList
Add a space in front of an Objective-C protocol list, i.e.
@ TCAS_Never
Don't align trailing comments but other formatter applies.
@ TCAS_Always
Align trailing comments.
RemoveParenthesesStyle RemoveParentheses
Remove redundant parentheses.
std::string MacroBlockBegin
A regular expression matching macros that start a block.
bool SpaceInEmptyBlock
If true, spaces will be inserted into {}.
LanguageKind Language
Language, this format style is targeted at.
@ SIPO_Custom
Configure each individual space in parentheses in SpacesInParensOptions.
@ SIPO_Never
Never put a space in parentheses.
bool RemoveBracesLLVM
Remove optional braces of control statements (if, else, for, and while) in C++ according to the LLVM ...
@ BAS_DontAlign
Don't align, instead use ContinuationIndentWidth, e.g.:
@ BAS_AlwaysBreak
Always break after an open bracket, if the parameters don't fit on a single line, e....
@ BAS_Align
Align parameters on the open bracket, e.g.:
@ BBIAS_OnlyMultiline
Break before inline ASM colon if the line length is longer than column limit.
bool VerilogBreakBetweenInstancePorts
For Verilog, put each port on its own line in module instantiations.
unsigned TabWidth
The number of columns used for tab stops.
@ PPDIS_None
Does not indent any directives.
@ LBI_Signature
Align lambda body relative to the lambda signature.
std::vector< std::string > JavaImportGroups
A vector of prefixes ordered by the desired groups for Java imports.
bool AllowShortCaseLabelsOnASingleLine
If true, short case labels will be contracted to a single line.
unsigned PenaltyBreakFirstLessLess
The penalty for breaking before the first <<.
std::vector< std::string > StatementAttributeLikeMacros
Macros which are ignored in front of a statement, as if they were an attribute.
unsigned ObjCBlockIndentWidth
The number of characters to use for indentation of ObjC blocks.
bool AllowShortLoopsOnASingleLine
If true, while (true) continue; can be put on a single line.
int AccessModifierOffset
The extra indent or outdent of access modifiers, e.g.
std::vector< std::string > QualifierOrder
The order in which the qualifiers appear.
bool AllowShortEnumsOnASingleLine
Allow short enums on a single line.
@ SBS_Empty
Only merge empty blocks.
@ SBS_Never
Never merge blocks into a single line.
std::optional< FormatStyle > GetLanguageStyle(LanguageKind Language) const
std::vector< std::string > IfMacros
A vector of macros that should be interpreted as conditionals instead of as function calls.
NamespaceIndentationKind NamespaceIndentation
The indentation used for namespaces.
bool BreakArrays
If true, clang-format will always break after a Json array [ otherwise it will scan until the closing...
bool BreakAfterJavaFieldAnnotations
Break after each annotation on a field in Java files.
@ SIS_WithoutElse
Put short ifs on the same line only if there is no else statement.
@ SIS_Never
Never put short ifs on the same line.
std::optional< unsigned > BracedInitializerIndentWidth
The number of columns to use to indent the contents of braced init lists.
std::vector< std::string > ObjCPropertyAttributeOrder
The order in which ObjC property attributes should appear.
bool ExperimentalAutoDetectBinPacking
If true, clang-format detects whether function calls and definitions are formatted with one parameter...
bool ObjCBreakBeforeNestedBlockParam
Break parameters list into lines when there is nested block parameters in a function call.
OperandAlignmentStyle AlignOperands
If true, horizontally align operands of binary and ternary expressions.
unsigned PenaltyBreakOpenParenthesis
The penalty for breaking after (.
unsigned PenaltyBreakBeforeMemberAccess
The penalty for breaking before a member access operator (.
@ BTDS_MultiLine
Force break after template declaration only when the following declaration spans multiple lines.
@ BTDS_Yes
Always break after template declaration.
bool AllowShortCompoundRequirementOnASingleLine
Allow short compound requirement on a single line.
friend std::error_code parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style, bool AllowUnknownOptions, llvm::SourceMgr::DiagHandlerTy DiagHandler, void *DiagHandlerCtxt)
Parse configuration from YAML-formatted text.
SpacesInParensStyle SpacesInParens
If true, spaces will be inserted after ( and before ).
SpacesInParensCustom SpacesInParensOptions
Control of individual spaces in parentheses.
std::vector< std::string > ForEachMacros
A vector of macros that should be interpreted as foreach loops instead of as function calls.
ReferenceAlignmentStyle ReferenceAlignment
Reference alignment style (overrides PointerAlignment for references).
BreakBinaryOperationsStyle BreakBinaryOperations
The break binary operations style to use.
AlignConsecutiveStyle AlignConsecutiveTableGenDefinitionColons
Style of aligning consecutive TableGen definition colons.
TrailingCommaStyle InsertTrailingCommas
If set to TCS_Wrapped will insert trailing commas in container literals (arrays and objects) that wra...
unsigned PenaltyBreakTemplateDeclaration
The penalty for breaking after template declaration.
SpaceBeforeParensCustom SpaceBeforeParensOptions
Control of individual space before parentheses.
BreakConstructorInitializersStyle BreakConstructorInitializers
The break constructor initializers style to use.
bool RemoveEmptyLinesInUnwrappedLines
Remove empty lines within unwrapped lines.
bool BreakStringLiterals
Allow breaking string literals when formatting.
bool SpaceAfterLogicalNot
If true, a space is inserted after the logical not operator (!).
@ SBPO_Custom
Configure each individual space before parentheses in SpaceBeforeParensOptions.
@ SBPO_NonEmptyParentheses
Put a space before opening parentheses only if the parentheses are not empty.
@ SBPO_ControlStatementsExceptControlMacros
Same as SBPO_ControlStatements except this option doesn't apply to ForEach and If macros.
@ SBPO_ControlStatements
Put a space before opening parentheses only after control statement keywords (for/if/while....
@ SBPO_Always
Always put a space before opening parentheses, except when it's prohibited by the syntax rules (in fu...
@ PCIS_BinPack
Bin-pack constructor initializers.
@ PCIS_NextLine
Same as PCIS_CurrentLine except that if all constructor initializers do not fit on the current line,...
std::vector< std::string > TypeNames
A vector of non-keyword identifiers that should be interpreted as type names.
bool ObjCSpaceAfterProperty
Add a space after @property in Objective-C, i.e.
BraceBreakingStyle BreakBeforeBraces
The brace breaking style to use.
@ BILS_BeforeColon
Break inheritance list before the colon and after the commas.
@ BILS_BeforeComma
Break inheritance list before the colon and commas, and align the commas with the colon.
unsigned PenaltyExcessCharacter
The penalty for each character outside of the column limit.
std::vector< std::string > WhitespaceSensitiveMacros
A vector of macros which are whitespace-sensitive and should not be touched.
std::vector< std::string > TemplateNames
A vector of non-keyword identifiers that should be interpreted as template names.
@ DAS_DontBreak
Never break inside DAGArg.
unsigned ConstructorInitializerIndentWidth
This option is deprecated.
@ BBNSS_Never
No line break allowed.
bool CompactNamespaces
If true, consecutive namespace declarations will be on the same line.
@ RCPS_OwnLine
Always put the requires clause on its own line (possibly followed by a semicolon).
LanguageStandard
Supported language standards for parsing and formatting C++ constructs.
@ LS_Cpp17
Parse and format as C++17.
@ LS_Latest
Parse and format using the latest supported language version.
@ LS_Cpp11
Parse and format as C++11.
@ LS_Auto
Automatic detection based on the input.
@ LS_Cpp14
Parse and format as C++14.
@ LS_Cpp20
Parse and format as C++20.
@ BWACS_Always
Always wrap braces after a control statement.
@ BWACS_Never
Never wrap braces after a control statement.
RequiresClausePositionStyle RequiresClausePosition
The position of the requires clause.
@ JSQS_Single
Always use single quotes.
@ JSQS_Leave
Leave string quotes as they are.
bool SpaceAfterCStyleCast
If true, a space is inserted after C style casts.
AlignConsecutiveStyle AlignConsecutiveBitFields
Style of aligning consecutive bit fields.
int PPIndentWidth
The number of columns to use for indentation of preprocessor statements.
AlignConsecutiveStyle AlignConsecutiveDeclarations
Style of aligning consecutive declarations.
IntegerLiteralSeparatorStyle IntegerLiteralSeparator
Format integer literal separators (' for C++ and _ for C#, Java, and JavaScript).
SpaceAroundPointerQualifiersStyle SpaceAroundPointerQualifiers
Defines in which cases to put a space before or after pointer qualifiers.
DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType
The function definition return type breaking style to use.
bool SpaceBeforeAssignmentOperators
If false, spaces will be removed before assignment operators.
BreakBeforeInlineASMColonStyle BreakBeforeInlineASMColon
The inline ASM colon style to use.
@ WNBWELS_Leave
Keep existing newlines at the beginning and the end of namespace body.
@ BS_Mozilla
Like Attach, but break before braces on enum, function, and record definitions.
@ BS_Whitesmiths
Like Allman but always indent braces and line up code with braces.
@ BS_Allman
Always break before braces.
@ BS_Stroustrup
Like Attach, but break before function definitions, catch, and else.
@ BS_Linux
Like Attach, but break before braces on function, namespace and class definitions.
@ BS_WebKit
Like Attach, but break before functions.
@ BS_Custom
Configure each individual brace in BraceWrapping.
@ BS_GNU
Always break before braces and add an extra level of indentation to braces of control statements,...
@ BS_Attach
Always attach braces to surrounding context.
@ ABS_Leave
Leave the line breaking after attributes as is.
bool BinPackArguments
If false, a function call's arguments will either be all on the same line or will have one line each.
ShortLambdaStyle AllowShortLambdasOnASingleLine
Dependent on the value, auto lambda []() { return 0; } can be put on a single line.
unsigned PenaltyBreakScopeResolution
The penalty for breaking after ::.
unsigned PenaltyReturnTypeOnItsOwnLine
Penalty for putting the return type of a function onto its own line.
@ BFCS_Both
Add one space on each side of the :
PointerAlignmentStyle PointerAlignment
Pointer and reference alignment style.
@ SFS_Inline
Only merge functions defined inside a class.
@ SFS_All
Merge all functions fitting on a single line.
@ SFS_Empty
Only merge empty functions.
@ SFS_None
Never merge functions into a single line.
bool BreakFunctionDefinitionParameters
If true, clang-format will always break before function definition parameters.
@ REI_OuterScope
Align requires expression body relative to the indentation level of the outer scope the requires expr...
PackConstructorInitializersStyle PackConstructorInitializers
The pack constructor initializers style to use.
@ BBCDS_Always
Always break before concept, putting it in the line after the template declaration.
ReflowCommentsStyle ReflowComments
Comment reformatting style.
KeepEmptyLinesStyle KeepEmptyLines
Which empty lines are kept.
bool AllowAllParametersOfDeclarationOnNextLine
This option is deprecated.
BracketAlignmentStyle AlignAfterOpenBracket
If true, horizontally aligns arguments after an open bracket.
AlignConsecutiveStyle AlignConsecutiveTableGenCondOperatorColons
Style of aligning consecutive TableGen cond operator colons.
BinPackParametersStyle BinPackParameters
The bin pack parameters style to use.
bool AllowShortCaseExpressionOnASingleLine
Whether to merge a short switch labeled rule into a single line.
unsigned MaxEmptyLinesToKeep
The maximum number of consecutive empty lines to keep.
bool SpaceBeforeSquareBrackets
If true, spaces will be before [.
BinPackStyle ObjCBinPackProtocolList
Controls bin-packing Objective-C protocol conformance list items into as few lines as possible when t...
ShortCaseStatementsAlignmentStyle AlignConsecutiveShortCaseStatements
Style of aligning consecutive short case labels.
EscapedNewlineAlignmentStyle AlignEscapedNewlines
Options for aligning backslashes in escaped newlines.
SpacesInLineComment SpacesInLineCommentPrefix
How many spaces are allowed at the start of a line comment.
std::string CommentPragmas
A regular expression that describes comments with special meaning, which should not be split into lin...
bool isJavaScript() const
DAGArgStyle TableGenBreakInsideDAGArg
The styles of the line break inside the DAGArg in TableGen.
JavaScriptQuoteStyle JavaScriptQuotes
The JavaScriptQuoteStyle to use for JavaScript strings.
bool SpacesInContainerLiterals
If true, spaces will be inserted around if/for/switch/while conditions.
SortJavaStaticImportOptions SortJavaStaticImport
When sorting Java imports, by default static imports are placed before non-static imports.
@ SAPQ_Default
Don't ensure spaces around pointer qualifiers and use PointerAlignment instead.
bool SpaceBeforeRangeBasedForLoopColon
If false, spaces will be removed before range-based for loop colon.
bool DisableFormat
Disables formatting completely.
@ ELAAMS_Never
Remove all empty lines after access modifiers.
@ DRTBS_All
Always break after the return type.
@ DRTBS_TopLevel
Always break after the return types of top-level functions.
@ DRTBS_None
Break after return type automatically.
bool AllowShortNamespacesOnASingleLine
If true, namespace a { class b; } can be put on a single line.
std::vector< std::string > NamespaceMacros
A vector of macros which are used to open namespace blocks.
AttributeBreakingStyle BreakAfterAttributes
Break after a group of C++11 attributes before variable or function (including constructor/destructor...
TrailingCommentsAlignmentStyle AlignTrailingComments
Control of trailing comments.
@ AIAS_None
Don't align array initializer columns.
LambdaBodyIndentationKind LambdaBodyIndentation
The indentation style of lambda bodies.
QualifierAlignmentStyle QualifierAlignment
Different ways to arrange specifiers and qualifiers (e.g.
@ BBO_Never
Don't break binary operations.
bool IndentGotoLabels
Indent goto labels.
BraceWrappingFlags BraceWrapping
Control of individual brace wrapping cases.
@ ENAS_Left
Align escaped newlines as far left as possible.
@ ENAS_Right
Align escaped newlines in the right-most column.
AlignConsecutiveStyle AlignConsecutiveMacros
Style of aligning consecutive macro definitions.
std::vector< std::string > StatementMacros
A vector of macros that should be interpreted as complete statements.
@ SIAS_Never
Remove spaces after < and before >.
@ SUD_LexicographicNumeric
Using declarations are sorted in the order defined as follows: Split the strings by :: and discard an...
@ SUD_Never
Using declarations are never sorted.
AlignConsecutiveStyle AlignConsecutiveAssignments
Style of aligning consecutive assignments.
ShortIfStyle AllowShortIfStatementsOnASingleLine
Dependent on the value, if (a) return; can be put on a single line.
@ RPS_Leave
Do not remove parentheses.
@ RPS_ReturnStatement
Also remove parentheses enclosing the expression in a return/co_return statement.
std::vector< std::string > TableGenBreakingDAGArgOperators
Works only when TableGenBreakInsideDAGArg is not DontBreak.
EmptyLineBeforeAccessModifierStyle EmptyLineBeforeAccessModifier
Defines in which cases to put empty line before access modifiers.
bool SpaceBeforeCaseColon
If false, spaces will be removed before case colon.
BreakBeforeNoexceptSpecifierStyle AllowBreakBeforeNoexceptSpecifier
Controls if there could be a line break before a noexcept specifier.
bool JavaScriptWrapImports
Whether to wrap JavaScript import/export statements.
bool SkipMacroDefinitionBody
Do not format macro definition body.
unsigned PenaltyBreakAssignment
The penalty for breaking around an assignment operator.
@ PAS_Left
Align pointer to the left.
@ PAS_Right
Align pointer to the right.
unsigned PenaltyBreakString
The penalty for each line break introduced inside a string literal.
RequiresExpressionIndentationKind RequiresExpressionIndentation
The indentation used for requires expression bodies.
bool SpaceAfterTemplateKeyword
If true, a space will be inserted after the template keyword.
unsigned PenaltyIndentedWhitespace
Penalty for each character of whitespace indentation (counted relative to leading non-whitespace colu...
ArrayInitializerAlignmentStyle AlignArrayOfStructures
If not None, when using initialization for an array of structs aligns the fields into columns.
@ NI_None
Don't indent in namespaces.
@ NI_All
Indent in all namespaces.
@ NI_Inner
Indent only in inner namespaces (nested in other namespaces).
ShortBlockStyle AllowShortBlocksOnASingleLine
Dependent on the value, while (true) { continue; } can be put on a single line.
std::string MacroBlockEnd
A regular expression matching macros that end a block.
ShortFunctionStyle AllowShortFunctionsOnASingleLine
Dependent on the value, int f() { return 0; } can be put on a single line.
bool AllowAllArgumentsOnNextLine
If a function call or braced initializer list doesn't fit on a line, allow putting all arguments onto...
unsigned PenaltyBreakComment
The penalty for each line break introduced inside a comment.
bool InheritsParentConfig
@ RTBS_TopLevel
Always break after the return types of top-level functions.
@ RTBS_None
This is deprecated. See Automatic below.
@ RTBS_AllDefinitions
Always break after the return type of function definitions.
@ RAS_Pointer
Align reference like PointerAlignment.
EmptyLineAfterAccessModifierStyle EmptyLineAfterAccessModifier
Defines when to put an empty line after access modifiers.
bool IndentAccessModifiers
Specify whether access modifiers should have their own indentation level.
bool InsertNewlineAtEOF
Insert a newline at end of file if missing.
SpaceBeforeParensStyle SpaceBeforeParens
Defines in which cases to put a space before opening parentheses.
bool SpaceBeforeCpp11BracedList
If true, a space will be inserted before a C++11 braced list used to initialize an object (after the ...
UseTabStyle UseTab
The way to use tab characters in the resulting file.
@ QAS_Leave
Don't change specifiers/qualifiers to either Left or Right alignment (default).
std::vector< std::string > TypenameMacros
A vector of macros that should be interpreted as type declarations instead of as function calls.
@ OAS_Align
Horizontally align operands of binary and ternary expressions.
@ OAS_DontAlign
Do not align operands of binary and ternary expressions.
LineEndingStyle LineEnding
Line ending style (\n or \r\n) to use.
bool BreakBeforeTernaryOperators
If true, ternary operators will be placed after line breaks.
unsigned ShortNamespaceLines
The maximal number of unwrapped lines that a short namespace spans.
SortUsingDeclarationsOptions SortUsingDeclarations
Controls if and how clang-format will sort using declarations.
IndentExternBlockStyle IndentExternBlock
IndentExternBlockStyle is the type of indenting of extern blocks.
SeparateDefinitionStyle SeparateDefinitionBlocks
Specifies the use of empty lines to separate definition blocks, including classes,...
tooling::IncludeStyle IncludeStyle
unsigned ColumnLimit
The column limit.
Represents the status of a formatting attempt.
static FormatStyle & element(IO &IO, std::vector< FormatStyle > &Seq, size_t Index)
static size_t size(IO &IO, std::vector< FormatStyle > &Seq)
static void mapping(IO &IO, FormatStyle &Style)
static void enumInput(IO &IO, FormatStyle::AlignConsecutiveStyle &Value)
static void mapping(IO &IO, FormatStyle::AlignConsecutiveStyle &Value)
static void mapping(IO &IO, FormatStyle::BraceWrappingFlags &Wrapping)
static void mapping(IO &IO, FormatStyle::IntegerLiteralSeparatorStyle &Base)
static void mapping(IO &IO, FormatStyle::KeepEmptyLinesStyle &Value)
static void mapping(IO &IO, FormatStyle::RawStringFormat &Format)
static void mapping(IO &IO, FormatStyle::ShortCaseStatementsAlignmentStyle &Value)
static void mapping(IO &IO, FormatStyle::SpaceBeforeParensCustom &Spacing)
static void mapping(IO &IO, FormatStyle::SpacesInParensCustom &Spaces)
static void enumeration(IO &IO, FormatStyle::ArrayInitializerAlignmentStyle &Value)
static void enumeration(IO &IO, FormatStyle::AttributeBreakingStyle &Value)
static void enumeration(IO &IO, FormatStyle::BinPackStyle &Value)
static void enumeration(IO &IO, FormatStyle::BinaryOperatorStyle &Value)
static void enumeration(IO &IO, FormatStyle::BitFieldColonSpacingStyle &Value)
static void enumeration(IO &IO, FormatStyle::BraceBreakingStyle &Value)
static void enumeration(IO &IO, FormatStyle::BraceWrappingAfterControlStatementStyle &Value)
static void enumeration(IO &IO, FormatStyle::BracketAlignmentStyle &Value)
static void enumeration(IO &IO, FormatStyle::BreakBeforeConceptDeclarationsStyle &Value)
static void enumeration(IO &IO, FormatStyle::BreakBeforeInlineASMColonStyle &Value)
static void enumeration(IO &IO, FormatStyle::BreakBeforeNoexceptSpecifierStyle &Value)
static void enumeration(IO &IO, FormatStyle::BreakBinaryOperationsStyle &Value)
static void enumeration(IO &IO, FormatStyle::BreakInheritanceListStyle &Value)
static void enumeration(IO &IO, FormatStyle::BreakTemplateDeclarationsStyle &Value)
static void enumeration(IO &IO, FormatStyle::DAGArgStyle &Value)
static void enumeration(IO &IO, FormatStyle::DefinitionReturnTypeBreakingStyle &Value)
static void enumeration(IO &IO, FormatStyle::EmptyLineAfterAccessModifierStyle &Value)
static void enumeration(IO &IO, FormatStyle::EmptyLineBeforeAccessModifierStyle &Value)
static void enumeration(IO &IO, FormatStyle::EscapedNewlineAlignmentStyle &Value)
static void enumeration(IO &IO, FormatStyle::IndentExternBlockStyle &Value)
static void enumeration(IO &IO, FormatStyle::JavaScriptQuoteStyle &Value)
static void enumeration(IO &IO, FormatStyle::LambdaBodyIndentationKind &Value)
static void enumeration(IO &IO, FormatStyle::LanguageKind &Value)
static void enumeration(IO &IO, FormatStyle::LanguageStandard &Value)
static void enumeration(IO &IO, FormatStyle::LineEndingStyle &Value)
static void enumeration(IO &IO, FormatStyle::NamespaceIndentationKind &Value)
static void enumeration(IO &IO, FormatStyle::OperandAlignmentStyle &Value)
static void enumeration(IO &IO, FormatStyle::PPDirectiveIndentStyle &Value)
static void enumeration(IO &IO, FormatStyle::PointerAlignmentStyle &Value)
static void enumeration(IO &IO, FormatStyle::QualifierAlignmentStyle &Value)
static void enumeration(IO &IO, FormatStyle::ReferenceAlignmentStyle &Value)
static void enumeration(IO &IO, FormatStyle::RemoveParenthesesStyle &Value)
static void enumeration(IO &IO, FormatStyle::RequiresClausePositionStyle &Value)
static void enumeration(IO &IO, FormatStyle::RequiresExpressionIndentationKind &Value)
static void enumeration(IO &IO, FormatStyle::ReturnTypeBreakingStyle &Value)
static void enumeration(IO &IO, FormatStyle::SeparateDefinitionStyle &Value)
static void enumeration(IO &IO, FormatStyle::ShortBlockStyle &Value)
static void enumeration(IO &IO, FormatStyle::ShortFunctionStyle &Value)
static void enumeration(IO &IO, FormatStyle::ShortIfStyle &Value)
static void enumeration(IO &IO, FormatStyle::ShortLambdaStyle &Value)
static void enumeration(IO &IO, FormatStyle::SortIncludesOptions &Value)
static void enumeration(IO &IO, FormatStyle::SortJavaStaticImportOptions &Value)
static void enumeration(IO &IO, FormatStyle::SortUsingDeclarationsOptions &Value)
static void enumeration(IO &IO, FormatStyle::SpaceBeforeParensStyle &Value)
static void enumeration(IO &IO, FormatStyle::SpacesInAnglesStyle &Value)
static void enumeration(IO &IO, FormatStyle::SpacesInParensStyle &Value)
static void enumeration(IO &IO, FormatStyle::TrailingCommaStyle &Value)
static void enumeration(IO &IO, FormatStyle::UseTabStyle &Value)
static void enumeration(IO &IO, FormatStyle::WrapNamespaceBodyWithEmptyLinesStyle &Value)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4