| 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}}, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 {%- set enum_name = enum|get_qualified_name_for_kind( | 87 {%- set enum_name = enum|get_qualified_name_for_kind( |
| 88 flatten_nested_kind=True, include_variant=False) %} | 88 flatten_nested_kind=True, include_variant=False) %} |
| 89 {%- set hash_fn_name = enum|wtf_hash_fn_name_for_enum %} | 89 {%- set hash_fn_name = enum|wtf_hash_fn_name_for_enum %} |
| 90 {# We need two unused enum values: #} | 90 {# We need two unused enum values: #} |
| 91 {%- set empty_value = -1000000 %} | 91 {%- set empty_value = -1000000 %} |
| 92 {%- set deleted_value = -1000001 %} | 92 {%- set deleted_value = -1000001 %} |
| 93 {%- set empty_value_unused = "false" if empty_value in enum|all_enum_values el
se "true" %} | 93 {%- set empty_value_unused = "false" if empty_value in enum|all_enum_values el
se "true" %} |
| 94 {%- set deleted_value_unused = "false" if empty_value in enum|all_enum_values
else "true" %} | 94 {%- set deleted_value_unused = "false" if empty_value in enum|all_enum_values
else "true" %} |
| 95 namespace WTF { | 95 namespace WTF { |
| 96 struct {{hash_fn_name}} { | 96 struct {{hash_fn_name}} { |
| 97 static unsigned hash(const {{enum_name}}& value) { | 97 static unsigned GetHash(const {{enum_name}}& value) { |
| 98 using utype = std::underlying_type<{{enum_name}}>::type; | 98 using utype = std::underlying_type<{{enum_name}}>::type; |
| 99 return DefaultHash<utype>::Hash().hash(static_cast<utype>(value)); | 99 return DefaultHash<utype>::Hash().GetHash(static_cast<utype>(value)); |
| 100 } | 100 } |
| 101 static bool equal(const {{enum_name}}& left, const {{enum_name}}& right) { | 101 static bool Equal(const {{enum_name}}& left, const {{enum_name}}& right) { |
| 102 return left == right; | 102 return left == right; |
| 103 } | 103 } |
| 104 static const bool safeToCompareToEmptyOrDeleted = true; | 104 static const bool safe_to_compare_to_empty_or_deleted = true; |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 template <> | 107 template <> |
| 108 struct DefaultHash<{{enum_name}}> { | 108 struct DefaultHash<{{enum_name}}> { |
| 109 using Hash = {{hash_fn_name}}; | 109 using Hash = {{hash_fn_name}}; |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 template <> | 112 template <> |
| 113 struct HashTraits<{{enum_name}}> | 113 struct HashTraits<{{enum_name}}> |
| 114 : public GenericHashTraits<{{enum_name}}> { | 114 : public GenericHashTraits<{{enum_name}}> { |
| 115 static_assert({{empty_value_unused}}, | 115 static_assert({{empty_value_unused}}, |
| 116 "{{empty_value}} is a reserved enum value"); | 116 "{{empty_value}} is a reserved enum value"); |
| 117 static_assert({{deleted_value_unused}}, | 117 static_assert({{deleted_value_unused}}, |
| 118 "{{deleted_value}} is a reserved enum value"); | 118 "{{deleted_value}} is a reserved enum value"); |
| 119 static const bool hasIsEmptyValueFunction = true; | 119 static const bool hasIsEmptyValueFunction = true; |
| 120 static bool isEmptyValue(const {{enum_name}}& value) { | 120 static bool IsEmptyValue(const {{enum_name}}& value) { |
| 121 return value == static_cast<{{enum_name}}>({{empty_value}}); | 121 return value == static_cast<{{enum_name}}>({{empty_value}}); |
| 122 } | 122 } |
| 123 static void constructDeletedValue({{enum_name}}& slot, bool) { | 123 static void ConstructDeletedValue({{enum_name}}& slot, bool) { |
| 124 slot = static_cast<{{enum_name}}>({{deleted_value}}); | 124 slot = static_cast<{{enum_name}}>({{deleted_value}}); |
| 125 } | 125 } |
| 126 static bool isDeletedValue(const {{enum_name}}& value) { | 126 static bool IsDeletedValue(const {{enum_name}}& value) { |
| 127 return value == static_cast<{{enum_name}}>({{deleted_value}}); | 127 return value == static_cast<{{enum_name}}>({{deleted_value}}); |
| 128 } | 128 } |
| 129 }; | 129 }; |
| 130 } // namespace WTF | 130 } // namespace WTF |
| 131 {%- endmacro %} | 131 {%- endmacro %} |
| OLD | NEW |