| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 } | 129 } |
| 130 | 130 |
| 131 _cpp_overloaded_callback_map = { | 131 _cpp_overloaded_callback_map = { |
| 132 ('DOMURL', 'createObjectUrlFromSourceCallback'): 'URLMediaSource', | 132 ('DOMURL', 'createObjectUrlFromSourceCallback'): 'URLMediaSource', |
| 133 ('DOMURL', 'createObjectUrlFromStreamCallback'): 'URLMediaStream', | 133 ('DOMURL', 'createObjectUrlFromStreamCallback'): 'URLMediaStream', |
| 134 ('DOMURL', '_createObjectUrlFromWebKitSourceCallback'): 'URLMediaSource', | 134 ('DOMURL', '_createObjectUrlFromWebKitSourceCallback'): 'URLMediaSource', |
| 135 ('DOMURL', '_createObjectURL_2Callback'): 'URLMediaSource', | 135 ('DOMURL', '_createObjectURL_2Callback'): 'URLMediaSource', |
| 136 ('DOMURL', '_createObjectURL_3Callback'): 'URLMediaStream', | 136 ('DOMURL', '_createObjectURL_3Callback'): 'URLMediaStream', |
| 137 } | 137 } |
| 138 | 138 |
| 139 _blink_1916_rename_map = { | |
| 140 'NavigatorID': 'Navigator', | |
| 141 'CanvasRenderingContext' : 'CanvasRenderingContext2D', | |
| 142 'Clipboard': 'DataTransfer', | |
| 143 'Player': 'AnimationPlayer', | |
| 144 'Algorithm': 'KeyAlgorithm', | |
| 145 'any': 'ScriptValue', | |
| 146 'URLUtils': 'URL', | |
| 147 'URLUtilsReadOnly': 'WorkerLocation', | |
| 148 'Path': 'Path2D' | |
| 149 } | |
| 150 | |
| 151 _cpp_partial_map = {} | 139 _cpp_partial_map = {} |
| 152 | 140 |
| 153 _cpp_no_auto_scope_list = set([ | 141 _cpp_no_auto_scope_list = set([ |
| 154 ('Document', 'body', 'Getter'), | 142 ('Document', 'body', 'Getter'), |
| 155 ('Document', 'getElementById', 'Callback'), | 143 ('Document', 'getElementById', 'Callback'), |
| 156 ('Document', 'getElementsByName', 'Callback'), | 144 ('Document', 'getElementsByName', 'Callback'), |
| 157 ('Document', 'getElementsByTagName', 'Callback'), | 145 ('Document', 'getElementsByTagName', 'Callback'), |
| 158 ('Element', 'getAttribute', 'Callback'), | 146 ('Element', 'getAttribute', 'Callback'), |
| 159 ('Element', 'getAttributeNS', 'Callback'), | 147 ('Element', 'getAttributeNS', 'Callback'), |
| 160 ('Element', 'id', 'Getter'), | 148 ('Element', 'id', 'Getter'), |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 seq_match = _sequence_matcher.match(interface_id) | 311 seq_match = _sequence_matcher.match(interface_id) |
| 324 if seq_match is not None: | 312 if seq_match is not None: |
| 325 t = TypeIdToBlinkName(seq_match.group(1), database) | 313 t = TypeIdToBlinkName(seq_match.group(1), database) |
| 326 return "sequence<%s>" % t | 314 return "sequence<%s>" % t |
| 327 | 315 |
| 328 arr_match = array_type(interface_id) | 316 arr_match = array_type(interface_id) |
| 329 if arr_match is not None: | 317 if arr_match is not None: |
| 330 t = TypeIdToBlinkName(arr_match, database) | 318 t = TypeIdToBlinkName(arr_match, database) |
| 331 return "%s[]" % t | 319 return "%s[]" % t |
| 332 | 320 |
| 333 if interface_id in _blink_1916_rename_map: | |
| 334 interface_id = _blink_1916_rename_map[interface_id] | |
| 335 return interface_id | 321 return interface_id |
| 336 | 322 |
| 337 def _GetCPPTypeName(interface_name, callback_name, cpp_name): | 323 def _GetCPPTypeName(interface_name, callback_name, cpp_name): |
| 338 # TODO(vsm): We need to track the original IDL file name in order to recover | 324 # TODO(vsm): We need to track the original IDL file name in order to recover |
| 339 # the proper CPP name. | 325 # the proper CPP name. |
| 340 | 326 |
| 341 cpp_tuple = (interface_name, callback_name) | 327 cpp_tuple = (interface_name, callback_name) |
| 342 if cpp_tuple in _cpp_callback_map: | 328 if cpp_tuple in _cpp_callback_map: |
| 343 cpp_type_name = _cpp_callback_map[cpp_tuple] | 329 cpp_type_name = _cpp_callback_map[cpp_tuple] |
| 344 elif (interface_name, cpp_name) in _cpp_overloaded_callback_map: | 330 elif (interface_name, cpp_name) in _cpp_overloaded_callback_map: |
| (...skipping 23 matching lines...) Expand all Loading... |
| 368 t = "SEQ_%s_SEQ" % t2 | 354 t = "SEQ_%s_SEQ" % t2 |
| 369 return t | 355 return t |
| 370 | 356 |
| 371 arr_match = array_type(t) | 357 arr_match = array_type(t) |
| 372 if arr_match is not None: | 358 if arr_match is not None: |
| 373 t = EncodeType(arr_match) | 359 t = EncodeType(arr_match) |
| 374 return "A_%s_A" % t | 360 return "A_%s_A" % t |
| 375 | 361 |
| 376 return _type_encoding_map.get(t) or t | 362 return _type_encoding_map.get(t) or t |
| 377 | 363 |
| 378 # FIXME(leafp) This should really go elsewhere. I think the right thing | |
| 379 # to do is to add support in the DartLibraries objects in systemhtml | |
| 380 # for emitting top level code in libraries. This can then just be a | |
| 381 # normal use of that kind of object | |
| 382 def GetNativeLibraryEmitter(emitters, template_loader, | |
| 383 dartium_output_dir, dart_output_dir, | |
| 384 auxiliary_dir): | |
| 385 def massage_path(path): | |
| 386 # The most robust way to emit path separators is to use / always. | |
| 387 return path.replace('\\', '/') | |
| 388 template = template_loader.Load('_blink_dartium.darttemplate') | |
| 389 dart_path = os.path.join(dartium_output_dir, '_blink_dartium.dart') | |
| 390 library_emitter = emitters.FileEmitter(dart_path) | |
| 391 auxiliary_dir = os.path.relpath(auxiliary_dir, dartium_output_dir) | |
| 392 emitter = \ | |
| 393 library_emitter.Emit(template, | |
| 394 AUXILIARY_DIR=massage_path(auxiliary_dir)) | |
| 395 return emitter | |
| 396 | |
| 397 class DartiumBackend(HtmlDartGenerator): | 364 class DartiumBackend(HtmlDartGenerator): |
| 398 """Generates Dart implementation for one DOM IDL interface.""" | 365 """Generates Dart implementation for one DOM IDL interface.""" |
| 399 | 366 |
| 400 def __init__(self, interface, native_library_emitter, | 367 def __init__(self, interface, |
| 401 cpp_library_emitter, options): | 368 cpp_library_emitter, options): |
| 402 super(DartiumBackend, self).__init__(interface, options, True) | 369 super(DartiumBackend, self).__init__(interface, options, True) |
| 403 | 370 |
| 404 self._interface = interface | 371 self._interface = interface |
| 405 self._cpp_library_emitter = cpp_library_emitter | 372 self._cpp_library_emitter = cpp_library_emitter |
| 406 self._native_library_emitter = native_library_emitter | |
| 407 self._database = options.database | 373 self._database = options.database |
| 408 self._template_loader = options.templates | 374 self._template_loader = options.templates |
| 409 self._type_registry = options.type_registry | 375 self._type_registry = options.type_registry |
| 410 self._interface_type_info = self._type_registry.TypeInfo(self._interface.id) | 376 self._interface_type_info = self._type_registry.TypeInfo(self._interface.id) |
| 411 self._metadata = options.metadata | 377 self._metadata = options.metadata |
| 412 # These get initialized by StartInterface | 378 # These get initialized by StartInterface |
| 413 self._blink_entries = None | |
| 414 self._cpp_header_emitter = None | 379 self._cpp_header_emitter = None |
| 415 self._cpp_impl_emitter = None | 380 self._cpp_impl_emitter = None |
| 416 self._members_emitter = None | 381 self._members_emitter = None |
| 417 self._cpp_declarations_emitter = None | 382 self._cpp_declarations_emitter = None |
| 418 self._cpp_impl_includes = None | 383 self._cpp_impl_includes = None |
| 419 self._cpp_definitions_emitter = None | 384 self._cpp_definitions_emitter = None |
| 420 self._cpp_resolver_emitter = None | 385 self._cpp_resolver_emitter = None |
| 421 self._native_class_emitter = None | |
| 422 | 386 |
| 423 def ImplementsMergedMembers(self): | 387 def ImplementsMergedMembers(self): |
| 424 # We could not add merged functions to implementation class because | 388 # We could not add merged functions to implementation class because |
| 425 # underlying c++ object doesn't implement them. Merged functions are | 389 # underlying c++ object doesn't implement them. Merged functions are |
| 426 # generated on merged interface implementation instead. | 390 # generated on merged interface implementation instead. |
| 427 return False | 391 return False |
| 428 | 392 |
| 429 def CustomJSMembers(self): | 393 def CustomJSMembers(self): |
| 430 return {} | 394 return {} |
| 431 | 395 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 INTERFACE_NAME=self._interface.id) | 604 INTERFACE_NAME=self._interface.id) |
| 641 | 605 |
| 642 self._cpp_impl_includes.add('"DartArrayBufferViewCustom.h"'); | 606 self._cpp_impl_includes.add('"DartArrayBufferViewCustom.h"'); |
| 643 self._cpp_definitions_emitter.Emit( | 607 self._cpp_definitions_emitter.Emit( |
| 644 '\n' | 608 '\n' |
| 645 'static void constructorCallback(Dart_NativeArguments args)\n' | 609 'static void constructorCallback(Dart_NativeArguments args)\n' |
| 646 '{\n' | 610 '{\n' |
| 647 ' WebCore::DartArrayBufferViewInternal::constructWebGLArray<Dart$(INT
ERFACE_NAME)>(args);\n' | 611 ' WebCore::DartArrayBufferViewInternal::constructWebGLArray<Dart$(INT
ERFACE_NAME)>(args);\n' |
| 648 '}\n', | 612 '}\n', |
| 649 INTERFACE_NAME=self._interface.id); | 613 INTERFACE_NAME=self._interface.id); |
| 650 self._native_class_emitter = self._native_library_emitter.Emit( | |
| 651 '\n' | |
| 652 'class $INTERFACE_NAME {' | |
| 653 '$!METHODS' | |
| 654 '}\n', | |
| 655 INTERFACE_NAME=DeriveBlinkClassName(self._interface.id)) | |
| 656 # TODO(vsm): Should we check for collisions between EventConstructors and ot
hers? | |
| 657 # Should we unify at some point? | |
| 658 if 'EventConstructor' in self._interface.ext_attrs: | |
| 659 self._native_class_emitter.Emit( | |
| 660 '\n' | |
| 661 ' static constructorCallback_2(type, options) native "$(INTERFACE_N
AME)_constructorCallback";\n', | |
| 662 INTERFACE_NAME=self._interface.id | |
| 663 ) | |
| 664 self._blink_entries = {} | |
| 665 | 614 |
| 666 def _EmitConstructorInfrastructure(self, | 615 def _EmitConstructorInfrastructure(self, |
| 667 constructor_info, cpp_prefix, cpp_suffix, factory_method_name, | 616 constructor_info, cpp_prefix, cpp_suffix, factory_method_name, |
| 668 arguments=None, emit_to_native=False, is_custom=False): | 617 arguments=None, emit_to_native=False, is_custom=False): |
| 669 | 618 |
| 670 constructor_callback_cpp_name = cpp_prefix + cpp_suffix | 619 constructor_callback_cpp_name = cpp_prefix + cpp_suffix |
| 671 | 620 |
| 672 if arguments is None: | 621 if arguments is None: |
| 673 arguments = constructor_info.idl_args[0] | 622 arguments = constructor_info.idl_args[0] |
| 674 argument_count = len(arguments) | 623 argument_count = len(arguments) |
| 675 else: | 624 else: |
| 676 argument_count = len(arguments) | 625 argument_count = len(arguments) |
| 677 | 626 |
| 678 typed_formals = constructor_info.ParametersAsArgumentList(argument_count) | 627 typed_formals = constructor_info.ParametersAsArgumentList(argument_count) |
| 679 parameters = constructor_info.ParametersAsStringOfVariables(argument_count) | 628 parameters = constructor_info.ParametersAsStringOfVariables(argument_count) |
| 680 interface_name = self._interface_type_info.interface_name() | 629 interface_name = self._interface_type_info.interface_name() |
| 681 | 630 |
| 682 dart_native_name, constructor_callback_id = \ | 631 dart_native_name, constructor_callback_id = \ |
| 683 self.DeriveNativeEntry(cpp_suffix, 'Constructor', argument_count) | 632 self.DeriveNativeEntry(cpp_suffix, 'Constructor', argument_count) |
| 684 if dart_native_name not in self._blink_entries: | |
| 685 entry = ' static %s(%s) native "%s";' % \ | |
| 686 (dart_native_name, parameters, constructor_callback_id) | |
| 687 self._blink_entries[dart_native_name] = entry | |
| 688 | 633 |
| 689 # Then we emit the impedance matching wrapper to call out to the | 634 # Then we emit the impedance matching wrapper to call out to the |
| 690 # toplevel wrapper | 635 # toplevel wrapper |
| 691 if not emit_to_native: | 636 if not emit_to_native: |
| 692 toplevel_name = \ | 637 toplevel_name = \ |
| 693 self.DeriveQualifiedBlinkName(self._interface.id, | 638 self.DeriveQualifiedBlinkName(self._interface.id, |
| 694 dart_native_name) | 639 dart_native_name) |
| 695 self._members_emitter.Emit( | 640 self._members_emitter.Emit( |
| 696 '\n @DocsEditable()\n' | 641 '\n @DocsEditable()\n' |
| 697 ' static $INTERFACE_NAME $FACTORY_METHOD_NAME($PARAMETERS) => ' | 642 ' static $INTERFACE_NAME $FACTORY_METHOD_NAME($PARAMETERS) => ' |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 | 722 |
| 778 def FinishInterface(self): | 723 def FinishInterface(self): |
| 779 interface = self._interface | 724 interface = self._interface |
| 780 if interface.parents: | 725 if interface.parents: |
| 781 supertype = '%sClassId' % interface.parents[0].type.id | 726 supertype = '%sClassId' % interface.parents[0].type.id |
| 782 else: | 727 else: |
| 783 supertype = '-1' | 728 supertype = '-1' |
| 784 | 729 |
| 785 self._GenerateCPPHeader() | 730 self._GenerateCPPHeader() |
| 786 | 731 |
| 787 for entry in sorted(self._blink_entries): | |
| 788 self._native_class_emitter.Emit( | |
| 789 '\n' + self._blink_entries[entry] + '\n') | |
| 790 | |
| 791 self._native_class_emitter.Emit('\n') | |
| 792 | |
| 793 self._cpp_impl_emitter.Emit( | 732 self._cpp_impl_emitter.Emit( |
| 794 self._template_loader.Load('cpp_implementation.template'), | 733 self._template_loader.Load('cpp_implementation.template'), |
| 795 INTERFACE=self._interface.id, | 734 INTERFACE=self._interface.id, |
| 796 SUPER_INTERFACE=supertype, | 735 SUPER_INTERFACE=supertype, |
| 797 INCLUDES=self._GenerateCPPIncludes(self._cpp_impl_includes), | 736 INCLUDES=self._GenerateCPPIncludes(self._cpp_impl_includes), |
| 798 CALLBACKS=self._cpp_definitions_emitter.Fragments(), | 737 CALLBACKS=self._cpp_definitions_emitter.Fragments(), |
| 799 RESOLVER=self._cpp_resolver_emitter.Fragments(), | 738 RESOLVER=self._cpp_resolver_emitter.Fragments(), |
| 800 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), | 739 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), |
| 801 WEBCORE_CLASS_NAME_ESCAPED= | 740 WEBCORE_CLASS_NAME_ESCAPED= |
| 802 self._interface_type_info.native_type().replace('<', '_').replace('>', '
_'), | 741 self._interface_type_info.native_type().replace('<', '_').replace('>', '
_'), |
| (...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1669 native_binding_id = TypeIdToBlinkName(native_binding_id, self._database) | 1608 native_binding_id = TypeIdToBlinkName(native_binding_id, self._database) |
| 1670 native_binding = \ | 1609 native_binding = \ |
| 1671 '%s_%s_%s' % (native_binding_id, idl_name, native_suffix) | 1610 '%s_%s_%s' % (native_binding_id, idl_name, native_suffix) |
| 1672 | 1611 |
| 1673 if not static: | 1612 if not static: |
| 1674 formals = ", ".join(['mthis'] + parameters) | 1613 formals = ", ".join(['mthis'] + parameters) |
| 1675 actuals = ", ".join(['this'] + parameters) | 1614 actuals = ", ".join(['this'] + parameters) |
| 1676 else: | 1615 else: |
| 1677 formals = ", ".join(parameters) | 1616 formals = ", ".join(parameters) |
| 1678 actuals = ", ".join(parameters) | 1617 actuals = ", ".join(parameters) |
| 1679 if dart_native_name not in self._blink_entries: | |
| 1680 entry = ' static %s(%s) native "%s";' % \ | |
| 1681 (dart_native_name, formals, native_binding) | |
| 1682 self._blink_entries[dart_native_name] = entry | |
| 1683 | 1618 |
| 1684 if not emit_to_native: | 1619 if not emit_to_native: |
| 1685 caller_emitter = self._members_emitter | 1620 caller_emitter = self._members_emitter |
| 1686 full_dart_name = \ | 1621 full_dart_name = \ |
| 1687 self.DeriveQualifiedBlinkName(self._interface.id, | 1622 self.DeriveQualifiedBlinkName(self._interface.id, |
| 1688 dart_native_name) | 1623 dart_native_name) |
| 1689 if IsPureInterface(self._interface.id): | 1624 if IsPureInterface(self._interface.id): |
| 1690 caller_emitter.Emit( | 1625 caller_emitter.Emit( |
| 1691 '\n' | 1626 '\n' |
| 1692 ' $METADATA$DART_DECLARATION;\n', | 1627 ' $METADATA$DART_DECLARATION;\n', |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1971 | 1906 |
| 1972 def _IsCustom(op_or_attr): | 1907 def _IsCustom(op_or_attr): |
| 1973 assert(isinstance(op_or_attr, IDLMember)) | 1908 assert(isinstance(op_or_attr, IDLMember)) |
| 1974 return 'Custom' in op_or_attr.ext_attrs or 'DartCustom' in op_or_attr.ext_attr
s | 1909 return 'Custom' in op_or_attr.ext_attrs or 'DartCustom' in op_or_attr.ext_attr
s |
| 1975 | 1910 |
| 1976 def _IsCustomValue(op_or_attr, value): | 1911 def _IsCustomValue(op_or_attr, value): |
| 1977 if _IsCustom(op_or_attr): | 1912 if _IsCustom(op_or_attr): |
| 1978 return op_or_attr.ext_attrs.get('Custom') == value \ | 1913 return op_or_attr.ext_attrs.get('Custom') == value \ |
| 1979 or op_or_attr.ext_attrs.get('DartCustom') == value | 1914 or op_or_attr.ext_attrs.get('DartCustom') == value |
| 1980 return False | 1915 return False |
| OLD | NEW |