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 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 dart_declaration = 'void operator[]=(int index, %s value)' % element_type | 421 dart_declaration = 'void operator[]=(int index, %s value)' % element_type |
422 self._GenerateNativeBinding('numericIndexSetter', 3, dart_declaration, | 422 self._GenerateNativeBinding('numericIndexSetter', 3, dart_declaration, |
423 'Callback', True) | 423 'Callback', True) |
424 | 424 |
425 def EmitOperation(self, info, html_name): | 425 def EmitOperation(self, info, html_name): |
426 """ | 426 """ |
427 Arguments: | 427 Arguments: |
428 info: An OperationInfo object. | 428 info: An OperationInfo object. |
429 """ | 429 """ |
430 | 430 |
431 operation = info.operations[0] | |
432 | |
433 is_custom = 'Custom' in operation.ext_attrs | |
434 has_optional_arguments = any(self._IsArgumentOptionalInWebCore(operation, ar
gument) for argument in operation.arguments) | |
435 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option
al_arguments) | |
436 | |
437 dart_declaration = '%s%s %s(%s)' % ( | 431 dart_declaration = '%s%s %s(%s)' % ( |
438 'static ' if info.IsStatic() else '', | 432 'static ' if info.IsStatic() else '', |
439 self.SecureOutputType(info.type_name), | 433 self.SecureOutputType(info.type_name), |
440 html_name, | 434 html_name, |
441 info.ParametersDeclaration( | 435 info.ParametersDeclaration(self._DartType)) |
442 (lambda x: 'dynamic') if needs_dispatcher else self._DartType)) | 436 |
| 437 operation = info.operations[0] |
| 438 is_custom = 'Custom' in operation.ext_attrs |
| 439 has_optional_arguments = any(self._IsArgumentOptionalInWebCore(operation, ar
gument) for argument in operation.arguments) |
| 440 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option
al_arguments) |
443 | 441 |
444 if not needs_dispatcher: | 442 if not needs_dispatcher: |
445 # Bind directly to native implementation | 443 # Bind directly to native implementation |
446 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) | 444 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) |
447 cpp_callback_name = self._GenerateNativeBinding( | 445 cpp_callback_name = self._GenerateNativeBinding( |
448 info.name, argument_count, dart_declaration, 'Callback', is_custom) | 446 info.name, argument_count, dart_declaration, 'Callback', is_custom) |
449 if not is_custom: | 447 if not is_custom: |
450 self._GenerateOperationNativeCallback(operation, operation.arguments, cp
p_callback_name) | 448 self._GenerateOperationNativeCallback(operation, operation.arguments, cp
p_callback_name) |
451 else: | 449 else: |
452 self._GenerateDispatcher(info.operations, dart_declaration, [info.name for
info in info.param_infos]) | 450 self._GenerateDispatcher(info.operations, dart_declaration, [info.name for
info in info.param_infos]) |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
876 LIBRARY_NAME=library_name) | 874 LIBRARY_NAME=library_name) |
877 | 875 |
878 headers = self._library_headers[library_name] | 876 headers = self._library_headers[library_name] |
879 for header_file in headers: | 877 for header_file in headers: |
880 path = os.path.relpath(header_file, output_dir) | 878 path = os.path.relpath(header_file, output_dir) |
881 includes_emitter.Emit('#include "$PATH"\n', PATH=path) | 879 includes_emitter.Emit('#include "$PATH"\n', PATH=path) |
882 body_emitter.Emit( | 880 body_emitter.Emit( |
883 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu
mentCount))\n' | 881 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu
mentCount))\n' |
884 ' return func;\n', | 882 ' return func;\n', |
885 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) | 883 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) |
OLD | NEW |