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

Side by Side Diff: lib/dom/scripts/systembase.py

Issue 10700006: Make per-interface generators an implementation detail of a system. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: . Created 8 years, 5 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 | « lib/dom/scripts/generator.py ('k') | lib/dom/scripts/systemfrog.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 base functionality for systems to generate 6 """This module provides base functionality for systems to generate
7 Dart APIs from the IDL database.""" 7 Dart APIs from the IDL database."""
8 8
9 import os 9 import os
10 from generator import * 10 from generator import *
(...skipping 13 matching lines...) Expand all
24 - Finish 24 - Finish
25 """ 25 """
26 26
27 def __init__(self, templates, database, emitters, output_dir): 27 def __init__(self, templates, database, emitters, output_dir):
28 self._templates = templates 28 self._templates = templates
29 self._database = database 29 self._database = database
30 self._emitters = emitters 30 self._emitters = emitters
31 self._output_dir = output_dir 31 self._output_dir = output_dir
32 self._dart_callback_file_paths = [] 32 self._dart_callback_file_paths = []
33 33
34 def InterfaceGenerator(self, 34 def ProcessInterface(self, interface):
35 interface, 35 """Processes an interface that is not a callback function."""
36 common_prefix, 36 pass
37 super_interface_name,
38 source_filter):
39 """Returns an interface generator for |interface|.
40
41 Called once for each interface that is not a callback function.
42 """
43 return None
44 37
45 def ProcessCallback(self, interface, info): 38 def ProcessCallback(self, interface, info):
46 """Processes an interface that is a callback function.""" 39 """Processes an interface that is a callback function."""
47 pass 40 pass
48 41
49 def GenerateLibraries(self, lib_dir): 42 def GenerateLibraries(self, lib_dir):
50 pass 43 pass
51 44
52 def Finish(self): 45 def Finish(self):
53 pass 46 pass
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 result.add(attr.id) 96 result.add(attr.id)
104 for op in parent_interface.operations: 97 for op in parent_interface.operations:
105 result.add(op.id) 98 result.add(op.id)
106 WalkParentChain(parent_interface) 99 WalkParentChain(parent_interface)
107 100
108 result = set() 101 result = set()
109 WalkParentChain(interface) 102 WalkParentChain(interface)
110 return result; 103 return result;
111 104
112 class BaseGenerator(object): 105 class BaseGenerator(object):
113 def __init__(self, database): 106 def __init__(self, database, interface):
114 self._database = database 107 self._database = database
108 self._interface = interface
109
110 def Generate(self):
111 self.StartInterface()
112 self.AddMembers(self._interface)
113 self.AddSecondaryMembers(self._interface)
114 self.FinishInterface()
115 115
116 def AddMembers(self, interface): 116 def AddMembers(self, interface):
117 for const in sorted(interface.constants, ConstantOutputOrder): 117 for const in sorted(interface.constants, ConstantOutputOrder):
118 self.AddConstant(const) 118 self.AddConstant(const)
119 119
120 attributes = [attr for attr in interface.attributes 120 attributes = [attr for attr in interface.attributes
121 if attr.type.id != 'EventListener'] 121 if attr.type.id != 'EventListener']
122 for (getter, setter) in _PairUpAttributes(attributes): 122 for (getter, setter) in _PairUpAttributes(attributes):
123 self.AddAttribute(getter, setter) 123 self.AddAttribute(getter, setter)
124 124
(...skipping 15 matching lines...) Expand all
140 140
141 # Generate operations 141 # Generate operations
142 for id in sorted(operationsById.keys()): 142 for id in sorted(operationsById.keys()):
143 operations = operationsById[id] 143 operations = operationsById[id]
144 info = AnalyzeOperation(interface, operations) 144 info = AnalyzeOperation(interface, operations)
145 if info.IsStatic(): 145 if info.IsStatic():
146 self.AddStaticOperation(info) 146 self.AddStaticOperation(info)
147 else: 147 else:
148 self.AddOperation(info) 148 self.AddOperation(info)
149 149
150 def AddSecondaryMembers(self, interface, secondary_parents): 150 def AddSecondaryMembers(self, interface):
151 # With multiple inheritance, attributes and operations of non-first 151 # With multiple inheritance, attributes and operations of non-first
152 # interfaces need to be added. Sometimes the attribute or operation is 152 # interfaces need to be added. Sometimes the attribute or operation is
153 # defined in the current interface as well as a parent. In that case we 153 # defined in the current interface as well as a parent. In that case we
154 # avoid making a duplicate definition and pray that the signatures match. 154 # avoid making a duplicate definition and pray that the signatures match.
155 155 secondary_parents = self._TransitiveSecondaryParents(interface)
156 for parent_interface in secondary_parents: 156 for parent_interface in secondary_parents:
157 if isinstance(parent_interface, str): # IsDartCollectionType(parent_inter face) 157 if isinstance(parent_interface, str): # IsDartCollectionType(parent_inter face)
158 continue 158 continue
159 attributes = [attr for attr in parent_interface.attributes 159 attributes = [attr for attr in parent_interface.attributes
160 if not FindMatchingAttribute(interface, attr)] 160 if not FindMatchingAttribute(interface, attr)]
161 for (getter, setter) in _PairUpAttributes(attributes): 161 for (getter, setter) in _PairUpAttributes(attributes):
162 self.AddSecondaryAttribute(parent_interface, getter, setter) 162 self.AddSecondaryAttribute(parent_interface, getter, setter)
163 163
164 # Group overloaded operations by id 164 # Group overloaded operations by id
165 operationsById = {} 165 operationsById = {}
(...skipping 26 matching lines...) Expand all
192 192
193 def AddStaticOperation(self, info): 193 def AddStaticOperation(self, info):
194 pass 194 pass
195 195
196 def AddSecondaryAttribute(self, interface, getter, setter): 196 def AddSecondaryAttribute(self, interface, getter, setter):
197 pass 197 pass
198 198
199 def AddSecondaryOperation(self, interface, attr): 199 def AddSecondaryOperation(self, interface, attr):
200 pass 200 pass
201 201
202 def _TransitiveSecondaryParents(self, interface):
203 """Returns a list of all non-primary parents.
204
205 The list contains the interface objects for interfaces defined in the
206 database, and the name for undefined interfaces.
207 """
208 def walk(parents):
209 for parent in parents:
210 if IsDartCollectionType(parent.type.id):
211 result.append(parent.type.id)
212 continue
213 if self._database.HasInterface(parent.type.id):
214 parent_interface = self._database.GetInterface(parent.type.id)
215 result.append(parent_interface)
216 walk(parent_interface.parents)
217
218 result = []
219 if interface.parents:
220 parent = interface.parents[0]
221 if IsPureInterface(parent.type.id):
222 walk(interface.parents)
223 else:
224 walk(interface.parents[1:])
225 return result;
226
202 227
203 def _PairUpAttributes(attributes): 228 def _PairUpAttributes(attributes):
204 """Returns a list of (getter, setter) pairs sorted by name. 229 """Returns a list of (getter, setter) pairs sorted by name.
205 230
206 One element of the pair may be None. 231 One element of the pair may be None.
207 """ 232 """
208 names = sorted(set(attr.id for attr in attributes)) 233 names = sorted(set(attr.id for attr in attributes))
209 getters = {} 234 getters = {}
210 setters = {} 235 setters = {}
211 for attr in attributes: 236 for attr in attributes:
212 if attr.is_fc_getter: 237 if attr.is_fc_getter:
213 getters[attr.id] = attr 238 getters[attr.id] = attr
214 elif attr.is_fc_setter and 'Replaceable' not in attr.ext_attrs: 239 elif attr.is_fc_setter and 'Replaceable' not in attr.ext_attrs:
215 setters[attr.id] = attr 240 setters[attr.id] = attr
216 return [(getters.get(id), setters.get(id)) for id in names] 241 return [(getters.get(id), setters.get(id)) for id in names]
OLDNEW
« no previous file with comments | « lib/dom/scripts/generator.py ('k') | lib/dom/scripts/systemfrog.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698