| 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 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 if info.callback_args: | 550 if info.callback_args: |
| 551 self._AddFutureifiedOperation(info, html_name) | 551 self._AddFutureifiedOperation(info, html_name) |
| 552 elif not needs_dispatcher: | 552 elif not needs_dispatcher: |
| 553 # Bind directly to native implementation | 553 # Bind directly to native implementation |
| 554 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) | 554 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) |
| 555 cpp_callback_name = self._GenerateNativeBinding( | 555 cpp_callback_name = self._GenerateNativeBinding( |
| 556 info.name, argument_count, dart_declaration, 'Callback', is_custom) | 556 info.name, argument_count, dart_declaration, 'Callback', is_custom) |
| 557 if not is_custom: | 557 if not is_custom: |
| 558 self._GenerateOperationNativeCallback(operation, operation.arguments, cp
p_callback_name) | 558 self._GenerateOperationNativeCallback(operation, operation.arguments, cp
p_callback_name) |
| 559 else: | 559 else: |
| 560 self._GenerateDispatcher(info.operations, dart_declaration, [info.name for
info in info.param_infos]) | 560 self._GenerateDispatcher(info.operations, info.NumberOfRequiredInDart(), d
art_declaration, [info.name for info in info.param_infos]) |
| 561 | 561 |
| 562 def _GenerateDispatcher(self, operations, dart_declaration, parameter_names): | 562 def _GenerateDispatcher(self, operations, number_of_required_in_dart, dart_dec
laration, parameter_names): |
| 563 | 563 |
| 564 def GenerateCall( | 564 def GenerateCall( |
| 565 stmts_emitter, call_emitter, version, operation, argument_count): | 565 stmts_emitter, call_emitter, version, operation, argument_count): |
| 566 overload_name = '_%s_%s' % (operation.id, version) | 566 overload_name = '_%s_%s' % (operation.id, version) |
| 567 argument_list = ', '.join(parameter_names[:argument_count]) | 567 argument_list = ', '.join(parameter_names[:argument_count]) |
| 568 call_emitter.Emit('$NAME($ARGS)', NAME=overload_name, ARGS=argument_list) | 568 call_emitter.Emit('$NAME($ARGS)', NAME=overload_name, ARGS=argument_list) |
| 569 | 569 |
| 570 dart_declaration = '%s%s %s(%s)' % ( | 570 dart_declaration = '%s%s %s(%s)' % ( |
| 571 'static ' if operation.is_static else '', | 571 'static ' if operation.is_static else '', |
| 572 self.SecureOutputType(operation.type.id), | 572 self.SecureOutputType(operation.type.id), |
| 573 overload_name, argument_list) | 573 overload_name, argument_list) |
| 574 cpp_callback_name = self._GenerateNativeBinding( | 574 cpp_callback_name = self._GenerateNativeBinding( |
| 575 overload_name, (0 if operation.is_static else 1) + argument_count, | 575 overload_name, (0 if operation.is_static else 1) + argument_count, |
| 576 dart_declaration, 'Callback', False, False) | 576 dart_declaration, 'Callback', False, False) |
| 577 self._GenerateOperationNativeCallback(operation, operation.arguments[:argu
ment_count], cpp_callback_name) | 577 self._GenerateOperationNativeCallback(operation, operation.arguments[:argu
ment_count], cpp_callback_name) |
| 578 | 578 |
| 579 self._GenerateDispatcherBody( | 579 self._GenerateDispatcherBody( |
| 580 operations, | 580 operations, |
| 581 parameter_names, | 581 parameter_names, |
| 582 number_of_required_in_dart, |
| 582 dart_declaration, | 583 dart_declaration, |
| 583 GenerateCall, | 584 GenerateCall, |
| 584 self._IsArgumentOptionalInWebCore) | 585 self._IsArgumentOptionalInWebCore) |
| 585 | 586 |
| 586 def SecondaryContext(self, interface): | 587 def SecondaryContext(self, interface): |
| 587 pass | 588 pass |
| 588 | 589 |
| 589 def _GenerateOperationNativeCallback(self, operation, arguments, cpp_callback_
name): | 590 def _GenerateOperationNativeCallback(self, operation, arguments, cpp_callback_
name): |
| 590 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i
d) | 591 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i
d) |
| 591 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi
on_name, operation) | 592 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi
on_name, operation) |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu
mentCount))\n' | 1017 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu
mentCount))\n' |
| 1017 ' return func;\n', | 1018 ' return func;\n', |
| 1018 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) | 1019 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) |
| 1019 | 1020 |
| 1020 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): | 1021 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): |
| 1021 return ( | 1022 return ( |
| 1022 interface.id.endswith('Event') and | 1023 interface.id.endswith('Event') and |
| 1023 operation.id.startswith('init') and | 1024 operation.id.startswith('init') and |
| 1024 argument.ext_attrs.get('Default') == 'Undefined' and | 1025 argument.ext_attrs.get('Default') == 'Undefined' and |
| 1025 argument.type.id == 'DOMString') | 1026 argument.type.id == 'DOMString') |
| OLD | NEW |