Skip to content

Commit 76b9123

Browse files
authored
Merge pull request #866 from ab9rf/constexpr-codegen
generate enum traits as `constexpr`
2 parents 24322fe + 22416cc commit 76b9123

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

Enum.pm

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,18 +154,18 @@ sub render_enum_tables($$$$$$) {
154154

155155
with_emit_traits {
156156
emit_block {
157-
emit "static const bool is_complex = " . ($complex ? 'true' : 'false') . ";";
158-
emit "typedef $base_type base_type;";
159-
emit "typedef $full_name enum_type;";
160-
emit "static const base_type first_item_value = $base;";
161-
emit "static const base_type last_item_value = $last_value;";
157+
emit "static constexpr bool is_complex = " . ($complex ? 'true' : 'false') . ";";
158+
emit "using base_type = $base_type;";
159+
emit "using enum_type = $full_name;";
160+
emit "static constexpr base_type first_item_value = $base;";
161+
emit "static constexpr base_type last_item_value = $last_value;";
162162
# Cast the enum to integer in order to avoid GCC <= 4.5 assuming the value range is correct.
163163
emit_block {
164164
emit "return (value >= first_item_value && ",
165165
"value <= last_item_value);";
166166
} "static inline bool is_valid(base_type value) ";
167-
emit "static const enum_type first_item = (enum_type)first_item_value;";
168-
emit "static const enum_type last_item = (enum_type)last_item_value;";
167+
emit "static constexpr enum_type first_item = (enum_type)first_item_value;";
168+
emit "static constexpr enum_type last_item = (enum_type)last_item_value;";
169169
emit "static const char *const key_table[", $count, "];";
170170
if ($complex) {
171171
emit "static const DFHack::enum_identity::ComplexData complex;";

changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Template for new versions:
1818

1919
# Future
2020

21+
## Structures
22+
- updated codegen to generate enum trait constants as ``constexpr``
23+
2124
## Structures
2225

2326
# 53.06-r1

0 commit comments

Comments
 (0)