| OLD | NEW |
| 1 {#--- | 1 {#--- |
| 2 Macro for enum definition, and the declaration of associated functions. | 2 Macro for enum definition, and the declaration of associated functions. |
| 3 ---#} | 3 ---#} |
| 4 | 4 |
| 5 {%- macro enum_decl(enum) %} | 5 {%- macro enum_decl(enum) %} |
| 6 {%- set enum_name = enum|get_name_for_kind(flatten_nested_kind=True) %} | 6 {%- set enum_name = enum|get_name_for_kind(flatten_nested_kind=True) %} |
| 7 enum class {{enum_name}} : int32_t { | 7 enum class {{enum_name}} : int32_t { |
| 8 {%- for field in enum.fields %} | 8 {%- for field in enum.fields %} |
| 9 {%- if field.value %} | 9 {%- if field.value %} |
| 10 {{field.name}} = {{field.value|expression_to_text}}, | 10 {{field.name}} = {{field.value|expression_to_text}}, |
| 11 {%- else %} | 11 {%- else %} |
| 12 {{field.name}}, | 12 {{field.name}}, |
| 13 {%- endif %} | 13 {%- endif %} |
| 14 {%- endfor %} | 14 {%- endfor %} |
| 15 }; | 15 }; |
| 16 | 16 |
| 17 inline std::ostream& operator<<(std::ostream& os, {{enum_name}} value) { | 17 inline std::ostream& operator<<(std::ostream& os, {{enum_name}} value) { |
| 18 {%- if enum.fields %} |
| 18 switch(value) { | 19 switch(value) { |
| 19 {%- for _, values in enum.fields|groupby('numeric_value') %} | 20 {%- for _, values in enum.fields|groupby('numeric_value') %} |
| 20 case {{enum_name}}::{{values[0].name}}: | 21 case {{enum_name}}::{{values[0].name}}: |
| 21 return os << "{{enum_name}}:: | 22 return os << "{{enum_name}}:: |
| 22 {%- if values|length > 1 -%} | 23 {%- if values|length > 1 -%} |
| 23 {{'{'}} | 24 {{'{'}} |
| 24 {%- endif -%} | 25 {%- endif -%} |
| 25 {{values|map(attribute='name')|join(', ')}} | 26 {{values|map(attribute='name')|join(', ')}} |
| 26 {%- if values|length > 1 -%} | 27 {%- if values|length > 1 -%} |
| 27 {{'}'}} | 28 {{'}'}} |
| 28 {%- endif -%} | 29 {%- endif -%} |
| 29 "; | 30 "; |
| 30 {%- endfor %} | 31 {%- endfor %} |
| 31 default: | 32 default: |
| 32 return os << "Unknown {{enum_name}} value: " << static_cast<int32_t>(value
); | 33 return os << "Unknown {{enum_name}} value: " << static_cast<int32_t>(value
); |
| 33 } | 34 } |
| 35 {%- else %} |
| 36 return os << "Unknown {{enum_name}} value: " << static_cast<int32_t>(value); |
| 37 {%- endif %} |
| 34 } | 38 } |
| 35 | 39 |
| 36 {#- Returns true if the given enum value exists in this version of enum. #} | 40 {#- Returns true if the given enum value exists in this version of enum. #} |
| 37 inline bool IsKnownEnumValue({{enum_name}} value) { | 41 inline bool IsKnownEnumValue({{enum_name}} value) { |
| 38 return {{enum|get_name_for_kind(internal=True, | 42 return {{enum|get_name_for_kind(internal=True, |
| 39 flatten_nested_kind=True)}}::IsKnownValue( | 43 flatten_nested_kind=True)}}::IsKnownValue( |
| 40 static_cast<int32_t>(value)); | 44 static_cast<int32_t>(value)); |
| 41 } | 45 } |
| 42 {%- endmacro %} | 46 {%- endmacro %} |
| 43 | 47 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 } | 122 } |
| 119 static void constructDeletedValue({{enum_name}}& slot, bool) { | 123 static void constructDeletedValue({{enum_name}}& slot, bool) { |
| 120 slot = static_cast<{{enum_name}}>({{deleted_value}}); | 124 slot = static_cast<{{enum_name}}>({{deleted_value}}); |
| 121 } | 125 } |
| 122 static bool isDeletedValue(const {{enum_name}}& value) { | 126 static bool isDeletedValue(const {{enum_name}}& value) { |
| 123 return value == static_cast<{{enum_name}}>({{deleted_value}}); | 127 return value == static_cast<{{enum_name}}>({{deleted_value}}); |
| 124 } | 128 } |
| 125 }; | 129 }; |
| 126 } // namespace WTF | 130 } // namespace WTF |
| 127 {%- endmacro %} | 131 {%- endmacro %} |
| OLD | NEW |