OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """ | 6 """ |
7 IDLRelease for PPAPI | 7 IDLRelease for PPAPI |
8 | 8 |
9 This file defines the behavior of the AST namespace which allows for resolving | 9 This file defines the behavior of the AST namespace which allows for resolving |
10 a symbol as one or more AST nodes given a Release or range of Releases. | 10 a symbol as one or more AST nodes given a Release or range of Releases. |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 if self.rmax <= rmin: | 100 if self.rmax <= rmin: |
101 return False | 101 return False |
102 if rmax is not None and self.rmin is not None: | 102 if rmax is not None and self.rmin is not None: |
103 if self.rmin >= rmax: | 103 if self.rmin >= rmax: |
104 return False | 104 return False |
105 | 105 |
106 if GetOption('release_debug'): | 106 if GetOption('release_debug'): |
107 InfoOut.Log('%f to %f is in %s' % (rmin, rmax, self)) | 107 InfoOut.Log('%f to %f is in %s' % (rmin, rmax, self)) |
108 return True | 108 return True |
109 | 109 |
| 110 def GetMinMax(self, releases = None): |
| 111 if not releases: |
| 112 return self.rmin, self.rmax |
| 113 |
| 114 if not self.rmin: |
| 115 rmin = releases[0] |
| 116 else: |
| 117 rmin = str(self.rmin) |
| 118 if not self.rmax: |
| 119 rmax = releases[-1] |
| 120 else: |
| 121 rmax = str(self.rmax) |
| 122 return (rmin, rmax) |
| 123 |
| 124 def SetMin(self, release): |
| 125 assert not self.rmin |
| 126 self.rmin = release |
| 127 |
110 def Error(self, msg): | 128 def Error(self, msg): |
111 ReportReleaseError(msg) | 129 ReportReleaseError(msg) |
112 | 130 |
113 def Warn(self, msg): | 131 def Warn(self, msg): |
114 ReportReleaseWarning(msg) | 132 ReportReleaseWarning(msg) |
115 | 133 |
116 | 134 |
117 # | 135 # |
118 # IDLReleaseList | 136 # IDLReleaseList |
119 # | 137 # |
120 # IDLReleaseList is a list based container for holding IDLRelease | 138 # IDLReleaseList is a list based container for holding IDLRelease |
121 # objects in order. The IDLReleaseList can be added to, and searched by | 139 # objects in order. The IDLReleaseList can be added to, and searched by |
122 # range. Objects are stored in order, and must be added in order. | 140 # range. Objects are stored in order, and must be added in order. |
123 # | 141 # |
124 class IDLReleaseList(object): | 142 class IDLReleaseList(object): |
125 def __init__(self): | 143 def __init__(self): |
126 self.nodes = [] | 144 self._nodes = [] |
| 145 |
| 146 def GetReleases(self): |
| 147 return self._nodes |
127 | 148 |
128 def FindRelease(self, release): | 149 def FindRelease(self, release): |
129 for node in self.nodes: | 150 for node in self._nodes: |
130 if node.IsRelease(release): | 151 if node.IsRelease(release): |
131 return node | 152 return node |
132 return None | 153 return None |
133 | 154 |
134 def FindRange(self, rmin, rmax): | 155 def FindRange(self, rmin, rmax): |
135 assert (rmin == None) or rmin != rmax | 156 assert (rmin == None) or rmin != rmax |
136 | 157 |
137 out = [] | 158 out = [] |
138 for node in self.nodes: | 159 for node in self._nodes: |
139 if node.InRange(rmin, rmax): | 160 if node.InRange(rmin, rmax): |
140 out.append(node) | 161 out.append(node) |
141 return out | 162 return out |
142 | 163 |
143 def AddNode(self, node): | 164 def AddNode(self, node): |
144 if GetOption('release_debug'): | 165 if GetOption('release_debug'): |
145 InfoOut.Log('\nAdding %s %s' % (node.Location(), node)) | 166 InfoOut.Log('\nAdding %s %s' % (node.Location(), node)) |
146 last = None | 167 last = None |
147 | 168 |
148 # Check current releases in that namespace | 169 # Check current releases in that namespace |
149 for cver in self.nodes: | 170 for cver in self._nodes: |
150 if GetOption('release_debug'): InfoOut.Log(' Checking %s' % cver) | 171 if GetOption('release_debug'): InfoOut.Log(' Checking %s' % cver) |
151 | 172 |
152 # We should only be missing a 'release' tag for the first item. | 173 # We should only be missing a 'release' tag for the first item. |
153 if not node.rmin: | 174 if not node.rmin: |
154 node.Error('Missing release on overload of previous %s.' % | 175 node.Error('Missing release on overload of previous %s.' % |
155 cver.Location()) | 176 cver.Location()) |
156 return False | 177 return False |
157 | 178 |
158 # If the node has no max, then set it to this one | 179 # If the node has no max, then set it to this one |
159 if not cver.rmax: | 180 if not cver.rmax: |
(...skipping 13 matching lines...) Expand all Loading... |
173 # Otherwise, the previous max and current min should match | 194 # Otherwise, the previous max and current min should match |
174 # unless this is the unlikely case of something being only | 195 # unless this is the unlikely case of something being only |
175 # temporarily deprecated. | 196 # temporarily deprecated. |
176 if last and last.rmax != node.rmin: | 197 if last and last.rmax != node.rmin: |
177 node.Warn('Gap in release numbers.') | 198 node.Warn('Gap in release numbers.') |
178 | 199 |
179 # If we made it here, this new node must be the 'newest' | 200 # If we made it here, this new node must be the 'newest' |
180 # and does not overlap with anything previously added, so | 201 # and does not overlap with anything previously added, so |
181 # we can add it to the end of the list. | 202 # we can add it to the end of the list. |
182 if GetOption('release_debug'): InfoOut.Log('Done %s' % node) | 203 if GetOption('release_debug'): InfoOut.Log('Done %s' % node) |
183 self.nodes.append(node) | 204 self._nodes.append(node) |
184 return True | 205 return True |
185 | 206 |
186 # | 207 # |
187 # IDLReleaseMap | 208 # IDLReleaseMap |
188 # | 209 # |
189 # A release map, can map from an float interface release, to a global | 210 # A release map, can map from an float interface release, to a global |
190 # release string. | 211 # release string. |
191 # | 212 # |
192 class IDLReleaseMap(object): | 213 class IDLReleaseMap(object): |
193 def __init__(self, release_info): | 214 def __init__(self, release_info): |
(...skipping 10 matching lines...) Expand all Loading... |
204 | 225 |
205 def GetVersions(self): | 226 def GetVersions(self): |
206 return self.versions | 227 return self.versions |
207 | 228 |
208 def GetRelease(self, version): | 229 def GetRelease(self, version): |
209 return self.version_to_release.get(version, None) | 230 return self.version_to_release.get(version, None) |
210 | 231 |
211 def GetReleases(self): | 232 def GetReleases(self): |
212 return self.releases | 233 return self.releases |
213 | 234 |
| 235 def GetReleaseRange(self): |
| 236 return (self.releases[0], self.releases[-1]) |
| 237 |
| 238 def GetVersionRange(self): |
| 239 return (self.versions[0], self.version[-1]) |
| 240 |
214 # | 241 # |
215 # Test Code | 242 # Test Code |
216 # | 243 # |
217 def TestReleaseNode(): | 244 def TestReleaseNode(): |
218 FooXX = IDLRelease(None, None) | 245 FooXX = IDLRelease(None, None) |
219 Foo1X = IDLRelease('M14', None) | 246 Foo1X = IDLRelease('M14', None) |
220 Foo23 = IDLRelease('M15', 'M16') | 247 Foo23 = IDLRelease('M15', 'M16') |
221 | 248 |
222 assert FooXX.IsRelease('M13') | 249 assert FooXX.IsRelease('M13') |
223 assert FooXX.IsRelease('M14') | 250 assert FooXX.IsRelease('M14') |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 TestReleaseNode() | 341 TestReleaseNode() |
315 TestReleaseListWarning() | 342 TestReleaseListWarning() |
316 TestReleaseListError() | 343 TestReleaseListError() |
317 TestReleaseListOK() | 344 TestReleaseListOK() |
318 print "Passed" | 345 print "Passed" |
319 return 0 | 346 return 0 |
320 | 347 |
321 | 348 |
322 if __name__ == '__main__': | 349 if __name__ == '__main__': |
323 sys.exit(Main(sys.argv[1:])) | 350 sys.exit(Main(sys.argv[1:])) |
| 351 |
OLD | NEW |