OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 # | 5 # |
6 # This module is responsible for translating a MojomFileGraph (see | 6 # This module is responsible for translating a MojomFileGraph (see |
7 # mojom_files.mojom) to one or more module.Module. | 7 # mojom_files.mojom) to one or more module.Module. |
8 # | 8 # |
9 # This module takes the output of the mojom parser, a MojomFileGraph and | 9 # This module takes the output of the mojom parser, a MojomFileGraph and |
10 # translates it to the input of the code generators, a module.Module object. | 10 # translates it to the input of the code generators, a module.Module object. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 user_defined_types = ['interfaces', 'structs', 'unions'] | 78 user_defined_types = ['interfaces', 'structs', 'unions'] |
79 for user_defined_type in user_defined_types: | 79 for user_defined_type in user_defined_types: |
80 if getattr(mojom_file.declared_mojom_objects, user_defined_type): | 80 if getattr(mojom_file.declared_mojom_objects, user_defined_type): |
81 setattr(mod, user_defined_type, [self.UserDefinedFromTypeKey(key) | 81 setattr(mod, user_defined_type, [self.UserDefinedFromTypeKey(key) |
82 for key in getattr( | 82 for key in getattr( |
83 mojom_file.declared_mojom_objects, user_defined_type)]) | 83 mojom_file.declared_mojom_objects, user_defined_type)]) |
84 if mojom_file.declared_mojom_objects.top_level_enums: | 84 if mojom_file.declared_mojom_objects.top_level_enums: |
85 mod.enums = [self.UserDefinedFromTypeKey(key) | 85 mod.enums = [self.UserDefinedFromTypeKey(key) |
86 for key in mojom_file.declared_mojom_objects.top_level_enums] | 86 for key in mojom_file.declared_mojom_objects.top_level_enums] |
87 | 87 |
| 88 mod.serialized_runtime_type_info = mojom_file.serialized_runtime_type_info |
| 89 |
88 return mod | 90 return mod |
89 | 91 |
90 def PopulateModuleMetadata(self, mod, mojom_file): | 92 def PopulateModuleMetadata(self, mod, mojom_file): |
91 """Populates some fields of a module.Module based on a MojomFile. | 93 """Populates some fields of a module.Module based on a MojomFile. |
92 | 94 |
93 Populates name, path, namespace and attributes of mod. | 95 Populates name, path, namespace and attributes of mod. |
94 | 96 |
95 Args: | 97 Args: |
96 mod: {module.Module} the module to be populated. | 98 mod: {module.Module} the module to be populated. |
97 mojom_file: {MojomFile} the file to be translated. | 99 mojom_file: {MojomFile} the file to be translated. |
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 # constructing map, array, and interface request types, but the value | 788 # constructing map, array, and interface request types, but the value |
787 # appears to be only used for error messages. | 789 # appears to be only used for error messages. |
788 module_type.spec = 'dummyspec' | 790 module_type.spec = 'dummyspec' |
789 | 791 |
790 # It is necessary to cache the type object before populating it since in | 792 # It is necessary to cache the type object before populating it since in |
791 # the course of populating it, it may be necessary to resolve that same | 793 # the course of populating it, it may be necessary to resolve that same |
792 # type (say, a struct with a field of its own type). | 794 # type (say, a struct with a field of its own type). |
793 self._type_cache[type_key] = module_type | 795 self._type_cache[type_key] = module_type |
794 from_mojom(module_type, mojom_type) | 796 from_mojom(module_type, mojom_type) |
795 | 797 |
| 798 module_type.type_key = type_key |
| 799 |
796 return module_type | 800 return module_type |
797 | 801 |
798 | 802 |
799 def TranslateFileGraph(graph): | 803 def TranslateFileGraph(graph): |
800 """Translates a mojom_types_mojom.MojomFileGraph to module.Module(s). | 804 """Translates a mojom_types_mojom.MojomFileGraph to module.Module(s). |
801 | 805 |
802 The input is the output of the parser. The output is the input to the | 806 The input is the output of the parser. The output is the input to the |
803 various bindings generators. | 807 various bindings generators. |
804 | 808 |
805 Args: | 809 Args: |
806 graph: {mojom_types_mojom.MojomFileGraph} to be translated. | 810 graph: {mojom_types_mojom.MojomFileGraph} to be translated. |
807 | 811 |
808 Return: | 812 Return: |
809 {dict<str, module.Module>} mapping the file's name to its module.Module | 813 {dict<str, module.Module>} mapping the file's name to its module.Module |
810 translation for all files in graph.files. | 814 translation for all files in graph.files. |
811 """ | 815 """ |
812 return {file_name: FileTranslator(graph, file_name).Translate() | 816 return {file_name: FileTranslator(graph, file_name).Translate() |
813 for file_name in graph.files} | 817 for file_name in graph.files} |
OLD | NEW |