| 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 import os.path | 8 import os.path |
| 9 import re | 9 import re |
| 10 | 10 |
| 11 import module as mojom | 11 import module as mojom |
| 12 import mojom.fileutil as fileutil | 12 import mojom.fileutil as fileutil |
| 13 import pack | 13 import pack |
| 14 | 14 |
| 15 def ExpectedArraySize(kind): | 15 def ExpectedArraySize(kind): |
| 16 if mojom.IsArrayKind(kind): | 16 if mojom.IsArrayKind(kind): |
| 17 return kind.length | 17 return kind.length |
| 18 return None | 18 return None |
| 19 | 19 |
| 20 def StudlyCapsToCamel(studly): | 20 def StudlyCapsToCamel(studly): |
| 21 return studly[0].lower() + studly[1:] | 21 return studly[0].lower() + studly[1:] |
| 22 | 22 |
| 23 def CamelCaseToAllCaps(camel_case): | |
| 24 return '_'.join( | |
| 25 word for word in re.split(r'([A-Z][^A-Z]+)', camel_case) if word).upper() | |
| 26 | |
| 27 def UnderToCamel(under): | 23 def UnderToCamel(under): |
| 28 """Converts underscore_separated strings to CamelCase strings.""" | 24 """Converts underscore_separated strings to CamelCase strings.""" |
| 29 return ''.join(word.capitalize() for word in under.split('_')) | 25 return ''.join(word.capitalize() for word in under.split('_')) |
| 30 | 26 |
| 31 def WriteFile(contents, full_path): | 27 def WriteFile(contents, full_path): |
| 32 # Make sure the containing directory exists. | 28 # Make sure the containing directory exists. |
| 33 full_dir = os.path.dirname(full_path) | 29 full_dir = os.path.dirname(full_path) |
| 34 fileutil.EnsureDirectoryExists(full_dir) | 30 fileutil.EnsureDirectoryExists(full_dir) |
| 35 | 31 |
| 36 # Dump the data to disk. | 32 # Dump the data to disk. |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 return self._AddStructComputedData(False, struct) | 136 return self._AddStructComputedData(False, struct) |
| 141 | 137 |
| 142 def _GetResponseStructFromMethod(self, method): | 138 def _GetResponseStructFromMethod(self, method): |
| 143 """Converts a method's response_parameters into the fields of a struct.""" | 139 """Converts a method's response_parameters into the fields of a struct.""" |
| 144 params_class = "%s_%s_ResponseParams" % (method.interface.name, method.name) | 140 params_class = "%s_%s_ResponseParams" % (method.interface.name, method.name) |
| 145 struct = mojom.Struct(params_class, module=method.interface.module) | 141 struct = mojom.Struct(params_class, module=method.interface.module) |
| 146 for param in method.response_parameters: | 142 for param in method.response_parameters: |
| 147 struct.AddField(param.name, param.kind, param.ordinal, | 143 struct.AddField(param.name, param.kind, param.ordinal, |
| 148 attributes=param.attributes) | 144 attributes=param.attributes) |
| 149 return self._AddStructComputedData(False, struct) | 145 return self._AddStructComputedData(False, struct) |
| OLD | NEW |