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 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 | 386 |
387 Args: | 387 Args: |
388 interface: {module.Interface} to be populated. | 388 interface: {module.Interface} to be populated. |
389 mojom_type: {UserDefinedType} referring to the MojomInterface to be | 389 mojom_type: {UserDefinedType} referring to the MojomInterface to be |
390 translated. | 390 translated. |
391 """ | 391 """ |
392 assert (mojom_type.tag | 392 assert (mojom_type.tag |
393 == mojom_types_mojom.UserDefinedType.Tags.interface_type) | 393 == mojom_types_mojom.UserDefinedType.Tags.interface_type) |
394 mojom_interface = mojom_type.interface_type | 394 mojom_interface = mojom_type.interface_type |
395 interface.attributes = self.AttributesFromMojom(mojom_interface) | 395 interface.attributes = self.AttributesFromMojom(mojom_interface) |
396 interface.service_name = None | 396 self.PopulateModuleOrImportedFrom(interface, mojom_interface) |
397 interface.name = mojom_interface.decl_data.short_name | |
398 interface.spec = interface.name | |
399 interface.service_name = mojom_interface.service_name | |
397 if interface.attributes: | 400 if interface.attributes: |
398 interface.service_name = interface.attributes.get('ServiceName') | 401 assert interface.service_name == interface.attributes.get( |
399 self.PopulateModuleOrImportedFrom(interface, mojom_interface) | 402 'ServiceName', None), interface.service_name |
400 interface.name = mojom_interface.interface_name | 403 else: |
401 interface.spec = interface.name | 404 assert interface.service_name == None, interface.service_name |
azani
2016/02/10 00:06:39
standard python practice is to use: is None instea
rudominer
2016/02/10 00:43:49
Done.
| |
405 | |
402 | 406 |
403 # Translate the dictionary of methods into a list of module.Methods. | 407 # Translate the dictionary of methods into a list of module.Methods. |
404 # In order to have a deterministic ordering we sort by method ordinal. | 408 # In order to have a deterministic ordering we sort by method ordinal. |
405 # TODO(rudominer) Consider ordering by declaration order instead once | 409 # TODO(rudominer) Consider ordering by declaration order instead once |
406 # this field is populated by the front-end. | 410 # this field is populated by the front-end. |
407 interface.methods = [self.MethodFromMojom(mojom_method, interface) | 411 interface.methods = [self.MethodFromMojom(mojom_method, interface) |
408 for ordinal, mojom_method in sorted(mojom_interface.methods.iteritems(), | 412 for ordinal, mojom_method in sorted(mojom_interface.methods.iteritems(), |
409 key=operator.itemgetter(0))] | 413 key=operator.itemgetter(0))] |
410 self.PopulateContainedDeclarationsFromMojom( | 414 self.PopulateContainedDeclarationsFromMojom( |
411 interface, mojom_interface.decl_data.contained_declarations) | 415 interface, mojom_interface.decl_data.contained_declarations) |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
800 | 804 |
801 Args: | 805 Args: |
802 graph: {mojom_types_mojom.MojomFileGraph} to be translated. | 806 graph: {mojom_types_mojom.MojomFileGraph} to be translated. |
803 | 807 |
804 Return: | 808 Return: |
805 {dict<str, module.Module>} mapping the file's name to its module.Module | 809 {dict<str, module.Module>} mapping the file's name to its module.Module |
806 translation for all files in graph.files. | 810 translation for all files in graph.files. |
807 """ | 811 """ |
808 return {file_name: FileTranslator(graph, file_name).Translate() | 812 return {file_name: FileTranslator(graph, file_name).Translate() |
809 for file_name in graph.files} | 813 for file_name in graph.files} |
OLD | NEW |