Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: tools/dom/scripts/htmldartgenerator.py

Issue 22933003: Removing overloaded operations in dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 if parent == self._interface: 86 if parent == self._interface:
87 continue 87 continue
88 parent_type_info = self._type_registry.TypeInfo(parent.id) 88 parent_type_info = self._type_registry.TypeInfo(parent.id)
89 if parent_type_info.list_item_type(): 89 if parent_type_info.list_item_type():
90 self.AmendIndexer(parent_type_info.list_item_type()) 90 self.AmendIndexer(parent_type_info.list_item_type())
91 break 91 break
92 92
93 # Group overloaded operations by name. 93 # Group overloaded operations by name.
94 self._AddRenamedOverloads(interface) 94 self._AddRenamedOverloads(interface)
95 operationsByName = self._OperationsByName(interface) 95 operationsByName = self._OperationsByName(interface)
96 if self.OmitOperationOverrides():
97 self._FilterOverloads(operationsByName, interface)
96 98
97 # Generate operations. 99 # Generate operations.
98 for id in sorted(operationsByName.keys()): 100 for id in sorted(operationsByName.keys()):
99 operations = operationsByName[id] 101 operations = operationsByName[id]
100 info = AnalyzeOperation(interface, operations) 102 info = AnalyzeOperation(interface, operations)
101 self.AddOperation(info, declare_only) 103 self.AddOperation(info, declare_only)
102 if ('%s.%s' % (interface.id, info.declared_name) in 104 if ('%s.%s' % (interface.id, info.declared_name) in
103 convert_to_future_members): 105 convert_to_future_members):
104 self.AddOperation(ConvertToFuture(info), declare_only) 106 self.AddOperation(ConvertToFuture(info), declare_only)
105 107
106 def AddSecondaryMembers(self, interface): 108 def AddSecondaryMembers(self, interface):
107 # With multiple inheritance, attributes and operations of non-first 109 # With multiple inheritance, attributes and operations of non-first
108 # interfaces need to be added. Sometimes the attribute or operation is 110 # 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 111 # 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. 112 # avoid making a duplicate definition and pray that the signatures match.
111 secondary_parents = self._database.TransitiveSecondaryParents(interface) 113 secondary_parents = self._database.TransitiveSecondaryParents(interface)
112 for parent_interface in sorted(secondary_parents): 114 for parent_interface in sorted(secondary_parents):
113 if isinstance(parent_interface, str): 115 if isinstance(parent_interface, str):
114 continue 116 continue
115 for attr in sorted(parent_interface.attributes, ConstantOutputOrder): 117 for attr in sorted(parent_interface.attributes, ConstantOutputOrder):
116 if not FindMatchingAttribute(interface, attr): 118 if not FindMatchingAttribute(interface, attr):
117 if attr.type.id != 'EventListener': 119 if attr.type.id != 'EventListener':
118 self.SecondaryContext(parent_interface) 120 self.SecondaryContext(parent_interface)
119 self.AddAttribute(attr) 121 self.AddAttribute(attr)
120 122
121 # Group overloaded operations by name. 123 # Group overloaded operations by name.
122 operationsByName =self._OperationsByName(parent_interface) 124 operationsByName =self._OperationsByName(parent_interface)
123 125
126 if self.OmitOperationOverrides():
127 self._FilterOverloads(operationsByName, interface)
128
124 # Generate operations. 129 # Generate operations.
125 for id in sorted(operationsByName.keys()): 130 for id in sorted(operationsByName.keys()):
126 if not any(op.id == id for op in interface.operations): 131 if not any(op.id == id for op in interface.operations):
127 operations = operationsByName[id] 132 operations = operationsByName[id]
128 info = AnalyzeOperation(interface, operations) 133 info = AnalyzeOperation(interface, operations)
129 self.SecondaryContext(parent_interface) 134 self.SecondaryContext(parent_interface)
130 self.AddOperation(info) 135 self.AddOperation(info)
131 136
137 def _FilterOverloads(self, operationsByName, interface):
sra1 2013/08/12 21:31:29 '_RemoveShadowingOperationsWithSameSignature'
blois 2013/08/13 00:22:15 Done.
138 if not interface.parents:
139 return
140
141 parent = self._database.GetInterface(interface.parents[0].type.id)
142 if parent == self._interface or parent == interface:
143 return
144 for operation in parent.operations:
145 if operation.id in operationsByName:
146 operations = operationsByName[operation.id]
147 for existing_operation in operations:
148 if existing_operation.ComparableTo(operation):
149 del operationsByName[operation.id]
150
132 def _AddRenamedOverloads(self, interface): 151 def _AddRenamedOverloads(self, interface):
133 """The IDL has a number of functions with the same name but that accept 152 """The IDL has a number of functions with the same name but that accept
134 different types. This is fine for JavaScript, but results in vague type 153 different types. This is fine for JavaScript, but results in vague type
135 signatures for Dart. We rename some of these (by adding a new identical 154 signatures for Dart. We rename some of these (by adding a new identical
136 operation with a different DartName), and leave the original version in a 155 operation with a different DartName), and leave the original version in a
137 few specific instances.""" 156 few specific instances."""
138 potential_added_operations = set() 157 potential_added_operations = set()
139 operations_by_name = self._OperationsByName(interface) 158 operations_by_name = self._OperationsByName(interface)
140 already_renamed = [operation.ext_attrs['DartName'] if 'DartName' in 159 already_renamed = [operation.ext_attrs['DartName'] if 'DartName' in
141 operation.ext_attrs else '' for operation in interface.operations] 160 operation.ext_attrs else '' for operation in interface.operations]
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 return '%s.%s(%s)' % (interface.id, operation.id, ', '.join( 213 return '%s.%s(%s)' % (interface.id, operation.id, ', '.join(
195 ['%s %s' % (arg.type.id, arg.id) for arg in operation.arguments])) 214 ['%s %s' % (arg.type.id, arg.id) for arg in operation.arguments]))
196 215
197 def _OperationsByName(self, interface): 216 def _OperationsByName(self, interface):
198 operationsByName = {} 217 operationsByName = {}
199 for operation in interface.operations: 218 for operation in interface.operations:
200 name = operation.ext_attrs.get('DartName', operation.id) 219 name = operation.ext_attrs.get('DartName', operation.id)
201 operationsByName.setdefault(name, []).append(operation) 220 operationsByName.setdefault(name, []).append(operation)
202 return operationsByName 221 return operationsByName
203 222
223 def OmitOperationOverrides(self):
224 return False
225
204 def AddConstant(self, constant): 226 def AddConstant(self, constant):
205 const_name = self._renamer.RenameMember( 227 const_name = self._renamer.RenameMember(
206 self._interface.id, constant, constant.id, 'get:', dartify_name=False) 228 self._interface.id, constant, constant.id, 'get:', dartify_name=False)
207 if not const_name: 229 if not const_name:
208 return 230 return
209 231
210 annotations = self._metadata.GetFormattedMetadata( 232 annotations = self._metadata.GetFormattedMetadata(
211 self._library_name, self._interface, constant.id, ' ') 233 self._library_name, self._interface, constant.id, ' ')
212 234
213 type = TypeOrNothing(self._DartType(constant.type.id), constant.type.id) 235 type = TypeOrNothing(self._DartType(constant.type.id), constant.type.id)
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 if dart_name == 'Window': 660 if dart_name == 'Window':
639 return _secure_base_types[dart_name] 661 return _secure_base_types[dart_name]
640 return dart_name 662 return dart_name
641 663
642 def SecureBaseName(self, type_name): 664 def SecureBaseName(self, type_name):
643 if type_name in _secure_base_types: 665 if type_name in _secure_base_types:
644 return _secure_base_types[type_name] 666 return _secure_base_types[type_name]
645 667
646 def _DartType(self, type_name): 668 def _DartType(self, type_name):
647 return self._type_registry.DartType(type_name) 669 return self._type_registry.DartType(type_name)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698