Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Unified Diff: third_party/mojo/src/mojo/public/tools/bindings/generators/dart_templates/union_definition.tmpl

Issue 1179733005: Update mojo sdk to rev bdbb0c7e396fc4044a8b194058d7a7e529715286 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update CommandBufferImpl (Binding::OnConnectionError is no more) Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/mojo/src/mojo/public/tools/bindings/generators/dart_templates/union_definition.tmpl
diff --git a/third_party/mojo/src/mojo/public/tools/bindings/generators/dart_templates/union_definition.tmpl b/third_party/mojo/src/mojo/public/tools/bindings/generators/dart_templates/union_definition.tmpl
new file mode 100644
index 0000000000000000000000000000000000000000..b4a74207a5d5bfb1ced36c414878dd996935d57e
--- /dev/null
+++ b/third_party/mojo/src/mojo/public/tools/bindings/generators/dart_templates/union_definition.tmpl
@@ -0,0 +1,109 @@
+{#--- Begin #}
+
+{%- import "encoding_macros.tmpl" as encoding_macros %}
+
+{%- macro enum_def(union) %}
+enum {{union|name}}Tag {
+{%- for field in union.fields %}
+ {{field|tag_name}},
+{%- endfor %}
+ unknown
+}
+{%- endmacro %}
+
+{%- macro wrapper_def(union) %}
+class {{union|name}}Wrapper extends bindings.Union {
+ static final _tag_to_int = const {
+{%- for field in union.fields %}
+ {{union|name}}Tag.{{field|tag_name}}: {{field.ordinal}},
+{%- endfor %}
+ };
+
+ static final _int_to_tag = const {
+{%- for field in union.fields %}
+ {{field.ordinal}}: {{union|name}}Tag.{{field|tag_name}},
+{%- endfor %}
+ };
+
+ var _data;
+ {{union|name}}Tag _tag = {{union|name}}Tag.unknown;
+
+ {{union|name}}Tag get tag => _tag;
+
+{%- for field in union.fields %}
+ {{field.kind|dart_type}} get {{field|name}} {
+ if (_tag != {{union|name}}Tag.{{field|tag_name}}) {
+ throw new bindings.UnsetUnionTagError(_tag, {{union|name}}Tag.{{field|tag_name}});
+ }
+ return _data;
+ }
+
+ set {{field|name}}({{field.kind|dart_type}} value) {
+ _tag = {{union|name}}Tag.{{field|tag_name}};
+ _data = value;
+ }
+{%- endfor %}
+
+ static {{union|name}}Wrapper decode(bindings.Decoder decoder0, int offset) {
+ int size = decoder0.decodeUint32(offset);
+ if (size == 0) {
+ return null;
+ }
+ {{union|name}}Wrapper result = new {{union|name}}Wrapper();
+
+ // TODO(azani): Handle unknown union member.
+ {{union|name}}Tag tag = _int_to_tag[decoder0.decodeUint32(offset + 4)];
+ switch (tag) {
+{%- for field in union.fields %}
+ case {{union|name}}Tag.{{field|tag_name}}:
+{%- if field.kind|is_union_kind %}
+ var decoder1 = decoder0.decodePointer(offset + 8, {{field.kind|is_nullable_kind|dart_true_false}});
+ result.{{field|name}} = {{field.kind|dart_type}}.decode(decoder1, 0);
+{%- else %}
+ {{encoding_macros.decode('result.' ~ field|name, field.kind, "offset + 8", 0)|indent(8)}}
+{%- endif %}
+ break;
+{%- endfor %}
+ }
+
+ return result;
+ }
+
+ void encode(bindings.Encoder encoder0, int offset) {
+ // TODO(azani): Error when trying to encode an unknown member.
+ encoder0.encodeUint32(16, offset);
+ encoder0.encodeUint32(_tag_to_int[_tag], offset + 4);
+ switch (_tag) {
+{%- for field in union.fields %}
+ case {{union|name}}Tag.{{field|tag_name}}:
+{%- if field.kind|is_union_kind %}
+ encoder0.encodeNestedUnion({{field|name}}, offset + 8, {{field.kind|is_nullable_kind|dart_true_false}});
+{%- else %}
+ {{encoding_macros.encode(field|name, field.kind, "offset + 8", 0)|indent(8)}}
+{%- endif %}
+ break;
+{%- endfor %}
+ }
+ }
+
+ String toString() {
+ String result = "{{union|name}}Wrapper(";
+ switch (_tag) {
+{%- for field in union.fields %}
+ case {{union|name}}Tag.{{field|tag_name}}:
+ result += "{{field|name}}";
+ break;
+{%- endfor %}
+ default:
+ result += "unknown";
+ }
+ result += ": $_data)"
+ }
+}
+{%- endmacro %}
+
+
+{%- macro union_def(union) %}
+{{enum_def(union)}}
+{{wrapper_def(union)}}
+{%- endmacro %}

Powered by Google App Engine
This is Rietveld 408576698