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