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

Unified Diff: mojo/public/tools/bindings/generators/go_templates/mojom_reference_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_reference_macros.tmpl
diff --git a/mojo/public/tools/bindings/generators/go_templates/mojom_reference_macros.tmpl b/mojo/public/tools/bindings/generators/go_templates/mojom_reference_macros.tmpl
new file mode 100644
index 0000000000000000000000000000000000000000..dadc6e52e3e3480c5ed9a147f01168466f82da4c
--- /dev/null
+++ b/mojo/public/tools/bindings/generators/go_templates/mojom_reference_macros.tmpl
@@ -0,0 +1,53 @@
+// 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 registerType(mapping, typepkg, pkg, t) -%}
azani 2015/10/12 21:13:07 t is type?
alexfandrianto 2015/10/16 21:25:49 Yes, it is a type (or kind).
azani 2015/10/19 18:27:02 Can you rename it to type or kind then?
alexfandrianto 2015/10/19 21:36:30 Done. I chose type
+{%- if t|identifier(pkg)|identifier_check('RegisterType') -%}{# Already printed out #}
+{%- elif t|package != '' -%} {# Don't print. That package will do it. #}
+{%- else -%}
+{{t|identifier(pkg)|identifier_store('RegisterType')}}
+
+{%- if t|mojom_type(typepkg) != "" -%}{#- simple kind case: do nothing -#}
+{%- elif t|is_array -%}
+{{registerType(mapping, typepkg, pkg, t.kind)}}
+{%- elif t|is_map -%}
+{{registerType(mapping, typepkg, pkg, t.key_kind)}}
+{{registerType(mapping, typepkg, pkg, t.value_kind)}}
+{% elif t|is_enum %}
+ {{mapping}}["{{util.typeName(t, typepkg, pkg)}}"] = &{{typepkg}}UserDefinedTypeEnumType{
+ Value: {{util.typeName(t, typepkg, pkg)}}(),
+ }
+{% elif t|is_struct %}
+ {{mapping}}["{{util.typeName(t, typepkg, pkg)}}"] = &{{typepkg}}UserDefinedTypeStructType{
+ Value: {{util.typeName(t, typepkg, pkg)}}(),
+ }
+ {% for field in t.fields %}
+{{registerType(mapping, typepkg, pkg, field.kind)}}
+ {% endfor %}
+{% elif t|is_union %}
+ {{mapping}}["{{util.typeName(t, typepkg, pkg)}}"] = &{{typepkg}}UserDefinedTypeUnionType{
+ Value: {{util.typeName(t, typepkg, pkg)}}(),
+ }
+ {% for field in t.fields %}
+{{registerType(mapping, typepkg, pkg, field.kind)}}
+ {% endfor %}
+{% elif t|is_interface %}
+ {{mapping}}["{{util.typeName(t, typepkg, pkg)}}"] = &{{typepkg}}UserDefinedTypeInterfaceType{
+ Value: {{util.typeName(t, typepkg, pkg)}}(),
+ }
+ {% for method in t.methods %}
+{{registerType(mapping, typepkg, pkg, method.param_struct)}}
+ {% if method.response_parameters -%}
+{{registerType(mapping, typepkg, pkg, method.response_param_struct)}}
+ {%- endif %}
+ {%- endfor %}
+{% elif t|is_interface_request -%} {# No need to register anything #}
+{%- else -%}
+ ERROR: UNSUPPORTED TYPE
+ {{t|identifier(pkg)}}
+{%- endif -%}
+{%- endif -%}
+{%- endmacro -%}

Powered by Google App Engine
This is Rietveld 408576698