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 import os | 7 import os |
8 import mojom | 8 import mojom |
9 import mojom_pack | 9 import mojom_pack |
10 import re | 10 import re |
11 from functools import partial | 11 from functools import partial |
12 | 12 |
13 def GetStructFromMethod(interface, method): | 13 def GetStructFromMethod(interface, method): |
14 """Converts a method's parameters into the fields of a struct.""" | 14 """Converts a method's parameters into the fields of a struct.""" |
15 params_class = "%s_%s_Params" % (interface.name, method.name) | 15 params_class = "%s_%s_Params" % (interface.name, method.name) |
16 struct = mojom.Struct(params_class) | 16 struct = mojom.Struct(params_class) |
17 for param in method.parameters: | 17 for param in method.parameters: |
18 struct.AddField(param.name, param.kind, param.ordinal) | 18 struct.AddField(param.name, param.kind, param.ordinal) |
19 struct.packed = mojom_pack.PackedStruct(struct) | 19 struct.packed = mojom_pack.PackedStruct(struct) |
20 return struct | 20 return struct |
21 | 21 |
| 22 def GetResponseStructFromMethod(interface, method): |
| 23 """Converts a method's response_parameters into the fields of a struct.""" |
| 24 params_class = "%s_%s_ResponseParams" % (interface.name, method.name) |
| 25 struct = mojom.Struct(params_class) |
| 26 for param in method.response_parameters: |
| 27 struct.AddField(param.name, param.kind, param.ordinal) |
| 28 struct.packed = mojom_pack.PackedStruct(struct) |
| 29 return struct |
| 30 |
22 def GetStructInfo(exported, struct): | 31 def GetStructInfo(exported, struct): |
23 struct.packed = mojom_pack.PackedStruct(struct) | 32 struct.packed = mojom_pack.PackedStruct(struct) |
24 struct.bytes = mojom_pack.GetByteLayout(struct.packed) | 33 struct.bytes = mojom_pack.GetByteLayout(struct.packed) |
25 struct.exported = exported | 34 struct.exported = exported |
26 return struct | 35 return struct |
27 | 36 |
28 def IsStringKind(kind): | 37 def IsStringKind(kind): |
29 return kind.spec == 's' | 38 return kind.spec == 's' |
30 | 39 |
31 def IsEnumKind(kind): | 40 def IsEnumKind(kind): |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 88 |
80 def Write(self, contents, filename): | 89 def Write(self, contents, filename): |
81 if self.output_dir is None: | 90 if self.output_dir is None: |
82 print contents | 91 print contents |
83 return | 92 return |
84 with open(os.path.join(self.output_dir, filename), "w+") as f: | 93 with open(os.path.join(self.output_dir, filename), "w+") as f: |
85 f.write(contents) | 94 f.write(contents) |
86 | 95 |
87 def GenerateFiles(self): | 96 def GenerateFiles(self): |
88 raise NotImplementedError("Subclasses must override/implement this method") | 97 raise NotImplementedError("Subclasses must override/implement this method") |
OLD | NEW |