| 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. |
| 11 # This is part of version 2 of the code generation pipeline. In version 1, the | 11 # This is part of version 2 of the code generation pipeline. In version 1, the |
| 12 # analogous functionality (translating from parser output to code generators | 12 # analogous functionality (translating from parser output to code generators |
| 13 # input) is performed by the data module. | 13 # input) is performed by the data module. |
| 14 # | 14 # |
| 15 # The code generators remain from version 1 of the pipeline and so this module | 15 # The code generators remain from version 1 of the pipeline and so this module |
| 16 # serves as an adapter between the v1 backends and the v2 frontend. | 16 # serves as an adapter between the v1 backends and the v2 frontend. |
| 17 # | 17 # |
| 18 # The current version of this script does not validate the input data at all | 18 # The current version of this script does not validate the input data at all |
| 19 # and instead trusts that it will be invoked with valid data produced by the | 19 # and instead trusts that it will be invoked with valid data produced by the |
| 20 # frontend parser. | 20 # frontend parser. |
| 21 # | 21 # |
| 22 # NOTE: This module assumes that the python path contains the generated modules | 22 # NOTE: This module assumes that the python path contains the generated modules |
| 23 # for mojom_files.mojom and mojom_types.mojom as well as their dependencies. | 23 # for mojom_files.mojom and mojom_types.mojom as well as their dependencies. |
| 24 # It is the responsibility of the module's loader to handle this. | 24 # It is the responsibility of the module's loader to handle this. |
| 25 | 25 |
| 26 import os | 26 import os |
| 27 import mojom_files_mojom | 27 |
| 28 import mojom_types_mojom | 28 from generated import mojom_files_mojom |
| 29 from generated import mojom_types_mojom |
| 29 import module | 30 import module |
| 30 | 31 |
| 31 | 32 |
| 32 class FileTranslator(object): | 33 class FileTranslator(object): |
| 33 """FileTranslator translates a MojomFile to a module.Module.""" | 34 """FileTranslator translates a MojomFile to a module.Module.""" |
| 34 def __init__(self, graph, file_name): | 35 def __init__(self, graph, file_name): |
| 35 """Initializes a FileTranslator. | 36 """Initializes a FileTranslator. |
| 36 | 37 |
| 37 Args: | 38 Args: |
| 38 graph: {mojom_files_mojom.MojomFileGraph} containing the file to be | 39 graph: {mojom_files_mojom.MojomFileGraph} containing the file to be |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 | 632 |
| 632 Args: | 633 Args: |
| 633 graph: {mojom_types_mojom.MojomFileGraph} to be translated. | 634 graph: {mojom_types_mojom.MojomFileGraph} to be translated. |
| 634 | 635 |
| 635 Return: | 636 Return: |
| 636 {dict<str, module.Module>} mapping the file's name to its module.Module | 637 {dict<str, module.Module>} mapping the file's name to its module.Module |
| 637 translation for all files in graph.files. | 638 translation for all files in graph.files. |
| 638 """ | 639 """ |
| 639 return {file_name: FileTranslator(graph, file_name).Translate() | 640 return {file_name: FileTranslator(graph, file_name).Translate() |
| 640 for file_name in graph.files} | 641 for file_name in graph.files} |
| OLD | NEW |