| 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 import systembase | 11 import systembase | 
| 12 from generator import * | 12 from generator import * | 
| 13 from systemhtml import HtmlSystemShared |  | 
| 14 | 13 | 
| 15 | 14 | 
| 16 class NativeImplementationSystem(systembase.System): | 15 class NativeImplementationSystem(systembase.System): | 
| 17 | 16 | 
| 18   def __init__(self, context, auxiliary_dir): | 17   def __init__(self, context, auxiliary_dir): | 
| 19     super(NativeImplementationSystem, self).__init__(context) | 18     super(NativeImplementationSystem, self).__init__(context) | 
| 20     self._auxiliary_dir = auxiliary_dir | 19     self._auxiliary_dir = auxiliary_dir | 
| 21     self._cpp_header_files = [] | 20     self._cpp_header_files = [] | 
| 22     self._cpp_impl_files = [] | 21     self._cpp_impl_files = [] | 
| 23     self._html_system = HtmlSystemShared(self._database) |  | 
| 24 | 22 | 
| 25   def ImplementationGenerator(self, interface): | 23   def ImplementationGenerator(self, interface): | 
| 26     return NativeImplementationGenerator(self, interface) | 24     return NativeImplementationGenerator(self, interface) | 
| 27 | 25 | 
| 28   def ProcessCallback(self, interface, info): | 26   def ProcessCallback(self, interface, info): | 
| 29     self._interface = interface | 27     self._interface = interface | 
| 30 | 28 | 
| 31     if IsPureInterface(self._interface.id): | 29     if IsPureInterface(self._interface.id): | 
| 32       return None | 30       return None | 
| 33 | 31 | 
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 160     Args: | 158     Args: | 
| 161       system: The NativeImplementationSystem. | 159       system: The NativeImplementationSystem. | 
| 162       interface: an IDLInterface instance. It is assumed that all types have | 160       interface: an IDLInterface instance. It is assumed that all types have | 
| 163           been converted to Dart types (e.g. int, String), unless they are in | 161           been converted to Dart types (e.g. int, String), unless they are in | 
| 164           the same package as the interface. | 162           the same package as the interface. | 
| 165     """ | 163     """ | 
| 166     super(NativeImplementationGenerator, self).__init__( | 164     super(NativeImplementationGenerator, self).__init__( | 
| 167         system._database, interface) | 165         system._database, interface) | 
| 168     self._system = system | 166     self._system = system | 
| 169     self._current_secondary_parent = None | 167     self._current_secondary_parent = None | 
| 170     self._html_system = self._system._html_system | 168     self._html_interface_name = system._type_registry.InterfaceName(self._interf
     ace.id) | 
