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

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

Issue 11720002: Next step in overload dispatcher refactoring. (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
« no previous file with comments | « tools/dom/scripts/systemhtml.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 481
482 dart_declaration = '%s%s _%s(%s)' % ( 482 dart_declaration = '%s%s _%s(%s)' % (
483 'static ' if operation.is_static else '', 483 'static ' if operation.is_static else '',
484 self.SecureOutputType(operation.type.id), 484 self.SecureOutputType(operation.type.id),
485 overload_name, argument_list) 485 overload_name, argument_list)
486 cpp_callback_name = self._GenerateNativeBinding( 486 cpp_callback_name = self._GenerateNativeBinding(
487 overload_name, (0 if operation.is_static else 1) + argument_count, 487 overload_name, (0 if operation.is_static else 1) + argument_count,
488 dart_declaration, 'Callback', False) 488 dart_declaration, 'Callback', False)
489 self._GenerateOperationNativeCallback(operation, operation.arguments[:argu ment_count], cpp_callback_name) 489 self._GenerateOperationNativeCallback(operation, operation.arguments[:argu ment_count], cpp_callback_name)
490 490
491 def GenerateChecksAndCall(operation, argument_count): 491 self._GenerateDispatcherBody(
492 GenerateCall(operation, argument_count, 492 body,
493 self._OverloadChecks(operation, parameter_names, argument_count)) 493 operations,
494 494 parameter_names,
495 # TODO: Optimize the dispatch to avoid repeated checks. 495 GenerateCall,
496 if len(operations) > 1: 496 self._IsArgumentOptionalInWebCore)
497 for operation in operations:
498 for position, argument in enumerate(operation.arguments):
499 if self._IsArgumentOptionalInWebCore(operation, argument):
500 GenerateChecksAndCall(operation, position)
501 GenerateChecksAndCall(operation, len(operation.arguments))
502 body.Emit(' throw "Incorrect number or type of arguments";\n');
503 else:
504 operation = operations[0]
505 argument_count = len(operation.arguments)
506 for position, argument in list(enumerate(operation.arguments))[::-1]:
507 if self._IsArgumentOptionalInWebCore(operation, argument):
508 check = '?%s' % parameter_names[position]
509 # argument_count instead of position + 1 is used here to cover one
510 # complicated case with the effectively optional argument in the middl e.
511 # Consider foo(x, [Optional] y, [Optional=DefaultIsNullString] z)
512 # (as of now it's modelled after HTMLMediaElement.webkitAddKey).
513 # y is optional in WebCore, while z is not.
514 # In this case, if y was actually passed, we'd like to emit foo(x, y, z) invocation,
515 # not foo(x, y).
516 GenerateCall(operation, argument_count, [check])
517 argument_count = position
518 GenerateCall(operation, argument_count, [])
519 497
520 def SecondaryContext(self, interface): 498 def SecondaryContext(self, interface):
521 pass 499 pass
522 500
523 def _GenerateOperationNativeCallback(self, operation, arguments, cpp_callback_ name): 501 def _GenerateOperationNativeCallback(self, operation, arguments, cpp_callback_ name):
524 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i d) 502 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i d)
525 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, operation) 503 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, operation)
526 self._GenerateNativeCallback( 504 self._GenerateNativeCallback(
527 cpp_callback_name, 505 cpp_callback_name,
528 not operation.is_static, 506 not operation.is_static,
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 LIBRARY_NAME=library_name) 885 LIBRARY_NAME=library_name)
908 886
909 headers = self._library_headers[library_name] 887 headers = self._library_headers[library_name]
910 for header_file in headers: 888 for header_file in headers:
911 path = os.path.relpath(header_file, output_dir) 889 path = os.path.relpath(header_file, output_dir)
912 includes_emitter.Emit('#include "$PATH"\n', PATH=path) 890 includes_emitter.Emit('#include "$PATH"\n', PATH=path)
913 body_emitter.Emit( 891 body_emitter.Emit(
914 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu mentCount))\n' 892 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu mentCount))\n'
915 ' return func;\n', 893 ' return func;\n',
916 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) 894 CLASS_NAME=os.path.splitext(os.path.basename(path))[0])
OLDNEW
« no previous file with comments | « tools/dom/scripts/systemhtml.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698