| OLD | NEW |
| 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 path, name in imports.iteritems() %} | 14 {% for path, name in imports.iteritems() %} |
| 15 {{name}} "{{path}}" | 15 {{name}} "{{path}}" |
| 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 %} | |
| 24 | |
| 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 | 23 |
| 35 {%- if should_gen_mojom_types -%} | 24 {%- if should_gen_mojom_types -%} |
| 36 // These IDs are the Mojom Identifiers / Type Keys. | 25 // This global variable contains a mojom_types.RuntimeTypeInfo struct |
| 37 // Mojom libraries importing this one will use these identifiers when building | 26 // describing the types defined in this file and all of its imports as |
| 38 // TypeReference objects. | 27 // well as the top-level interfaces defined in this file. |
| 39 {% for enum in enums %} | 28 var runtimeTypeInfo__ = {{typepkg}}RuntimeTypeInfo{} |
| 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 | 29 |
| 52 {% set mapping = package|qualified(None, false) ~ 'Desc__' %} | |
| 53 var {{mapping}} = make(map[string]{{typepkg}}UserDefinedType) | |
| 54 func init() { | 30 func init() { |
| 55 {% for enum in enums %} | 31 // serializedRuntimeTypeInfo contains the bytes of the Mojo serialization of |
| 56 {{mojom_reference_macros.registerType(mapping, typepkg, package, enum)}} | 32 // a mojom_types.RuntimeTypeInfo struct describing the Mojom types in this fil
e. |
| 57 {%- endfor %} | 33 serializedRuntimeTypeInfo := []uint8{{serialized_runtime_type_info_literal}} |
| 58 {% for struct in structs %} | 34 |
| 59 {{mojom_reference_macros.registerType(mapping, typepkg, package, struct)}} | 35 // Deserialize RuntimeTypeInfo |
| 60 {%- endfor %} | 36 decoder := bindings.NewDecoder(serializedRuntimeTypeInfo, nil) |
| 61 {% for union in unions %} | 37 runtimeTypeInfo__.Decode(decoder) |
| 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 | 38 |
| 68 {% for mi in mojom_imports.values() %} | 39 {% for mi in mojom_imports.values() %} |
| 69 {%- if mi ~ '.' != typepkg and mi ~ '.' != descpkg %} | 40 {%- if mi ~ '.' != typepkg and mi ~ '.' != descpkg %} |
| 70 for s, udt := range {{mi}}.GetAllMojomTypeDefinitions() { | 41 for s, udt := range {{mi}}.GetAllMojomTypeDefinitions() { |
| 71 {{mapping}}[s] = udt | 42 runtimeTypeInfo__.TypeMap[s] = udt |
| 72 } | 43 } |
| 44 |
| 45 |
| 73 {% endif -%} | 46 {% endif -%} |
| 74 {% endfor %} | 47 {% endfor %} |
| 75 } | 48 } |
| 76 func GetAllMojomTypeDefinitions() map[string]{{typepkg}}UserDefinedType { | 49 func GetAllMojomTypeDefinitions() map[string]{{typepkg}}UserDefinedType { |
| 77 return {{mapping}} | 50 return runtimeTypeInfo__.TypeMap |
| 78 } | 51 } |
| 79 {% endif %} | 52 {% endif %} |
| 80 | 53 |
| 81 {# Enum definitions #} | 54 {# Enum definitions #} |
| 82 {%- for enum in enums %} | 55 {%- for enum in enums %} |
| 83 {{enum_macros.define(enum, typepkg, package)}} | 56 {{enum_macros.define(enum, typepkg, package)}} |
| 84 {%- endfor %} | 57 {%- endfor %} |
| 85 | 58 |
| 86 {#- Interface definitions #} | 59 {#- Interface definitions #} |
| 87 {% for interface in interfaces %} | 60 {% for interface in interfaces %} |
| 88 {{interface_macros.define(interface, descpkg, typepkg, package)}} | 61 {{interface_macros.define(interface, descpkg, typepkg, package)}} |
| 89 {%- endfor %} | 62 {%- endfor %} |
| 90 | 63 |
| 91 {#- Struct definitions #} | 64 {#- Struct definitions #} |
| 92 {% for struct in structs %} | 65 {% for struct in structs %} |
| 93 {{struct_macros.define(struct, typepkg, package)}} | 66 {{struct_macros.define(struct, typepkg, package)}} |
| 94 {%- endfor %} | 67 {%- endfor %} |
| 95 | 68 |
| 96 {#- Union definitions #} | 69 {#- Union definitions #} |
| 97 {% for union in unions %} | 70 {% for union in unions %} |
| 98 {{union_macros.define(union, typepkg, package)}} | 71 {{union_macros.define(union, typepkg, package)}} |
| 99 {%- endfor %} | 72 {%- endfor %} |
| OLD | NEW |