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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 source_filter, common_prefix) | 344 source_filter, common_prefix) |
| 345 | 345 |
| 346 # Libraries | 346 # Libraries |
| 347 if lib_dir: | 347 if lib_dir: |
| 348 for system in self._systems: | 348 for system in self._systems: |
| 349 system.GenerateLibraries(lib_dir) | 349 system.GenerateLibraries(lib_dir) |
| 350 | 350 |
| 351 for system in self._systems: | 351 for system in self._systems: |
| 352 system.Finish() | 352 system.Finish() |
| 353 | 353 |
| 354 | |
| 355 def _PreOrderInterfaces(self, interfaces): | 354 def _PreOrderInterfaces(self, interfaces): |
| 356 """Returns the interfaces in pre-order, i.e. parents first.""" | 355 """Returns the interfaces in pre-order, i.e. parents first.""" |
| 357 seen = set() | 356 seen = set() |
| 358 ordered = [] | 357 ordered = [] |
| 359 def visit(interface): | 358 def visit(interface): |
| 360 if interface.id in seen: | 359 if interface.id in seen: |
| 361 return | 360 return |
| 362 seen.add(interface.id) | 361 seen.add(interface.id) |
| 363 for parent in interface.parents: | 362 for parent in interface.parents: |
| 364 if IsDartCollectionType(parent.type.id): | 363 if IsDartCollectionType(parent.type.id): |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 387 generators = filter(None, generators) | 386 generators = filter(None, generators) |
| 388 | 387 |
| 389 for generator in generators: | 388 for generator in generators: |
| 390 generator.StartInterface() | 389 generator.StartInterface() |
| 391 | 390 |
| 392 for const in sorted(interface.constants, ConstantOutputOrder): | 391 for const in sorted(interface.constants, ConstantOutputOrder): |
| 393 for generator in generators: | 392 for generator in generators: |
| 394 generator.AddConstant(const) | 393 generator.AddConstant(const) |
| 395 | 394 |
| 396 attributes = [attr for attr in interface.attributes | 395 attributes = [attr for attr in interface.attributes |
| 397 if not self._IsEventAttribute(interface, attr)] | 396 if attr.type.id != 'EventListener'] |
| 398 for (getter, setter) in _PairUpAttributes(attributes): | 397 for (getter, setter) in _PairUpAttributes(attributes): |
| 399 for generator in generators: | 398 for generator in generators: |
| 400 generator.AddAttribute(getter, setter) | 399 generator.AddAttribute(getter, setter) |
| 401 | 400 |
| 402 # The implementation should define an indexer if the interface directly | 401 # The implementation should define an indexer if the interface directly |
| 403 # extends List. | 402 # extends List. |
| 404 element_type = MaybeListElementType(interface) | 403 element_type = MaybeListElementType(interface) |
| 405 if element_type: | 404 if element_type: |
| 406 for generator in generators: | 405 for generator in generators: |
| 407 generator.AddIndexer(element_type) | 406 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): | 444 if not any(op.id == id for op in interface.operations): |
| 446 operations = operationsById[id] | 445 operations = operationsById[id] |
| 447 info = AnalyzeOperation(interface, operations) | 446 info = AnalyzeOperation(interface, operations) |
| 448 for generator in generators: | 447 for generator in generators: |
| 449 generator.AddSecondaryOperation(parent_interface, info) | 448 generator.AddSecondaryOperation(parent_interface, info) |
| 450 | 449 |
| 451 for generator in generators: | 450 for generator in generators: |
| 452 generator.FinishInterface() | 451 generator.FinishInterface() |
| 453 return | 452 return |
| 454 | 453 |
| 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): | 454 def _TransitiveSecondaryParents(self, interface): |
| 462 """Returns a list of all non-primary parents. | 455 """Returns a list of all non-primary parents. |
| 463 | 456 |
| 464 The list contains the interface objects for interfaces defined in the | 457 The list contains the interface objects for interfaces defined in the |
| 465 database, and the name for undefined interfaces. | 458 database, and the name for undefined interfaces. |
| 466 """ | 459 """ |
| 467 def walk(parents): | 460 def walk(parents): |
| 468 for parent in parents: | 461 for parent in parents: |
| 469 if IsDartCollectionType(parent.type.id): | 462 if IsDartCollectionType(parent.type.id): |
| 470 result.append(parent.type.id) | 463 result.append(parent.type.id) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 collected.append(name) | 504 collected.append(name) |
| 512 for parent in interface.parents: | 505 for parent in interface.parents: |
| 513 # TODO(sra): Handle parameterized types. | 506 # TODO(sra): Handle parameterized types. |
| 514 if not '<' in parent.type.id: | 507 if not '<' in parent.type.id: |
| 515 if self._database.HasInterface(parent.type.id): | 508 if self._database.HasInterface(parent.type.id): |
| 516 Collect(self._database.GetInterface(parent.type.id), | 509 Collect(self._database.GetInterface(parent.type.id), |
| 517 seen, collected) | 510 seen, collected) |
| 518 | 511 |
| 519 self._inheritance_closure = {} | 512 self._inheritance_closure = {} |
| 520 for interface in self._database.GetInterfaces(): | 513 for interface in self._database.GetInterfaces(): |
| 514 # Create fake EventTarget parent interface for interfaces that have | |
|
sra1
2012/04/12 15:56:17
I think it would be best to move this fixing to a
| |
| 515 # 'EventTarget' extended attribute. | |
| 516 if 'EventTarget' in interface.ext_attrs: | |
| 517 ast = [('Annotation', [('Id', 'WebKit')]), | |
| 518 ('InterfaceType', ('ScopedName', 'EventTarget'))] | |
| 519 interface.parents.append(idlnode.IDLParentInterface(ast)) | |
| 520 | |
| 521 seen = set() | 521 seen = set() |
| 522 collected = [] | 522 collected = [] |
| 523 Collect(interface, seen, collected) | 523 Collect(interface, seen, collected) |
| 524 self._inheritance_closure[interface.id] = collected | 524 self._inheritance_closure[interface.id] = collected |
| 525 | 525 |
| 526 def _AllImplementedInterfaces(self, interface): | 526 def _AllImplementedInterfaces(self, interface): |
| 527 """Returns a list of the names of all interfaces implemented by 'interface'. | 527 """Returns a list of the names of all interfaces implemented by 'interface'. |
| 528 List includes the name of 'interface'. | 528 List includes the name of 'interface'. |
| 529 """ | 529 """ |
| 530 return self._inheritance_closure[interface.id] | 530 return self._inheritance_closure[interface.id] |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 625 pass | 625 pass |
| 626 | 626 |
| 627 def AddTypedArrayConstructors(self, element_type): | 627 def AddTypedArrayConstructors(self, element_type): |
| 628 pass | 628 pass |
| 629 | 629 |
| 630 def AddOperation(self, info): | 630 def AddOperation(self, info): |
| 631 pass | 631 pass |
| 632 | 632 |
| 633 def AddEventAttributes(self, event_attrs): | 633 def AddEventAttributes(self, event_attrs): |
| 634 pass | 634 pass |
| OLD | NEW |