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 """Nodes for PPAPI IDL AST""" | 6 """Nodes for PPAPI IDL AST""" |
7 | 7 |
8 # | 8 # |
9 # IDL Node | 9 # IDL Node |
10 # | 10 # |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 56 |
57 show_versions = False | 57 show_versions = False |
58 def __init__(self, cls, filename, lineno, pos, children=None): | 58 def __init__(self, cls, filename, lineno, pos, children=None): |
59 # Initialize with no starting or ending Version | 59 # Initialize with no starting or ending Version |
60 IDLRelease.__init__(self, None, None) | 60 IDLRelease.__init__(self, None, None) |
61 | 61 |
62 self.cls = cls | 62 self.cls = cls |
63 self.lineno = lineno | 63 self.lineno = lineno |
64 self.pos = pos | 64 self.pos = pos |
65 self.filename = filename | 65 self.filename = filename |
| 66 self.filenode = None |
66 self.hashes = {} | 67 self.hashes = {} |
67 self.deps = {} | 68 self.deps = {} |
68 self.errors = 0 | 69 self.errors = 0 |
69 self.namespace = None | 70 self.namespace = None |
70 self.typelist = None | 71 self.typelist = None |
71 self.parent = None | 72 self.parent = None |
72 self.property_node = IDLPropertyNode() | 73 self.property_node = IDLPropertyNode() |
| 74 |
| 75 # A list of unique releases for this node |
| 76 self.releases = None |
| 77 |
| 78 # A map from any release, to the first unique release |
| 79 self.first_release = None |
| 80 |
73 # self.children is a list of children ordered as defined | 81 # self.children is a list of children ordered as defined |
74 self.children = [] | 82 self.children = [] |
75 # Process the passed in list of children, placing ExtAttributes into the | 83 # Process the passed in list of children, placing ExtAttributes into the |
76 # property dictionary, and nodes into the local child list in order. In | 84 # property dictionary, and nodes into the local child list in order. In |
77 # addition, add nodes to the namespace if the class is in the NamedSet. | 85 # addition, add nodes to the namespace if the class is in the NamedSet. |
78 if not children: children = [] | 86 if not children: children = [] |
79 for child in children: | 87 for child in children: |
80 if child.cls == 'ExtAttribute': | 88 if child.cls == 'ExtAttribute': |
81 self.SetProperty(child.name, child.value) | 89 self.SetProperty(child.name, child.value) |
82 else: | 90 else: |
(...skipping 14 matching lines...) Expand all Loading... |
97 | 105 |
98 # Return file and line number for where node was defined | 106 # Return file and line number for where node was defined |
99 def Location(self): | 107 def Location(self): |
100 return '%s(%d)' % (self.filename, self.lineno) | 108 return '%s(%d)' % (self.filename, self.lineno) |
101 | 109 |
102 # Log an error for this object | 110 # Log an error for this object |
103 def Error(self, msg): | 111 def Error(self, msg): |
104 self.errors += 1 | 112 self.errors += 1 |
105 ErrOut.LogLine(self.filename, self.lineno, 0, ' %s %s' % | 113 ErrOut.LogLine(self.filename, self.lineno, 0, ' %s %s' % |
106 (str(self), msg)) | 114 (str(self), msg)) |
107 if self.lineno == 46: raise Exception("huh?") | 115 if self.filenode: |
| 116 errcnt = self.filenode.GetProperty('ERRORS', 0) |
| 117 self.filenode.SetProperty('ERRORS', errcnt + 1) |
108 | 118 |
109 # Log a warning for this object | 119 # Log a warning for this object |
110 def Warning(self, msg): | 120 def Warning(self, msg): |
111 WarnOut.LogLine(self.filename, self.lineno, 0, ' %s %s' % | 121 WarnOut.LogLine(self.filename, self.lineno, 0, ' %s %s' % |
112 (str(self), msg)) | 122 (str(self), msg)) |
113 | 123 |
114 def GetName(self): | 124 def GetName(self): |
115 return self.GetProperty('NAME') | 125 return self.GetProperty('NAME') |
116 | 126 |
117 def GetNameVersion(self): | 127 def GetNameVersion(self): |
118 name = self.GetProperty('NAME', default='') | 128 name = self.GetProperty('NAME', default='') |
119 ver = IDLRelease.__str__(self) | 129 ver = IDLRelease.__str__(self) |
120 return '%s%s' % (name, ver) | 130 return '%s%s' % (name, ver) |
121 | 131 |
122 # Dump this object and its children | 132 # Dump this object and its children |
123 def Dump(self, depth=0, comments=False, out=sys.stdout): | 133 def Dump(self, depth=0, comments=False, out=sys.stdout): |
124 if self.cls in ['Comment', 'Copyright']: | 134 if self.cls in ['Comment', 'Copyright']: |
125 is_comment = True | 135 is_comment = True |
126 else: | 136 else: |
127 is_comment = False | 137 is_comment = False |
128 | 138 |
129 # Skip this node if it's a comment, and we are not printing comments | 139 # Skip this node if it's a comment, and we are not printing comments |
130 if not comments and is_comment: return | 140 if not comments and is_comment: return |
131 | 141 |
132 tab = ''.rjust(depth * 2) | 142 tab = ''.rjust(depth * 2) |
133 | |
134 if is_comment: | 143 if is_comment: |
135 out.write('%sComment\n' % tab) | 144 out.write('%sComment\n' % tab) |
136 for line in self.GetName().split('\n'): | 145 for line in self.GetName().split('\n'): |
137 out.write('%s "%s"\n' % (tab, line)) | 146 out.write('%s "%s"\n' % (tab, line)) |
138 else: | 147 else: |
139 out.write('%s%s\n' % (tab, self)) | 148 ver = IDLRelease.__str__(self) |
| 149 if self.releases: |
| 150 release_list = ': ' + ' '.join(self.releases) |
| 151 else: |
| 152 release_list = ': undefined' |
| 153 out.write('%s%s%s%s\n' % (tab, self, ver, release_list)) |
| 154 if self.typelist: |
| 155 out.write('%s Typelist: %s\n' % (tab, self.typelist.GetReleases()[0])) |
140 properties = self.property_node.GetPropertyList() | 156 properties = self.property_node.GetPropertyList() |
141 if properties: | 157 if properties: |
142 out.write('%s Properties\n' % tab) | 158 out.write('%s Properties\n' % tab) |
143 for p in properties: | 159 for p in properties: |
144 if is_comment and p == 'NAME': | 160 if is_comment and p == 'NAME': |
145 # Skip printing the name for comments, since we printed above already | 161 # Skip printing the name for comments, since we printed above already |
146 continue | 162 continue |
147 out.write('%s %s : %s\n' % (tab, p, self.GetProperty(p))) | 163 out.write('%s %s : %s\n' % (tab, p, self.GetProperty(p))) |
148 for child in self.children: | 164 for child in self.children: |
149 child.Dump(depth+1, comments=comments, out=out) | 165 child.Dump(depth+1, comments=comments, out=out) |
150 | 166 |
151 # | 167 # |
152 # Search related functions | 168 # Search related functions |
153 # | 169 # |
154 | |
155 # Check if node is of a given type | 170 # Check if node is of a given type |
156 def IsA(self, *typelist): | 171 def IsA(self, *typelist): |
157 if self.cls in typelist: return True | 172 if self.cls in typelist: return True |
158 return False | 173 return False |
159 | 174 |
160 # Get a list of objects for this key | 175 # Get a list of objects for this key |
161 def GetListOf(self, *keys): | 176 def GetListOf(self, *keys): |
162 out = [] | 177 out = [] |
163 for child in self.children: | 178 for child in self.children: |
164 if child.cls in keys: out.append(child) | 179 if child.cls in keys: out.append(child) |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 if typeref: deps |= typeref.GetDeps(release) | 255 if typeref: deps |= typeref.GetDeps(release) |
241 self.deps[release] = deps | 256 self.deps[release] = deps |
242 return deps | 257 return deps |
243 | 258 |
244 def GetVersion(self, release): | 259 def GetVersion(self, release): |
245 filenode = self.GetProperty('FILE') | 260 filenode = self.GetProperty('FILE') |
246 if not filenode: | 261 if not filenode: |
247 return None | 262 return None |
248 return filenode.release_map.GetVersion(release) | 263 return filenode.release_map.GetVersion(release) |
249 | 264 |
| 265 def GetUniqueReleases(self, releases): |
| 266 my_min, my_max = self.GetMinMax(releases) |
| 267 if my_min > releases[-1] or my_max < releases[0]: |
| 268 return [] |
| 269 |
| 270 out = set() |
| 271 for rel in releases: |
| 272 remapped = self.first_release[rel] |
| 273 if not remapped: continue |
| 274 if remapped < releases[0]: |
| 275 remapped = releases[0] |
| 276 out |= set([remapped]) |
| 277 out = sorted(out) |
| 278 return out |
| 279 |
| 280 |
250 def GetRelease(self, version): | 281 def GetRelease(self, version): |
251 filenode = self.GetProperty('FILE') | 282 filenode = self.GetProperty('FILE') |
252 if not filenode: | 283 if not filenode: |
253 return None | 284 return None |
254 return filenode.release_map.GetRelease(version) | 285 return filenode.release_map.GetRelease(version) |
255 | 286 |
256 def GetUniqueReleases(self, releases): | 287 def _GetReleases(self, releases): |
257 # Given a list of global release, return a subset of releases | 288 if not self.releases: |
258 # for this object that change. | 289 my_min, my_max = self.GetMinMax(releases) |
259 last_hash = None | 290 my_releases = [my_min] |
260 builds = [] | 291 if my_max != releases[-1]: |
261 filenode = self.GetProperty('FILE') | 292 my_releases.append(my_max) |
262 file_releases = filenode.release_map.GetReleases() | 293 my_releases = set(my_releases) |
| 294 for child in self.GetChildren(): |
| 295 if child.IsA('Copyright', 'Comment', 'Label'): |
| 296 continue |
| 297 my_releases |= child.GetReleases(releases) |
| 298 self.releases = my_releases |
| 299 return self.releases |
263 | 300 |
264 # Generate a set of unique releases for this object based on versions | |
265 # available in this file's release labels. | |
266 for rel in file_releases: | |
267 # Check if this object is valid for the release in question. | |
268 if not self.IsRelease(rel): continue | |
269 # Only add it if the hash is different. | |
270 cur_hash = self.GetHash(rel) | |
271 if last_hash != cur_hash: | |
272 builds.append(rel) | |
273 last_hash = cur_hash | |
274 | 301 |
275 # Remap the requested releases to releases in the unique build set to | 302 def _GetReleaseList(self, releases): |
276 # use first available release names and remove duplicates. | 303 if not self.releases: |
277 # UNIQUE VERSION: 'M13', 'M14', 'M17' | 304 # If we are unversionable, then return first available release |
278 # REQUESTED RANGE: 'M15', 'M16', 'M17', 'M18' | 305 if self.IsA('Comment', 'Copyright', 'Label'): |
279 # REMAP RESULT: 'M14', 'M17' | 306 self.releases = [] |
280 out_list = [] | 307 return self.releases |
281 build_len = len(builds) | |
282 build_index = 0 | |
283 rel_len = len(releases) | |
284 rel_index = 0 | |
285 | 308 |
286 while build_index < build_len and rel_index < rel_len: | 309 # Generate the first and if deprecated within this subset, the |
287 while rel_index < rel_len and releases[rel_index] < builds[build_index]: | 310 # last release for this node |
288 rel_index = rel_index + 1 | 311 my_min, my_max = self.GetMinMax(releases) |
289 | 312 |
290 # If we've reached the end of the request list, we must be done | 313 if my_max != releases[-1]: |
291 if rel_index == rel_len: | 314 my_releases = set([my_min, my_max]) |
292 break | 315 else: |
| 316 my_releases = set([my_min]) |
293 | 317 |
294 # Check this current request | 318 # Files inherit all there releases from items in the file |
295 cur = releases[rel_index] | 319 if self.IsA('AST', 'File'): |
296 while build_index < build_len and cur >= builds[build_index]: | 320 my_releases = set() |
297 build_index = build_index + 1 | |
298 | 321 |
299 out_list.append(builds[build_index - 1]) | 322 child_releases = set() |
300 rel_index = rel_index + 1 | 323 for child in self.children: |
301 return out_list | 324 child_releases |= set(child._GetReleaseList(releases)) |
| 325 |
| 326 type_releases = set() |
| 327 if self.typelist: |
| 328 type_list = self.typelist.GetReleases() |
| 329 for typenode in type_list: |
| 330 type_releases |= set(typenode._GetReleaseList(releases)) |
| 331 |
| 332 type_release_list = sorted(type_releases) |
| 333 if my_min < type_release_list[0]: |
| 334 type_node = type_list[0] |
| 335 self.Error('requires %s in %s which is undefined at %s.' % ( |
| 336 type_node, type_node.filename, my_min)) |
| 337 |
| 338 for rel in child_releases: |
| 339 if rel >= my_min and rel <= my_max: |
| 340 my_releases |= set([rel]) |
| 341 |
| 342 self.releases = sorted(my_releases) |
| 343 |
| 344 return self.releases |
| 345 |
| 346 def GetReleaseList(self): |
| 347 return self.releases |
| 348 |
| 349 def BuildReleaseMap(self, releases): |
| 350 unique_list = self._GetReleaseList(releases) |
| 351 my_min, my_max = self.GetMinMax(releases) |
| 352 |
| 353 self.first_release = {} |
| 354 last_rel = None |
| 355 for rel in releases: |
| 356 if rel in unique_list: |
| 357 last_rel = rel |
| 358 self.first_release[rel] = last_rel |
| 359 if rel == my_max: |
| 360 last_rel = None |
302 | 361 |
303 def SetProperty(self, name, val): | 362 def SetProperty(self, name, val): |
304 self.property_node.SetProperty(name, val) | 363 self.property_node.SetProperty(name, val) |
305 | 364 |
306 def GetProperty(self, name, default=None): | 365 def GetProperty(self, name, default=None): |
307 return self.property_node.GetProperty(name, default) | 366 return self.property_node.GetProperty(name, default) |
308 | 367 |
309 def Traverse(self, data, func): | 368 def Traverse(self, data, func): |
310 func(self, data) | 369 func(self, data) |
311 for child in self.children: | 370 for child in self.children: |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 errors = StringTest() | 445 errors = StringTest() |
387 errors += ChildTest() | 446 errors += ChildTest() |
388 | 447 |
389 if errors: | 448 if errors: |
390 ErrOut.Log('IDLNode failed with %d errors.' % errors) | 449 ErrOut.Log('IDLNode failed with %d errors.' % errors) |
391 return -1 | 450 return -1 |
392 return 0 | 451 return 0 |
393 | 452 |
394 if __name__ == '__main__': | 453 if __name__ == '__main__': |
395 sys.exit(Main()) | 454 sys.exit(Main()) |
| 455 |
OLD | NEW |