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

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: 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_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..226ef79a45b1a9fc2799a4d4faf118feff8320f7
--- /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, descpkg, typepkg, pkg, t) -%}
+{%- 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, descpkg, typepkg, pkg, t.kind)}}
+{%- elif t|is_map -%}
+{{registerType(mapping, descpkg, typepkg, pkg, t.key_kind)}}
+{{registerType(mapping, descpkg, typepkg, pkg, t.value_kind)}}
+{% elif t|is_enum %}
+ {{mapping}}["{{util.typeName(t, typepkg, pkg)}}"] = &{{descpkg}}UserDefinedTypeEnumType{
+ Value: {{util.typeName(t, typepkg, pkg)}},
+ }
+{% elif t|is_struct %}
+ {{mapping}}["{{util.typeName(t, typepkg, pkg)}}"] = &{{descpkg}}UserDefinedTypeStructType{
+ Value: {{util.typeName(t, typepkg, pkg)}},
+ }
+ {% for field in t.fields %}
+{{registerType(mapping, descpkg, typepkg, pkg, field.kind)}}
+ {% endfor %}
+{% elif t|is_union %}
+ {{mapping}}["{{util.typeName(t, typepkg, pkg)}}"] = &{{descpkg}}UserDefinedTypeUnionType{
+ Value: {{util.typeName(t, typepkg, pkg)}},
+ }
+ {% for field in t.fields %}
+{{registerType(mapping, descpkg, typepkg, pkg, field.kind)}}
+ {% endfor %}
+{% elif t|is_interface %}
+ {{mapping}}["{{util.typeName(t, typepkg, pkg)}}"] = &{{descpkg}}UserDefinedTypeInterfaceType{
+ Value: {{util.typeName(t, typepkg, pkg)}},
+ }
+ {% for method in t.methods %}
+{{registerType(mapping, descpkg, typepkg, pkg, method.param_struct)}}
+ {% if method.response_parameters -%}
+{{registerType(mapping, descpkg, 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