Chromium Code Reviews| 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 generates Dart APIs from the IDL database.""" | 6 """This module generates Dart APIs from the IDL database.""" |
| 7 | 7 |
| 8 import emitter | 8 import emitter |
| 9 import idlnode | 9 import idlnode |
| 10 import logging | 10 import logging |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 super_interface = None | 319 super_interface = None |
| 320 super_name = interface.id | 320 super_name = interface.id |
| 321 | 321 |
| 322 if super_name in super_map: | 322 if super_name in super_map: |
| 323 super_name = super_map[super_name] | 323 super_name = super_map[super_name] |
| 324 | 324 |
| 325 if (super_database is not None and | 325 if (super_database is not None and |
| 326 super_database.HasInterface(super_name)): | 326 super_database.HasInterface(super_name)): |
| 327 super_interface = super_name | 327 super_interface = super_name |
| 328 | 328 |
| 329 # Create fake EventTarget parent interface for interfaces that have | |
| 330 # 'EventTarget' extended attribute. | |
| 331 class EventTargetParentInterface(): | |
| 332 def __init__(self): | |
| 333 self.type = database.GetInterface('EventTarget') | |
| 334 self.annotations = ['WebKit'] | |
| 335 | |
| 336 if 'EventTarget' in interface.ext_attrs: | |
| 337 interface.parents.append(EventTargetParentInterface()) | |
|
sra1
2012/04/11 20:23:05
We should really append an IDLParentInterface, oth
podivilov
2012/04/12 14:37:41
Done.
| |
| 338 | |
| 329 interface_name = interface.id | 339 interface_name = interface.id |
| 330 auxiliary_file = self._auxiliary_files.get(interface_name) | 340 auxiliary_file = self._auxiliary_files.get(interface_name) |
| 331 if auxiliary_file is not None: | 341 if auxiliary_file is not None: |
| 332 _logger.info('Skipping %s because %s exists' % ( | 342 _logger.info('Skipping %s because %s exists' % ( |
| 333 interface_name, auxiliary_file)) | 343 interface_name, auxiliary_file)) |
| 334 continue | 344 continue |
| 335 | 345 |
| 336 info = RecognizeCallback(interface) | 346 info = RecognizeCallback(interface) |
| 337 if info: | 347 if info: |
| 338 for system in self._systems: | 348 for system in self._systems: |
| 339 system.ProcessCallback(interface, info) | 349 system.ProcessCallback(interface, info) |
| 340 else: | 350 else: |
| 341 if 'Callback' in interface.ext_attrs: | 351 if 'Callback' in interface.ext_attrs: |
| 342 _logger.info('Malformed callback: %s' % interface.id) | 352 _logger.info('Malformed callback: %s' % interface.id) |
| 343 self._ProcessInterface(interface, super_interface, | 353 self._ProcessInterface(interface, super_interface, |
| 344 source_filter, common_prefix) | 354 source_filter, common_prefix) |
| 345 | 355 |
| 346 # Libraries | 356 # Libraries |
| 347 if lib_dir: | 357 if lib_dir: |
| 348 for system in self._systems: | 358 for system in self._systems: |
| 349 system.GenerateLibraries(lib_dir) | 359 system.GenerateLibraries(lib_dir) |
| 350 | 360 |
| 351 for system in self._systems: | 361 for system in self._systems: |
| 352 system.Finish() | 362 system.Finish() |
| 353 | 363 |
| 354 | |
| 355 def _PreOrderInterfaces(self, interfaces): | 364 def _PreOrderInterfaces(self, interfaces): |
| 356 """Returns the interfaces in pre-order, i.e. parents first.""" | 365 """Returns the interfaces in pre-order, i.e. parents first.""" |
| 357 seen = set() | 366 seen = set() |
| 358 ordered = [] | 367 ordered = [] |
| 359 def visit(interface): | 368 def visit(interface): |
| 360 if interface.id in seen: | 369 if interface.id in seen: |
| 361 return | 370 return |
| 362 seen.add(interface.id) | 371 seen.add(interface.id) |
| 363 for parent in interface.parents: | 372 for parent in interface.parents: |
| 364 if IsDartCollectionType(parent.type.id): | 373 if IsDartCollectionType(parent.type.id): |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 387 generators = filter(None, generators) | 396 generators = filter(None, generators) |
| 388 | 397 |
| 389 for generator in generators: | 398 for generator in generators: |
| 390 generator.StartInterface() | 399 generator.StartInterface() |
| 391 | 400 |
| 392 for const in sorted(interface.constants, ConstantOutputOrder): | 401 for const in sorted(interface.constants, ConstantOutputOrder): |
| 393 for generator in generators: | 402 for generator in generators: |
| 394 generator.AddConstant(const) | 403 generator.AddConstant(const) |
| 395 | 404 |
| 396 attributes = [attr for attr in interface.attributes | 405 attributes = [attr for attr in interface.attributes |
| 397 if not self._IsEventAttribute(interface, attr)] | 406 if attr.type.id != 'EventListener'] |
| 398 for (getter, setter) in _PairUpAttributes(attributes): | 407 for (getter, setter) in _PairUpAttributes(attributes): |
| 399 for generator in generators: | 408 for generator in generators: |
| 400 generator.AddAttribute(getter, setter) | 409 generator.AddAttribute(getter, setter) |
| 401 | 410 |
| 402 # The implementation should define an indexer if the interface directly | 411 # The implementation should define an indexer if the interface directly |
| 403 # extends List. | 412 # extends List. |
| 404 element_type = MaybeListElementType(interface) | 413 element_type = MaybeListElementType(interface) |
| 405 if element_type: | 414 if element_type: |
| 406 for generator in generators: | 415 for generator in generators: |
| 407 generator.AddIndexer(element_type) | 416 generator.AddIndexer(element_type) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 if not any(op.id == id for op in interface.operations): | 454 if not any(op.id == id for op in interface.operations): |
| 446 operations = operationsById[id] | 455 operations = operationsById[id] |
| 447 info = AnalyzeOperation(interface, operations) | 456 info = AnalyzeOperation(interface, operations) |
| 448 for generator in generators: | 457 for generator in generators: |
| 449 generator.AddSecondaryOperation(parent_interface, info) | 458 generator.AddSecondaryOperation(parent_interface, info) |
| 450 | 459 |
| 451 for generator in generators: | 460 for generator in generators: |
| 452 generator.FinishInterface() | 461 generator.FinishInterface() |
| 453 return | 462 return |
| 454 | 463 |
| 455 def _IsEventAttribute(self, interface, attr): | |
| 456 # Remove EventListener attributes like 'onclick' when addEventListener | |
| 457 # is available. | |
| 458 return (attr.type.id == 'EventListener' and | |
| 459 'EventTarget' in self._AllImplementedInterfaces(interface)) | |
| 460 | |
| 461 def _TransitiveSecondaryParents(self, interface): | 464 def _TransitiveSecondaryParents(self, interface): |
| 462 """Returns a list of all non-primary parents. | 465 """Returns a list of all non-primary parents. |
| 463 | 466 |
| 464 The list contains the interface objects for interfaces defined in the | 467 The list contains the interface objects for interfaces defined in the |
| 465 database, and the name for undefined interfaces. | 468 database, and the name for undefined interfaces. |
| 466 """ | 469 """ |
| 467 def walk(parents): | 470 def walk(parents): |
| 468 for parent in parents: | 471 for parent in parents: |
| 469 if IsDartCollectionType(parent.type.id): | 472 if IsDartCollectionType(parent.type.id): |
| 470 result.append(parent.type.id) | 473 result.append(parent.type.id) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 if not '<' in parent.type.id: | 517 if not '<' in parent.type.id: |
| 515 if self._database.HasInterface(parent.type.id): | 518 if self._database.HasInterface(parent.type.id): |
| 516 Collect(self._database.GetInterface(parent.type.id), | 519 Collect(self._database.GetInterface(parent.type.id), |
| 517 seen, collected) | 520 seen, collected) |
| 518 | 521 |
| 519 self._inheritance_closure = {} | 522 self._inheritance_closure = {} |
| 520 for interface in self._database.GetInterfaces(): | 523 for interface in self._database.GetInterfaces(): |
| 521 seen = set() | 524 seen = set() |
| 522 collected = [] | 525 collected = [] |
| 523 Collect(interface, seen, collected) | 526 Collect(interface, seen, collected) |
| 527 if 'EventTarget' in interface.ext_attrs: | |
| 528 collected.append('EventTarget') | |
|
sra1
2012/04/11 20:23:05
Why do you need this if you added a parent interfa
podivilov
2012/04/12 14:37:41
_ComputeInheritanceClosure is called too early, I
| |
| 524 self._inheritance_closure[interface.id] = collected | 529 self._inheritance_closure[interface.id] = collected |
| 525 | 530 |
| 526 def _AllImplementedInterfaces(self, interface): | 531 def _AllImplementedInterfaces(self, interface): |
| 527 """Returns a list of the names of all interfaces implemented by 'interface'. | 532 """Returns a list of the names of all interfaces implemented by 'interface'. |
| 528 List includes the name of 'interface'. | 533 List includes the name of 'interface'. |
| 529 """ | 534 """ |
| 530 return self._inheritance_closure[interface.id] | 535 return self._inheritance_closure[interface.id] |
| 531 | 536 |
| 532 def _PairUpAttributes(attributes): | 537 def _PairUpAttributes(attributes): |
| 533 """Returns a list of (getter, setter) pairs sorted by name. | 538 """Returns a list of (getter, setter) pairs sorted by name. |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 625 pass | 630 pass |
| 626 | 631 |
| 627 def AddTypedArrayConstructors(self, element_type): | 632 def AddTypedArrayConstructors(self, element_type): |
| 628 pass | 633 pass |
| 629 | 634 |
| 630 def AddOperation(self, info): | 635 def AddOperation(self, info): |
| 631 pass | 636 pass |
| 632 | 637 |
| 633 def AddEventAttributes(self, event_attrs): | 638 def AddEventAttributes(self, event_attrs): |
| 634 pass | 639 pass |
| OLD | NEW |