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 from generator import * | 11 from generator import * |
12 from htmldartgenerator import * | 12 from htmldartgenerator import * |
13 from systemhtml import js_support_checks | 13 from systemhtml import js_support_checks, GetCallbackInfo |
14 | 14 |
15 class DartiumBackend(HtmlDartGenerator): | 15 class DartiumBackend(HtmlDartGenerator): |
16 """Generates Dart implementation for one DOM IDL interface.""" | 16 """Generates Dart implementation for one DOM IDL interface.""" |
17 | 17 |
18 def __init__(self, interface, cpp_library_emitter, options): | 18 def __init__(self, interface, cpp_library_emitter, options): |
19 super(DartiumBackend, self).__init__(interface, options) | 19 super(DartiumBackend, self).__init__(interface, options) |
20 | 20 |
21 self._interface = interface | 21 self._interface = interface |
22 self._cpp_library_emitter = cpp_library_emitter | 22 self._cpp_library_emitter = cpp_library_emitter |
23 self._database = options.database | 23 self._database = options.database |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 self.SecureOutputType(info.type_name), | 469 self.SecureOutputType(info.type_name), |
470 html_name, | 470 html_name, |
471 info.ParametersDeclaration(self._DartType)) | 471 info.ParametersDeclaration(self._DartType)) |
472 | 472 |
473 operation = info.operations[0] | 473 operation = info.operations[0] |
474 is_custom = 'Custom' in operation.ext_attrs | 474 is_custom = 'Custom' in operation.ext_attrs |
475 has_optional_arguments = any(self._IsArgumentOptionalInWebCore(operation, ar
gument) for argument in operation.arguments) | 475 has_optional_arguments = any(self._IsArgumentOptionalInWebCore(operation, ar
gument) for argument in operation.arguments) |
476 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option
al_arguments) | 476 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option
al_arguments) |
477 | 477 |
478 if not needs_dispatcher: | 478 if not needs_dispatcher: |
479 # Bind directly to native implementation | 479 if info.callback_args: |
480 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) | 480 self._AddFutureifiedOperation(info, html_name) |
481 cpp_callback_name = self._GenerateNativeBinding( | 481 else: |
482 info.name, argument_count, dart_declaration, 'Callback', is_custom) | 482 # Bind directly to native implementation |
483 if not is_custom: | 483 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) |
484 self._GenerateOperationNativeCallback(operation, operation.arguments, cp
p_callback_name) | 484 cpp_callback_name = self._GenerateNativeBinding( |
| 485 info.name, argument_count, dart_declaration, 'Callback', is_custom) |
| 486 if not is_custom: |
| 487 self._GenerateOperationNativeCallback(operation, operation.arguments,
cpp_callback_name) |
485 else: | 488 else: |
486 self._GenerateDispatcher(info.operations, dart_declaration, [info.name for
info in info.param_infos]) | 489 self._GenerateDispatcher(info.operations, dart_declaration, [info.name for
info in info.param_infos]) |
487 | 490 |
488 def _GenerateDispatcher(self, operations, dart_declaration, parameter_names): | 491 def _GenerateDispatcher(self, operations, dart_declaration, parameter_names): |
489 | 492 |
490 def GenerateCall( | 493 def GenerateCall( |
491 stmts_emitter, call_emitter, version, operation, argument_count): | 494 stmts_emitter, call_emitter, version, operation, argument_count): |
492 overload_name = '_%s_%s' % (operation.id, version) | 495 overload_name = '_%s_%s' % (operation.id, version) |
493 argument_list = ', '.join(parameter_names[:argument_count]) | 496 argument_list = ', '.join(parameter_names[:argument_count]) |
494 call_emitter.Emit('$NAME($ARGS)', NAME=overload_name, ARGS=argument_list) | 497 call_emitter.Emit('$NAME($ARGS)', NAME=overload_name, ARGS=argument_list) |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu
mentCount))\n' | 897 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu
mentCount))\n' |
895 ' return func;\n', | 898 ' return func;\n', |
896 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) | 899 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) |
897 | 900 |
898 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): | 901 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): |
899 return ( | 902 return ( |
900 interface.id.endswith('Event') and | 903 interface.id.endswith('Event') and |
901 operation.id.startswith('init') and | 904 operation.id.startswith('init') and |
902 argument.ext_attrs.get('Optional') == 'DefaultIsUndefined' and | 905 argument.ext_attrs.get('Optional') == 'DefaultIsUndefined' and |
903 argument.type.id == 'DOMString') | 906 argument.type.id == 'DOMString') |
OLD | NEW |