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

Side by Side Diff: lib/html/scripts/systemnative.py

Issue 11338033: Do not emit is dynamic/Object checks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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 | « lib/html/dartium/html_dartium.dart ('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 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 466
467 body = self._members_emitter.Emit( 467 body = self._members_emitter.Emit(
468 '\n' 468 '\n'
469 ' $DECLARATION {\n' 469 ' $DECLARATION {\n'
470 '$!BODY' 470 '$!BODY'
471 ' }\n', 471 ' }\n',
472 DECLARATION=dart_declaration) 472 DECLARATION=dart_declaration)
473 473
474 version = [1] 474 version = [1]
475 def GenerateCall(operation, argument_count, checks): 475 def GenerateCall(operation, argument_count, checks):
476 checks = filter(lambda e: e != 'true', checks)
podivilov 2012/10/30 13:28:00 This looks sketchy. Please don't add those checks
Anton Muhin 2012/10/30 13:29:35 a) that's the easier for the current solution when
podivilov 2012/10/30 13:32:58 If I remember correctly, dart2js code was copy-pas
476 if checks: 477 if checks:
477 if operation.type.id != 'void': 478 if operation.type.id != 'void':
478 template = ' if ($CHECKS) {\n return $CALL;\n }\n' 479 template = ' if ($CHECKS) {\n return $CALL;\n }\n'
479 else: 480 else:
480 template = ' if ($CHECKS) {\n $CALL;\n return;\n }\n' 481 template = ' if ($CHECKS) {\n $CALL;\n return;\n }\n'
481 else: 482 else:
482 if operation.type.id != 'void': 483 if operation.type.id != 'void':
483 template = ' return $CALL;\n' 484 template = ' return $CALL;\n'
484 else: 485 else:
485 template = ' $CALL;\n' 486 template = ' $CALL;\n'
(...skipping 10 matching lines...) Expand all
496 cpp_callback_name = self._GenerateNativeBinding( 497 cpp_callback_name = self._GenerateNativeBinding(
497 overload_name, (0 if operation.is_static else 1) + argument_count, 498 overload_name, (0 if operation.is_static else 1) + argument_count,
498 dart_declaration, 'Callback', False) 499 dart_declaration, 'Callback', False)
499 self._GenerateOperationNativeCallback(operation, operation.arguments[:argu ment_count], cpp_callback_name) 500 self._GenerateOperationNativeCallback(operation, operation.arguments[:argu ment_count], cpp_callback_name)
500 501
501 def GenerateChecksAndCall(operation, argument_count): 502 def GenerateChecksAndCall(operation, argument_count):
502 checks = ['!?%s' % name for name in argument_names] 503 checks = ['!?%s' % name for name in argument_names]
503 for i in range(0, argument_count): 504 for i in range(0, argument_count):
504 argument = operation.arguments[i] 505 argument = operation.arguments[i]
505 argument_name = argument_names[i] 506 argument_name = argument_names[i]
506 checks[i] = '(%s is %s || %s == null)' % ( 507 type = self._DartType(argument.type.id)
507 argument_name, self._DartType(argument.type.id), argument_name) 508 if type not in ['dynamic', 'Object']:
509 checks[i] = '(%s is %s || %s == null)' % (argument_name, type, argumen t_name)
510 else:
511 checks[i] = 'true'
508 GenerateCall(operation, argument_count, checks) 512 GenerateCall(operation, argument_count, checks)
509 513
510 # TODO: Optimize the dispatch to avoid repeated checks. 514 # TODO: Optimize the dispatch to avoid repeated checks.
511 if len(operations) > 1: 515 if len(operations) > 1:
512 for operation in operations: 516 for operation in operations:
513 for position, argument in enumerate(operation.arguments): 517 for position, argument in enumerate(operation.arguments):
514 if self._IsArgumentOptionalInWebCore(operation, argument): 518 if self._IsArgumentOptionalInWebCore(operation, argument):
515 GenerateChecksAndCall(operation, position) 519 GenerateChecksAndCall(operation, position)
516 GenerateChecksAndCall(operation, len(operation.arguments)) 520 GenerateChecksAndCall(operation, len(operation.arguments))
517 body.Emit(' throw "Incorrect number or type of arguments";\n'); 521 body.Emit(' throw "Incorrect number or type of arguments";\n');
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 def EmitResolver(self, template, output_dir): 860 def EmitResolver(self, template, output_dir):
857 file_path = os.path.join(output_dir, 'DartResolver.cpp') 861 file_path = os.path.join(output_dir, 'DartResolver.cpp')
858 includes_emitter, body_emitter = self._emitters.FileEmitter(file_path).Emit( template) 862 includes_emitter, body_emitter = self._emitters.FileEmitter(file_path).Emit( template)
859 for header_file in self._headers_list: 863 for header_file in self._headers_list:
860 path = os.path.relpath(header_file, output_dir) 864 path = os.path.relpath(header_file, output_dir)
861 includes_emitter.Emit('#include "$PATH"\n', PATH=path) 865 includes_emitter.Emit('#include "$PATH"\n', PATH=path)
862 body_emitter.Emit( 866 body_emitter.Emit(
863 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argume ntCount))\n' 867 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argume ntCount))\n'
864 ' return func;\n', 868 ' return func;\n',
865 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) 869 CLASS_NAME=os.path.splitext(os.path.basename(path))[0])
OLDNEW
« no previous file with comments | « lib/html/dartium/html_dartium.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698