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 |
11 from generator import * | 11 from generator import * |
12 from htmldartgenerator import * | 12 from htmldartgenerator import * |
13 from idlnode import IDLArgument, IDLAttribute | 13 from idlnode import IDLArgument, IDLAttribute, IDLEnum |
14 from systemhtml import js_support_checks, GetCallbackInfo, HTML_LIBRARY_NAMES | 14 from systemhtml import js_support_checks, GetCallbackInfo, HTML_LIBRARY_NAMES |
15 | 15 |
16 # This is an ugly hack to get things working on the M35 roll. Once we | 16 # This is an ugly hack to get things working on the M35 roll. Once we |
17 # generate dart:blink from the new scripts, this shouldn't be needed. | 17 # generate dart:blink from the new scripts, this shouldn't be needed. |
18 _cpp_resolver_string_map = { | 18 _cpp_resolver_string_map = { |
19 # These custom constructors all resolve to a common entry, so choosing any | 19 # These custom constructors all resolve to a common entry, so choosing any |
20 # of the generated strings works. | 20 # of the generated strings works. |
21 'Blob_constructorCallback_RESOLVER_STRING_3_Array_DOMString_DOMString': | 21 'Blob_constructorCallback_RESOLVER_STRING_3_Array_DOMString_DOMString': |
22 'Blob_constructorCallback_RESOLVER_STRING_0_', | 22 'Blob_constructorCallback_RESOLVER_STRING_0_', |
23 'XMLHttpRequest_constructorCallback_RESOLVER_STRING_0_': | 23 'XMLHttpRequest_constructorCallback_RESOLVER_STRING_0_': |
24 'XMLHttpRequest_constructorCallback_RESOLVER_STRING_1_XMLHttpRequestOpti
ons', | 24 'XMLHttpRequest_constructorCallback_RESOLVER_STRING_1_XMLHttpRequestOpti
ons', |
| 25 # This callback name just gets generated sligtly different and we don't |
| 26 # want to bother fixing it. |
| 27 'ScriptProcessorNode__setEventListener_Callback': |
| 28 'ScriptProcessorNode_setEventListener_Callback', |
| 29 # We don't know how to get GLenum to show up as the correct type in this |
| 30 # script and don't want to bother fixing it the right way. |
| 31 'WebGLDrawBuffers_drawBuffersWEBGL_Callback_RESOLVER_STRING_1_sequence<GLenu
m>' : |
| 32 'WebGLDrawBuffers_drawBuffersWEBGL_Callback_RESOLVER_STRING_1_sequence<u
nsigned long>' |
25 } | 33 } |
26 | 34 |
27 # TODO(vsm): This logic needs to pulled from the source IDL. These tables are | 35 # TODO(vsm): This logic needs to pulled from the source IDL. These tables are |
28 # an ugly workaround. | 36 # an ugly workaround. |
29 _cpp_callback_map = { | 37 _cpp_callback_map = { |
30 ('DataTransferItem', 'webkitGetAsEntry'): 'DataTransferItemFileSystem', | 38 ('DataTransferItem', 'webkitGetAsEntry'): 'DataTransferItemFileSystem', |
31 ('Document', 'fonts'): 'DocumentFontFaceSet', | 39 ('Document', 'fonts'): 'DocumentFontFaceSet', |
32 ('Document', 'webkitIsFullScreen'): 'DocumentFullscreen', | 40 ('Document', 'webkitIsFullScreen'): 'DocumentFullscreen', |
33 ('Document', 'webkitFullScreenKeyboardInputAllowed'): 'DocumentFullscreen', | 41 ('Document', 'webkitFullScreenKeyboardInputAllowed'): 'DocumentFullscreen', |
34 ('Document', 'webkitCurrentFullScreenElement'): 'DocumentFullscreen', | 42 ('Document', 'webkitCurrentFullScreenElement'): 'DocumentFullscreen', |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 ('DOMURL', 'createObjectUrlFromStreamCallback'): 'URLMediaStream', | 152 ('DOMURL', 'createObjectUrlFromStreamCallback'): 'URLMediaStream', |
145 ('DOMURL', '_createObjectUrlFromWebKitSourceCallback'): 'URLMediaSource', | 153 ('DOMURL', '_createObjectUrlFromWebKitSourceCallback'): 'URLMediaSource', |
146 ('DOMURL', '_createObjectURL_2Callback'): 'URLMediaSource', | 154 ('DOMURL', '_createObjectURL_2Callback'): 'URLMediaSource', |
147 ('DOMURL', '_createObjectURL_3Callback'): 'URLMediaStream', | 155 ('DOMURL', '_createObjectURL_3Callback'): 'URLMediaStream', |
148 } | 156 } |
149 | 157 |
150 _blink_1916_rename_map = { | 158 _blink_1916_rename_map = { |
151 'NavigatorID': 'Navigator', | 159 'NavigatorID': 'Navigator', |
152 'Clipboard': 'DataTransfer', | 160 'Clipboard': 'DataTransfer', |
153 'Player': 'AnimationPlayer', | 161 'Player': 'AnimationPlayer', |
| 162 'Algorithm': 'KeyAlgorithm', |
| 163 'any': 'ScriptValue', |
| 164 'URLUtils': 'URL', |
| 165 'URLUtilsReadOnly': 'WorkerLocation' |
154 } | 166 } |
155 | 167 |
156 _cpp_partial_map = {} | 168 _cpp_partial_map = {} |
157 | 169 |
158 _cpp_no_auto_scope_list = set([ | 170 _cpp_no_auto_scope_list = set([ |
159 ('Document', 'body', 'Getter'), | 171 ('Document', 'body', 'Getter'), |
160 ('Document', 'getElementById', 'Callback'), | 172 ('Document', 'getElementById', 'Callback'), |
161 ('Document', 'getElementsByName', 'Callback'), | 173 ('Document', 'getElementsByName', 'Callback'), |
162 ('Document', 'getElementsByTagName', 'Callback'), | 174 ('Document', 'getElementsByTagName', 'Callback'), |
163 ('Element', 'getAttribute', 'Callback'), | 175 ('Element', 'getAttribute', 'Callback'), |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 return _cpp_partial_map[interface_name] | 323 return _cpp_partial_map[interface_name] |
312 else: | 324 else: |
313 return set([]) | 325 return set([]) |
314 | 326 |
315 def array_type(data_type): | 327 def array_type(data_type): |
316 matched = re.match(r'([\w\d_\s]+)\[\]', data_type) | 328 matched = re.match(r'([\w\d_\s]+)\[\]', data_type) |
317 if not matched: | 329 if not matched: |
318 return None | 330 return None |
319 return matched.group(1) | 331 return matched.group(1) |
320 | 332 |
321 def TypeIdToBlinkName(interface_id): | 333 def TypeIdToBlinkName(interface_id, database): |
| 334 if database.HasEnum(interface_id): |
| 335 return "DOMString" # All enums are strings. |
| 336 |
322 if interface_id in _blink_1916_rename_map: | 337 if interface_id in _blink_1916_rename_map: |
323 interface_id = _blink_1916_rename_map[interface_id] | 338 interface_id = _blink_1916_rename_map[interface_id] |
324 return interface_id | 339 return interface_id |
325 | 340 |
326 def _GetCPPTypeName(interface_name, callback_name, cpp_name): | 341 def _GetCPPTypeName(interface_name, callback_name, cpp_name): |
327 # TODO(vsm): We need to track the original IDL file name in order to recover | 342 # TODO(vsm): We need to track the original IDL file name in order to recover |
328 # the proper CPP name. | 343 # the proper CPP name. |
329 | 344 |
330 cpp_tuple = (interface_name, callback_name) | 345 cpp_tuple = (interface_name, callback_name) |
331 if cpp_tuple in _cpp_callback_map: | 346 if cpp_tuple in _cpp_callback_map: |
332 cpp_type_name = _cpp_callback_map[cpp_tuple] | 347 cpp_type_name = _cpp_callback_map[cpp_tuple] |
333 elif (interface_name, cpp_name) in _cpp_overloaded_callback_map: | 348 elif (interface_name, cpp_name) in _cpp_overloaded_callback_map: |
334 cpp_type_name = _cpp_overloaded_callback_map[(interface_name, cpp_name)] | 349 cpp_type_name = _cpp_overloaded_callback_map[(interface_name, cpp_name)] |
335 else: | 350 else: |
336 cpp_type_name = interface_name | 351 cpp_type_name = interface_name |
337 return cpp_type_name | 352 return cpp_type_name |
338 | 353 |
339 def DeriveQualifiedName(library_name, name): | 354 def DeriveQualifiedName(library_name, name): |
340 return library_name + "." + name | 355 return library_name + "." + name |
341 | 356 |
342 def DeriveNativeName(interface_name, name, suffix): | 357 def DeriveNativeName(interface_name, name, suffix): |
343 fields = ["Native", interface_name, name] | 358 fields = ["Native", interface_name, name] |
344 if suffix != "": | 359 if suffix != "": |
345 fields.append(suffix) | 360 fields.append(suffix) |
346 return "_".join(fields) | 361 return "_".join(fields) |
347 | 362 |
348 def DeriveResolverString(interface_id, operation_id, native_suffix, type_ids, is
_custom=False): | 363 def DeriveResolverString(interface_id, operation_id, native_suffix, type_ids, da
tabase, is_custom): |
349 type_string = \ | 364 type_string = \ |
350 "_".join(map(TypeIdToBlinkName, type_ids)) | 365 "_".join(map(lambda type_id : TypeIdToBlinkName(type_id, database), type
_ids)) |
351 if native_suffix: | 366 if native_suffix: |
352 operation_id = "%s_%s" % (operation_id, native_suffix) | 367 operation_id = "%s_%s" % (operation_id, native_suffix) |
353 if is_custom: | 368 if is_custom: |
354 components = \ | 369 components = \ |
355 [TypeIdToBlinkName(interface_id), operation_id] | 370 [TypeIdToBlinkName(interface_id, database), operation_id] |
356 else: | 371 else: |
357 components = \ | 372 components = \ |
358 [TypeIdToBlinkName(interface_id), operation_id, | 373 [TypeIdToBlinkName(interface_id, database), operation_id, |
359 "RESOLVER_STRING", str(len(type_ids)), type_string] | 374 "RESOLVER_STRING", str(len(type_ids)), type_string] |
360 return "_".join(components) | 375 return "_".join(components) |
361 | 376 |
362 # FIXME(leafp) This should really go elsewhere. I think the right thing | 377 # FIXME(leafp) This should really go elsewhere. I think the right thing |
363 # to do is to add support in the DartLibraries objects in systemhtml | 378 # to do is to add support in the DartLibraries objects in systemhtml |
364 # for emitting top level code in libraries. This can then just be a | 379 # for emitting top level code in libraries. This can then just be a |
365 # normal use of that kind of object | 380 # normal use of that kind of object |
366 def GetNativeLibraryEmitter(emitters, template_loader, | 381 def GetNativeLibraryEmitter(emitters, template_loader, |
367 dartium_output_dir, dart_output_dir, | 382 dartium_output_dir, dart_output_dir, |
368 auxiliary_dir): | 383 auxiliary_dir): |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 else: | 613 else: |
599 argument_count = len(arguments) | 614 argument_count = len(arguments) |
600 | 615 |
601 typed_formals = constructor_info.ParametersAsArgumentList(argument_count) | 616 typed_formals = constructor_info.ParametersAsArgumentList(argument_count) |
602 parameters = constructor_info.ParametersAsStringOfVariables(argument_count) | 617 parameters = constructor_info.ParametersAsStringOfVariables(argument_count) |
603 interface_name = self._interface_type_info.interface_name() | 618 interface_name = self._interface_type_info.interface_name() |
604 | 619 |
605 if self._dart_use_blink: | 620 if self._dart_use_blink: |
606 type_ids = [p.type.id for p in arguments[:argument_count]] | 621 type_ids = [p.type.id for p in arguments[:argument_count]] |
607 constructor_callback_id = \ | 622 constructor_callback_id = \ |
608 DeriveResolverString(self._interface.id, cpp_suffix, None, type_ids,
is_custom) | 623 DeriveResolverString(self._interface.id, cpp_suffix, None, type_ids,
self._database, is_custom) |
609 else: | 624 else: |
610 constructor_callback_id = self._interface.id + '_' + constructor_callbac
k_cpp_name | 625 constructor_callback_id = self._interface.id + '_' + constructor_callbac
k_cpp_name |
611 | 626 |
612 if self._dart_use_blink: | 627 if self._dart_use_blink: |
613 # First we emit the toplevel function | 628 # First we emit the toplevel function |
614 dart_native_name = \ | 629 dart_native_name = \ |
615 DeriveNativeName(self._interface.id, constructor_callback_cpp_name,
"") | 630 DeriveNativeName(self._interface.id, constructor_callback_cpp_name,
"") |
616 if constructor_callback_id in _cpp_resolver_string_map: | 631 if constructor_callback_id in _cpp_resolver_string_map: |
617 constructor_callback_id = \ | 632 constructor_callback_id = \ |
618 _cpp_resolver_string_map[constructor_callback_id] | 633 _cpp_resolver_string_map[constructor_callback_id] |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1023 # | 1038 # |
1024 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } | 1039 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } |
1025 # | 1040 # |
1026 dart_element_type = self._DartType(element_type) | 1041 dart_element_type = self._DartType(element_type) |
1027 if self._HasNativeIndexGetter(): | 1042 if self._HasNativeIndexGetter(): |
1028 self._EmitNativeIndexGetter(dart_element_type) | 1043 self._EmitNativeIndexGetter(dart_element_type) |
1029 elif self._HasExplicitIndexedGetter(): | 1044 elif self._HasExplicitIndexedGetter(): |
1030 self._EmitExplicitIndexedGetter(dart_element_type) | 1045 self._EmitExplicitIndexedGetter(dart_element_type) |
1031 else: | 1046 else: |
1032 if self._dart_use_blink: | 1047 if self._dart_use_blink: |
| 1048 is_custom = any((op.id == 'item' and 'Custom' in op.ext_attrs) for op
in self._interface.operations) |
1033 dart_native_name = \ | 1049 dart_native_name = \ |
1034 DeriveNativeName(self._interface.id, "NativeIndexed", "Getter") | 1050 DeriveNativeName(self._interface.id, "NativeIndexed", "Getter") |
1035 # First emit a toplevel function to do the native call | 1051 # First emit a toplevel function to do the native call |
1036 # Calls to this are emitted elsewhere, | 1052 # Calls to this are emitted elsewhere, |
1037 resolver_string = \ | 1053 resolver_string = \ |
1038 DeriveResolverString(self._interface.id, "item", "Callback", | 1054 DeriveResolverString(self._interface.id, "item", "Callback", |
1039 ["unsigned long"]) | 1055 ["unsigned long"], self._database, is_custom) |
1040 if resolver_string in _cpp_resolver_string_map: | 1056 if resolver_string in _cpp_resolver_string_map: |
1041 resolver_string = \ | 1057 resolver_string = \ |
1042 _cpp_resolver_string_map[resolver_string] | 1058 _cpp_resolver_string_map[resolver_string] |
1043 self._native_library_emitter.Emit( | 1059 self._native_library_emitter.Emit( |
1044 '\n' | 1060 '\n' |
1045 '$(DART_NATIVE_NAME)(mthis, index) ' | 1061 '$(DART_NATIVE_NAME)(mthis, index) ' |
1046 'native "$(RESOLVER_STRING)";\n', | 1062 'native "$(RESOLVER_STRING)";\n', |
1047 DART_NATIVE_NAME = dart_native_name, | 1063 DART_NATIVE_NAME = dart_native_name, |
1048 RESOLVER_STRING=resolver_string) | 1064 RESOLVER_STRING=resolver_string) |
1049 | 1065 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1168 elif not needs_dispatcher: | 1184 elif not needs_dispatcher: |
1169 # Bind directly to native implementation | 1185 # Bind directly to native implementation |
1170 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) | 1186 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) |
1171 native_suffix = 'Callback' | 1187 native_suffix = 'Callback' |
1172 auto_scope_setup = self._GenerateAutoSetupScope(info.name, native_suffix) | 1188 auto_scope_setup = self._GenerateAutoSetupScope(info.name, native_suffix) |
1173 if self._dart_use_blink: | 1189 if self._dart_use_blink: |
1174 type_ids = [argument.type.id | 1190 type_ids = [argument.type.id |
1175 for argument in operation.arguments[:len(info.param_infos)
]] | 1191 for argument in operation.arguments[:len(info.param_infos)
]] |
1176 resolver_string = \ | 1192 resolver_string = \ |
1177 DeriveResolverString(self._interface.id, operation.id, | 1193 DeriveResolverString(self._interface.id, operation.id, |
1178 native_suffix, type_ids, is_custom) | 1194 native_suffix, type_ids, self._database, is_c
ustom) |
1179 else: | 1195 else: |
1180 resolver_string = None | 1196 resolver_string = None |
1181 cpp_callback_name = self._GenerateNativeBinding( | 1197 cpp_callback_name = self._GenerateNativeBinding( |
1182 info.name, argument_count, dart_declaration, | 1198 info.name, argument_count, dart_declaration, |
1183 info.IsStatic(), return_type, parameters, | 1199 info.IsStatic(), return_type, parameters, |
1184 native_suffix, is_custom, auto_scope_setup, | 1200 native_suffix, is_custom, auto_scope_setup, |
1185 resolver_string=resolver_string) | 1201 resolver_string=resolver_string) |
1186 if not is_custom: | 1202 if not is_custom: |
1187 self._GenerateOperationNativeCallback(operation, operation.arguments, cp
p_callback_name, auto_scope_setup) | 1203 self._GenerateOperationNativeCallback(operation, operation.arguments, cp
p_callback_name, auto_scope_setup) |
1188 else: | 1204 else: |
(...skipping 15 matching lines...) Expand all Loading... |
1204 static = True | 1220 static = True |
1205 if not operation.is_static: | 1221 if not operation.is_static: |
1206 actuals = ['mthis'] + actuals | 1222 actuals = ['mthis'] + actuals |
1207 actuals_s = ", ".join(actuals) | 1223 actuals_s = ", ".join(actuals) |
1208 dart_declaration = '%s(%s)' % ( | 1224 dart_declaration = '%s(%s)' % ( |
1209 base_name, actuals_s) | 1225 base_name, actuals_s) |
1210 type_ids = [argument.type.id | 1226 type_ids = [argument.type.id |
1211 for argument in operation.arguments[:argument_count]] | 1227 for argument in operation.arguments[:argument_count]] |
1212 resolver_string = \ | 1228 resolver_string = \ |
1213 DeriveResolverString(self._interface.id, operation.id, | 1229 DeriveResolverString(self._interface.id, operation.id, |
1214 native_suffix, type_ids) | 1230 native_suffix, type_ids, self._database, is_c
ustom) |
1215 else: | 1231 else: |
1216 base_name = '_%s_%s' % (operation.id, version) | 1232 base_name = '_%s_%s' % (operation.id, version) |
1217 overload_name = base_name | 1233 overload_name = base_name |
1218 static = operation.is_static | 1234 static = operation.is_static |
1219 actuals_s = ", ".join(actuals) | 1235 actuals_s = ", ".join(actuals) |
1220 dart_declaration = '%s%s %s(%s)' % ( | 1236 dart_declaration = '%s%s %s(%s)' % ( |
1221 'static ' if static else '', | 1237 'static ' if static else '', |
1222 return_type, | 1238 return_type, |
1223 overload_name, actuals_s) | 1239 overload_name, actuals_s) |
1224 resolver_string = None | 1240 resolver_string = None |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1666 self._renamer.GetLibraryName(self._interface), | 1682 self._renamer.GetLibraryName(self._interface), |
1667 self._interface, idl_name, ' ') | 1683 self._interface, idl_name, ' ') |
1668 dart_native_name = \ | 1684 dart_native_name = \ |
1669 DeriveNativeName(self._interface.id, idl_name, native_suffix) | 1685 DeriveNativeName(self._interface.id, idl_name, native_suffix) |
1670 | 1686 |
1671 if (resolver_string): | 1687 if (resolver_string): |
1672 native_binding = resolver_string | 1688 native_binding = resolver_string |
1673 else: | 1689 else: |
1674 native_binding_id = self._interface.id | 1690 native_binding_id = self._interface.id |
1675 if self._dart_use_blink: | 1691 if self._dart_use_blink: |
1676 native_binding_id = TypeIdToBlinkName(native_binding_id) | 1692 native_binding_id = TypeIdToBlinkName(native_binding_id, self._databas
e) |
1677 native_binding = \ | 1693 native_binding = \ |
1678 '%s_%s_%s' % (native_binding_id, idl_name, native_suffix) | 1694 '%s_%s_%s' % (native_binding_id, idl_name, native_suffix) |
1679 | 1695 |
1680 if self._dart_use_blink: | 1696 if self._dart_use_blink: |
1681 if not static: | 1697 if not static: |
1682 formals = ", ".join(['mthis'] + parameters) | 1698 formals = ", ".join(['mthis'] + parameters) |
1683 actuals = ", ".join(['this'] + parameters) | 1699 actuals = ", ".join(['this'] + parameters) |
1684 else: | 1700 else: |
1685 formals = ", ".join(parameters) | 1701 formals = ", ".join(parameters) |
1686 actuals = ", ".join(parameters) | 1702 actuals = ", ".join(parameters) |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1973 e.Emit("};\n"); | 1989 e.Emit("};\n"); |
1974 e.Emit('\n'); | 1990 e.Emit('\n'); |
1975 e.Emit('} // namespace WebCore\n'); | 1991 e.Emit('} // namespace WebCore\n'); |
1976 | 1992 |
1977 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): | 1993 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): |
1978 return ( | 1994 return ( |
1979 interface.id.endswith('Event') and | 1995 interface.id.endswith('Event') and |
1980 operation.id.startswith('init') and | 1996 operation.id.startswith('init') and |
1981 argument.ext_attrs.get('Default') == 'Undefined' and | 1997 argument.ext_attrs.get('Default') == 'Undefined' and |
1982 argument.type.id == 'DOMString') | 1998 argument.type.id == 'DOMString') |
OLD | NEW |