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

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

Issue 1682783002: Dartium 45 roll (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: removed htmlcommon Created 4 years, 10 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
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 26 matching lines...) Expand all
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 self._all_dictionaries = {}
47 # TODO(terry): Hack to remember all typedef unions.
48 self._all_type_defs = {}
47 49
48 def Clone(self): 50 def Clone(self):
49 new_database = Database(self._root_dir) 51 new_database = Database(self._root_dir)
50 new_database._all_interfaces = copy.deepcopy(self._all_interfaces) 52 new_database._all_interfaces = copy.deepcopy(self._all_interfaces)
51 new_database._interfaces_to_delete = copy.deepcopy( 53 new_database._interfaces_to_delete = copy.deepcopy(
52 self._interfaces_to_delete) 54 self._interfaces_to_delete)
53 new_database._enums = copy.deepcopy(self._enums) 55 new_database._enums = copy.deepcopy(self._enums)
54 new_database._all_dictionaries = copy.deepcopy(self._all_dictionaries) 56 new_database._all_dictionaries = copy.deepcopy(self._all_dictionaries)
57 new_database._all_type_defs = copy.deepcopy(self._all_type_defs)
55 58
56 return new_database 59 return new_database
57 60
58 def Delete(self): 61 def Delete(self):
59 """Deletes the database by deleting its directory""" 62 """Deletes the database by deleting its directory"""
60 if os.path.exists(self._root_dir): 63 if os.path.exists(self._root_dir):
61 shutil.rmtree(self._root_dir) 64 shutil.rmtree(self._root_dir)
62 # reset in-memory constructs 65 # reset in-memory constructs
63 self._all_interfaces = {} 66 self._all_interfaces = {}
64 67
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 raise RuntimeError('Dictionary %s already exists' % dictionary_name) 278 raise RuntimeError('Dictionary %s already exists' % dictionary_name)
276 self._all_dictionaries[dictionary_name] = dictionary 279 self._all_dictionaries[dictionary_name] = dictionary
277 280
278 def GetDictionaries(self): 281 def GetDictionaries(self):
279 """Returns a list of all loaded dictionaries.""" 282 """Returns a list of all loaded dictionaries."""
280 res = [] 283 res = []
281 for _, dictionary in sorted(self._all_dictionaries.items()): 284 for _, dictionary in sorted(self._all_dictionaries.items()):
282 res.append(dictionary) 285 res.append(dictionary)
283 return res 286 return res
284 287
288 def HasTypeDef(self, type_def_name):
289 """Returns True if the typedef is in memory"""
290 return type_def_name in self._all_type_defs
291
292 def GetTypeDef(self, type_def_name):
293 """Returns an IDLTypeDef corresponding to the type_def_name
294 from memory.
295
296 Args:
297 type_def_name -- the name of the typedef.
298 """
299 if type_def_name not in self._all_type_defs:
300 raise RuntimeError('Typedef %s is not loaded' % type_def_name)
301 return self._all_type_defs[type_def_name]
302
303 def AddTypeDef(self, type_def):
304 """Add only a typedef that a unions they map to any (no type)."""
305 type_def_name = type_def.id
306 if type_def_name in self._all_type_defs:
307 raise RuntimeError('Typedef %s already exists' % type_def_name)
308 self._all_type_defs[type_def_name] = type_def
309 print ' Added typedef %s' % type_def_name
310
285 def TransitiveSecondaryParents(self, interface, propagate_event_target): 311 def TransitiveSecondaryParents(self, interface, propagate_event_target):
286 """Returns a list of all non-primary parents. 312 """Returns a list of all non-primary parents.
287 313
288 The list contains the interface objects for interfaces defined in the 314 The list contains the interface objects for interfaces defined in the
289 database, and the name for undefined interfaces. 315 database, and the name for undefined interfaces.
290 """ 316 """
291 def walk(parents): 317 def walk(parents):
292 for parent in parents: 318 for parent in parents:
293 parent_name = parent.type.id 319 parent_name = parent.type.id
294 if IsDartCollectionType(parent_name): 320 if IsDartCollectionType(parent_name):
295 result.append(parent_name) 321 result.append(parent_name)
296 continue 322 continue
297 if self.HasInterface(parent_name): 323 if self.HasInterface(parent_name):
298 parent_interface = self.GetInterface(parent_name) 324 parent_interface = self.GetInterface(parent_name)
299 result.append(parent_interface) 325 result.append(parent_interface)
300 walk(parent_interface.parents) 326 walk(parent_interface.parents)
301 327
302 result = [] 328 result = []
303 if interface.parents: 329 if interface.parents:
304 parent = interface.parents[0] 330 parent = interface.parents[0]
305 if (IsPureInterface(parent.type.id) or 331 if (IsPureInterface(parent.type.id) or
306 (propagate_event_target and parent.type.id == 'EventTarget')): 332 (propagate_event_target and parent.type.id == 'EventTarget')):
307 walk(interface.parents) 333 walk(interface.parents)
308 else: 334 else:
309 walk(interface.parents[1:]) 335 walk(interface.parents[1:])
310 return result 336 return result
311 337
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698