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, \ |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 100 |
101 # Generate operations. | 101 # Generate operations. |
102 for id in sorted(operationsByName.keys()): | 102 for id in sorted(operationsByName.keys()): |
103 operations = operationsByName[id] | 103 operations = operationsByName[id] |
104 info = AnalyzeOperation(interface, operations) | 104 info = AnalyzeOperation(interface, operations) |
105 self.AddOperation(info, declare_only) | 105 self.AddOperation(info, declare_only) |
106 if ('%s.%s' % (interface.id, info.declared_name) in | 106 if ('%s.%s' % (interface.id, info.declared_name) in |
107 convert_to_future_members): | 107 convert_to_future_members): |
108 self.AddOperation(ConvertToFuture(info), declare_only) | 108 self.AddOperation(ConvertToFuture(info), declare_only) |
109 | 109 |
| 110 def _HoistableConstants(self, interface): |
| 111 consts = [] |
| 112 if interface.parents: |
| 113 for parent in interface.parents: |
| 114 parent_interface = self._database.GetInterface(parent.type.id) |
| 115 # TODO(vsm): This should be a general check. E.g., on private |
| 116 # interfaces? |
| 117 if parent.type.id == 'WebGLRenderingContextBase': |
| 118 consts = consts + parent_interface.constants |
| 119 return consts |
| 120 |
110 def AddSecondaryMembers(self, interface): | 121 def AddSecondaryMembers(self, interface): |
111 # With multiple inheritance, attributes and operations of non-first | 122 # With multiple inheritance, attributes and operations of non-first |
112 # interfaces need to be added. Sometimes the attribute or operation is | 123 # interfaces need to be added. Sometimes the attribute or operation is |
113 # defined in the current interface as well as a parent. In that case we | 124 # defined in the current interface as well as a parent. In that case we |
114 # avoid making a duplicate definition and pray that the signatures match. | 125 # avoid making a duplicate definition and pray that the signatures match. |
| 126 if not self._renamer.ShouldSuppressInterface(interface): |
| 127 secondary_constants = sorted(self._HoistableConstants(interface), |
| 128 ConstantOutputOrder) |
| 129 for const in secondary_constants: |
| 130 self.AddConstant(const) |
| 131 |
115 secondary_parents = self._database.TransitiveSecondaryParents(interface, | 132 secondary_parents = self._database.TransitiveSecondaryParents(interface, |
116 not self._dart_use_blink) | 133 not self._dart_use_blink) |
117 for parent_interface in sorted(secondary_parents): | 134 for parent_interface in sorted(secondary_parents): |
118 if isinstance(parent_interface, str): | 135 if isinstance(parent_interface, str): |
119 continue | 136 continue |
120 for attr in sorted(parent_interface.attributes, ConstantOutputOrder): | 137 for attr in sorted(parent_interface.attributes, ConstantOutputOrder): |
121 if not FindMatchingAttribute(interface, attr): | 138 if not FindMatchingAttribute(interface, attr): |
122 if attr.type.id != 'EventHandler': | 139 if attr.type.id != 'EventHandler': |
123 self.SecondaryContext(parent_interface) | 140 self.SecondaryContext(parent_interface) |
124 self.AddAttribute(attr) | 141 self.AddAttribute(attr) |
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 return self._type_registry.TypeInfo(type_name).narrow_dart_type() | 778 return self._type_registry.TypeInfo(type_name).narrow_dart_type() |
762 | 779 |
763 def _NarrowInputType(self, type_name): | 780 def _NarrowInputType(self, type_name): |
764 return self._NarrowToImplementationType(type_name) | 781 return self._NarrowToImplementationType(type_name) |
765 | 782 |
766 def _DartType(self, type_name): | 783 def _DartType(self, type_name): |
767 return self._type_registry.DartType(type_name) | 784 return self._type_registry.DartType(type_name) |
768 | 785 |
769 def _TypeInfo(self, type_name): | 786 def _TypeInfo(self, type_name): |
770 return self._type_registry.TypeInfo(type_name) | 787 return self._type_registry.TypeInfo(type_name) |
OLD | NEW |