[llvm-branch-commits] [clang] c7e825b - [format][NFC] Use unsigned char as the base of all enums in FormatStyle
Nathan James via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Dec 23 12:32:36 PST 2020
Author: Nathan James
Date: 2020-12-23T20:27:44Z
New Revision: c7e825b910a96c42bda1de4e7fb34c369da76625
URL: https://github.com/llvm/llvm-project/commit/c7e825b910a96c42bda1de4e7fb34c369da76625
DIFF: https://github.com/llvm/llvm-project/commit/c7e825b910a96c42bda1de4e7fb34c369da76625.diff
LOG: [format][NFC] Use unsigned char as the base of all enums in FormatStyle
This removes alot of unnecessary padding, trimming the size of the struct from 728->608 on 64 bit platforms.
Reviewed By: MyDeveloperDay
Differential Revision: https://reviews.llvm.org/D93758
Added:
Modified:
clang/docs/tools/dump_format_style.py
clang/include/clang/Format/Format.h
Removed:
################################################################################
diff --git a/clang/docs/tools/dump_format_style.py b/clang/docs/tools/dump_format_style.py
index 61167979b3e6..d01c823a9a20 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -144,7 +144,7 @@ class State(object):
comment += clean_comment_line(line)
elif line.startswith('enum'):
state = State.InEnum
- name = re.sub(r'enum\s+(\w+)\s*\{', '\\1', line)
+ name = re.sub(r'enum\s+(\w+)\s*(:((\s*\w+)+)\s*)?\{', '\\1', line)
enum = Enum(name, comment)
elif line.startswith('struct'):
state = State.InNestedStruct
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index 208fc105d4b6..9b8309213261 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -56,7 +56,7 @@ struct FormatStyle {
int AccessModifierOffset;
/// Different styles for aligning after open brackets.
- enum BracketAlignmentStyle {
+ enum BracketAlignmentStyle : unsigned char {
/// Align parameters on the open bracket, e.g.:
/// \code
/// someLongFunction(argument1,
@@ -131,7 +131,7 @@ struct FormatStyle {
bool AlignConsecutiveDeclarations;
/// Different styles for aligning escaped newlines.
- enum EscapedNewlineAlignmentStyle {
+ enum EscapedNewlineAlignmentStyle : unsigned char {
/// Don't align escaped newlines.
/// \code
/// #define A \
@@ -165,7 +165,7 @@ struct FormatStyle {
EscapedNewlineAlignmentStyle AlignEscapedNewlines;
/// Different styles for aligning operands.
- enum OperandAlignmentStyle {
+ enum OperandAlignmentStyle : unsigned char {
/// Do not align operands of binary and ternary expressions.
/// The wrapped lines are indented ``ContinuationIndentWidth`` spaces from
/// the start of the line.
@@ -275,7 +275,7 @@ struct FormatStyle {
/// Different styles for merging short blocks containing at most one
/// statement.
- enum ShortBlockStyle {
+ enum ShortBlockStyle : unsigned char {
/// Never merge blocks into a single line.
/// \code
/// while (true) {
@@ -320,7 +320,7 @@ struct FormatStyle {
/// Different styles for merging short functions containing at most one
/// statement.
- enum ShortFunctionStyle {
+ enum ShortFunctionStyle : unsigned char {
/// Never merge functions into a single line.
SFS_None,
/// Only merge functions defined inside a class. Same as "inline",
@@ -371,7 +371,7 @@ struct FormatStyle {
ShortFunctionStyle AllowShortFunctionsOnASingleLine;
/// Different styles for handling short if lines
- enum ShortIfStyle {
+ enum ShortIfStyle : unsigned char {
/// Never put short ifs on the same line.
/// \code
/// if (a)
@@ -405,7 +405,7 @@ struct FormatStyle {
/// Different styles for merging short lambdas containing at most one
/// statement.
- enum ShortLambdaStyle {
+ enum ShortLambdaStyle : unsigned char {
/// Never merge lambdas into a single line.
SLS_None,
/// Only merge empty lambdas.
@@ -442,7 +442,7 @@ struct FormatStyle {
/// Different ways to break after the function definition return type.
/// This option is **deprecated** and is retained for backwards compatibility.
- enum DefinitionReturnTypeBreakingStyle {
+ enum DefinitionReturnTypeBreakingStyle : unsigned char {
/// Break after return type automatically.
/// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
DRTBS_None,
@@ -454,7 +454,7 @@ struct FormatStyle {
/// Different ways to break after the function definition or
/// declaration return type.
- enum ReturnTypeBreakingStyle {
+ enum ReturnTypeBreakingStyle : unsigned char {
/// Break after return type automatically.
/// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
/// \code
@@ -545,7 +545,7 @@ struct FormatStyle {
bool AlwaysBreakBeforeMultilineStrings;
/// Different ways to break after the template declaration.
- enum BreakTemplateDeclarationsStyle {
+ enum BreakTemplateDeclarationsStyle : unsigned char {
/// Do not force break before declaration.
/// ``PenaltyBreakTemplateDeclaration`` is taken into account.
/// \code
@@ -620,7 +620,7 @@ struct FormatStyle {
bool BinPackArguments;
/// The style of inserting trailing commas into container literals.
- enum TrailingCommaStyle {
+ enum TrailingCommaStyle : unsigned char {
/// Do not insert trailing commas.
TCS_None,
/// Insert trailing commas in container literals that were wrapped over
@@ -664,7 +664,7 @@ struct FormatStyle {
/// The style of wrapping parameters on the same line (bin-packed) or
/// on one line each.
- enum BinPackStyle {
+ enum BinPackStyle : unsigned char {
/// Automatically determine parameter bin-packing behavior.
BPS_Auto,
/// Always bin-pack parameters.
@@ -674,7 +674,7 @@ struct FormatStyle {
};
/// The style of breaking before or after binary operators.
- enum BinaryOperatorStyle {
+ enum BinaryOperatorStyle : unsigned char {
/// Break after operators.
/// \code
/// LooooooooooongType loooooooooooooooooooooongVariable =
@@ -717,7 +717,7 @@ struct FormatStyle {
BinaryOperatorStyle BreakBeforeBinaryOperators;
/// Different ways to attach braces to their surrounding context.
- enum BraceBreakingStyle {
+ enum BraceBreakingStyle : unsigned char {
/// Always attach braces to surrounding context.
/// \code
/// namespace N {
@@ -1151,7 +1151,7 @@ struct FormatStyle {
BraceBreakingStyle BreakBeforeBraces;
/// Different ways to wrap braces after control statements.
- enum BraceWrappingAfterControlStatementStyle {
+ enum BraceWrappingAfterControlStatementStyle : unsigned char {
/// Never wrap braces after a control statement.
/// \code
/// if (foo()) {
@@ -1450,7 +1450,7 @@ struct FormatStyle {
bool BreakBeforeTernaryOperators;
/// Different ways to break initializers.
- enum BreakConstructorInitializersStyle {
+ enum BreakConstructorInitializersStyle : unsigned char {
/// Break constructor initializers before the colon and after the commas.
/// \code
/// Constructor()
@@ -1517,7 +1517,7 @@ struct FormatStyle {
std::string CommentPragmas;
/// Different ways to break inheritance list.
- enum BreakInheritanceListStyle {
+ enum BreakInheritanceListStyle : unsigned char {
/// Break inheritance list before the colon and after the commas.
/// \code
/// class Foo
@@ -1816,7 +1816,7 @@ struct FormatStyle {
bool IndentPragmas;
/// Options for indenting preprocessor directives.
- enum PPDirectiveIndentStyle {
+ enum PPDirectiveIndentStyle : unsigned char {
/// Does not indent any directives.
/// \code
/// #if FOO
@@ -1850,7 +1850,7 @@ struct FormatStyle {
PPDirectiveIndentStyle IndentPPDirectives;
/// Indents extern blocks
- enum IndentExternBlockStyle {
+ enum IndentExternBlockStyle : unsigned char {
/// Backwards compatible with AfterExternBlock's indenting.
/// \code
/// IndentExternBlock: AfterExternBlock
@@ -1967,7 +1967,7 @@ struct FormatStyle {
/// Quotation styles for JavaScript strings. Does not affect template
/// strings.
- enum JavaScriptQuoteStyle {
+ enum JavaScriptQuoteStyle : unsigned char {
/// Leave string quotes as they are.
/// \code{.js}
/// string1 = "foo";
@@ -2022,7 +2022,7 @@ struct FormatStyle {
/// When stored in a configuration file, specifies the language, that the
/// configuration targets. When passed to the ``reformat()`` function, enables
/// syntax features specific to the language.
- enum LanguageKind {
+ enum LanguageKind : unsigned char {
/// Do not use.
LK_None,
/// Should be used for C, C++.
@@ -2095,7 +2095,7 @@ struct FormatStyle {
unsigned MaxEmptyLinesToKeep;
/// Different ways to indent namespace contents.
- enum NamespaceIndentationKind {
+ enum NamespaceIndentationKind : unsigned char {
/// Don't indent in namespaces.
/// \code
/// namespace out {
@@ -2234,7 +2234,7 @@ struct FormatStyle {
unsigned PenaltyIndentedWhitespace;
/// The ``&`` and ``*`` alignment style.
- enum PointerAlignmentStyle {
+ enum PointerAlignmentStyle : unsigned char {
/// Align pointer to the left.
/// \code
/// int* a;
@@ -2339,7 +2339,7 @@ struct FormatStyle {
bool SortIncludes;
/// Position for Java Static imports.
- enum SortJavaStaticImportOptions {
+ enum SortJavaStaticImportOptions : unsigned char {
/// Static imports are placed before non-static imports.
/// \code{.java}
/// import static org.example.function1;
@@ -2399,7 +2399,7 @@ struct FormatStyle {
bool SpaceAfterTemplateKeyword;
/// Different ways to put a space before opening parentheses.
- enum SpaceAroundPointerQualifiersStyle {
+ enum SpaceAroundPointerQualifiersStyle : unsigned char {
/// Don't ensure spaces around pointer qualifiers and use PointerAlignment
/// instead.
/// \code
@@ -2465,7 +2465,7 @@ struct FormatStyle {
bool SpaceBeforeInheritanceColon;
/// Different ways to put a space before opening parentheses.
- enum SpaceBeforeParensOptions {
+ enum SpaceBeforeParensOptions : unsigned char {
/// Never put a space before opening parentheses.
/// \code
/// void f() {
@@ -2629,7 +2629,7 @@ struct FormatStyle {
bool SpaceBeforeSquareBrackets;
/// Styles for adding spacing around ``:`` in bitfield definitions.
- enum BitFieldColonSpacingStyle {
+ enum BitFieldColonSpacingStyle : unsigned char {
/// Add one space on each side of the ``:``
/// \code
/// unsigned bf : 2;
@@ -2664,7 +2664,7 @@ struct FormatStyle {
///
/// The correct way to spell a specific language version is e.g. ``c++11``.
/// The historical aliases ``Cpp03`` and ``Cpp11`` are deprecated.
- enum LanguageStandard {
+ enum LanguageStandard : unsigned char {
/// Parse and format as C++03.
/// ``Cpp03`` is a deprecated alias for ``c++03``
LS_Cpp03, // c++03
@@ -2694,7 +2694,7 @@ struct FormatStyle {
unsigned TabWidth;
/// Different ways to use tab in formatting.
- enum UseTabStyle {
+ enum UseTabStyle : unsigned char {
/// Never use tab.
UT_Never,
/// Use tabs only for indentation.
More information about the llvm-branch-commits
mailing list