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

Side by Side Diff: mojo/public/tools/bindings/pylib/mojom/generate/generator.py

Issue 459873003: Mojom generator: move Is.*Kind() functions into module.py and use them from all mojom_.*_generator.… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix java compilation Created 6 years, 4 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 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 18 matching lines...) Expand all
29 struct.packed = pack.PackedStruct(struct) 29 struct.packed = pack.PackedStruct(struct)
30 return struct 30 return struct
31 31
32 def GetDataHeader(exported, struct): 32 def GetDataHeader(exported, struct):
33 struct.packed = pack.PackedStruct(struct) 33 struct.packed = pack.PackedStruct(struct)
34 struct.bytes = pack.GetByteLayout(struct.packed) 34 struct.bytes = pack.GetByteLayout(struct.packed)
35 struct.exported = exported 35 struct.exported = exported
36 return struct 36 return struct
37 37
38 def ExpectedArraySize(kind): 38 def ExpectedArraySize(kind):
39 if isinstance(kind, mojom.FixedArray): 39 if mojom.IsFixedArrayKind(kind):
40 return kind.length 40 return kind.length
41 return 0 41 return 0
42 42
43 def IsArrayKind(kind):
44 return isinstance(kind, (mojom.Array, mojom.FixedArray))
45
46 def IsStringKind(kind):
47 return kind.spec == 's'
48
49 def IsEnumKind(kind):
50 return isinstance(kind, mojom.Enum)
51
52 def IsObjectKind(kind):
53 return isinstance(kind, (mojom.Struct, mojom.Array, mojom.FixedArray)) or \
54 IsStringKind(kind)
55
56 def IsHandleKind(kind):
57 return kind.spec.startswith('h') or \
58 isinstance(kind, mojom.Interface) or \
59 isinstance(kind, mojom.InterfaceRequest)
60
61 def IsInterfaceKind(kind):
62 return isinstance(kind, mojom.Interface)
63
64 def IsInterfaceRequestKind(kind):
65 return isinstance(kind, mojom.InterfaceRequest)
66
67 def IsMoveOnlyKind(kind):
68 return IsObjectKind(kind) or IsHandleKind(kind)
69
70 def StudlyCapsToCamel(studly): 43 def StudlyCapsToCamel(studly):
71 return studly[0].lower() + studly[1:] 44 return studly[0].lower() + studly[1:]
72 45
73 def CamelCaseToAllCaps(camel_case): 46 def CamelCaseToAllCaps(camel_case):
74 return '_'.join( 47 return '_'.join(
75 word for word in re.split(r'([A-Z][^A-Z]+)', camel_case) if word).upper() 48 word for word in re.split(r'([A-Z][^A-Z]+)', camel_case) if word).upper()
76 49
77 class Generator(object): 50 class Generator(object):
78 # Pass |output_dir| to emit files to disk. Omit |output_dir| to echo all 51 # Pass |output_dir| to emit files to disk. Omit |output_dir| to echo all
79 # files to stdout. 52 # files to stdout.
(...skipping 23 matching lines...) Expand all
103 def GenerateFiles(self, args): 76 def GenerateFiles(self, args):
104 raise NotImplementedError("Subclasses must override/implement this method") 77 raise NotImplementedError("Subclasses must override/implement this method")
105 78
106 def GetJinjaParameters(self): 79 def GetJinjaParameters(self):
107 """Returns default constructor parameters for the jinja environment.""" 80 """Returns default constructor parameters for the jinja environment."""
108 return {} 81 return {}
109 82
110 def GetGlobals(self): 83 def GetGlobals(self):
111 """Returns global mappings for the template generation.""" 84 """Returns global mappings for the template generation."""
112 return {} 85 return {}
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/generators/mojom_js_generator.py ('k') | mojo/public/tools/bindings/pylib/mojom/generate/module.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698