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 19 matching lines...) Expand all Loading... | |
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 = set([ |
47 'Conditional', | 48 'Conditional', |
48 'PerContextEnabled', | 49 'PerContextEnabled', |
49 'RuntimeEnabled', | 50 'RuntimeEnabled', |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 'have a dictionary.' % definitions.idl_name) | 104 'have a dictionary.' % definitions.idl_name) |
104 | 105 |
105 target_interface = next(definitions.interfaces.itervalues()) | 106 target_interface = next(definitions.interfaces.itervalues()) |
106 interface_name = target_interface.name | 107 interface_name = target_interface.name |
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 |
114 # FIXME: new method for partial interface dependencies full paths? | |
113 resolved_definitions = merge_interface_dependencies( | 115 resolved_definitions = merge_interface_dependencies( |
114 definitions, | 116 definitions, |
115 component, | 117 component, |
116 target_interface, | 118 target_interface, |
117 interface_info['dependencies_full_paths'], | 119 interface_info['dependencies_full_paths'] + |
120 interface_info['partial_interface_dependencies_full_paths'], | |
118 self.reader) | 121 self.reader) |
119 | 122 |
120 for referenced_interface_name in interface_info['referenced_interfaces'] : | 123 for referenced_interface_name in interface_info['referenced_interfaces'] : |
121 referenced_definitions = self.reader.read_idl_definitions( | 124 referenced_definitions = self.reader.read_idl_definitions( |
122 self.interfaces_info[referenced_interface_name]['full_path']) | 125 self.interfaces_info[referenced_interface_name]['full_path']) |
123 | 126 |
124 if component not in referenced_definitions: | 127 for referenced_component in referenced_definitions: |
125 raise Exception('This definitions: %s is defined in %s ' | 128 if not is_valid_component_dependency(component, referenced_compo nent): |
126 'but reference interface:%s is not defined ' | 129 raise Exception('This definitions: %s is defined in %s ' |
127 'in %s' % (definitions.idl_name, | 130 'but reference interface:%s is defined ' |
128 component, | 131 'in %s' % (definitions.idl_name, |
129 referenced_interface_name, | 132 component, |
130 component)) | 133 referenced_interface_name, |
134 referenced_component)) | |
131 | 135 |
132 resolved_definitions[component].update(referenced_definitions[compon ent]) | 136 resolved_definitions[component].update(referenced_definitions[co mponent]) |
137 | |
133 return resolved_definitions | 138 return resolved_definitions |
134 | 139 |
135 | 140 |
136 def merge_interface_dependencies(definitions, component, target_interface, depen dency_idl_filenames, reader): | 141 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. | 142 """Merge dependencies ('partial interface' and 'implements') in dependency_i dl_filenames into target_interface. |
138 | 143 |
139 No return: modifies target_interface in place. | 144 No return: modifies target_interface in place. |
bashi
2014/10/15 05:29:23
Could you update the comment? This method returns
tasak
2014/10/15 11:24:18
Done.
| |
140 """ | 145 """ |
146 resolved_definitions = {component: definitions} | |
141 # Sort so order consistent, so can compare output from run to run. | 147 # Sort so order consistent, so can compare output from run to run. |
142 for dependency_idl_filename in sorted(dependency_idl_filenames): | 148 for dependency_idl_filename in sorted(dependency_idl_filenames): |
143 dependency_definitions = reader.read_idl_file(dependency_idl_filename) | 149 dependency_definitions = reader.read_idl_file(dependency_idl_filename) |
144 # FIXME(crbug.com/358074): should not merge core definitions with | 150 dependency_component = idl_filename_to_component(dependency_idl_filename ) |
145 # modules definitions. | 151 |
146 dependency_interface = next(dependency_definitions.interfaces.itervalues ()) | 152 dependency_interface = next(dependency_definitions.interfaces.itervalues ()) |
147 dependency_interface_basename, _ = os.path.splitext(os.path.basename(dep endency_idl_filename)) | 153 dependency_interface_basename, _ = os.path.splitext(os.path.basename(dep endency_idl_filename)) |
148 | 154 |
149 transfer_extended_attributes(dependency_interface, | 155 transfer_extended_attributes(dependency_interface, |
150 dependency_interface_basename) | 156 dependency_interface_basename) |
151 definitions.update(dependency_definitions) # merges partial interfaces | 157 |
152 if not dependency_interface.is_partial: | 158 # We need to use different checkdeps here for partial interface and |
159 # inheritance. | |
160 if dependency_interface.is_partial: | |
161 # Case: dependency_interface is a partial interface of | |
162 # target_interface. | |
163 # So, | |
164 # - A partial interface defined in modules can update | |
165 # the original interface defined in core. | |
166 # However, | |
167 # - A partial interface defined in core cannot update | |
168 # the original interface defined in modules. | |
169 if not is_valid_component_dependency(dependency_component, component ): | |
170 raise Exception('The partial interface:%s in %s cannot update ' | |
171 'the original interface:%s in %s' % (dependency_ interface.name, | |
172 dependency_ component, | |
173 target_inte rface.name, | |
174 component)) | |
175 | |
176 if dependency_component in resolved_definitions: | |
177 resolved_definitions[dependency_component].update(dependency_def initions) | |
bashi
2014/10/15 05:29:23
Don't we need to update |original_interface| and |
tasak
2014/10/15 11:24:18
In this case, partial interfaces and the original
bashi
2014/10/17 02:23:24
Acknowledged.
| |
178 continue | |
179 | |
180 extended_attributes = {} | |
181 extended_attributes.update(target_interface.extended_attributes) | |
182 extended_attributes.update(dependency_interface.extended_attributes) | |
183 dependency_interface.extended_attributes.update(extended_attributes) | |
bashi
2014/10/15 05:29:22
Can't we do below?
dependency_interface.extended_
tasak
2014/10/15 11:24:18
Done.
| |
184 assert target_interface == definitions.interfaces[dependency_interfa ce.name] | |
185 dependency_interface.original_interface = target_interface | |
186 target_interface.partial_interfaces.append(dependency_interface) | |
187 resolved_definitions[dependency_component] = dependency_definitions | |
188 else: | |
189 # Case: target_interface implements dependency_interface. | |
190 # So, | |
191 # - An interface defined in modules can implement some interface | |
192 # defined in core. | |
193 # In this case, we need "NoInterfaceObject" extended attribute. | |
194 # However, | |
195 # - An interface defined in core cannot implement any interface | |
196 # defined in modules. | |
197 if not is_valid_component_dependency(component, dependency_component ): | |
198 raise Exception('The interface:%s in %s cannot implement ' | |
199 'the interface:%s in %s.' % (dependency_interfac e.name, | |
200 dependency_componen t, | |
201 target_interface.na me, | |
202 component)) | |
203 | |
204 if component != dependency_component: | |
205 if 'NoInterfaceObject' not in dependency_interface.extended_attr ibutes: | |
206 raise Exception('The interface:%s in %s cannot implement ' | |
207 'the interface:%s in %s because of ' | |
208 'missing NoInterfaceObject.' % (dependency_i nterface.name, | |
209 dependency_c omponent, | |
210 target_inter face.name, | |
211 component)) | |
212 | |
213 resolved_definitions[component].update(dependency_definitions) # me rges partial interfaces | |
153 # Implemented interfaces (non-partial dependencies) are also merged | 214 # Implemented interfaces (non-partial dependencies) are also merged |
154 # into the target interface, so Code Generator can just iterate | 215 # into the target interface, so Code Generator can just iterate |
155 # over one list (and not need to handle 'implements' itself). | 216 # over one list (and not need to handle 'implements' itself). |
156 target_interface.merge(dependency_interface) | 217 target_interface.merge(dependency_interface) |
157 | 218 |
158 # FIXME: Currently, this function just returns one IdlDefinitions | 219 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 | 220 |
164 | 221 |
165 def transfer_extended_attributes(dependency_interface, dependency_interface_base name): | 222 def transfer_extended_attributes(dependency_interface, dependency_interface_base name): |
166 """Transfer extended attributes from dependency interface onto members. | 223 """Transfer extended attributes from dependency interface onto members. |
167 | 224 |
168 Merging consists of storing certain interface-level data in extended | 225 Merging consists of storing certain interface-level data in extended |
169 attributes of the *members* (because there is no separate dependency | 226 attributes of the *members* (because there is no separate dependency |
170 interface post-merging). | 227 interface post-merging). |
171 | 228 |
172 The data storing consists of: | 229 The data storing consists of: |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 merged_extended_attributes['PartialInterfaceImplementedAs'] = ( | 267 merged_extended_attributes['PartialInterfaceImplementedAs'] = ( |
211 dependency_interface.extended_attributes.get( | 268 dependency_interface.extended_attributes.get( |
212 'ImplementedAs', dependency_interface_basename)) | 269 'ImplementedAs', dependency_interface_basename)) |
213 | 270 |
214 for attribute in dependency_interface.attributes: | 271 for attribute in dependency_interface.attributes: |
215 attribute.extended_attributes.update(merged_extended_attributes) | 272 attribute.extended_attributes.update(merged_extended_attributes) |
216 for constant in dependency_interface.constants: | 273 for constant in dependency_interface.constants: |
217 constant.extended_attributes.update(merged_extended_attributes) | 274 constant.extended_attributes.update(merged_extended_attributes) |
218 for operation in dependency_interface.operations: | 275 for operation in dependency_interface.operations: |
219 operation.extended_attributes.update(merged_extended_attributes) | 276 operation.extended_attributes.update(merged_extended_attributes) |
OLD | NEW |