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

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

Issue 14976004: Remove more question marks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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 | « sdk/lib/web_gl/dartium/web_gl_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 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 call_emitter = call_emitter.Emit('$(INDENT)$!CALL;\n$(INDENT)return;\n') 232 call_emitter = call_emitter.Emit('$(INDENT)$!CALL;\n$(INDENT)return;\n')
233 else: 233 else:
234 call_emitter = call_emitter.Emit('$(INDENT)return $!CALL;\n') 234 call_emitter = call_emitter.Emit('$(INDENT)return $!CALL;\n')
235 235
236 version[0] += 1 236 version[0] += 1
237 generate_call(stmts_emitter, call_emitter, 237 generate_call(stmts_emitter, call_emitter,
238 version[0], signature_index, argument_count) 238 version[0], signature_index, argument_count)
239 239
240 def GenerateChecksAndCall(signature_index, argument_count): 240 def GenerateChecksAndCall(signature_index, argument_count):
241 checks = [] 241 checks = []
242 for i in range(0, argument_count): 242 for i in reversed(range(0, argument_count)):
243 argument = signatures[signature_index][i] 243 argument = signatures[signature_index][i]
244 parameter_name = parameter_names[i] 244 parameter_name = parameter_names[i]
245 test_type = self._DartType(argument.type.id) 245 test_type = self._DartType(argument.type.id)
246 246
247 if test_type in ['dynamic', 'Object']: 247 if test_type in ['dynamic', 'Object']:
248 checks.append('?%s' % parameter_name) 248 checks.append('%s != null' % parameter_name)
249 elif not can_omit_type_check(test_type, i): 249 elif not can_omit_type_check(test_type, i):
250 checks.append('(%s is %s || %s == null)' % ( 250 checks.append('(%s is %s || %s == null)' % (
251 parameter_name, test_type, parameter_name)) 251 parameter_name, test_type, parameter_name))
252 elif i >= number_of_required_in_dart: 252 elif i >= number_of_required_in_dart:
253 checks.append('?%s' % parameter_name) 253 checks.append('%s != null' % parameter_name)
254 254
255 # There can be multiple presence checks. We need them all since a later 255 # There can be multiple presence checks. We need them all since a later
256 # optional argument could have been passed by name, leaving 'holes'. 256 # optional argument could have been passed by name, leaving 'holes'.
257 checks.extend(['!?%s' % name for name in parameter_names[argument_count:]] ) 257 checks.extend(['%s == null' % name for name in parameter_names[argument_co unt:]])
258 258
259 GenerateCall(signature_index, argument_count, checks) 259 GenerateCall(signature_index, argument_count, checks)
260 260
261 # TODO: Optimize the dispatch to avoid repeated checks. 261 # TODO: Optimize the dispatch to avoid repeated checks.
262 if len(signatures) > 1: 262 if len(signatures) > 1:
263 index_swaps = {} 263 index_swaps = {}
264 for signature_index, signature in enumerate(signatures): 264 for signature_index, signature in enumerate(signatures):
265 for argument_position, argument in enumerate(signature): 265 for argument_position, argument in enumerate(signature):
266 if argument.type.id != 'ArrayBuffer': 266 if argument.type.id != 'ArrayBuffer':
267 continue 267 continue
(...skipping 17 matching lines...) Expand all
285 GenerateChecksAndCall(signature_index, argument_position) 285 GenerateChecksAndCall(signature_index, argument_position)
286 GenerateChecksAndCall(signature_index, len(signature)) 286 GenerateChecksAndCall(signature_index, len(signature))
287 body_emitter.Emit( 287 body_emitter.Emit(
288 ' throw new ArgumentError("Incorrect number or type of arguments"); ' 288 ' throw new ArgumentError("Incorrect number or type of arguments"); '
289 '\n'); 289 '\n');
290 else: 290 else:
291 signature = signatures[0] 291 signature = signatures[0]
292 argument_count = len(signature) 292 argument_count = len(signature)
293 for argument_position, argument in list(enumerate(signature))[::-1]: 293 for argument_position, argument in list(enumerate(signature))[::-1]:
294 if is_optional(0, argument): 294 if is_optional(0, argument):
295 check = '?%s' % parameter_names[argument_position] 295 check = '%s != null' % parameter_names[argument_position]
296 # argument_count instead of argument_position + 1 is used here to cove r one 296 # argument_count instead of argument_position + 1 is used here to cove r one
297 # complicated case with the effectively optional argument in the middl e. 297 # complicated case with the effectively optional argument in the middl e.
298 # Consider foo(x, optional y, [Default=NullString] optional z) 298 # Consider foo(x, optional y, [Default=NullString] optional z)
299 # (as of now it's modelled after HTMLMediaElement.webkitAddKey). 299 # (as of now it's modelled after HTMLMediaElement.webkitAddKey).
300 # y is optional in WebCore, while z is not. 300 # y is optional in WebCore, while z is not.
301 # In this case, if y was actually passed, we'd like to emit foo(x, y, z) invocation, 301 # In this case, if y was actually passed, we'd like to emit foo(x, y, z) invocation,
302 # not foo(x, y). 302 # not foo(x, y).
303 GenerateCall(0, argument_count, [check]) 303 GenerateCall(0, argument_count, [check])
304 argument_count = argument_position 304 argument_count = argument_position
305 GenerateCall(0, argument_count, []) 305 GenerateCall(0, argument_count, [])
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 constructor_info, factory_name, factory_constructor_name): 368 constructor_info, factory_name, factory_constructor_name):
369 if self.GenerateCustomFactory(constructor_info): 369 if self.GenerateCustomFactory(constructor_info):
370 return 370 return
371 371
372 metadata = self._metadata.GetFormattedMetadata( 372 metadata = self._metadata.GetFormattedMetadata(
373 self._library_name, self._interface, self._interface.id, ' ') 373 self._library_name, self._interface, self._interface.id, ' ')
374 374
375 if not factory_constructor_name: 375 if not factory_constructor_name:
376 factory_constructor_name = '_create' 376 factory_constructor_name = '_create'
377 factory_parameters = constructor_info.ParametersAsArgumentList() 377 factory_parameters = constructor_info.ParametersAsArgumentList()
378 has_factory_provider = True
379 else: 378 else:
380 factory_parameters = ', '.join(constructor_info.factory_parameters) 379 factory_parameters = ', '.join(constructor_info.factory_parameters)
381 has_factory_provider = False
382 380
383 if constructor_info.pure_dart_constructor: 381 if constructor_info.pure_dart_constructor:
384 # TODO(antonm): use common dispatcher generation for this case as well. 382 # TODO(antonm): use common dispatcher generation for this case as well.
385 has_optional = any(param_info.is_optional 383 has_optional = any(param_info.is_optional
386 for param_info in constructor_info.param_infos) 384 for param_info in constructor_info.param_infos)
387 385
388 if not has_optional: 386 if not has_optional:
389 self._members_emitter.Emit( 387 self._members_emitter.Emit(
390 '\n $(METADATA)' 388 '\n $(METADATA)'
391 'factory $CTOR($PARAMS) => ' 389 'factory $CTOR($PARAMS) => '
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 if interface.parents: 585 if interface.parents:
588 parent = interface.parents[0] 586 parent = interface.parents[0]
589 if IsPureInterface(parent.type.id): 587 if IsPureInterface(parent.type.id):
590 walk(interface.parents) 588 walk(interface.parents)
591 else: 589 else:
592 walk(interface.parents[1:]) 590 walk(interface.parents[1:])
593 return result 591 return result
594 592
595 def _DartType(self, type_name): 593 def _DartType(self, type_name):
596 return self._type_registry.DartType(type_name) 594 return self._type_registry.DartType(type_name)
OLDNEW
« no previous file with comments | « sdk/lib/web_gl/dartium/web_gl_dartium.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698