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;
222 bool AllowShortBlocksOnASingleLine;
235 bool AllowShortCaseLabelsOnASingleLine;
239 enum ShortFunctionStyle {
287 ShortFunctionStyle AllowShortFunctionsOnASingleLine;
320 ShortIfStyle AllowShortIfStatementsOnASingleLine;
324 enum ShortLambdaStyle {
353 ShortLambdaStyle AllowShortLambdasOnASingleLine;
357 bool AllowShortLoopsOnASingleLine;
361 enum DefinitionReturnTypeBreakingStyle {
373 enum ReturnTypeBreakingStyle {
439 RTBS_TopLevelDefinitions,
444 DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType;
447 ReturnTypeBreakingStyle AlwaysBreakAfterReturnType;
461 bool AlwaysBreakBeforeMultilineStrings;
464 enum BreakTemplateDeclarationsStyle {
500 BreakTemplateDeclarationsStyle AlwaysBreakTemplateDeclarations;
518 bool BinPackArguments;
532 bool BinPackParameters;
546 enum BinaryOperatorStyle {
586 BinaryOperatorStyle BreakBeforeBinaryOperators;
589 enum BraceBreakingStyle {
730 BraceBreakingStyle BreakBeforeBraces;
739 struct BraceWrappingFlags {
783 bool AfterControlStatement;
831 bool AfterObjCDeclaration;
873 bool AfterExternBlock;
917 bool SplitEmptyFunction;
928 bool SplitEmptyRecord;
939 bool SplitEmptyNamespace;
954 BraceWrappingFlags BraceWrapping;
968 bool BreakBeforeTernaryOperators;
971 enum BreakConstructorInitializersStyle {
997 BreakConstructorInitializersStyle BreakConstructorInitializers;
1006 bool BreakAfterJavaFieldAnnotations;
1009 bool BreakStringLiterals;
1016 unsigned ColumnLimit;
1025 std::string CommentPragmas;
1028 enum BreakInheritanceListStyle {
1057 BreakInheritanceListStyle BreakInheritanceList;
1080 bool CompactNamespaces;
1098 bool ConstructorInitializerAllOnOneLineOrOnePerLine;
1102 unsigned ConstructorInitializerIndentWidth;
1112 unsigned ContinuationIndentWidth;
1134 bool Cpp11BracedListStyle;
1141 bool DerivePointerAlignment;
1156 bool ExperimentalAutoDetectBinPacking;
1166 bool FixNamespaceComments;
1183 std::vector<std::string> ForEachMacros;
1199 std::vector<std::string> TypenameMacros;
1209 std::vector<std::string> StatementMacros;
1221 std::vector<std::string> NamespaceMacros;
1239 bool IndentCaseLabels;
1242 enum PPDirectiveIndentStyle {
1273 PPDirectiveIndentStyle IndentPPDirectives;
1286 unsigned IndentWidth;
1299 bool IndentWrappedFunctionNames;
1330 std::vector<std::string> JavaImportGroups;
1334 enum JavaScriptQuoteStyle {
1356 JavaScriptQuoteStyle JavaScriptQuotes;
1370 bool JavaScriptWrapImports;
1380 bool KeepEmptyLinesAtTheStartOfBlocks;
1409 bool isCpp()
const {
return Language == LK_Cpp || Language == LK_ObjC; }
1410 bool isCSharp()
const {
return Language == LK_CSharp; }
1413 LanguageKind Language;
1441 std::string MacroBlockBegin;
1444 std::string MacroBlockEnd;
1457 unsigned MaxEmptyLinesToKeep;
1460 enum NamespaceIndentationKind {
1494 NamespaceIndentationKind NamespaceIndentation;
1526 BinPackStyle ObjCBinPackProtocolList;
1536 unsigned ObjCBlockIndentWidth;
1540 bool ObjCSpaceAfterProperty;
1544 bool ObjCSpaceBeforeProtocolList;
1547 unsigned PenaltyBreakAssignment;
1550 unsigned PenaltyBreakBeforeFirstCallParameter;
1553 unsigned PenaltyBreakComment;
1556 unsigned PenaltyBreakFirstLessLess;
1559 unsigned PenaltyBreakString;
1562 unsigned PenaltyBreakTemplateDeclaration;
1565 unsigned PenaltyExcessCharacter;
1569 unsigned PenaltyReturnTypeOnItsOwnLine;
1572 enum PointerAlignmentStyle {
1591 PointerAlignmentStyle PointerAlignment;
1594 struct RawStringFormat {
1596 LanguageKind Language;
1598 std::vector<std::string> Delimiters;
1600 std::vector<std::string> EnclosingFunctions;
1602 std::string CanonicalDelimiter;
1606 std::string BasedOnStyle;
1607 bool operator==(
const RawStringFormat &Other)
const {
1608 return Language == Other.Language && Delimiters == Other.Delimiters &&
1609 EnclosingFunctions == Other.EnclosingFunctions &&
1610 CanonicalDelimiter == Other.CanonicalDelimiter &&
1611 BasedOnStyle == Other.BasedOnStyle;
1650 std::vector<RawStringFormat> RawStringFormats;
1664 bool ReflowComments;
1688 bool SortUsingDeclarations;
1695 bool SpaceAfterCStyleCast;
1702 bool SpaceAfterLogicalNot;
1709 bool SpaceAfterTemplateKeyword;
1717 bool SpaceBeforeAssignmentOperators;
1728 bool SpaceBeforeCpp11BracedList;
1736 bool SpaceBeforeCtorInitializerColon;
1743 bool SpaceBeforeInheritanceColon;
1746 enum SpaceBeforeParensOptions {
1765 SBPO_ControlStatements,
1776 SBPO_NonEmptyParentheses,
1792 SpaceBeforeParensOptions SpaceBeforeParens;
1800 bool SpaceBeforeRangeBasedForLoopColon;
1812 bool SpaceInEmptyParentheses;
1828 unsigned SpacesBeforeTrailingComments;
1837 bool SpacesInAngles;
1846 bool SpacesInContainerLiterals;
1853 bool SpacesInCStyleCastParentheses;
1860 bool SpacesInParentheses;
1869 bool SpacesInSquareBrackets;
1872 enum LanguageStandard {
1884 LanguageStandard Standard;
1896 UT_ForContinuationAndIndentation,
1914 AllowAllConstructorInitializersOnNextLine ==
1915 R.AllowAllConstructorInitializersOnNextLine &&
1916 AllowAllParametersOfDeclarationOnNextLine ==
1917 R.AllowAllParametersOfDeclarationOnNextLine &&
1918 AllowShortBlocksOnASingleLine == R.AllowShortBlocksOnASingleLine &&
1919 AllowShortCaseLabelsOnASingleLine ==
1920 R.AllowShortCaseLabelsOnASingleLine &&
1921 AllowShortFunctionsOnASingleLine ==
1922 R.AllowShortFunctionsOnASingleLine &&
1923 AllowShortIfStatementsOnASingleLine ==
1924 R.AllowShortIfStatementsOnASingleLine &&
1925 AllowShortLambdasOnASingleLine == R.AllowShortLambdasOnASingleLine &&
1926 AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine &&
1927 AlwaysBreakAfterReturnType == R.AlwaysBreakAfterReturnType &&
1928 AlwaysBreakBeforeMultilineStrings ==
1929 R.AlwaysBreakBeforeMultilineStrings &&
1930 AlwaysBreakTemplateDeclarations ==
1931 R.AlwaysBreakTemplateDeclarations &&
1932 BinPackArguments == R.BinPackArguments &&
1933 BinPackParameters == R.BinPackParameters &&
1934 BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators &&
1935 BreakBeforeBraces == R.BreakBeforeBraces &&
1936 BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
1937 BreakConstructorInitializers == R.BreakConstructorInitializers &&
1938 CompactNamespaces == R.CompactNamespaces &&
1939 BreakAfterJavaFieldAnnotations == R.BreakAfterJavaFieldAnnotations &&
1940 BreakStringLiterals == R.BreakStringLiterals &&
1941 ColumnLimit == R.ColumnLimit && CommentPragmas == R.CommentPragmas &&
1942 BreakInheritanceList == R.BreakInheritanceList &&
1943 ConstructorInitializerAllOnOneLineOrOnePerLine ==
1944 R.ConstructorInitializerAllOnOneLineOrOnePerLine &&
1945 ConstructorInitializerIndentWidth ==
1946 R.ConstructorInitializerIndentWidth &&
1947 ContinuationIndentWidth == R.ContinuationIndentWidth &&
1948 Cpp11BracedListStyle == R.Cpp11BracedListStyle &&
1949 DerivePointerAlignment == R.DerivePointerAlignment &&
1950 DisableFormat == R.DisableFormat &&
1951 ExperimentalAutoDetectBinPacking ==
1952 R.ExperimentalAutoDetectBinPacking &&
1953 FixNamespaceComments == R.FixNamespaceComments &&
1954 ForEachMacros == R.ForEachMacros &&
1955 IncludeStyle.
IncludeBlocks == R.IncludeStyle.IncludeBlocks &&
1957 IndentCaseLabels == R.IndentCaseLabels &&
1958 IndentPPDirectives == R.IndentPPDirectives &&
1959 IndentWidth == R.IndentWidth && Language == R.Language &&
1960 IndentWrappedFunctionNames == R.IndentWrappedFunctionNames &&
1961 JavaImportGroups == R.JavaImportGroups &&
1962 JavaScriptQuotes == R.JavaScriptQuotes &&
1963 JavaScriptWrapImports == R.JavaScriptWrapImports &&
1964 KeepEmptyLinesAtTheStartOfBlocks ==
1965 R.KeepEmptyLinesAtTheStartOfBlocks &&
1966 MacroBlockBegin == R.MacroBlockBegin &&
1967 MacroBlockEnd == R.MacroBlockEnd &&
1968 MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep &&
1969 NamespaceIndentation == R.NamespaceIndentation &&
1970 NamespaceMacros == R.NamespaceMacros &&
1971 ObjCBinPackProtocolList == R.ObjCBinPackProtocolList &&
1972 ObjCBlockIndentWidth == R.ObjCBlockIndentWidth &&
1973 ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty &&
1974 ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList &&
1975 PenaltyBreakAssignment == R.PenaltyBreakAssignment &&
1976 PenaltyBreakBeforeFirstCallParameter ==
1977 R.PenaltyBreakBeforeFirstCallParameter &&
1978 PenaltyBreakComment == R.PenaltyBreakComment &&
1979 PenaltyBreakFirstLessLess == R.PenaltyBreakFirstLessLess &&
1980 PenaltyBreakString == R.PenaltyBreakString &&
1981 PenaltyExcessCharacter == R.PenaltyExcessCharacter &&
1982 PenaltyReturnTypeOnItsOwnLine == R.PenaltyReturnTypeOnItsOwnLine &&
1983 PenaltyBreakTemplateDeclaration ==
1984 R.PenaltyBreakTemplateDeclaration &&
1985 PointerAlignment == R.PointerAlignment &&
1986 RawStringFormats == R.RawStringFormats &&
1987 SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
1988 SpaceAfterLogicalNot == R.SpaceAfterLogicalNot &&
1989 SpaceAfterTemplateKeyword == R.SpaceAfterTemplateKeyword &&
1990 SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators &&
1991 SpaceBeforeCpp11BracedList == R.SpaceBeforeCpp11BracedList &&
1992 SpaceBeforeCtorInitializerColon ==
1993 R.SpaceBeforeCtorInitializerColon &&
1994 SpaceBeforeInheritanceColon == R.SpaceBeforeInheritanceColon &&
1995 SpaceBeforeParens == R.SpaceBeforeParens &&
1996 SpaceBeforeRangeBasedForLoopColon ==
1997 R.SpaceBeforeRangeBasedForLoopColon &&
1998 SpaceInEmptyParentheses == R.SpaceInEmptyParentheses &&
1999 SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments &&
2000 SpacesInAngles == R.SpacesInAngles &&
2001 SpacesInContainerLiterals == R.SpacesInContainerLiterals &&
2002 SpacesInCStyleCastParentheses == R.SpacesInCStyleCastParentheses &&
2003 SpacesInParentheses == R.SpacesInParentheses &&
2004 SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
2005 Standard == R.Standard && TabWidth == R.TabWidth &&
2006 StatementMacros == R.StatementMacros && UseTab == R.UseTab &&
2007 TypenameMacros == R.TypenameMacros;
2019 struct FormatStyleSet {
2020 typedef std::map<FormatStyle::LanguageKind, FormatStyle> MapType;
2035 std::shared_ptr<MapType> Styles;
2038 static FormatStyleSet BuildStyleSetFromConfiguration(
2040 const std::vector<FormatStyle> &ConfigurationStyles);
2043 FormatStyleSet StyleSet;
2051 FormatStyle::LanguageKind Language = FormatStyle::LanguageKind::LK_Cpp);
2106 unsigned *
Cursor =
nullptr);
2136 bool FormatComplete =
true;
2157 StringRef FileName =
"<stdin>",
2166 bool *IncompleteFormat);
2174 StringRef FileName =
"<stdin>");
2183 StringRef FileName =
"<stdin>");
2193 StringRef FileName =
"<stdin>");
2239 StringRef FallbackStyle,
2240 StringRef Code =
"",
2241 llvm::vfs::FileSystem *FS =
nullptr);
2245 FormatStyle::LanguageKind
guessLanguage(StringRef FileName, StringRef Code);
2250 case FormatStyle::LK_Cpp:
2252 case FormatStyle::LK_CSharp:
2254 case FormatStyle::LK_ObjC:
2255 return "Objective-C";
2256 case FormatStyle::LK_Java:
2258 case FormatStyle::LK_JavaScript:
2259 return "JavaScript";
2260 case FormatStyle::LK_Proto:
2262 case FormatStyle::LK_TableGen:
2264 case FormatStyle::LK_TextProto:
2279 #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...
Defines the clang::LangOptions interface.
const AnnotatedLine * Line
Dataflow Directional Tag Classes.