| 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 |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 | 629 |
| 630 def interface_name(self): | 630 def interface_name(self): |
| 631 raise NotImplementedError() | 631 raise NotImplementedError() |
| 632 | 632 |
| 633 def implementation_name(self): | 633 def implementation_name(self): |
| 634 raise NotImplementedError() | 634 raise NotImplementedError() |
| 635 | 635 |
| 636 def has_generated_interface(self): | 636 def has_generated_interface(self): |
| 637 raise NotImplementedError() | 637 raise NotImplementedError() |
| 638 | 638 |
| 639 def merged_interface(self): |
| 640 return None |
| 641 |
| 642 def merged_into(self): |
| 643 return None |
| 644 |
| 639 def native_type(self): | 645 def native_type(self): |
| 640 return self._data.native_type or self._idl_type | 646 return self._data.native_type or self._idl_type |
| 641 | 647 |
| 642 def bindings_class(self): | 648 def bindings_class(self): |
| 643 return 'Dart%s' % self.idl_type() | 649 return 'Dart%s' % self.idl_type() |
| 644 | 650 |
| 645 def vector_to_dart_template_parameter(self): | 651 def vector_to_dart_template_parameter(self): |
| 646 return self.bindings_class() | 652 return self.bindings_class() |
| 647 | 653 |
| 648 def requires_v8_scope(self): | 654 def requires_v8_scope(self): |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 | 741 |
| 736 def interface_name(self): | 742 def interface_name(self): |
| 737 return self._dart_interface_name | 743 return self._dart_interface_name |
| 738 | 744 |
| 739 def implementation_name(self): | 745 def implementation_name(self): |
| 740 return ImplementationClassNameForInterfaceName(self._dart_interface_name) | 746 return ImplementationClassNameForInterfaceName(self._dart_interface_name) |
| 741 | 747 |
| 742 def has_generated_interface(self): | 748 def has_generated_interface(self): |
| 743 return True | 749 return True |
| 744 | 750 |
| 751 def merged_interface(self): |
| 752 # All constants, attributes, and operations of merged interface should be |
| 753 # added to this interface. Merged idl interface does not have corresponding |
| 754 # Dart generated interface, and all references to merged idl interface |
| 755 # (e.g. parameter types, return types, parent interfaces) should be replaced |
| 756 # with this interface. There are two important restrictions: |
| 757 # 1) Merged and target interfaces shouldn't have common members, otherwise |
| 758 # there would be duplicated declarations in generated Dart code. |
| 759 # 2) Merged interface should be direct child of target interface, so the |
| 760 # children of merged interface are not affected by the merge. |
| 761 # As a consequence, target interface implementation and its direct children |
| 762 # interface implementations should implement merged attribute accessors and |
| 763 # operations. For example, SVGElement and Element implementation classes |
| 764 # should implement HTMLElement.insertAdjacentElement(), |
| 765 # HTMLElement.innerHTML, etc. |
| 766 return self._data.merged_interface |
| 767 |
| 768 def merged_into(self): |
| 769 return self._data.merged_into |
| 770 |
| 745 | 771 |
| 746 class CallbackIDLTypeInfo(IDLTypeInfo): | 772 class CallbackIDLTypeInfo(IDLTypeInfo): |
| 747 def __init__(self, idl_type, data): | 773 def __init__(self, idl_type, data): |
| 748 super(CallbackIDLTypeInfo, self).__init__(idl_type, data) | 774 super(CallbackIDLTypeInfo, self).__init__(idl_type, data) |
| 749 | 775 |
| 750 | 776 |
| 751 # Type info for DOM types that are converted to dart lists and therefore whose | 777 # Type info for DOM types that are converted to dart lists and therefore whose |
| 752 # actual interface generation should be suppressed. For type information, we | 778 # actual interface generation should be suppressed. For type information, we |
| 753 # still generate the implementations though, so these types should not be | 779 # still generate the implementations though, so these types should not be |
| 754 # suppressed entirely. | 780 # suppressed entirely. |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 conversion_cast = 'static_cast<%s*>(%s)' | 923 conversion_cast = 'static_cast<%s*>(%s)' |
| 898 conversion_cast = conversion_cast % (self.native_type(), value) | 924 conversion_cast = conversion_cast % (self.native_type(), value) |
| 899 return 'Dart%s::toDart(%s)' % (self._idl_type, conversion_cast) | 925 return 'Dart%s::toDart(%s)' % (self._idl_type, conversion_cast) |
| 900 | 926 |
| 901 def argument_expression(self, name, interface_name): | 927 def argument_expression(self, name, interface_name): |
| 902 return name if interface_name.endswith('List') else '%s->propertyReference()
' % name | 928 return name if interface_name.endswith('List') else '%s->propertyReference()
' % name |
| 903 | 929 |
| 904 | 930 |
| 905 class TypeData(object): | 931 class TypeData(object): |
| 906 def __init__(self, clazz, dart_type=None, native_type=None, | 932 def __init__(self, clazz, dart_type=None, native_type=None, |
| 933 merged_interface=None, merged_into=None, |
| 907 custom_to_dart=None, custom_to_native=None, | 934 custom_to_dart=None, custom_to_native=None, |
| 908 conversion_includes=None, | 935 conversion_includes=None, |
| 909 webcore_getter_name='getAttribute', | 936 webcore_getter_name='getAttribute', |
| 910 webcore_setter_name='setAttribute', | 937 webcore_setter_name='setAttribute', |
| 911 requires_v8_scope=False, | 938 requires_v8_scope=False, |
| 912 item_type=None): | 939 item_type=None): |
| 913 self.clazz = clazz | 940 self.clazz = clazz |
| 914 self.dart_type = dart_type | 941 self.dart_type = dart_type |
| 915 self.native_type = native_type | 942 self.native_type = native_type |
| 943 self.merged_interface = merged_interface |
| 944 self.merged_into = merged_into |
| 916 self.custom_to_dart = custom_to_dart | 945 self.custom_to_dart = custom_to_dart |
| 917 self.custom_to_native = custom_to_native | 946 self.custom_to_native = custom_to_native |
| 918 self.conversion_includes = conversion_includes | 947 self.conversion_includes = conversion_includes |
| 919 self.webcore_getter_name = webcore_getter_name | 948 self.webcore_getter_name = webcore_getter_name |
| 920 self.webcore_setter_name = webcore_setter_name | 949 self.webcore_setter_name = webcore_setter_name |
| 921 self.requires_v8_scope = requires_v8_scope | 950 self.requires_v8_scope = requires_v8_scope |
| 922 self.item_type = item_type | 951 self.item_type = item_type |
| 923 | 952 |
| 924 | 953 |
| 925 _idl_type_registry = { | 954 _idl_type_registry = { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 'WebKitFlags': TypeData(clazz='Primitive', dart_type='Object'), | 1000 'WebKitFlags': TypeData(clazz='Primitive', dart_type='Object'), |
| 972 | 1001 |
| 973 'sequence': TypeData(clazz='Primitive', dart_type='List'), | 1002 'sequence': TypeData(clazz='Primitive', dart_type='List'), |
| 974 'void': TypeData(clazz='Primitive', dart_type='void'), | 1003 'void': TypeData(clazz='Primitive', dart_type='void'), |
| 975 | 1004 |
| 976 'CSSRule': TypeData(clazz='Interface', conversion_includes=['CSSImportRule']
), | 1005 'CSSRule': TypeData(clazz='Interface', conversion_includes=['CSSImportRule']
), |
| 977 'DOMException': TypeData(clazz='Interface', native_type='DOMCoreException'), | 1006 'DOMException': TypeData(clazz='Interface', native_type='DOMCoreException'), |
| 978 'DOMStringList': TypeData(clazz='Interface', dart_type='List<String>', custo
m_to_native=True), | 1007 'DOMStringList': TypeData(clazz='Interface', dart_type='List<String>', custo
m_to_native=True), |
| 979 'DOMStringMap': TypeData(clazz='Interface', dart_type='Map<String, String>')
, | 1008 'DOMStringMap': TypeData(clazz='Interface', dart_type='Map<String, String>')
, |
| 980 'DOMWindow': TypeData(clazz='Interface', custom_to_dart=True), | 1009 'DOMWindow': TypeData(clazz='Interface', custom_to_dart=True), |
| 981 'Element': TypeData(clazz='Interface', custom_to_dart=True), | 1010 'Document': TypeData(clazz='Interface', merged_interface='HTMLDocument'), |
| 1011 'Element': TypeData(clazz='Interface', merged_interface='HTMLElement', |
| 1012 custom_to_dart=True), |
| 982 'EventListener': TypeData(clazz='Interface', custom_to_native=True), | 1013 'EventListener': TypeData(clazz='Interface', custom_to_native=True), |
| 983 'EventTarget': TypeData(clazz='Interface', custom_to_native=True), | 1014 'EventTarget': TypeData(clazz='Interface', custom_to_native=True), |
| 984 'HTMLElement': TypeData(clazz='Interface', custom_to_dart=True), | 1015 'HTMLDocument': TypeData(clazz='Interface', merged_into='Document'), |
| 1016 'HTMLElement': TypeData(clazz='Interface', merged_into='Element', |
| 1017 custom_to_dart=True), |
| 985 'IDBAny': TypeData(clazz='Interface', dart_type='Dynamic', custom_to_native=
True), | 1018 'IDBAny': TypeData(clazz='Interface', dart_type='Dynamic', custom_to_native=
True), |
| 986 'IDBKey': TypeData(clazz='Interface', dart_type='Dynamic', custom_to_native=
True), | 1019 'IDBKey': TypeData(clazz='Interface', dart_type='Dynamic', custom_to_native=
True), |
| 987 'MutationRecordArray': TypeData(clazz='Interface', # C++ pass by pointer. | 1020 'MutationRecordArray': TypeData(clazz='Interface', # C++ pass by pointer. |
| 988 native_type='MutationRecordArray', dart_type='List<MutationRecord>'), | 1021 native_type='MutationRecordArray', dart_type='List<MutationRecord>'), |
| 989 'StyleSheet': TypeData(clazz='Interface', conversion_includes=['CSSStyleShee
t']), | 1022 'StyleSheet': TypeData(clazz='Interface', conversion_includes=['CSSStyleShee
t']), |
| 990 'SVGElement': TypeData(clazz='Interface', custom_to_dart=True), | 1023 'SVGElement': TypeData(clazz='Interface', custom_to_dart=True), |
| 991 | 1024 |
| 992 'ClientRectList': TypeData(clazz='ListLike', item_type='ClientRect'), | 1025 'ClientRectList': TypeData(clazz='ListLike', item_type='ClientRect'), |
| 993 'CSSRuleList': TypeData(clazz='ListLike', item_type='CSSRule'), | 1026 'CSSRuleList': TypeData(clazz='ListLike', item_type='CSSRule'), |
| 994 'CSSValueList': TypeData(clazz='ListLike', item_type='CSSValue'), | 1027 'CSSValueList': TypeData(clazz='ListLike', item_type='CSSValue'), |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1072 self._database.GetInterface(type_name)) | 1105 self._database.GetInterface(type_name)) |
| 1073 else: | 1106 else: |
| 1074 dart_interface_name = type_name | 1107 dart_interface_name = type_name |
| 1075 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name) | 1108 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name) |
| 1076 | 1109 |
| 1077 if type_data.clazz == 'ListLike': | 1110 if type_data.clazz == 'ListLike': |
| 1078 return ListLikeIDLTypeInfo(type_name, type_data, self.TypeInfo(type_data.i
tem_type)) | 1111 return ListLikeIDLTypeInfo(type_name, type_data, self.TypeInfo(type_data.i
tem_type)) |
| 1079 | 1112 |
| 1080 class_name = '%sIDLTypeInfo' % type_data.clazz | 1113 class_name = '%sIDLTypeInfo' % type_data.clazz |
| 1081 return globals()[class_name](type_name, type_data) | 1114 return globals()[class_name](type_name, type_data) |
| OLD | NEW |