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

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

Issue 198343002: Mojo: request/response bindings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 9 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 """Generates C++ source files from a mojom.Module.""" 5 """Generates C++ source files from a mojom.Module."""
6 6
7 from generate import mojom 7 from generate import mojom
8 from generate import mojom_pack 8 from generate import mojom_pack
9 from generate import mojom_generator 9 from generate import mojom_generator
10 10
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 if isinstance(kind, (mojom.Struct, mojom.Enum)): 58 if isinstance(kind, (mojom.Struct, mojom.Enum)):
59 return GetNameForKind(kind) 59 return GetNameForKind(kind)
60 if isinstance(kind, mojom.Array): 60 if isinstance(kind, mojom.Array):
61 return "mojo::Array<%s >" % GetCppArrayArgWrapperType(kind.kind) 61 return "mojo::Array<%s >" % GetCppArrayArgWrapperType(kind.kind)
62 if isinstance(kind, mojom.Interface): 62 if isinstance(kind, mojom.Interface):
63 return "mojo::Interface<%s>::Handle" % kind.name 63 return "mojo::Interface<%s>::Handle" % kind.name
64 if kind.spec == 's': 64 if kind.spec == 's':
65 return "mojo::String" 65 return "mojo::String"
66 return _kind_to_cpp_type[kind] 66 return _kind_to_cpp_type[kind]
67 67
68 def GetCppResultWrapperType(kind):
69 if isinstance(kind, (mojom.Struct, mojom.Enum)):
70 return GetNameForKind(kind)
71 if isinstance(kind, mojom.Array):
72 return "mojo::Array<%s >" % GetCppArrayArgWrapperType(kind.kind)
73 if isinstance(kind, mojom.Interface):
74 return "mojo::Interface<%s>::ScopedHandle" % kind.name
75 if kind.spec == 's':
76 return "mojo::String"
77 if kind.spec == 'h':
78 return "mojo::ScopedHandle"
79 if kind.spec == 'h:d:c':
80 return "mojo::ScopedDataPipeConsumerHandle"
81 if kind.spec == 'h:d:p':
82 return "mojo::ScopedDataPipeProducerHandle"
83 if kind.spec == 'h:m':
84 return "mojo::ScopedMessagePipeHandle"
85 return _kind_to_cpp_type[kind]
86
68 def GetCppWrapperType(kind): 87 def GetCppWrapperType(kind):
69 if isinstance(kind, (mojom.Struct, mojom.Enum)): 88 if isinstance(kind, (mojom.Struct, mojom.Enum)):
70 return GetNameForKind(kind) 89 return GetNameForKind(kind)
71 if isinstance(kind, mojom.Array): 90 if isinstance(kind, mojom.Array):
72 return "mojo::Array<%s >" % GetCppArrayArgWrapperType(kind.kind) 91 return "mojo::Array<%s >" % GetCppArrayArgWrapperType(kind.kind)
73 if isinstance(kind, mojom.Interface): 92 if isinstance(kind, mojom.Interface):
74 return "mojo::Passable<typename mojo::Interface<%s>::Handle>" % kind.name 93 return "mojo::Passable<typename mojo::Interface<%s>::Handle>" % kind.name
75 if kind.spec == 's': 94 if kind.spec == 's':
76 return "mojo::String" 95 return "mojo::String"
77 if mojom_generator.IsHandleKind(kind): 96 if mojom_generator.IsHandleKind(kind):
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 lambda token: TranslateConstants(token, module))) 160 lambda token: TranslateConstants(token, module)))
142 161
143 _HEADER_SIZE = 8 162 _HEADER_SIZE = 8
144 163
145 class Generator(mojom_generator.Generator): 164 class Generator(mojom_generator.Generator):
146 165
147 cpp_filters = { 166 cpp_filters = {
148 "cpp_const_wrapper_type": GetCppConstWrapperType, 167 "cpp_const_wrapper_type": GetCppConstWrapperType,
149 "cpp_field_type": GetCppFieldType, 168 "cpp_field_type": GetCppFieldType,
150 "cpp_type": GetCppType, 169 "cpp_type": GetCppType,
170 "cpp_result_type": GetCppResultWrapperType,
151 "cpp_wrapper_type": GetCppWrapperType, 171 "cpp_wrapper_type": GetCppWrapperType,
152 "expression_to_text": ExpressionToText, 172 "expression_to_text": ExpressionToText,
153 "get_pad": mojom_pack.GetPad, 173 "get_pad": mojom_pack.GetPad,
154 "is_enum_kind": mojom_generator.IsEnumKind, 174 "is_enum_kind": mojom_generator.IsEnumKind,
155 "is_handle_kind": mojom_generator.IsHandleKind, 175 "is_handle_kind": mojom_generator.IsHandleKind,
156 "is_object_kind": mojom_generator.IsObjectKind, 176 "is_object_kind": mojom_generator.IsObjectKind,
157 "is_string_kind": mojom_generator.IsStringKind, 177 "is_string_kind": mojom_generator.IsStringKind,
158 "is_array_kind": lambda kind: isinstance(kind, mojom.Array), 178 "is_array_kind": lambda kind: isinstance(kind, mojom.Array),
159 "is_struct_with_handles": IsStructWithHandles, 179 "is_struct_with_handles": IsStructWithHandles,
160 "struct_size": lambda ps: ps.GetTotalSize() + _HEADER_SIZE, 180 "struct_size": lambda ps: ps.GetTotalSize() + _HEADER_SIZE,
161 "struct_from_method": mojom_generator.GetStructFromMethod, 181 "struct_from_method": mojom_generator.GetStructFromMethod,
182 "response_struct_from_method": mojom_generator.GetResponseStructFromMethod,
162 "stylize_method": mojom_generator.StudlyCapsToCamel, 183 "stylize_method": mojom_generator.StudlyCapsToCamel,
163 "verify_token_type": mojom_generator.VerifyTokenType, 184 "verify_token_type": mojom_generator.VerifyTokenType,
164 } 185 }
165 186
166 def GetJinjaExports(self): 187 def GetJinjaExports(self):
167 return { 188 return {
168 "module": self.module, 189 "module": self.module,
169 "namespace": self.module.namespace, 190 "namespace": self.module.namespace,
170 "imports": self.module.imports, 191 "imports": self.module.imports,
171 "kinds": self.module.kinds, 192 "kinds": self.module.kinds,
(...skipping 12 matching lines...) Expand all
184 205
185 @UseJinja("cpp_templates/module.cc.tmpl", filters=cpp_filters) 206 @UseJinja("cpp_templates/module.cc.tmpl", filters=cpp_filters)
186 def GenerateModuleSource(self): 207 def GenerateModuleSource(self):
187 return self.GetJinjaExports() 208 return self.GetJinjaExports()
188 209
189 def GenerateFiles(self): 210 def GenerateFiles(self):
190 self.Write(self.GenerateModuleHeader(), "%s.h" % self.module.name) 211 self.Write(self.GenerateModuleHeader(), "%s.h" % self.module.name)
191 self.Write(self.GenerateModuleInternalHeader(), 212 self.Write(self.GenerateModuleInternalHeader(),
192 "%s-internal.h" % self.module.name) 213 "%s-internal.h" % self.module.name)
193 self.Write(self.GenerateModuleSource(), "%s.cc" % self.module.name) 214 self.Write(self.GenerateModuleSource(), "%s.cc" % self.module.name)
OLDNEW
« no previous file with comments | « mojo/public/bindings/generators/cpp_templates/params_definition.tmpl ('k') | mojo/public/bindings/lib/callback_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698