| 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 os | 10 import os |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 self.obsolete_old_declarations = obsolete_old_declarations | 62 self.obsolete_old_declarations = obsolete_old_declarations |
| 63 | 63 |
| 64 | 64 |
| 65 class DatabaseBuilder(object): | 65 class DatabaseBuilder(object): |
| 66 def __init__(self, database): | 66 def __init__(self, database): |
| 67 """DatabaseBuilder is used for importing and merging interfaces into | 67 """DatabaseBuilder is used for importing and merging interfaces into |
| 68 the Database""" | 68 the Database""" |
| 69 self._database = database | 69 self._database = database |
| 70 self._imported_interfaces = [] | 70 self._imported_interfaces = [] |
| 71 self._impl_stmts = [] | 71 self._impl_stmts = [] |
| 72 self._same_signatures = {} | |
| 73 | 72 |
| 74 def _load_idl_file(self, file_name, import_options): | 73 def _load_idl_file(self, file_name, import_options): |
| 75 """Loads an IDL file intor memory""" | 74 """Loads an IDL file intor memory""" |
| 76 idl_parser = idlparser.IDLParser(import_options.idl_syntax) | 75 idl_parser = idlparser.IDLParser(import_options.idl_syntax) |
| 77 | 76 |
| 78 try: | 77 try: |
| 79 f = open(file_name, 'r') | 78 f = open(file_name, 'r') |
| 80 content = f.read() | 79 content = f.read() |
| 81 f.close() | 80 f.close() |
| 82 | 81 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 map(add_source_annotation, interface.attributes) | 201 map(add_source_annotation, interface.attributes) |
| 203 map(add_source_annotation, interface.operations) | 202 map(add_source_annotation, interface.operations) |
| 204 | 203 |
| 205 def _sign(self, node): | 204 def _sign(self, node): |
| 206 """Computes a unique signature for the node, for merging purposed, by | 205 """Computes a unique signature for the node, for merging purposed, by |
| 207 concatenating types and names in the declaration.""" | 206 concatenating types and names in the declaration.""" |
| 208 if isinstance(node, IDLType): | 207 if isinstance(node, IDLType): |
| 209 res = node.id | 208 res = node.id |
| 210 if res.startswith('unsigned '): | 209 if res.startswith('unsigned '): |
| 211 res = res[len('unsigned '):] | 210 res = res[len('unsigned '):] |
| 212 if res in self._same_signatures: | |
| 213 res = self._same_signatures[res] | |
| 214 return res | 211 return res |
| 215 | 212 |
| 216 res = [] | 213 res = [] |
| 217 if isinstance(node, IDLInterface): | 214 if isinstance(node, IDLInterface): |
| 218 res = ['interface', node.id] | 215 res = ['interface', node.id] |
| 219 elif isinstance(node, IDLParentInterface): | 216 elif isinstance(node, IDLParentInterface): |
| 220 res = ['parent', self._sign(node.type)] | 217 res = ['parent', self._sign(node.type)] |
| 221 elif isinstance(node, IDLOperation): | 218 elif isinstance(node, IDLOperation): |
| 222 res = ['op'] | 219 res = ['op'] |
| 223 for special in node.specials: | 220 for special in node.specials: |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 import_options.source_attributes) | 423 import_options.source_attributes) |
| 427 return | 424 return |
| 428 # not found, so add new one | 425 # not found, so add new one |
| 429 parent = IDLParentInterface(None) | 426 parent = IDLParentInterface(None) |
| 430 parent.type = IDLType(implemented_name) | 427 parent.type = IDLType(implemented_name) |
| 431 if source: | 428 if source: |
| 432 parent.annotations[source] = IDLAnnotation( | 429 parent.annotations[source] = IDLAnnotation( |
| 433 import_options.source_attributes) | 430 import_options.source_attributes) |
| 434 interface.parents.append(parent) | 431 interface.parents.append(parent) |
| 435 | 432 |
| 436 def set_same_signatures(self, signatures_table): | |
| 437 """Customize signature calculations by providing a custom table | |
| 438 indicating which types are equivalent""" | |
| 439 self._same_signatures = signatures_table | |
| 440 | |
| 441 def merge_imported_interfaces(self, optional_argument_whitelist): | 433 def merge_imported_interfaces(self, optional_argument_whitelist): |
| 442 """Merges all imported interfaces and loads them into the DB.""" | 434 """Merges all imported interfaces and loads them into the DB.""" |
| 443 | 435 |
| 444 # Step 1: Pre process imported interfaces | 436 # Step 1: Pre process imported interfaces |
| 445 for interface, module_name, import_options in self._imported_interfaces: | 437 for interface, module_name, import_options in self._imported_interfaces: |
| 446 self._split_declarations(interface, optional_argument_whitelist) | 438 self._split_declarations(interface, optional_argument_whitelist) |
| 447 self._annotate(interface, module_name, import_options) | 439 self._annotate(interface, module_name, import_options) |
| 448 | 440 |
| 449 # Step 2: Add all new interfaces and merge overlapping ones | 441 # Step 2: Add all new interfaces and merge overlapping ones |
| 450 for interface, module_name, import_options in self._imported_interfaces: | 442 for interface, module_name, import_options in self._imported_interfaces: |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 annotation = idl_node.annotations[source] | 582 annotation = idl_node.annotations[source] |
| 591 for name, value in annotation.items(): | 583 for name, value in annotation.items(): |
| 592 if (name in top_level_annotation | 584 if (name in top_level_annotation |
| 593 and value == top_level_annotation[name]): | 585 and value == top_level_annotation[name]): |
| 594 del annotation[name] | 586 del annotation[name] |
| 595 | 587 |
| 596 map(normalize, interface.parents) | 588 map(normalize, interface.parents) |
| 597 map(normalize, interface.constants) | 589 map(normalize, interface.constants) |
| 598 map(normalize, interface.attributes) | 590 map(normalize, interface.attributes) |
| 599 map(normalize, interface.operations) | 591 map(normalize, interface.operations) |
| OLD | NEW |