| 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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 they are imported from another module). | 311 they are imported from another module). |
| 312 | 312 |
| 313 Args: | 313 Args: |
| 314 module_type: {module.Struct|Union|Enum|Interface} to be populated. | 314 module_type: {module.Struct|Union|Enum|Interface} to be populated. |
| 315 mojom: {MojomStruct|MojomUnion|MojomEnum|MojomInterface} to be translated. | 315 mojom: {MojomStruct|MojomUnion|MojomEnum|MojomInterface} to be translated. |
| 316 """ | 316 """ |
| 317 if mojom.decl_data.source_file_info: | 317 if mojom.decl_data.source_file_info: |
| 318 if mojom.decl_data.source_file_info.file_name == self._file_name: | 318 if mojom.decl_data.source_file_info.file_name == self._file_name: |
| 319 module_type.module = self._module | 319 module_type.module = self._module |
| 320 else: | 320 else: |
| 321 module_type.imported_from = self._imports[ | 321 imported_from = self._imports[ |
| 322 mojom.decl_data.source_file_info.file_name] | 322 mojom.decl_data.source_file_info.file_name] |
| 323 module_type.imported_from = imported_from |
| 324 module_type.module = imported_from['module'] |
| 325 |
| 323 | 326 |
| 324 def OrdinalFromMojom(self, mojom): | 327 def OrdinalFromMojom(self, mojom): |
| 325 """Extracts the declared ordinal from a mojom StructField or UnionField. | 328 """Extracts the declared ordinal from a mojom StructField or UnionField. |
| 326 | 329 |
| 327 Args: | 330 Args: |
| 328 mojom: {MojomStruct|MojomUnion} from which the ordinal is to be extracted. | 331 mojom: {MojomStruct|MojomUnion} from which the ordinal is to be extracted. |
| 329 | 332 |
| 330 Returns: | 333 Returns: |
| 331 {int} if an ordinal was present, {NoneType} otherwise. | 334 {int} if an ordinal was present, {NoneType} otherwise. |
| 332 """ | 335 """ |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 (module.Interface, self.InterfaceFromMojom), | 617 (module.Interface, self.InterfaceFromMojom), |
| 615 } | 618 } |
| 616 module_type_class, from_mojom = user_defined_types[mojom_type.tag] | 619 module_type_class, from_mojom = user_defined_types[mojom_type.tag] |
| 617 module_type = module_type_class() | 620 module_type = module_type_class() |
| 618 # It is necessary to cache the type object before populating it since in | 621 # It is necessary to cache the type object before populating it since in |
| 619 # the course of populating it, it may be necessary to resolve that same | 622 # the course of populating it, it may be necessary to resolve that same |
| 620 # type (say, a struct with a field of its own type). | 623 # type (say, a struct with a field of its own type). |
| 621 self._type_cache[type_key] = module_type | 624 self._type_cache[type_key] = module_type |
| 622 from_mojom(module_type, mojom_type) | 625 from_mojom(module_type, mojom_type) |
| 623 | 626 |
| 627 # module.py expects the spec of user defined types to be set when |
| 628 # constructing map and array types, but the value appears unimportant. |
| 629 module_type.spec = 'dummyspec' |
| 630 |
| 624 return module_type | 631 return module_type |
| 625 | 632 |
| 626 | 633 |
| 627 def TranslateFileGraph(graph): | 634 def TranslateFileGraph(graph): |
| 628 """Translates a mojom_types_mojom.MojomFileGraph to module.Module(s). | 635 """Translates a mojom_types_mojom.MojomFileGraph to module.Module(s). |
| 629 | 636 |
| 630 The input is the output of the parser. The output is the input to the | 637 The input is the output of the parser. The output is the input to the |
| 631 various bindings generators. | 638 various bindings generators. |
| 632 | 639 |
| 633 Args: | 640 Args: |
| 634 graph: {mojom_types_mojom.MojomFileGraph} to be translated. | 641 graph: {mojom_types_mojom.MojomFileGraph} to be translated. |
| 635 | 642 |
| 636 Return: | 643 Return: |
| 637 {dict<str, module.Module>} mapping the file's name to its module.Module | 644 {dict<str, module.Module>} mapping the file's name to its module.Module |
| 638 translation for all files in graph.files. | 645 translation for all files in graph.files. |
| 639 """ | 646 """ |
| 640 return {file_name: FileTranslator(graph, file_name).Translate() | 647 return {file_name: FileTranslator(graph, file_name).Translate() |
| 641 for file_name in graph.files} | 648 for file_name in graph.files} |
| OLD | NEW |