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. |
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 |
158 if not is_valid_component_dependency(component, dependency_component) an d dependency_interface.is_partial: | |
haraken
2014/10/09 04:24:00
Would you elaborate on what this is doing?
Why do
tasak
2014/10/10 07:52:22
Done.
| |
159 if dependency_component in resolved_definitions: | |
160 resolved_definitions[dependency_component].update(dependency_def initions) | |
161 continue | |
162 | |
163 extended_attributes = {} | |
164 extended_attributes.update(target_interface.extended_attributes) | |
165 extended_attributes.update(dependency_interface.extended_attributes) | |
166 dependency_interface.extended_attributes.update(extended_attributes) | |
167 assert target_interface == definitions.interfaces[dependency_interfa ce.name] | |
168 dependency_interface.original_interface = target_interface | |
169 target_interface.partial_interfaces.append(dependency_interface) | |
170 resolved_definitions[dependency_component] = dependency_definitions | |
171 continue | |
172 | |
173 resolved_definitions[component].update(dependency_definitions) # merges partial interfaces | |
152 if not dependency_interface.is_partial: | 174 if not dependency_interface.is_partial: |
153 # Implemented interfaces (non-partial dependencies) are also merged | 175 # Implemented interfaces (non-partial dependencies) are also merged |
154 # into the target interface, so Code Generator can just iterate | 176 # into the target interface, so Code Generator can just iterate |
155 # over one list (and not need to handle 'implements' itself). | 177 # over one list (and not need to handle 'implements' itself). |
156 target_interface.merge(dependency_interface) | 178 target_interface.merge(dependency_interface) |
157 | 179 |
158 # FIXME: Currently, this function just returns one IdlDefinitions | 180 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 | 181 |
164 | 182 |
165 def transfer_extended_attributes(dependency_interface, dependency_interface_base name): | 183 def transfer_extended_attributes(dependency_interface, dependency_interface_base name): |
166 """Transfer extended attributes from dependency interface onto members. | 184 """Transfer extended attributes from dependency interface onto members. |
167 | 185 |
168 Merging consists of storing certain interface-level data in extended | 186 Merging consists of storing certain interface-level data in extended |
169 attributes of the *members* (because there is no separate dependency | 187 attributes of the *members* (because there is no separate dependency |
170 interface post-merging). | 188 interface post-merging). |
171 | 189 |
172 The data storing consists of: | 190 The data storing consists of: |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 merged_extended_attributes['PartialInterfaceImplementedAs'] = ( | 228 merged_extended_attributes['PartialInterfaceImplementedAs'] = ( |
211 dependency_interface.extended_attributes.get( | 229 dependency_interface.extended_attributes.get( |
212 'ImplementedAs', dependency_interface_basename)) | 230 'ImplementedAs', dependency_interface_basename)) |
213 | 231 |
214 for attribute in dependency_interface.attributes: | 232 for attribute in dependency_interface.attributes: |
215 attribute.extended_attributes.update(merged_extended_attributes) | 233 attribute.extended_attributes.update(merged_extended_attributes) |
216 for constant in dependency_interface.constants: | 234 for constant in dependency_interface.constants: |
217 constant.extended_attributes.update(merged_extended_attributes) | 235 constant.extended_attributes.update(merged_extended_attributes) |
218 for operation in dependency_interface.operations: | 236 for operation in dependency_interface.operations: |
219 operation.extended_attributes.update(merged_extended_attributes) | 237 operation.extended_attributes.update(merged_extended_attributes) |
OLD | NEW |