| 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 } | 136 } |
| 137 | 137 |
| 138 _cpp_overloaded_callback_map = { | 138 _cpp_overloaded_callback_map = { |
| 139 ('DOMURL', 'createObjectUrlFromSourceCallback'): 'URLMediaSource', | 139 ('DOMURL', 'createObjectUrlFromSourceCallback'): 'URLMediaSource', |
| 140 ('DOMURL', 'createObjectUrlFromStreamCallback'): 'URLMediaStream', | 140 ('DOMURL', 'createObjectUrlFromStreamCallback'): 'URLMediaStream', |
| 141 ('DOMURL', '_createObjectUrlFromWebKitSourceCallback'): 'URLMediaSource', | 141 ('DOMURL', '_createObjectUrlFromWebKitSourceCallback'): 'URLMediaSource', |
| 142 ('DOMURL', '_createObjectURL_2Callback'): 'URLMediaSource', | 142 ('DOMURL', '_createObjectURL_2Callback'): 'URLMediaSource', |
| 143 ('DOMURL', '_createObjectURL_3Callback'): 'URLMediaStream', | 143 ('DOMURL', '_createObjectURL_3Callback'): 'URLMediaStream', |
| 144 } | 144 } |
| 145 | 145 |
| 146 _blink_1916_rename_map = { |
| 147 'NavigatorID': 'Navigator', |
| 148 'Clipboard': 'DataTransfer', |
| 149 'Player': 'AnimationPlayer', |
| 150 } |
| 151 |
| 146 _cpp_partial_map = {} | 152 _cpp_partial_map = {} |
| 147 | 153 |
| 148 _cpp_no_auto_scope_list = set([ | 154 _cpp_no_auto_scope_list = set([ |
| 149 ('Document', 'body', 'Getter'), | 155 ('Document', 'body', 'Getter'), |
| 150 ('Document', 'getElementById', 'Callback'), | 156 ('Document', 'getElementById', 'Callback'), |
| 151 ('Document', 'getElementsByName', 'Callback'), | 157 ('Document', 'getElementsByName', 'Callback'), |
| 152 ('Document', 'getElementsByTagName', 'Callback'), | 158 ('Document', 'getElementsByTagName', 'Callback'), |
| 153 ('Element', 'getAttribute', 'Callback'), | 159 ('Element', 'getAttribute', 'Callback'), |
| 154 ('Element', 'getAttributeNS', 'Callback'), | 160 ('Element', 'getAttributeNS', 'Callback'), |
| 155 ('Element', 'id', 'Getter'), | 161 ('Element', 'id', 'Getter'), |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 return _cpp_partial_map[interface_name] | 307 return _cpp_partial_map[interface_name] |
| 302 else: | 308 else: |
| 303 return set([]) | 309 return set([]) |
| 304 | 310 |
| 305 def array_type(data_type): | 311 def array_type(data_type): |
| 306 matched = re.match(r'([\w\d_\s]+)\[\]', data_type) | 312 matched = re.match(r'([\w\d_\s]+)\[\]', data_type) |
| 307 if not matched: | 313 if not matched: |
| 308 return None | 314 return None |
| 309 return matched.group(1) | 315 return matched.group(1) |
| 310 | 316 |
| 317 def TypeIdToBlinkName(interface_id): |
| 318 if interface_id in _blink_1916_rename_map: |
| 319 interface_id = _blink_1916_rename_map[interface_id] |
| 320 return interface_id |
| 321 |
| 311 def _GetCPPTypeName(interface_name, callback_name, cpp_name): | 322 def _GetCPPTypeName(interface_name, callback_name, cpp_name): |
| 312 # TODO(vsm): We need to track the original IDL file name in order to recover | 323 # TODO(vsm): We need to track the original IDL file name in order to recover |
| 313 # the proper CPP name. | 324 # the proper CPP name. |
| 314 | 325 |
| 315 cpp_tuple = (interface_name, callback_name) | 326 cpp_tuple = (interface_name, callback_name) |
| 316 if cpp_tuple in _cpp_callback_map: | 327 if cpp_tuple in _cpp_callback_map: |
| 317 cpp_type_name = _cpp_callback_map[cpp_tuple] | 328 cpp_type_name = _cpp_callback_map[cpp_tuple] |
| 318 elif (interface_name, cpp_name) in _cpp_overloaded_callback_map: | 329 elif (interface_name, cpp_name) in _cpp_overloaded_callback_map: |
| 319 cpp_type_name = _cpp_overloaded_callback_map[(interface_name, cpp_name)] | 330 cpp_type_name = _cpp_overloaded_callback_map[(interface_name, cpp_name)] |
| 320 else: | 331 else: |
| 321 cpp_type_name = interface_name | 332 cpp_type_name = interface_name |
| 322 return cpp_type_name | 333 return cpp_type_name |
| 323 | 334 |
| 324 def DeriveQualifiedName(library_name, name): | 335 def DeriveQualifiedName(library_name, name): |
| 325 return library_name + "." + name | 336 return library_name + "." + name |
| 326 | 337 |
| 327 def DeriveNativeName(interface_name, name, suffix): | 338 def DeriveNativeName(interface_name, name, suffix): |
| 328 fields = ["Native", interface_name, name] | 339 fields = ["Native", interface_name, name] |
| 329 if suffix != "": | 340 if suffix != "": |
| 330 fields.append(suffix) | 341 fields.append(suffix) |
| 331 return "_".join(fields) | 342 return "_".join(fields) |
| 332 | 343 |
| 333 def DeriveResolverString(interface_id, operation_id, native_suffix, type_ids): | 344 def DeriveResolverString(interface_id, operation_id, native_suffix, type_ids): |
| 334 type_string = \ | 345 type_string = \ |
| 335 "_".join(type_ids) | 346 "_".join(map(TypeIdToBlinkName, type_ids)) |
| 336 if native_suffix: | 347 if native_suffix: |
| 337 operation_id = "%s_%s" % (operation_id, native_suffix) | 348 operation_id = "%s_%s" % (operation_id, native_suffix) |
| 338 components = \ | 349 components = \ |
| 339 [interface_id, operation_id, | 350 [TypeIdToBlinkName(interface_id), operation_id, |
| 340 "RESOLVER_STRING", str(len(type_ids)), type_string] | 351 "RESOLVER_STRING", str(len(type_ids)), type_string] |
| 341 return "_".join(components) | 352 return "_".join(components) |
| 342 | 353 |
| 343 # FIXME(leafp) This should really go elsewhere. I think the right thing | 354 # FIXME(leafp) This should really go elsewhere. I think the right thing |
| 344 # to do is to add support in the DartLibraries objects in systemhtml | 355 # to do is to add support in the DartLibraries objects in systemhtml |
| 345 # for emitting top level code in libraries. This can then just be a | 356 # for emitting top level code in libraries. This can then just be a |
| 346 # normal use of that kind of object | 357 # normal use of that kind of object |
| 347 def GetNativeLibraryEmitter(emitters, template_loader, | 358 def GetNativeLibraryEmitter(emitters, template_loader, |
| 348 dartium_output_dir, dart_output_dir, | 359 dartium_output_dir, dart_output_dir, |
| 349 auxiliary_dir): | 360 auxiliary_dir): |
| (...skipping 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1645 if emit_metadata: | 1656 if emit_metadata: |
| 1646 metadata = self._metadata.GetFormattedMetadata( | 1657 metadata = self._metadata.GetFormattedMetadata( |
| 1647 self._renamer.GetLibraryName(self._interface), | 1658 self._renamer.GetLibraryName(self._interface), |
| 1648 self._interface, idl_name, ' ') | 1659 self._interface, idl_name, ' ') |
| 1649 dart_native_name = \ | 1660 dart_native_name = \ |
| 1650 DeriveNativeName(self._interface.id, idl_name, native_suffix) | 1661 DeriveNativeName(self._interface.id, idl_name, native_suffix) |
| 1651 | 1662 |
| 1652 if (resolver_string): | 1663 if (resolver_string): |
| 1653 native_binding = resolver_string | 1664 native_binding = resolver_string |
| 1654 else: | 1665 else: |
| 1666 native_binding_id = self._interface.id |
| 1667 if self._dart_use_blink: |
| 1668 native_binding_id = TypeIdToBlinkName(native_binding_id) |
| 1655 native_binding = \ | 1669 native_binding = \ |
| 1656 '%s_%s_%s' % (self._interface.id, idl_name, native_suffix) | 1670 '%s_%s_%s' % (native_binding_id, idl_name, native_suffix) |
| 1657 | 1671 |
| 1658 if self._dart_use_blink: | 1672 if self._dart_use_blink: |
| 1659 if not static: | 1673 if not static: |
| 1660 formals = ", ".join(['mthis'] + parameters) | 1674 formals = ", ".join(['mthis'] + parameters) |
| 1661 actuals = ", ".join(['this'] + parameters) | 1675 actuals = ", ".join(['this'] + parameters) |
| 1662 else: | 1676 else: |
| 1663 formals = ", ".join(parameters) | 1677 formals = ", ".join(parameters) |
| 1664 actuals = ", ".join(parameters) | 1678 actuals = ", ".join(parameters) |
| 1665 if native_binding in _cpp_resolver_string_map: | 1679 if native_binding in _cpp_resolver_string_map: |
| 1666 native_binding = \ | 1680 native_binding = \ |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1951 e.Emit("};\n"); | 1965 e.Emit("};\n"); |
| 1952 e.Emit('\n'); | 1966 e.Emit('\n'); |
| 1953 e.Emit('} // namespace WebCore\n'); | 1967 e.Emit('} // namespace WebCore\n'); |
| 1954 | 1968 |
| 1955 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): | 1969 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): |
| 1956 return ( | 1970 return ( |
| 1957 interface.id.endswith('Event') and | 1971 interface.id.endswith('Event') and |
| 1958 operation.id.startswith('init') and | 1972 operation.id.startswith('init') and |
| 1959 argument.ext_attrs.get('Default') == 'Undefined' and | 1973 argument.ext_attrs.get('Default') == 'Undefined' and |
| 1960 argument.type.id == 'DOMString') | 1974 argument.type.id == 'DOMString') |
| OLD | NEW |