| 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 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, \ |
| 11 DartDomNameOfAttribute, FindMatchingAttribute, IsDartCollectionType, \ | 11 DartDomNameOfAttribute, FindMatchingAttribute, \ |
| 12 IsPureInterface, TypeOrNothing, ConvertToFuture, GetCallbackInfo | 12 TypeOrNothing, ConvertToFuture, GetCallbackInfo |
| 13 from copy import deepcopy | 13 from copy import deepcopy |
| 14 from htmlrenamer import convert_to_future_members, keep_overloaded_members, \ | 14 from htmlrenamer import convert_to_future_members, keep_overloaded_members, \ |
| 15 private_html_members, renamed_html_members, renamed_overloads, \ | 15 private_html_members, renamed_html_members, renamed_overloads, \ |
| 16 removed_html_members | 16 removed_html_members |
| 17 import logging | 17 import logging |
| 18 import monitored | 18 import monitored |
| 19 import sys | 19 import sys |
| 20 | 20 |
| 21 _logger = logging.getLogger('htmldartgenerator') | 21 _logger = logging.getLogger('htmldartgenerator') |
| 22 | 22 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 self.AddOperation(info, declare_only) | 101 self.AddOperation(info, declare_only) |
| 102 if ('%s.%s' % (interface.id, info.declared_name) in | 102 if ('%s.%s' % (interface.id, info.declared_name) in |
| 103 convert_to_future_members): | 103 convert_to_future_members): |
| 104 self.AddOperation(ConvertToFuture(info), declare_only) | 104 self.AddOperation(ConvertToFuture(info), declare_only) |
| 105 | 105 |
| 106 def AddSecondaryMembers(self, interface): | 106 def AddSecondaryMembers(self, interface): |
| 107 # With multiple inheritance, attributes and operations of non-first | 107 # With multiple inheritance, attributes and operations of non-first |
| 108 # interfaces need to be added. Sometimes the attribute or operation is | 108 # interfaces need to be added. Sometimes the attribute or operation is |
| 109 # defined in the current interface as well as a parent. In that case we | 109 # defined in the current interface as well as a parent. In that case we |
| 110 # avoid making a duplicate definition and pray that the signatures match. | 110 # avoid making a duplicate definition and pray that the signatures match. |
| 111 secondary_parents = self._TransitiveSecondaryParents(interface) | 111 secondary_parents = self._database.TransitiveSecondaryParents(interface) |
| 112 for parent_interface in sorted(secondary_parents): | 112 for parent_interface in sorted(secondary_parents): |
| 113 if isinstance(parent_interface, str): | 113 if isinstance(parent_interface, str): |
| 114 continue | 114 continue |
| 115 for attr in sorted(parent_interface.attributes, ConstantOutputOrder): | 115 for attr in sorted(parent_interface.attributes, ConstantOutputOrder): |
| 116 if not FindMatchingAttribute(interface, attr): | 116 if not FindMatchingAttribute(interface, attr): |
| 117 self.SecondaryContext(parent_interface) | 117 if attr.type.id != 'EventListener': |
| 118 self.AddAttribute(attr) | 118 self.SecondaryContext(parent_interface) |
| 119 self.AddAttribute(attr) |
| 119 | 120 |
| 120 # Group overloaded operations by name. | 121 # Group overloaded operations by name. |
| 121 operationsByName =self._OperationsByName(parent_interface) | 122 operationsByName =self._OperationsByName(parent_interface) |
| 122 | 123 |
| 123 # Generate operations. | 124 # Generate operations. |
| 124 for id in sorted(operationsByName.keys()): | 125 for id in sorted(operationsByName.keys()): |
| 125 if not any(op.id == id for op in interface.operations): | 126 if not any(op.id == id for op in interface.operations): |
| 126 operations = operationsByName[id] | 127 operations = operationsByName[id] |
| 127 info = AnalyzeOperation(interface, operations) | 128 info = AnalyzeOperation(interface, operations) |
| 128 self.SecondaryContext(parent_interface) | 129 self.SecondaryContext(parent_interface) |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 # returned in generated code. | 636 # returned in generated code. |
| 636 assert(dart_name != 'HistoryBase' and dart_name != 'LocationBase') | 637 assert(dart_name != 'HistoryBase' and dart_name != 'LocationBase') |
| 637 if dart_name == 'Window': | 638 if dart_name == 'Window': |
| 638 return _secure_base_types[dart_name] | 639 return _secure_base_types[dart_name] |
| 639 return dart_name | 640 return dart_name |
| 640 | 641 |
| 641 def SecureBaseName(self, type_name): | 642 def SecureBaseName(self, type_name): |
| 642 if type_name in _secure_base_types: | 643 if type_name in _secure_base_types: |
| 643 return _secure_base_types[type_name] | 644 return _secure_base_types[type_name] |
| 644 | 645 |
| 645 def _TransitiveSecondaryParents(self, interface): | |
| 646 """Returns a list of all non-primary parents. | |
| 647 | |
| 648 The list contains the interface objects for interfaces defined in the | |
| 649 database, and the name for undefined interfaces. | |
| 650 """ | |
| 651 def walk(parents): | |
| 652 for parent in parents: | |
| 653 parent_name = parent.type.id | |
| 654 if parent_name == 'EventTarget': | |
| 655 # Currently EventTarget is implemented as a mixin, not a proper | |
| 656 # super interface---ignore its members. | |
| 657 continue | |
| 658 if IsDartCollectionType(parent_name): | |
| 659 result.append(parent_name) | |
| 660 continue | |
| 661 if self._database.HasInterface(parent_name): | |
| 662 parent_interface = self._database.GetInterface(parent_name) | |
| 663 result.append(parent_interface) | |
| 664 walk(parent_interface.parents) | |
| 665 | |
| 666 result = [] | |
| 667 if interface.parents: | |
| 668 parent = interface.parents[0] | |
| 669 if IsPureInterface(parent.type.id): | |
| 670 walk(interface.parents) | |
| 671 else: | |
| 672 walk(interface.parents[1:]) | |
| 673 return result | |
| 674 | |
| 675 def _DartType(self, type_name): | 646 def _DartType(self, type_name): |
| 676 return self._type_registry.DartType(type_name) | 647 return self._type_registry.DartType(type_name) |
| OLD | NEW |