Chromium Code Reviews| 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..da46cb8f211906f26242b3a744d6278483ecbc26 |
| --- /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}}' |
| + ..fullIdentifier = '{{type|fullidentifier}}') |
| + ..interfaceName = '{{type|name}}' |
| + ..methods = <int, {{typepkg}}MojomMethod>{ |
| +{% for method in type.methods -%} |
| + _{{type|name}}_{{method|name}}Name: new {{typepkg}}MojomMethod() |
| + ..declData = (new {{typepkg}}DeclarationData()..shortName = '{{method|name|upper_camel}}') |
|
zra
2016/01/15 21:01:34
Usually we don't have much control over line lengt
zra
2016/01/15 23:33:17
So, method|name can do arbitrary things to make me
alexfandrianto
2016/01/15 23:49:00
While Mojo does do method matching based on index,
alexfandrianto
2016/01/20 00:08:29
Done.
|
| + ..ordinal = _{{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 -%} |
| + {{ raise("Bad type name given") }} |
|
zra
2016/01/15 21:01:34
Maybe append the name that was bad here.
alexfandrianto
2016/01/20 00:08:29
Done.
|
| +{%- endif -%} |
| +{%- endif -%} |
| +{%- endmacro -%} |
| + |
| + |
| +{%- macro writeMojomType(type, typepkg, pkg, topLevel=true) -%} |
| +{%- 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 -%} |
| + {%- 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 -%} |
| + {{writeTypeTypeReference(type, typepkg, pkg)}} |
| +{%- else -%} |
| + {{ raise("Unsupported type") }} |
|
zra
2016/01/15 21:01:34
Maybe append the type here.
alexfandrianto
2016/01/20 00:08:29
Done.
|
| +{%- 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}}' |
| + ..fullIdentifier = '{{type|fullidentifier}}') |
| + ..values = <{{typepkg}}EnumValue>[ |
| + {%- for field in type.fields -%} |
| + new {{typepkg}}EnumValue() |
| + ..declData = (new {{typepkg}}DeclarationData()..shortName = '{{field|name|upper_camel}}') |
|
zra
2016/01/15 21:01:34
ditto re upper_camel.
|
| + ..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}}' |
| + ..fullIdentifier = '{{type|fullidentifier}}') |
| + {%- 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}}') |
|
zra
2016/01/15 21:01:34
ditto
|
| + ..type = ({{writeMojomType(field.kind, typepkg, pkg, false)}}), |
| + {% endfor -%} |
| + ] |
| +{%- endmacro -%} |
| + |
| +{%- macro writeMojomUnionType(type, typepkg, pkg) -%} |
| + new {{typepkg}}MojomUnion() |
| + ..declData = (new {{typepkg}}DeclarationData() |
| + ..shortName = '{{type|name}}' |
| + ..fullIdentifier = '{{type|fullidentifier}}') |
| + {%- 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}}') |
|
zra
2016/01/15 21:01:34
ditto
|
| + ..type = ({{writeMojomType(field.kind, typepkg, pkg, false)}}) |
| + ..tag = {{field.ordinal}}, |
| + {% endfor -%} |
| + ] |
| +{%- endmacro -%} |