OLD | NEW |
1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 return ''.join(lines) | 63 return ''.join(lines) |
64 | 64 |
65 | 65 |
66 def get_partial_interface_name_from_idl(file_contents): | 66 def get_partial_interface_name_from_idl(file_contents): |
67 match = re.search(r'partial\s+interface\s+(\w+)', file_contents) | 67 match = re.search(r'partial\s+interface\s+(\w+)', file_contents) |
68 if match: | 68 if match: |
69 return match.group(1) | 69 return match.group(1) |
70 return None | 70 return None |
71 | 71 |
72 | 72 |
| 73 # identifier-A implements identifier-B; |
| 74 # http://www.w3.org/TR/WebIDL/#idl-implements-statements |
| 75 def get_implementers_from_idl(file_contents, interface_name): |
| 76 implementers = [] |
| 77 for match in re.finditer(r'(\w+)\s+implements\s+(\w+)\s*;', file_contents): |
| 78 # identifier-B must be the current interface |
| 79 assert match.group(2) == interface_name |
| 80 implementers.append(match.group(1)) |
| 81 return implementers |
| 82 |
73 def is_callback_interface_from_idl(file_contents): | 83 def is_callback_interface_from_idl(file_contents): |
74 match = re.search(r'callback\s+interface\s+\w+', file_contents) | 84 match = re.search(r'callback\s+interface\s+\w+', file_contents) |
75 return match is not None | 85 return match is not None |
76 | 86 |
77 | 87 |
78 def get_interface_extended_attributes_from_idl(file_contents): | 88 def get_interface_extended_attributes_from_idl(file_contents): |
79 extended_attributes = {} | 89 extended_attributes = {} |
80 match = re.search(r'\[(.*)\]\s+(interface|exception)\s+(\w+)', | 90 match = re.search(r'\[(.*)\]\s+(interface|exception)\s+(\w+)', |
81 file_contents, flags=re.DOTALL) | 91 file_contents, flags=re.DOTALL) |
82 if match: | 92 if match: |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 interface_name_to_idl_file = {} | 145 interface_name_to_idl_file = {} |
136 idl_file_to_interface_name = {} | 146 idl_file_to_interface_name = {} |
137 supplemental_dependencies = {} | 147 supplemental_dependencies = {} |
138 supplementals = {} | 148 supplementals = {} |
139 window_constructor_attributes_list = [] | 149 window_constructor_attributes_list = [] |
140 workercontext_constructor_attributes_list = [] | 150 workercontext_constructor_attributes_list = [] |
141 | 151 |
142 for idl_file_name in idl_files: | 152 for idl_file_name in idl_files: |
143 full_path = os.path.realpath(idl_file_name) | 153 full_path = os.path.realpath(idl_file_name) |
144 idl_file_contents = get_file_contents(full_path) | 154 idl_file_contents = get_file_contents(full_path) |
| 155 # Handle partial interfaces |
145 partial_interface_name = get_partial_interface_name_from_idl(idl_file_co
ntents) | 156 partial_interface_name = get_partial_interface_name_from_idl(idl_file_co
ntents) |
146 if partial_interface_name: | 157 if partial_interface_name: |
147 supplemental_dependencies[full_path] = partial_interface_name | 158 supplemental_dependencies[full_path] = [partial_interface_name] |
148 continue | 159 continue |
149 interface_name, _ = os.path.splitext(os.path.basename(idl_file_name)) | 160 interface_name, _ = os.path.splitext(os.path.basename(idl_file_name)) |
| 161 # Parse 'identifier-A implements identifier-B; statements |
| 162 implementers = get_implementers_from_idl(idl_file_contents, interface_na
me) |
| 163 for implementer in implementers: |
| 164 supplemental_dependencies.setdefault(full_path, []).append(implement
er) |
| 165 # Handle [NoInterfaceObject] |
150 if not is_callback_interface_from_idl(idl_file_contents): | 166 if not is_callback_interface_from_idl(idl_file_contents): |
151 extended_attributes = get_interface_extended_attributes_from_idl(idl
_file_contents) | 167 extended_attributes = get_interface_extended_attributes_from_idl(idl
_file_contents) |
152 if 'NoInterfaceObject' not in extended_attributes: | 168 if 'NoInterfaceObject' not in extended_attributes: |
153 global_context = extended_attributes.get("GlobalContext", "Windo
wOnly") | 169 global_context = extended_attributes.get("GlobalContext", "Windo
wOnly") |
154 constructor_list = generate_constructor_attribute_list(interface
_name, extended_attributes) | 170 constructor_list = generate_constructor_attribute_list(interface
_name, extended_attributes) |
155 if global_context != "WorkerOnly": | 171 if global_context != "WorkerOnly": |
156 window_constructor_attributes_list.extend(constructor_list) | 172 window_constructor_attributes_list.extend(constructor_list) |
157 if global_context != "WindowOnly": | 173 if global_context != "WindowOnly": |
158 workercontext_constructor_attributes_list.extend(constructor
_list) | 174 workercontext_constructor_attributes_list.extend(constructor
_list) |
159 interface_name_to_idl_file[interface_name] = full_path | 175 interface_name_to_idl_file[interface_name] = full_path |
160 idl_file_to_interface_name[full_path] = interface_name | 176 idl_file_to_interface_name[full_path] = interface_name |
161 supplementals[full_path] = [] | 177 supplementals[full_path] = [] |
162 | 178 |
163 # Generate Global constructors | 179 # Generate Global constructors |
164 generate_global_constructors_partial_interface("Window", window_constructors
_filename, window_constructor_attributes_list) | 180 generate_global_constructors_partial_interface("Window", window_constructors
_filename, window_constructor_attributes_list) |
165 if 'Window' in interface_name_to_idl_file: | 181 if 'Window' in interface_name_to_idl_file: |
166 supplemental_dependencies[window_constructors_filename] = 'Window' | 182 supplemental_dependencies[window_constructors_filename] = ['Window'] |
167 generate_global_constructors_partial_interface("WorkerContext", workercontex
t_constructors_filename, workercontext_constructor_attributes_list) | 183 generate_global_constructors_partial_interface("WorkerContext", workercontex
t_constructors_filename, workercontext_constructor_attributes_list) |
168 if 'WorkerContext' in interface_name_to_idl_file: | 184 if 'WorkerContext' in interface_name_to_idl_file: |
169 supplemental_dependencies[workercontext_constructors_filename] = 'Worker
Context' | 185 supplemental_dependencies[workercontext_constructors_filename] = ['Worke
rContext'] |
170 | 186 |
171 # Resolve partial interfaces dependencies | 187 # Resolve partial interfaces dependencies |
172 for idl_file, base_file in supplemental_dependencies.iteritems(): | 188 for idl_file, base_files in supplemental_dependencies.iteritems(): |
173 target_idl_file = interface_name_to_idl_file[base_file] | 189 for base_file in base_files: |
174 supplementals[target_idl_file].append(idl_file) | 190 target_idl_file = interface_name_to_idl_file[base_file] |
175 if idl_file in supplementals: | 191 supplementals[target_idl_file].append(idl_file) |
176 # Should never occur. Might be needed in corner cases. | 192 if idl_file in supplementals: |
177 del supplementals[idl_file] | 193 # Should never occur. Might be needed in corner cases. |
| 194 del supplementals[idl_file] |
178 return supplementals | 195 return supplementals |
179 | 196 |
180 | 197 |
181 def write_dependency_file(filename, supplementals, only_if_changed=False): | 198 def write_dependency_file(filename, supplementals, only_if_changed=False): |
182 """Outputs the dependency file. | 199 """Outputs the dependency file. |
183 | 200 |
184 The format of a supplemental dependency file: | 201 The format of a supplemental dependency file: |
185 | 202 |
186 Window.idl P.idl Q.idl R.idl | 203 Window.idl P.idl Q.idl R.idl |
187 Document.idl S.idl | 204 Document.idl S.idl |
(...skipping 25 matching lines...) Expand all Loading... |
213 idl_files = [] | 230 idl_files = [] |
214 with open(options.idl_files_list) as idl_files_list_file: | 231 with open(options.idl_files_list) as idl_files_list_file: |
215 for line in idl_files_list_file: | 232 for line in idl_files_list_file: |
216 idl_files.append(string.rstrip(line, '\n')) | 233 idl_files.append(string.rstrip(line, '\n')) |
217 resolved_supplementals = parse_idl_files(idl_files, options.window_construct
ors_file, options.workercontext_constructors_file) | 234 resolved_supplementals = parse_idl_files(idl_files, options.window_construct
ors_file, options.workercontext_constructors_file) |
218 write_dependency_file(options.supplemental_dependency_file, resolved_supplem
entals, only_if_changed=options.write_file_only_if_changed) | 235 write_dependency_file(options.supplemental_dependency_file, resolved_supplem
entals, only_if_changed=options.write_file_only_if_changed) |
219 | 236 |
220 | 237 |
221 if __name__ == '__main__': | 238 if __name__ == '__main__': |
222 main() | 239 main() |
OLD | NEW |