| 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 json | 10 import json |
| (...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 def receiver(self): | 702 def receiver(self): |
| 703 return 'receiver->' | 703 return 'receiver->' |
| 704 | 704 |
| 705 def conversion_includes(self): | 705 def conversion_includes(self): |
| 706 includes = [self._idl_type] + (self._data.conversion_includes or []) | 706 includes = [self._idl_type] + (self._data.conversion_includes or []) |
| 707 return ['"Dart%s.h"' % include for include in includes] | 707 return ['"Dart%s.h"' % include for include in includes] |
| 708 | 708 |
| 709 def to_dart_conversion(self, value, interface_name=None, attributes=None): | 709 def to_dart_conversion(self, value, interface_name=None, attributes=None): |
| 710 return 'Dart%s::toDart(%s)' % (self._idl_type, value) | 710 return 'Dart%s::toDart(%s)' % (self._idl_type, value) |
| 711 | 711 |
| 712 def return_to_dart_conversion(self, value, |
| 713 interface_name=None, attributes=None): |
| 714 return 'Dart%s::returnToDart(args, %s)' % (self._idl_type, value) |
| 715 |
| 712 def custom_to_dart(self): | 716 def custom_to_dart(self): |
| 713 return self._data.custom_to_dart | 717 return self._data.custom_to_dart |
| 714 | 718 |
| 715 | 719 |
| 716 class InterfaceIDLTypeInfo(IDLTypeInfo): | 720 class InterfaceIDLTypeInfo(IDLTypeInfo): |
| 717 def __init__(self, idl_type, data, dart_interface_name, type_registry): | 721 def __init__(self, idl_type, data, dart_interface_name, type_registry): |
| 718 super(InterfaceIDLTypeInfo, self).__init__(idl_type, data) | 722 super(InterfaceIDLTypeInfo, self).__init__(idl_type, data) |
| 719 self._dart_interface_name = dart_interface_name | 723 self._dart_interface_name = dart_interface_name |
| 720 self._type_registry = type_registry | 724 self._type_registry = type_registry |
| 721 | 725 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 | 829 |
| 826 return native_type | 830 return native_type |
| 827 | 831 |
| 828 def pass_native_by_ref(self): return True | 832 def pass_native_by_ref(self): return True |
| 829 | 833 |
| 830 def to_dart_conversion(self, value, interface_name=None, attributes=None): | 834 def to_dart_conversion(self, value, interface_name=None, attributes=None): |
| 831 if isinstance(self._item_info, PrimitiveIDLTypeInfo): | 835 if isinstance(self._item_info, PrimitiveIDLTypeInfo): |
| 832 return 'DartDOMWrapper::vectorToDart(%s)' % value | 836 return 'DartDOMWrapper::vectorToDart(%s)' % value |
| 833 return 'DartDOMWrapper::vectorToDart<%s>(%s)' % (self._item_info.bindings_cl
ass(), value) | 837 return 'DartDOMWrapper::vectorToDart<%s>(%s)' % (self._item_info.bindings_cl
ass(), value) |
| 834 | 838 |
| 839 def return_to_dart_conversion(self, value, |
| 840 interface_name=None, attributes=None): |
| 841 return 'Dart_SetReturnValue(args, %s)' % self.to_dart_conversion( |
| 842 value, |
| 843 interface_name, |
| 844 attributes) |
| 845 |
| 835 def conversion_includes(self): | 846 def conversion_includes(self): |
| 836 return self._item_info.conversion_includes() | 847 return self._item_info.conversion_includes() |
| 837 | 848 |
| 838 | 849 |
| 839 class DOMStringArrayTypeInfo(SequenceIDLTypeInfo): | 850 class DOMStringArrayTypeInfo(SequenceIDLTypeInfo): |
| 840 def __init__(self, data, item_info): | 851 def __init__(self, data, item_info): |
| 841 super(DOMStringArrayTypeInfo, self).__init__('DOMString[]', data, item_info) | 852 super(DOMStringArrayTypeInfo, self).__init__('DOMString[]', data, item_info) |
| 842 | 853 |
| 843 def to_native_info(self, idl_node, interface_name): | 854 def to_native_info(self, idl_node, interface_name): |
| 844 return '%s', 'RefPtr<DOMStringList>', 'DartDOMStringList', 'toNative' | 855 return '%s', 'RefPtr<DOMStringList>', 'DartDOMStringList', 'toNative' |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 if self.idl_type() == 'Date': | 893 if self.idl_type() == 'Date': |
| 883 function_name = 'date' | 894 function_name = 'date' |
| 884 else: | 895 else: |
| 885 function_name = self._capitalized_native_type() | 896 function_name = self._capitalized_native_type() |
| 886 function_name = function_name[0].lower() + function_name[1:] | 897 function_name = function_name[0].lower() + function_name[1:] |
| 887 function_name = 'DartUtilities::%sToDart' % function_name | 898 function_name = 'DartUtilities::%sToDart' % function_name |
| 888 if attributes and 'TreatReturnedNullStringAs' in attributes: | 899 if attributes and 'TreatReturnedNullStringAs' in attributes: |
| 889 function_name += 'WithNullCheck' | 900 function_name += 'WithNullCheck' |
| 890 return '%s(%s)' % (function_name, value) | 901 return '%s(%s)' % (function_name, value) |
| 891 | 902 |
| 903 def return_to_dart_conversion(self, value, |
| 904 interface_name=None, attributes=None): |
| 905 return 'Dart_SetReturnValue(args, %s)' % self.to_dart_conversion( |
| 906 value, |
| 907 interface_name, |
| 908 attributes) |
| 909 |
| 892 def webcore_getter_name(self): | 910 def webcore_getter_name(self): |
| 893 return self._data.webcore_getter_name | 911 return self._data.webcore_getter_name |
| 894 | 912 |
| 895 def webcore_setter_name(self): | 913 def webcore_setter_name(self): |
| 896 return self._data.webcore_setter_name | 914 return self._data.webcore_setter_name |
| 897 | 915 |
| 898 def _capitalized_native_type(self): | 916 def _capitalized_native_type(self): |
| 899 return re.sub(r'(^| )([a-z])', lambda x: x.group(2).upper(), self.native_typ
e()) | 917 return re.sub(r'(^| )([a-z])', lambda x: x.group(2).upper(), self.native_typ
e()) |
| 900 | 918 |
| 901 | 919 |
| 902 class SVGTearOffIDLTypeInfo(InterfaceIDLTypeInfo): | 920 class SVGTearOffIDLTypeInfo(InterfaceIDLTypeInfo): |
| 903 def __init__(self, idl_type, data, interface_name, type_registry): | 921 def __init__(self, idl_type, data, interface_name, type_registry): |
| 904 super(SVGTearOffIDLTypeInfo, self).__init__( | 922 super(SVGTearOffIDLTypeInfo, self).__init__( |
| 905 idl_type, data, interface_name, type_registry) | 923 idl_type, data, interface_name, type_registry) |
| 906 | 924 |
| 907 def native_type(self): | 925 def native_type(self): |
| 908 if self._data.native_type: | 926 if self._data.native_type: |
| 909 return self._data.native_type | 927 return self._data.native_type |
| 910 tear_off_type = 'SVGPropertyTearOff' | 928 tear_off_type = 'SVGPropertyTearOff' |
| 911 if self._idl_type.endswith('List'): | 929 if self._idl_type.endswith('List'): |
| 912 tear_off_type = 'SVGListPropertyTearOff' | 930 tear_off_type = 'SVGListPropertyTearOff' |
| 913 return '%s<%s>' % (tear_off_type, self._idl_type) | 931 return '%s<%s>' % (tear_off_type, self._idl_type) |
| 914 | 932 |
| 915 def receiver(self): | 933 def receiver(self): |
| 916 if self._idl_type.endswith('List'): | 934 if self._idl_type.endswith('List'): |
| 917 return 'receiver->' | 935 return 'receiver->' |
| 918 return 'receiver->propertyReference().' | 936 return 'receiver->propertyReference().' |
| 919 | 937 |
| 920 def to_dart_conversion(self, value, interface_name, attributes): | 938 def to_conversion_cast(self, value, interface_name, attributes): |
| 921 svg_primitive_types = ['SVGAngle', 'SVGLength', 'SVGMatrix', | 939 svg_primitive_types = ['SVGAngle', 'SVGLength', 'SVGMatrix', |
| 922 'SVGNumber', 'SVGPoint', 'SVGRect', 'SVGTransform'] | 940 'SVGNumber', 'SVGPoint', 'SVGRect', 'SVGTransform'] |
| 923 conversion_cast = '%s::create(%s)' | 941 conversion_cast = '%s::create(%s)' |
| 924 if interface_name.startswith('SVGAnimated'): | 942 if interface_name.startswith('SVGAnimated'): |
| 925 conversion_cast = 'static_cast<%s*>(%s)' | 943 conversion_cast = 'static_cast<%s*>(%s)' |
| 926 elif self.idl_type() == 'SVGStringList': | 944 elif self.idl_type() == 'SVGStringList': |
| 927 conversion_cast = '%s::create(receiver, %s)' | 945 conversion_cast = '%s::create(receiver, %s)' |
| 928 elif interface_name.endswith('List'): | 946 elif interface_name.endswith('List'): |
| 929 conversion_cast = 'static_cast<%s*>(%s.get())' | 947 conversion_cast = 'static_cast<%s*>(%s.get())' |
| 930 elif self.idl_type() in svg_primitive_types: | 948 elif self.idl_type() in svg_primitive_types: |
| 931 conversion_cast = '%s::create(%s)' | 949 conversion_cast = '%s::create(%s)' |
| 932 else: | 950 else: |
| 933 conversion_cast = 'static_cast<%s*>(%s)' | 951 conversion_cast = 'static_cast<%s*>(%s)' |
| 934 conversion_cast = conversion_cast % (self.native_type(), value) | 952 conversion_cast = conversion_cast % (self.native_type(), value) |
| 935 return 'Dart%s::toDart(%s)' % (self._idl_type, conversion_cast) | 953 return '%s' % (conversion_cast) |
| 954 |
| 955 def to_dart_conversion(self, value, interface_name, attributes): |
| 956 return 'Dart%s::toDart(%s)' % (self._idl_type, self.to_conversion_cast(value
, interface_name, attributes)) |
| 957 |
| 958 def return_to_dart_conversion(self, value, interface_name, attr): |
| 959 return 'Dart%s::returnToDart(args, %s)' % (self._idl_type, |
| 960 self.to_conversion_cast( |
| 961 value, |
| 962 interface_name, |
| 963 attr)) |
| 936 | 964 |
| 937 def argument_expression(self, name, interface_name): | 965 def argument_expression(self, name, interface_name): |
| 938 return name if interface_name.endswith('List') else '%s->propertyReference()
' % name | 966 return name if interface_name.endswith('List') else '%s->propertyReference()
' % name |
| 939 | 967 |
| 940 | 968 |
| 941 class TypedListIDLTypeInfo(InterfaceIDLTypeInfo): | 969 class TypedListIDLTypeInfo(InterfaceIDLTypeInfo): |
| 942 def __init__(self, idl_type, data, interface_name, type_registry): | 970 def __init__(self, idl_type, data, interface_name, type_registry): |
| 943 super(TypedListIDLTypeInfo, self).__init__( | 971 super(TypedListIDLTypeInfo, self).__init__( |
| 944 idl_type, data, interface_name, type_registry) | 972 idl_type, data, interface_name, type_registry) |
| 945 | 973 |
| 946 def conversion_includes(self): | 974 def conversion_includes(self): |
| 947 return [ '"wtf/%s.h"' % self._idl_type ] | 975 return [ '"wtf/%s.h"' % self._idl_type ] |
| 948 | 976 |
| 949 def to_dart_conversion(self, value, interface_name, attributes): | 977 def to_dart_conversion(self, value, interface_name, attributes): |
| 950 return 'DartUtilities::arrayBufferViewToDart(%s)' % value | 978 return 'DartUtilities::arrayBufferViewToDart(%s)' % value |
| 951 | 979 |
| 980 def return_to_dart_conversion(self, value, interface_name, attributes): |
| 981 return 'Dart_SetReturnValue(args, %s)' % self.to_dart_conversion( |
| 982 value, |
| 983 interface_name, |
| 984 attributes) |
| 985 |
| 952 def to_native_info(self, idl_node, interface_name): | 986 def to_native_info(self, idl_node, interface_name): |
| 953 return '%s.get()', 'RefPtr<%s>' % self._idl_type, 'DartUtilities', 'dartTo%s
' % self._idl_type | 987 return '%s.get()', 'RefPtr<%s>' % self._idl_type, 'DartUtilities', 'dartTo%s
' % self._idl_type |
| 954 | 988 |
| 955 | 989 |
| 956 class BasicTypedListIDLTypeInfo(InterfaceIDLTypeInfo): | 990 class BasicTypedListIDLTypeInfo(InterfaceIDLTypeInfo): |
| 957 def __init__(self, idl_type, data, interface_name, type_registry): | 991 def __init__(self, idl_type, data, interface_name, type_registry): |
| 958 super(BasicTypedListIDLTypeInfo, self).__init__( | 992 super(BasicTypedListIDLTypeInfo, self).__init__( |
| 959 idl_type, data, interface_name, type_registry) | 993 idl_type, data, interface_name, type_registry) |
| 960 | 994 |
| 961 def conversion_includes(self): | 995 def conversion_includes(self): |
| 962 return [] | 996 return [] |
| 963 | 997 |
| 964 def to_dart_conversion(self, value, interface_name, attributes): | 998 def to_dart_conversion(self, value, interface_name, attributes): |
| 965 function_name = 'DartUtilities::%sToDart' % self._idl_type | 999 function_name = 'DartUtilities::%sToDart' % self._idl_type |
| 966 function_name = function_name[0].lower() + function_name[1:] | 1000 function_name = function_name[0].lower() + function_name[1:] |
| 967 return '%s(%s)' % (function_name, value) | 1001 return '%s(%s)' % (function_name, value) |
| 968 | 1002 |
| 1003 def return_to_dart_conversion(self, value, interface_name, attributes): |
| 1004 return 'Dart_SetReturnValue(args, %s)' % self.to_dart_conversion( |
| 1005 value, |
| 1006 interface_name, |
| 1007 attributes) |
| 1008 |
| 969 def to_native_info(self, idl_node, interface_name): | 1009 def to_native_info(self, idl_node, interface_name): |
| 970 return '%s.get()', 'RefPtr<%s>' % self._idl_type, 'DartUtilities', 'dartTo%s
' % self._idl_type | 1010 return '%s.get()', 'RefPtr<%s>' % self._idl_type, 'DartUtilities', 'dartTo%s
' % self._idl_type |
| 971 | 1011 |
| 972 | 1012 |
| 973 class TypeData(object): | 1013 class TypeData(object): |
| 974 def __init__(self, clazz, dart_type=None, native_type=None, | 1014 def __init__(self, clazz, dart_type=None, native_type=None, |
| 975 merged_interface=None, merged_into=None, | 1015 merged_interface=None, merged_into=None, |
| 976 custom_to_dart=False, custom_to_native=False, | 1016 custom_to_dart=False, custom_to_native=False, |
| 977 conversion_includes=None, | 1017 conversion_includes=None, |
| 978 webcore_getter_name='getAttribute', | 1018 webcore_getter_name='getAttribute', |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1199 if type_data.clazz == 'BasicTypedList': | 1239 if type_data.clazz == 'BasicTypedList': |
| 1200 if type_name == 'ArrayBuffer': | 1240 if type_name == 'ArrayBuffer': |
| 1201 dart_interface_name = 'ByteBuffer' | 1241 dart_interface_name = 'ByteBuffer' |
| 1202 else: | 1242 else: |
| 1203 dart_interface_name = self._renamer.RenameInterfaceId(type_name) | 1243 dart_interface_name = self._renamer.RenameInterfaceId(type_name) |
| 1204 return BasicTypedListIDLTypeInfo( | 1244 return BasicTypedListIDLTypeInfo( |
| 1205 type_name, type_data, dart_interface_name, self) | 1245 type_name, type_data, dart_interface_name, self) |
| 1206 | 1246 |
| 1207 class_name = '%sIDLTypeInfo' % type_data.clazz | 1247 class_name = '%sIDLTypeInfo' % type_data.clazz |
| 1208 return globals()[class_name](type_name, type_data) | 1248 return globals()[class_name](type_name, type_data) |
| OLD | NEW |