OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Code shared by the various language-specific code generators.""" | 5 """Code shared by the various language-specific code generators.""" |
6 | 6 |
7 from functools import partial | 7 from functools import partial |
8 from itertools import chain | 8 from itertools import chain |
9 import os.path | 9 import os.path |
10 import re | 10 import re |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 used repeatedly in the generation process.""" | 162 used repeatedly in the generation process.""" |
163 if not hasattr(struct, 'packed') or struct.packed is None: | 163 if not hasattr(struct, 'packed') or struct.packed is None: |
164 struct.packed = pack.PackedStruct(struct) | 164 struct.packed = pack.PackedStruct(struct) |
165 struct.bytes = pack.GetByteLayout(struct.packed) | 165 struct.bytes = pack.GetByteLayout(struct.packed) |
166 struct.exported = exported | 166 struct.exported = exported |
167 return struct | 167 return struct |
168 | 168 |
169 def _AddInterfaceComputedData(self, interface): | 169 def _AddInterfaceComputedData(self, interface): |
170 """Adds computed data to the given interface. The data is computed once and | 170 """Adds computed data to the given interface. The data is computed once and |
171 used repeatedly in the generation process.""" | 171 used repeatedly in the generation process.""" |
172 # Here we set the interface's |version| attribute to be the maximum value | |
173 # of the |min_version| attributes of all methods in the interface and all | |
174 # parameters in those methods. | |
175 # TODO(rudominer) Consider adding this value to the intermediate | |
176 # representation. | |
177 interface.version = 0 | |
178 for method in interface.methods: | 172 for method in interface.methods: |
179 if method.min_version is not None: | |
180 interface.version = max(interface.version, method.min_version) | |
181 | |
182 method.param_struct = self._GetStructFromMethod(method) | 173 method.param_struct = self._GetStructFromMethod(method) |
183 interface.version = max(interface.version, | |
184 method.param_struct.versions[-1].version) | |
185 | |
186 if method.response_parameters is not None: | 174 if method.response_parameters is not None: |
187 method.response_param_struct = self._GetResponseStructFromMethod(method) | 175 method.response_param_struct = self._GetResponseStructFromMethod(method) |
188 interface.version = max( | |
189 interface.version, | |
190 method.response_param_struct.versions[-1].version) | |
191 else: | 176 else: |
192 method.response_param_struct = None | 177 method.response_param_struct = None |
193 return interface | 178 return interface |
194 | 179 |
195 def _GetStructFromMethod(self, method): | 180 def _GetStructFromMethod(self, method): |
196 """Returns a method's parameters as a struct.""" | 181 """Returns a method's parameters as a struct.""" |
197 return self._AddStructComputedData(False, method.param_struct) | 182 return self._AddStructComputedData(False, method.param_struct) |
198 | 183 |
199 def _GetResponseStructFromMethod(self, method): | 184 def _GetResponseStructFromMethod(self, method): |
200 """Returns a method's response_parameters as a struct.""" | 185 """Returns a method's response_parameters as a struct.""" |
201 return self._AddStructComputedData(False, method.response_param_struct) | 186 return self._AddStructComputedData(False, method.response_param_struct) |
OLD | NEW |