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

Side by Side Diff: mojo/public/tools/bindings/generators/go_templates/source.tmpl

Issue 1345263002: Generate Mojom Types in Go (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Add a toggle that can turn off mojom type generation 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file is autogenerated by: 5 // This file is autogenerated by:
6 // mojo/public/tools/bindings/mojom_bindings_generator.py 6 // mojo/public/tools/bindings/mojom_bindings_generator.py
7 // For: 7 // For:
8 // {{module.path}} 8 // {{module.path}}
9 // 9 //
10 10
11 package {{package}} 11 package {{package}}
12 12
13 import ( 13 import (
14 {% for i in imports %} 14 {% for i in imports %}
15 {{i}} 15 {{i}}
16 {% endfor %} 16 {% endfor %}
17 ) 17 )
18 18
19 {% import "enum.tmpl" as enum_macros %} 19 {% import "enum.tmpl" as enum_macros %}
20 {% import "interface.tmpl" as interface_macros %} 20 {% import "interface.tmpl" as interface_macros %}
21 {% import "struct.tmpl" as struct_macros %} 21 {% import "struct.tmpl" as struct_macros %}
22 {% import "union.tmpl" as union_macros %} 22 {% import "union.tmpl" as union_macros %}
23 {% import "mojom_reference_macros.tmpl" as mojom_reference_macros %}
23 24
24 {#- Enum definitions #} 25 {#- This init function initializes a mapping between identifiers and their
26 corresponding user-defined type. This could have been a MojomDescriptor,
27 but since it allows Types to be unresolved, it is more complex than is
28 necessary. It's simpler to resolve everything in codegen.
29 It is also difficult to insert changes to the description during the
30 process of generating each type, so this mapping is computed in Python.
31 Note: While we may register items into the map multiple times, this is okay
32 because the keys will match.
33 -#}
34
35 {%- if should_gen_mojom_types -%}
36 // These IDs are the Mojom Identifiers / Type Keys.
37 // Mojom libraries importing this one will use these identifiers when building
38 // TypeReference objects.
25 {% for enum in enums %} 39 {% for enum in enums %}
26 {{enum_macros.define(enum)}} 40 var ID_{{enum|mojom_type_identifier}} string = "{{enum|mojom_type_identifier}}"
41 {% endfor %}
42 {% for struct in structs %}
43 var ID_{{struct|mojom_type_identifier}} string = "{{struct|mojom_type_identifier }}"
44 {% endfor %}
45 {% for union in unions %}
46 var ID_{{union|mojom_type_identifier}} string = "{{union|mojom_type_identifier}} "
47 {% endfor %}
48 {% for interface in interfaces %}
49 var ID_{{interface|mojom_type_identifier}} string = "{{interface|mojom_type_iden tifier}}"
50 {% endfor %}
51
52 {% set mapping = package|qualified(None, true) ~ 'Desc__' %}
53 var {{mapping}} = make(map[string]{{typepkg}}UserDefinedType)
54 func init() {
55 {% for enum in enums %}
56 {{mojom_reference_macros.registerType(mapping, typepkg, package, enum)}}
57 {%- endfor %}
58 {% for struct in structs %}
59 {{mojom_reference_macros.registerType(mapping, typepkg, package, struct)}}
60 {%- endfor %}
61 {% for union in unions %}
62 {{mojom_reference_macros.registerType(mapping, typepkg, package, union)}}
63 {%- endfor %}
64 {% for interface in interfaces %}
65 {{mojom_reference_macros.registerType(mapping, typepkg, package, interface)}}
66 {%- endfor %}
67
68 {% for mi in mojom_imports.values() %}
69 {%- if mi ~ '.' != typepkg and mi ~ '.' != descpkg %}
70 for s, udt := range {{mi}}.Descriptor() {
71 {{mapping}}[s] = udt
72 }
73 {% endif -%}
74 {% endfor %}
75 }
76 func Descriptor() map[string]{{typepkg}}UserDefinedType {
rudominer 2015/10/22 21:28:48 I don't understand why you want this function. You
alexfandrianto 2015/10/22 22:58:11 My reason for having Descriptor() is so that the m
77 return {{mapping}}
78 }
79 {% endif %}
80
81 {# Enum definitions #}
82 {%- for enum in enums %}
83 {{enum_macros.define(enum, typepkg, package)}}
27 {%- endfor %} 84 {%- endfor %}
28 85
29 {#- Interface definitions #} 86 {#- Interface definitions #}
30 {% for interface in interfaces %} 87 {% for interface in interfaces %}
31 {{interface_macros.define(interface)}} 88 {{interface_macros.define(interface, descpkg, typepkg, package)}}
32 {%- endfor %} 89 {%- endfor %}
33 90
34 {#- Struct definitions #} 91 {#- Struct definitions #}
35 {% for struct in structs %} 92 {% for struct in structs %}
36 {{struct_macros.define(struct)}} 93 {{struct_macros.define(struct, typepkg, package)}}
37 {%- endfor %} 94 {%- endfor %}
38 95
39 {#- Union definitions #} 96 {#- Union definitions #}
40 {% for union in unions %} 97 {% for union in unions %}
41 {{union_macros.define(union)}} 98 {{union_macros.define(union, typepkg, package)}}
42 {%- endfor %} 99 {%- endfor %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698