Chromium Code Reviews| 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, interface_name=None, attributes=Non e): | |
|
vsm
2013/09/19 21:05:57
nit: line len
siva
2013/09/19 23:50:34
Done.
| |
| 713 return 'Dart%s::returnToDart(args, %s)' % (self._idl_type, value) | |
| 714 | |
| 712 def custom_to_dart(self): | 715 def custom_to_dart(self): |
| 713 return self._data.custom_to_dart | 716 return self._data.custom_to_dart |
| 714 | 717 |
| 715 | 718 |
| 716 class InterfaceIDLTypeInfo(IDLTypeInfo): | 719 class InterfaceIDLTypeInfo(IDLTypeInfo): |
| 717 def __init__(self, idl_type, data, dart_interface_name, type_registry): | 720 def __init__(self, idl_type, data, dart_interface_name, type_registry): |
| 718 super(InterfaceIDLTypeInfo, self).__init__(idl_type, data) | 721 super(InterfaceIDLTypeInfo, self).__init__(idl_type, data) |
| 719 self._dart_interface_name = dart_interface_name | 722 self._dart_interface_name = dart_interface_name |
| 720 self._type_registry = type_registry | 723 self._type_registry = type_registry |
| 721 | 724 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 825 | 828 |
| 826 return native_type | 829 return native_type |
| 827 | 830 |
| 828 def pass_native_by_ref(self): return True | 831 def pass_native_by_ref(self): return True |
| 829 | 832 |
| 830 def to_dart_conversion(self, value, interface_name=None, attributes=None): | 833 def to_dart_conversion(self, value, interface_name=None, attributes=None): |
| 831 if isinstance(self._item_info, PrimitiveIDLTypeInfo): | 834 if isinstance(self._item_info, PrimitiveIDLTypeInfo): |
| 832 return 'DartDOMWrapper::vectorToDart(%s)' % value | 835 return 'DartDOMWrapper::vectorToDart(%s)' % value |
| 833 return 'DartDOMWrapper::vectorToDart<%s>(%s)' % (self._item_info.bindings_cl ass(), value) | 836 return 'DartDOMWrapper::vectorToDart<%s>(%s)' % (self._item_info.bindings_cl ass(), value) |
| 834 | 837 |
| 838 def return_to_dart_conversion(self, value, interface_name=None, attributes=Non e): | |
| 839 return 'Dart_SetReturnValue(args, %s)' % self.to_dart_conversion(value, inte rface_name, attributes) | |
|
vsm
2013/09/19 21:05:57
line len
siva
2013/09/19 23:50:34
Done.
| |
| 840 | |
| 835 def conversion_includes(self): | 841 def conversion_includes(self): |
| 836 return self._item_info.conversion_includes() | 842 return self._item_info.conversion_includes() |
| 837 | 843 |
| 838 | 844 |
| 839 class DOMStringArrayTypeInfo(SequenceIDLTypeInfo): | 845 class DOMStringArrayTypeInfo(SequenceIDLTypeInfo): |
| 840 def __init__(self, data, item_info): | 846 def __init__(self, data, item_info): |
| 841 super(DOMStringArrayTypeInfo, self).__init__('DOMString[]', data, item_info) | 847 super(DOMStringArrayTypeInfo, self).__init__('DOMString[]', data, item_info) |
| 842 | 848 |
| 843 def to_native_info(self, idl_node, interface_name): | 849 def to_native_info(self, idl_node, interface_name): |
| 844 return '%s', 'RefPtr<DOMStringList>', 'DartDOMStringList', 'toNative' | 850 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': | 888 if self.idl_type() == 'Date': |
| 883 function_name = 'date' | 889 function_name = 'date' |
| 884 else: | 890 else: |
| 885 function_name = self._capitalized_native_type() | 891 function_name = self._capitalized_native_type() |
| 886 function_name = function_name[0].lower() + function_name[1:] | 892 function_name = function_name[0].lower() + function_name[1:] |
| 887 function_name = 'DartUtilities::%sToDart' % function_name | 893 function_name = 'DartUtilities::%sToDart' % function_name |
| 888 if attributes and 'TreatReturnedNullStringAs' in attributes: | 894 if attributes and 'TreatReturnedNullStringAs' in attributes: |
| 889 function_name += 'WithNullCheck' | 895 function_name += 'WithNullCheck' |
| 890 return '%s(%s)' % (function_name, value) | 896 return '%s(%s)' % (function_name, value) |
| 891 | 897 |
| 898 def return_to_dart_conversion(self, value, interface_name=None, attributes=Non e): | |
| 899 return 'Dart_SetReturnValue(args, %s)' % self.to_dart_conversion(value, inte rface_name, attributes) | |
| 900 | |
| 892 def webcore_getter_name(self): | 901 def webcore_getter_name(self): |
| 893 return self._data.webcore_getter_name | 902 return self._data.webcore_getter_name |
| 894 | 903 |
| 895 def webcore_setter_name(self): | 904 def webcore_setter_name(self): |
| 896 return self._data.webcore_setter_name | 905 return self._data.webcore_setter_name |
| 897 | 906 |
| 898 def _capitalized_native_type(self): | 907 def _capitalized_native_type(self): |
| 899 return re.sub(r'(^| )([a-z])', lambda x: x.group(2).upper(), self.native_typ e()) | 908 return re.sub(r'(^| )([a-z])', lambda x: x.group(2).upper(), self.native_typ e()) |
| 900 | 909 |
| 901 | 910 |
| 902 class SVGTearOffIDLTypeInfo(InterfaceIDLTypeInfo): | 911 class SVGTearOffIDLTypeInfo(InterfaceIDLTypeInfo): |
| 903 def __init__(self, idl_type, data, interface_name, type_registry): | 912 def __init__(self, idl_type, data, interface_name, type_registry): |
| 904 super(SVGTearOffIDLTypeInfo, self).__init__( | 913 super(SVGTearOffIDLTypeInfo, self).__init__( |
| 905 idl_type, data, interface_name, type_registry) | 914 idl_type, data, interface_name, type_registry) |
| 906 | 915 |
| 907 def native_type(self): | 916 def native_type(self): |
| 908 if self._data.native_type: | 917 if self._data.native_type: |
| 909 return self._data.native_type | 918 return self._data.native_type |
| 910 tear_off_type = 'SVGPropertyTearOff' | 919 tear_off_type = 'SVGPropertyTearOff' |
| 911 if self._idl_type.endswith('List'): | 920 if self._idl_type.endswith('List'): |
| 912 tear_off_type = 'SVGListPropertyTearOff' | 921 tear_off_type = 'SVGListPropertyTearOff' |
| 913 return '%s<%s>' % (tear_off_type, self._idl_type) | 922 return '%s<%s>' % (tear_off_type, self._idl_type) |
| 914 | 923 |
| 915 def receiver(self): | 924 def receiver(self): |
| 916 if self._idl_type.endswith('List'): | 925 if self._idl_type.endswith('List'): |
| 917 return 'receiver->' | 926 return 'receiver->' |
| 918 return 'receiver->propertyReference().' | 927 return 'receiver->propertyReference().' |
| 919 | 928 |
| 920 def to_dart_conversion(self, value, interface_name, attributes): | 929 def to_conversion_cast(self, value, interface_name, attributes): |
| 921 svg_primitive_types = ['SVGAngle', 'SVGLength', 'SVGMatrix', | 930 svg_primitive_types = ['SVGAngle', 'SVGLength', 'SVGMatrix', |
| 922 'SVGNumber', 'SVGPoint', 'SVGRect', 'SVGTransform'] | 931 'SVGNumber', 'SVGPoint', 'SVGRect', 'SVGTransform'] |
| 923 conversion_cast = '%s::create(%s)' | 932 conversion_cast = '%s::create(%s)' |
| 924 if interface_name.startswith('SVGAnimated'): | 933 if interface_name.startswith('SVGAnimated'): |
| 925 conversion_cast = 'static_cast<%s*>(%s)' | 934 conversion_cast = 'static_cast<%s*>(%s)' |
| 926 elif self.idl_type() == 'SVGStringList': | 935 elif self.idl_type() == 'SVGStringList': |
| 927 conversion_cast = '%s::create(receiver, %s)' | 936 conversion_cast = '%s::create(receiver, %s)' |
| 928 elif interface_name.endswith('List'): | 937 elif interface_name.endswith('List'): |
| 929 conversion_cast = 'static_cast<%s*>(%s.get())' | 938 conversion_cast = 'static_cast<%s*>(%s.get())' |
| 930 elif self.idl_type() in svg_primitive_types: | 939 elif self.idl_type() in svg_primitive_types: |
| 931 conversion_cast = '%s::create(%s)' | 940 conversion_cast = '%s::create(%s)' |
| 932 else: | 941 else: |
| 933 conversion_cast = 'static_cast<%s*>(%s)' | 942 conversion_cast = 'static_cast<%s*>(%s)' |
| 934 conversion_cast = conversion_cast % (self.native_type(), value) | 943 conversion_cast = conversion_cast % (self.native_type(), value) |
| 935 return 'Dart%s::toDart(%s)' % (self._idl_type, conversion_cast) | 944 return '%s' % (conversion_cast) |
| 945 | |
| 946 def to_dart_conversion(self, value, interface_name, attributes): | |
| 947 return 'Dart%s::toDart(%s)' % (self._idl_type, self.to_conversion_cast(value , interface_name, attributes)) | |
| 948 | |
| 949 def return_to_dart_conversion(self, value, interface_name, attr): | |
| 950 return 'Dart%s::returnToDart(args, %s)' % (self._idl_type, self.to_conversio n_cast(value, interface_name, attr)) | |
| 936 | 951 |
| 937 def argument_expression(self, name, interface_name): | 952 def argument_expression(self, name, interface_name): |
| 938 return name if interface_name.endswith('List') else '%s->propertyReference() ' % name | 953 return name if interface_name.endswith('List') else '%s->propertyReference() ' % name |
| 939 | 954 |
| 940 | 955 |
| 941 class TypedListIDLTypeInfo(InterfaceIDLTypeInfo): | 956 class TypedListIDLTypeInfo(InterfaceIDLTypeInfo): |
| 942 def __init__(self, idl_type, data, interface_name, type_registry): | 957 def __init__(self, idl_type, data, interface_name, type_registry): |
| 943 super(TypedListIDLTypeInfo, self).__init__( | 958 super(TypedListIDLTypeInfo, self).__init__( |
| 944 idl_type, data, interface_name, type_registry) | 959 idl_type, data, interface_name, type_registry) |
| 945 | 960 |
| 946 def conversion_includes(self): | 961 def conversion_includes(self): |
| 947 return [ '"wtf/%s.h"' % self._idl_type ] | 962 return [ '"wtf/%s.h"' % self._idl_type ] |
| 948 | 963 |
| 949 def to_dart_conversion(self, value, interface_name, attributes): | 964 def to_dart_conversion(self, value, interface_name, attributes): |
| 950 return 'DartUtilities::arrayBufferViewToDart(%s)' % value | 965 return 'DartUtilities::arrayBufferViewToDart(%s)' % value |
| 951 | 966 |
| 967 def return_to_dart_conversion(self, value, interface_name, attributes): | |
| 968 return 'Dart_SetReturnValue(args, %s)' % self.to_dart_conversion(value, inte rface_name, attributes) | |
| 969 | |
| 952 def to_native_info(self, idl_node, interface_name): | 970 def to_native_info(self, idl_node, interface_name): |
| 953 return '%s.get()', 'RefPtr<%s>' % self._idl_type, 'DartUtilities', 'dartTo%s ' % self._idl_type | 971 return '%s.get()', 'RefPtr<%s>' % self._idl_type, 'DartUtilities', 'dartTo%s ' % self._idl_type |
| 954 | 972 |
| 955 | 973 |
| 956 class BasicTypedListIDLTypeInfo(InterfaceIDLTypeInfo): | 974 class BasicTypedListIDLTypeInfo(InterfaceIDLTypeInfo): |
| 957 def __init__(self, idl_type, data, interface_name, type_registry): | 975 def __init__(self, idl_type, data, interface_name, type_registry): |
| 958 super(BasicTypedListIDLTypeInfo, self).__init__( | 976 super(BasicTypedListIDLTypeInfo, self).__init__( |
| 959 idl_type, data, interface_name, type_registry) | 977 idl_type, data, interface_name, type_registry) |
| 960 | 978 |
| 961 def conversion_includes(self): | 979 def conversion_includes(self): |
| 962 return [] | 980 return [] |
| 963 | 981 |
| 964 def to_dart_conversion(self, value, interface_name, attributes): | 982 def to_dart_conversion(self, value, interface_name, attributes): |
| 965 function_name = 'DartUtilities::%sToDart' % self._idl_type | 983 function_name = 'DartUtilities::%sToDart' % self._idl_type |
| 966 function_name = function_name[0].lower() + function_name[1:] | 984 function_name = function_name[0].lower() + function_name[1:] |
| 967 return '%s(%s)' % (function_name, value) | 985 return '%s(%s)' % (function_name, value) |
| 968 | 986 |
| 987 def return_to_dart_conversion(self, value, interface_name, attributes): | |
| 988 return 'Dart_SetReturnValue(args, %s)' % self.to_dart_conversion(value, inte rface_name, attributes) | |
| 989 | |
| 969 def to_native_info(self, idl_node, interface_name): | 990 def to_native_info(self, idl_node, interface_name): |
| 970 return '%s.get()', 'RefPtr<%s>' % self._idl_type, 'DartUtilities', 'dartTo%s ' % self._idl_type | 991 return '%s.get()', 'RefPtr<%s>' % self._idl_type, 'DartUtilities', 'dartTo%s ' % self._idl_type |
| 971 | 992 |
| 972 | 993 |
| 973 class TypeData(object): | 994 class TypeData(object): |
| 974 def __init__(self, clazz, dart_type=None, native_type=None, | 995 def __init__(self, clazz, dart_type=None, native_type=None, |
| 975 merged_interface=None, merged_into=None, | 996 merged_interface=None, merged_into=None, |
| 976 custom_to_dart=False, custom_to_native=False, | 997 custom_to_dart=False, custom_to_native=False, |
| 977 conversion_includes=None, | 998 conversion_includes=None, |
| 978 webcore_getter_name='getAttribute', | 999 webcore_getter_name='getAttribute', |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1199 if type_data.clazz == 'BasicTypedList': | 1220 if type_data.clazz == 'BasicTypedList': |
| 1200 if type_name == 'ArrayBuffer': | 1221 if type_name == 'ArrayBuffer': |
| 1201 dart_interface_name = 'ByteBuffer' | 1222 dart_interface_name = 'ByteBuffer' |
| 1202 else: | 1223 else: |
| 1203 dart_interface_name = self._renamer.RenameInterfaceId(type_name) | 1224 dart_interface_name = self._renamer.RenameInterfaceId(type_name) |
| 1204 return BasicTypedListIDLTypeInfo( | 1225 return BasicTypedListIDLTypeInfo( |
| 1205 type_name, type_data, dart_interface_name, self) | 1226 type_name, type_data, dart_interface_name, self) |
| 1206 | 1227 |
| 1207 class_name = '%sIDLTypeInfo' % type_data.clazz | 1228 class_name = '%sIDLTypeInfo' % type_data.clazz |
| 1208 return globals()[class_name](type_name, type_data) | 1229 return globals()[class_name](type_name, type_data) |
| OLD | NEW |