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 the systems to generate | 6 """This module provides shared functionality for the systems to generate |
7 native binding from the IDL database.""" | 7 native binding from the IDL database.""" |
8 | 8 |
9 import emitter | 9 import emitter |
10 import os | 10 import os |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 CPP_CALLBACK=constructor_callback_cpp_name) | 659 CPP_CALLBACK=constructor_callback_cpp_name) |
660 | 660 |
661 def GenerateCustomFactory(self, constructor_info): | 661 def GenerateCustomFactory(self, constructor_info): |
662 if 'CustomConstructor' not in self._interface.ext_attrs: | 662 if 'CustomConstructor' not in self._interface.ext_attrs: |
663 return False | 663 return False |
664 | 664 |
665 annotations = self._metadata.GetFormattedMetadata(self._library_name, | 665 annotations = self._metadata.GetFormattedMetadata(self._library_name, |
666 self._interface, self._interface.id, ' ') | 666 self._interface, self._interface.id, ' ') |
667 | 667 |
668 self._members_emitter.Emit( | 668 self._members_emitter.Emit( |
669 '\n $(ANNOTATIONS)factory $CTOR($PARAMS) => _create($FACTORY_PARAMS);\n
', | 669 '\n $(ANNOTATIONS)factory $CTOR($PARAMS) => wrap_jso(_create($FACTORY_P
ARAMS));\n', |
670 ANNOTATIONS=annotations, | 670 ANNOTATIONS=annotations, |
671 CTOR=constructor_info._ConstructorFullName(self._DartType), | 671 CTOR=constructor_info._ConstructorFullName(self._DartType), |
672 PARAMS=constructor_info.ParametersAsDeclaration(self._DartType), | 672 PARAMS=constructor_info.ParametersAsDeclaration(self._DartType), |
673 FACTORY_PARAMS= \ | 673 FACTORY_PARAMS= \ |
674 constructor_info.ParametersAsArgumentList()) | 674 constructor_info.ParametersAsArgumentList()) |
675 | 675 |
676 constructor_callback_cpp_name = 'constructorCallback' | 676 # MutationObserver has custom _create. TODO(terry): Consider table but this
is only one. |
677 self._EmitConstructorInfrastructure( | 677 if self._interface.id != 'MutationObserver': |
678 constructor_info, "", constructor_callback_cpp_name, '_create', | 678 constructor_callback_cpp_name = 'constructorCallback' |
679 is_custom=True) | 679 self._EmitConstructorInfrastructure( |
| 680 constructor_info, "", constructor_callback_cpp_name, '_create', |
| 681 is_custom=True) |
680 | 682 |
681 self._cpp_declarations_emitter.Emit( | 683 self._cpp_declarations_emitter.Emit( |
682 '\n' | 684 '\n' |
683 'void $CPP_CALLBACK(Dart_NativeArguments);\n', | 685 'void $CPP_CALLBACK(Dart_NativeArguments);\n', |
684 CPP_CALLBACK=constructor_callback_cpp_name) | 686 CPP_CALLBACK=constructor_callback_cpp_name) |
685 | 687 |
686 return True | 688 return True |
687 | 689 |
688 def IsConstructorArgumentOptional(self, argument): | 690 def IsConstructorArgumentOptional(self, argument): |
689 return IsOptional(argument) | 691 return IsOptional(argument) |
690 | 692 |
691 def EmitStaticFactoryOverload(self, constructor_info, name, arguments): | 693 def EmitStaticFactoryOverload(self, constructor_info, name, arguments): |
692 constructor_callback_cpp_name = name + 'constructorCallback' | 694 constructor_callback_cpp_name = name + 'constructorCallback' |
693 self._EmitConstructorInfrastructure( | 695 self._EmitConstructorInfrastructure( |
694 constructor_info, name, 'constructorCallback', name, arguments, | 696 constructor_info, name, 'constructorCallback', name, arguments, |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 # Temporary hack to force dart:scalarlist clamped array for ImageData.data. | 911 # Temporary hack to force dart:scalarlist clamped array for ImageData.data. |
910 # TODO(antonm): solve in principled way. | 912 # TODO(antonm): solve in principled way. |
911 if self._interface.id == 'ImageData' and html_name == 'data': | 913 if self._interface.id == 'ImageData' and html_name == 'data': |
912 html_name = '_data' | 914 html_name = '_data' |
913 type_info = self._TypeInfo(attr.type.id) | 915 type_info = self._TypeInfo(attr.type.id) |
914 return_type = self.SecureOutputType(attr.type.id, False, read_only) | 916 return_type = self.SecureOutputType(attr.type.id, False, read_only) |
915 parameters = [] | 917 parameters = [] |
916 dart_declaration = '%s get %s' % (return_type, html_name) | 918 dart_declaration = '%s get %s' % (return_type, html_name) |
917 is_custom = _IsCustom(attr) and (_IsCustomValue(attr, None) or | 919 is_custom = _IsCustom(attr) and (_IsCustomValue(attr, None) or |
918 _IsCustomValue(attr, 'Getter')) | 920 _IsCustomValue(attr, 'Getter')) |
| 921 |
| 922 # Operation uses blink? |
| 923 wrap_unwrap_list = []; |
| 924 return_wrap_jso = False |
| 925 if self._dart_use_blink: |
| 926 # Unwrap the type to get the JsObject if Type is: |
| 927 # |
| 928 # - known IDL type |
| 929 # - type_id is None then it's probably a union type or overloaded |
| 930 # it's a dynamic/any type |
| 931 # - type is Object |
| 932 # |
| 933 # JsObject maybe stored in the Dart class. |
| 934 return_wrap_jso = (isinstance(type_info, InterfaceIDLTypeInfo) or |
| 935 not(type_info) or attr.type.id == 'Object') |
| 936 wrap_unwrap_list.append(return_wrap_jso) # wrap_jso the returned objec
t |
| 937 wrap_unwrap_list.append(self._dart_use_blink) # this must be unwrap_jso |
| 938 |
919 # This seems to have been replaced with Custom=Getter (see above), but | 939 # This seems to have been replaced with Custom=Getter (see above), but |
920 # check to be sure we don't see the old syntax | 940 # check to be sure we don't see the old syntax |
921 assert(not ('CustomGetter' in attr.ext_attrs)) | 941 assert(not ('CustomGetter' in attr.ext_attrs)) |
922 native_suffix = 'Getter' | 942 native_suffix = 'Getter' |
923 auto_scope_setup = self._GenerateAutoSetupScope(attr.id, native_suffix) | 943 auto_scope_setup = self._GenerateAutoSetupScope(attr.id, native_suffix) |
924 native_entry = \ | 944 native_entry = \ |
925 self.DeriveNativeEntry(attr.id, 'Getter', None) | 945 self.DeriveNativeEntry(attr.id, 'Getter', None) |
926 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1, | 946 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1, |
927 dart_declaration, attr.is_static, return_type, parameters, | 947 dart_declaration, attr.is_static, return_type, parameters, |
928 native_suffix, is_custom, auto_scope_setup, native_entry=native_entry) | 948 native_suffix, is_custom, auto_scope_setup, native_entry=native_entry, |
| 949 wrap_unwrap_list=wrap_unwrap_list) |
929 if is_custom: | 950 if is_custom: |
930 return | 951 return |
931 | 952 |
932 if 'Reflect' in attr.ext_attrs: | 953 if 'Reflect' in attr.ext_attrs: |
933 webcore_function_name = self._TypeInfo(attr.type.id).webcore_getter_name() | 954 webcore_function_name = self._TypeInfo(attr.type.id).webcore_getter_name() |
934 if 'URL' in attr.ext_attrs: | 955 if 'URL' in attr.ext_attrs: |
935 if 'NonEmpty' in attr.ext_attrs: | 956 if 'NonEmpty' in attr.ext_attrs: |
936 webcore_function_name = 'getNonEmptyURLAttribute' | 957 webcore_function_name = 'getNonEmptyURLAttribute' |
937 else: | 958 else: |
938 webcore_function_name = 'getURLAttribute' | 959 webcore_function_name = 'getURLAttribute' |
(...skipping 17 matching lines...) Expand all Loading... |
956 True, | 977 True, |
957 function_expression, | 978 function_expression, |
958 attr, | 979 attr, |
959 [], | 980 [], |
960 attr.type.id, | 981 attr.type.id, |
961 attr.type.nullable, | 982 attr.type.nullable, |
962 raises, | 983 raises, |
963 auto_scope_setup) | 984 auto_scope_setup) |
964 | 985 |
965 def _AddSetter(self, attr, html_name): | 986 def _AddSetter(self, attr, html_name): |
| 987 return_type = 'void' |
| 988 ptype = self._DartType(attr.type.id) |
| 989 |
966 type_info = self._TypeInfo(attr.type.id) | 990 type_info = self._TypeInfo(attr.type.id) |
967 return_type = 'void' | 991 |
968 parameters = ['value'] | 992 # Is the setter value a DartClass (that has a JsObject) or the type is |
969 ptype = self._DartType(attr.type.id) | 993 # None (it's a dynamic/any type) then unwrap_jso before passing to blink. |
| 994 parameters = ['unwrap_jso(value)' if (isinstance(type_info, InterfaceIDLType
Info) or |
| 995 not(attr.type.id) or ptype == 'Object'
) |
| 996 else 'value'] |
| 997 |
970 dart_declaration = 'void set %s(%s value)' % (html_name, ptype) | 998 dart_declaration = 'void set %s(%s value)' % (html_name, ptype) |
971 is_custom = _IsCustom(attr) and (_IsCustomValue(attr, None) or | 999 is_custom = _IsCustom(attr) and (_IsCustomValue(attr, None) or |
972 _IsCustomValue(attr, 'Setter')) | 1000 _IsCustomValue(attr, 'Setter')) |
973 # This seems to have been replaced with Custom=Setter (see above), but | 1001 # This seems to have been replaced with Custom=Setter (see above), but |
974 # check to be sure we don't see the old syntax | 1002 # check to be sure we don't see the old syntax |
975 assert(not ('CustomSetter' in attr.ext_attrs)) | 1003 assert(not ('CustomSetter' in attr.ext_attrs)) |
976 assert(not ('V8CustomSetter' in attr.ext_attrs)) | 1004 assert(not ('V8CustomSetter' in attr.ext_attrs)) |
977 native_suffix = 'Setter' | 1005 native_suffix = 'Setter' |
978 auto_scope_setup = self._GenerateAutoSetupScope(attr.id, native_suffix) | 1006 auto_scope_setup = self._GenerateAutoSetupScope(attr.id, native_suffix) |
979 native_entry = \ | 1007 native_entry = \ |
980 self.DeriveNativeEntry(attr.id, 'Setter', None) | 1008 self.DeriveNativeEntry(attr.id, 'Setter', None) |
| 1009 |
| 1010 # setters return no object and if blink this must be unwrapped.? |
| 1011 wrap_unwrap_list = [False, self._dart_use_blink]; |
| 1012 |
981 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2, | 1013 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2, |
982 dart_declaration, attr.is_static, return_type, parameters, | 1014 dart_declaration, attr.is_static, return_type, parameters, |
983 native_suffix, is_custom, auto_scope_setup, native_entry=native_entry) | 1015 native_suffix, is_custom, auto_scope_setup, native_entry=native_entry, |
| 1016 wrap_unwrap_list=wrap_unwrap_list) |
984 if is_custom: | 1017 if is_custom: |
985 return | 1018 return |
986 | 1019 |
987 if 'Reflect' in attr.ext_attrs: | 1020 if 'Reflect' in attr.ext_attrs: |
988 webcore_function_name = self._TypeInfo(attr.type.id).webcore_setter_name() | 1021 webcore_function_name = self._TypeInfo(attr.type.id).webcore_setter_name() |
989 else: | 1022 else: |
990 if 'ImplementedAs' in attr.ext_attrs: | 1023 if 'ImplementedAs' in attr.ext_attrs: |
991 attr_name = attr.ext_attrs['ImplementedAs'] | 1024 attr_name = attr.ext_attrs['ImplementedAs'] |
992 else: | 1025 else: |
993 attr_name = attr.id | 1026 attr_name = attr.id |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1040 # First emit a toplevel function to do the native call | 1073 # First emit a toplevel function to do the native call |
1041 # Calls to this are emitted elsewhere, | 1074 # Calls to this are emitted elsewhere, |
1042 dart_native_name, resolver_string = \ | 1075 dart_native_name, resolver_string = \ |
1043 self.DeriveNativeEntry("item", 'Method', 1) | 1076 self.DeriveNativeEntry("item", 'Method', 1) |
1044 | 1077 |
1045 # Emit the method which calls the toplevel function, along with | 1078 # Emit the method which calls the toplevel function, along with |
1046 # the [] operator. | 1079 # the [] operator. |
1047 dart_qualified_name = \ | 1080 dart_qualified_name = \ |
1048 self.DeriveQualifiedBlinkName(self._interface.id, | 1081 self.DeriveQualifiedBlinkName(self._interface.id, |
1049 dart_native_name) | 1082 dart_native_name) |
1050 self._members_emitter.Emit( | 1083 |
1051 '\n' | 1084 type_info = self._TypeInfo(element_type) |
1052 ' $TYPE operator[](int index) {\n' | 1085 # Does nativeIndexGetter return a DartClass (JsObject) if so wrap_jso. |
1053 ' if (index < 0 || index >= length)\n' | 1086 wrap_jso_start = '' |
1054 ' throw new RangeError.index(index, this);\n' | 1087 wrap_jso_end = '' |
1055 ' return $(DART_NATIVE_NAME)(this, index);\n' | 1088 if isinstance(type_info, InterfaceIDLTypeInfo): |
1056 ' }\n\n' | 1089 wrap_jso_start = 'wrap_jso(' |
1057 ' $TYPE _nativeIndexedGetter(int index) =>' | 1090 wrap_jso_end = ')' |
1058 ' $(DART_NATIVE_NAME)(this, index);\n', | 1091 blinkNativeIndexed = """ |
1059 DART_NATIVE_NAME=dart_qualified_name, | 1092 $TYPE operator[](int index) { |
1060 TYPE=self.SecureOutputType(element_type), | 1093 if (index < 0 || index >= length) |
1061 INTERFACE=self._interface.id) | 1094 throw new RangeError.index(index, this); |
| 1095 return %s$(DART_NATIVE_NAME)(unwrap_jso(this), index)%s; |
| 1096 } |
| 1097 |
| 1098 $TYPE _nativeIndexedGetter(int index) => %s$(DART_NATIVE_NAME)(unwrap_jso(this
), index)%s; |
| 1099 """ % (wrap_jso_start, wrap_jso_end, wrap_jso_start, wrap_jso_end) |
| 1100 # Wrap the type to store the JsObject if Type is: |
| 1101 # |
| 1102 # - known IDL type |
| 1103 # - type_id is None then it's probably a union type or overloaded |
| 1104 # it's a dynamic/any type |
| 1105 # - type is Object |
| 1106 # |
| 1107 # JsObject maybe stored in the Dart class. |
| 1108 if isinstance(type_info, InterfaceIDLTypeInfo) or not(type_info) or dart_e
lement_type == 'Object': |
| 1109 blinkNativeIndexedGetter = \ |
| 1110 ' {0}$(DART_NATIVE_NAME)(unwrap_jso(this), index){1};\n'.format('w
rap_jso(', ')') |
| 1111 else: |
| 1112 blinkNativeIndexedGetter = \ |
| 1113 ' $(DART_NATIVE_NAME)(unwrap_jso(this), index);\n' |
| 1114 self._members_emitter.Emit(blinkNativeIndexed, |
| 1115 DART_NATIVE_NAME=dart_qualified_name, |
| 1116 TYPE=self.SecureOutputType(element_type), |
| 1117 INTERFACE=self._interface.id) |
1062 | 1118 |
1063 if self._HasNativeIndexSetter(): | 1119 if self._HasNativeIndexSetter(): |
1064 self._EmitNativeIndexSetter(dart_element_type) | 1120 self._EmitNativeIndexSetter(dart_element_type) |
1065 else: | 1121 else: |
1066 self._members_emitter.Emit( | 1122 self._members_emitter.Emit( |
1067 '\n' | 1123 '\n' |
1068 ' void operator[]=(int index, $TYPE value) {\n' | 1124 ' void operator[]=(int index, $TYPE value) {\n' |
1069 ' throw new UnsupportedError("Cannot assign element of immutable Li
st.");\n' | 1125 ' throw new UnsupportedError("Cannot assign element of immutable Li
st.");\n' |
1070 ' }\n', | 1126 ' }\n', |
1071 TYPE=dart_element_type) | 1127 TYPE=dart_element_type) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1126 self._GenerateNativeBinding('numericIndexSetter', 3, | 1182 self._GenerateNativeBinding('numericIndexSetter', 3, |
1127 dart_declaration, False, return_type, parameters, | 1183 dart_declaration, False, return_type, parameters, |
1128 'Callback', True, False) | 1184 'Callback', True, False) |
1129 | 1185 |
1130 def EmitOperation(self, info, html_name): | 1186 def EmitOperation(self, info, html_name): |
1131 """ | 1187 """ |
1132 Arguments: | 1188 Arguments: |
1133 info: An OperationInfo object. | 1189 info: An OperationInfo object. |
1134 """ | 1190 """ |
1135 return_type = self.SecureOutputType(info.type_name, False, True) | 1191 return_type = self.SecureOutputType(info.type_name, False, True) |
| 1192 |
1136 formals = info.ParametersAsDeclaration(self._DartType) | 1193 formals = info.ParametersAsDeclaration(self._DartType) |
1137 parameters = info.ParametersAsListOfVariables() | 1194 |
| 1195 parameters = info.ParametersAsListOfVariables(None, self._type_registry if s
elf._dart_use_blink else None) |
1138 dart_declaration = '%s%s %s(%s)' % ( | 1196 dart_declaration = '%s%s %s(%s)' % ( |
1139 'static ' if info.IsStatic() else '', | 1197 'static ' if info.IsStatic() else '', |
1140 return_type, | 1198 return_type, |
1141 html_name, | 1199 html_name, |
1142 formals) | 1200 formals) |
1143 | 1201 |
1144 operation = info.operations[0] | 1202 operation = info.operations[0] |
| 1203 |
1145 is_custom = _IsCustom(operation) | 1204 is_custom = _IsCustom(operation) |
1146 has_optional_arguments = any(IsOptional(argument) for argument in operation.
arguments) | 1205 has_optional_arguments = any(IsOptional(argument) for argument in operation.
arguments) |
1147 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option
al_arguments) | 1206 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option
al_arguments) |
1148 | 1207 |
| 1208 # Operation uses blink? |
| 1209 wrap_unwrap_list = []; |
| 1210 return_wrap_jso = False |
| 1211 # return type wrapped? |
| 1212 if self._dart_use_blink: |
| 1213 # Wrap the type to store the JsObject if Type is: |
| 1214 # |
| 1215 # - known IDL type |
| 1216 # - type_id is None then it's probably a union type or overloaded |
| 1217 # it's a dynamic/any type |
| 1218 # - type is Object |
| 1219 # |
| 1220 # JsObject maybe stored in the Dart class. |
| 1221 return_wrap_jso = (info.wrap_unwrap_type_blink(return_type, self._type_r
egistry) or |
| 1222 return_type == 'Rectangle' or |
| 1223 info.wrap_unwrap_list_blink(return_type, self._type_r
egistry)) |
| 1224 wrap_unwrap_list.append(return_wrap_jso) # wrap_jso the returned objec
t |
| 1225 wrap_unwrap_list.append(self._dart_use_blink) # The 'this' parameter must b
e unwrap_jso |
| 1226 |
1149 if info.callback_args: | 1227 if info.callback_args: |
1150 self._AddFutureifiedOperation(info, html_name) | 1228 self._AddFutureifiedOperation(info, html_name) |
1151 elif not needs_dispatcher: | 1229 elif not needs_dispatcher: |
1152 # Bind directly to native implementation | 1230 # Bind directly to native implementation |
1153 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) | 1231 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) |
1154 native_suffix = 'Callback' | 1232 native_suffix = 'Callback' |
1155 auto_scope_setup = self._GenerateAutoSetupScope(info.name, native_suffix) | 1233 auto_scope_setup = self._GenerateAutoSetupScope(info.name, native_suffix) |
1156 native_entry = \ | 1234 native_entry = \ |
1157 self.DeriveNativeEntry(operation.id, 'Method', len(info.param_infos)) | 1235 self.DeriveNativeEntry(operation.id, 'Method', len(info.param_infos)) |
1158 cpp_callback_name = self._GenerateNativeBinding( | 1236 cpp_callback_name = self._GenerateNativeBinding( |
1159 info.name, argument_count, dart_declaration, | 1237 info.name, argument_count, dart_declaration, |
1160 info.IsStatic(), return_type, parameters, | 1238 info.IsStatic(), return_type, parameters, |
1161 native_suffix, is_custom, auto_scope_setup, | 1239 native_suffix, is_custom, auto_scope_setup, |
1162 native_entry=native_entry) | 1240 native_entry=native_entry, |
| 1241 wrap_unwrap_list=wrap_unwrap_list) |
1163 if not is_custom: | 1242 if not is_custom: |
1164 self._GenerateOperationNativeCallback(operation, operation.arguments, cp
p_callback_name, auto_scope_setup) | 1243 self._GenerateOperationNativeCallback(operation, operation.arguments, cp
p_callback_name, auto_scope_setup) |
1165 else: | 1244 else: |
1166 self._GenerateDispatcher(info, info.operations, dart_declaration, html_nam
e) | 1245 self._GenerateDispatcher(info, info.operations, dart_declaration, html_nam
e) |
1167 | 1246 |
1168 def _GenerateDispatcher(self, info, operations, dart_declaration, html_name): | 1247 def _GenerateDispatcher(self, info, operations, dart_declaration, html_name): |
1169 | 1248 |
1170 def GenerateCall( | 1249 def GenerateCall( |
1171 stmts_emitter, call_emitter, version, operation, argument_count): | 1250 stmts_emitter, call_emitter, version, operation, argument_count): |
1172 native_suffix = 'Callback' | 1251 native_suffix = 'Callback' |
1173 actuals = info.ParametersAsListOfVariables(argument_count) | 1252 actuals = info.ParametersAsListOfVariables(argument_count, self._type_regi
stry if self._dart_use_blink else None) |
1174 actuals_s = ", ".join(actuals) | 1253 actuals_s = ", ".join(actuals) |
1175 formals=actuals | 1254 formals=actuals |
1176 return_type = self.SecureOutputType(operation.type.id) | 1255 return_type = self.SecureOutputType(operation.type.id) |
| 1256 |
| 1257 return_wrap_jso = False |
| 1258 if self._dart_use_blink: |
| 1259 return_wrap_jso = self._type_registry.HasInterface(return_type) |
| 1260 |
1177 native_suffix = 'Callback' | 1261 native_suffix = 'Callback' |
1178 is_custom = _IsCustom(operation) | 1262 is_custom = _IsCustom(operation) |
1179 base_name = '_%s_%s' % (operation.id, version) | 1263 base_name = '_%s_%s' % (operation.id, version) |
1180 static = True | 1264 static = True |
1181 if not operation.is_static: | 1265 if not operation.is_static: |
1182 actuals = ['this'] + actuals | 1266 actuals = ['unwrap_jso(this)' if self._dart_use_blink else 'this'] + act
uals |
1183 formals = ['mthis'] + formals | 1267 formals = ['mthis'] + formals |
1184 actuals_s = ", ".join(actuals) | 1268 actuals_s = ", ".join(actuals) |
1185 formals_s = ", ".join(formals) | 1269 formals_s = ", ".join(formals) |
1186 dart_declaration = '%s(%s)' % ( | 1270 dart_declaration = '%s(%s)' % ( |
1187 base_name, formals_s) | 1271 base_name, formals_s) |
1188 native_entry = \ | 1272 native_entry = \ |
1189 self.DeriveNativeEntry(operation.id, 'Method', argument_count) | 1273 self.DeriveNativeEntry(operation.id, 'Method', argument_count) |
1190 overload_base_name = native_entry[0] | 1274 overload_base_name = native_entry[0] |
1191 overload_name = \ | 1275 overload_name = \ |
1192 self.DeriveQualifiedBlinkName(self._interface.id, | 1276 self.DeriveQualifiedBlinkName(self._interface.id, |
1193 overload_base_name) | 1277 overload_base_name) |
1194 call_emitter.Emit('$NAME($ARGS)', NAME=overload_name, ARGS=actuals_s) | 1278 if return_wrap_jso: |
| 1279 call_emitter.Emit('wrap_jso($NAME($ARGS))', NAME=overload_name, ARGS=a
ctuals_s) |
| 1280 else: |
| 1281 call_emitter.Emit('$NAME($ARGS)', NAME=overload_name, ARGS=actuals_s) |
1195 auto_scope_setup = \ | 1282 auto_scope_setup = \ |
1196 self._GenerateAutoSetupScope(base_name, native_suffix) | 1283 self._GenerateAutoSetupScope(base_name, native_suffix) |
1197 cpp_callback_name = self._GenerateNativeBinding( | 1284 cpp_callback_name = self._GenerateNativeBinding( |
1198 base_name, (0 if static else 1) + argument_count, | 1285 base_name, (0 if static else 1) + argument_count, |
1199 dart_declaration, static, return_type, formals, | 1286 dart_declaration, static, return_type, formals, |
1200 native_suffix, is_custom, auto_scope_setup, emit_metadata=False, | 1287 native_suffix, is_custom, auto_scope_setup, emit_metadata=False, |
1201 emit_to_native=True, native_entry=native_entry) | 1288 emit_to_native=True, native_entry=native_entry) |
1202 if not is_custom: | 1289 if not is_custom: |
1203 self._GenerateOperationNativeCallback(operation, | 1290 self._GenerateOperationNativeCallback(operation, |
1204 operation.arguments[:argument_count], cpp_callback_name, | 1291 operation.arguments[:argument_count], cpp_callback_name, |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1597 self._interface.id, | 1684 self._interface.id, |
1598 ext_attrs) | 1685 ext_attrs) |
1599 set_return_value = '%s' % (return_to_dart_conversion) | 1686 set_return_value = '%s' % (return_to_dart_conversion) |
1600 invocation_emitter.Emit( | 1687 invocation_emitter.Emit( |
1601 ' $RETURN_VALUE;\n', | 1688 ' $RETURN_VALUE;\n', |
1602 RETURN_VALUE=set_return_value) | 1689 RETURN_VALUE=set_return_value) |
1603 | 1690 |
1604 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration, | 1691 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration, |
1605 static, return_type, parameters, native_suffix, is_custom, | 1692 static, return_type, parameters, native_suffix, is_custom, |
1606 auto_scope_setup=True, emit_metadata=True, emit_to_native=False, | 1693 auto_scope_setup=True, emit_metadata=True, emit_to_native=False, |
1607 native_entry=None): | 1694 native_entry=None, wrap_unwrap_list=[]): |
1608 metadata = [] | 1695 metadata = [] |
1609 if emit_metadata: | 1696 if emit_metadata: |
1610 metadata = self._metadata.GetFormattedMetadata( | 1697 metadata = self._metadata.GetFormattedMetadata( |
1611 self._renamer.GetLibraryName(self._interface), | 1698 self._renamer.GetLibraryName(self._interface), |
1612 self._interface, idl_name, ' ') | 1699 self._interface, idl_name, ' ') |
1613 | 1700 |
1614 if (native_entry): | 1701 if (native_entry): |
1615 dart_native_name, native_binding = native_entry | 1702 dart_native_name, native_binding = native_entry |
1616 else: | 1703 else: |
1617 dart_native_name = \ | 1704 dart_native_name = \ |
1618 self.DeriveNativeName(idl_name, native_suffix) | 1705 self.DeriveNativeName(idl_name, native_suffix) |
1619 native_binding_id = self._interface.id | 1706 native_binding_id = self._interface.id |
1620 native_binding_id = TypeIdToBlinkName(native_binding_id, self._database) | 1707 native_binding_id = TypeIdToBlinkName(native_binding_id, self._database) |
1621 native_binding = \ | 1708 native_binding = \ |
1622 '%s_%s_%s' % (native_binding_id, idl_name, native_suffix) | 1709 '%s_%s_%s' % (native_binding_id, idl_name, native_suffix) |
1623 | 1710 |
1624 if not static: | 1711 if not static: |
1625 formals = ", ".join(['mthis'] + parameters) | 1712 formals = ", ".join(['mthis'] + parameters) |
1626 actuals = ", ".join(['this'] + parameters) | 1713 if wrap_unwrap_list and wrap_unwrap_list[1]: |
| 1714 actuals = ", ".join(['unwrap_jso(this)'] + parameters) |
| 1715 else: |
| 1716 actuals = ", ".join(['this'] + parameters) |
1627 else: | 1717 else: |
1628 formals = ", ".join(parameters) | 1718 formals = ", ".join(parameters) |
1629 actuals = ", ".join(parameters) | 1719 actuals = ", ".join(parameters) |
1630 | 1720 |
1631 if not emit_to_native: | 1721 if not emit_to_native: |
1632 caller_emitter = self._members_emitter | 1722 caller_emitter = self._members_emitter |
1633 full_dart_name = \ | 1723 full_dart_name = \ |
1634 self.DeriveQualifiedBlinkName(self._interface.id, | 1724 self.DeriveQualifiedBlinkName(self._interface.id, |
1635 dart_native_name) | 1725 dart_native_name) |
1636 if IsPureInterface(self._interface.id): | 1726 if IsPureInterface(self._interface.id): |
1637 caller_emitter.Emit( | 1727 caller_emitter.Emit( |
1638 '\n' | 1728 '\n' |
1639 ' $METADATA$DART_DECLARATION;\n', | 1729 ' $METADATA$DART_DECLARATION;\n', |
1640 METADATA=metadata, | 1730 METADATA=metadata, |
1641 DART_DECLARATION=dart_declaration) | 1731 DART_DECLARATION=dart_declaration) |
1642 else: | 1732 else: |
1643 caller_emitter.Emit( | 1733 emit_template = ''' |
1644 '\n' | 1734 $METADATA$DART_DECLARATION => $DART_NAME($ACTUALS); |
1645 ' $METADATA$DART_DECLARATION => $DART_NAME($ACTUALS);\n', | 1735 ''' |
1646 METADATA=metadata, | 1736 if wrap_unwrap_list and wrap_unwrap_list[0]: |
1647 DART_DECLARATION=dart_declaration, | 1737 emit_jso_template = ''' |
1648 DART_NAME=full_dart_name, | 1738 $METADATA$DART_DECLARATION => %s($DART_NAME($ACTUALS)); |
1649 ACTUALS=actuals) | 1739 ''' |
| 1740 if return_type == 'Rectangle': |
| 1741 jso_util_method = 'make_dart_rectangle' |
| 1742 # TODO(terry): More checks that the return is a List<Node>. |
| 1743 elif return_type.startswith('List<'): |
| 1744 jso_util_method = 'wrap_jso_list' |
| 1745 else: |
| 1746 jso_util_method = 'wrap_jso' |
| 1747 # Always return List<String> unwrapped. |
| 1748 if return_type != 'List<String>': |
| 1749 emit_template = emit_jso_template % jso_util_method |
| 1750 caller_emitter.Emit(emit_template, |
| 1751 METADATA=metadata, |
| 1752 DART_DECLARATION=dart_declaration, |
| 1753 DART_NAME=full_dart_name, |
| 1754 ACTUALS=actuals) |
1650 cpp_callback_name = '%s%s' % (idl_name, native_suffix) | 1755 cpp_callback_name = '%s%s' % (idl_name, native_suffix) |
1651 | 1756 |
1652 self._cpp_resolver_emitter.Emit( | 1757 self._cpp_resolver_emitter.Emit( |
1653 ' if (argumentCount == $ARGC && name == "$NATIVE_BINDING") {\n' | 1758 ' if (argumentCount == $ARGC && name == "$NATIVE_BINDING") {\n' |
1654 ' *autoSetupScope = $AUTO_SCOPE_SETUP;\n' | 1759 ' *autoSetupScope = $AUTO_SCOPE_SETUP;\n' |
1655 ' return Dart$(INTERFACE_NAME)Internal::$CPP_CALLBACK_NAME;\n' | 1760 ' return Dart$(INTERFACE_NAME)Internal::$CPP_CALLBACK_NAME;\n' |
1656 ' }\n', | 1761 ' }\n', |
1657 ARGC=argument_count, | 1762 ARGC=argument_count, |
1658 NATIVE_BINDING=native_binding, | 1763 NATIVE_BINDING=native_binding, |
1659 INTERFACE_NAME=self._interface.id, | 1764 INTERFACE_NAME=self._interface.id, |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1918 | 2023 |
1919 def _IsCustom(op_or_attr): | 2024 def _IsCustom(op_or_attr): |
1920 assert(isinstance(op_or_attr, IDLMember)) | 2025 assert(isinstance(op_or_attr, IDLMember)) |
1921 return 'Custom' in op_or_attr.ext_attrs or 'DartCustom' in op_or_attr.ext_attr
s | 2026 return 'Custom' in op_or_attr.ext_attrs or 'DartCustom' in op_or_attr.ext_attr
s |
1922 | 2027 |
1923 def _IsCustomValue(op_or_attr, value): | 2028 def _IsCustomValue(op_or_attr, value): |
1924 if _IsCustom(op_or_attr): | 2029 if _IsCustom(op_or_attr): |
1925 return op_or_attr.ext_attrs.get('Custom') == value \ | 2030 return op_or_attr.ext_attrs.get('Custom') == value \ |
1926 or op_or_attr.ext_attrs.get('DartCustom') == value | 2031 or op_or_attr.ext_attrs.get('DartCustom') == value |
1927 return False | 2032 return False |
OLD | NEW |