| 171     self._html_interface_name = self._html_system._html_renames.get( |  | 
| 172         self._interface.id, self._interface.id) |  | 
| 173 | 169 | 
| 174   def HasImplementation(self): | 170   def HasImplementation(self): | 
| 175     return not IsPureInterface(self._interface.id) | 171     return not IsPureInterface(self._interface.id) | 
| 176 | 172 | 
| 177   def ImplementationClassName(self): | 173   def ImplementationClassName(self): | 
| 178     return self._ImplClassName(self._interface.id) | 174     return self._ImplClassName(self._interface.id) | 
| 179 | 175 | 
| 180   def FilePathForDartImplementation(self): | 176   def FilePathForDartImplementation(self): | 
| 181     return os.path.join(self._system._output_dir, 'dart', | 177     return os.path.join(self._system._output_dir, 'dart', | 
| 182                         '%sImplementation.dart' % self._interface.id) | 178                         '%sImplementation.dart' % self._interface.id) | 
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 313 | 309 | 
| 314     self._GenerateNativeCallback(callback_name='constructorCallback', | 310     self._GenerateNativeCallback(callback_name='constructorCallback', | 
| 315         parameter_definitions=parameter_definitions_emitter.Fragments(), | 311         parameter_definitions=parameter_definitions_emitter.Fragments(), | 
| 316         needs_receiver=False, invocation=invocation, | 312         needs_receiver=False, invocation=invocation, | 
| 317         raises_exceptions=raises_exceptions, | 313         raises_exceptions=raises_exceptions, | 
| 318         runtime_check=runtime_check) | 314         runtime_check=runtime_check) | 
| 319 | 315 | 
| 320   def _ImplClassName(self, interface_name): | 316   def _ImplClassName(self, interface_name): | 
| 321     return '_%sImpl' % interface_name | 317     return '_%sImpl' % interface_name | 
| 322 | 318 | 
| 323   def _DartType(self, idl_type): |  | 
| 324     return self._html_system.DartType(idl_type) |  | 
| 325 |  | 
| 326   def _BaseClassName(self): | 319   def _BaseClassName(self): | 
| 327     root_class = 'NativeFieldWrapperClass1' | 320     root_class = 'NativeFieldWrapperClass1' | 
| 328 | 321 | 
| 329     if not self._interface.parents: | 322     if not self._interface.parents: | 
| 330       return root_class | 323       return root_class | 
| 331 | 324 | 
| 332     supertype = self._interface.parents[0].type.id | 325     supertype = self._interface.parents[0].type.id | 
| 333 | 326 | 
| 334     if IsPureInterface(supertype):    # The class is a root. | 327     if IsPureInterface(supertype):    # The class is a root. | 
| 335       return root_class | 328       return root_class | 
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 637         'Callback', True) | 630         'Callback', True) | 
| 638 | 631 | 
| 639   def _HasNativeIndexSetter(self): | 632   def _HasNativeIndexSetter(self): | 
| 640     return 'CustomIndexedSetter' in self._interface.ext_attrs | 633     return 'CustomIndexedSetter' in self._interface.ext_attrs | 
| 641 | 634 | 
| 642   def _EmitNativeIndexSetter(self, element_type): | 635   def _EmitNativeIndexSetter(self, element_type): | 
| 643     dart_declaration = 'void operator[]=(int index, %s value)' % element_type | 636     dart_declaration = 'void operator[]=(int index, %s value)' % element_type | 
| 644     self._GenerateNativeBinding('numericIndexSetter', 3, dart_declaration, | 637     self._GenerateNativeBinding('numericIndexSetter', 3, dart_declaration, | 
| 645         'Callback', True) | 638         'Callback', True) | 
| 646 | 639 | 
| 647   def _AddOperation(self, info): | 640   def AddOperation(self, info, html_name): | 
| 648     """ | 641     """ | 
| 649     Arguments: | 642     Arguments: | 
| 650       info: An OperationInfo object. | 643       info: An OperationInfo object. | 
| 651     """ | 644     """ | 
| 652 | 645 | 
| 653     operation = info.operations[0] | 646     operation = info.operations[0] | 
| 654 | 647 | 
| 655     if 'CheckSecurityForNode' in operation.ext_attrs: | 648     if 'CheckSecurityForNode' in operation.ext_attrs: | 
| 656       # FIXME: exclude from interface as well. | 649       # FIXME: exclude from interface as well. | 
| 657       return | 650       return | 
| 658 | 651 | 
| 659     html_name = self._html_system.RenameInHtmlLibrary( |  | 
| 660         self._interface.id, info.name, implementation_class=True) |  | 
| 661 |  | 
| 662     if not html_name and info.name == 'item': |  | 
| 663       # FIXME: item should be renamed to operator[], not removed. |  | 
| 664       html_name = '_item' |  | 
| 665 |  | 
| 666     if not html_name: |  | 
| 667       return |  | 
| 668 |  | 
| 669     is_custom = 'Custom' in operation.ext_attrs | 652     is_custom = 'Custom' in operation.ext_attrs | 
| 670     has_optional_arguments = any(_IsArgumentOptionalInWebCore(argument) for argu
     ment in operation.arguments) | 653     has_optional_arguments = any(_IsArgumentOptionalInWebCore(argument) for argu
     ment in operation.arguments) | 
