14 #ifndef LLVM_CLANG_FORMAT_FORMAT_H 15 #define LLVM_CLANG_FORMAT_FORMAT_H 20 #include "llvm/ADT/ArrayRef.h" 21 #include "llvm/Support/Regex.h" 22 #include <system_error> 34 class DiagnosticConsumer;
41 const char *
name()
const noexcept
override;
42 std::string message(
int EV)
const override;
200 bool AllowAllConstructorInitializersOnNextLine;
217 bool AllowAllParametersOfDeclarationOnNextLine;
221 enum ShortBlockStyle {
249 ShortBlockStyle AllowShortBlocksOnASingleLine;
262 bool AllowShortCaseLabelsOnASingleLine;
266 enum ShortFunctionStyle {
314 ShortFunctionStyle AllowShortFunctionsOnASingleLine;
347 ShortIfStyle AllowShortIfStatementsOnASingleLine;
351 enum ShortLambdaStyle {
380 ShortLambdaStyle AllowShortLambdasOnASingleLine;
384 bool AllowShortLoopsOnASingleLine;
388 enum DefinitionReturnTypeBreakingStyle {
400 enum ReturnTypeBreakingStyle {
466 RTBS_TopLevelDefinitions,
471 DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType;
474 ReturnTypeBreakingStyle AlwaysBreakAfterReturnType;
488 bool AlwaysBreakBeforeMultilineStrings;
491 enum BreakTemplateDeclarationsStyle {
527 BreakTemplateDeclarationsStyle AlwaysBreakTemplateDeclarations;
545 bool BinPackArguments;
559 bool BinPackParameters;
573 enum BinaryOperatorStyle {
613 BinaryOperatorStyle BreakBeforeBinaryOperators;
616 enum BraceBreakingStyle {
783 BraceBreakingStyle BreakBeforeBraces;
786 enum BraceWrappingAfterControlStatementStyle {
826 struct BraceWrappingFlags {
855 BraceWrappingAfterControlStatementStyle AfterControlStatement;
903 bool AfterObjCDeclaration;
945 bool AfterExternBlock;
989 bool SplitEmptyFunction;
1000 bool SplitEmptyRecord;
1011 bool SplitEmptyNamespace;
1026 BraceWrappingFlags BraceWrapping;
1040 bool BreakBeforeTernaryOperators;
1043 enum BreakConstructorInitializersStyle {
1069 BreakConstructorInitializersStyle BreakConstructorInitializers;
1078 bool BreakAfterJavaFieldAnnotations;
1091 bool BreakStringLiterals;
1098 unsigned ColumnLimit;
1107 std::string CommentPragmas;
1110 enum BreakInheritanceListStyle {
1139 BreakInheritanceListStyle BreakInheritanceList;
1162 bool CompactNamespaces;
1181 bool ConstructorInitializerAllOnOneLineOrOnePerLine;
1186 unsigned ConstructorInitializerIndentWidth;
1196 unsigned ContinuationIndentWidth;
1218 bool Cpp11BracedListStyle;
1222 bool DeriveLineEnding;
1229 bool DerivePointerAlignment;
1244 bool ExperimentalAutoDetectBinPacking;
1254 bool FixNamespaceComments;
1271 std::vector<std::string> ForEachMacros;
1287 std::vector<std::string> TypenameMacros;
1297 std::vector<std::string> StatementMacros;
1309 std::vector<std::string> NamespaceMacros;
1328 bool IndentCaseLabels;
1344 bool IndentGotoLabels;
1347 enum PPDirectiveIndentStyle {
1378 PPDirectiveIndentStyle IndentPPDirectives;
1391 unsigned IndentWidth;
1404 bool IndentWrappedFunctionNames;
1435 std::vector<std::string> JavaImportGroups;
1439 enum JavaScriptQuoteStyle {
1461 JavaScriptQuoteStyle JavaScriptQuotes;
1476 bool JavaScriptWrapImports;
1487 bool KeepEmptyLinesAtTheStartOfBlocks;
1517 bool isCSharp()
const {
return Language == LK_CSharp; }
1548 std::string MacroBlockBegin;
1551 std::string MacroBlockEnd;
1564 unsigned MaxEmptyLinesToKeep;
1567 enum NamespaceIndentationKind {
1601 NamespaceIndentationKind NamespaceIndentation;
1633 BinPackStyle ObjCBinPackProtocolList;
1643 unsigned ObjCBlockIndentWidth;
1647 bool ObjCSpaceAfterProperty;
1651 bool ObjCSpaceBeforeProtocolList;
1654 unsigned PenaltyBreakAssignment;
1657 unsigned PenaltyBreakBeforeFirstCallParameter;
1660 unsigned PenaltyBreakComment;
1663 unsigned PenaltyBreakFirstLessLess;
1666 unsigned PenaltyBreakString;
1669 unsigned PenaltyBreakTemplateDeclaration;
1672 unsigned PenaltyExcessCharacter;
1676 unsigned PenaltyReturnTypeOnItsOwnLine;
1679 enum PointerAlignmentStyle {
1698 PointerAlignmentStyle PointerAlignment;
1701 struct RawStringFormat {
1705 std::vector<std::string> Delimiters;
1707 std::vector<std::string> EnclosingFunctions;
1709 std::string CanonicalDelimiter;
1713 std::string BasedOnStyle;
1714 bool operator==(
const RawStringFormat &Other)
const {
1715 return Language == Other.Language && Delimiters == Other.Delimiters &&
1716 EnclosingFunctions == Other.EnclosingFunctions &&
1717 CanonicalDelimiter == Other.CanonicalDelimiter &&
1718 BasedOnStyle == Other.BasedOnStyle;
1757 std::vector<RawStringFormat> RawStringFormats;
1772 bool ReflowComments;
1797 bool SortUsingDeclarations;
1804 bool SpaceAfterCStyleCast;
1811 bool SpaceAfterLogicalNot;
1818 bool SpaceAfterTemplateKeyword;
1826 bool SpaceBeforeAssignmentOperators;
1837 bool SpaceBeforeCpp11BracedList;
1845 bool SpaceBeforeCtorInitializerColon;
1852 bool SpaceBeforeInheritanceColon;
1855 enum SpaceBeforeParensOptions {
1874 SBPO_ControlStatements,
1885 SBPO_NonEmptyParentheses,
1901 SpaceBeforeParensOptions SpaceBeforeParens;
1909 bool SpaceBeforeRangeBasedForLoopColon;
1917 bool SpaceInEmptyBlock;
1929 bool SpaceInEmptyParentheses;
1945 unsigned SpacesBeforeTrailingComments;
1954 bool SpacesInAngles;
1963 bool SpacesInConditionalStatement;
1972 bool SpacesInContainerLiterals;
1979 bool SpacesInCStyleCastParentheses;
1986 bool SpacesInParentheses;
1996 bool SpacesInSquareBrackets;
2005 bool SpaceBeforeSquareBrackets;
2015 enum LanguageStandard {
2039 LanguageStandard Standard;
2051 UT_ForContinuationAndIndentation,
2073 AllowAllConstructorInitializersOnNextLine ==
2074 R.AllowAllConstructorInitializersOnNextLine &&
2075 AllowAllParametersOfDeclarationOnNextLine ==
2076 R.AllowAllParametersOfDeclarationOnNextLine &&
2077 AllowShortBlocksOnASingleLine == R.AllowShortBlocksOnASingleLine &&
2078 AllowShortCaseLabelsOnASingleLine ==
2079 R.AllowShortCaseLabelsOnASingleLine &&
2080 AllowShortFunctionsOnASingleLine ==
2081 R.AllowShortFunctionsOnASingleLine &&
2082 AllowShortIfStatementsOnASingleLine ==
2083 R.AllowShortIfStatementsOnASingleLine &&
2084 AllowShortLambdasOnASingleLine == R.AllowShortLambdasOnASingleLine &&
2085 AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine &&
2086 AlwaysBreakAfterReturnType == R.AlwaysBreakAfterReturnType &&
2087 AlwaysBreakBeforeMultilineStrings ==
2088 R.AlwaysBreakBeforeMultilineStrings &&
2089 AlwaysBreakTemplateDeclarations ==
2090 R.AlwaysBreakTemplateDeclarations &&
2091 BinPackArguments == R.BinPackArguments &&
2092 BinPackParameters == R.BinPackParameters &&
2093 BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators &&
2094 BreakBeforeBraces == R.BreakBeforeBraces &&
2095 BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
2096 BreakConstructorInitializers == R.BreakConstructorInitializers &&
2097 CompactNamespaces == R.CompactNamespaces &&
2098 BreakAfterJavaFieldAnnotations == R.BreakAfterJavaFieldAnnotations &&
2099 BreakStringLiterals == R.BreakStringLiterals &&
2100 ColumnLimit == R.ColumnLimit && CommentPragmas == R.CommentPragmas &&
2101 BreakInheritanceList == R.BreakInheritanceList &&
2102 ConstructorInitializerAllOnOneLineOrOnePerLine ==
2103 R.ConstructorInitializerAllOnOneLineOrOnePerLine &&
2104 ConstructorInitializerIndentWidth ==
2105 R.ConstructorInitializerIndentWidth &&
2106 ContinuationIndentWidth == R.ContinuationIndentWidth &&
2107 Cpp11BracedListStyle == R.Cpp11BracedListStyle &&
2108 DeriveLineEnding == R.DeriveLineEnding &&
2109 DerivePointerAlignment == R.DerivePointerAlignment &&
2110 DisableFormat == R.DisableFormat &&
2111 ExperimentalAutoDetectBinPacking ==
2112 R.ExperimentalAutoDetectBinPacking &&
2113 FixNamespaceComments == R.FixNamespaceComments &&
2114 ForEachMacros == R.ForEachMacros &&
2115 IncludeStyle.
IncludeBlocks == R.IncludeStyle.IncludeBlocks &&
2118 R.IncludeStyle.IncludeIsMainRegex &&
2120 R.IncludeStyle.IncludeIsMainSourceRegex &&
2121 IndentCaseLabels == R.IndentCaseLabels &&
2122 IndentGotoLabels == R.IndentGotoLabels &&
2123 IndentPPDirectives == R.IndentPPDirectives &&
2124 IndentWidth == R.IndentWidth && Language == R.Language &&
2125 IndentWrappedFunctionNames == R.IndentWrappedFunctionNames &&
2126 JavaImportGroups == R.JavaImportGroups &&
2127 JavaScriptQuotes == R.JavaScriptQuotes &&
2128 JavaScriptWrapImports == R.JavaScriptWrapImports &&
2129 KeepEmptyLinesAtTheStartOfBlocks ==
2130 R.KeepEmptyLinesAtTheStartOfBlocks &&
2131 MacroBlockBegin == R.MacroBlockBegin &&
2132 MacroBlockEnd == R.MacroBlockEnd &&
2133 MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep &&
2134 NamespaceIndentation == R.NamespaceIndentation &&
2135 NamespaceMacros == R.NamespaceMacros &&
2136 ObjCBinPackProtocolList == R.ObjCBinPackProtocolList &&
2137 ObjCBlockIndentWidth == R.ObjCBlockIndentWidth &&
2138 ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty &&
2139 ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList &&
2140 PenaltyBreakAssignment == R.PenaltyBreakAssignment &&
2141 PenaltyBreakBeforeFirstCallParameter ==
2142 R.PenaltyBreakBeforeFirstCallParameter &&
2143 PenaltyBreakComment == R.PenaltyBreakComment &&
2144 PenaltyBreakFirstLessLess == R.PenaltyBreakFirstLessLess &&
2145 PenaltyBreakString == R.PenaltyBreakString &&
2146 PenaltyExcessCharacter == R.PenaltyExcessCharacter &&
2147 PenaltyReturnTypeOnItsOwnLine == R.PenaltyReturnTypeOnItsOwnLine &&
2148 PenaltyBreakTemplateDeclaration ==
2149 R.PenaltyBreakTemplateDeclaration &&
2150 PointerAlignment == R.PointerAlignment &&
2151 RawStringFormats == R.RawStringFormats &&
2152 SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
2153 SpaceAfterLogicalNot == R.SpaceAfterLogicalNot &&
2154 SpaceAfterTemplateKeyword == R.SpaceAfterTemplateKeyword &&
2155 SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators &&
2156 SpaceBeforeCpp11BracedList == R.SpaceBeforeCpp11BracedList &&
2157 SpaceBeforeCtorInitializerColon ==
2158 R.SpaceBeforeCtorInitializerColon &&
2159 SpaceBeforeInheritanceColon == R.SpaceBeforeInheritanceColon &&
2160 SpaceBeforeParens == R.SpaceBeforeParens &&
2161 SpaceBeforeRangeBasedForLoopColon ==
2162 R.SpaceBeforeRangeBasedForLoopColon &&
2163 SpaceInEmptyBlock == R.SpaceInEmptyBlock &&
2164 SpaceInEmptyParentheses == R.SpaceInEmptyParentheses &&
2165 SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments &&
2166 SpacesInAngles == R.SpacesInAngles &&
2167 SpacesInConditionalStatement == R.SpacesInConditionalStatement &&
2168 SpacesInContainerLiterals == R.SpacesInContainerLiterals &&
2169 SpacesInCStyleCastParentheses == R.SpacesInCStyleCastParentheses &&
2170 SpacesInParentheses == R.SpacesInParentheses &&
2171 SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
2172 SpaceBeforeSquareBrackets == R.SpaceBeforeSquareBrackets &&
2173 Standard == R.Standard && TabWidth == R.TabWidth &&
2174 StatementMacros == R.StatementMacros && UseTab == R.UseTab &&
2175 UseCRLF == R.UseCRLF && TypenameMacros == R.TypenameMacros;
2187 struct FormatStyleSet {
2188 typedef std::map<FormatStyle::LanguageKind, FormatStyle> MapType;
2203 std::shared_ptr<MapType> Styles;
2206 static FormatStyleSet BuildStyleSetFromConfiguration(
2208 const std::vector<FormatStyle> &ConfigurationStyles);
2211 FormatStyleSet StyleSet;
2219 FormatStyle::LanguageKind
Language = FormatStyle::LanguageKind::LK_Cpp);
2278 unsigned *
Cursor =
nullptr);
2308 bool FormatComplete =
true;
2329 StringRef FileName =
"<stdin>",
2337 StringRef FileName,
bool *IncompleteFormat);
2345 StringRef FileName =
"<stdin>");
2354 StringRef FileName =
"<stdin>");
2364 StringRef FileName =
"<stdin>");
2410 StringRef FallbackStyle,
2411 StringRef Code =
"",
2412 llvm::vfs::FileSystem *FS =
nullptr);
2416 FormatStyle::LanguageKind
guessLanguage(StringRef FileName, StringRef Code);
2421 case FormatStyle::LK_Cpp:
2423 case FormatStyle::LK_CSharp:
2425 case FormatStyle::LK_ObjC:
2426 return "Objective-C";
2427 case FormatStyle::LK_Java:
2429 case FormatStyle::LK_JavaScript:
2430 return "JavaScript";
2431 case FormatStyle::LK_Proto:
2433 case FormatStyle::LK_TableGen:
2435 case FormatStyle::LK_TextProto:
2450 #endif // LLVM_CLANG_FORMAT_FORMAT_H bool operator==(CanQual< T > x, CanQual< U > y)
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Language
The language for the input, used to select and validate the language standard and possible actions...
Defines the clang::LangOptions interface.
const AnnotatedLine * Line
Dataflow Directional Tag Classes.
bool Add(InterpState &S, CodePtr OpPC)