Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: tools/dom/scripts/systemnative.py

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

Powered by Google App Engine
This is Rietveld 408576698