| 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 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 def receiver(self): | 718 def receiver(self): |
| 719 return 'receiver->' | 719 return 'receiver->' |
| 720 | 720 |
| 721 def conversion_includes(self): | 721 def conversion_includes(self): |
| 722 includes = [self._idl_type] + (self._data.conversion_includes or []) | 722 includes = [self._idl_type] + (self._data.conversion_includes or []) |
| 723 return ['"Dart%s.h"' % include for include in includes] | 723 return ['"Dart%s.h"' % include for include in includes] |
| 724 | 724 |
| 725 def to_dart_conversion(self, value, interface_name=None, attributes=None): | 725 def to_dart_conversion(self, value, interface_name=None, attributes=None): |
| 726 return 'Dart%s::toDart(%s)' % (self._idl_type, value) | 726 return 'Dart%s::toDart(%s)' % (self._idl_type, value) |
| 727 | 727 |
| 728 def return_to_dart_conversion(self, value, | 728 def return_to_dart_conversion(self, value, auto_dart_scope_setup, |
| 729 interface_name=None, attributes=None): | 729 interface_name=None, attributes=None): |
| 730 return 'Dart%s::returnToDart(args, %s)' % (self._idl_type, value) | 730 auto_dart_scope='true' if auto_dart_scope_setup else 'false' |
| 731 return 'Dart%s::returnToDart(args, %s, %s)' % (self._idl_type, |
| 732 value, |
| 733 auto_dart_scope) |
| 731 | 734 |
| 732 def custom_to_dart(self): | 735 def custom_to_dart(self): |
| 733 return self._data.custom_to_dart | 736 return self._data.custom_to_dart |
| 734 | 737 |
| 735 | 738 |
| 736 class InterfaceIDLTypeInfo(IDLTypeInfo): | 739 class InterfaceIDLTypeInfo(IDLTypeInfo): |
| 737 def __init__(self, idl_type, data, dart_interface_name, type_registry): | 740 def __init__(self, idl_type, data, dart_interface_name, type_registry): |
| 738 super(InterfaceIDLTypeInfo, self).__init__(idl_type, data) | 741 super(InterfaceIDLTypeInfo, self).__init__(idl_type, data) |
| 739 self._dart_interface_name = dart_interface_name | 742 self._dart_interface_name = dart_interface_name |
| 740 self._type_registry = type_registry | 743 self._type_registry = type_registry |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 | 851 |
| 849 return native_type | 852 return native_type |
| 850 | 853 |
| 851 def pass_native_by_ref(self): return True | 854 def pass_native_by_ref(self): return True |
| 852 | 855 |
| 853 def to_dart_conversion(self, value, interface_name=None, attributes=None): | 856 def to_dart_conversion(self, value, interface_name=None, attributes=None): |
| 854 if isinstance(self._item_info, PrimitiveIDLTypeInfo): | 857 if isinstance(self._item_info, PrimitiveIDLTypeInfo): |
| 855 return 'DartDOMWrapper::vectorToDart(%s)' % value | 858 return 'DartDOMWrapper::vectorToDart(%s)' % value |
| 856 return 'DartDOMWrapper::vectorToDart<%s>(%s)' % (self._item_info.bindings_cl
ass(), value) | 859 return 'DartDOMWrapper::vectorToDart<%s>(%s)' % (self._item_info.bindings_cl
ass(), value) |
| 857 | 860 |
| 858 def return_to_dart_conversion(self, value, | 861 def return_to_dart_conversion(self, value, auto_dart_scope_setup=True, |
| 859 interface_name=None, attributes=None): | 862 interface_name=None, attributes=None): |
| 860 return 'Dart_SetReturnValue(args, %s)' % self.to_dart_conversion( | 863 return 'Dart_SetReturnValue(args, %s)' % self.to_dart_conversion( |
| 861 value, | 864 value, |
| 862 interface_name, | 865 interface_name, |
| 863 attributes) | 866 attributes) |
| 864 | 867 |
| 865 def conversion_includes(self): | 868 def conversion_includes(self): |
| 866 return self._item_info.conversion_includes() | 869 return self._item_info.conversion_includes() |
| 867 | 870 |
| 868 | 871 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 if self.idl_type() == 'Date': | 918 if self.idl_type() == 'Date': |
| 916 function_name = 'date' | 919 function_name = 'date' |
| 917 else: | 920 else: |
| 918 function_name = self._capitalized_native_type() | 921 function_name = self._capitalized_native_type() |
| 919 function_name = function_name[0].lower() + function_name[1:] | 922 function_name = function_name[0].lower() + function_name[1:] |
| 920 function_name = 'DartUtilities::%sToDart' % function_name | 923 function_name = 'DartUtilities::%sToDart' % function_name |
| 921 if attributes and 'TreatReturnedNullStringAs' in attributes: | 924 if attributes and 'TreatReturnedNullStringAs' in attributes: |
| 922 function_name += 'WithNullCheck' | 925 function_name += 'WithNullCheck' |
| 923 return '%s(%s)' % (function_name, value) | 926 return '%s(%s)' % (function_name, value) |
| 924 | 927 |
| 925 def return_to_dart_conversion(self, value, | 928 def return_to_dart_conversion(self, value, auto_dart_scope_setup=True, |
| 926 interface_name=None, attributes=None): | 929 interface_name=None, attributes=None): |
| 927 return 'Dart_SetReturnValue(args, %s)' % self.to_dart_conversion( | 930 return 'Dart_SetReturnValue(args, %s)' % self.to_dart_conversion( |
| 928 value, | 931 value, |
| 929 interface_name, | 932 interface_name, |
| 930 attributes) | 933 attributes) |
| 931 | 934 |
| 932 def webcore_getter_name(self): | 935 def webcore_getter_name(self): |
| 933 return self._data.webcore_getter_name | 936 return self._data.webcore_getter_name |
| 934 | 937 |
| 935 def webcore_setter_name(self): | 938 def webcore_setter_name(self): |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 elif self.idl_type() in svg_primitive_types: | 973 elif self.idl_type() in svg_primitive_types: |
| 971 conversion_cast = '%s::create(%s)' | 974 conversion_cast = '%s::create(%s)' |
| 972 else: | 975 else: |
| 973 conversion_cast = 'static_cast<%s*>(%s)' | 976 conversion_cast = 'static_cast<%s*>(%s)' |
| 974 conversion_cast = conversion_cast % (self.native_type(), value) | 977 conversion_cast = conversion_cast % (self.native_type(), value) |
| 975 return '%s' % (conversion_cast) | 978 return '%s' % (conversion_cast) |
| 976 | 979 |
| 977 def to_dart_conversion(self, value, interface_name, attributes): | 980 def to_dart_conversion(self, value, interface_name, attributes): |
| 978 return 'Dart%s::toDart(%s)' % (self._idl_type, self.to_conversion_cast(value
, interface_name, attributes)) | 981 return 'Dart%s::toDart(%s)' % (self._idl_type, self.to_conversion_cast(value
, interface_name, attributes)) |
| 979 | 982 |
| 980 def return_to_dart_conversion(self, value, interface_name, attr): | 983 def return_to_dart_conversion(self, value, auto_dart_scope_setup, |
| 981 return 'Dart%s::returnToDart(args, %s)' % (self._idl_type, | 984 interface_name, attr): |
| 982 self.to_conversion_cast( | 985 auto_dart_scope='true' if auto_dart_scope_setup else 'false' |
| 983 value, | 986 return 'Dart%s::returnToDart(args, %s, %s)' % (self._idl_type, |
| 984 interface_name, | 987 self.to_conversion_cast( |
| 985 attr)) | 988 value, |
| 989 interface_name, |
| 990 attr), |
| 991 auto_dart_scope) |
| 986 | 992 |
| 987 def argument_expression(self, name, interface_name): | 993 def argument_expression(self, name, interface_name): |
| 988 return name if interface_name.endswith('List') else '%s->propertyReference()
' % name | 994 return name if interface_name.endswith('List') else '%s->propertyReference()
' % name |
| 989 | 995 |
| 990 | 996 |
| 991 class TypedListIDLTypeInfo(InterfaceIDLTypeInfo): | 997 class TypedListIDLTypeInfo(InterfaceIDLTypeInfo): |
| 992 def __init__(self, idl_type, data, interface_name, type_registry): | 998 def __init__(self, idl_type, data, interface_name, type_registry): |
| 993 super(TypedListIDLTypeInfo, self).__init__( | 999 super(TypedListIDLTypeInfo, self).__init__( |
| 994 idl_type, data, interface_name, type_registry) | 1000 idl_type, data, interface_name, type_registry) |
| 995 | 1001 |
| 996 def conversion_includes(self): | 1002 def conversion_includes(self): |
| 997 return [ '"wtf/%s.h"' % self._idl_type ] | 1003 return [ '"wtf/%s.h"' % self._idl_type ] |
| 998 | 1004 |
| 999 def to_dart_conversion(self, value, interface_name, attributes): | 1005 def to_dart_conversion(self, value, interface_name, attributes): |
| 1000 return 'DartUtilities::arrayBufferViewToDart(%s)' % value | 1006 return 'DartUtilities::arrayBufferViewToDart(%s)' % value |
| 1001 | 1007 |
| 1002 def return_to_dart_conversion(self, value, interface_name, attributes): | 1008 def return_to_dart_conversion(self, value, auto_dart_scope_setup, |
| 1009 interface_name, attributes): |
| 1003 return 'Dart_SetReturnValue(args, %s)' % self.to_dart_conversion( | 1010 return 'Dart_SetReturnValue(args, %s)' % self.to_dart_conversion( |
| 1004 value, | 1011 value, |
| 1005 interface_name, | 1012 interface_name, |
| 1006 attributes) | 1013 attributes) |
| 1007 | 1014 |
| 1008 def to_native_info(self, idl_node, interface_name): | 1015 def to_native_info(self, idl_node, interface_name): |
| 1009 return '%s.get()', 'RefPtr<%s>' % self._idl_type, 'DartUtilities', 'dartTo%s
' % self._idl_type | 1016 return '%s.get()', 'RefPtr<%s>' % self._idl_type, 'DartUtilities', 'dartTo%s
' % self._idl_type |
| 1010 | 1017 |
| 1011 | 1018 |
| 1012 class BasicTypedListIDLTypeInfo(InterfaceIDLTypeInfo): | 1019 class BasicTypedListIDLTypeInfo(InterfaceIDLTypeInfo): |
| 1013 def __init__(self, idl_type, data, interface_name, type_registry): | 1020 def __init__(self, idl_type, data, interface_name, type_registry): |
| 1014 super(BasicTypedListIDLTypeInfo, self).__init__( | 1021 super(BasicTypedListIDLTypeInfo, self).__init__( |
| 1015 idl_type, data, interface_name, type_registry) | 1022 idl_type, data, interface_name, type_registry) |
| 1016 | 1023 |
| 1017 def conversion_includes(self): | 1024 def conversion_includes(self): |
| 1018 return [] | 1025 return [] |
| 1019 | 1026 |
| 1020 def to_dart_conversion(self, value, interface_name, attributes): | 1027 def to_dart_conversion(self, value, interface_name, attributes): |
| 1021 function_name = 'DartUtilities::%sToDart' % self._idl_type | 1028 function_name = 'DartUtilities::%sToDart' % self._idl_type |
| 1022 function_name = function_name[0].lower() + function_name[1:] | 1029 function_name = function_name[0].lower() + function_name[1:] |
| 1023 return '%s(%s)' % (function_name, value) | 1030 return '%s(%s)' % (function_name, value) |
| 1024 | 1031 |
| 1025 def return_to_dart_conversion(self, value, interface_name, attributes): | 1032 def return_to_dart_conversion(self, value, auto_dart_scope_setup, |
| 1033 interface_name, attributes): |
| 1026 return 'Dart_SetReturnValue(args, %s)' % self.to_dart_conversion( | 1034 return 'Dart_SetReturnValue(args, %s)' % self.to_dart_conversion( |
| 1027 value, | 1035 value, |
| 1028 interface_name, | 1036 interface_name, |
| 1029 attributes) | 1037 attributes) |
| 1030 | 1038 |
| 1031 def to_native_info(self, idl_node, interface_name): | 1039 def to_native_info(self, idl_node, interface_name): |
| 1032 return '%s.get()', 'RefPtr<%s>' % self._idl_type, 'DartUtilities', 'dartTo%s
' % self._idl_type | 1040 return '%s.get()', 'RefPtr<%s>' % self._idl_type, 'DartUtilities', 'dartTo%s
' % self._idl_type |
| 1033 | 1041 |
| 1034 | 1042 |
| 1035 class TypeData(object): | 1043 class TypeData(object): |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1261 if type_data.clazz == 'BasicTypedList': | 1269 if type_data.clazz == 'BasicTypedList': |
| 1262 if type_name == 'ArrayBuffer': | 1270 if type_name == 'ArrayBuffer': |
| 1263 dart_interface_name = 'ByteBuffer' | 1271 dart_interface_name = 'ByteBuffer' |
| 1264 else: | 1272 else: |
| 1265 dart_interface_name = self._renamer.RenameInterfaceId(type_name) | 1273 dart_interface_name = self._renamer.RenameInterfaceId(type_name) |
| 1266 return BasicTypedListIDLTypeInfo( | 1274 return BasicTypedListIDLTypeInfo( |
| 1267 type_name, type_data, dart_interface_name, self) | 1275 type_name, type_data, dart_interface_name, self) |
| 1268 | 1276 |
| 1269 class_name = '%sIDLTypeInfo' % type_data.clazz | 1277 class_name = '%sIDLTypeInfo' % type_data.clazz |
| 1270 return globals()[class_name](type_name, type_data) | 1278 return globals()[class_name](type_name, type_data) |
| OLD | NEW |