| 671     needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option
     al_arguments) | 654     needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option
     al_arguments) | 
| 672 | 655 | 
| 673     if not needs_dispatcher: | 656     if not needs_dispatcher: | 
| 674       type_renamer = self._DartType | 657       type_renamer = self._DartType | 
| 675       default_value = 'null' | 658       default_value = 'null' | 
| 676     else: | 659     else: | 
| 677       type_renamer = lambda x: 'Dynamic' | 660       type_renamer = lambda x: 'Dynamic' | 
| 678       default_value = '_null' | 661       default_value = '_null' | 
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 747         GenerateChecksAndCall(operation, len(operation.arguments)) | 730         GenerateChecksAndCall(operation, len(operation.arguments)) | 
| 748       body.Emit('    throw "Incorrect number or type of arguments";\n'); | 731       body.Emit('    throw "Incorrect number or type of arguments";\n'); | 
| 749     else: | 732     else: | 
| 750       operation = operations[0] | 733       operation = operations[0] | 
| 751       for position, argument in list(enumerate(operation.arguments))[::-1]: | 734       for position, argument in list(enumerate(operation.arguments))[::-1]: | 
| 752         if _IsArgumentOptionalInWebCore(argument): | 735         if _IsArgumentOptionalInWebCore(argument): | 
| 753           check = '%s === _null' % argument_names[position] | 736           check = '%s === _null' % argument_names[position] | 
| 754           GenerateCall(operation, position, [check]) | 737           GenerateCall(operation, position, [check]) | 
| 755       GenerateCall(operation, len(operation.arguments), []) | 738       GenerateCall(operation, len(operation.arguments), []) | 
| 756 | 739 | 
| 757   def AddOperation(self, info): |  | 
| 758     self._AddOperation(info) |  | 
| 759 |  | 
| 760   def AddStaticOperation(self, info): |  | 
| 761     self._AddOperation(info) |  | 
| 762 |  | 
| 763   def SecondaryContext(self, interface): | 740   def SecondaryContext(self, interface): | 
| 764     pass | 741     pass | 
| 765 | 742 | 
| 766   def _GenerateOperationNativeCallback(self, operation, arguments, cpp_callback_
     name): | 743   def _GenerateOperationNativeCallback(self, operation, arguments, cpp_callback_
     name): | 
| 767     webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i
     d) | 744     webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i
     d) | 
| 768 | 745 | 
| 769     parameter_definitions_emitter = emitter.Emitter() | 746     parameter_definitions_emitter = emitter.Emitter() | 
| 770     cpp_arguments = [] | 747     cpp_arguments = [] | 
| 771     raises_exceptions = self._GenerateCallWithHandling( | 748     raises_exceptions = self._GenerateCallWithHandling( | 
| 772         operation, parameter_definitions_emitter, cpp_arguments) | 749         operation, parameter_definitions_emitter, cpp_arguments) | 
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 966 | 943 | 
| 967 def _IsArgumentOptionalInWebCore(argument): | 944 def _IsArgumentOptionalInWebCore(argument): | 
| 968   return IsOptional(argument) and not 'Callback' in argument.ext_attrs | 945   return IsOptional(argument) and not 'Callback' in argument.ext_attrs | 
| 969 | 946 | 
| 970 def _ToWebKitName(name): | 947 def _ToWebKitName(name): | 
| 971   name = name[0].lower() + name[1:] | 948   name = name[0].lower() + name[1:] | 
| 972   name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(), | 949   name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(), | 
| 973                 name) | 950                 name) | 
| 974   return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize()
     , | 951   return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize()
     , | 
| 975                 name) | 952                 name) | 
| OLD | NEW | 
|---|