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

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: Created 5 years, 3 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..d69e8f3b2c62281245a63b7c573b2a29f4cb75b0
--- /dev/null
+++ b/mojo/public/tools/bindings/generators/go_templates/mojom_type_macros.tmpl
@@ -0,0 +1,121 @@
+// 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 -#}
+{{writeTypeReference(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{
+ Values: []{{typepkg}}EnumValue{
+ {%- for field in t.fields -%}
+ {{typepkg}}EnumValue{
+ Value: {{typepkg}}ConstantOccurrence{
+ Value: &{{typepkg}}ConstantValueInt64Value{
+ Value: int64({{field.numeric_value}}),
+ },
+ },
+ },
+ {%- endfor -%}
+ },
+ }
+ {%- else -%}
+ {{writeTypeReference(typepkg, t, pkg)}}
+ {%- endif -%}
+{%- elif t|is_struct -%}
+ {%- if topLevel -%}
+ {{t|identifier(pkg)|identifier_store('WriteMojomType')}}
+ {{typepkg}}MojomStruct{
+ {%- if t|is_nullable -%}
+ Nullable: true,
+ {%- endif -%}
+ Fields: []{{typepkg}}StructField{
+ {%- for field in t.fields -%}
+ {{typepkg}}StructField{
+ FieldType: {{writeMojomType(typepkg, field.kind, pkg, exported, false)}},
+ },
+ {%- endfor -%}
+ },
+ }
+ {%- else -%}
+ {{writeTypeReference(typepkg, t, pkg)}}
+ {%- endif -%}
+{%- elif t|is_union -%}
+ {%- if topLevel -%}
+ {{t|identifier(pkg)|identifier_store('WriteMojomType')}}
+ {{typepkg}}MojomUnion{
+ {%- if t|is_nullable -%}
+ Nullable: true,
+ {%- endif -%}
+ Fields: []{{typepkg}}UnionField{
+ {%- for field in t.fields -%}
+ {{typepkg}}UnionField{
+ Type: {{writeMojomType(typepkg, field.kind, pkg, exported, false)}},
+ Tag: {{field.ordinal}},
+ },
+ {%- endfor -%}
+ },
+ }
+ {%- else -%}
+ {{writeTypeReference(typepkg, t, pkg)}}
+ {%- endif -%}
+{%- elif t|is_interface or t|is_interface_request -%}
+ {{t|identifier(pkg)|identifier_store('WriteMojomType')}}
+ {{writeTypeReference(typepkg, t, pkg)}}
+{%- else -%}
+ ERROR: UNSUPPORTED TYPE
+{%- endif -%}
+{%- endif -%}
+{%- endmacro -%}
+
+{%- macro writeTypeReference(typepkg, t, pkg) -%}
+&{{typepkg}}TypeTypeReference{
+ Value: {{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