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

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

Issue 952133004: Changes to support roll 39 IDLs (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Cleanup Created 5 years, 9 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 | « tools/dom/scripts/dartmetadata.py ('k') | tools/dom/scripts/databasebuilder.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) 2011, the Dart project authors. Please see the AUTHORS file 2 # Copyright (c) 2011, 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 """Module to manage IDL files.""" 6 """Module to manage IDL files."""
7 7
8 import copy 8 import copy
9 import pickle 9 import pickle
10 import logging 10 import logging
(...skipping 25 matching lines...) Expand all
36 root_dir -- a directory. If directory does not exist, it will 36 root_dir -- a directory. If directory does not exist, it will
37 be created. 37 be created.
38 """ 38 """
39 self._root_dir = root_dir 39 self._root_dir = root_dir
40 if not os.path.exists(root_dir): 40 if not os.path.exists(root_dir):
41 _logger.debug('creating root directory %s' % root_dir) 41 _logger.debug('creating root directory %s' % root_dir)
42 os.makedirs(root_dir) 42 os.makedirs(root_dir)
43 self._all_interfaces = {} 43 self._all_interfaces = {}
44 self._interfaces_to_delete = [] 44 self._interfaces_to_delete = []
45 self._enums = {} 45 self._enums = {}
46 self._all_dictionaries = {}
46 47
47 def Clone(self): 48 def Clone(self):
48 new_database = Database(self._root_dir) 49 new_database = Database(self._root_dir)
49 new_database._all_interfaces = copy.deepcopy(self._all_interfaces) 50 new_database._all_interfaces = copy.deepcopy(self._all_interfaces)
50 new_database._interfaces_to_delete = copy.deepcopy( 51 new_database._interfaces_to_delete = copy.deepcopy(
51 self._interfaces_to_delete) 52 self._interfaces_to_delete)
52 new_database._enums = copy.deepcopy(self._enums) 53 new_database._enums = copy.deepcopy(self._enums)
54 new_database._all_dictionaries = copy.deepcopy(self._all_dictionaries)
55
53 return new_database 56 return new_database
54 57
55 def Delete(self): 58 def Delete(self):
56 """Deletes the database by deleting its directory""" 59 """Deletes the database by deleting its directory"""
57 if os.path.exists(self._root_dir): 60 if os.path.exists(self._root_dir):
58 shutil.rmtree(self._root_dir) 61 shutil.rmtree(self._root_dir)
59 # reset in-memory constructs 62 # reset in-memory constructs
60 self._all_interfaces = {} 63 self._all_interfaces = {}
61 64
62 def _ScanForInterfaces(self): 65 def _ScanForInterfaces(self):
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 241
239 def HasEnum(self, enum_name): 242 def HasEnum(self, enum_name):
240 return enum_name in self._enums 243 return enum_name in self._enums
241 244
242 def GetEnum(self, enum_name): 245 def GetEnum(self, enum_name):
243 return self._enums[enum_name] 246 return self._enums[enum_name]
244 247
245 def AddEnum(self, enum): 248 def AddEnum(self, enum):
246 self._enums[enum.id] = enum 249 self._enums[enum.id] = enum
247 250
251 def HasDictionary(self, dictionary_name):
252 """Returns True if the dictionary is in memory"""
253 return dictionary_name in self._all_dictionaries
254
255 def GetDictionary(self, dictionary_name):
256 """Returns an IDLDictionary corresponding to the dictionary_name
257 from memory.
258
259 Args:
260 dictionary_name -- the name of the dictionary.
261 """
262 if dictionary_name not in self._all_dictionaries:
263 raise RuntimeError('Dictionary %s is not loaded' % dictionary_name)
264 return self._all_dictionaries[dictionary_name]
265
266 def AddDictionary(self, dictionary):
267 """Returns an IDLDictionary corresponding to the dictionary_name
268 from memory.
269
270 Args:
271 dictionary -- the name of the dictionary.
272 """
273 dictionary_name = dictionary.id
274 if dictionary_name in self._all_dictionaries:
275 raise RuntimeError('Dictionary %s already exists' % dictionary_name)
276 self._all_dictionaries[dictionary_name] = dictionary
277
248 def TransitiveSecondaryParents(self, interface, propagate_event_target): 278 def TransitiveSecondaryParents(self, interface, propagate_event_target):
249 """Returns a list of all non-primary parents. 279 """Returns a list of all non-primary parents.
250 280
251 The list contains the interface objects for interfaces defined in the 281 The list contains the interface objects for interfaces defined in the
252 database, and the name for undefined interfaces. 282 database, and the name for undefined interfaces.
253 """ 283 """
254 def walk(parents): 284 def walk(parents):
255 for parent in parents: 285 for parent in parents:
256 parent_name = parent.type.id 286 parent_name = parent.type.id
257 if IsDartCollectionType(parent_name): 287 if IsDartCollectionType(parent_name):
258 result.append(parent_name) 288 result.append(parent_name)
259 continue 289 continue
260 if self.HasInterface(parent_name): 290 if self.HasInterface(parent_name):
261 parent_interface = self.GetInterface(parent_name) 291 parent_interface = self.GetInterface(parent_name)
262 result.append(parent_interface) 292 result.append(parent_interface)
263 walk(parent_interface.parents) 293 walk(parent_interface.parents)
264 294
265 result = [] 295 result = []
266 if interface.parents: 296 if interface.parents:
267 parent = interface.parents[0] 297 parent = interface.parents[0]
268 if (IsPureInterface(parent.type.id) or 298 if (IsPureInterface(parent.type.id) or
269 (propagate_event_target and parent.type.id == 'EventTarget')): 299 (propagate_event_target and parent.type.id == 'EventTarget')):
270 walk(interface.parents) 300 walk(interface.parents)
271 else: 301 else:
272 walk(interface.parents[1:]) 302 walk(interface.parents[1:])
273 return result 303 return result
274 304
OLDNEW
« no previous file with comments | « tools/dom/scripts/dartmetadata.py ('k') | tools/dom/scripts/databasebuilder.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698