OLD | NEW |
1 {%- import "validation_macros.tmpl" as validation_macros %} | 1 {%- import "validation_macros.tmpl" as validation_macros %} |
2 {%- set class_name = union.name ~ "_Data" %} | 2 {%- set class_name = union.name ~ "_Data" %} |
3 {%- set enum_name = union.name ~ "_Tag" -%} | 3 {%- set enum_name = union.name ~ "_Tag" -%} |
4 | 4 |
5 // static | 5 // static |
6 {{class_name}}* {{class_name}}::New(mojo::internal::Buffer* buf) { | 6 {{class_name}}* {{class_name}}::New(mojo::internal::Buffer* buf) { |
7 return new (buf->Allocate(sizeof({{class_name}}))) {{class_name}}(); | 7 return new (buf->Allocate(sizeof({{class_name}}))) {{class_name}}(); |
8 } | 8 } |
9 | 9 |
10 // static | 10 // static |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 // If the union is inlined in another structure its memory was already claimed
. | 23 // If the union is inlined in another structure its memory was already claimed
. |
24 // This ONLY applies to the union itself, NOT anything which the union points | 24 // This ONLY applies to the union itself, NOT anything which the union points |
25 // to. | 25 // to. |
26 if (!inlined && !bounds_checker->ClaimMemory(data, sizeof({{class_name}}))) { | 26 if (!inlined && !bounds_checker->ClaimMemory(data, sizeof({{class_name}}))) { |
27 ReportValidationError( | 27 ReportValidationError( |
28 mojo::internal::VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE); | 28 mojo::internal::VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE); |
29 return false; | 29 return false; |
30 } | 30 } |
31 const {{class_name}}* object = static_cast<const {{class_name}}*>(data); | 31 const {{class_name}}* object = static_cast<const {{class_name}}*>(data); |
32 MOJO_ALLOW_UNUSED_LOCAL(object); | 32 ALLOW_UNUSED_LOCAL(object); |
33 | 33 |
34 switch (object->tag) { | 34 switch (object->tag) { |
35 {% for field in union.fields %} | 35 {% for field in union.fields %} |
36 case {{enum_name}}::{{field.name|upper}}: { | 36 case {{enum_name}}::{{field.name|upper}}: { |
37 {{ validation_macros.validate_union_field(field, union)|indent(6) }} | 37 {{ validation_macros.validate_union_field(field, union)|indent(6) }} |
38 } | 38 } |
39 {%- endfor %} | 39 {%- endfor %} |
40 default: { | 40 default: { |
41 ReportValidationError( | 41 ReportValidationError( |
42 mojo::internal::VALIDATION_ERROR_UNKNOWN_UNION_TAG, | 42 mojo::internal::VALIDATION_ERROR_UNKNOWN_UNION_TAG, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 {%- elif field.kind|is_interface_kind %} | 87 {%- elif field.kind|is_interface_kind %} |
88 mojo::internal::DecodeHandle( | 88 mojo::internal::DecodeHandle( |
89 reinterpret_cast<mojo::internal::Interface_Data*>( | 89 reinterpret_cast<mojo::internal::Interface_Data*>( |
90 &data.f_{{field.name}}), handles); | 90 &data.f_{{field.name}}), handles); |
91 {%- endif %} | 91 {%- endif %} |
92 return; | 92 return; |
93 } | 93 } |
94 {%- endfor %} | 94 {%- endfor %} |
95 } | 95 } |
96 } | 96 } |
OLD | NEW |