diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-04-13 20:28:17 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-04-14 14:54:06 +0200 |
commit | c66da0f2cb54f552abc7574f873ccb4a9260f4c9 (patch) | |
tree | 330610720b88c21df75937804a06162eae4978a3 /Meta | |
parent | c50661067d08d0b54abb90c3fb708dd1ba161904 (diff) | |
download | serenity-c66da0f2cb54f552abc7574f873ccb4a9260f4c9.zip |
LibWeb: Assign an underlying type to generated CSS enums
I'm *pretty* sure that even a u32 would be overkill but you never know
with CSS specs.
Diffstat (limited to 'Meta')
-rw-r--r-- | Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSEnums.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSEnums.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSEnums.cpp index a9d6aa06aa..bb31170488 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSEnums.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSEnums.cpp @@ -62,7 +62,19 @@ enum class ValueID; enum_generator.set("name:titlecase", title_casify(name)); enum_generator.set("name:snakecase", snake_casify(name)); - enum_generator.appendln("enum class @name:titlecase@ {"); + // Find the smallest possible type to use. + auto member_max_value = members.size() - 1; + if (NumericLimits<u8>::max() >= member_max_value) { + enum_generator.set("enum_type", "u8"); + } else if (NumericLimits<u16>::max() >= member_max_value) { + enum_generator.set("enum_type", "u16"); + } else if (NumericLimits<u32>::max() >= member_max_value) { + enum_generator.set("enum_type", "u32"); + } else { + enum_generator.set("enum_type", "u64"); + } + + enum_generator.appendln("enum class @name:titlecase@ : @enum_type@ {"); for (auto& member : members.values()) { auto member_name = member.to_string(); |