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

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
« no previous file with comments | « sdk/lib/web_audio/dart2js/web_audio_dart2js.dart ('k') | tools/dom/scripts/idlnode.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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._RemoveShadowingOperationsWithSameSignature(operationsByName,
98 interface)
96 99
97 # Generate operations. 100 # Generate operations.
98 for id in sorted(operationsByName.keys()): 101 for id in sorted(operationsByName.keys()):
99 operations = operationsByName[id] 102 operations = operationsByName[id]
100 info = AnalyzeOperation(interface, operations) 103 info = AnalyzeOperation(interface, operations)
101 self.AddOperation(info, declare_only) 104 self.AddOperation(info, declare_only)
102 if ('%s.%s' % (interface.id, info.declared_name) in 105 if ('%s.%s' % (interface.id, info.declared_name) in
103 convert_to_future_members): 106 convert_to_future_members):
104 self.AddOperation(ConvertToFuture(info), declare_only) 107 self.AddOperation(ConvertToFuture(info), declare_only)
105 108
106 def AddSecondaryMembers(self, interface): 109 def AddSecondaryMembers(self, interface):
107 # With multiple inheritance, attributes and operations of non-first 110 # With multiple inheritance, attributes and operations of non-first
108 # interfaces need to be added. Sometimes the attribute or operation is 111 # 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 112 # 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. 113 # avoid making a duplicate definition and pray that the signatures match.
111 secondary_parents = self._database.TransitiveSecondaryParents(interface) 114 secondary_parents = self._database.TransitiveSecondaryParents(interface)
112 for parent_interface in sorted(secondary_parents): 115 for parent_interface in sorted(secondary_parents):
113 if isinstance(parent_interface, str): 116 if isinstance(parent_interface, str):
114 continue 117 continue
115 for attr in sorted(parent_interface.attributes, ConstantOutputOrder): 118 for attr in sorted(parent_interface.attributes, ConstantOutputOrder):
116 if not FindMatchingAttribute(interface, attr): 119 if not FindMatchingAttribute(interface, attr):
117 if attr.type.id != 'EventListener': 120 if attr.type.id != 'EventListener':
118 self.SecondaryContext(parent_interface) 121 self.SecondaryContext(parent_interface)
119 self.AddAttribute(attr) 122 self.AddAttribute(attr)
120 123
121 # Group overloaded operations by name. 124 # Group overloaded operations by name.
122 operationsByName =self._OperationsByName(parent_interface) 125 operationsByName =self._OperationsByName(parent_interface)
123 126
127 if self.OmitOperationOverrides():
128 self._RemoveShadowingOperationsWithSameSignature(operationsByName,
129 interface)
130
124 # Generate operations. 131 # Generate operations.
125 for id in sorted(operationsByName.keys()): 132 for id in sorted(operationsByName.keys()):
126 if not any(op.id == id for op in interface.operations): 133 if not any(op.id == id for op in interface.operations):
127 operations = operationsByName[id] 134 operations = operationsByName[id]
128 info = AnalyzeOperation(interface, operations) 135 info = AnalyzeOperation(interface, operations)
129 self.SecondaryContext(parent_interface) 136 self.SecondaryContext(parent_interface)
130 self.AddOperation(info) 137 self.AddOperation(info)
131 138
139 def _RemoveShadowingOperationsWithSameSignature(self, operationsByName,
140 interface):
141 if not interface.parents:
142 return
143
144 parent = self._database.GetInterface(interface.parents[0].type.id)
145 if parent == self._interface or parent == interface:
146 return
147 for operation in parent.operations:
148 if operation.id in operationsByName:
149 operations = operationsByName[operation.id]
150 for existing_operation in operations:
151 if existing_operation.SameSignatureAs(operation):
152 del operationsByName[operation.id]
153
132 def _AddRenamedOverloads(self, interface): 154 def _AddRenamedOverloads(self, interface):
133 """The IDL has a number of functions with the same name but that accept 155 """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 156 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 157 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 158 operation with a different DartName), and leave the original version in a
137 few specific instances.""" 159 few specific instances."""
138 potential_added_operations = set() 160 potential_added_operations = set()
139 operations_by_name = self._OperationsByName(interface) 161 operations_by_name = self._OperationsByName(interface)
140 already_renamed = [operation.ext_attrs['DartName'] if 'DartName' in 162 already_renamed = [operation.ext_attrs['DartName'] if 'DartName' in
141 operation.ext_attrs else '' for operation in interface.operations] 163 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( 216 return '%s.%s(%s)' % (interface.id, operation.id, ', '.join(
195 ['%s %s' % (arg.type.id, arg.id) for arg in operation.arguments])) 217 ['%s %s' % (arg.type.id, arg.id) for arg in operation.arguments]))
196 218
197 def _OperationsByName(self, interface): 219 def _OperationsByName(self, interface):
198 operationsByName = {} 220 operationsByName = {}
199 for operation in interface.operations: 221 for operation in interface.operations:
200 name = operation.ext_attrs.get('DartName', operation.id) 222 name = operation.ext_attrs.get('DartName', operation.id)
201 operationsByName.setdefault(name, []).append(operation) 223 operationsByName.setdefault(name, []).append(operation)
202 return operationsByName 224 return operationsByName
203 225
226 def OmitOperationOverrides(self):
227 return False
228
204 def AddConstant(self, constant): 229 def AddConstant(self, constant):
205 const_name = self._renamer.RenameMember( 230 const_name = self._renamer.RenameMember(
206 self._interface.id, constant, constant.id, 'get:', dartify_name=False) 231 self._interface.id, constant, constant.id, 'get:', dartify_name=False)
207 if not const_name: 232 if not const_name:
208 return 233 return
209 234
210 annotations = self._metadata.GetFormattedMetadata( 235 annotations = self._metadata.GetFormattedMetadata(
211 self._library_name, self._interface, constant.id, ' ') 236 self._library_name, self._interface, constant.id, ' ')
212 237
213 type = TypeOrNothing(self._DartType(constant.type.id), constant.type.id) 238 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': 663 if dart_name == 'Window':
639 return _secure_base_types[dart_name] 664 return _secure_base_types[dart_name]
640 return dart_name 665 return dart_name
641 666
642 def SecureBaseName(self, type_name): 667 def SecureBaseName(self, type_name):
643 if type_name in _secure_base_types: 668 if type_name in _secure_base_types:
644 return _secure_base_types[type_name] 669 return _secure_base_types[type_name]
645 670
646 def _DartType(self, type_name): 671 def _DartType(self, type_name):
647 return self._type_registry.DartType(type_name) 672 return self._type_registry.DartType(type_name)
OLDNEW
« no previous file with comments | « sdk/lib/web_audio/dart2js/web_audio_dart2js.dart ('k') | tools/dom/scripts/idlnode.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698