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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 56 |
57 Args: | 57 Args: |
58 interfaces_info: | 58 interfaces_info: |
59 dict of interfaces information, from compute_dependencies.py | 59 dict of interfaces information, from compute_dependencies.py |
60 reader: | 60 reader: |
61 IdlReader, used for reading dependency files | 61 IdlReader, used for reading dependency files |
62 """ | 62 """ |
63 self.interfaces_info = interfaces_info | 63 self.interfaces_info = interfaces_info |
64 self.reader = reader | 64 self.reader = reader |
65 | 65 |
66 def resolve_dependencies(self, definitions): | 66 def resolve_dependencies(self, definitions, component): |
67 """Resolve dependencies, merging them into IDL definitions of main file. | 67 """Resolve dependencies, merging them into IDL definitions of main file. |
68 | 68 |
69 Dependencies consist of 'partial interface' for the same interface as | 69 Dependencies consist of 'partial interface' for the same interface as |
70 in the main file, and other interfaces that this interface 'implements'. | 70 in the main file, and other interfaces that this interface 'implements'. |
71 These are merged into the main IdlInterface, as the main IdlInterface | 71 These are merged into the main IdlInterface, as the main IdlInterface |
72 implements all these members. | 72 implements all these members. |
73 | 73 |
74 Referenced interfaces are added to IdlDefinitions, but not merged into | 74 Referenced interfaces are added to IdlDefinitions, but not merged into |
75 the main IdlInterface, as these are only referenced (their members are | 75 the main IdlInterface, as these are only referenced (their members are |
76 introspected, but not implemented in this interface). | 76 introspected, but not implemented in this interface). |
77 | 77 |
78 Inherited extended attributes are also added to the main IdlInterface. | 78 Inherited extended attributes are also added to the main IdlInterface. |
79 | 79 |
80 Modifies definitions in place by adding parsed dependencies. | 80 Modifies definitions in place by adding parsed dependencies. |
81 | 81 |
82 Args: | 82 Args: |
83 definitions: IdlDefinitions object, modified in place | 83 definitions: IdlDefinitions object, modified in place |
| 84 component: |
| 85 string, describing where the above definitions are defined, |
| 86 'core' or 'modules'. See KNOWN_COMPONENTS in utilities.py |
| 87 |
| 88 Returns: |
| 89 A dictionary whose key is component and value is IdlDefinitions |
| 90 object whose dependency is resolved. |
| 91 |
| 92 Raises: |
| 93 Exception: |
| 94 A given IdlDefinitions object doesn't have any interfaces, |
| 95 or a given IdlDefinitions object has incorrect referenced |
| 96 interfaces. |
84 """ | 97 """ |
| 98 # FIXME: we need to resolve dependency when we implement partial |
| 99 # dictionary. |
85 if not definitions.interfaces: | 100 if not definitions.interfaces: |
86 # This definitions should have a dictionary. Nothing to do for it. | 101 raise Exception('No need to resolve any dependencies of ' |
87 return | 102 'this definition: %s, because this should ' |
| 103 'have a dictionary.' % definitions.idl_name) |
| 104 |
88 target_interface = next(definitions.interfaces.itervalues()) | 105 target_interface = next(definitions.interfaces.itervalues()) |
89 interface_name = target_interface.name | 106 interface_name = target_interface.name |
90 interface_info = self.interfaces_info[interface_name] | 107 interface_info = self.interfaces_info[interface_name] |
91 | 108 |
92 if 'inherited_extended_attributes' in interface_info: | 109 if 'inherited_extended_attributes' in interface_info: |
93 target_interface.extended_attributes.update( | 110 target_interface.extended_attributes.update( |
94 interface_info['inherited_extended_attributes']) | 111 interface_info['inherited_extended_attributes']) |
95 | 112 |
96 merge_interface_dependencies(definitions, | 113 resolved_definitions = merge_interface_dependencies( |
97 target_interface, | 114 definitions, |
98 interface_info['dependencies_full_paths'], | 115 component, |
99 self.reader) | 116 target_interface, |
| 117 interface_info['dependencies_full_paths'], |
| 118 self.reader) |
100 | 119 |
101 for referenced_interface_name in interface_info['referenced_interfaces']
: | 120 for referenced_interface_name in interface_info['referenced_interfaces']
: |
102 referenced_definitions = self.reader.read_idl_definitions( | 121 referenced_definitions = self.reader.read_idl_definitions( |
103 self.interfaces_info[referenced_interface_name]['full_path']) | 122 self.interfaces_info[referenced_interface_name]['full_path']) |
104 definitions.update(referenced_definitions) | 123 |
| 124 if component not in referenced_definitions: |
| 125 raise Exception('This definitions: %s is defined in %s ' |
| 126 'but reference interface:%s is not defined ' |
| 127 'in %s' % (definitions.idl_name, |
| 128 component, |
| 129 referenced_interface_name, |
| 130 component)) |
| 131 |
| 132 resolved_definitions[component].update(referenced_definitions[compon
ent]) |
| 133 return resolved_definitions |
105 | 134 |
106 | 135 |
107 def merge_interface_dependencies(definitions, target_interface, dependency_idl_f
ilenames, reader): | 136 def merge_interface_dependencies(definitions, component, target_interface, depen
dency_idl_filenames, reader): |
108 """Merge dependencies ('partial interface' and 'implements') in dependency_i
dl_filenames into target_interface. | 137 """Merge dependencies ('partial interface' and 'implements') in dependency_i
dl_filenames into target_interface. |
109 | 138 |
110 No return: modifies target_interface in place. | 139 No return: modifies target_interface in place. |
111 """ | 140 """ |
112 # Sort so order consistent, so can compare output from run to run. | 141 # Sort so order consistent, so can compare output from run to run. |
113 for dependency_idl_filename in sorted(dependency_idl_filenames): | 142 for dependency_idl_filename in sorted(dependency_idl_filenames): |
114 dependency_definitions = reader.read_idl_file(dependency_idl_filename) | 143 dependency_definitions = reader.read_idl_file(dependency_idl_filename) |
| 144 # FIXME(crbug.com/358074): should not merge core definitions with |
| 145 # modules definitions. |
115 dependency_interface = next(dependency_definitions.interfaces.itervalues
()) | 146 dependency_interface = next(dependency_definitions.interfaces.itervalues
()) |
116 dependency_interface_basename, _ = os.path.splitext(os.path.basename(dep
endency_idl_filename)) | 147 dependency_interface_basename, _ = os.path.splitext(os.path.basename(dep
endency_idl_filename)) |
117 | 148 |
118 transfer_extended_attributes(dependency_interface, | 149 transfer_extended_attributes(dependency_interface, |
119 dependency_interface_basename) | 150 dependency_interface_basename) |
120 definitions.update(dependency_definitions) # merges partial interfaces | 151 definitions.update(dependency_definitions) # merges partial interfaces |
121 if not dependency_interface.is_partial: | 152 if not dependency_interface.is_partial: |
122 # Implemented interfaces (non-partial dependencies) are also merged | 153 # Implemented interfaces (non-partial dependencies) are also merged |
123 # into the target interface, so Code Generator can just iterate | 154 # into the target interface, so Code Generator can just iterate |
124 # over one list (and not need to handle 'implements' itself). | 155 # over one list (and not need to handle 'implements' itself). |
125 target_interface.merge(dependency_interface) | 156 target_interface.merge(dependency_interface) |
126 | 157 |
| 158 # FIXME: Currently, this function just returns one IdlDefinitions |
| 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 |
127 | 164 |
128 def transfer_extended_attributes(dependency_interface, dependency_interface_base
name): | 165 def transfer_extended_attributes(dependency_interface, dependency_interface_base
name): |
129 """Transfer extended attributes from dependency interface onto members. | 166 """Transfer extended attributes from dependency interface onto members. |
130 | 167 |
131 Merging consists of storing certain interface-level data in extended | 168 Merging consists of storing certain interface-level data in extended |
132 attributes of the *members* (because there is no separate dependency | 169 attributes of the *members* (because there is no separate dependency |
133 interface post-merging). | 170 interface post-merging). |
134 | 171 |
135 The data storing consists of: | 172 The data storing consists of: |
136 * applying certain extended attributes from the dependency interface | 173 * applying certain extended attributes from the dependency interface |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 merged_extended_attributes['PartialInterfaceImplementedAs'] = ( | 210 merged_extended_attributes['PartialInterfaceImplementedAs'] = ( |
174 dependency_interface.extended_attributes.get( | 211 dependency_interface.extended_attributes.get( |
175 'ImplementedAs', dependency_interface_basename)) | 212 'ImplementedAs', dependency_interface_basename)) |
176 | 213 |
177 for attribute in dependency_interface.attributes: | 214 for attribute in dependency_interface.attributes: |
178 attribute.extended_attributes.update(merged_extended_attributes) | 215 attribute.extended_attributes.update(merged_extended_attributes) |
179 for constant in dependency_interface.constants: | 216 for constant in dependency_interface.constants: |
180 constant.extended_attributes.update(merged_extended_attributes) | 217 constant.extended_attributes.update(merged_extended_attributes) |
181 for operation in dependency_interface.operations: | 218 for operation in dependency_interface.operations: |
182 operation.extended_attributes.update(merged_extended_attributes) | 219 operation.extended_attributes.update(merged_extended_attributes) |
OLD | NEW |