| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 71 }; | 71 }; | 
| 72 {%- endmacro %} | 72 {%- endmacro %} | 
| 73 | 73 | 
| 74 {%- macro enum_hash(enum) %} | 74 {%- macro enum_hash(enum) %} | 
| 75 {%-   set enum_name = enum|get_qualified_name_for_kind( | 75 {%-   set enum_name = enum|get_qualified_name_for_kind( | 
| 76           flatten_nested_kind=True) %} | 76           flatten_nested_kind=True) %} | 
| 77 template <> | 77 template <> | 
| 78 struct hash<{{enum_name}}> | 78 struct hash<{{enum_name}}> | 
| 79     : public mojo::internal::EnumHashImpl<{{enum_name}}> {}; | 79     : public mojo::internal::EnumHashImpl<{{enum_name}}> {}; | 
| 80 {%- endmacro %} | 80 {%- endmacro %} | 
|  | 81 | 
|  | 82 {%- macro enum_hash_blink(enum) %} | 
|  | 83 {%-   set enum_name = enum|get_qualified_name_for_kind( | 
|  | 84           flatten_nested_kind=True, include_variant=False) %} | 
|  | 85 {%-   set hash_fn_name = enum|wtf_hash_fn_name_for_enum %} | 
|  | 86 {#    We need two unused enum values: #} | 
|  | 87 {%-   set empty_value = -1000000 %} | 
|  | 88 {%-   set deleted_value = -1000001 %} | 
|  | 89 {%-   set empty_value_unused = "false" if empty_value in enum|all_enum_values el
     se "true" %} | 
|  | 90 {%-   set deleted_value_unused = "false" if empty_value in enum|all_enum_values 
     else "true" %} | 
|  | 91 namespace WTF { | 
|  | 92 struct {{hash_fn_name}} { | 
|  | 93   static unsigned hash(const {{enum_name}}& value) { | 
|  | 94     typedef base::underlying_type<{{enum_name}}>::type utype; | 
|  | 95     return DefaultHash<utype>::Hash().hash(static_cast<utype>(value)); | 
|  | 96   } | 
|  | 97   static bool equal(const {{enum_name}}& left, const {{enum_name}}& right) { | 
|  | 98     return left == right; | 
|  | 99   } | 
|  | 100   static const bool safeToCompareToEmptyOrDeleted = true; | 
|  | 101 }; | 
|  | 102 | 
|  | 103 template <> | 
|  | 104 struct DefaultHash<{{enum_name}}> { | 
|  | 105   using Hash = {{hash_fn_name}}; | 
|  | 106 }; | 
|  | 107 | 
|  | 108 template <> | 
|  | 109 struct HashTraits<{{enum_name}}> | 
|  | 110     : public GenericHashTraits<{{enum_name}}> { | 
|  | 111   static_assert({{empty_value_unused}}, | 
|  | 112                 "{{empty_value}} is a reserved enum value"); | 
|  | 113   static_assert({{deleted_value_unused}}, | 
|  | 114                 "{{deleted_value}} is a reserved enum value"); | 
|  | 115   static const bool hasIsEmptyValueFunction = true; | 
|  | 116   static bool isEmptyValue(const {{enum_name}}& value) { | 
|  | 117     return value == static_cast<{{enum_name}}>({{empty_value}}); | 
|  | 118   } | 
|  | 119   static void constructDeletedValue({{enum_name}}& slot, bool) { | 
|  | 120     slot = static_cast<{{enum_name}}>({{deleted_value}}); | 
|  | 121   } | 
|  | 122   static bool isDeletedValue(const {{enum_name}}& value) { | 
|  | 123     return value == static_cast<{{enum_name}}>({{deleted_value}}); | 
|  | 124   } | 
|  | 125 }; | 
|  | 126 }  // namespace WTF | 
|  | 127 {%- endmacro %} | 
| OLD | NEW | 
|---|