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

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

Issue 10383302: Move dart:dom implementation classes to dart:html library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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
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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 def _FilePathForDartFactoryProviderImplementation(self, interface_name): 200 def _FilePathForDartFactoryProviderImplementation(self, interface_name):
201 return os.path.join(self._output_dir, 'dart', 201 return os.path.join(self._output_dir, 'dart',
202 '%sFactoryProviderImplementation.dart' % interface_name) 202 '%sFactoryProviderImplementation.dart' % interface_name)
203 203
204 def _FilePathForCppHeader(self, interface_name): 204 def _FilePathForCppHeader(self, interface_name):
205 return os.path.join(self._output_dir, 'cpp', 'Dart%s.h' % interface_name) 205 return os.path.join(self._output_dir, 'cpp', 'Dart%s.h' % interface_name)
206 206
207 def _FilePathForCppImplementation(self, interface_name): 207 def _FilePathForCppImplementation(self, interface_name):
208 return os.path.join(self._output_dir, 'cpp', 'Dart%s.cpp' % interface_name) 208 return os.path.join(self._output_dir, 'cpp', 'Dart%s.cpp' % interface_name)
209 209
210 def DartImplementationFiles(self):
211 return self._dom_impl_files
212
210 213
211 class NativeImplementationGenerator(object): 214 class NativeImplementationGenerator(object):
212 """Generates Dart implementation for one DOM IDL interface.""" 215 """Generates Dart implementation for one DOM IDL interface."""
213 216
214 def __init__(self, system, interface, 217 def __init__(self, system, interface,
215 dart_impl_emitter, cpp_header_emitter, cpp_impl_emitter, 218 dart_impl_emitter, cpp_header_emitter, cpp_impl_emitter,
216 base_members, templates): 219 base_members, templates):
217 """Generates Dart and C++ code for the given interface. 220 """Generates Dart and C++ code for the given interface.
218 221
219 Args: 222 Args:
(...skipping 12 matching lines...) Expand all
232 self._system = system 235 self._system = system
233 self._interface = interface 236 self._interface = interface
234 self._dart_impl_emitter = dart_impl_emitter 237 self._dart_impl_emitter = dart_impl_emitter
235 self._cpp_header_emitter = cpp_header_emitter 238 self._cpp_header_emitter = cpp_header_emitter
236 self._cpp_impl_emitter = cpp_impl_emitter 239 self._cpp_impl_emitter = cpp_impl_emitter
237 self._base_members = base_members 240 self._base_members = base_members
238 self._templates = templates 241 self._templates = templates
239 self._current_secondary_parent = None 242 self._current_secondary_parent = None
240 243
241 def StartInterface(self): 244 def StartInterface(self):
242 self._class_name = self._ImplClassName(self._interface.id)
243 self._interface_type_info = GetIDLTypeInfo(self._interface.id) 245 self._interface_type_info = GetIDLTypeInfo(self._interface.id)
244 self._members_emitter = emitter.Emitter() 246 self._members_emitter = emitter.Emitter()
245 self._cpp_declarations_emitter = emitter.Emitter() 247 self._cpp_declarations_emitter = emitter.Emitter()
246 self._cpp_impl_includes = set() 248 self._cpp_impl_includes = set()
247 self._cpp_definitions_emitter = emitter.Emitter() 249 self._cpp_definitions_emitter = emitter.Emitter()
248 self._cpp_resolver_emitter = emitter.Emitter() 250 self._cpp_resolver_emitter = emitter.Emitter()
249 251
250 self._GenerateConstructors() 252 self._GenerateConstructors()
251 self._GenerateEvents() 253 self._GenerateEvents()
252 254
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 self._interface.id, self._interface.ext_attrs, raises_dom_exceptions) 317 self._interface.id, self._interface.ext_attrs, raises_dom_exceptions)
316 self._GenerateNativeCallback(callback_name='constructorCallback', 318 self._GenerateNativeCallback(callback_name='constructorCallback',
317 parameter_definitions=parameter_definitions_emitter.Fragments(), 319 parameter_definitions=parameter_definitions_emitter.Fragments(),
318 needs_receiver=False, invocation=invocation, 320 needs_receiver=False, invocation=invocation,
319 raises_exceptions=raises_exceptions) 321 raises_exceptions=raises_exceptions)
320 322
321 def _GenerateEvents(self): 323 def _GenerateEvents(self):
322 if self._interface.id == 'DocumentFragment': 324 if self._interface.id == 'DocumentFragment':
323 # Interface DocumentFragment extends Element in dart:html but this fact 325 # Interface DocumentFragment extends Element in dart:html but this fact
324 # is not reflected in idls. 326 # is not reflected in idls.
325 self._EmitEventGetter('ElementEventsImplementation') 327 self._EmitEventGetter('_ElementEventsImpl')
326 return 328 return
327 329
328 events_attributes = [attr for attr in self._interface.attributes 330 events_attributes = [attr for attr in self._interface.attributes
329 if attr.type.id == 'EventListener'] 331 if attr.type.id == 'EventListener']
330 if not 'EventTarget' in self._interface.ext_attrs and not events_attributes: 332 if not 'EventTarget' in self._interface.ext_attrs and not events_attributes:
331 return 333 return
332 334
333 def IsEventTarget(interface): 335 def IsEventTarget(interface):
334 return ('EventTarget' in interface.ext_attrs and 336 return ('EventTarget' in interface.ext_attrs and
335 interface.id != 'EventTarget') 337 interface.id != 'EventTarget')
336 is_root = not _FindParent(self._interface, self._system._database, IsEventTa rget) 338 is_root = not _FindParent(self._interface, self._system._database, IsEventTa rget)
337 if is_root: 339 if is_root:
338 self._members_emitter.Emit(' EventsImplementation _on;\n') 340 self._members_emitter.Emit(' _EventsImpl _on;\n')
339 341
340 if not events_attributes: 342 if not events_attributes:
341 if is_root: 343 if is_root:
342 self._EmitEventGetter('EventsImplementation') 344 self._EmitEventGetter('_EventsImpl')
343 return 345 return
344 346
345 events_class = '%sEventsImplementation' % self._interface.id 347 events_class = '_%sEventsImpl' % self._interface.id
346 self._EmitEventGetter(events_class) 348 self._EmitEventGetter(events_class)
347 349
348 def HasEventAttributes(interface): 350 def HasEventAttributes(interface):
349 return any([a.type.id == 'EventListener' for a in interface.attributes]) 351 return any([a.type.id == 'EventListener' for a in interface.attributes])
350 parent = _FindParent(self._interface, self._system._database, HasEventAttrib utes) 352 parent = _FindParent(self._interface, self._system._database, HasEventAttrib utes)
351 if parent: 353 if parent:
352 parent_events_class = '%sEventsImplementation' % parent.id 354 parent_events_class = '_%sEventsImpl' % parent.id
353 else: 355 else:
354 parent_events_class = 'EventsImplementation' 356 parent_events_class = '_EventsImpl'
355 html_inteface = self._system._html_renames.get(self._interface.id, self._int erface.id) 357 html_inteface = self._system._html_renames.get(self._interface.id, self._int erface.id)
356 events_members = self._dart_impl_emitter.Emit( 358 events_members = self._dart_impl_emitter.Emit(
357 '\n' 359 '\n'
358 'class $EVENTS_CLASS extends $PARENT_EVENTS_CLASS implements $EVENTS_INT ERFACE {\n' 360 'class $EVENTS_CLASS extends $PARENT_EVENTS_CLASS implements $EVENTS_INT ERFACE {\n'
359 ' $EVENTS_CLASS(_ptr) : super(_ptr);\n' 361 ' $EVENTS_CLASS(_ptr) : super(_ptr);\n'
360 '$!MEMBERS\n' 362 '$!MEMBERS\n'
361 '}\n', 363 '}\n',
362 EVENTS_CLASS=events_class, 364 EVENTS_CLASS=events_class,
363 PARENT_EVENTS_CLASS=parent_events_class, 365 PARENT_EVENTS_CLASS=parent_events_class,
364 EVENTS_INTERFACE='html.%sEvents' % html_inteface) 366 EVENTS_INTERFACE='%sEvents' % html_inteface)
365 367
366 events_attributes = DomToHtmlEvents(self._interface.id, events_attributes) 368 events_attributes = DomToHtmlEvents(self._interface.id, events_attributes)
367 for event_name in events_attributes: 369 for event_name in events_attributes:
368 events_members.Emit( 370 events_members.Emit(
369 ' EventListenerList get $HTML_NAME() => this[\'$DOM_NAME\'];\n', 371 ' EventListenerList get $HTML_NAME() => this[\'$DOM_NAME\'];\n',
370 HTML_NAME=DomToHtmlEvent(event_name), 372 HTML_NAME=DomToHtmlEvent(event_name),
371 DOM_NAME=event_name) 373 DOM_NAME=event_name)
372 374
373 def _EmitEventGetter(self, events_class): 375 def _EmitEventGetter(self, events_class):
374 self._members_emitter.Emit( 376 self._members_emitter.Emit(
375 '\n' 377 '\n'
376 ' $EVENTS_CLASS get on() {\n' 378 ' $EVENTS_CLASS get on() {\n'
377 ' if (_on === null) _on = new $EVENTS_CLASS(this);\n' 379 ' if (_on === null) _on = new $EVENTS_CLASS(this);\n'
378 ' return _on;\n' 380 ' return _on;\n'
379 ' }\n', 381 ' }\n',
380 EVENTS_CLASS=events_class) 382 EVENTS_CLASS=events_class)
381 383
382 def _ImplClassName(self, interface_name): 384 def _ImplClassName(self, interface_name):
383 return interface_name + 'Implementation' 385 return '_%sDOMImpl' % interface_name
386
387 def _DartType(self, idl_type):
Anton Muhin 2012/05/23 14:03:31 shouldn't this logic belong to IDLTypeInfo?
podivilov 2012/05/23 14:52:40 This is temporary, only needed because dom wrapper
Anton Muhin 2012/05/23 15:25:23 Please, add a TODO w/ explanations On 2012/05/23
podivilov 2012/05/24 10:33:07 Done.
388 if idl_type in ['EventListener', 'TimeoutHandler']:
389 return idl_type
390 if idl_type in ['EventTarget', 'IDBAny', 'IDBKey']:
391 return 'Dynamic'
392 if idl_type == 'DOMStringList':
393 return 'List<String>'
394
395 type_info = GetIDLTypeInfo(idl_type)
396 if isinstance(type_info, PrimitiveIDLTypeInfo) or isinstance(type_info, Sequ enceIDLTypeInfo):
397 return type_info.dart_type()
398
399 if self._system._database.HasInterface(idl_type):
400 interface = self._system._database.GetInterface(idl_type)
401 if 'Callback' in interface.ext_attrs:
402 return idl_type
403 return '_%s' % idl_type
404 return idl_type
384 405
385 def _BaseClassName(self): 406 def _BaseClassName(self):
386 if not self._interface.parents: 407 if not self._interface.parents:
387 return 'DOMWrapperBase' 408 return '_DOMWrapperBase'
388 409
389 supertype = self._interface.parents[0].type.id 410 supertype = self._interface.parents[0].type.id
390 411
391 # FIXME: We're currently injecting List<..> and EventTarget as 412 # FIXME: We're currently injecting List<..> and EventTarget as
392 # supertypes in dart.idl. We should annotate/preserve as 413 # supertypes in dart.idl. We should annotate/preserve as
393 # attributes instead. For now, this hack lets the self._interfaces 414 # attributes instead. For now, this hack lets the self._interfaces
394 # inherit, but not the classes. 415 # inherit, but not the classes.
395 # List methods are injected in AddIndexer. 416 # List methods are injected in AddIndexer.
396 if IsDartListType(supertype) or IsDartCollectionType(supertype): 417 if IsDartListType(supertype) or IsDartCollectionType(supertype):
397 return 'DOMWrapperBase' 418 return '_DOMWrapperBase'
398 419
399 if supertype == 'EventTarget': 420 if supertype == 'EventTarget':
400 # Most implementors of EventTarget specify the EventListener operations 421 # Most implementors of EventTarget specify the EventListener operations
401 # again. If the operations are not specified, try to inherit from the 422 # again. If the operations are not specified, try to inherit from the
402 # EventTarget implementation. 423 # EventTarget implementation.
403 # 424 #
404 # Applies to MessagePort. 425 # Applies to MessagePort.
405 if not [op for op in self._interface.operations if op.id == 'addEventListe ner']: 426 if not [op for op in self._interface.operations if op.id == 'addEventListe ner']:
406 return self._ImplClassName(supertype) 427 return self._ImplClassName(supertype)
407 return 'DOMWrapperBase' 428 return '_DOMWrapperBase'
408 429
409 return self._ImplClassName(supertype) 430 return self._ImplClassName(supertype)
410 431
411 def _IsConstructable(self): 432 def _IsConstructable(self):
412 # FIXME: support ConstructorTemplate. 433 # FIXME: support ConstructorTemplate.
413 return set(['CustomConstructor', 'V8CustomConstructor', 'Constructor', 'Name dConstructor']) & set(self._interface.ext_attrs) 434 return set(['CustomConstructor', 'V8CustomConstructor', 'Constructor', 'Name dConstructor']) & set(self._interface.ext_attrs)
414 435
415 def _EmitFactoryProvider(self, interface_name, constructor_info): 436 def _EmitFactoryProvider(self, interface_name, constructor_info):
416 factory_provider = '_' + interface_name + 'FactoryProvider' 437 factory_provider = '_%sFactoryProvider' % interface_name
417 implementation_class = interface_name + 'FactoryProviderImplementation' 438 implementation_class = '_%sFactoryProviderImpl' % interface_name
418 implementation_function = 'create' + interface_name 439 implementation_function = 'create' + interface_name
419 native_implementation_function = '%s_constructor_Callback' % interface_name 440 native_implementation_function = '%s_constructor_Callback' % interface_name
420 441
421 # Emit private factory provider in public library. 442 # Emit private factory provider in public library.
422 template_file = 'factoryprovider_%s.darttemplate' % interface_name 443 template_file = 'factoryprovider_%s.darttemplate' % interface_name
423 template = self._system._templates.TryLoad(template_file) 444 template = self._system._templates.TryLoad(template_file)
424 if not template: 445 if not template:
425 template = self._system._templates.Load('factoryprovider.darttemplate') 446 template = self._system._templates.Load('factoryprovider.darttemplate')
426 447
427 dart_impl_path = self._system._FilePathForDartFactoryProvider( 448 dart_impl_path = self._system._FilePathForDartFactoryProvider(
428 interface_name) 449 interface_name)
429 self._system._dom_public_files.append(dart_impl_path) 450 self._system._dom_public_files.append(dart_impl_path)
430 451
452 parameters = constructor_info.ParametersImplementationDeclaration(lambda x: self._DartType(x))
Anton Muhin 2012/05/23 14:03:31 nit: no need in lambda, self._DartType should work
podivilov 2012/05/23 14:52:40 Done.
453
431 emitter = self._system._emitters.FileEmitter(dart_impl_path) 454 emitter = self._system._emitters.FileEmitter(dart_impl_path)
432 emitter.Emit( 455 emitter.Emit(
433 template, 456 template,
434 FACTORY_PROVIDER=factory_provider, 457 FACTORY_PROVIDER=factory_provider,
435 CONSTRUCTOR=interface_name, 458 CONSTRUCTOR=interface_name,
436 PARAMETERS=constructor_info.ParametersImplementationDeclaration(), 459 PARAMETERS=parameters,
437 IMPL_CLASS=implementation_class, 460 IMPL_CLASS=implementation_class,
438 IMPL_FUNCTION=implementation_function, 461 IMPL_FUNCTION=implementation_function,
439 ARGUMENTS=constructor_info.ParametersAsArgumentList()) 462 ARGUMENTS=constructor_info.ParametersAsArgumentList())
440 463
441 # Emit public implementation in implementation libary. 464 # Emit public implementation in implementation libary.
442 dart_impl_path = self._system._FilePathForDartFactoryProviderImplementation( 465 dart_impl_path = self._system._FilePathForDartFactoryProviderImplementation(
443 interface_name) 466 interface_name)
444 self._system._dom_impl_files.append(dart_impl_path) 467 self._system._dom_impl_files.append(dart_impl_path)
445 emitter = self._system._emitters.FileEmitter(dart_impl_path) 468 emitter = self._system._emitters.FileEmitter(dart_impl_path)
446 emitter.Emit( 469 emitter.Emit(
447 'class $IMPL_CLASS {\n' 470 'class $IMPL_CLASS {\n'
448 ' static $INTERFACE_NAME $IMPL_FUNCTION($PARAMETERS)\n' 471 ' static $TYPE $IMPL_FUNCTION($PARAMETERS)\n'
449 ' native "$NATIVE_NAME";\n' 472 ' native "$NATIVE_NAME";\n'
450 '}', 473 '}',
451 INTERFACE_NAME=interface_name, 474 PARAMETERS=parameters,
452 PARAMETERS=constructor_info.ParametersImplementationDeclaration(),
453 IMPL_CLASS=implementation_class, 475 IMPL_CLASS=implementation_class,
476 TYPE=self._ImplClassName(interface_name),
454 IMPL_FUNCTION=implementation_function, 477 IMPL_FUNCTION=implementation_function,
455 NATIVE_NAME=native_implementation_function) 478 NATIVE_NAME=native_implementation_function)
456 479
457 def FinishInterface(self): 480 def FinishInterface(self):
481 class_name = self._ImplClassName(self._interface.id)
458 base = self._BaseClassName() 482 base = self._BaseClassName()
459 self._dart_impl_emitter.Emit( 483 self._dart_impl_emitter.Emit(
460 self._templates.Load('dart_implementation.darttemplate'), 484 self._templates.Load('dart_implementation.darttemplate'),
461 CLASS=self._class_name, BASE=base, INTERFACE=self._interface.id, 485 CLASS=class_name, BASE=base, INTERFACE=self._interface.id,
462 MEMBERS=self._members_emitter.Fragments()) 486 MEMBERS=self._members_emitter.Fragments())
463 487
464 self._GenerateCppHeader() 488 self._GenerateCppHeader()
465 489
466 self._cpp_impl_emitter.Emit( 490 self._cpp_impl_emitter.Emit(
467 self._templates.Load('cpp_implementation.template'), 491 self._templates.Load('cpp_implementation.template'),
468 INTERFACE=self._interface.id, 492 INTERFACE=self._interface.id,
469 INCLUDES=_GenerateCPPIncludes(self._cpp_impl_includes), 493 INCLUDES=_GenerateCPPIncludes(self._cpp_impl_includes),
470 CALLBACKS=self._cpp_definitions_emitter.Fragments(), 494 CALLBACKS=self._cpp_definitions_emitter.Fragments(),
471 RESOLVER=self._cpp_resolver_emitter.Fragments()) 495 RESOLVER=self._cpp_resolver_emitter.Fragments(),
496 DART_IMPLEMENTATION_CLASS=class_name)
472 497
473 def _GenerateCppHeader(self): 498 def _GenerateCppHeader(self):
474 to_native_emitter = emitter.Emitter() 499 to_native_emitter = emitter.Emitter()
475 if self._interface_type_info.custom_to_native(): 500 if self._interface_type_info.custom_to_native():
476 to_native_emitter.Emit( 501 to_native_emitter.Emit(
477 ' static PassRefPtr<NativeType> toNative(Dart_Handle handle, Dart_H andle& exception);\n') 502 ' static PassRefPtr<NativeType> toNative(Dart_Handle handle, Dart_H andle& exception);\n')
478 else: 503 else:
479 to_native_emitter.Emit( 504 to_native_emitter.Emit(
480 ' static NativeType* toNative(Dart_Handle handle, Dart_Handle& exce ption)\n' 505 ' static NativeType* toNative(Dart_Handle handle, Dart_Handle& exce ption)\n'
481 ' {\n' 506 ' {\n'
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 self._AddGetter(getter) 586 self._AddGetter(getter)
562 if setter: 587 if setter:
563 self._AddSetter(setter) 588 self._AddSetter(setter)
564 589
565 def AddSecondaryAttribute(self, interface, getter, setter): 590 def AddSecondaryAttribute(self, interface, getter, setter):
566 self.AddAttribute(getter, setter) 591 self.AddAttribute(getter, setter)
567 592
568 def _AddGetter(self, attr): 593 def _AddGetter(self, attr):
569 type_info = GetIDLTypeInfo(attr.type.id) 594 type_info = GetIDLTypeInfo(attr.type.id)
570 dart_declaration = '%s get %s()' % ( 595 dart_declaration = '%s get %s()' % (
571 type_info.dart_type(), DartDomNameOfAttribute(attr)) 596 self._DartType(attr.type.id), DartDomNameOfAttribute(attr))
572 is_custom = 'Custom' in attr.ext_attrs or 'CustomGetter' in attr.ext_attrs 597 is_custom = 'Custom' in attr.ext_attrs or 'CustomGetter' in attr.ext_attrs
573 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1, 598 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1,
574 dart_declaration, 'Getter', is_custom) 599 dart_declaration, 'Getter', is_custom)
575 if is_custom: 600 if is_custom:
576 return 601 return
577 602
578 arguments = [] 603 arguments = []
579 parameter_definitions_emitter = emitter.Emitter() 604 parameter_definitions_emitter = emitter.Emitter()
580 raises_exceptions = self._GenerateCallWithHandling(attr, parameter_definitio ns_emitter, arguments) 605 raises_exceptions = self._GenerateCallWithHandling(attr, parameter_definitio ns_emitter, arguments)
581 raises_exceptions = raises_exceptions or attr.get_raises 606 raises_exceptions = raises_exceptions or attr.get_raises
(...skipping 23 matching lines...) Expand all
605 630
606 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) 631 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr)
607 invocation = self._GenerateWebCoreInvocation(function_expression, 632 invocation = self._GenerateWebCoreInvocation(function_expression,
608 arguments, attr.type.id, attr.ext_attrs, attr.get_raises) 633 arguments, attr.type.id, attr.ext_attrs, attr.get_raises)
609 self._GenerateNativeCallback(cpp_callback_name, parameter_definitions_emitte r.Fragments(), 634 self._GenerateNativeCallback(cpp_callback_name, parameter_definitions_emitte r.Fragments(),
610 True, invocation, raises_exceptions=raises_exceptions) 635 True, invocation, raises_exceptions=raises_exceptions)
611 636
612 def _AddSetter(self, attr): 637 def _AddSetter(self, attr):
613 type_info = GetIDLTypeInfo(attr.type.id) 638 type_info = GetIDLTypeInfo(attr.type.id)
614 dart_declaration = 'void set %s(%s)' % ( 639 dart_declaration = 'void set %s(%s)' % (
615 DartDomNameOfAttribute(attr), type_info.dart_type()) 640 DartDomNameOfAttribute(attr), self._DartType(attr.type.id))
616 is_custom = set(['Custom', 'CustomSetter', 'V8CustomSetter']) & set(attr.ext _attrs) 641 is_custom = set(['Custom', 'CustomSetter', 'V8CustomSetter']) & set(attr.ext _attrs)
617 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2, 642 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2,
618 dart_declaration, 'Setter', is_custom) 643 dart_declaration, 'Setter', is_custom)
619 if is_custom: 644 if is_custom:
620 return 645 return
621 646
622 arguments = [] 647 arguments = []
623 parameter_definitions_emitter = emitter.Emitter() 648 parameter_definitions_emitter = emitter.Emitter()
624 self._GenerateCallWithHandling(attr, parameter_definitions_emitter, argument s) 649 self._GenerateCallWithHandling(attr, parameter_definitions_emitter, argument s)
625 650
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 # interface Y extends X, List<T> ... 683 # interface Y extends X, List<T> ...
659 # 684 #
660 # In the non-root case we have to choose between: 685 # In the non-root case we have to choose between:
661 # 686 #
662 # class YImpl extends XImpl { add List<T> methods; } 687 # class YImpl extends XImpl { add List<T> methods; }
663 # 688 #
664 # and 689 # and
665 # 690 #
666 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } 691 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; }
667 # 692 #
668 dart_element_type = DartType(element_type) 693 dart_element_type = self._DartType(element_type)
669 if self._HasNativeIndexGetter(): 694 if self._HasNativeIndexGetter():
670 self._EmitNativeIndexGetter(dart_element_type) 695 self._EmitNativeIndexGetter(dart_element_type)
671 else: 696 else:
672 self._members_emitter.Emit( 697 self._members_emitter.Emit(
673 '\n' 698 '\n'
674 ' $TYPE operator[](int index) {\n' 699 ' $TYPE operator[](int index) {\n'
675 ' return item(index);\n' 700 ' return item(index);\n'
676 ' }\n', 701 ' }\n',
677 TYPE=dart_element_type) 702 TYPE=dart_element_type)
678 703
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 TYPE=dart_element_type) 801 TYPE=dart_element_type)
777 802
778 def AmendIndexer(self, element_type): 803 def AmendIndexer(self, element_type):
779 # If interface is marked as having native indexed 804 # If interface is marked as having native indexed
780 # getter or setter, we must emit overrides as it's not 805 # getter or setter, we must emit overrides as it's not
781 # guaranteed that the corresponding methods in C++ would be 806 # guaranteed that the corresponding methods in C++ would be
782 # virtual. For example, as of time of writing, even though 807 # virtual. For example, as of time of writing, even though
783 # Uint8ClampedArray inherits from Uint8Array, ::set method 808 # Uint8ClampedArray inherits from Uint8Array, ::set method
784 # is not virtual and accessing it through Uint8Array pointer 809 # is not virtual and accessing it through Uint8Array pointer
785 # would lead to wrong semantics (modulo vs. clamping.) 810 # would lead to wrong semantics (modulo vs. clamping.)
786 dart_element_type = DartType(element_type) 811 dart_element_type = self._DartType(element_type)
787 812
788 if self._HasNativeIndexGetter(): 813 if self._HasNativeIndexGetter():
789 self._EmitNativeIndexGetter(dart_element_type) 814 self._EmitNativeIndexGetter(dart_element_type)
790 if self._HasNativeIndexSetter(): 815 if self._HasNativeIndexSetter():
791 self._EmitNativeIndexSetter(dart_element_type) 816 self._EmitNativeIndexSetter(dart_element_type)
792 817
793 def _HasNativeIndexGetter(self): 818 def _HasNativeIndexGetter(self):
794 ext_attrs = self._interface.ext_attrs 819 ext_attrs = self._interface.ext_attrs
795 return ('CustomIndexedGetter' in ext_attrs or 820 return ('CustomIndexedGetter' in ext_attrs or
796 'NumericIndexedGetter' in ext_attrs) 821 'NumericIndexedGetter' in ext_attrs)
(...skipping 14 matching lines...) Expand all
811 def _AddOperation(self, info): 836 def _AddOperation(self, info):
812 """ 837 """
813 Arguments: 838 Arguments:
814 info: An OperationInfo object. 839 info: An OperationInfo object.
815 """ 840 """
816 841
817 if 'CheckSecurityForNode' in info.overloads[0].ext_attrs: 842 if 'CheckSecurityForNode' in info.overloads[0].ext_attrs:
818 # FIXME: exclude from interface as well. 843 # FIXME: exclude from interface as well.
819 return 844 return
820 845
846 parameters = info.ParametersImplementationDeclaration(lambda x: self._DartTy pe(x))
821 if 'Custom' in info.overloads[0].ext_attrs: 847 if 'Custom' in info.overloads[0].ext_attrs:
822 parameters = info.ParametersImplementationDeclaration() 848 dart_declaration = '%s %s(%s)' % (self._DartType(info.type_name), info.nam e, parameters)
823 dart_declaration = '%s %s(%s)' % (info.type_name, info.name, parameters)
824 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) 849 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos)
825 self._GenerateNativeBinding(info.name, argument_count, dart_declaration, 850 self._GenerateNativeBinding(info.name, argument_count, dart_declaration,
826 'Callback', True) 851 'Callback', True)
827 return 852 return
828 853
829 modifier = '' 854 modifier = ''
830 if info.IsStatic(): 855 if info.IsStatic():
831 modifier = 'static ' 856 modifier = 'static '
832 body = self._members_emitter.Emit( 857 body = self._members_emitter.Emit(
833 '\n' 858 '\n'
834 ' $MODIFIER$TYPE $NAME($PARAMETERS) {\n' 859 ' $MODIFIER$TYPE $NAME($PARAMETERS) {\n'
835 '$!BODY' 860 '$!BODY'
836 ' }\n', 861 ' }\n',
837 MODIFIER=modifier, 862 MODIFIER=modifier,
838 TYPE=info.type_name, 863 TYPE=self._DartType(info.type_name),
839 NAME=info.name, 864 NAME=info.name,
840 PARAMETERS=info.ParametersImplementationDeclaration()) 865 PARAMETERS=parameters)
841 866
842 # Process in order of ascending number of arguments to ensure missing 867 # Process in order of ascending number of arguments to ensure missing
843 # optional arguments are processed early. 868 # optional arguments are processed early.
844 overloads = sorted(info.overloads, 869 overloads = sorted(info.overloads,
845 key=lambda overload: len(overload.arguments)) 870 key=lambda overload: len(overload.arguments))
846 self._native_version = 0 871 self._native_version = 0
847 fallthrough = self.GenerateDispatch(body, info, ' ', 0, overloads) 872 fallthrough = self.GenerateDispatch(body, info, ' ', 0, overloads)
848 if fallthrough: 873 if fallthrough:
849 body.Emit(' throw "Incorrect number or type of arguments";\n'); 874 body.Emit(' throw "Incorrect number or type of arguments";\n');
850 875
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 positive = [] 929 positive = []
905 negative = [] 930 negative = []
906 first_overload = overloads[0] 931 first_overload = overloads[0]
907 param = info.param_infos[position] 932 param = info.param_infos[position]
908 933
909 if position < len(first_overload.arguments): 934 if position < len(first_overload.arguments):
910 # FIXME: This will not work if the second overload has a more 935 # FIXME: This will not work if the second overload has a more
911 # precise type than the first. E.g., 936 # precise type than the first. E.g.,
912 # void foo(Node x); 937 # void foo(Node x);
913 # void foo(Element x); 938 # void foo(Element x);
914 type = DartType(first_overload.arguments[position].type.id) 939 type = self._DartType(first_overload.arguments[position].type.id)
915 test = TypeCheck(param.name, type) 940 test = TypeCheck(param.name, type)
916 pred = lambda op: len(op.arguments) > position and DartType(op.arguments[p osition].type.id) == type 941 pred = lambda op: len(op.arguments) > position and self._DartType(op.argum ents[position].type.id) == type
917 else: 942 else:
918 type = None 943 type = None
919 test = NullCheck(param.name) 944 test = NullCheck(param.name)
920 pred = lambda op: position >= len(op.arguments) 945 pred = lambda op: position >= len(op.arguments)
921 946
922 for overload in overloads: 947 for overload in overloads:
923 if pred(overload): 948 if pred(overload):
924 positive.append(overload) 949 positive.append(overload)
925 else: 950 else:
926 negative.append(overload) 951 negative.append(overload)
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 else: 1026 else:
1002 dispatch_emitter.Emit('$(INDENT)_$NATIVENAME($ARGS);\n' 1027 dispatch_emitter.Emit('$(INDENT)_$NATIVENAME($ARGS);\n'
1003 '$(INDENT)return;\n', 1028 '$(INDENT)return;\n',
1004 INDENT=indent, 1029 INDENT=indent,
1005 NATIVENAME=native_name, 1030 NATIVENAME=native_name,
1006 ARGS=argument_list) 1031 ARGS=argument_list)
1007 # Generate binding. 1032 # Generate binding.
1008 modifier = '' 1033 modifier = ''
1009 if operation.is_static: 1034 if operation.is_static:
1010 modifier = 'static ' 1035 modifier = 'static '
1011 dart_declaration = '%s%s _%s(%s)' % (modifier, info.type_name, native_name, 1036 dart_declaration = '%s%s _%s(%s)' % (modifier, self._DartType(info.type_name ), native_name,
1012 argument_list) 1037 argument_list)
1013 is_custom = 'Custom' in operation.ext_attrs 1038 is_custom = 'Custom' in operation.ext_attrs
1014 cpp_callback_name = self._GenerateNativeBinding( 1039 cpp_callback_name = self._GenerateNativeBinding(
1015 native_name, (0 if operation.is_static else 1) + len(operation.arguments ), dart_declaration, 'Callback', 1040 native_name, (0 if operation.is_static else 1) + len(operation.arguments ), dart_declaration, 'Callback',
1016 is_custom) 1041 is_custom)
1017 if is_custom: 1042 if is_custom:
1018 return 1043 return
1019 1044
1020 # Generate callback. 1045 # Generate callback.
1021 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i d) 1046 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i d)
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 for parent in interface.parents: 1236 for parent in interface.parents:
1212 parent_name = parent.type.id 1237 parent_name = parent.type.id
1213 if not database.HasInterface(parent.type.id): 1238 if not database.HasInterface(parent.type.id):
1214 continue 1239 continue
1215 parent_interface = database.GetInterface(parent.type.id) 1240 parent_interface = database.GetInterface(parent.type.id)
1216 if callback(parent_interface): 1241 if callback(parent_interface):
1217 return parent_interface 1242 return parent_interface
1218 parent_interface = _FindParent(parent_interface, database, callback) 1243 parent_interface = _FindParent(parent_interface, database, callback)
1219 if parent_interface: 1244 if parent_interface:
1220 return parent_interface 1245 return parent_interface
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698