| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
| 4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 """This module provides shared functionality for systems to generate | 6 """This module provides shared functionality for systems to generate |
| 7 Dart APIs from the IDL database.""" | 7 Dart APIs from the IDL database.""" |
| 8 | 8 |
| 9 import copy | 9 import copy |
| 10 import re | 10 import re |
| 11 from htmlrenamer import html_interface_renames | 11 from htmlrenamer import html_interface_renames |
| 12 | 12 |
| 13 _pure_interfaces = set([ | 13 _pure_interfaces = set([ |
| 14 # TODO(sra): DOMStringMap should be a class implementing Map<String,String>. | 14 # TODO(sra): DOMStringMap should be a class implementing Map<String,String>. |
| 15 'DOMStringMap', | 15 'DOMStringMap', |
| 16 'ElementTimeControl', | 16 'ElementTimeControl', |
| 17 'ElementTraversal', | 17 'ElementTraversal', |
| 18 'EventListener', |
| 18 'MediaQueryListListener', | 19 'MediaQueryListListener', |
| 19 'NodeSelector', | 20 'NodeSelector', |
| 20 'SVGExternalResourcesRequired', | 21 'SVGExternalResourcesRequired', |
| 21 'SVGFilterPrimitiveStandardAttributes', | 22 'SVGFilterPrimitiveStandardAttributes', |
| 22 'SVGFitToViewBox', | 23 'SVGFitToViewBox', |
| 23 'SVGLangSpace', | 24 'SVGLangSpace', |
| 24 'SVGLocatable', | 25 'SVGLocatable', |
| 25 'SVGStylable', | 26 'SVGStylable', |
| 26 'SVGTests', | 27 'SVGTests', |
| 27 'SVGTransformable', | 28 'SVGTransformable', |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 else: | 499 else: |
| 499 return '\n' | 500 return '\n' |
| 500 return ''.join(FormatLine(line) for line in text.split('\n')) | 501 return ''.join(FormatLine(line) for line in text.split('\n')) |
| 501 | 502 |
| 502 # Given a sorted sequence of type identifiers, return an appropriate type | 503 # Given a sorted sequence of type identifiers, return an appropriate type |
| 503 # name | 504 # name |
| 504 def TypeName(type_ids, interface): | 505 def TypeName(type_ids, interface): |
| 505 # Dynamically type this field for now. | 506 # Dynamically type this field for now. |
| 506 return 'Dynamic' | 507 return 'Dynamic' |
| 507 | 508 |
| 509 def ImplementationClassName(interface_name): |
| 510 return '_%sImpl' % interface_name |
| 511 |
| 508 # ------------------------------------------------------------------------------ | 512 # ------------------------------------------------------------------------------ |
| 509 | 513 |
| 510 class Conversion(object): | 514 class Conversion(object): |
| 511 """Represents a way of converting between types.""" | 515 """Represents a way of converting between types.""" |
| 512 def __init__(self, name, input_type, output_type): | 516 def __init__(self, name, input_type, output_type): |
| 513 # input_type is the type of the API input (and the argument type of the | 517 # input_type is the type of the API input (and the argument type of the |
| 514 # conversion function) | 518 # conversion function) |
| 515 # output_type is the type of the API output (and the result type of the | 519 # output_type is the type of the API output (and the result type of the |
| 516 # conversion function) | 520 # conversion function) |
| 517 self.function_name = name | 521 self.function_name = name |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 def __init__(self, idl_type, data): | 605 def __init__(self, idl_type, data): |
| 602 self._idl_type = idl_type | 606 self._idl_type = idl_type |
| 603 self._data = data | 607 self._data = data |
| 604 | 608 |
| 605 def idl_type(self): | 609 def idl_type(self): |
| 606 return self._idl_type | 610 return self._idl_type |
| 607 | 611 |
| 608 def dart_type(self): | 612 def dart_type(self): |
| 609 return self._data.dart_type or self._idl_type | 613 return self._data.dart_type or self._idl_type |
| 610 | 614 |
| 615 def narrow_dart_type(self): |
| 616 return self.dart_type() |
| 617 |
| 611 def native_type(self): | 618 def native_type(self): |
| 612 return self._data.native_type or self._idl_type | 619 return self._data.native_type or self._idl_type |
| 613 | 620 |
| 614 def bindings_class(self): | 621 def bindings_class(self): |
| 615 return 'Dart%s' % self.idl_type() | 622 return 'Dart%s' % self.idl_type() |
| 616 | 623 |
| 617 def vector_to_dart_template_parameter(self): | 624 def vector_to_dart_template_parameter(self): |
| 618 return self.bindings_class() | 625 return self.bindings_class() |
| 619 | 626 |
| 620 def requires_v8_scope(self): | 627 def requires_v8_scope(self): |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 | 696 |
| 690 | 697 |
| 691 class InterfaceIDLTypeInfo(IDLTypeInfo): | 698 class InterfaceIDLTypeInfo(IDLTypeInfo): |
| 692 def __init__(self, idl_type, data, dart_interface_name): | 699 def __init__(self, idl_type, data, dart_interface_name): |
| 693 super(InterfaceIDLTypeInfo, self).__init__(idl_type, data) | 700 super(InterfaceIDLTypeInfo, self).__init__(idl_type, data) |
| 694 self._dart_interface_name = dart_interface_name | 701 self._dart_interface_name = dart_interface_name |
| 695 | 702 |
| 696 def dart_type(self): | 703 def dart_type(self): |
| 697 return self._data.dart_type or self._dart_interface_name | 704 return self._data.dart_type or self._dart_interface_name |
| 698 | 705 |
| 706 def narrow_dart_type(self): |
| 707 # TODO(podivilov): introduce ListLikeIDLTypeInfo and remove this hack. |
| 708 if self._data.suppress_public_interface: |
| 709 return ImplementationClassName(self.idl_type()) |
| 710 # TODO(podivilov): only primitive and collection types should override |
| 711 # dart_type. |
| 712 if self._data.dart_type != None: |
| 713 return self.dart_type() |
| 714 if IsPureInterface(self.idl_type()): |
| 715 return self.idl_type() |
| 716 return ImplementationClassName(self._dart_interface_name) |
| 717 |
| 718 |
| 719 class CallbackIDLTypeInfo(IDLTypeInfo): |
| 720 def __init__(self, idl_type, data): |
| 721 super(CallbackIDLTypeInfo, self).__init__(idl_type, data) |
| 722 |
| 699 | 723 |
| 700 class SequenceIDLTypeInfo(IDLTypeInfo): | 724 class SequenceIDLTypeInfo(IDLTypeInfo): |
| 701 def __init__(self, idl_type, data, item_info): | 725 def __init__(self, idl_type, data, item_info): |
| 702 super(SequenceIDLTypeInfo, self).__init__(idl_type, data) | 726 super(SequenceIDLTypeInfo, self).__init__(idl_type, data) |
| 703 self._item_info = item_info | 727 self._item_info = item_info |
| 704 | 728 |
| 705 def dart_type(self): | 729 def dart_type(self): |
| 706 return 'List<%s>' % self._item_info.dart_type() | 730 return 'List<%s>' % self._item_info.dart_type() |
| 707 | 731 |
| 708 def vector_to_dart_template_parameter(self): | 732 def vector_to_dart_template_parameter(self): |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 def webcore_getter_name(self): | 792 def webcore_getter_name(self): |
| 769 return self._data.webcore_getter_name | 793 return self._data.webcore_getter_name |
| 770 | 794 |
| 771 def webcore_setter_name(self): | 795 def webcore_setter_name(self): |
| 772 return self._data.webcore_setter_name | 796 return self._data.webcore_setter_name |
| 773 | 797 |
| 774 def _capitalized_native_type(self): | 798 def _capitalized_native_type(self): |
| 775 return re.sub(r'(^| )([a-z])', lambda x: x.group(2).upper(), self.native_typ
e()) | 799 return re.sub(r'(^| )([a-z])', lambda x: x.group(2).upper(), self.native_typ
e()) |
| 776 | 800 |
| 777 | 801 |
| 778 class SVGTearOffIDLTypeInfo(IDLTypeInfo): | 802 class SVGTearOffIDLTypeInfo(InterfaceIDLTypeInfo): |
| 779 def __init__(self, idl_type, data): | 803 def __init__(self, idl_type, data): |
| 780 super(SVGTearOffIDLTypeInfo, self).__init__(idl_type, data) | 804 super(SVGTearOffIDLTypeInfo, self).__init__(idl_type, data, idl_type) |
| 781 | 805 |
| 782 def native_type(self): | 806 def native_type(self): |
| 783 if self._data.native_type: | 807 if self._data.native_type: |
| 784 return self._data.native_type | 808 return self._data.native_type |
| 785 tear_off_type = 'SVGPropertyTearOff' | 809 tear_off_type = 'SVGPropertyTearOff' |
| 786 if self._idl_type.endswith('List'): | 810 if self._idl_type.endswith('List'): |
| 787 tear_off_type = 'SVGListPropertyTearOff' | 811 tear_off_type = 'SVGListPropertyTearOff' |
| 788 return '%s<%s>' % (tear_off_type, self._idl_type) | 812 return '%s<%s>' % (tear_off_type, self._idl_type) |
| 789 | 813 |
| 790 def receiver(self): | 814 def receiver(self): |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 985 def _TypeInfo(self, type_name): | 1009 def _TypeInfo(self, type_name): |
| 986 match = re.match(r'(?:sequence<(\w+)>|(\w+)\[\])$', type_name) | 1010 match = re.match(r'(?:sequence<(\w+)>|(\w+)\[\])$', type_name) |
| 987 if match: | 1011 if match: |
| 988 if type_name == 'DOMString[]': | 1012 if type_name == 'DOMString[]': |
| 989 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt
ring')) | 1013 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt
ring')) |
| 990 item_info = self.TypeInfo(match.group(1) or match.group(2)) | 1014 item_info = self.TypeInfo(match.group(1) or match.group(2)) |
| 991 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info) | 1015 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info) |
| 992 | 1016 |
| 993 if not type_name in _idl_type_registry: | 1017 if not type_name in _idl_type_registry: |
| 994 interface = self._database.GetInterface(type_name) | 1018 interface = self._database.GetInterface(type_name) |
| 1019 if 'Callback' in interface.ext_attrs: |
| 1020 return CallbackIDLTypeInfo(type_name, TypeData('Callback')) |
| 995 return InterfaceIDLTypeInfo( | 1021 return InterfaceIDLTypeInfo( |
| 996 type_name, | 1022 type_name, |
| 997 TypeData('Interface'), | 1023 TypeData('Interface'), |
| 998 self._renamer.RenameInterface(interface)) | 1024 self._renamer.RenameInterface(interface)) |
| 999 | 1025 |
| 1000 type_data = _idl_type_registry.get(type_name) | 1026 type_data = _idl_type_registry.get(type_name) |
| 1001 if type_data.clazz == 'Interface': | 1027 if type_data.clazz == 'Interface': |
| 1002 if self._database.HasInterface(type_name): | 1028 if self._database.HasInterface(type_name): |
| 1003 dart_interface_name = self._renamer.RenameInterface( | 1029 dart_interface_name = self._renamer.RenameInterface( |
| 1004 self._database.GetInterface(type_name)) | 1030 self._database.GetInterface(type_name)) |
| 1005 else: | 1031 else: |
| 1006 dart_interface_name = type_name | 1032 dart_interface_name = type_name |
| 1007 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name) | 1033 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name) |
| 1008 | 1034 |
| 1009 class_name = '%sIDLTypeInfo' % type_data.clazz | 1035 class_name = '%sIDLTypeInfo' % type_data.clazz |
| 1010 return globals()[class_name](type_name, type_data) | 1036 return globals()[class_name](type_name, type_data) |
| OLD | NEW |