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

Side by Side Diff: Source/bindings/scripts/preprocess_idls.py

Issue 17550010: Move IDL implements statements to IDL files that implement the interface (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 6 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
« no previous file with comments | « no previous file | Source/core/dom/CharacterData.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
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; 73 # identifier-A implements identifier-B;
74 # http://www.w3.org/TR/WebIDL/#idl-implements-statements 74 # http://www.w3.org/TR/WebIDL/#idl-implements-statements
75 def get_implementers_from_idl(file_contents, interface_name): 75 def get_implemented_interfaces_from_idl(file_contents, interface_name):
76 implementers = [] 76 implemented_interfaces = []
77 for match in re.finditer(r'(\w+)\s+implements\s+(\w+)\s*;', file_contents): 77 for match in re.finditer(r'(\w+)\s+implements\s+(\w+)\s*;', file_contents):
78 # identifier-B must be the current interface 78 # identifier-A must be the current interface
79 assert match.group(2) == interface_name 79 assert match.group(1) == interface_name, \
80 implementers.append(match.group(1)) 80 "Identifier on the left of the 'implements' statement should be %s in %s.idl, bu t found %s" % (interface_name, interface_name, match.group(1))
81 return implementers 81 implemented_interfaces.append(match.group(2))
82 return implemented_interfaces
82 83
83 def is_callback_interface_from_idl(file_contents): 84 def is_callback_interface_from_idl(file_contents):
84 match = re.search(r'callback\s+interface\s+\w+', file_contents) 85 match = re.search(r'callback\s+interface\s+\w+', file_contents)
85 return match is not None 86 return match is not None
86 87
87 88
88 def get_interface_extended_attributes_from_idl(file_contents): 89 def get_interface_extended_attributes_from_idl(file_contents):
89 extended_attributes = {} 90 extended_attributes = {}
90 match = re.search(r'\[(.*)\]\s+(interface|exception)\s+(\w+)', 91 match = re.search(r'\[(.*)\]\s+(interface|exception)\s+(\w+)',
91 file_contents, flags=re.DOTALL) 92 file_contents, flags=re.DOTALL)
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 143
143 144
144 def parse_idl_files(idl_files, window_constructors_filename, workercontext_const ructors_filename): 145 def parse_idl_files(idl_files, window_constructors_filename, workercontext_const ructors_filename):
145 interface_name_to_idl_file = {} 146 interface_name_to_idl_file = {}
146 idl_file_to_interface_name = {} 147 idl_file_to_interface_name = {}
147 supplemental_dependencies = {} 148 supplemental_dependencies = {}
148 supplementals = {} 149 supplementals = {}
149 window_constructor_attributes_list = [] 150 window_constructor_attributes_list = []
150 workercontext_constructor_attributes_list = [] 151 workercontext_constructor_attributes_list = []
151 152
153 # Populate interface_name_to_idl_file first
154 for idl_file_name in idl_files:
155 full_path = os.path.realpath(idl_file_name)
156 interface_name, _ = os.path.splitext(os.path.basename(idl_file_name))
157 interface_name_to_idl_file[interface_name] = full_path
158
152 for idl_file_name in idl_files: 159 for idl_file_name in idl_files:
153 full_path = os.path.realpath(idl_file_name) 160 full_path = os.path.realpath(idl_file_name)
154 idl_file_contents = get_file_contents(full_path) 161 idl_file_contents = get_file_contents(full_path)
155 # Handle partial interfaces 162 # Handle partial interfaces
156 partial_interface_name = get_partial_interface_name_from_idl(idl_file_co ntents) 163 partial_interface_name = get_partial_interface_name_from_idl(idl_file_co ntents)
157 if partial_interface_name: 164 if partial_interface_name:
158 supplemental_dependencies[full_path] = [partial_interface_name] 165 supplemental_dependencies[full_path] = [partial_interface_name]
159 continue 166 continue
160 interface_name, _ = os.path.splitext(os.path.basename(idl_file_name)) 167 interface_name, _ = os.path.splitext(os.path.basename(idl_file_name))
161 # Parse 'identifier-A implements identifier-B; statements 168 # Parse 'identifier-A implements identifier-B; statements
162 implementers = get_implementers_from_idl(idl_file_contents, interface_na me) 169 implemented_interfaces = get_implemented_interfaces_from_idl(idl_file_co ntents, interface_name)
163 for implementer in implementers: 170 for implemented_interface in implemented_interfaces:
164 supplemental_dependencies.setdefault(full_path, []).append(implement er) 171 assert implemented_interface in interface_name_to_idl_file, \
172 "Could not find a the IDL file where the following implemented interface is defi ned: %s" % implemented_interface
173 supplemental_dependencies.setdefault(interface_name_to_idl_file[impl emented_interface], []).append(interface_name)
165 # Handle [NoInterfaceObject] 174 # Handle [NoInterfaceObject]
166 if not is_callback_interface_from_idl(idl_file_contents): 175 if not is_callback_interface_from_idl(idl_file_contents):
167 extended_attributes = get_interface_extended_attributes_from_idl(idl _file_contents) 176 extended_attributes = get_interface_extended_attributes_from_idl(idl _file_contents)
168 if 'NoInterfaceObject' not in extended_attributes: 177 if 'NoInterfaceObject' not in extended_attributes:
169 global_context = extended_attributes.get("GlobalContext", "Windo wOnly") 178 global_context = extended_attributes.get("GlobalContext", "Windo wOnly")
170 constructor_list = generate_constructor_attribute_list(interface _name, extended_attributes) 179 constructor_list = generate_constructor_attribute_list(interface _name, extended_attributes)
171 if global_context != "WorkerOnly": 180 if global_context != "WorkerOnly":
172 window_constructor_attributes_list.extend(constructor_list) 181 window_constructor_attributes_list.extend(constructor_list)
173 if global_context != "WindowOnly": 182 if global_context != "WindowOnly":
174 workercontext_constructor_attributes_list.extend(constructor _list) 183 workercontext_constructor_attributes_list.extend(constructor _list)
175 interface_name_to_idl_file[interface_name] = full_path
176 idl_file_to_interface_name[full_path] = interface_name 184 idl_file_to_interface_name[full_path] = interface_name
177 supplementals[full_path] = [] 185 supplementals[full_path] = []
178 186
179 # Generate Global constructors 187 # Generate Global constructors
180 generate_global_constructors_partial_interface("Window", window_constructors _filename, window_constructor_attributes_list) 188 generate_global_constructors_partial_interface("Window", window_constructors _filename, window_constructor_attributes_list)
181 if 'Window' in interface_name_to_idl_file: 189 if 'Window' in interface_name_to_idl_file:
182 supplemental_dependencies[window_constructors_filename] = ['Window'] 190 supplemental_dependencies[window_constructors_filename] = ['Window']
183 generate_global_constructors_partial_interface("WorkerContext", workercontex t_constructors_filename, workercontext_constructor_attributes_list) 191 generate_global_constructors_partial_interface("WorkerContext", workercontex t_constructors_filename, workercontext_constructor_attributes_list)
184 if 'WorkerContext' in interface_name_to_idl_file: 192 if 'WorkerContext' in interface_name_to_idl_file:
185 supplemental_dependencies[workercontext_constructors_filename] = ['Worke rContext'] 193 supplemental_dependencies[workercontext_constructors_filename] = ['Worke rContext']
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 idl_files = [] 238 idl_files = []
231 with open(options.idl_files_list) as idl_files_list_file: 239 with open(options.idl_files_list) as idl_files_list_file:
232 for line in idl_files_list_file: 240 for line in idl_files_list_file:
233 idl_files.append(string.rstrip(line, '\n')) 241 idl_files.append(string.rstrip(line, '\n'))
234 resolved_supplementals = parse_idl_files(idl_files, options.window_construct ors_file, options.workercontext_constructors_file) 242 resolved_supplementals = parse_idl_files(idl_files, options.window_construct ors_file, options.workercontext_constructors_file)
235 write_dependency_file(options.supplemental_dependency_file, resolved_supplem entals, only_if_changed=options.write_file_only_if_changed) 243 write_dependency_file(options.supplemental_dependency_file, resolved_supplem entals, only_if_changed=options.write_file_only_if_changed)
236 244
237 245
238 if __name__ == '__main__': 246 if __name__ == '__main__':
239 main() 247 main()
OLDNEW
« no previous file with comments | « no previous file | Source/core/dom/CharacterData.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698