Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(504)

Side by Side Diff: mojo/public/bindings/generators/mojom_generator.py

Issue 138143003: Support default values for POD struct fields in mojom IDL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 GetStructInfo(exported, struct): 22 def GetStructInfo(exported, struct):
23 struct.packed = mojom_pack.PackedStruct(struct) 23 struct.packed = mojom_pack.PackedStruct(struct)
24 struct.bytes = mojom_pack.GetByteLayout(struct.packed) 24 struct.bytes = mojom_pack.GetByteLayout(struct.packed)
25 struct.exported = exported 25 struct.exported = exported
26 return struct 26 return struct
27 27
28 def IsStringKind(kind):
29 return kind.spec == 's'
30
28 def IsObjectKind(kind): 31 def IsObjectKind(kind):
29 return isinstance(kind, (mojom.Struct, mojom.Array)) or kind.spec == 's' 32 return isinstance(kind, (mojom.Struct, mojom.Array)) or IsStringKind(kind)
30 33
31 def IsHandleKind(kind): 34 def IsHandleKind(kind):
32 return kind.spec.startswith('h') 35 return kind.spec.startswith('h')
33 36
34 def CamelToUnderscores(camel): 37 def CamelToUnderscores(camel):
35 s = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', camel) 38 s = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', camel)
36 return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s).lower() 39 return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s).lower()
37 40
38 def StudlyCapsToCamel(studly): 41 def StudlyCapsToCamel(studly):
39 return studly[0].lower() + studly[1:] 42 return studly[0].lower() + studly[1:]
(...skipping 15 matching lines...) Expand all
55 58
56 def GetStructs(self): 59 def GetStructs(self):
57 return map(partial(GetStructInfo, True), self.module.structs) 60 return map(partial(GetStructInfo, True), self.module.structs)
58 61
59 def Write(self, contents, filename): 62 def Write(self, contents, filename):
60 if self.output_dir is None: 63 if self.output_dir is None:
61 print contents 64 print contents
62 return 65 return
63 with open(os.path.join(self.output_dir, filename), "w+") as f: 66 with open(os.path.join(self.output_dir, filename), "w+") as f:
64 f.write(contents) 67 f.write(contents)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698