| Index: mojo/public/tools/bindings/generators/go_templates/mojom_type_macros.tmpl
|
| diff --git a/mojo/public/tools/bindings/generators/go_templates/mojom_type_macros.tmpl b/mojo/public/tools/bindings/generators/go_templates/mojom_type_macros.tmpl
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9841a3bf4d5fda7f45f016ac920e8e7ff24354f0
|
| --- /dev/null
|
| +++ b/mojo/public/tools/bindings/generators/go_templates/mojom_type_macros.tmpl
|
| @@ -0,0 +1,144 @@
|
| +// 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.
|
| +
|
| +{% import "mojom_util_macros.tmpl" as util %}
|
| +
|
| +{%- macro writeMojomType(typepkg, t, pkg, exported=true, topLevel=true) -%}
|
| +{%- if t|identifier(pkg)|identifier_check('WriteMojomType') -%} {#- Already printed out -#}
|
| +{{writeTypeTypeReference(typepkg, t, pkg)}}
|
| +{%- else -%}
|
| +
|
| +{%- if t|mojom_type(typepkg) != "" -%}{#- simple kind case -#}
|
| + &{{t|mojom_type(typepkg)}}
|
| +{%- elif t|is_array -%}
|
| + &{{typepkg}}TypeArrayType{
|
| + Value: {{typepkg}}ArrayType{
|
| + {%- if t|is_nullable -%}
|
| + Nullable: true,
|
| + {%- endif -%}
|
| + {%- if t.length is not none -%}
|
| + FixedLength: {{t.length}},
|
| + {%- endif -%}
|
| + ElementType: {{writeMojomType(typepkg, t.kind, pkg, exported, false)}},
|
| + },
|
| + }
|
| +{%- elif t|is_map -%}
|
| + &{{typepkg}}TypeMapType{
|
| + Value: {{typepkg}}MapType{
|
| + {%- if t|is_nullable -%}
|
| + Nullable: true,
|
| + {%- endif -%}
|
| + KeyType: {{writeMojomType(typepkg, t.key_kind, pkg, exported, false)}},
|
| + ValueType: {{writeMojomType(typepkg, t.value_kind, pkg, exported, false)}},
|
| + },
|
| + }
|
| +{%- elif t|is_enum -%}
|
| + {%- if topLevel -%}
|
| + {{- t|identifier(pkg)|identifier_store('WriteMojomType') -}}
|
| + {{typepkg}}MojomEnum{
|
| + DeclData: &{{typepkg}}DeclarationData{
|
| + ShortName: &enumName_{{t|name}},
|
| + },
|
| + Values: []{{typepkg}}EnumValue{
|
| + {%- for field in t.fields -%}
|
| + {{typepkg}}EnumValue{
|
| + Value: {{typepkg}}ConstantOccurrence{
|
| + Value: &{{typepkg}}ConstantValueEnumValue{
|
| + Value: {{typepkg}}EnumConstantValue{
|
| + EnumType: {{writeTypeReference(typepkg, t, pkg)}},
|
| + EnumValueName: &enumFieldName_{{t|name}}_{{field|name}},
|
| + IntValue: int32({{field.numeric_value}}),
|
| + },
|
| + },
|
| + },
|
| + },
|
| + {%- endfor -%}
|
| + },
|
| + }
|
| + {%- else -%}
|
| + {{writeTypeTypeReference(typepkg, t, pkg)}}
|
| + {%- endif -%}
|
| +{%- elif t|is_struct -%}
|
| + {%- if topLevel -%}
|
| + {{- t|identifier(pkg)|identifier_store('WriteMojomType') -}}
|
| + {{typepkg}}MojomStruct{
|
| + DeclData: &{{typepkg}}DeclarationData{
|
| + ShortName: &structName_{{t|name}},
|
| + },
|
| + {%- if t|is_nullable -%}
|
| + Nullable: true,
|
| + {%- endif -%}
|
| + Fields: []{{typepkg}}StructField{
|
| + {%- for field in t.fields -%}
|
| + {{typepkg}}StructField{
|
| + DeclData: &{{typepkg}}DeclarationData{
|
| + ShortName: &structFieldName_{{t|name}}_{{field|name}},
|
| + },
|
| + FieldType: {{writeMojomType(typepkg, field.kind, pkg, exported, false)}},
|
| + },
|
| + {%- endfor -%}
|
| + },
|
| + }
|
| + {%- else -%}
|
| + {{writeTypeTypeReference(typepkg, t, pkg)}}
|
| + {%- endif -%}
|
| +{%- elif t|is_union -%}
|
| + {%- if topLevel -%}
|
| + {{- t|identifier(pkg)|identifier_store('WriteMojomType') -}}
|
| + {{typepkg}}MojomUnion{
|
| + DeclData: &{{typepkg}}DeclarationData{
|
| + ShortName: &unionName_{{t|name}},
|
| + },
|
| + {%- if t|is_nullable -%}
|
| + Nullable: true,
|
| + {%- endif -%}
|
| + Fields: []{{typepkg}}UnionField{
|
| + {%- for field in t.fields -%}
|
| + {{typepkg}}UnionField{
|
| + DeclData: &{{typepkg}}DeclarationData{
|
| + ShortName: &unionFieldName_{{t|name}}_{{field|name}},
|
| + },
|
| + Type: {{writeMojomType(typepkg, field.kind, pkg, exported, false)}},
|
| + Tag: {{field.ordinal}},
|
| + },
|
| + {%- endfor -%}
|
| + },
|
| + }
|
| + {%- else -%}
|
| + {{writeTypeTypeReference(typepkg, t, pkg)}}
|
| + {%- endif -%}
|
| +{%- elif t|is_interface or t|is_interface_request -%}
|
| + {{- t|identifier(pkg)|identifier_store('WriteMojomType') -}}
|
| + {{writeTypeTypeReference(typepkg, t, pkg)}}
|
| +{%- else -%}
|
| + ERROR: UNSUPPORTED TYPE
|
| +{%- endif -%}
|
| +{%- endif -%}
|
| +{%- endmacro -%}
|
| +
|
| +{%- macro writeTypeTypeReference(typepkg, t, pkg) -%}
|
| +&{{typepkg}}TypeTypeReference{
|
| + Value: {{writeTypeReference(typepkg, t, pkg)}},
|
| +}
|
| +{%- endmacro -%}
|
| +
|
| +{%- macro writeTypeReference(typepkg, t, pkg) -%}
|
| +{{typepkg}}TypeReference {
|
| + {%- if t|is_nullable -%}
|
| + Nullable: true,
|
| + {%- endif -%}
|
| + {%- if t|is_interface_request -%}{# Interface request collapses to interface. #}
|
| + IsInterfaceRequest: true,
|
| + Identifier: &{{writePackagedTypeID(typepkg, t.kind, pkg)}},
|
| + TypeKey: &{{writePackagedTypeID(typepkg, t.kind, pkg)}},
|
| + {%- else -%}
|
| + Identifier: &{{writePackagedTypeID(typepkg, t, pkg)}},
|
| + TypeKey: &{{writePackagedTypeID(typepkg, t, pkg)}},
|
| + {%- endif -%}
|
| +}
|
| +{%- endmacro -%}
|
| +
|
| +{%- macro writePackagedTypeID(typepkg, t, pkg) -%}
|
| +{%- if t|package != '' -%}{{t|package}}.{%- endif -%}ID_{{util.typeName(t, typepkg, pkg)}}
|
| +{%- endmacro -%}
|
|
|