| 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 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 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) |
| 445 cpp_callback_name = self._GenerateNativeBinding( | 445 cpp_callback_name = self._GenerateNativeBinding( |
| 446 info.name, argument_count, dart_declaration, 'Callback', is_custom) | 446 info.name, argument_count, dart_declaration, 'Callback', is_custom) |
| 447 if not is_custom: | 447 if not is_custom: |
| 448 self._GenerateOperationNativeCallback(operation, operation.arguments, cp
p_callback_name) | 448 self._GenerateOperationNativeCallback(operation, operation.arguments, cp
p_callback_name) |
| 449 else: | 449 else: |
| 450 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]) |
| 451 | 451 |
| 452 def _GenerateDispatcher(self, operations, dart_declaration, parameter_names): | 452 def _GenerateDispatcher(self, operations, dart_declaration, parameter_names): |
| 453 | 453 |
| 454 body = self._members_emitter.Emit( | 454 def GenerateCall( |
| 455 '\n' | 455 stmts_emitter, call_emitter, version, operation, argument_count): |
| 456 ' $DECLARATION {\n' | 456 overload_name = '_%s_%s' % (operation.id, version) |
| 457 '$!BODY' | |
| 458 ' }\n', | |
| 459 DECLARATION=dart_declaration) | |
| 460 | |
| 461 version = [1] | |
| 462 def GenerateCall(operation, argument_count, checks): | |
| 463 if checks: | |
| 464 if operation.type.id != 'void': | |
| 465 template = ' if ($CHECKS) {\n return $CALL;\n }\n' | |
| 466 else: | |
| 467 template = ' if ($CHECKS) {\n $CALL;\n return;\n }\n' | |
| 468 else: | |
| 469 if operation.type.id != 'void': | |
| 470 template = ' return $CALL;\n' | |
| 471 else: | |
| 472 template = ' $CALL;\n' | |
| 473 | |
| 474 overload_name = '_%s_%s' % (operation.id, version[0]) | |
| 475 version[0] += 1 | |
| 476 argument_list = ', '.join(parameter_names[:argument_count]) | 457 argument_list = ', '.join(parameter_names[:argument_count]) |
| 477 call = '%s(%s)' % (overload_name, argument_list) | 458 call_emitter.Emit('$NAME($ARGS)', NAME=overload_name, ARGS=argument_list) |
| 478 body.Emit(template, CHECKS=' && '.join(checks), CALL=call) | |
| 479 | 459 |
| 480 dart_declaration = '%s%s %s(%s)' % ( | 460 dart_declaration = '%s%s %s(%s)' % ( |
| 481 'static ' if operation.is_static else '', | 461 'static ' if operation.is_static else '', |
| 482 self.SecureOutputType(operation.type.id), | 462 self.SecureOutputType(operation.type.id), |
| 483 overload_name, argument_list) | 463 overload_name, argument_list) |
| 484 cpp_callback_name = self._GenerateNativeBinding( | 464 cpp_callback_name = self._GenerateNativeBinding( |
| 485 overload_name, (0 if operation.is_static else 1) + argument_count, | 465 overload_name, (0 if operation.is_static else 1) + argument_count, |
| 486 dart_declaration, 'Callback', False) | 466 dart_declaration, 'Callback', False) |
| 487 self._GenerateOperationNativeCallback(operation, operation.arguments[:argu
ment_count], cpp_callback_name) | 467 self._GenerateOperationNativeCallback(operation, operation.arguments[:argu
ment_count], cpp_callback_name) |
| 488 | 468 |
| 489 self._GenerateDispatcherBody( | 469 self._GenerateDispatcherBody( |
| 490 body, | |
| 491 operations, | 470 operations, |
| 492 parameter_names, | 471 parameter_names, |
| 472 dart_declaration, |
| 493 GenerateCall, | 473 GenerateCall, |
| 494 self._IsArgumentOptionalInWebCore) | 474 self._IsArgumentOptionalInWebCore) |
| 495 | 475 |
| 496 def SecondaryContext(self, interface): | 476 def SecondaryContext(self, interface): |
| 497 pass | 477 pass |
| 498 | 478 |
| 499 def _GenerateOperationNativeCallback(self, operation, arguments, cpp_callback_
name): | 479 def _GenerateOperationNativeCallback(self, operation, arguments, cpp_callback_
name): |
| 500 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i
d) | 480 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i
d) |
| 501 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi
on_name, operation) | 481 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi
on_name, operation) |
| 502 self._GenerateNativeCallback( | 482 self._GenerateNativeCallback( |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 LIBRARY_NAME=library_name) | 848 LIBRARY_NAME=library_name) |
| 869 | 849 |
| 870 headers = self._library_headers[library_name] | 850 headers = self._library_headers[library_name] |
| 871 for header_file in headers: | 851 for header_file in headers: |
| 872 path = os.path.relpath(header_file, output_dir) | 852 path = os.path.relpath(header_file, output_dir) |
| 873 includes_emitter.Emit('#include "$PATH"\n', PATH=path) | 853 includes_emitter.Emit('#include "$PATH"\n', PATH=path) |
| 874 body_emitter.Emit( | 854 body_emitter.Emit( |
| 875 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu
mentCount))\n' | 855 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu
mentCount))\n' |
| 876 ' return func;\n', | 856 ' return func;\n', |
| 877 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) | 857 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) |
| OLD | NEW |