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

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

Issue 10704100: Do not split attributes on getters and setters in databasebuilder. (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
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 import copy 6 import copy
7 import database 7 import database
8 import idlparser 8 import idlparser
9 import logging 9 import logging
10 import os 10 import os
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 for type_node in idl_file.all(IDLType): 96 for type_node in idl_file.all(IDLType):
97 while type_node.id in type_def_map: 97 while type_node.id in type_def_map:
98 type_node.id = type_def_map[type_node.id] 98 type_node.id = type_def_map[type_node.id]
99 99
100 def _strip_ext_attributes(self, idl_file): 100 def _strip_ext_attributes(self, idl_file):
101 """Strips unuseful extended attributes.""" 101 """Strips unuseful extended attributes."""
102 for ext_attrs in idl_file.all(IDLExtAttrs): 102 for ext_attrs in idl_file.all(IDLExtAttrs):
103 # TODO: Decide which attributes are uninteresting. 103 # TODO: Decide which attributes are uninteresting.
104 pass 104 pass
105 105
106 def _split_declarations(self, interface, optional_argument_whitelist):
107 """Splits read-write attributes and operations with optional
108 arguments into multiple declarations"""
109
110 # split attributes into setters and getters
111 new_attributes = []
112 for attribute in interface.attributes:
113 if attribute.is_fc_getter or attribute.is_fc_setter:
114 new_attributes.append(attribute)
115 continue
116 getter_attr = copy.deepcopy(attribute)
117 getter_attr.is_fc_getter = True
118 new_attributes.append(getter_attr)
119 if not attribute.is_read_only:
120 setter_attr = copy.deepcopy(attribute)
121 setter_attr.is_fc_setter = True
122 new_attributes.append(setter_attr)
123 interface.attributes = new_attributes
124
125 # Add 'Optional' attribute to whitelisted arguments.
126 for op in interface.operations:
127 for argument in op.arguments:
128 in_optional_whitelist = (interface.id, op.id, argument.id) in optional_a rgument_whitelist
129 if in_optional_whitelist:
130 argument.ext_attrs['Optional'] = None
131
132 def _rename_types(self, idl_file, import_options): 106 def _rename_types(self, idl_file, import_options):
133 """Rename interface and type names with names provided in the 107 """Rename interface and type names with names provided in the
134 options. Also clears scopes from scoped names""" 108 options. Also clears scopes from scoped names"""
135 109
136 def rename(name): 110 def rename(name):
137 name_parts = name.split('::') 111 name_parts = name.split('::')
138 name = name_parts[-1] 112 name = name_parts[-1]
139 if name in import_options.type_rename_map: 113 if name in import_options.type_rename_map:
140 name = import_options.type_rename_map[name] 114 name = import_options.type_rename_map[name]
141 return name 115 return name
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 res = ['op'] 171 res = ['op']
198 for special in node.specials: 172 for special in node.specials:
199 res.append(special) 173 res.append(special)
200 if node.id is not None: 174 if node.id is not None:
201 res.append(node.id) 175 res.append(node.id)
202 for arg in node.arguments: 176 for arg in node.arguments:
203 res.append(self._sign(arg.type)) 177 res.append(self._sign(arg.type))
204 res.append(self._sign(node.type)) 178 res.append(self._sign(node.type))
205 elif isinstance(node, IDLAttribute): 179 elif isinstance(node, IDLAttribute):
206 res = [] 180 res = []
207 if node.is_fc_getter: 181 if node.is_read_only:
208 res.append('getter') 182 res.append('readonly')
209 elif node.is_fc_setter:
210 res.append('setter')
211 res.append(node.id) 183 res.append(node.id)
212 res.append(self._sign(node.type)) 184 res.append(self._sign(node.type))
213 elif isinstance(node, IDLConstant): 185 elif isinstance(node, IDLConstant):
214 res = [] 186 res = []
215 res.append('const') 187 res.append('const')
216 res.append(node.id) 188 res.append(node.id)
217 res.append(node.value) 189 res.append(node.value)
218 res.append(self._sign(node.type)) 190 res.append(self._sign(node.type))
219 else: 191 else:
220 raise TypeError("Can't sign input of type %s" % type(node)) 192 raise TypeError("Can't sign input of type %s" % type(node))
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 if source: 373 if source:
402 parent.annotations[source] = IDLAnnotation( 374 parent.annotations[source] = IDLAnnotation(
403 import_options.source_attributes) 375 import_options.source_attributes)
404 interface.parents.append(parent) 376 interface.parents.append(parent)
405 377
406 def merge_imported_interfaces(self, optional_argument_whitelist): 378 def merge_imported_interfaces(self, optional_argument_whitelist):
407 """Merges all imported interfaces and loads them into the DB.""" 379 """Merges all imported interfaces and loads them into the DB."""
408 380
409 # Step 1: Pre process imported interfaces 381 # Step 1: Pre process imported interfaces
410 for interface, module_name, import_options in self._imported_interfaces: 382 for interface, module_name, import_options in self._imported_interfaces:
411 self._split_declarations(interface, optional_argument_whitelist) 383 # Add 'Optional' attribute to whitelisted arguments.
384 for op in interface.operations:
385 for argument in op.arguments:
386 in_optional_whitelist = (interface.id, op.id, argument.id) in optional _argument_whitelist
387 if in_optional_whitelist:
388 argument.ext_attrs['Optional'] = None
412 self._annotate(interface, module_name, import_options) 389 self._annotate(interface, module_name, import_options)
413 390
414 # Step 2: Add all new interfaces and merge overlapping ones 391 # Step 2: Add all new interfaces and merge overlapping ones
415 for interface, module_name, import_options in self._imported_interfaces: 392 for interface, module_name, import_options in self._imported_interfaces:
416 if not interface.is_supplemental: 393 if not interface.is_supplemental:
417 if self._database.HasInterface(interface.id): 394 if self._database.HasInterface(interface.id):
418 old_interface = self._database.GetInterface(interface.id) 395 old_interface = self._database.GetInterface(interface.id)
419 self._merge_interfaces(old_interface, interface, import_options) 396 self._merge_interfaces(old_interface, interface, import_options)
420 else: 397 else:
421 if import_options.add_new_interfaces: 398 if import_options.add_new_interfaces:
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 del annotation[name] 536 del annotation[name]
560 537
561 map(normalize, interface.parents) 538 map(normalize, interface.parents)
562 map(normalize, interface.constants) 539 map(normalize, interface.constants)
563 map(normalize, interface.attributes) 540 map(normalize, interface.attributes)
564 map(normalize, interface.operations) 541 map(normalize, interface.operations)
565 542
566 def fetch_constructor_data(self, options): 543 def fetch_constructor_data(self, options):
567 window_interface = self._database.GetInterface('Window') 544 window_interface = self._database.GetInterface('Window')
568 for attr in window_interface.attributes: 545 for attr in window_interface.attributes:
569 if not attr.is_fc_getter:
570 continue
571 type = attr.type.id 546 type = attr.type.id
572 if not type.endswith('Constructor'): 547 if not type.endswith('Constructor'):
573 continue 548 continue
574 type = re.sub('(Constructor)+$', '', type) 549 type = re.sub('(Constructor)+$', '', type)
575 # TODO(antonm): Ideally we'd like to have pristine copy of WebKit IDLs and fetch 550 # TODO(antonm): Ideally we'd like to have pristine copy of WebKit IDLs and fetch
576 # this information directly from it. Unfortunately right now database is massaged 551 # this information directly from it. Unfortunately right now database is massaged
577 # a lot so it's difficult to maintain necessary information on DOMWindow i tself. 552 # a lot so it's difficult to maintain necessary information on DOMWindow i tself.
578 interface = self._database.GetInterface(options.type_rename_map.get(type, type)) 553 interface = self._database.GetInterface(options.type_rename_map.get(type, type))
579 if 'V8EnabledPerContext' in attr.ext_attrs: 554 if 'V8EnabledPerContext' in attr.ext_attrs:
580 interface.ext_attrs['synthesizedV8EnabledPerContext'] = \ 555 interface.ext_attrs['synthesizedV8EnabledPerContext'] = \
581 attr.ext_attrs['V8EnabledPerContext'] 556 attr.ext_attrs['V8EnabledPerContext']
582 if 'V8EnabledAtRuntime' in attr.ext_attrs: 557 if 'V8EnabledAtRuntime' in attr.ext_attrs:
583 interface.ext_attrs['synthesizedV8EnabledAtRuntime'] = \ 558 interface.ext_attrs['synthesizedV8EnabledAtRuntime'] = \
584 attr.ext_attrs['V8EnabledAtRuntime'] or attr.id 559 attr.ext_attrs['V8EnabledAtRuntime'] or attr.id
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698