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

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

Issue 814543006: Move //mojo/{public, edk} underneath //third_party (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 11 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/struct_definition.tmpl
diff --git a/mojo/public/tools/bindings/generators/dart_templates/struct_definition.tmpl b/mojo/public/tools/bindings/generators/dart_templates/struct_definition.tmpl
deleted file mode 100644
index f5b62a9eeb285e21a05f30faa3060d0cd72071e7..0000000000000000000000000000000000000000
--- a/mojo/public/tools/bindings/generators/dart_templates/struct_definition.tmpl
+++ /dev/null
@@ -1,136 +0,0 @@
-{#--- Begin #}
-
-{%- macro encode(variable, kind, offset, bit, level=0, check_for_null=True) %}
-{%- if kind|is_pointer_array_kind %}
-{%- set sub_kind = kind.kind %}
-{%- if check_for_null %}
-if ({{variable}} == null) {
- encoder{{level}}.encodeNullPointer({{offset}}, {{kind|is_nullable_kind|dart_true_false}});
-} else {
-{%- else %}
-{
-{%- endif %}
- var encoder{{level + 1}} = encoder{{level}}.encodePointerArray({{variable}}.length, {{offset}}, {{kind|array_expected_length}});
- for (int i{{level}} = 0; i{{level}} < {{variable}}.length; ++i{{level}}) {
- {{encode(variable~'[i'~level~']', sub_kind, 'bindings.DataHeader.kHeaderSize + bindings.kPointerSize * i'~level, 0, level+1)|indent(4)}}
- }
-}
-{%- elif kind|is_map_kind %}
-if ({{variable}} == null) {
- encoder{{level}}.encodeNullPointer({{offset}}, {{kind|is_nullable_kind|dart_true_false}});
-} else {
- var encoder{{level + 1}} = encoder{{level}}.encoderForMap({{offset}});
- int size{{level}} = {{variable}}.length;
- var keys{{level}} = {{variable}}.keys.toList();
- var values{{level}} = {{variable}}.values.toList();
- {{encode('keys'~level, kind.key_kind|array, 'bindings.DataHeader.kHeaderSize', 0, level+1, False)|indent(2)}}
- {{encode('values'~level, kind.value_kind|array, 'bindings.DataHeader.kHeaderSize + bindings.kPointerSize', 0, level+1, False)|indent(2)}}
-}
-{%- else %}
-encoder{{level}}.{{kind|encode_method(variable, offset, bit)}};
-{%- endif %}
-{%- endmacro %}
-
-
-{%- macro decode(variable, kind, offset, bit, level=0) %}
-{%- if kind|is_struct_kind or kind|is_pointer_array_kind or kind|is_map_kind %}
-var decoder{{level+1}} = decoder{{level}}.decodePointer({{offset}}, {{kind|is_nullable_kind|dart_true_false}});
-{%- if kind|is_struct_kind %}
-{{variable}} = {{kind|dart_type}}.decode(decoder{{level+1}});
-{%- else %}{# kind|is_pointer_array_kind or is_map_kind #}
-{%- if kind|is_nullable_kind %}
-if (decoder{{level+1}} == null) {
- {{variable}} = null;
-} else {
-{%- else %}
-{
-{%- endif %}
-{%- if kind|is_map_kind %}
- decoder{{level+1}}.decodeDataHeaderForMap();
- List<{{kind.key_kind|dart_type}}> keys{{level}};
- List<{{kind.value_kind|dart_type}}> values{{level}};
- {
- {{decode('keys'~level, kind.key_kind|array, 'DataHeader.HEADER_SIZE', 0, level+1)|indent(4)}}
- }
- {
- {{decode('values'~level, kind.value_kind|array('keys'~level~'.length'), 'bindings.DataHeader.kHeaderSize + bindings.kPointerSize', 0, level+1)|indent(4)}}
- }
- {{variable}} = new Map<{{kind.key_kind|dart_type}}, {{kind.value_kind|dart_type}}>.fromIterables(keys, values);
-{%- else %}
- var si{{level+1}} = decoder{{level+1}}.decodeDataHeaderForPointerArray({{kind|array_expected_length}});
- {{variable}} = new {{kind|dart_type}}(si{{level+1}}.numFields);
- for (int i{{level+1}} = 0; i{{level+1}} < si{{level+1}}.numFields; ++i{{level+1}}) {
- {{decode(variable~'[i'~(level+1)~']', kind.kind, 'bindings.DataHeader.kHeaderSize + bindings.kPointerSize * i'~(level+1), 0, level+1)|indent(4)}}
- }
-{%- endif %}
-}
-{%- endif %}
-{%- else %}
-{{variable}} = decoder{{level}}.{{kind|decode_method(offset, bit)}};
-{%- endif %}
-{%- endmacro %}
-
-
-{%- macro struct_def(struct) %}
-class {{struct|name}} extends bindings.Struct {
- static const int kStructSize = {{struct.packed|struct_size}};
- static const bindings.DataHeader kDefaultStructInfo =
- const bindings.DataHeader(kStructSize, {{struct.packed.packed_fields|length}});
-
-{#--- Enums #}
-{%- from "enum_definition.tmpl" import enum_def %}
-{%- for enum in struct.enums %}
- {{enum_def(" static ", enum)}}
-{%- endfor %}
-
-
-{#--- Constants #}
-{%- for constant in struct.constants %}
- static final {{constant.name}} = {{constant.value|expression_to_text}};
-{%- endfor %}
-
-{#--- initDefaults() #}
-{%- for packed_field in struct.packed.packed_fields %}
- {{packed_field.field.kind|dart_type}} {{packed_field.field|name}} = {{packed_field.field|default_value}};
-{%- endfor %}
-
- {{struct|name}}() : super(kStructSize);
-
- static {{struct|name}} deserialize(bindings.Message message) {
- return decode(new bindings.Decoder(message));
- }
-
- static {{struct|name}} decode(bindings.Decoder decoder0) {
- if (decoder0 == null) {
- return null;
- }
- {{struct|name}} result = new {{struct|name}}();
-{%- if not struct.bytes %}
- decoder0.decodeDataHeader();
-{%- else %}
- var mainDataHeader = decoder0.decodeDataHeader();
-{%- endif %}
-{%- for byte in struct.bytes %}
-{%- for packed_field in byte.packed_fields %}
- if (mainDataHeader.numFields > {{packed_field.ordinal}}) {
- {{decode('result.' ~ packed_field.field|name, packed_field.field.kind, 8+packed_field.offset, packed_field.bit)|indent(6)}}
- }
-{%- endfor %}
-{%- endfor %}
- return result;
- }
-
- void encode(bindings.Encoder encoder) {
-{%- if not struct.bytes %}
- encoder.getEncoderAtOffset(kDefaultStructInfo);
-{%- else %}
- var encoder0 = encoder.getEncoderAtOffset(kDefaultStructInfo);
-{%- endif %}
-{%- for byte in struct.bytes %}
-{%- for packed_field in byte.packed_fields %}
- {{encode(packed_field.field|name, packed_field.field.kind, 8+packed_field.offset, packed_field.bit)|indent(4)}}
-{%- endfor %}
-{%- endfor %}
- }
-}
-{%- endmacro %}

Powered by Google App Engine
This is Rietveld 408576698