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

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

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 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: mojo/public/tools/bindings/generators/dart_templates/union_definition.tmpl
diff --git a/mojo/public/tools/bindings/generators/dart_templates/union_definition.tmpl b/mojo/public/tools/bindings/generators/dart_templates/union_definition.tmpl
deleted file mode 100644
index 8c1754c66648c33c1da0f2c0b0a0d377bac05e54..0000000000000000000000000000000000000000
--- a/mojo/public/tools/bindings/generators/dart_templates/union_definition.tmpl
+++ /dev/null
@@ -1,114 +0,0 @@
-{#--- Begin #}
-
-{%- import "encoding_macros.tmpl" as encoding_macros %}
-{%- macro enum_def(union) %}
-enum {{union|name}}Tag {
-{%- for field in union.fields %}
- {{field|name}},
-{%- endfor %}
- unknown
-}
-{%- endmacro %}
-
-{%- macro wrapper_def(union) %}
-class {{union|name}} extends bindings.Union {
- static final _tagToInt = const {
-{%- for field in union.fields %}
- {{union|name}}Tag.{{field|name}}: {{field.ordinal}},
-{%- endfor %}
- };
-
- static final _intToTag = const {
-{%- for field in union.fields %}
- {{field.ordinal}}: {{union|name}}Tag.{{field|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|name}}) {
- throw new bindings.UnsetUnionTagError(_tag, {{union|name}}Tag.{{field|name}});
- }
- return _data;
- }
-
- set {{field|name}}({{field.kind|dart_type}} value) {
- _tag = {{union|name}}Tag.{{field|name}};
- _data = value;
- }
-{%- endfor %}
-
- static {{union|name}} decode(bindings.Decoder decoder0, int offset) {
- int size = decoder0.decodeUint32(offset);
- if (size == 0) {
- return null;
- }
- {{union|name}} result = new {{union|name}}();
-
- {# Unknown union members not handled. #}
- {{union|name}}Tag tag = _intToTag[decoder0.decodeUint32(offset + 4)];
- switch (tag) {
-{%- for field in union.fields %}
- case {{union|name}}Tag.{{field|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 %}
- default:
- throw new bindings.MojoCodecError("Bad union tag: $tag");
- }
-
- 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(_tagToInt[_tag], offset + 4);
- switch (_tag) {
-{%- for field in union.fields %}
- case {{union|name}}Tag.{{field|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 %}
- default:
- throw new bindings.MojoCodecError("Bad union tag: $_tag");
- }
- }
-
- String toString() {
- String result = "{{union|name}}(";
- switch (_tag) {
-{%- for field in union.fields %}
- case {{union|name}}Tag.{{field|name}}:
- result += "{{field|name}}";
- break;
-{%- endfor %}
- default:
- result += "unknown";
- }
- result += ": $_data)";
- return result;
- }
-}
-{%- endmacro %}
-
-
-{%- macro union_def(union, typepkg, package) %}
-{{enum_def(union)}}
-{{wrapper_def(union)}}
-
-{%- endmacro %}

Powered by Google App Engine
This is Rietveld 408576698