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 |
(...skipping 22 matching lines...) Expand all Loading... |
33 full_dir = os.path.dirname(full_path) | 33 full_dir = os.path.dirname(full_path) |
34 fileutil.EnsureDirectoryExists(full_dir) | 34 fileutil.EnsureDirectoryExists(full_dir) |
35 | 35 |
36 # Dump the data to disk. | 36 # Dump the data to disk. |
37 with open(full_path, "w+") as f: | 37 with open(full_path, "w+") as f: |
38 f.write(contents) | 38 f.write(contents) |
39 | 39 |
40 class Generator(object): | 40 class Generator(object): |
41 # Pass |output_dir| to emit files to disk. Omit |output_dir| to echo all | 41 # Pass |output_dir| to emit files to disk. Omit |output_dir| to echo all |
42 # files to stdout. | 42 # files to stdout. |
43 def __init__(self, module, output_dir=None, typemap={}, variant=None): | 43 def __init__(self, module, output_dir=None, typemap=None, variant=None, |
| 44 bytecode_path=None): |
44 self.module = module | 45 self.module = module |
45 self.output_dir = output_dir | 46 self.output_dir = output_dir |
46 self.typemap = typemap | 47 self.typemap = typemap or {} |
47 self.variant = variant | 48 self.variant = variant |
| 49 self.bytecode_path = bytecode_path |
48 | 50 |
49 def GetStructsFromMethods(self): | 51 def GetStructsFromMethods(self): |
50 result = [] | 52 result = [] |
51 for interface in self.module.interfaces: | 53 for interface in self.module.interfaces: |
52 for method in interface.methods: | 54 for method in interface.methods: |
53 result.append(self._GetStructFromMethod(method)) | 55 result.append(self._GetStructFromMethod(method)) |
54 if method.response_parameters != None: | 56 if method.response_parameters != None: |
55 result.append(self._GetResponseStructFromMethod(method)) | 57 result.append(self._GetResponseStructFromMethod(method)) |
56 return result | 58 return result |
57 | 59 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 return self._AddStructComputedData(False, struct) | 140 return self._AddStructComputedData(False, struct) |
139 | 141 |
140 def _GetResponseStructFromMethod(self, method): | 142 def _GetResponseStructFromMethod(self, method): |
141 """Converts a method's response_parameters into the fields of a struct.""" | 143 """Converts a method's response_parameters into the fields of a struct.""" |
142 params_class = "%s_%s_ResponseParams" % (method.interface.name, method.name) | 144 params_class = "%s_%s_ResponseParams" % (method.interface.name, method.name) |
143 struct = mojom.Struct(params_class, module=method.interface.module) | 145 struct = mojom.Struct(params_class, module=method.interface.module) |
144 for param in method.response_parameters: | 146 for param in method.response_parameters: |
145 struct.AddField(param.name, param.kind, param.ordinal, | 147 struct.AddField(param.name, param.kind, param.ordinal, |
146 attributes=param.attributes) | 148 attributes=param.attributes) |
147 return self._AddStructComputedData(False, struct) | 149 return self._AddStructComputedData(False, struct) |
OLD | NEW |