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

Unified Diff: mojo/public/tools/bindings/generators/go_templates/mojom_type_macros.tmpl

Issue 1345263002: Generate Mojom Types in Go (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Use unexported functions instead of variables Created 5 years, 2 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/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 -%}

Powered by Google App Engine
This is Rietveld 408576698