| 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 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 cpp_callback_name = self._GenerateNativeBinding( | 496 cpp_callback_name = self._GenerateNativeBinding( |
| 497 overload_name, (0 if operation.is_static else 1) + argument_count, | 497 overload_name, (0 if operation.is_static else 1) + argument_count, |
| 498 dart_declaration, 'Callback', False) | 498 dart_declaration, 'Callback', False) |
| 499 self._GenerateOperationNativeCallback(operation, operation.arguments[:argu
ment_count], cpp_callback_name) | 499 self._GenerateOperationNativeCallback(operation, operation.arguments[:argu
ment_count], cpp_callback_name) |
| 500 | 500 |
| 501 def GenerateChecksAndCall(operation, argument_count): | 501 def GenerateChecksAndCall(operation, argument_count): |
| 502 checks = ['!?%s' % name for name in argument_names] | 502 checks = ['!?%s' % name for name in argument_names] |
| 503 for i in range(0, argument_count): | 503 for i in range(0, argument_count): |
| 504 argument = operation.arguments[i] | 504 argument = operation.arguments[i] |
| 505 argument_name = argument_names[i] | 505 argument_name = argument_names[i] |
| 506 checks[i] = '(%s is %s || %s === null)' % ( | 506 checks[i] = '(%s is %s || %s == null)' % ( |
| 507 argument_name, self._DartType(argument.type.id), argument_name) | 507 argument_name, self._DartType(argument.type.id), argument_name) |
| 508 GenerateCall(operation, argument_count, checks) | 508 GenerateCall(operation, argument_count, checks) |
| 509 | 509 |
| 510 # TODO: Optimize the dispatch to avoid repeated checks. | 510 # TODO: Optimize the dispatch to avoid repeated checks. |
| 511 if len(operations) > 1: | 511 if len(operations) > 1: |
| 512 for operation in operations: | 512 for operation in operations: |
| 513 for position, argument in enumerate(operation.arguments): | 513 for position, argument in enumerate(operation.arguments): |
| 514 if self._IsArgumentOptionalInWebCore(operation, argument): | 514 if self._IsArgumentOptionalInWebCore(operation, argument): |
| 515 GenerateChecksAndCall(operation, position) | 515 GenerateChecksAndCall(operation, position) |
| 516 GenerateChecksAndCall(operation, len(operation.arguments)) | 516 GenerateChecksAndCall(operation, len(operation.arguments)) |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 def EmitResolver(self, template, output_dir): | 856 def EmitResolver(self, template, output_dir): |
| 857 file_path = os.path.join(output_dir, 'DartResolver.cpp') | 857 file_path = os.path.join(output_dir, 'DartResolver.cpp') |
| 858 includes_emitter, body_emitter = self._emitters.FileEmitter(file_path).Emit(
template) | 858 includes_emitter, body_emitter = self._emitters.FileEmitter(file_path).Emit(
template) |
| 859 for header_file in self._headers_list: | 859 for header_file in self._headers_list: |
| 860 path = os.path.relpath(header_file, output_dir) | 860 path = os.path.relpath(header_file, output_dir) |
| 861 includes_emitter.Emit('#include "$PATH"\n', PATH=path) | 861 includes_emitter.Emit('#include "$PATH"\n', PATH=path) |
| 862 body_emitter.Emit( | 862 body_emitter.Emit( |
| 863 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argume
ntCount))\n' | 863 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argume
ntCount))\n' |
| 864 ' return func;\n', | 864 ' return func;\n', |
| 865 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) | 865 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) |
| OLD | NEW |