Index: mojo/public/tools/bindings/generators/dart_templates/mojom_type_macros.tmpl |
diff --git a/mojo/public/tools/bindings/generators/dart_templates/mojom_type_macros.tmpl b/mojo/public/tools/bindings/generators/dart_templates/mojom_type_macros.tmpl |
new file mode 100644 |
index 0000000000000000000000000000000000000000..199dfced50339befd89b044bf6f139ee4257f057 |
--- /dev/null |
+++ b/mojo/public/tools/bindings/generators/dart_templates/mojom_type_macros.tmpl |
@@ -0,0 +1,166 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+{%- macro writeMojomTypeDef(type, typepkg, pkg) -%} |
+{%- if should_gen_mojom_types -%} |
+{%- if type|is_enum_kind -%} |
+{{typepkg}}MojomEnum {{type|mojom_type_identifier}}() { |
+ return {{ writeMojomType(type, typepkg, pkg) }}; |
+} |
+{%- elif type|is_struct_kind -%} |
+{{typepkg}}MojomStruct {{type|mojom_type_identifier}}() { |
+ return {{ writeMojomType(type, typepkg, pkg) }}; |
+} |
+{%- elif type|is_union_kind -%} |
+{{typepkg}}MojomUnion {{type|mojom_type_identifier}}() { |
+ return {{ writeMojomType(type, typepkg, pkg) }}; |
+} |
+{%- elif type|is_interface_kind -%} |
+{{typepkg}}MojomInterface {{type|mojom_type_identifier}}() { |
+ return new {{typepkg}}MojomInterface() |
+ ..declData = (new {{typepkg}}DeclarationData()..shortName = "{{type|name}}") |
+ ..interfaceName = "{{type|name}}" |
+ ..methods = <int, {{typepkg}}MojomMethod>{ |
+{% for method in type.methods -%} |
+ k{{type|name}}_{{method|name}}_name: new {{typepkg}}MojomMethod() |
+ ..declData = (new {{typepkg}}DeclarationData()..shortName = "{{method|name|upper_camel}}") |
+ ..ordinal = k{{type|name}}_{{method|name}}_name |
+{%- if method.response_parameters != None %} |
+ ..responseParams = {{method.response_param_struct|mojom_type_identifier}}() |
+{%- endif -%} |
+ ..parameters = {{method.param_struct|mojom_type_identifier}}(), |
+{%- endfor %} |
+ }; |
+} |
+ |
+{%- else -%} |
+BAD TYPE NAME GIVEN |
+{%- endif -%} |
+{%- endif -%} |
+{%- endmacro -%} |
+ |
+ |
+{%- macro writeMojomType(type, typepkg, pkg, topLevel=true) -%} |
+{%- if type|identifier|identifier_check('WriteMojomType') -%} {#- Already printed out -#} |
+{{writeTypeTypeReference(type, typepkg, pkg)}} |
+{%- else -%} |
+ |
+{%- if type|mojom_type_value(typepkg) != "" -%}{#- simple kind case -#} |
+ {{type|mojom_type_value(typepkg)}} |
+{%- elif type|is_array_kind -%} |
+ {{writeTypeArrayType(type, typepkg, pkg)}} |
+{%- elif type|is_map_kind -%} |
+ {{writeTypeMapType(type, typepkg, pkg)}} |
+{%- elif type|is_enum_kind or type|is_struct_kind or type|is_union_kind -%} |
+ {%- if topLevel -%} |
+ {{- type|identifier|identifier_store('WriteMojomType') -}} |
+ {%- if type|is_enum_kind -%} |
+ {{writeMojomEnumType(type, typepkg, pkg)}} |
+ {%- elif type|is_struct_kind -%} |
+ {{writeMojomStructType(type, typepkg, pkg)}} |
+ {%- else -%} {#- Must be a union -#} |
+ {{writeMojomUnionType(type, typepkg, pkg)}} |
+ {%- endif -%} |
+ {%- else -%} |
+ {{writeTypeTypeReference(type, typepkg, pkg)}} |
+ {%- endif -%} |
+{%- elif type|is_interface_kind or type|is_interface_request_kind -%} |
+ {{- type|identifier|identifier_store('WriteMojomType') -}} |
+ {{writeTypeTypeReference(type, typepkg, pkg)}} |
+{%- else -%} |
+ ERROR: UNSUPPORTED TYPE |
+{%- endif -%} |
+ |
+{%- endif -%} |
+{%- endmacro -%} |
+ |
+ |
+{%- macro writeTypeArrayType(type, typepkg, pkg) -%} |
+ new {{typepkg}}Type()..arrayType = (new {{typepkg}}ArrayType() |
+ {%- if type|is_nullable_kind %} |
+ ..nullable = true |
+ {% endif -%} |
+ {%- if type.length is not none -%} |
+ ..fixedLength = {{type.length}} |
+ {%- endif %} |
+ ..elementType = ({{writeMojomType(type.kind, typepkg, pkg, false)}})) |
+{%- endmacro -%} |
+ |
+{%- macro writeTypeMapType(type, typepkg, pkg) -%} |
+ new {{typepkg}}Type()..mapType = (new {{typepkg}}MapType() |
+ {%- if type|is_nullable_kind %} |
+ ..nullable = true |
+ {% endif %} |
+ ..keyType = ({{writeMojomType(type.key_kind, typepkg, pkg, false)}}) |
+ ..valueType = ({{writeMojomType(type.value_kind, typepkg, pkg, false)}})) |
+{%- endmacro -%} |
+ |
+{%- macro writeMojomEnumType(type, typepkg, pkg) -%} |
+ new {{typepkg}}MojomEnum() |
+ ..declData = (new {{typepkg}}DeclarationData()..shortName = "{{type|name}}") |
+ ..values = <{{typepkg}}EnumValue>[ |
+ {%- for field in type.fields -%} |
+ new {{typepkg}}EnumValue() |
+ ..declData = (new {{typepkg}}DeclarationData()..shortName = "{{field|name}}") |
+ ..enumTypeKey = {{writePackagedTypeID(type)}} |
+ ..intValue = {{field.numeric_value}}, |
+ {%- endfor -%} |
+ ] |
+{%- endmacro -%} |
+ |
+ |
+{%- macro writeTypeTypeReference(type, typepkg, pkg) -%} |
+ new {{typepkg}}Type() |
+ ..typeReference = ({{writeTypeReference(type, typepkg, pkg)}}) |
+{%- endmacro -%} |
+ |
+{%- macro writeTypeReference(type, typepkg, pkg) -%} |
+ new {{typepkg}}TypeReference() |
+ {%- if type|is_nullable_kind %} |
+ ..nullable = true |
+ {% endif %} |
+ {% if type|is_interface_request_kind %}{# Interface request collapses to interface. #} |
+ ..isInterfaceRequest = true |
+ ..identifier = {{writePackagedTypeID(type.kind)}} |
+ ..typeKey = {{writePackagedTypeID(type.kind)}} |
+ {% else %} |
+ ..identifier = {{writePackagedTypeID(type)}} |
+ ..typeKey = {{writePackagedTypeID(type)}} |
+ {% endif -%} |
+{%- endmacro -%} |
+ |
+{%- macro writePackagedTypeID(type) -%} |
+ '{{type|mojom_type_identifier}}' |
+{%- endmacro -%} |
+ |
+{%- macro writeMojomStructType(type, typepkg, pkg) -%} |
+ new {{typepkg}}MojomStruct() |
+ ..declData = (new {{typepkg}}DeclarationData()..shortName = '{{type|name}}') |
+ {%- if type|is_nullable_kind %} |
+ ..nullable = true |
+ {% endif %} |
+ ..fields = <{{typepkg}}StructField>[ |
+ {%- for field in type.fields %} |
+ new {{typepkg}}StructField() |
+ ..declData = (new {{typepkg}}DeclarationData()..shortName = '{{field|name|upper_camel}}') |
+ ..type = ({{writeMojomType(field.kind, typepkg, pkg, false)}}), |
+ {% endfor -%} |
+ ] |
+{%- endmacro -%} |
+ |
+{%- macro writeMojomUnionType(type, typepkg, pkg) -%} |
+ new {{typepkg}}MojomUnion() |
+ ..declData = (new {{typepkg}}DeclarationData()..shortName = '{{type|name}}') |
+ {%- if type|is_nullable_kind %} |
+ ..nullable = true |
+ {% endif %} |
+ ..fields = <{{typepkg}}UnionField>[ |
+ {%- for field in type.fields %} |
+ new {{typepkg}}UnionField() |
+ ..declData = (new {{typepkg}}DeclarationData()..shortName = '{{field|name|upper_camel}}') |
+ ..type = ({{writeMojomType(field.kind, typepkg, pkg, false)}}) |
+ ..tag = {{field.ordinal}}, |
+ {% endfor -%} |
+ ] |
+{%- endmacro -%} |