| OLD | NEW |
| 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 multiprocessing | 10 import multiprocessing |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 _MODULE_ANNOTATION_ATTR_NAME = 'module' | 26 _MODULE_ANNOTATION_ATTR_NAME = 'module' |
| 27 | 27 |
| 28 | 28 |
| 29 class DatabaseBuilderOptions(object): | 29 class DatabaseBuilderOptions(object): |
| 30 """Used in specifying options when importing new interfaces""" | 30 """Used in specifying options when importing new interfaces""" |
| 31 | 31 |
| 32 def __init__(self, | 32 def __init__(self, |
| 33 idl_syntax=idlparser.WEBIDL_SYNTAX, | 33 idl_syntax=idlparser.WEBIDL_SYNTAX, |
| 34 idl_defines=[], | 34 idl_defines=[], |
| 35 source=None, source_attributes={}, | 35 source=None, source_attributes={}, |
| 36 type_rename_map={}, | |
| 37 rename_operation_arguments_on_merge=False, | 36 rename_operation_arguments_on_merge=False, |
| 38 add_new_interfaces=True, | 37 add_new_interfaces=True, |
| 39 obsolete_old_declarations=False): | 38 obsolete_old_declarations=False): |
| 40 """Constructor. | 39 """Constructor. |
| 41 Args: | 40 Args: |
| 42 idl_syntax -- the syntax of the IDL file that is imported. | 41 idl_syntax -- the syntax of the IDL file that is imported. |
| 43 idl_defines -- list of definitions for the idl gcc pre-processor | 42 idl_defines -- list of definitions for the idl gcc pre-processor |
| 44 source -- the origin of the IDL file, used for annotating the | 43 source -- the origin of the IDL file, used for annotating the |
| 45 database. | 44 database. |
| 46 source_attributes -- this map of attributes is used as | 45 source_attributes -- this map of attributes is used as |
| 47 annotation attributes. | 46 annotation attributes. |
| 48 rename_operation_arguments_on_merge -- if True, will rename | 47 rename_operation_arguments_on_merge -- if True, will rename |
| 49 operation arguments when merging using the new name rather | 48 operation arguments when merging using the new name rather |
| 50 than the old. | 49 than the old. |
| 51 add_new_interfaces -- when False, if an interface is a new | 50 add_new_interfaces -- when False, if an interface is a new |
| 52 addition, it will be ignored. | 51 addition, it will be ignored. |
| 53 obsolete_old_declarations -- when True, if a declaration | 52 obsolete_old_declarations -- when True, if a declaration |
| 54 from a certain source is not re-declared, it will be removed. | 53 from a certain source is not re-declared, it will be removed. |
| 55 """ | 54 """ |
| 56 self.source = source | 55 self.source = source |
| 57 self.source_attributes = source_attributes | 56 self.source_attributes = source_attributes |
| 58 self.idl_syntax = idl_syntax | 57 self.idl_syntax = idl_syntax |
| 59 self.idl_defines = idl_defines | 58 self.idl_defines = idl_defines |
| 60 self.type_rename_map = type_rename_map | |
| 61 self.rename_operation_arguments_on_merge = \ | 59 self.rename_operation_arguments_on_merge = \ |
| 62 rename_operation_arguments_on_merge | 60 rename_operation_arguments_on_merge |
| 63 self.add_new_interfaces = add_new_interfaces | 61 self.add_new_interfaces = add_new_interfaces |
| 64 self.obsolete_old_declarations = obsolete_old_declarations | 62 self.obsolete_old_declarations = obsolete_old_declarations |
| 65 | 63 |
| 66 | 64 |
| 67 def _load_idl_file(file_name, import_options, result_queue): | 65 def _load_idl_file(file_name, import_options, result_queue): |
| 68 """Loads an IDL file into memory""" | 66 """Loads an IDL file into memory""" |
| 69 idl_parser = idlparser.IDLParser(import_options.idl_syntax) | 67 idl_parser = idlparser.IDLParser(import_options.idl_syntax) |
| 70 | 68 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 def _strip_ext_attributes(self, idl_file): | 108 def _strip_ext_attributes(self, idl_file): |
| 111 """Strips unuseful extended attributes.""" | 109 """Strips unuseful extended attributes.""" |
| 112 for ext_attrs in idl_file.all(IDLExtAttrs): | 110 for ext_attrs in idl_file.all(IDLExtAttrs): |
| 113 # TODO: Decide which attributes are uninteresting. | 111 # TODO: Decide which attributes are uninteresting. |
| 114 pass | 112 pass |
| 115 | 113 |
| 116 def _rename_types(self, idl_file, import_options): | 114 def _rename_types(self, idl_file, import_options): |
| 117 """Rename interface and type names with names provided in the | 115 """Rename interface and type names with names provided in the |
| 118 options. Also clears scopes from scoped names""" | 116 options. Also clears scopes from scoped names""" |
| 119 | 117 |
| 120 def rename(name): | 118 strip_modules = lambda name: name.split('::')[-1] |
| 121 name_parts = name.split('::') | |
| 122 name = name_parts[-1] | |
| 123 if name in import_options.type_rename_map: | |
| 124 name = import_options.type_rename_map[name] | |
| 125 return name | |
| 126 | 119 |
| 127 def rename_node(idl_node): | 120 def rename_node(idl_node): |
| 128 idl_node.reset_id(rename(idl_node.id)) | 121 idl_node.reset_id(strip_modules(idl_node.id)) |
| 129 | 122 |
| 130 def rename_ext_attrs(ext_attrs_node): | 123 def rename_ext_attrs(ext_attrs_node): |
| 131 for type_valued_attribute_name in ['Supplemental']: | 124 for type_valued_attribute_name in ['Supplemental']: |
| 132 if type_valued_attribute_name in ext_attrs_node: | 125 if type_valued_attribute_name in ext_attrs_node: |
| 133 value = ext_attrs_node[type_valued_attribute_name] | 126 value = ext_attrs_node[type_valued_attribute_name] |
| 134 if isinstance(value, str): | 127 if isinstance(value, str): |
| 135 ext_attrs_node[type_valued_attribute_name] = rename(value) | 128 ext_attrs_node[type_valued_attribute_name] = strip_modules(value) |
| 136 | 129 |
| 137 map(rename_node, idl_file.all(IDLInterface)) | 130 map(rename_node, idl_file.all(IDLInterface)) |
| 138 map(rename_node, idl_file.all(IDLType)) | 131 map(rename_node, idl_file.all(IDLType)) |
| 139 map(rename_ext_attrs, idl_file.all(IDLExtAttrs)) | 132 map(rename_ext_attrs, idl_file.all(IDLExtAttrs)) |
| 140 | 133 |
| 141 def _annotate(self, interface, module_name, import_options): | 134 def _annotate(self, interface, module_name, import_options): |
| 142 """Adds @ annotations based on the source and source_attributes | 135 """Adds @ annotations based on the source and source_attributes |
| 143 members of import_options.""" | 136 members of import_options.""" |
| 144 | 137 |
| 145 source = import_options.source | 138 source = import_options.source |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 if (name in top_level_annotation | 556 if (name in top_level_annotation |
| 564 and value == top_level_annotation[name]): | 557 and value == top_level_annotation[name]): |
| 565 del annotation[name] | 558 del annotation[name] |
| 566 | 559 |
| 567 map(normalize, interface.parents) | 560 map(normalize, interface.parents) |
| 568 map(normalize, interface.constants) | 561 map(normalize, interface.constants) |
| 569 map(normalize, interface.attributes) | 562 map(normalize, interface.attributes) |
| 570 map(normalize, interface.operations) | 563 map(normalize, interface.operations) |
| 571 | 564 |
| 572 def fetch_constructor_data(self, options): | 565 def fetch_constructor_data(self, options): |
| 573 window_interface = self._database.GetInterface('Window') | 566 window_interface = self._database.GetInterface('DOMWindow') |
| 574 for attr in window_interface.attributes: | 567 for attr in window_interface.attributes: |
| 575 type = attr.type.id | 568 type = attr.type.id |
| 576 if not type.endswith('Constructor'): | 569 if not type.endswith('Constructor'): |
| 577 continue | 570 continue |
| 578 type = re.sub('(Constructor)+$', '', type) | 571 type = re.sub('(Constructor)+$', '', type) |
| 579 # TODO(antonm): Ideally we'd like to have pristine copy of WebKit IDLs and
fetch | 572 # TODO(antonm): Ideally we'd like to have pristine copy of WebKit IDLs and
fetch |
| 580 # this information directly from it. Unfortunately right now database is
massaged | 573 # this information directly from it. Unfortunately right now database is
massaged |
| 581 # a lot so it's difficult to maintain necessary information on DOMWindow i
tself. | 574 # a lot so it's difficult to maintain necessary information on DOMWindow i
tself. |
| 582 interface = self._database.GetInterface(options.type_rename_map.get(type,
type)) | 575 interface = self._database.GetInterface(type) |
| 583 if 'V8EnabledPerContext' in attr.ext_attrs: | 576 if 'V8EnabledPerContext' in attr.ext_attrs: |
| 584 interface.ext_attrs['synthesizedV8EnabledPerContext'] = \ | 577 interface.ext_attrs['synthesizedV8EnabledPerContext'] = \ |
| 585 attr.ext_attrs['V8EnabledPerContext'] | 578 attr.ext_attrs['V8EnabledPerContext'] |
| 586 if 'V8EnabledAtRuntime' in attr.ext_attrs: | 579 if 'V8EnabledAtRuntime' in attr.ext_attrs: |
| 587 interface.ext_attrs['synthesizedV8EnabledAtRuntime'] = \ | 580 interface.ext_attrs['synthesizedV8EnabledAtRuntime'] = \ |
| 588 attr.ext_attrs['V8EnabledAtRuntime'] or attr.id | 581 attr.ext_attrs['V8EnabledAtRuntime'] or attr.id |
| OLD | NEW |