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 logging | 8 import logging |
9 import monitored | 9 import monitored |
10 import multiprocessing | 10 import multiprocessing |
11 import os | 11 import os |
12 import os.path | 12 import os.path |
13 import re | 13 import re |
14 import sys | 14 import sys |
15 import tempfile | 15 import tempfile |
16 import time | 16 import time |
17 import traceback | 17 import traceback |
18 | 18 |
19 import idl_validator | 19 import idl_validator |
20 | 20 |
21 import compiler | 21 import compiler |
22 import compute_interfaces_info_individual | 22 import compute_interfaces_info_individual |
23 from compute_interfaces_info_individual import compute_info_individual, info_ind
ividual | 23 from compute_interfaces_info_individual import InterfaceInfoCollector |
24 import compute_interfaces_info_overall | |
25 from compute_interfaces_info_overall import compute_interfaces_info_overall, int
erfaces_info | |
26 import idl_definitions | 24 import idl_definitions |
27 | 25 |
28 from idlnode import * | 26 from idlnode import * |
29 | 27 |
30 _logger = logging.getLogger('databasebuilder') | 28 _logger = logging.getLogger('databasebuilder') |
31 | 29 |
32 # Used in source annotations to specify the parent interface declaring | 30 # Used in source annotations to specify the parent interface declaring |
33 # a displaced declaration. The 'via' attribute specifies the parent interface | 31 # a displaced declaration. The 'via' attribute specifies the parent interface |
34 # which implements a displaced declaration. | 32 # which implements a displaced declaration. |
35 _VIA_ANNOTATION_ATTR_NAME = 'via' | 33 _VIA_ANNOTATION_ATTR_NAME = 'via' |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 # driven by the databasebuilder. Blink compiler requires | 123 # driven by the databasebuilder. Blink compiler requires |
126 # an output directory even though we don't use (yet). Might | 124 # an output directory even though we don't use (yet). Might |
127 # use the code generator portion of the new IDL compiler | 125 # use the code generator portion of the new IDL compiler |
128 # then we'd have a real output directory. Today we use the | 126 # then we'd have a real output directory. Today we use the |
129 # compiler to only create an AST. | 127 # compiler to only create an AST. |
130 self.output_directory = tempfile.mkdtemp() | 128 self.output_directory = tempfile.mkdtemp() |
131 attrib_file = os.path.join('Source', idl_validator.EXTENDED_ATTRIBUTES_F
ILENAME) | 129 attrib_file = os.path.join('Source', idl_validator.EXTENDED_ATTRIBUTES_F
ILENAME) |
132 # Create compiler. | 130 # Create compiler. |
133 self.idl_compiler = compiler.IdlCompilerDart(self.output_directory, | 131 self.idl_compiler = compiler.IdlCompilerDart(self.output_directory, |
134 attrib_file, | 132 attrib_file, |
135 interfaces_info=interfaces_info, | 133 interfaces_info=provider._info_colle
ctor.interfaces_info, |
136 only_if_changed=True) | 134 only_if_changed=True) |
137 | 135 |
138 def format_exception(self, e): | 136 def format_exception(self, e): |
139 exception_list = traceback.format_stack() | 137 exception_list = traceback.format_stack() |
140 exception_list = exception_list[:-2] | 138 exception_list = exception_list[:-2] |
141 exception_list.extend(traceback.format_tb(sys.exc_info()[2])) | 139 exception_list.extend(traceback.format_tb(sys.exc_info()[2])) |
142 exception_list.extend(traceback.format_exception_only(sys.exc_info()[0],
sys.exc_info()[1])) | 140 exception_list.extend(traceback.format_exception_only(sys.exc_info()[0],
sys.exc_info()[1])) |
143 | 141 |
144 exception_str = "Traceback (most recent call last):\n" | 142 exception_str = "Traceback (most recent call last):\n" |
145 exception_str += "".join(exception_list) | 143 exception_str += "".join(exception_list) |
(...skipping 15 matching lines...) Expand all Loading... |
161 | 159 |
162 return 1 | 160 return 1 |
163 | 161 |
164 return IDLFile(idl_ast, file_name) | 162 return IDLFile(idl_ast, file_name) |
165 | 163 |
166 | 164 |
167 class DatabaseBuilder(object): | 165 class DatabaseBuilder(object): |
168 def __init__(self, database): | 166 def __init__(self, database): |
169 """DatabaseBuilder is used for importing and merging interfaces into | 167 """DatabaseBuilder is used for importing and merging interfaces into |
170 the Database""" | 168 the Database""" |
| 169 self._info_collector = InterfaceInfoCollector() |
| 170 |
171 self._database = database | 171 self._database = database |
172 self._imported_interfaces = [] | 172 self._imported_interfaces = [] |
173 self._impl_stmts = [] | 173 self._impl_stmts = [] |
174 self.conditionals_met = set() | 174 self.conditionals_met = set() |
175 | 175 |
176 # Spin up the new IDL parser. | 176 # Spin up the new IDL parser. |
177 self.build = Build(None) | 177 self.build = Build(self) |
178 | 178 |
179 # Global typedef to mapping. | 179 # Global typedef to mapping. |
180 self.global_type_defs = monitored.Dict('databasebuilder.global_type_defs', { | 180 self.global_type_defs = monitored.Dict('databasebuilder.global_type_defs', { |
181 'Transferable' : 'MessagePort', | 181 'Transferable' : 'MessagePort', |
182 }) | 182 }) |
183 | 183 |
184 # TODO(terry): Consider keeping richer type information (e.g., | 184 # TODO(terry): Consider keeping richer type information (e.g., |
185 # IdlArrayOrSequenceType from the Blink parser) instead of just | 185 # IdlArrayOrSequenceType from the Blink parser) instead of just |
186 # a type name. | 186 # a type name. |
187 def _resolve_type_defs(self, idl_file): | 187 def _resolve_type_defs(self, idl_file): |
188 for type_node in idl_file.all(IDLType): | 188 for type_node in idl_file.all(IDLType): |
| 189 resolved = False |
189 type_name = type_node.id | 190 type_name = type_node.id |
190 for typedef in self.global_type_defs: | 191 for typedef in self.global_type_defs: |
191 seq_name_typedef = 'sequence<%s>' % typedef | 192 seq_name_typedef = 'sequence<%s>' % typedef |
192 if type_name == typedef: | 193 if type_name == typedef: |
193 type_node.id = self.global_type_defs[typedef] | 194 type_node.id = self.global_type_defs[typedef] |
| 195 resolved = True |
194 elif type_name == seq_name_typedef: | 196 elif type_name == seq_name_typedef: |
195 type_node.id = 'sequence<%s>' % self.global_type_defs[typedef] | 197 type_node.id = 'sequence<%s>' % self.global_type_defs[typedef] |
| 198 resolved = True |
| 199 if not(resolved): |
| 200 for typedef in idl_file.typeDefs: |
| 201 if type_name == typedef.id: |
| 202 type_node.id = typedef.type.id |
| 203 resolved = True |
196 | 204 |
197 def _strip_ext_attributes(self, idl_file): | 205 def _strip_ext_attributes(self, idl_file): |
198 """Strips unuseful extended attributes.""" | 206 """Strips unuseful extended attributes.""" |
199 for ext_attrs in idl_file.all(IDLExtAttrs): | 207 for ext_attrs in idl_file.all(IDLExtAttrs): |
200 # TODO: Decide which attributes are uninteresting. | 208 # TODO: Decide which attributes are uninteresting. |
201 pass | 209 pass |
202 | 210 |
203 def _rename_types(self, idl_file, import_options): | 211 def _rename_types(self, idl_file, import_options): |
204 """Rename interface and type names with names provided in the | 212 """Rename interface and type names with names provided in the |
205 options. Also clears scopes from scoped names""" | 213 options. Also clears scopes from scoped names""" |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 | 560 |
553 implements_matches = re.finditer(implements_re, idl_file_contents, re.MULTIL
INE) | 561 implements_matches = re.finditer(implements_re, idl_file_contents, re.MULTIL
INE) |
554 return [match.groups() for match in implements_matches] | 562 return [match.groups() for match in implements_matches] |
555 | 563 |
556 # Compile the IDL file with the Blink compiler and remember each AST for the | 564 # Compile the IDL file with the Blink compiler and remember each AST for the |
557 # IDL. | 565 # IDL. |
558 def _blink_compile_idl_files(self, file_paths, import_options, is_dart_idl): | 566 def _blink_compile_idl_files(self, file_paths, import_options, is_dart_idl): |
559 if not(is_dart_idl): | 567 if not(is_dart_idl): |
560 start_time = time.time() | 568 start_time = time.time() |
561 | 569 |
562 # 2-stage computation: individual, then overall | 570 # Compute information for individual files |
| 571 # Information is stored in global variables interfaces_info and |
| 572 # partial_interface_files. |
563 for file_path in file_paths: | 573 for file_path in file_paths: |
564 compute_info_individual(file_path) | 574 self._info_collector.collect_info(file_path) |
565 info_individuals = [info_individual()] | |
566 compute_interfaces_info_overall(info_individuals) | |
567 | 575 |
568 end_time = time.time() | 576 end_time = time.time() |
569 print 'Compute dependencies %s seconds' % round((end_time - start_time), 2
) | 577 print 'Compute dependencies %s seconds' % round((end_time - start_time), 2
) |
570 else: | 578 else: |
571 # Compute the interface_info for dart.idl for implements defined. This | 579 # Compute the interface_info for dart.idl for implements defined. This |
572 # file is special in that more than one interface can exist in this file. | 580 # file is special in that more than one interface can exist in this file. |
573 implement_pairs = self._compute_dart_idl_implements(file_paths[0]) | 581 implement_pairs = self._compute_dart_idl_implements(file_paths[0]) |
574 | 582 |
575 interfaces_info['__dart_idl___'] = { | 583 self._info_collector.interfaces_info['__dart_idl___'] = { |
576 'implement_pairs': implement_pairs, | 584 'implement_pairs': implement_pairs, |
577 } | 585 } |
578 | 586 |
579 # Parse the IDL files serially. | 587 # Parse the IDL files serially. |
580 start_time = time.time() | 588 start_time = time.time() |
581 | 589 |
582 for file_path in file_paths: | 590 for file_path in file_paths: |
583 file_path = os.path.normpath(file_path) | 591 file_path = os.path.normpath(file_path) |
584 ast = _compile_idl_file(self.build, file_path, import_options) | 592 ast = _compile_idl_file(self.build, file_path, import_options) |
585 self._process_ast(os.path.splitext(os.path.basename(file_path))[0], ast) | 593 self._process_ast(os.path.splitext(os.path.basename(file_path))[0], ast) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 if hasattr(idl_file, 'implementsStatements'): | 646 if hasattr(idl_file, 'implementsStatements'): |
639 for implStmt in idl_file.implementsStatements: | 647 for implStmt in idl_file.implementsStatements: |
640 self._impl_stmts.append((implStmt, import_options)) | 648 self._impl_stmts.append((implStmt, import_options)) |
641 | 649 |
642 for enum in idl_file.enums: | 650 for enum in idl_file.enums: |
643 self._database.AddEnum(enum) | 651 self._database.AddEnum(enum) |
644 | 652 |
645 for dictionary in idl_file.dictionaries: | 653 for dictionary in idl_file.dictionaries: |
646 self._database.AddDictionary(dictionary) | 654 self._database.AddDictionary(dictionary) |
647 | 655 |
| 656 # TODO(terry): Hack to remember all typedef unions they're mapped to any |
| 657 # - no type. |
| 658 for typedef in idl_file.typeDefs: |
| 659 self._database.AddTypeDef(typedef) |
648 | 660 |
649 def _is_node_enabled(self, node, idl_defines): | 661 def _is_node_enabled(self, node, idl_defines): |
650 if not 'Conditional' in node.ext_attrs: | 662 if not 'Conditional' in node.ext_attrs: |
651 return True | 663 return True |
652 | 664 |
653 def enabled(condition): | 665 def enabled(condition): |
654 return 'ENABLE_%s' % condition in idl_defines | 666 return 'ENABLE_%s' % condition in idl_defines |
655 | 667 |
656 conditional = node.ext_attrs['Conditional'] | 668 conditional = node.ext_attrs['Conditional'] |
657 if conditional.find('&') != -1: | 669 if conditional.find('&') != -1: |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1007 | columns[0] | columns[1] | columns[2] | ... | | 1019 | columns[0] | columns[1] | columns[2] | ... | |
1008 """ | 1020 """ |
1009 if len(columns) > 0: | 1021 if len(columns) > 0: |
1010 for column in columns: | 1022 for column in columns: |
1011 value = '' if not column else column | 1023 value = '' if not column else column |
1012 sys.stdout.write('|{0:^{1}}'.format(value, self._TABULATE_WIDTH())) | 1024 sys.stdout.write('|{0:^{1}}'.format(value, self._TABULATE_WIDTH())) |
1013 else: | 1025 else: |
1014 sys.stdout.write('|{0:^{1}}'.format('', self._TABULATE_WIDTH())) | 1026 sys.stdout.write('|{0:^{1}}'.format('', self._TABULATE_WIDTH())) |
1015 | 1027 |
1016 sys.stdout.write('|\n') | 1028 sys.stdout.write('|\n') |
OLD | NEW |