Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1376)

Side by Side Diff: mojo/public/tools/bindings/pylib/mojom/generate/mojom_translator.py

Issue 1522583003: New Mojom compiler: Assign a meaningful spec string instead of 'dummyspec' because it turns out it… (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | mojo/public/tools/bindings/pylib/mojom/generate/mojom_translator_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 326
327 def PopulateUserDefinedType(self, module_type, mojom): 327 def PopulateUserDefinedType(self, module_type, mojom):
328 """Populates fields that are common among user-defined types. 328 """Populates fields that are common among user-defined types.
329 329
330 Args: 330 Args:
331 module_type: {module.Struct|Union|Enum} to be populated. 331 module_type: {module.Struct|Union|Enum} to be populated.
332 mojom: {MojomStruct|MojomUnion|MojomEnum} to be translated. 332 mojom: {MojomStruct|MojomUnion|MojomEnum} to be translated.
333 """ 333 """
334 module_type.attributes = self.AttributesFromMojom(mojom) 334 module_type.attributes = self.AttributesFromMojom(mojom)
335 module_type.name = mojom.decl_data.short_name 335 module_type.name = mojom.decl_data.short_name
336 module_type.spec = mojom.decl_data.full_identifier
337 if module_type.spec == None:
338 module_type.spec = mojom.decl_data.short_name
336 self.PopulateModuleOrImportedFrom(module_type, mojom) 339 self.PopulateModuleOrImportedFrom(module_type, mojom)
337 340
338 def PopulateModuleOrImportedFrom(self, module_type, mojom): 341 def PopulateModuleOrImportedFrom(self, module_type, mojom):
339 """Populates either the module field or the imported_from field. 342 """Populates either the module field or the imported_from field.
340 343
341 All user-defined types must have either the module field populated (if 344 All user-defined types must have either the module field populated (if
342 they are from the currently-processed module) or the imported_from (if 345 they are from the currently-processed module) or the imported_from (if
343 they are imported from another module). 346 they are imported from another module).
344 347
345 Args: 348 Args:
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 """ 383 """
381 assert (mojom_type.tag 384 assert (mojom_type.tag
382 == mojom_types_mojom.UserDefinedType.Tags.interface_type) 385 == mojom_types_mojom.UserDefinedType.Tags.interface_type)
383 mojom_interface = mojom_type.interface_type 386 mojom_interface = mojom_type.interface_type
384 interface.attributes = self.AttributesFromMojom(mojom_interface) 387 interface.attributes = self.AttributesFromMojom(mojom_interface)
385 interface.service_name = None 388 interface.service_name = None
386 if interface.attributes: 389 if interface.attributes:
387 interface.service_name = interface.attributes.get('ServiceName') 390 interface.service_name = interface.attributes.get('ServiceName')
388 self.PopulateModuleOrImportedFrom(interface, mojom_interface) 391 self.PopulateModuleOrImportedFrom(interface, mojom_interface)
389 interface.name = mojom_interface.interface_name 392 interface.name = mojom_interface.interface_name
393 interface.spec = interface.name
394
390 interface.methods = [self.MethodFromMojom(mojom_method, interface) 395 interface.methods = [self.MethodFromMojom(mojom_method, interface)
391 for mojom_method in mojom_interface.methods.itervalues()] 396 for mojom_method in mojom_interface.methods.itervalues()]
392 self.PopulateContainedDeclarationsFromMojom( 397 self.PopulateContainedDeclarationsFromMojom(
393 interface, mojom_interface.decl_data.contained_declarations) 398 interface, mojom_interface.decl_data.contained_declarations)
394 399
395 def MethodFromMojom(self, mojom_method, interface): 400 def MethodFromMojom(self, mojom_method, interface):
396 """Translates a mojom_types_mojom.MojomMethod to a module.Method. 401 """Translates a mojom_types_mojom.MojomMethod to a module.Method.
397 402
398 Args: 403 Args:
399 mojom_method: {mojom_types_mojom.MojomMethod} to be translated. 404 mojom_method: {mojom_types_mojom.MojomMethod} to be translated.
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 mojom_types_mojom.UserDefinedType.Tags.enum_type: 757 mojom_types_mojom.UserDefinedType.Tags.enum_type:
753 (module.Enum, self.EnumFromMojom), 758 (module.Enum, self.EnumFromMojom),
754 mojom_types_mojom.UserDefinedType.Tags.union_type: 759 mojom_types_mojom.UserDefinedType.Tags.union_type:
755 (module.Union, self.UnionFromMojom), 760 (module.Union, self.UnionFromMojom),
756 mojom_types_mojom.UserDefinedType.Tags.interface_type: 761 mojom_types_mojom.UserDefinedType.Tags.interface_type:
757 (module.Interface, self.InterfaceFromMojom), 762 (module.Interface, self.InterfaceFromMojom),
758 } 763 }
759 module_type_class, from_mojom = user_defined_types[mojom_type.tag] 764 module_type_class, from_mojom = user_defined_types[mojom_type.tag]
760 module_type = module_type_class() 765 module_type = module_type_class()
761 766
762 # module.py expects the spec of user defined types to be set when 767 if module_type.spec == None:
763 # constructing map, array, and interface request types, but the value 768 # module.py expects the spec of user defined types to be set when
764 # appears unimportant. 769 # constructing map, array, and interface request types, but the value
765 module_type.spec = 'dummyspec' 770 # appears to be only used for error messages.
771 module_type.spec = 'dummyspec'
766 772
767 # It is necessary to cache the type object before populating it since in 773 # It is necessary to cache the type object before populating it since in
768 # the course of populating it, it may be necessary to resolve that same 774 # the course of populating it, it may be necessary to resolve that same
769 # type (say, a struct with a field of its own type). 775 # type (say, a struct with a field of its own type).
770 self._type_cache[type_key] = module_type 776 self._type_cache[type_key] = module_type
771 from_mojom(module_type, mojom_type) 777 from_mojom(module_type, mojom_type)
772 778
773 return module_type 779 return module_type
774 780
775 781
776 def TranslateFileGraph(graph): 782 def TranslateFileGraph(graph):
777 """Translates a mojom_types_mojom.MojomFileGraph to module.Module(s). 783 """Translates a mojom_types_mojom.MojomFileGraph to module.Module(s).
778 784
779 The input is the output of the parser. The output is the input to the 785 The input is the output of the parser. The output is the input to the
780 various bindings generators. 786 various bindings generators.
781 787
782 Args: 788 Args:
783 graph: {mojom_types_mojom.MojomFileGraph} to be translated. 789 graph: {mojom_types_mojom.MojomFileGraph} to be translated.
784 790
785 Return: 791 Return:
786 {dict<str, module.Module>} mapping the file's name to its module.Module 792 {dict<str, module.Module>} mapping the file's name to its module.Module
787 translation for all files in graph.files. 793 translation for all files in graph.files.
788 """ 794 """
789 return {file_name: FileTranslator(graph, file_name).Translate() 795 return {file_name: FileTranslator(graph, file_name).Translate()
790 for file_name in graph.files} 796 for file_name in graph.files}
OLDNEW
« no previous file with comments | « no previous file | mojo/public/tools/bindings/pylib/mojom/generate/mojom_translator_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698