Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(881)

Side by Side Diff: tools/dom/scripts/systemnative.py

Issue 11896038: Some more refactorings of overload dispatcher generation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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(stmts_emitter, call_emitter, version, operation, argument_c ount):
Emily Fortuna 2013/01/22 19:16:40 80 char
Anton Muhin 2013/01/23 08:16:51 Done.
455 '\n' 455 overload_name = '_%s_%s' % (operation.id, version)
456 ' $DECLARATION {\n'
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]) 456 argument_list = ', '.join(parameter_names[:argument_count])
477 call = '%s(%s)' % (overload_name, argument_list) 457 call_emitter.Emit('$NAME($ARGS)', NAME=overload_name, ARGS=argument_list)
478 body.Emit(template, CHECKS=' && '.join(checks), CALL=call)
479 458
480 dart_declaration = '%s%s %s(%s)' % ( 459 dart_declaration = '%s%s %s(%s)' % (
481 'static ' if operation.is_static else '', 460 'static ' if operation.is_static else '',
482 self.SecureOutputType(operation.type.id), 461 self.SecureOutputType(operation.type.id),
483 overload_name, argument_list) 462 overload_name, argument_list)
484 cpp_callback_name = self._GenerateNativeBinding( 463 cpp_callback_name = self._GenerateNativeBinding(
485 overload_name, (0 if operation.is_static else 1) + argument_count, 464 overload_name, (0 if operation.is_static else 1) + argument_count,
486 dart_declaration, 'Callback', False) 465 dart_declaration, 'Callback', False)
487 self._GenerateOperationNativeCallback(operation, operation.arguments[:argu ment_count], cpp_callback_name) 466 self._GenerateOperationNativeCallback(operation, operation.arguments[:argu ment_count], cpp_callback_name)
488 467
489 self._GenerateDispatcherBody( 468 self._GenerateDispatcherBody(
490 body,
491 operations, 469 operations,
492 parameter_names, 470 parameter_names,
471 dart_declaration,
493 GenerateCall, 472 GenerateCall,
494 self._IsArgumentOptionalInWebCore) 473 self._IsArgumentOptionalInWebCore)
495 474
496 def SecondaryContext(self, interface): 475 def SecondaryContext(self, interface):
497 pass 476 pass
498 477
499 def _GenerateOperationNativeCallback(self, operation, arguments, cpp_callback_ name): 478 def _GenerateOperationNativeCallback(self, operation, arguments, cpp_callback_ name):
500 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i d) 479 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i d)
501 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, operation) 480 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, operation)
502 self._GenerateNativeCallback( 481 self._GenerateNativeCallback(
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 LIBRARY_NAME=library_name) 847 LIBRARY_NAME=library_name)
869 848
870 headers = self._library_headers[library_name] 849 headers = self._library_headers[library_name]
871 for header_file in headers: 850 for header_file in headers:
872 path = os.path.relpath(header_file, output_dir) 851 path = os.path.relpath(header_file, output_dir)
873 includes_emitter.Emit('#include "$PATH"\n', PATH=path) 852 includes_emitter.Emit('#include "$PATH"\n', PATH=path)
874 body_emitter.Emit( 853 body_emitter.Emit(
875 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu mentCount))\n' 854 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu mentCount))\n'
876 ' return func;\n', 855 ' return func;\n',
877 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) 856 CLASS_NAME=os.path.splitext(os.path.basename(path))[0])
OLDNEW
« tools/dom/scripts/htmldartgenerator.py ('K') | « tools/dom/scripts/systemhtml.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698