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

Side by Side Diff: bindings/scripts/interface_dependency_resolver.py

Issue 1660113002: Updated to Chrome 45 (2454) moved from SVN to git. Base URL: https://github.com/dart-lang/webcore.git@roll_45
Patch Set: Created 4 years, 10 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
« no previous file with comments | « bindings/scripts/idl_types.py ('k') | bindings/scripts/utilities.py » ('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 19 matching lines...) Expand all
30 30
31 This library computes interface dependencies (partial interfaces and 31 This library computes interface dependencies (partial interfaces and
32 implements), reads the dependency files, and merges them to the IdlDefinitions 32 implements), reads the dependency files, and merges them to the IdlDefinitions
33 for the main IDL file, producing an IdlDefinitions object representing the 33 for the main IDL file, producing an IdlDefinitions object representing the
34 entire interface. 34 entire interface.
35 35
36 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler#TOC -Dependency-resolution 36 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler#TOC -Dependency-resolution
37 """ 37 """
38 38
39 import os.path 39 import os.path
40 from utilities import idl_filename_to_component, is_valid_component_dependency
40 41
41 # The following extended attributes can be applied to a dependency interface, 42 # The following extended attributes can be applied to a dependency interface,
42 # and are then applied to the individual members when merging. 43 # and are then applied to the individual members when merging.
43 # Note that this moves the extended attribute from the interface to the member, 44 # Note that this moves the extended attribute from the interface to the member,
44 # which changes the semantics and yields different code than the same extended 45 # which changes the semantics and yields different code than the same extended
45 # attribute on the main interface. 46 # attribute on the main interface.
46 DEPENDENCY_EXTENDED_ATTRIBUTES = set([ 47 DEPENDENCY_EXTENDED_ATTRIBUTES = frozenset([
47 'Conditional', 48 'Conditional',
48 'PerContextEnabled',
49 'RuntimeEnabled', 49 'RuntimeEnabled',
50 'TypeChecking',
50 ]) 51 ])
51 52
52 53
53 class InterfaceDependencyResolver(object): 54 class InterfaceDependencyResolver(object):
54 def __init__(self, interfaces_info, reader): 55 def __init__(self, interfaces_info, reader):
55 """Initialize dependency resolver. 56 """Initialize dependency resolver.
56 57
57 Args: 58 Args:
58 interfaces_info: 59 interfaces_info:
59 dict of interfaces information, from compute_dependencies.py 60 dict of interfaces information, from compute_dependencies.py
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 interface_info = self.interfaces_info[interface_name] 108 interface_info = self.interfaces_info[interface_name]
108 109
109 if 'inherited_extended_attributes' in interface_info: 110 if 'inherited_extended_attributes' in interface_info:
110 target_interface.extended_attributes.update( 111 target_interface.extended_attributes.update(
111 interface_info['inherited_extended_attributes']) 112 interface_info['inherited_extended_attributes'])
112 113
113 resolved_definitions = merge_interface_dependencies( 114 resolved_definitions = merge_interface_dependencies(
114 definitions, 115 definitions,
115 component, 116 component,
116 target_interface, 117 target_interface,
117 interface_info['dependencies_full_paths'], 118 interface_info['dependencies_full_paths'] +
119 interface_info['dependencies_other_component_full_paths'],
118 self.reader) 120 self.reader)
119 121
120 for referenced_interface_name in interface_info['referenced_interfaces'] : 122 for referenced_interface_name in interface_info['referenced_interfaces'] :
121 referenced_definitions = self.reader.read_idl_definitions( 123 referenced_definitions = self.reader.read_idl_definitions(
122 self.interfaces_info[referenced_interface_name]['full_path']) 124 self.interfaces_info[referenced_interface_name]['full_path'])
123 125
124 if component not in referenced_definitions: 126 for referenced_component in referenced_definitions:
125 raise Exception('This definitions: %s is defined in %s ' 127 if not is_valid_component_dependency(component, referenced_compo nent):
126 'but reference interface:%s is not defined ' 128 raise Exception('This definitions: %s is defined in %s '
127 'in %s' % (definitions.idl_name, 129 'but reference interface:%s is defined '
128 component, 130 'in %s' % (definitions.idl_name,
129 referenced_interface_name, 131 component,
130 component)) 132 referenced_interface_name,
133 referenced_component))
131 134
132 resolved_definitions[component].update(referenced_definitions[compon ent]) 135 resolved_definitions[component].update(referenced_definitions[co mponent])
136
133 return resolved_definitions 137 return resolved_definitions
134 138
135 139
136 def merge_interface_dependencies(definitions, component, target_interface, depen dency_idl_filenames, reader): 140 def merge_interface_dependencies(definitions, component, target_interface, depen dency_idl_filenames, reader):
137 """Merge dependencies ('partial interface' and 'implements') in dependency_i dl_filenames into target_interface. 141 """Merge dependencies ('partial interface' and 'implements') in dependency_i dl_filenames into target_interface.
138 142
139 No return: modifies target_interface in place. 143 Args:
144 definitions: IdlDefinitions object, modified in place
145 component:
146 string, describing where the above definitions are defined,
147 'core' or 'modules'. See KNOWN_COMPONENTS in utilities.py
148 target_interface: IdlInterface object, modified in place
149 dependency_idl_filenames:
150 Idl filenames which depend on the above definitions.
151 reader: IdlReader object.
152 Returns:
153 A dictionary whose key is component and value is IdlDefinitions
154 object whose dependency is resolved.
140 """ 155 """
156 resolved_definitions = {component: definitions}
141 # Sort so order consistent, so can compare output from run to run. 157 # Sort so order consistent, so can compare output from run to run.
142 for dependency_idl_filename in sorted(dependency_idl_filenames): 158 for dependency_idl_filename in sorted(dependency_idl_filenames):
143 dependency_definitions = reader.read_idl_file(dependency_idl_filename) 159 dependency_definitions = reader.read_idl_file(dependency_idl_filename)
144 # FIXME(crbug.com/358074): should not merge core definitions with 160 dependency_component = idl_filename_to_component(dependency_idl_filename )
145 # modules definitions. 161
146 dependency_interface = next(dependency_definitions.interfaces.itervalues ()) 162 dependency_interface = next(dependency_definitions.interfaces.itervalues ())
147 dependency_interface_basename, _ = os.path.splitext(os.path.basename(dep endency_idl_filename)) 163 dependency_interface_basename, _ = os.path.splitext(os.path.basename(dep endency_idl_filename))
148 164
149 transfer_extended_attributes(dependency_interface, 165 transfer_extended_attributes(dependency_interface,
150 dependency_interface_basename) 166 dependency_interface_basename)
151 definitions.update(dependency_definitions) # merges partial interfaces 167
152 if not dependency_interface.is_partial: 168 # We need to use different checkdeps here for partial interface and
169 # inheritance.
170 if dependency_interface.is_partial:
171 # Case: dependency_interface is a partial interface of
172 # target_interface.
173 # So,
174 # - A partial interface defined in modules can update
175 # the original interface defined in core.
176 # However,
177 # - A partial interface defined in core cannot update
178 # the original interface defined in modules.
179 if not is_valid_component_dependency(dependency_component, component ):
180 raise Exception('The partial interface:%s in %s cannot update '
181 'the original interface:%s in %s' % (dependency_ interface.name,
182 dependency_ component,
183 target_inte rface.name,
184 component))
185
186 if dependency_component in resolved_definitions:
187 # When merging a new partial interfaces, should not overwrite
188 # ImpelemntedAs extended attributes in merged partial
189 # interface.
190 # See also the below "if 'ImplementedAs' not in ... " line's
191 # comment.
192 dependency_interface.extended_attributes.pop('ImplementedAs', No ne)
193 resolved_definitions[dependency_component].update(dependency_def initions)
194 continue
195
196 dependency_interface.extended_attributes.update(target_interface.ext ended_attributes)
197 assert target_interface == definitions.interfaces[dependency_interfa ce.name]
198 # A partial interface should use its original interface's
199 # ImplementedAs. If the original interface doesn't have,
200 # remove ImplementedAs defined in the partial interface.
201 # Because partial interface needs the original interface's
202 # cpp class to obtain partial interface's cpp class.
203 # e.g.. V8WindowPartial.cpp:
204 # DOMWindow* impl = V8Window::toImpl(holder);
205 # RawPtr<...> cppValue(DOMWindowQuota::webkitStorageInfo(impl));
206 # TODO(tasak): remove ImplementedAs extended attributes
207 # from all partial interfaces. Instead, rename all cpp/header
208 # files correctly. ImplementedAs should not be allowed in
209 # partial interfaces.
210 if 'ImplementedAs' not in target_interface.extended_attributes:
211 dependency_interface.extended_attributes.pop('ImplementedAs', No ne)
212 dependency_interface.original_interface = target_interface
213 target_interface.partial_interfaces.append(dependency_interface)
214 resolved_definitions[dependency_component] = dependency_definitions
215 else:
216 # Case: target_interface implements dependency_interface.
217 # So,
218 # - An interface defined in modules can implement some interface
219 # defined in core.
220 # In this case, we need "NoInterfaceObject" extended attribute.
221 # However,
222 # - An interface defined in core cannot implement any interface
223 # defined in modules.
224 if not is_valid_component_dependency(component, dependency_component ):
225 raise Exception('The interface:%s in %s cannot implement '
226 'the interface:%s in %s.' % (dependency_interfac e.name,
227 dependency_componen t,
228 target_interface.na me,
229 component))
230
231 if component != dependency_component and 'NoInterfaceObject' not in dependency_interface.extended_attributes:
232 raise Exception('The interface:%s in %s cannot implement '
233 'the interface:%s in %s because of '
234 'missing NoInterfaceObject.' % (dependency_inter face.name,
235 dependency_compo nent,
236 target_interface .name,
237 component))
238
239 resolved_definitions[component].update(dependency_definitions) # me rges partial interfaces
153 # Implemented interfaces (non-partial dependencies) are also merged 240 # Implemented interfaces (non-partial dependencies) are also merged
154 # into the target interface, so Code Generator can just iterate 241 # into the target interface, so Code Generator can just iterate
155 # over one list (and not need to handle 'implements' itself). 242 # over one list (and not need to handle 'implements' itself).
156 target_interface.merge(dependency_interface) 243 target_interface.merge(dependency_interface)
157 244
158 # FIXME: Currently, this function just returns one IdlDefinitions 245 return resolved_definitions
159 # instance. However, for partial interface modularization, we need to
160 # make this function return multiple definitions, i.e.
161 # { 'core': ..., 'modules': ... }.
162 return {component: definitions}
163 246
164 247
165 def transfer_extended_attributes(dependency_interface, dependency_interface_base name): 248 def transfer_extended_attributes(dependency_interface, dependency_interface_base name):
166 """Transfer extended attributes from dependency interface onto members. 249 """Transfer extended attributes from dependency interface onto members.
167 250
168 Merging consists of storing certain interface-level data in extended 251 Merging consists of storing certain interface-level data in extended
169 attributes of the *members* (because there is no separate dependency 252 attributes of the *members* (because there is no separate dependency
170 interface post-merging). 253 interface post-merging).
171 254
172 The data storing consists of: 255 The data storing consists of:
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 # and members: 287 # and members:
205 # for Blink class name and function name (or constant name), respectively. 288 # for Blink class name and function name (or constant name), respectively.
206 # Thus we do not want to copy this from the interface to the member, but 289 # Thus we do not want to copy this from the interface to the member, but
207 # instead extract it and handle it separately. 290 # instead extract it and handle it separately.
208 if (dependency_interface.is_partial or 291 if (dependency_interface.is_partial or
209 'LegacyTreatAsPartialInterface' in dependency_interface.extended_attribu tes): 292 'LegacyTreatAsPartialInterface' in dependency_interface.extended_attribu tes):
210 merged_extended_attributes['PartialInterfaceImplementedAs'] = ( 293 merged_extended_attributes['PartialInterfaceImplementedAs'] = (
211 dependency_interface.extended_attributes.get( 294 dependency_interface.extended_attributes.get(
212 'ImplementedAs', dependency_interface_basename)) 295 'ImplementedAs', dependency_interface_basename))
213 296
297 def update_attributes(attributes, extras):
298 for key, value in extras.items():
299 if key not in attributes:
300 attributes[key] = value
301
214 for attribute in dependency_interface.attributes: 302 for attribute in dependency_interface.attributes:
215 attribute.extended_attributes.update(merged_extended_attributes) 303 update_attributes(attribute.extended_attributes, merged_extended_attribu tes)
216 for constant in dependency_interface.constants: 304 for constant in dependency_interface.constants:
217 constant.extended_attributes.update(merged_extended_attributes) 305 update_attributes(constant.extended_attributes, merged_extended_attribut es)
218 for operation in dependency_interface.operations: 306 for operation in dependency_interface.operations:
219 operation.extended_attributes.update(merged_extended_attributes) 307 update_attributes(operation.extended_attributes, merged_extended_attribu tes)
OLDNEW
« no previous file with comments | « bindings/scripts/idl_types.py ('k') | bindings/scripts/utilities.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698