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

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

Issue 15885002: Verify that correct number of arguments was passed. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 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/systemhtml.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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 if declare_only: 194 if declare_only:
195 self.DeclareOperation(info, 195 self.DeclareOperation(info,
196 self.SecureOutputType(info.type_name), method_name) 196 self.SecureOutputType(info.type_name), method_name)
197 else: 197 else:
198 self.EmitOperation(info, method_name) 198 self.EmitOperation(info, method_name)
199 199
200 def _GenerateOverloadDispatcher(self, 200 def _GenerateOverloadDispatcher(self,
201 signatures, 201 signatures,
202 is_void, 202 is_void,
203 parameter_names, 203 parameter_names,
204 number_of_required_in_dart,
204 declaration, 205 declaration,
205 generate_call, 206 generate_call,
206 is_optional, 207 is_optional,
207 can_omit_type_check=lambda type, pos: False): 208 can_omit_type_check=lambda type, pos: False):
208 209
209 body_emitter = self._members_emitter.Emit( 210 body_emitter = self._members_emitter.Emit(
210 '\n' 211 '\n'
211 ' $DECLARATION {\n' 212 ' $DECLARATION {\n'
212 '$!BODY' 213 '$!BODY'
213 ' }\n', 214 ' }\n',
(...skipping 24 matching lines...) Expand all
238 checks = [] 239 checks = []
239 for i in range(0, argument_count): 240 for i in range(0, argument_count):
240 argument = signatures[signature_index][i] 241 argument = signatures[signature_index][i]
241 parameter_name = parameter_names[i] 242 parameter_name = parameter_names[i]
242 test_type = self._DartType(argument.type.id) 243 test_type = self._DartType(argument.type.id)
243 if test_type in ['dynamic', 'Object']: 244 if test_type in ['dynamic', 'Object']:
244 checks.append('?%s' % parameter_name) 245 checks.append('?%s' % parameter_name)
245 elif not can_omit_type_check(test_type, i): 246 elif not can_omit_type_check(test_type, i):
246 checks.append('(%s is %s || %s == null)' % ( 247 checks.append('(%s is %s || %s == null)' % (
247 parameter_name, test_type, parameter_name)) 248 parameter_name, test_type, parameter_name))
249 elif i > number_of_required_in_dart:
250 checks.append('?%s' % parameter_name)
251
248 # There can be multiple presence checks. We need them all since a later 252 # There can be multiple presence checks. We need them all since a later
249 # optional argument could have been passed by name, leaving 'holes'. 253 # optional argument could have been passed by name, leaving 'holes'.
250 checks.extend(['!?%s' % name for name in parameter_names[argument_count:]] ) 254 checks.extend(['!?%s' % name for name in parameter_names[argument_count:]] )
251 255
252 GenerateCall(signature_index, argument_count, checks) 256 GenerateCall(signature_index, argument_count, checks)
253 257
254 # TODO: Optimize the dispatch to avoid repeated checks. 258 # TODO: Optimize the dispatch to avoid repeated checks.
255 if len(signatures) > 1: 259 if len(signatures) > 1:
256 index_swaps = {} 260 index_swaps = {}
257 for signature_index, signature in enumerate(signatures): 261 for signature_index, signature in enumerate(signatures):
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 # y is optional in WebCore, while z is not. 297 # y is optional in WebCore, while z is not.
294 # In this case, if y was actually passed, we'd like to emit foo(x, y, z) invocation, 298 # In this case, if y was actually passed, we'd like to emit foo(x, y, z) invocation,
295 # not foo(x, y). 299 # not foo(x, y).
296 GenerateCall(0, argument_count, [check]) 300 GenerateCall(0, argument_count, [check])
297 argument_count = argument_position 301 argument_count = argument_position
298 GenerateCall(0, argument_count, []) 302 GenerateCall(0, argument_count, [])
299 303
300 def _GenerateDispatcherBody(self, 304 def _GenerateDispatcherBody(self,
301 operations, 305 operations,
302 parameter_names, 306 parameter_names,
307 number_of_required_in_dart,
303 declaration, 308 declaration,
304 generate_call, 309 generate_call,
305 is_optional, 310 is_optional,
306 can_omit_type_check=lambda type, pos: False): 311 can_omit_type_check=lambda type, pos: False):
307 312
308 def GenerateCall( 313 def GenerateCall(
309 stmts_emitter, call_emitter, version, signature_index, argument_count): 314 stmts_emitter, call_emitter, version, signature_index, argument_count):
310 generate_call( 315 generate_call(
311 stmts_emitter, call_emitter, 316 stmts_emitter, call_emitter,
312 version, operations[signature_index], argument_count) 317 version, operations[signature_index], argument_count)
313 318
314 def IsOptional(signature_index, argument): 319 def IsOptional(signature_index, argument):
315 return is_optional(operations[signature_index], argument) 320 return is_optional(operations[signature_index], argument)
316 321
317 self._GenerateOverloadDispatcher( 322 self._GenerateOverloadDispatcher(
318 [operation.arguments for operation in operations], 323 [operation.arguments for operation in operations],
319 operations[0].type.id == 'void', 324 operations[0].type.id == 'void',
320 parameter_names, 325 parameter_names,
326 number_of_required_in_dart,
321 declaration, 327 declaration,
322 GenerateCall, 328 GenerateCall,
323 IsOptional, 329 IsOptional,
324 can_omit_type_check) 330 can_omit_type_check)
325 331
326 def AdditionalImplementedInterfaces(self): 332 def AdditionalImplementedInterfaces(self):
327 # TODO: Include all implemented interfaces, including other Lists. 333 # TODO: Include all implemented interfaces, including other Lists.
328 implements = [] 334 implements = []
329 if self._interface_type_info.list_item_type(): 335 if self._interface_type_info.list_item_type():
330 item_type_info = self._type_registry.TypeInfo( 336 item_type_info = self._type_registry.TypeInfo(
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 def IsOptional(signature_index, argument): 430 def IsOptional(signature_index, argument):
425 return self.IsConstructorArgumentOptional(argument) 431 return self.IsConstructorArgumentOptional(argument)
426 432
427 custom_factory_ctr = self._interface.id in _custom_factories 433 custom_factory_ctr = self._interface.id in _custom_factories
428 constructor_full_name = constructor_info._ConstructorFullName( 434 constructor_full_name = constructor_info._ConstructorFullName(
429 self._DartType) 435 self._DartType)
430 self._GenerateOverloadDispatcher( 436 self._GenerateOverloadDispatcher(
431 constructor_info.idl_args, 437 constructor_info.idl_args,
432 False, 438 False,
433 [info.name for info in constructor_info.param_infos], 439 [info.name for info in constructor_info.param_infos],
440 constructor_info.NumberOfRequiredInDart(),
434 emitter.Format('$(METADATA)$FACTORY_KEYWORD $CTOR($PARAMS)', 441 emitter.Format('$(METADATA)$FACTORY_KEYWORD $CTOR($PARAMS)',
435 FACTORY_KEYWORD=('factory' if not custom_factory_ctr else 442 FACTORY_KEYWORD=('factory' if not custom_factory_ctr else
436 'static %s' % constructor_full_name), 443 'static %s' % constructor_full_name),
437 CTOR=(('' if not custom_factory_ctr else '_factory') 444 CTOR=(('' if not custom_factory_ctr else '_factory')
438 + constructor_full_name), 445 + constructor_full_name),
439 METADATA=metadata, 446 METADATA=metadata,
440 PARAMS=constructor_info.ParametersDeclaration(self._DartType)), 447 PARAMS=constructor_info.ParametersDeclaration(self._DartType)),
441 GenerateCall, 448 GenerateCall,
442 IsOptional) 449 IsOptional)
443 450
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 if interface.parents: 587 if interface.parents:
581 parent = interface.parents[0] 588 parent = interface.parents[0]
582 if IsPureInterface(parent.type.id): 589 if IsPureInterface(parent.type.id):
583 walk(interface.parents) 590 walk(interface.parents)
584 else: 591 else:
585 walk(interface.parents[1:]) 592 walk(interface.parents[1:])
586 return result 593 return result
587 594
588 def _DartType(self, type_name): 595 def _DartType(self, type_name):
589 return self._type_registry.DartType(type_name) 596 return self._type_registry.DartType(type_name)
OLDNEW
« no previous file with comments | « tools/dom/scripts/generator.py ('k') | tools/dom/scripts/systemhtml.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698