| OLD | NEW |
| 1 {%- set class_name = union.name ~ "_Data" -%} | 1 {%- set class_name = union.name ~ "_Data" -%} |
| 2 {%- set enum_name = union.name ~ "_Tag" -%} | 2 {%- set enum_name = union.name ~ "_Tag" -%} |
| 3 {%- import "struct_macros.tmpl" as struct_macros %} | 3 {%- import "struct_macros.tmpl" as struct_macros %} |
| 4 | 4 |
| 5 class {{class_name}} { | 5 class {{class_name}} { |
| 6 public: | 6 public: |
| 7 // Used to identify Mojom Union Data Classes. | 7 // Used to identify Mojom Union Data Classes. |
| 8 typedef void MojomUnionDataType; | 8 typedef void MojomUnionDataType; |
| 9 static {{class_name}}* New(mojo::internal::Buffer* buf); | 9 static {{class_name}}* New(mojo::internal::Buffer* buf); |
| 10 {{class_name}}(); | 10 {{class_name}}(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 {% for field in union.fields %} | 25 {% for field in union.fields %} |
| 26 {{field.name|upper}}, | 26 {{field.name|upper}}, |
| 27 {%- endfor %} | 27 {%- endfor %} |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 // A note on layout: | 30 // A note on layout: |
| 31 // "Each non-static data member is allocated as if it were the sole member of | 31 // "Each non-static data member is allocated as if it were the sole member of |
| 32 // a struct." - Section 9.5.2 ISO/IEC 14882:2011 (The C++ Spec) | 32 // a struct." - Section 9.5.2 ISO/IEC 14882:2011 (The C++ Spec) |
| 33 union MOJO_ALIGNAS(8) Union_ { | 33 union MOJO_ALIGNAS(8) Union_ { |
| 34 {%- for field in union.fields %} | 34 {%- for field in union.fields %} |
| 35 {%- if field.kind|is_string_kind or field.kind|is_struct_kind %} | 35 {%- if field.kind|is_object_kind %} |
| 36 uint64_t f_{{field.name}}; | 36 uint64_t f_{{field.name}}; |
| 37 {%- elif field.kind.spec == 'b' %} | 37 {%- elif field.kind.spec == 'b' %} |
| 38 uint8_t f_{{field.name}} : 1; | 38 uint8_t f_{{field.name}} : 1; |
| 39 {%- elif field.kind|is_enum_kind %} | 39 {%- elif field.kind|is_enum_kind %} |
| 40 int32_t f_{{field.name}}; | 40 int32_t f_{{field.name}}; |
| 41 {%- else %} | 41 {%- else %} |
| 42 {{field.kind|cpp_pod_type}} f_{{field.name}}; | 42 {{field.kind|cpp_pod_type}} f_{{field.name}}; |
| 43 {%- endif %} | 43 {%- endif %} |
| 44 {%- endfor %} | 44 {%- endfor %} |
| 45 uint64_t unknown; | 45 uint64_t unknown; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 uint32_t size; | 48 uint32_t size; |
| 49 {{enum_name}} tag; | 49 {{enum_name}} tag; |
| 50 Union_ data; | 50 Union_ data; |
| 51 | 51 |
| 52 void EncodePointersAndHandles(std::vector<mojo::Handle>* handles); | 52 void EncodePointersAndHandles(std::vector<mojo::Handle>* handles); |
| 53 void DecodePointersAndHandles(std::vector<mojo::Handle>* handles); | 53 void DecodePointersAndHandles(std::vector<mojo::Handle>* handles); |
| 54 }; | 54 }; |
| 55 static_assert(sizeof({{class_name}}) == 16, | 55 static_assert(sizeof({{class_name}}) == 16, |
| 56 "Bad sizeof({{class_name}})"); | 56 "Bad sizeof({{class_name}})"); |
| 57 static_assert(sizeof({{class_name}}::Union_) == 8, | 57 static_assert(sizeof({{class_name}}::Union_) == 8, |
| 58 "Bad sizeof({{class_name}}::Union_)"); | 58 "Bad sizeof({{class_name}}::Union_)"); |
| OLD | NEW |