| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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() => _get(\'$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): |
| 388 # FIXME: Make dart:html wrapperless and cleanup this method. |
| 389 if idl_type in ['EventListener', 'TimeoutHandler']: |
| 390 return idl_type |
| 391 if idl_type in ['EventTarget', 'IDBAny', 'IDBKey']: |
| 392 return 'Dynamic' |
| 393 if idl_type == 'DOMStringList': |
| 394 return 'List<String>' |
| 395 |
| 396 type_info = GetIDLTypeInfo(idl_type) |
| 397 if isinstance(type_info, PrimitiveIDLTypeInfo) or isinstance(type_info, Sequ
enceIDLTypeInfo): |
| 398 return type_info.dart_type() |
| 399 |
| 400 if self._system._database.HasInterface(idl_type): |
| 401 interface = self._system._database.GetInterface(idl_type) |
| 402 if 'Callback' in interface.ext_attrs: |
| 403 return idl_type |
| 404 return '_%s' % idl_type |
| 405 return idl_type |
| 384 | 406 |
| 385 def _BaseClassName(self): | 407 def _BaseClassName(self): |
| 386 if not self._interface.parents: | 408 if not self._interface.parents: |
| 387 return 'DOMWrapperBase' | 409 return '_DOMWrapperBase' |
| 388 | 410 |
| 389 supertype = self._interface.parents[0].type.id | 411 supertype = self._interface.parents[0].type.id |
| 390 | 412 |
| 391 # FIXME: We're currently injecting List<..> and EventTarget as | 413 # FIXME: We're currently injecting List<..> and EventTarget as |
| 392 # supertypes in dart.idl. We should annotate/preserve as | 414 # supertypes in dart.idl. We should annotate/preserve as |
| 393 # attributes instead. For now, this hack lets the self._interfaces | 415 # attributes instead. For now, this hack lets the self._interfaces |
| 394 # inherit, but not the classes. | 416 # inherit, but not the classes. |
| 395 # List methods are injected in AddIndexer. | 417 # List methods are injected in AddIndexer. |
| 396 if IsDartListType(supertype) or IsDartCollectionType(supertype): | 418 if IsDartListType(supertype) or IsDartCollectionType(supertype): |
| 397 return 'DOMWrapperBase' | 419 return '_DOMWrapperBase' |
| 398 | 420 |
| 399 if supertype == 'EventTarget': | 421 if supertype == 'EventTarget': |
| 400 # Most implementors of EventTarget specify the EventListener operations | 422 # Most implementors of EventTarget specify the EventListener operations |
| 401 # again. If the operations are not specified, try to inherit from the | 423 # again. If the operations are not specified, try to inherit from the |
| 402 # EventTarget implementation. | 424 # EventTarget implementation. |
| 403 # | 425 # |
| 404 # Applies to MessagePort. | 426 # Applies to MessagePort. |
| 405 if not [op for op in self._interface.operations if op.id == 'addEventListe
ner']: | 427 if not [op for op in self._interface.operations if op.id == 'addEventListe
ner']: |
| 406 return self._ImplClassName(supertype) | 428 return self._ImplClassName(supertype) |
| 407 return 'DOMWrapperBase' | 429 return '_DOMWrapperBase' |
| 408 | 430 |
| 409 return self._ImplClassName(supertype) | 431 return self._ImplClassName(supertype) |
| 410 | 432 |
| 411 def _IsConstructable(self): | 433 def _IsConstructable(self): |
| 412 # FIXME: support ConstructorTemplate. | 434 # FIXME: support ConstructorTemplate. |
| 413 return set(['CustomConstructor', 'V8CustomConstructor', 'Constructor', 'Name
dConstructor']) & set(self._interface.ext_attrs) | 435 return set(['CustomConstructor', 'V8CustomConstructor', 'Constructor', 'Name
dConstructor']) & set(self._interface.ext_attrs) |
| 414 | 436 |
| 415 def _EmitFactoryProvider(self, interface_name, constructor_info): | 437 def _EmitFactoryProvider(self, interface_name, constructor_info): |
| 416 factory_provider = '_' + interface_name + 'FactoryProvider' | 438 factory_provider = '_%sFactoryProvider' % interface_name |
| 417 implementation_class = interface_name + 'FactoryProviderImplementation' | 439 implementation_class = '_%sFactoryProviderImpl' % interface_name |
| 418 implementation_function = 'create' + interface_name | 440 implementation_function = 'create' + interface_name |
| 419 native_implementation_function = '%s_constructor_Callback' % interface_name | 441 native_implementation_function = '%s_constructor_Callback' % interface_name |
| 420 | 442 |
| 421 # Emit private factory provider in public library. | 443 # Emit private factory provider in public library. |
| 422 template_file = 'factoryprovider_%s.darttemplate' % interface_name | 444 template_file = 'factoryprovider_%s.darttemplate' % interface_name |
| 423 template = self._system._templates.TryLoad(template_file) | 445 template = self._system._templates.TryLoad(template_file) |
| 424 if not template: | 446 if not template: |
| 425 template = self._system._templates.Load('factoryprovider.darttemplate') | 447 template = self._system._templates.Load('factoryprovider.darttemplate') |
| 426 | 448 |
| 427 dart_impl_path = self._system._FilePathForDartFactoryProvider( | 449 dart_impl_path = self._system._FilePathForDartFactoryProvider( |
| 428 interface_name) | 450 interface_name) |
| 429 self._system._dom_public_files.append(dart_impl_path) | 451 self._system._dom_public_files.append(dart_impl_path) |
| 430 | 452 |
| 453 parameters = constructor_info.ParametersImplementationDeclaration(self._Dart
Type) |
| 454 |
| 431 emitter = self._system._emitters.FileEmitter(dart_impl_path) | 455 emitter = self._system._emitters.FileEmitter(dart_impl_path) |
| 432 emitter.Emit( | 456 emitter.Emit( |
| 433 template, | 457 template, |
| 434 FACTORY_PROVIDER=factory_provider, | 458 FACTORY_PROVIDER=factory_provider, |
| 435 CONSTRUCTOR=interface_name, | 459 CONSTRUCTOR=interface_name, |
| 436 PARAMETERS=constructor_info.ParametersImplementationDeclaration(), | 460 PARAMETERS=parameters, |
| 437 IMPL_CLASS=implementation_class, | 461 IMPL_CLASS=implementation_class, |
| 438 IMPL_FUNCTION=implementation_function, | 462 IMPL_FUNCTION=implementation_function, |
| 439 ARGUMENTS=constructor_info.ParametersAsArgumentList()) | 463 ARGUMENTS=constructor_info.ParametersAsArgumentList()) |
| 440 | 464 |
| 441 # Emit public implementation in implementation libary. | 465 # Emit public implementation in implementation libary. |
| 442 dart_impl_path = self._system._FilePathForDartFactoryProviderImplementation( | 466 dart_impl_path = self._system._FilePathForDartFactoryProviderImplementation( |
| 443 interface_name) | 467 interface_name) |
| 444 self._system._dom_impl_files.append(dart_impl_path) | 468 self._system._dom_impl_files.append(dart_impl_path) |
| 445 emitter = self._system._emitters.FileEmitter(dart_impl_path) | 469 emitter = self._system._emitters.FileEmitter(dart_impl_path) |
| 446 emitter.Emit( | 470 emitter.Emit( |
| 447 'class $IMPL_CLASS {\n' | 471 'class $IMPL_CLASS {\n' |
| 448 ' static $INTERFACE_NAME $IMPL_FUNCTION($PARAMETERS)\n' | 472 ' static $TYPE $IMPL_FUNCTION($PARAMETERS)\n' |
| 449 ' native "$NATIVE_NAME";\n' | 473 ' native "$NATIVE_NAME";\n' |
| 450 '}', | 474 '}', |
| 451 INTERFACE_NAME=interface_name, | 475 PARAMETERS=parameters, |
| 452 PARAMETERS=constructor_info.ParametersImplementationDeclaration(), | |
| 453 IMPL_CLASS=implementation_class, | 476 IMPL_CLASS=implementation_class, |
| 477 TYPE=self._ImplClassName(interface_name), |
| 454 IMPL_FUNCTION=implementation_function, | 478 IMPL_FUNCTION=implementation_function, |
| 455 NATIVE_NAME=native_implementation_function) | 479 NATIVE_NAME=native_implementation_function) |
| 456 | 480 |
| 457 def FinishInterface(self): | 481 def FinishInterface(self): |
| 482 class_name = self._ImplClassName(self._interface.id) |
| 458 base = self._BaseClassName() | 483 base = self._BaseClassName() |
| 459 self._dart_impl_emitter.Emit( | 484 self._dart_impl_emitter.Emit( |
| 460 self._templates.Load('dart_implementation.darttemplate'), | 485 self._templates.Load('dart_implementation.darttemplate'), |
| 461 CLASS=self._class_name, BASE=base, INTERFACE=self._interface.id, | 486 CLASS=class_name, BASE=base, INTERFACE=self._interface.id, |
| 462 MEMBERS=self._members_emitter.Fragments()) | 487 MEMBERS=self._members_emitter.Fragments()) |
| 463 | 488 |
| 464 self._GenerateCppHeader() | 489 self._GenerateCppHeader() |
| 465 | 490 |
| 466 self._cpp_impl_emitter.Emit( | 491 self._cpp_impl_emitter.Emit( |
| 467 self._templates.Load('cpp_implementation.template'), | 492 self._templates.Load('cpp_implementation.template'), |
| 468 INTERFACE=self._interface.id, | 493 INTERFACE=self._interface.id, |
| 469 INCLUDES=_GenerateCPPIncludes(self._cpp_impl_includes), | 494 INCLUDES=_GenerateCPPIncludes(self._cpp_impl_includes), |
| 470 CALLBACKS=self._cpp_definitions_emitter.Fragments(), | 495 CALLBACKS=self._cpp_definitions_emitter.Fragments(), |
| 471 RESOLVER=self._cpp_resolver_emitter.Fragments()) | 496 RESOLVER=self._cpp_resolver_emitter.Fragments(), |
| 497 DART_IMPLEMENTATION_CLASS=class_name) |
| 472 | 498 |
| 473 def _GenerateCppHeader(self): | 499 def _GenerateCppHeader(self): |
| 474 to_native_emitter = emitter.Emitter() | 500 to_native_emitter = emitter.Emitter() |
| 475 if self._interface_type_info.custom_to_native(): | 501 if self._interface_type_info.custom_to_native(): |
| 476 to_native_emitter.Emit( | 502 to_native_emitter.Emit( |
| 477 ' static PassRefPtr<NativeType> toNative(Dart_Handle handle, Dart_H
andle& exception);\n') | 503 ' static PassRefPtr<NativeType> toNative(Dart_Handle handle, Dart_H
andle& exception);\n') |
| 478 else: | 504 else: |
| 479 to_native_emitter.Emit( | 505 to_native_emitter.Emit( |
| 480 ' static NativeType* toNative(Dart_Handle handle, Dart_Handle& exce
ption)\n' | 506 ' static NativeType* toNative(Dart_Handle handle, Dart_Handle& exce
ption)\n' |
| 481 ' {\n' | 507 ' {\n' |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 self._AddGetter(getter) | 587 self._AddGetter(getter) |
| 562 if setter: | 588 if setter: |
| 563 self._AddSetter(setter) | 589 self._AddSetter(setter) |
| 564 | 590 |
| 565 def AddSecondaryAttribute(self, interface, getter, setter): | 591 def AddSecondaryAttribute(self, interface, getter, setter): |
| 566 self.AddAttribute(getter, setter) | 592 self.AddAttribute(getter, setter) |
| 567 | 593 |
| 568 def _AddGetter(self, attr): | 594 def _AddGetter(self, attr): |
| 569 type_info = GetIDLTypeInfo(attr.type.id) | 595 type_info = GetIDLTypeInfo(attr.type.id) |
| 570 dart_declaration = '%s get %s()' % ( | 596 dart_declaration = '%s get %s()' % ( |
| 571 type_info.dart_type(), DartDomNameOfAttribute(attr)) | 597 self._DartType(attr.type.id), DartDomNameOfAttribute(attr)) |
| 572 is_custom = 'Custom' in attr.ext_attrs or 'CustomGetter' in attr.ext_attrs | 598 is_custom = 'Custom' in attr.ext_attrs or 'CustomGetter' in attr.ext_attrs |
| 573 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1, | 599 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1, |
| 574 dart_declaration, 'Getter', is_custom) | 600 dart_declaration, 'Getter', is_custom) |
| 575 if is_custom: | 601 if is_custom: |
| 576 return | 602 return |
| 577 | 603 |
| 578 arguments = [] | 604 arguments = [] |
| 579 parameter_definitions_emitter = emitter.Emitter() | 605 parameter_definitions_emitter = emitter.Emitter() |
| 580 raises_exceptions = self._GenerateCallWithHandling(attr, parameter_definitio
ns_emitter, arguments) | 606 raises_exceptions = self._GenerateCallWithHandling(attr, parameter_definitio
ns_emitter, arguments) |
| 581 raises_exceptions = raises_exceptions or attr.get_raises | 607 raises_exceptions = raises_exceptions or attr.get_raises |
| (...skipping 23 matching lines...) Expand all Loading... |
| 605 | 631 |
| 606 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi
on_name, attr) | 632 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi
on_name, attr) |
| 607 invocation = self._GenerateWebCoreInvocation(function_expression, | 633 invocation = self._GenerateWebCoreInvocation(function_expression, |
| 608 arguments, attr.type.id, attr.ext_attrs, attr.get_raises) | 634 arguments, attr.type.id, attr.ext_attrs, attr.get_raises) |
| 609 self._GenerateNativeCallback(cpp_callback_name, parameter_definitions_emitte
r.Fragments(), | 635 self._GenerateNativeCallback(cpp_callback_name, parameter_definitions_emitte
r.Fragments(), |
| 610 True, invocation, raises_exceptions=raises_exceptions) | 636 True, invocation, raises_exceptions=raises_exceptions) |
| 611 | 637 |
| 612 def _AddSetter(self, attr): | 638 def _AddSetter(self, attr): |
| 613 type_info = GetIDLTypeInfo(attr.type.id) | 639 type_info = GetIDLTypeInfo(attr.type.id) |
| 614 dart_declaration = 'void set %s(%s)' % ( | 640 dart_declaration = 'void set %s(%s)' % ( |
| 615 DartDomNameOfAttribute(attr), type_info.dart_type()) | 641 DartDomNameOfAttribute(attr), self._DartType(attr.type.id)) |
| 616 is_custom = set(['Custom', 'CustomSetter', 'V8CustomSetter']) & set(attr.ext
_attrs) | 642 is_custom = set(['Custom', 'CustomSetter', 'V8CustomSetter']) & set(attr.ext
_attrs) |
| 617 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2, | 643 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2, |
| 618 dart_declaration, 'Setter', is_custom) | 644 dart_declaration, 'Setter', is_custom) |
| 619 if is_custom: | 645 if is_custom: |
| 620 return | 646 return |
| 621 | 647 |
| 622 arguments = [] | 648 arguments = [] |
| 623 parameter_definitions_emitter = emitter.Emitter() | 649 parameter_definitions_emitter = emitter.Emitter() |
| 624 self._GenerateCallWithHandling(attr, parameter_definitions_emitter, argument
s) | 650 self._GenerateCallWithHandling(attr, parameter_definitions_emitter, argument
s) |
| 625 | 651 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 # interface Y extends X, List<T> ... | 684 # interface Y extends X, List<T> ... |
| 659 # | 685 # |
| 660 # In the non-root case we have to choose between: | 686 # In the non-root case we have to choose between: |
| 661 # | 687 # |
| 662 # class YImpl extends XImpl { add List<T> methods; } | 688 # class YImpl extends XImpl { add List<T> methods; } |
| 663 # | 689 # |
| 664 # and | 690 # and |
| 665 # | 691 # |
| 666 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } | 692 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } |
| 667 # | 693 # |
| 668 dart_element_type = DartType(element_type) | 694 dart_element_type = self._DartType(element_type) |
| 669 if self._HasNativeIndexGetter(): | 695 if self._HasNativeIndexGetter(): |
| 670 self._EmitNativeIndexGetter(dart_element_type) | 696 self._EmitNativeIndexGetter(dart_element_type) |
| 671 else: | 697 else: |
| 672 self._members_emitter.Emit( | 698 self._members_emitter.Emit( |
| 673 '\n' | 699 '\n' |
| 674 ' $TYPE operator[](int index) {\n' | 700 ' $TYPE operator[](int index) {\n' |
| 675 ' return item(index);\n' | 701 ' return item(index);\n' |
| 676 ' }\n', | 702 ' }\n', |
| 677 TYPE=dart_element_type) | 703 TYPE=dart_element_type) |
| 678 | 704 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 TYPE=dart_element_type) | 802 TYPE=dart_element_type) |
| 777 | 803 |
| 778 def AmendIndexer(self, element_type): | 804 def AmendIndexer(self, element_type): |
| 779 # If interface is marked as having native indexed | 805 # If interface is marked as having native indexed |
| 780 # getter or setter, we must emit overrides as it's not | 806 # getter or setter, we must emit overrides as it's not |
| 781 # guaranteed that the corresponding methods in C++ would be | 807 # guaranteed that the corresponding methods in C++ would be |
| 782 # virtual. For example, as of time of writing, even though | 808 # virtual. For example, as of time of writing, even though |
| 783 # Uint8ClampedArray inherits from Uint8Array, ::set method | 809 # Uint8ClampedArray inherits from Uint8Array, ::set method |
| 784 # is not virtual and accessing it through Uint8Array pointer | 810 # is not virtual and accessing it through Uint8Array pointer |
| 785 # would lead to wrong semantics (modulo vs. clamping.) | 811 # would lead to wrong semantics (modulo vs. clamping.) |
| 786 dart_element_type = DartType(element_type) | 812 dart_element_type = self._DartType(element_type) |
| 787 | 813 |
| 788 if self._HasNativeIndexGetter(): | 814 if self._HasNativeIndexGetter(): |
| 789 self._EmitNativeIndexGetter(dart_element_type) | 815 self._EmitNativeIndexGetter(dart_element_type) |
| 790 if self._HasNativeIndexSetter(): | 816 if self._HasNativeIndexSetter(): |
| 791 self._EmitNativeIndexSetter(dart_element_type) | 817 self._EmitNativeIndexSetter(dart_element_type) |
| 792 | 818 |
| 793 def _HasNativeIndexGetter(self): | 819 def _HasNativeIndexGetter(self): |
| 794 ext_attrs = self._interface.ext_attrs | 820 ext_attrs = self._interface.ext_attrs |
| 795 return ('CustomIndexedGetter' in ext_attrs or | 821 return ('CustomIndexedGetter' in ext_attrs or |
| 796 'NumericIndexedGetter' in ext_attrs) | 822 'NumericIndexedGetter' in ext_attrs) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 811 def _AddOperation(self, info): | 837 def _AddOperation(self, info): |
| 812 """ | 838 """ |
| 813 Arguments: | 839 Arguments: |
| 814 info: An OperationInfo object. | 840 info: An OperationInfo object. |
| 815 """ | 841 """ |
| 816 | 842 |
| 817 if 'CheckSecurityForNode' in info.overloads[0].ext_attrs: | 843 if 'CheckSecurityForNode' in info.overloads[0].ext_attrs: |
| 818 # FIXME: exclude from interface as well. | 844 # FIXME: exclude from interface as well. |
| 819 return | 845 return |
| 820 | 846 |
| 847 parameters = info.ParametersImplementationDeclaration(self._DartType) |
| 821 if 'Custom' in info.overloads[0].ext_attrs: | 848 if 'Custom' in info.overloads[0].ext_attrs: |
| 822 parameters = info.ParametersImplementationDeclaration() | 849 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) | 850 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) |
| 825 self._GenerateNativeBinding(info.name, argument_count, dart_declaration, | 851 self._GenerateNativeBinding(info.name, argument_count, dart_declaration, |
| 826 'Callback', True) | 852 'Callback', True) |
| 827 return | 853 return |
| 828 | 854 |
| 829 modifier = '' | 855 modifier = '' |
| 830 if info.IsStatic(): | 856 if info.IsStatic(): |
| 831 modifier = 'static ' | 857 modifier = 'static ' |
| 832 body = self._members_emitter.Emit( | 858 body = self._members_emitter.Emit( |
| 833 '\n' | 859 '\n' |
| 834 ' $MODIFIER$TYPE $NAME($PARAMETERS) {\n' | 860 ' $MODIFIER$TYPE $NAME($PARAMETERS) {\n' |
| 835 '$!BODY' | 861 '$!BODY' |
| 836 ' }\n', | 862 ' }\n', |
| 837 MODIFIER=modifier, | 863 MODIFIER=modifier, |
| 838 TYPE=info.type_name, | 864 TYPE=self._DartType(info.type_name), |
| 839 NAME=info.name, | 865 NAME=info.name, |
| 840 PARAMETERS=info.ParametersImplementationDeclaration()) | 866 PARAMETERS=parameters) |
| 841 | 867 |
| 842 # Process in order of ascending number of arguments to ensure missing | 868 # Process in order of ascending number of arguments to ensure missing |
| 843 # optional arguments are processed early. | 869 # optional arguments are processed early. |
| 844 overloads = sorted(info.overloads, | 870 overloads = sorted(info.overloads, |
| 845 key=lambda overload: len(overload.arguments)) | 871 key=lambda overload: len(overload.arguments)) |
| 846 self._native_version = 0 | 872 self._native_version = 0 |
| 847 fallthrough = self.GenerateDispatch(body, info, ' ', 0, overloads) | 873 fallthrough = self.GenerateDispatch(body, info, ' ', 0, overloads) |
| 848 if fallthrough: | 874 if fallthrough: |
| 849 body.Emit(' throw "Incorrect number or type of arguments";\n'); | 875 body.Emit(' throw "Incorrect number or type of arguments";\n'); |
| 850 | 876 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 positive = [] | 930 positive = [] |
| 905 negative = [] | 931 negative = [] |
| 906 first_overload = overloads[0] | 932 first_overload = overloads[0] |
| 907 param = info.param_infos[position] | 933 param = info.param_infos[position] |
| 908 | 934 |
| 909 if position < len(first_overload.arguments): | 935 if position < len(first_overload.arguments): |
| 910 # FIXME: This will not work if the second overload has a more | 936 # FIXME: This will not work if the second overload has a more |
| 911 # precise type than the first. E.g., | 937 # precise type than the first. E.g., |
| 912 # void foo(Node x); | 938 # void foo(Node x); |
| 913 # void foo(Element x); | 939 # void foo(Element x); |
| 914 type = DartType(first_overload.arguments[position].type.id) | 940 type = self._DartType(first_overload.arguments[position].type.id) |
| 915 test = TypeCheck(param.name, type) | 941 test = TypeCheck(param.name, type) |
| 916 pred = lambda op: len(op.arguments) > position and DartType(op.arguments[p
osition].type.id) == type | 942 pred = lambda op: len(op.arguments) > position and self._DartType(op.argum
ents[position].type.id) == type |
| 917 else: | 943 else: |
| 918 type = None | 944 type = None |
| 919 test = NullCheck(param.name) | 945 test = NullCheck(param.name) |
| 920 pred = lambda op: position >= len(op.arguments) | 946 pred = lambda op: position >= len(op.arguments) |
| 921 | 947 |
| 922 for overload in overloads: | 948 for overload in overloads: |
| 923 if pred(overload): | 949 if pred(overload): |
| 924 positive.append(overload) | 950 positive.append(overload) |
| 925 else: | 951 else: |
| 926 negative.append(overload) | 952 negative.append(overload) |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 else: | 1027 else: |
| 1002 dispatch_emitter.Emit('$(INDENT)_$NATIVENAME($ARGS);\n' | 1028 dispatch_emitter.Emit('$(INDENT)_$NATIVENAME($ARGS);\n' |
| 1003 '$(INDENT)return;\n', | 1029 '$(INDENT)return;\n', |
| 1004 INDENT=indent, | 1030 INDENT=indent, |
| 1005 NATIVENAME=native_name, | 1031 NATIVENAME=native_name, |
| 1006 ARGS=argument_list) | 1032 ARGS=argument_list) |
| 1007 # Generate binding. | 1033 # Generate binding. |
| 1008 modifier = '' | 1034 modifier = '' |
| 1009 if operation.is_static: | 1035 if operation.is_static: |
| 1010 modifier = 'static ' | 1036 modifier = 'static ' |
| 1011 dart_declaration = '%s%s _%s(%s)' % (modifier, info.type_name, native_name, | 1037 dart_declaration = '%s%s _%s(%s)' % (modifier, self._DartType(info.type_name
), native_name, |
| 1012 argument_list) | 1038 argument_list) |
| 1013 is_custom = 'Custom' in operation.ext_attrs | 1039 is_custom = 'Custom' in operation.ext_attrs |
| 1014 cpp_callback_name = self._GenerateNativeBinding( | 1040 cpp_callback_name = self._GenerateNativeBinding( |
| 1015 native_name, (0 if operation.is_static else 1) + len(operation.arguments
), dart_declaration, 'Callback', | 1041 native_name, (0 if operation.is_static else 1) + len(operation.arguments
), dart_declaration, 'Callback', |
| 1016 is_custom) | 1042 is_custom) |
| 1017 if is_custom: | 1043 if is_custom: |
| 1018 return | 1044 return |
| 1019 | 1045 |
| 1020 # Generate callback. | 1046 # Generate callback. |
| 1021 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i
d) | 1047 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i
d) |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1211 for parent in interface.parents: | 1237 for parent in interface.parents: |
| 1212 parent_name = parent.type.id | 1238 parent_name = parent.type.id |
| 1213 if not database.HasInterface(parent.type.id): | 1239 if not database.HasInterface(parent.type.id): |
| 1214 continue | 1240 continue |
| 1215 parent_interface = database.GetInterface(parent.type.id) | 1241 parent_interface = database.GetInterface(parent.type.id) |
| 1216 if callback(parent_interface): | 1242 if callback(parent_interface): |
| 1217 return parent_interface | 1243 return parent_interface |
| 1218 parent_interface = _FindParent(parent_interface, database, callback) | 1244 parent_interface = _FindParent(parent_interface, database, callback) |
| 1219 if parent_interface: | 1245 if parent_interface: |
| 1220 return parent_interface | 1246 return parent_interface |
| OLD | NEW |