| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Generates dart source files from a mojom.Module.""" | 5 """Generates dart source files from a mojom.Module.""" |
| 6 | 6 |
| 7 import errno | 7 import errno |
| 8 import os | 8 import os |
| 9 import re | 9 import re |
| 10 import shutil | 10 import shutil |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 | 451 |
| 452 def GetImportUri(module): | 452 def GetImportUri(module): |
| 453 package = GetPackage(module); | 453 package = GetPackage(module); |
| 454 elements = module.namespace.split('.') | 454 elements = module.namespace.split('.') |
| 455 elements.append("%s" % module.name) | 455 elements.append("%s" % module.name) |
| 456 return os.path.join(package, *elements) | 456 return os.path.join(package, *elements) |
| 457 | 457 |
| 458 def RaiseHelper(msg): | 458 def RaiseHelper(msg): |
| 459 raise Exception(msg) | 459 raise Exception(msg) |
| 460 | 460 |
| 461 def GetSerializedRuntimeTypeInfoLiteral(module, enabled): | |
| 462 """ Constructs a string that represents a literal definition in Dart of | |
| 463 an array of bytes corresponding to |module.serialized_runtime_type_info|. | |
| 464 | |
| 465 Args: | |
| 466 module: {mojom.Module} the module being processed. | |
| 467 enabled: {bool} Is this feature enabled. | |
| 468 | |
| 469 Returns: A string of the form 'b0, b1, b2,...' where the 'bi' are | |
| 470 the decimal representation of the bytes of | |
| 471 |module.serialized_runtime_type_info| or the empty string if either | |
| 472 |enabled| is false or |module.serialized_runtime_type_info| is None. | |
| 473 Furthermore the returned string will have embedded newline characters inserted | |
| 474 every 1000 characters to make the generated source code more tractable. | |
| 475 """ | |
| 476 if not enabled or not module.serialized_runtime_type_info: | |
| 477 return '' | |
| 478 return '%s' % ','.join('%s%d' % | |
| 479 ('\n' if index > 0 and index%1000 == 0 else '', b) | |
| 480 for index, b in enumerate(module.serialized_runtime_type_info)) | |
| 481 | |
| 482 class Generator(generator.Generator): | 461 class Generator(generator.Generator): |
| 483 | 462 |
| 484 dart_filters = { | 463 dart_filters = { |
| 485 'array_expected_length': GetArrayExpectedLength, | 464 'array_expected_length': GetArrayExpectedLength, |
| 486 'array': GetArrayKind, | 465 'array': GetArrayKind, |
| 487 'decode_method': DecodeMethod, | 466 'decode_method': DecodeMethod, |
| 488 'default_value': DartDefaultValue, | 467 'default_value': DartDefaultValue, |
| 489 'encode_method': EncodeMethod, | 468 'encode_method': EncodeMethod, |
| 490 'is_imported_kind': IsImportedKind, | 469 'is_imported_kind': IsImportedKind, |
| 491 'is_array_kind': mojom.IsArrayKind, | 470 'is_array_kind': mojom.IsArrayKind, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 "namespace": self.module.namespace, | 507 "namespace": self.module.namespace, |
| 529 "imports": self.GetImports(args), | 508 "imports": self.GetImports(args), |
| 530 "kinds": self.module.kinds, | 509 "kinds": self.module.kinds, |
| 531 "enums": self.module.enums, | 510 "enums": self.module.enums, |
| 532 "module": resolver.ResolveConstants(self.module, ExpressionToText), | 511 "module": resolver.ResolveConstants(self.module, ExpressionToText), |
| 533 "structs": self.GetStructs() + self.GetStructsFromMethods(), | 512 "structs": self.GetStructs() + self.GetStructsFromMethods(), |
| 534 "unions": self.GetUnions(), | 513 "unions": self.GetUnions(), |
| 535 "interfaces": self.GetInterfaces(), | 514 "interfaces": self.GetInterfaces(), |
| 536 "imported_interfaces": self.GetImportedInterfaces(), | 515 "imported_interfaces": self.GetImportedInterfaces(), |
| 537 "imported_from": self.ImportedFrom(), | 516 "imported_from": self.ImportedFrom(), |
| 538 "serialized_runtime_type_info_literal" : ( | |
| 539 GetSerializedRuntimeTypeInfoLiteral(self.module, | |
| 540 self.should_gen_mojom_types)), | |
| 541 "typepkg": '%s.' % _mojom_types_pkg_short, | 517 "typepkg": '%s.' % _mojom_types_pkg_short, |
| 542 "descpkg": '%s.' % _service_describer_pkg_short, | 518 "descpkg": '%s.' % _service_describer_pkg_short, |
| 543 "mojom_types_import": 'import \'%s\' as %s;' % \ | 519 "mojom_types_import": 'import \'%s\' as %s;' % \ |
| 544 (_mojom_types_pkg, _mojom_types_pkg_short), | 520 (_mojom_types_pkg, _mojom_types_pkg_short), |
| 545 "service_describer_import": 'import \'%s\' as %s;' % \ | 521 "service_describer_import": 'import \'%s\' as %s;' % \ |
| 546 (_service_describer_pkg, _service_describer_pkg_short), | 522 (_service_describer_pkg, _service_describer_pkg_short), |
| 547 "has_handles": has_handles, | 523 "has_handles": has_handles, |
| 548 } | 524 } |
| 549 | 525 |
| 550 # If this is the mojom types package, clear the import-related params. | 526 # If this is the mojom types package, clear the import-related params. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 interface_to_import[name] = each_import["unique_name"] + "." + name | 628 interface_to_import[name] = each_import["unique_name"] + "." + name |
| 653 return interface_to_import | 629 return interface_to_import |
| 654 | 630 |
| 655 def ImportedFrom(self): | 631 def ImportedFrom(self): |
| 656 interface_to_import = {} | 632 interface_to_import = {} |
| 657 for each_import in self.module.imports: | 633 for each_import in self.module.imports: |
| 658 for each_interface in each_import["module"].interfaces: | 634 for each_interface in each_import["module"].interfaces: |
| 659 name = each_interface.name | 635 name = each_interface.name |
| 660 interface_to_import[name] = each_import["unique_name"] + "." | 636 interface_to_import[name] = each_import["unique_name"] + "." |
| 661 return interface_to_import | 637 return interface_to_import |
| OLD | NEW |