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: tools/dom/scripts/htmldartgenerator.py

Issue 569783002: Migrate to Chrome 37 IDL (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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/generator.py ('k') | tools/dom/scripts/htmlrenamer.py » ('j') | 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 system to generate 6 """This module provides shared functionality for the system to generate
7 dart:html APIs from the IDL database.""" 7 dart:html APIs from the IDL database."""
8 8
9 import emitter 9 import emitter
10 from generator import AnalyzeOperation, ConstantOutputOrder, \ 10 from generator import AnalyzeOperation, ConstantOutputOrder, \
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 call_emitter = call_emitter.Emit('$(INDENT)$!CALL;\n$(INDENT)return;\n') 347 call_emitter = call_emitter.Emit('$(INDENT)$!CALL;\n$(INDENT)return;\n')
348 else: 348 else:
349 call_emitter = call_emitter.Emit('$(INDENT)return $!CALL;\n') 349 call_emitter = call_emitter.Emit('$(INDENT)return $!CALL;\n')
350 350
351 version[0] += 1 351 version[0] += 1
352 generate_call(stmts_emitter, call_emitter, 352 generate_call(stmts_emitter, call_emitter,
353 version[0], signature_index, argument_count) 353 version[0], signature_index, argument_count)
354 354
355 def GenerateChecksAndCall(signature_index, argument_count): 355 def GenerateChecksAndCall(signature_index, argument_count):
356 checks = [] 356 checks = []
357 typechecked_interface = \
358 ('TypeChecking' in self._interface.ext_attrs) and \
359 ('Interface' in self._interface.ext_attrs['TypeChecking'])
360
357 for i in reversed(range(0, argument_count)): 361 for i in reversed(range(0, argument_count)):
358 argument = signatures[signature_index][i] 362 argument = signatures[signature_index][i]
359 parameter_name = parameter_names[i] 363 parameter_name = parameter_names[i]
360 364
361 test_type = self._NarrowToImplementationType(argument.type.id) 365 test_type = self._NarrowToImplementationType(argument.type.id)
362 366
363 if test_type in ['dynamic', 'Object']: 367 if test_type in ['dynamic', 'Object']:
364 checks.append('%s != null' % parameter_name) 368 checks.append('%s != null' % parameter_name)
365 elif not can_omit_type_check(test_type, i): 369 elif not can_omit_type_check(test_type, i):
366 checks.append('(%s is %s || %s == null)' % ( 370 typechecked = typechecked_interface or \
367 parameter_name, test_type, parameter_name)) 371 ('TypeChecking' in argument.ext_attrs) and \
372 ('Interface' in argument.ext_attrs['TypeChecking'])
373 converts_null = \
374 ('TreatNullAs' in argument.ext_attrs) or \
375 (argument.default_value is not None) or \
376 (argument.default_value_is_null)
377 if argument.type.nullable or converts_null or not typechecked:
378 checks.append('(%s is %s || %s == null)' % (
379 parameter_name, test_type, parameter_name))
380 else:
381 checks.append('(%s is %s)' % (
382 parameter_name, test_type))
368 elif i >= number_of_required_in_dart: 383 elif i >= number_of_required_in_dart:
369 checks.append('%s != null' % parameter_name) 384 checks.append('%s != null' % parameter_name)
370 385
371 # There can be multiple presence checks. We need them all since a later 386 # There can be multiple presence checks. We need them all since a later
372 # optional argument could have been passed by name, leaving 'holes'. 387 # optional argument could have been passed by name, leaving 'holes'.
373 checks.extend(['%s == null' % name for name in parameter_names[argument_co unt:]]) 388 checks.extend(['%s == null' % name for name in parameter_names[argument_co unt:]])
374 389
375 GenerateCall(signature_index, argument_count, checks) 390 GenerateCall(signature_index, argument_count, checks)
376 391
377 # TODO: Optimize the dispatch to avoid repeated checks. 392 # TODO: Optimize the dispatch to avoid repeated checks.
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 return self._type_registry.TypeInfo(type_name).narrow_dart_type() 754 return self._type_registry.TypeInfo(type_name).narrow_dart_type()
740 755
741 def _NarrowInputType(self, type_name): 756 def _NarrowInputType(self, type_name):
742 return self._NarrowToImplementationType(type_name) 757 return self._NarrowToImplementationType(type_name)
743 758
744 def _DartType(self, type_name): 759 def _DartType(self, type_name):
745 return self._type_registry.DartType(type_name) 760 return self._type_registry.DartType(type_name)
746 761
747 def _TypeInfo(self, type_name): 762 def _TypeInfo(self, type_name):
748 return self._type_registry.TypeInfo(type_name) 763 return self._type_registry.TypeInfo(type_name)
OLDNEW
« no previous file with comments | « tools/dom/scripts/generator.py ('k') | tools/dom/scripts/htmlrenamer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698