Skip to content

Instantly share code, notes, and snippets.

@jevinskie
Created October 20, 2025 19:46
Show Gist options
  • Save jevinskie/c0462d7476e2b63c7f8ea660255e500a to your computer and use it in GitHub Desktop.
Save jevinskie/c0462d7476e2b63c7f8ea660255e500a to your computer and use it in GitHub Desktop.
Condensed C++ clang/Format/Format.h (use `gcc -E -fpreprocessed -dD -P llvm-project/clang/include/clang/Format/Format.h`)
#ifndef LLVM_CLANG_FORMAT_FORMAT_H
#define LLVM_CLANG_FORMAT_FORMAT_H
#include "clang/Basic/LangOptions.h"
#include "clang/Tooling/Core/Replacement.h"
#include "clang/Tooling/Inclusions/IncludeStyle.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/SourceMgr.h"
#include <optional>
#include <system_error>
namespace llvm {
namespace vfs {
class FileSystem;
}
}
namespace clang {
namespace format {
enum class ParseError {
Success = 0,
Error,
Unsuitable,
BinPackTrailingCommaConflict,
InvalidQualifierSpecified,
DuplicateQualifierSpecified,
MissingQualifierType,
MissingQualifierOrder
};
class ParseErrorCategory final : public std::error_category {
public:
const char *name() const noexcept override;
std::string message(int EV) const override;
};
const std::error_category &getParseCategory();
std::error_code make_error_code(ParseError e);
struct FormatStyle {
bool InheritsParentConfig;
int AccessModifierOffset;
enum BracketAlignmentStyle : int8_t {
BAS_Align,
BAS_DontAlign,
BAS_AlwaysBreak,
BAS_BlockIndent,
};
BracketAlignmentStyle AlignAfterOpenBracket;
enum ArrayInitializerAlignmentStyle : int8_t {
AIAS_Left,
AIAS_Right,
AIAS_None
};
ArrayInitializerAlignmentStyle AlignArrayOfStructures;
struct AlignConsecutiveStyle {
bool Enabled;
bool AcrossEmptyLines;
bool AcrossComments;
bool AlignCompound;
bool AlignFunctionDeclarations;
bool AlignFunctionPointers;
bool PadOperators;
bool operator==(const AlignConsecutiveStyle &R) const {
return Enabled == R.Enabled && AcrossEmptyLines == R.AcrossEmptyLines &&
AcrossComments == R.AcrossComments &&
AlignCompound == R.AlignCompound &&
AlignFunctionDeclarations == R.AlignFunctionDeclarations &&
AlignFunctionPointers == R.AlignFunctionPointers &&
PadOperators == R.PadOperators;
}
bool operator!=(const AlignConsecutiveStyle &R) const {
return !(*this == R);
}
};
AlignConsecutiveStyle AlignConsecutiveMacros;
AlignConsecutiveStyle AlignConsecutiveAssignments;
AlignConsecutiveStyle AlignConsecutiveBitFields;
AlignConsecutiveStyle AlignConsecutiveDeclarations;
struct ShortCaseStatementsAlignmentStyle {
bool Enabled;
bool AcrossEmptyLines;
bool AcrossComments;
bool AlignCaseArrows;
bool AlignCaseColons;
bool operator==(const ShortCaseStatementsAlignmentStyle &R) const {
return Enabled == R.Enabled && AcrossEmptyLines == R.AcrossEmptyLines &&
AcrossComments == R.AcrossComments &&
AlignCaseArrows == R.AlignCaseArrows &&
AlignCaseColons == R.AlignCaseColons;
}
};
ShortCaseStatementsAlignmentStyle AlignConsecutiveShortCaseStatements;
AlignConsecutiveStyle AlignConsecutiveTableGenBreakingDAGArgColons;
AlignConsecutiveStyle AlignConsecutiveTableGenCondOperatorColons;
AlignConsecutiveStyle AlignConsecutiveTableGenDefinitionColons;
enum EscapedNewlineAlignmentStyle : int8_t {
ENAS_DontAlign,
ENAS_Left,
ENAS_LeftWithLastLine,
ENAS_Right,
};
EscapedNewlineAlignmentStyle AlignEscapedNewlines;
enum OperandAlignmentStyle : int8_t {
OAS_DontAlign,
OAS_Align,
OAS_AlignAfterOperator,
};
OperandAlignmentStyle AlignOperands;
enum TrailingCommentsAlignmentKinds : int8_t {
TCAS_Leave,
TCAS_Always,
TCAS_Never,
};
struct TrailingCommentsAlignmentStyle {
TrailingCommentsAlignmentKinds Kind;
unsigned OverEmptyLines;
bool operator==(const TrailingCommentsAlignmentStyle &R) const {
return Kind == R.Kind && OverEmptyLines == R.OverEmptyLines;
}
bool operator!=(const TrailingCommentsAlignmentStyle &R) const {
return !(*this == R);
}
};
TrailingCommentsAlignmentStyle AlignTrailingComments;
bool AllowAllArgumentsOnNextLine;
bool AllowAllParametersOfDeclarationOnNextLine;
enum BreakBeforeNoexceptSpecifierStyle : int8_t {
BBNSS_Never,
BBNSS_OnlyWithParen,
BBNSS_Always,
};
BreakBeforeNoexceptSpecifierStyle AllowBreakBeforeNoexceptSpecifier;
bool AllowBreakBeforeQtProperty;
enum ShortBlockStyle : int8_t {
SBS_Never,
SBS_Empty,
SBS_Always,
};
ShortBlockStyle AllowShortBlocksOnASingleLine;
bool AllowShortCaseExpressionOnASingleLine;
bool AllowShortCaseLabelsOnASingleLine;
bool AllowShortCompoundRequirementOnASingleLine;
bool AllowShortEnumsOnASingleLine;
enum ShortFunctionStyle : int8_t {
SFS_None,
SFS_InlineOnly,
SFS_Empty,
SFS_Inline,
SFS_All,
};
ShortFunctionStyle AllowShortFunctionsOnASingleLine;
enum ShortIfStyle : int8_t {
SIS_Never,
SIS_WithoutElse,
SIS_OnlyFirstIf,
SIS_AllIfsAndElse,
};
ShortIfStyle AllowShortIfStatementsOnASingleLine;
enum ShortLambdaStyle : int8_t {
SLS_None,
SLS_Empty,
SLS_Inline,
SLS_All,
};
ShortLambdaStyle AllowShortLambdasOnASingleLine;
bool AllowShortLoopsOnASingleLine;
bool AllowShortNamespacesOnASingleLine;
enum DefinitionReturnTypeBreakingStyle : int8_t {
DRTBS_None,
DRTBS_All,
DRTBS_TopLevel,
};
enum ReturnTypeBreakingStyle : int8_t {
RTBS_None,
RTBS_Automatic,
RTBS_ExceptShortType,
RTBS_All,
RTBS_TopLevel,
RTBS_AllDefinitions,
RTBS_TopLevelDefinitions,
};
DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType;
bool AlwaysBreakBeforeMultilineStrings;
enum BreakTemplateDeclarationsStyle : int8_t {
BTDS_Leave,
BTDS_No,
BTDS_MultiLine,
BTDS_Yes
};
std::vector<std::string> AttributeMacros;
bool BinPackArguments;
bool BinPackLongBracedList;
enum BinPackParametersStyle : int8_t {
BPPS_BinPack,
BPPS_OnePerLine,
BPPS_AlwaysOnePerLine,
};
BinPackParametersStyle BinPackParameters;
enum BitFieldColonSpacingStyle : int8_t {
BFCS_Both,
BFCS_None,
BFCS_Before,
BFCS_After
};
BitFieldColonSpacingStyle BitFieldColonSpacing;
int BracedInitializerIndentWidth;
enum BraceWrappingAfterControlStatementStyle : int8_t {
BWACS_Never,
BWACS_MultiLine,
BWACS_Always
};
struct BraceWrappingFlags {
bool AfterCaseLabel;
bool AfterClass;
BraceWrappingAfterControlStatementStyle AfterControlStatement;
bool AfterEnum;
bool AfterFunction;
bool AfterNamespace;
bool AfterObjCDeclaration;
bool AfterStruct;
bool AfterUnion;
bool AfterExternBlock;
bool BeforeCatch;
bool BeforeElse;
bool BeforeLambdaBody;
bool BeforeWhile;
bool IndentBraces;
bool SplitEmptyFunction;
bool SplitEmptyRecord;
bool SplitEmptyNamespace;
};
BraceWrappingFlags BraceWrapping;
bool BreakAdjacentStringLiterals;
enum AttributeBreakingStyle : int8_t {
ABS_Always,
ABS_Leave,
ABS_Never,
};
AttributeBreakingStyle BreakAfterAttributes;
ReturnTypeBreakingStyle BreakAfterReturnType;
bool BreakArrays;
enum BinPackStyle : int8_t {
BPS_Auto,
BPS_Always,
BPS_Never,
};
enum BinaryOperatorStyle : int8_t {
BOS_None,
BOS_NonAssignment,
BOS_All,
};
BinaryOperatorStyle BreakBeforeBinaryOperators;
enum BraceBreakingStyle : int8_t {
BS_Attach,
BS_Linux,
BS_Mozilla,
BS_Stroustrup,
BS_Allman,
BS_Whitesmiths,
BS_GNU,
BS_WebKit,
BS_Custom
};
BraceBreakingStyle BreakBeforeBraces;
enum BreakBeforeConceptDeclarationsStyle : int8_t {
BBCDS_Never,
BBCDS_Allowed,
BBCDS_Always,
};
BreakBeforeConceptDeclarationsStyle BreakBeforeConceptDeclarations;
enum BreakBeforeInlineASMColonStyle : int8_t {
BBIAS_Never,
BBIAS_OnlyMultiline,
BBIAS_Always,
};
BreakBeforeInlineASMColonStyle BreakBeforeInlineASMColon;
bool BreakBeforeTemplateCloser;
bool BreakBeforeTernaryOperators;
enum BreakBinaryOperationsStyle : int8_t {
BBO_Never,
BBO_OnePerLine,
BBO_RespectPrecedence
};
BreakBinaryOperationsStyle BreakBinaryOperations;
enum BreakConstructorInitializersStyle : int8_t {
BCIS_BeforeColon,
BCIS_BeforeComma,
BCIS_AfterColon
};
BreakConstructorInitializersStyle BreakConstructorInitializers;
bool BreakFunctionDefinitionParameters;
bool BreakAfterJavaFieldAnnotations;
bool BreakStringLiterals;
unsigned ColumnLimit;
std::string CommentPragmas;
enum BreakInheritanceListStyle : int8_t {
BILS_BeforeColon,
BILS_BeforeComma,
BILS_AfterColon,
BILS_AfterComma,
};
BreakInheritanceListStyle BreakInheritanceList;
BreakTemplateDeclarationsStyle BreakTemplateDeclarations;
bool CompactNamespaces;
unsigned ConstructorInitializerIndentWidth;
unsigned ContinuationIndentWidth;
bool Cpp11BracedListStyle;
bool DerivePointerAlignment;
bool DisableFormat;
enum EmptyLineAfterAccessModifierStyle : int8_t {
ELAAMS_Never,
ELAAMS_Leave,
ELAAMS_Always,
};
EmptyLineAfterAccessModifierStyle EmptyLineAfterAccessModifier;
enum EmptyLineBeforeAccessModifierStyle : int8_t {
ELBAMS_Never,
ELBAMS_Leave,
ELBAMS_LogicalBlock,
ELBAMS_Always,
};
EmptyLineBeforeAccessModifierStyle EmptyLineBeforeAccessModifier;
enum EnumTrailingCommaStyle : int8_t {
ETC_Leave,
ETC_Insert,
ETC_Remove,
};
EnumTrailingCommaStyle EnumTrailingComma;
bool ExperimentalAutoDetectBinPacking;
bool FixNamespaceComments;
std::vector<std::string> ForEachMacros;
tooling::IncludeStyle IncludeStyle;
std::vector<std::string> IfMacros;
bool IndentAccessModifiers;
bool IndentCaseBlocks;
bool IndentCaseLabels;
bool IndentExportBlock;
enum IndentExternBlockStyle : int8_t {
IEBS_AfterExternBlock,
IEBS_NoIndent,
IEBS_Indent,
};
IndentExternBlockStyle IndentExternBlock;
bool IndentGotoLabels;
enum PPDirectiveIndentStyle : int8_t {
PPDIS_None,
PPDIS_AfterHash,
PPDIS_BeforeHash,
PPDIS_Leave
};
PPDirectiveIndentStyle IndentPPDirectives;
bool IndentRequiresClause;
unsigned IndentWidth;
bool IndentWrappedFunctionNames;
bool InsertBraces;
bool InsertNewlineAtEOF;
enum TrailingCommaStyle : int8_t {
TCS_None,
TCS_Wrapped,
};
TrailingCommaStyle InsertTrailingCommas;
struct IntegerLiteralSeparatorStyle {
int8_t Binary;
int8_t BinaryMinDigits;
int8_t Decimal;
int8_t DecimalMinDigits;
int8_t Hex;
int8_t HexMinDigits;
bool operator==(const IntegerLiteralSeparatorStyle &R) const {
return Binary == R.Binary && BinaryMinDigits == R.BinaryMinDigits &&
Decimal == R.Decimal && DecimalMinDigits == R.DecimalMinDigits &&
Hex == R.Hex && HexMinDigits == R.HexMinDigits;
}
};
IntegerLiteralSeparatorStyle IntegerLiteralSeparator;
std::vector<std::string> JavaImportGroups;
enum JavaScriptQuoteStyle : int8_t {
JSQS_Leave,
JSQS_Single,
JSQS_Double
};
JavaScriptQuoteStyle JavaScriptQuotes;
bool JavaScriptWrapImports;
struct KeepEmptyLinesStyle {
bool AtEndOfFile;
bool AtStartOfBlock;
bool AtStartOfFile;
bool operator==(const KeepEmptyLinesStyle &R) const {
return AtEndOfFile == R.AtEndOfFile &&
AtStartOfBlock == R.AtStartOfBlock &&
AtStartOfFile == R.AtStartOfFile;
}
};
KeepEmptyLinesStyle KeepEmptyLines;
bool KeepFormFeed;
enum LambdaBodyIndentationKind : int8_t {
LBI_Signature,
LBI_OuterScope,
};
LambdaBodyIndentationKind LambdaBodyIndentation;
enum LanguageKind : int8_t {
LK_None,
LK_C,
LK_Cpp,
LK_CSharp,
LK_Java,
LK_JavaScript,
LK_Json,
LK_ObjC,
LK_Proto,
LK_TableGen,
LK_TextProto,
LK_Verilog
};
bool isCpp() const {
return Language == LK_Cpp || Language == LK_C || Language == LK_ObjC;
}
bool isCSharp() const { return Language == LK_CSharp; }
bool isJson() const { return Language == LK_Json; }
bool isJava() const { return Language == LK_Java; }
bool isJavaScript() const { return Language == LK_JavaScript; }
bool isVerilog() const { return Language == LK_Verilog; }
bool isTextProto() const { return Language == LK_TextProto; }
bool isProto() const { return Language == LK_Proto || isTextProto(); }
bool isTableGen() const { return Language == LK_TableGen; }
LanguageKind Language;
enum LineEndingStyle : int8_t {
LE_LF,
LE_CRLF,
LE_DeriveLF,
LE_DeriveCRLF,
};
LineEndingStyle LineEnding;
std::string MacroBlockBegin;
std::string MacroBlockEnd;
std::vector<std::string> Macros;
std::vector<std::string> MacrosSkippedByRemoveParentheses;
unsigned MaxEmptyLinesToKeep;
enum NamespaceIndentationKind : int8_t {
NI_None,
NI_Inner,
NI_All
};
NamespaceIndentationKind NamespaceIndentation;
std::vector<std::string> NamespaceMacros;
enum NumericLiteralComponentStyle : int8_t {
NLCS_Leave,
NLCS_Upper,
NLCS_Lower,
};
struct NumericLiteralCaseStyle {
NumericLiteralComponentStyle ExponentLetter;
NumericLiteralComponentStyle HexDigit;
NumericLiteralComponentStyle Prefix;
NumericLiteralComponentStyle Suffix;
bool operator==(const NumericLiteralCaseStyle &R) const {
return ExponentLetter == R.ExponentLetter && HexDigit == R.HexDigit &&
Prefix == R.Prefix && Suffix == R.Suffix;
}
bool operator!=(const NumericLiteralCaseStyle &R) const {
return !(*this == R);
}
};
NumericLiteralCaseStyle NumericLiteralCase;
BinPackStyle ObjCBinPackProtocolList;
unsigned ObjCBlockIndentWidth;
bool ObjCBreakBeforeNestedBlockParam;
std::vector<std::string> ObjCPropertyAttributeOrder;
bool ObjCSpaceAfterProperty;
bool ObjCSpaceBeforeProtocolList;
std::string OneLineFormatOffRegex;
enum PackConstructorInitializersStyle : int8_t {
PCIS_Never,
PCIS_BinPack,
PCIS_CurrentLine,
PCIS_NextLine,
PCIS_NextLineOnly,
};
PackConstructorInitializersStyle PackConstructorInitializers;
unsigned PenaltyBreakAssignment;
unsigned PenaltyBreakBeforeFirstCallParameter;
unsigned PenaltyBreakBeforeMemberAccess;
unsigned PenaltyBreakComment;
unsigned PenaltyBreakFirstLessLess;
unsigned PenaltyBreakOpenParenthesis;
unsigned PenaltyBreakScopeResolution;
unsigned PenaltyBreakString;
unsigned PenaltyBreakTemplateDeclaration;
unsigned PenaltyExcessCharacter;
unsigned PenaltyIndentedWhitespace;
unsigned PenaltyReturnTypeOnItsOwnLine;
enum PointerAlignmentStyle : int8_t {
PAS_Left,
PAS_Right,
PAS_Middle
};
PointerAlignmentStyle PointerAlignment;
int PPIndentWidth;
enum QualifierAlignmentStyle : int8_t {
QAS_Leave,
QAS_Left,
QAS_Right,
QAS_Custom
};
QualifierAlignmentStyle QualifierAlignment;
std::vector<std::string> QualifierOrder;
struct RawStringFormat {
LanguageKind Language;
std::vector<std::string> Delimiters;
std::vector<std::string> EnclosingFunctions;
std::string CanonicalDelimiter;
std::string BasedOnStyle;
bool operator==(const RawStringFormat &Other) const {
return Language == Other.Language && Delimiters == Other.Delimiters &&
EnclosingFunctions == Other.EnclosingFunctions &&
CanonicalDelimiter == Other.CanonicalDelimiter &&
BasedOnStyle == Other.BasedOnStyle;
}
};
std::vector<RawStringFormat> RawStringFormats;
enum ReferenceAlignmentStyle : int8_t {
RAS_Pointer,
RAS_Left,
RAS_Right,
RAS_Middle
};
ReferenceAlignmentStyle ReferenceAlignment;
enum ReflowCommentsStyle : int8_t {
RCS_Never,
RCS_IndentOnly,
RCS_Always
};
ReflowCommentsStyle ReflowComments;
bool RemoveBracesLLVM;
bool RemoveEmptyLinesInUnwrappedLines;
enum RemoveParenthesesStyle : int8_t {
RPS_Leave,
RPS_MultipleParentheses,
RPS_ReturnStatement,
};
RemoveParenthesesStyle RemoveParentheses;
bool RemoveSemicolon;
enum RequiresClausePositionStyle : int8_t {
RCPS_OwnLine,
RCPS_OwnLineWithBrace,
RCPS_WithPreceding,
RCPS_WithFollowing,
RCPS_SingleLine,
};
RequiresClausePositionStyle RequiresClausePosition;
enum RequiresExpressionIndentationKind : int8_t {
REI_OuterScope,
REI_Keyword,
};
RequiresExpressionIndentationKind RequiresExpressionIndentation;
enum SeparateDefinitionStyle : int8_t {
SDS_Leave,
SDS_Always,
SDS_Never
};
SeparateDefinitionStyle SeparateDefinitionBlocks;
unsigned ShortNamespaceLines;
bool SkipMacroDefinitionBody;
struct SortIncludesOptions {
bool Enabled;
bool IgnoreCase;
bool IgnoreExtension;
bool operator==(const SortIncludesOptions &R) const {
return Enabled == R.Enabled && IgnoreCase == R.IgnoreCase &&
IgnoreExtension == R.IgnoreExtension;
}
bool operator!=(const SortIncludesOptions &R) const {
return !(*this == R);
}
};
SortIncludesOptions SortIncludes;
enum SortJavaStaticImportOptions : int8_t {
SJSIO_Before,
SJSIO_After,
};
SortJavaStaticImportOptions SortJavaStaticImport;
enum SortUsingDeclarationsOptions : int8_t {
SUD_Never,
SUD_Lexicographic,
SUD_LexicographicNumeric,
};
SortUsingDeclarationsOptions SortUsingDeclarations;
bool SpaceAfterCStyleCast;
bool SpaceAfterLogicalNot;
bool SpaceAfterOperatorKeyword;
bool SpaceAfterTemplateKeyword;
enum SpaceAroundPointerQualifiersStyle : int8_t {
SAPQ_Default,
SAPQ_Before,
SAPQ_After,
SAPQ_Both,
};
SpaceAroundPointerQualifiersStyle SpaceAroundPointerQualifiers;
bool SpaceBeforeAssignmentOperators;
bool SpaceBeforeCaseColon;
bool SpaceBeforeCpp11BracedList;
bool SpaceBeforeCtorInitializerColon;
bool SpaceBeforeInheritanceColon;
bool SpaceBeforeJsonColon;
enum SpaceBeforeParensStyle : int8_t {
SBPO_Never,
SBPO_ControlStatements,
SBPO_ControlStatementsExceptControlMacros,
SBPO_NonEmptyParentheses,
SBPO_Always,
SBPO_Custom,
};
SpaceBeforeParensStyle SpaceBeforeParens;
struct SpaceBeforeParensCustom {
bool AfterControlStatements;
bool AfterForeachMacros;
bool AfterFunctionDeclarationName;
bool AfterFunctionDefinitionName;
bool AfterIfMacros;
bool AfterNot;
bool AfterOverloadedOperator;
bool AfterPlacementOperator;
bool AfterRequiresInClause;
bool AfterRequiresInExpression;
bool BeforeNonEmptyParentheses;
SpaceBeforeParensCustom()
: AfterControlStatements(false), AfterForeachMacros(false),
AfterFunctionDeclarationName(false),
AfterFunctionDefinitionName(false), AfterIfMacros(false),
AfterNot(false), AfterOverloadedOperator(false),
AfterPlacementOperator(true), AfterRequiresInClause(false),
AfterRequiresInExpression(false), BeforeNonEmptyParentheses(false) {}
bool operator==(const SpaceBeforeParensCustom &Other) const {
return AfterControlStatements == Other.AfterControlStatements &&
AfterForeachMacros == Other.AfterForeachMacros &&
AfterFunctionDeclarationName ==
Other.AfterFunctionDeclarationName &&
AfterFunctionDefinitionName == Other.AfterFunctionDefinitionName &&
AfterIfMacros == Other.AfterIfMacros &&
AfterNot == Other.AfterNot &&
AfterOverloadedOperator == Other.AfterOverloadedOperator &&
AfterPlacementOperator == Other.AfterPlacementOperator &&
AfterRequiresInClause == Other.AfterRequiresInClause &&
AfterRequiresInExpression == Other.AfterRequiresInExpression &&
BeforeNonEmptyParentheses == Other.BeforeNonEmptyParentheses;
}
};
SpaceBeforeParensCustom SpaceBeforeParensOptions;
bool SpaceBeforeSquareBrackets;
bool SpaceBeforeRangeBasedForLoopColon;
enum SpaceInEmptyBracesStyle : int8_t {
SIEB_Always,
SIEB_Block,
SIEB_Never
};
SpaceInEmptyBracesStyle SpaceInEmptyBraces;
unsigned SpacesBeforeTrailingComments;
enum SpacesInAnglesStyle : int8_t {
SIAS_Never,
SIAS_Always,
SIAS_Leave
};
SpacesInAnglesStyle SpacesInAngles;
bool SpacesInContainerLiterals;
struct SpacesInLineComment {
unsigned Minimum;
unsigned Maximum;
};
SpacesInLineComment SpacesInLineCommentPrefix;
enum SpacesInParensStyle : int8_t {
SIPO_Never,
SIPO_Custom,
};
SpacesInParensStyle SpacesInParens;
struct SpacesInParensCustom {
bool ExceptDoubleParentheses;
bool InConditionalStatements;
bool InCStyleCasts;
bool InEmptyParentheses;
bool Other;
SpacesInParensCustom()
: ExceptDoubleParentheses(false), InConditionalStatements(false),
InCStyleCasts(false), InEmptyParentheses(false), Other(false) {}
SpacesInParensCustom(bool ExceptDoubleParentheses,
bool InConditionalStatements, bool InCStyleCasts,
bool InEmptyParentheses, bool Other)
: ExceptDoubleParentheses(ExceptDoubleParentheses),
InConditionalStatements(InConditionalStatements),
InCStyleCasts(InCStyleCasts), InEmptyParentheses(InEmptyParentheses),
Other(Other) {}
bool operator==(const SpacesInParensCustom &R) const {
return ExceptDoubleParentheses == R.ExceptDoubleParentheses &&
InConditionalStatements == R.InConditionalStatements &&
InCStyleCasts == R.InCStyleCasts &&
InEmptyParentheses == R.InEmptyParentheses && Other == R.Other;
}
bool operator!=(const SpacesInParensCustom &R) const {
return !(*this == R);
}
};
SpacesInParensCustom SpacesInParensOptions;
bool SpacesInSquareBrackets;
enum LanguageStandard : int8_t {
LS_Cpp03,
LS_Cpp11,
LS_Cpp14,
LS_Cpp17,
LS_Cpp20,
LS_Latest,
LS_Auto,
};
LanguageStandard Standard;
std::vector<std::string> StatementAttributeLikeMacros;
std::vector<std::string> StatementMacros;
std::vector<std::string> TableGenBreakingDAGArgOperators;
enum DAGArgStyle : int8_t {
DAS_DontBreak,
DAS_BreakElements,
DAS_BreakAll,
};
DAGArgStyle TableGenBreakInsideDAGArg;
unsigned TabWidth;
std::vector<std::string> TemplateNames;
std::vector<std::string> TypeNames;
std::vector<std::string> TypenameMacros;
enum UseTabStyle : int8_t {
UT_Never,
UT_ForIndentation,
UT_ForContinuationAndIndentation,
UT_AlignWithSpaces,
UT_Always
};
UseTabStyle UseTab;
std::vector<std::string> VariableTemplates;
bool VerilogBreakBetweenInstancePorts;
std::vector<std::string> WhitespaceSensitiveMacros;
enum WrapNamespaceBodyWithEmptyLinesStyle : int8_t {
WNBWELS_Never,
WNBWELS_Always,
WNBWELS_Leave
};
WrapNamespaceBodyWithEmptyLinesStyle WrapNamespaceBodyWithEmptyLines;
bool operator==(const FormatStyle &R) const {
return AccessModifierOffset == R.AccessModifierOffset &&
AlignAfterOpenBracket == R.AlignAfterOpenBracket &&
AlignArrayOfStructures == R.AlignArrayOfStructures &&
AlignConsecutiveAssignments == R.AlignConsecutiveAssignments &&
AlignConsecutiveBitFields == R.AlignConsecutiveBitFields &&
AlignConsecutiveDeclarations == R.AlignConsecutiveDeclarations &&
AlignConsecutiveMacros == R.AlignConsecutiveMacros &&
AlignConsecutiveShortCaseStatements ==
R.AlignConsecutiveShortCaseStatements &&
AlignConsecutiveTableGenBreakingDAGArgColons ==
R.AlignConsecutiveTableGenBreakingDAGArgColons &&
AlignConsecutiveTableGenCondOperatorColons ==
R.AlignConsecutiveTableGenCondOperatorColons &&
AlignConsecutiveTableGenDefinitionColons ==
R.AlignConsecutiveTableGenDefinitionColons &&
AlignEscapedNewlines == R.AlignEscapedNewlines &&
AlignOperands == R.AlignOperands &&
AlignTrailingComments == R.AlignTrailingComments &&
AllowAllArgumentsOnNextLine == R.AllowAllArgumentsOnNextLine &&
AllowAllParametersOfDeclarationOnNextLine ==
R.AllowAllParametersOfDeclarationOnNextLine &&
AllowBreakBeforeNoexceptSpecifier ==
R.AllowBreakBeforeNoexceptSpecifier &&
AllowBreakBeforeQtProperty == R.AllowBreakBeforeQtProperty &&
AllowShortBlocksOnASingleLine == R.AllowShortBlocksOnASingleLine &&
AllowShortCaseExpressionOnASingleLine ==
R.AllowShortCaseExpressionOnASingleLine &&
AllowShortCaseLabelsOnASingleLine ==
R.AllowShortCaseLabelsOnASingleLine &&
AllowShortCompoundRequirementOnASingleLine ==
R.AllowShortCompoundRequirementOnASingleLine &&
AllowShortEnumsOnASingleLine == R.AllowShortEnumsOnASingleLine &&
AllowShortFunctionsOnASingleLine ==
R.AllowShortFunctionsOnASingleLine &&
AllowShortIfStatementsOnASingleLine ==
R.AllowShortIfStatementsOnASingleLine &&
AllowShortLambdasOnASingleLine == R.AllowShortLambdasOnASingleLine &&
AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine &&
AllowShortNamespacesOnASingleLine ==
R.AllowShortNamespacesOnASingleLine &&
AlwaysBreakBeforeMultilineStrings ==
R.AlwaysBreakBeforeMultilineStrings &&
AttributeMacros == R.AttributeMacros &&
BinPackArguments == R.BinPackArguments &&
BinPackLongBracedList == R.BinPackLongBracedList &&
BinPackParameters == R.BinPackParameters &&
BitFieldColonSpacing == R.BitFieldColonSpacing &&
BracedInitializerIndentWidth == R.BracedInitializerIndentWidth &&
BreakAdjacentStringLiterals == R.BreakAdjacentStringLiterals &&
BreakAfterAttributes == R.BreakAfterAttributes &&
BreakAfterJavaFieldAnnotations == R.BreakAfterJavaFieldAnnotations &&
BreakAfterReturnType == R.BreakAfterReturnType &&
BreakArrays == R.BreakArrays &&
BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators &&
BreakBeforeBraces == R.BreakBeforeBraces &&
BreakBeforeConceptDeclarations == R.BreakBeforeConceptDeclarations &&
BreakBeforeInlineASMColon == R.BreakBeforeInlineASMColon &&
BreakBeforeTemplateCloser == R.BreakBeforeTemplateCloser &&
BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
BreakBinaryOperations == R.BreakBinaryOperations &&
BreakConstructorInitializers == R.BreakConstructorInitializers &&
BreakFunctionDefinitionParameters ==
R.BreakFunctionDefinitionParameters &&
BreakInheritanceList == R.BreakInheritanceList &&
BreakStringLiterals == R.BreakStringLiterals &&
BreakTemplateDeclarations == R.BreakTemplateDeclarations &&
ColumnLimit == R.ColumnLimit && CommentPragmas == R.CommentPragmas &&
CompactNamespaces == R.CompactNamespaces &&
ConstructorInitializerIndentWidth ==
R.ConstructorInitializerIndentWidth &&
ContinuationIndentWidth == R.ContinuationIndentWidth &&
Cpp11BracedListStyle == R.Cpp11BracedListStyle &&
DerivePointerAlignment == R.DerivePointerAlignment &&
DisableFormat == R.DisableFormat &&
EmptyLineAfterAccessModifier == R.EmptyLineAfterAccessModifier &&
EmptyLineBeforeAccessModifier == R.EmptyLineBeforeAccessModifier &&
EnumTrailingComma == R.EnumTrailingComma &&
ExperimentalAutoDetectBinPacking ==
R.ExperimentalAutoDetectBinPacking &&
FixNamespaceComments == R.FixNamespaceComments &&
ForEachMacros == R.ForEachMacros &&
IncludeStyle.IncludeBlocks == R.IncludeStyle.IncludeBlocks &&
IncludeStyle.IncludeCategories == R.IncludeStyle.IncludeCategories &&
IncludeStyle.IncludeIsMainRegex ==
R.IncludeStyle.IncludeIsMainRegex &&
IncludeStyle.IncludeIsMainSourceRegex ==
R.IncludeStyle.IncludeIsMainSourceRegex &&
IncludeStyle.MainIncludeChar == R.IncludeStyle.MainIncludeChar &&
IndentAccessModifiers == R.IndentAccessModifiers &&
IndentCaseBlocks == R.IndentCaseBlocks &&
IndentCaseLabels == R.IndentCaseLabels &&
IndentExportBlock == R.IndentExportBlock &&
IndentExternBlock == R.IndentExternBlock &&
IndentGotoLabels == R.IndentGotoLabels &&
IndentPPDirectives == R.IndentPPDirectives &&
IndentRequiresClause == R.IndentRequiresClause &&
IndentWidth == R.IndentWidth &&
IndentWrappedFunctionNames == R.IndentWrappedFunctionNames &&
InsertBraces == R.InsertBraces &&
InsertNewlineAtEOF == R.InsertNewlineAtEOF &&
IntegerLiteralSeparator == R.IntegerLiteralSeparator &&
JavaImportGroups == R.JavaImportGroups &&
JavaScriptQuotes == R.JavaScriptQuotes &&
JavaScriptWrapImports == R.JavaScriptWrapImports &&
KeepEmptyLines == R.KeepEmptyLines &&
KeepFormFeed == R.KeepFormFeed && Language == R.Language &&
LambdaBodyIndentation == R.LambdaBodyIndentation &&
LineEnding == R.LineEnding && MacroBlockBegin == R.MacroBlockBegin &&
MacroBlockEnd == R.MacroBlockEnd && Macros == R.Macros &&
MacrosSkippedByRemoveParentheses ==
R.MacrosSkippedByRemoveParentheses &&
MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep &&
NamespaceIndentation == R.NamespaceIndentation &&
NamespaceMacros == R.NamespaceMacros &&
NumericLiteralCase == R.NumericLiteralCase &&
ObjCBinPackProtocolList == R.ObjCBinPackProtocolList &&
ObjCBlockIndentWidth == R.ObjCBlockIndentWidth &&
ObjCBreakBeforeNestedBlockParam ==
R.ObjCBreakBeforeNestedBlockParam &&
ObjCPropertyAttributeOrder == R.ObjCPropertyAttributeOrder &&
ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty &&
ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList &&
OneLineFormatOffRegex == R.OneLineFormatOffRegex &&
PackConstructorInitializers == R.PackConstructorInitializers &&
PenaltyBreakAssignment == R.PenaltyBreakAssignment &&
PenaltyBreakBeforeFirstCallParameter ==
R.PenaltyBreakBeforeFirstCallParameter &&
PenaltyBreakBeforeMemberAccess == R.PenaltyBreakBeforeMemberAccess &&
PenaltyBreakComment == R.PenaltyBreakComment &&
PenaltyBreakFirstLessLess == R.PenaltyBreakFirstLessLess &&
PenaltyBreakOpenParenthesis == R.PenaltyBreakOpenParenthesis &&
PenaltyBreakScopeResolution == R.PenaltyBreakScopeResolution &&
PenaltyBreakString == R.PenaltyBreakString &&
PenaltyBreakTemplateDeclaration ==
R.PenaltyBreakTemplateDeclaration &&
PenaltyExcessCharacter == R.PenaltyExcessCharacter &&
PenaltyReturnTypeOnItsOwnLine == R.PenaltyReturnTypeOnItsOwnLine &&
PointerAlignment == R.PointerAlignment &&
QualifierAlignment == R.QualifierAlignment &&
QualifierOrder == R.QualifierOrder &&
RawStringFormats == R.RawStringFormats &&
ReferenceAlignment == R.ReferenceAlignment &&
RemoveBracesLLVM == R.RemoveBracesLLVM &&
RemoveEmptyLinesInUnwrappedLines ==
R.RemoveEmptyLinesInUnwrappedLines &&
RemoveParentheses == R.RemoveParentheses &&
RemoveSemicolon == R.RemoveSemicolon &&
RequiresClausePosition == R.RequiresClausePosition &&
RequiresExpressionIndentation == R.RequiresExpressionIndentation &&
SeparateDefinitionBlocks == R.SeparateDefinitionBlocks &&
ShortNamespaceLines == R.ShortNamespaceLines &&
SkipMacroDefinitionBody == R.SkipMacroDefinitionBody &&
SortIncludes == R.SortIncludes &&
SortJavaStaticImport == R.SortJavaStaticImport &&
SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
SpaceAfterLogicalNot == R.SpaceAfterLogicalNot &&
SpaceAfterOperatorKeyword == R.SpaceAfterOperatorKeyword &&
SpaceAfterTemplateKeyword == R.SpaceAfterTemplateKeyword &&
SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators &&
SpaceBeforeCaseColon == R.SpaceBeforeCaseColon &&
SpaceBeforeCpp11BracedList == R.SpaceBeforeCpp11BracedList &&
SpaceBeforeCtorInitializerColon ==
R.SpaceBeforeCtorInitializerColon &&
SpaceBeforeInheritanceColon == R.SpaceBeforeInheritanceColon &&
SpaceBeforeJsonColon == R.SpaceBeforeJsonColon &&
SpaceBeforeParens == R.SpaceBeforeParens &&
SpaceBeforeParensOptions == R.SpaceBeforeParensOptions &&
SpaceAroundPointerQualifiers == R.SpaceAroundPointerQualifiers &&
SpaceBeforeRangeBasedForLoopColon ==
R.SpaceBeforeRangeBasedForLoopColon &&
SpaceBeforeSquareBrackets == R.SpaceBeforeSquareBrackets &&
SpaceInEmptyBraces == R.SpaceInEmptyBraces &&
SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments &&
SpacesInAngles == R.SpacesInAngles &&
SpacesInContainerLiterals == R.SpacesInContainerLiterals &&
SpacesInLineCommentPrefix.Minimum ==
R.SpacesInLineCommentPrefix.Minimum &&
SpacesInLineCommentPrefix.Maximum ==
R.SpacesInLineCommentPrefix.Maximum &&
SpacesInParens == R.SpacesInParens &&
SpacesInParensOptions == R.SpacesInParensOptions &&
SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
Standard == R.Standard &&
StatementAttributeLikeMacros == R.StatementAttributeLikeMacros &&
StatementMacros == R.StatementMacros &&
TableGenBreakingDAGArgOperators ==
R.TableGenBreakingDAGArgOperators &&
TableGenBreakInsideDAGArg == R.TableGenBreakInsideDAGArg &&
TabWidth == R.TabWidth && TemplateNames == R.TemplateNames &&
TypeNames == R.TypeNames && TypenameMacros == R.TypenameMacros &&
UseTab == R.UseTab && VariableTemplates == R.VariableTemplates &&
VerilogBreakBetweenInstancePorts ==
R.VerilogBreakBetweenInstancePorts &&
WhitespaceSensitiveMacros == R.WhitespaceSensitiveMacros &&
WrapNamespaceBodyWithEmptyLines == R.WrapNamespaceBodyWithEmptyLines;
}
std::optional<FormatStyle> GetLanguageStyle(LanguageKind Language) const;
struct FormatStyleSet {
typedef std::map<LanguageKind, FormatStyle> MapType;
std::optional<FormatStyle> Get(LanguageKind Language) const;
void Add(FormatStyle Style);
void Clear();
private:
std::shared_ptr<MapType> Styles;
};
static FormatStyleSet BuildStyleSetFromConfiguration(
const FormatStyle &MainStyle,
const std::vector<FormatStyle> &ConfigurationStyles);
private:
FormatStyleSet StyleSet;
friend std::error_code
parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
bool AllowUnknownOptions,
llvm::SourceMgr::DiagHandlerTy DiagHandler,
void *DiagHandlerCtxt, bool IsDotHFile);
};
FormatStyle
getLLVMStyle(FormatStyle::LanguageKind Language = FormatStyle::LK_Cpp);
FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language);
FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language);
FormatStyle getMozillaStyle();
FormatStyle getWebKitStyle();
FormatStyle getGNUStyle();
FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind Language);
FormatStyle getClangFormatStyle();
FormatStyle getNoStyle();
bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language,
FormatStyle *Style);
std::error_code
parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
bool AllowUnknownOptions = false,
llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr,
void *DiagHandlerCtx = nullptr, bool IsDotHFile = false);
inline std::error_code parseConfiguration(StringRef Config, FormatStyle *Style,
bool AllowUnknownOptions = false,
bool IsDotHFile = false) {
return parseConfiguration(llvm::MemoryBufferRef(Config, "YAML"), Style,
AllowUnknownOptions, nullptr,
nullptr, IsDotHFile);
}
std::string configurationAsText(const FormatStyle &Style);
tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code,
ArrayRef<tooling::Range> Ranges,
StringRef FileName,
unsigned *Cursor = nullptr);
Expected<tooling::Replacements>
formatReplacements(StringRef Code, const tooling::Replacements &Replaces,
const FormatStyle &Style);
Expected<tooling::Replacements>
cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces,
const FormatStyle &Style);
struct FormattingAttemptStatus {
bool FormatComplete = true;
unsigned Line = 0;
};
tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
ArrayRef<tooling::Range> Ranges,
StringRef FileName = "<stdin>",
FormattingAttemptStatus *Status = nullptr);
tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
ArrayRef<tooling::Range> Ranges,
StringRef FileName, bool *IncompleteFormat);
tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code,
ArrayRef<tooling::Range> Ranges,
StringRef FileName = "<stdin>");
tooling::Replacements fixNamespaceEndComments(const FormatStyle &Style,
StringRef Code,
ArrayRef<tooling::Range> Ranges,
StringRef FileName = "<stdin>");
tooling::Replacements separateDefinitionBlocks(const FormatStyle &Style,
StringRef Code,
ArrayRef<tooling::Range> Ranges,
StringRef FileName = "<stdin>");
tooling::Replacements sortUsingDeclarations(const FormatStyle &Style,
StringRef Code,
ArrayRef<tooling::Range> Ranges,
StringRef FileName = "<stdin>");
LangOptions getFormattingLangOpts(const FormatStyle &Style = getLLVMStyle());
extern const char *StyleOptionHelpDescription;
extern const char *DefaultFormatStyle;
extern const char *DefaultFallbackStyle;
Expected<FormatStyle>
getStyle(StringRef StyleName, StringRef FileName, StringRef FallbackStyle,
StringRef Code = "", llvm::vfs::FileSystem *FS = nullptr,
bool AllowUnknownOptions = false,
llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr);
FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code);
inline StringRef getLanguageName(FormatStyle::LanguageKind Language) {
switch (Language) {
case FormatStyle::LK_C:
return "C";
case FormatStyle::LK_Cpp:
return "C++";
case FormatStyle::LK_CSharp:
return "CSharp";
case FormatStyle::LK_ObjC:
return "Objective-C";
case FormatStyle::LK_Java:
return "Java";
case FormatStyle::LK_JavaScript:
return "JavaScript";
case FormatStyle::LK_Json:
return "Json";
case FormatStyle::LK_Proto:
return "Proto";
case FormatStyle::LK_TableGen:
return "TableGen";
case FormatStyle::LK_TextProto:
return "TextProto";
case FormatStyle::LK_Verilog:
return "Verilog";
default:
return "Unknown";
}
}
bool isClangFormatOn(StringRef Comment);
bool isClangFormatOff(StringRef Comment);
}
}
template <>
struct std::is_error_code_enum<clang::format::ParseError> : std::true_type {};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment