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

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

Issue 11342046: Do not pass tautology predicates into check list. (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/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 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)
477 if checks: 476 if checks:
478 if operation.type.id != 'void': 477 if operation.type.id != 'void':
479 template = ' if ($CHECKS) {\n return $CALL;\n }\n' 478 template = ' if ($CHECKS) {\n return $CALL;\n }\n'
480 else: 479 else:
481 template = ' if ($CHECKS) {\n $CALL;\n return;\n }\n' 480 template = ' if ($CHECKS) {\n $CALL;\n return;\n }\n'
482 else: 481 else:
483 if operation.type.id != 'void': 482 if operation.type.id != 'void':
484 template = ' return $CALL;\n' 483 template = ' return $CALL;\n'
485 else: 484 else:
486 template = ' $CALL;\n' 485 template = ' $CALL;\n'
487 486
488 overload_name = '%s_%s' % (operation.id, version[0]) 487 overload_name = '%s_%s' % (operation.id, version[0])
489 version[0] += 1 488 version[0] += 1
490 argument_list = ', '.join(argument_names[:argument_count]) 489 argument_list = ', '.join(argument_names[:argument_count])
491 call = '_%s(%s)' % (overload_name, argument_list) 490 call = '_%s(%s)' % (overload_name, argument_list)
492 body.Emit(template, CHECKS=' && '.join(checks), CALL=call) 491 body.Emit(template, CHECKS=' && '.join(checks), CALL=call)
493 492
494 dart_declaration = '%s%s _%s(%s)' % ( 493 dart_declaration = '%s%s _%s(%s)' % (
495 'static ' if operation.is_static else '', 494 'static ' if operation.is_static else '',
496 SecureOutputType(self, operation.type.id), overload_name, argument_lis t) 495 SecureOutputType(self, operation.type.id), overload_name, argument_lis t)
497 cpp_callback_name = self._GenerateNativeBinding( 496 cpp_callback_name = self._GenerateNativeBinding(
498 overload_name, (0 if operation.is_static else 1) + argument_count, 497 overload_name, (0 if operation.is_static else 1) + argument_count,
499 dart_declaration, 'Callback', False) 498 dart_declaration, 'Callback', False)
500 self._GenerateOperationNativeCallback(operation, operation.arguments[:argu ment_count], cpp_callback_name) 499 self._GenerateOperationNativeCallback(operation, operation.arguments[:argu ment_count], cpp_callback_name)
501 500
502 def GenerateChecksAndCall(operation, argument_count): 501 def GenerateChecksAndCall(operation, argument_count):
503 checks = ['!?%s' % name for name in argument_names] 502 checks = []
504 for i in range(0, argument_count): 503 for i in range(0, argument_count):
505 argument = operation.arguments[i] 504 argument = operation.arguments[i]
506 argument_name = argument_names[i] 505 argument_name = argument_names[i]
507 type = self._DartType(argument.type.id) 506 type = self._DartType(argument.type.id)
508 if type not in ['dynamic', 'Object']: 507 if type not in ['dynamic', 'Object']:
509 checks[i] = '(%s is %s || %s == null)' % (argument_name, type, argumen t_name) 508 checks.append('(%s is %s || %s == null)' % (argument_name, type, argum ent_name))
510 else: 509 checks.extend(['!?%s' % name for name in argument_names[argument_count:]])
511 checks[i] = 'true'
512 GenerateCall(operation, argument_count, checks) 510 GenerateCall(operation, argument_count, checks)
513 511
514 # TODO: Optimize the dispatch to avoid repeated checks. 512 # TODO: Optimize the dispatch to avoid repeated checks.
515 if len(operations) > 1: 513 if len(operations) > 1:
516 for operation in operations: 514 for operation in operations:
517 for position, argument in enumerate(operation.arguments): 515 for position, argument in enumerate(operation.arguments):
518 if self._IsArgumentOptionalInWebCore(operation, argument): 516 if self._IsArgumentOptionalInWebCore(operation, argument):
519 GenerateChecksAndCall(operation, position) 517 GenerateChecksAndCall(operation, position)
520 GenerateChecksAndCall(operation, len(operation.arguments)) 518 GenerateChecksAndCall(operation, len(operation.arguments))
521 body.Emit(' throw "Incorrect number or type of arguments";\n'); 519 body.Emit(' throw "Incorrect number or type of arguments";\n');
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 def EmitResolver(self, template, output_dir): 858 def EmitResolver(self, template, output_dir):
861 file_path = os.path.join(output_dir, 'DartResolver.cpp') 859 file_path = os.path.join(output_dir, 'DartResolver.cpp')
862 includes_emitter, body_emitter = self._emitters.FileEmitter(file_path).Emit( template) 860 includes_emitter, body_emitter = self._emitters.FileEmitter(file_path).Emit( template)
863 for header_file in self._headers_list: 861 for header_file in self._headers_list:
864 path = os.path.relpath(header_file, output_dir) 862 path = os.path.relpath(header_file, output_dir)
865 includes_emitter.Emit('#include "$PATH"\n', PATH=path) 863 includes_emitter.Emit('#include "$PATH"\n', PATH=path)
866 body_emitter.Emit( 864 body_emitter.Emit(
867 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argume ntCount))\n' 865 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argume ntCount))\n'
868 ' return func;\n', 866 ' return func;\n',
869 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) 867 CLASS_NAME=os.path.splitext(os.path.basename(path))[0])
OLDNEW
« no previous file with comments | « lib/html/scripts/systemhtml.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698