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 """Generates C++ source files from a mojom.Module.""" | 5 """Generates C++ source files from a mojom.Module.""" |
6 | 6 |
7 import mojom.generate.generator as generator | 7 import mojom.generate.generator as generator |
8 import mojom.generate.module as mojom | 8 import mojom.generate.module as mojom |
9 import mojom.generate.pack as pack | 9 import mojom.generate.pack as pack |
10 from mojom.generate.template_expander import UseJinja | 10 from mojom.generate.template_expander import UseJinja |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 name.append( | 221 name.append( |
222 "%s_%s" % (generator.CamelCaseToAllCaps(token.enum_name), token.name)) | 222 "%s_%s" % (generator.CamelCaseToAllCaps(token.enum_name), token.name)) |
223 else: | 223 else: |
224 name.append(token.name) | 224 name.append(token.name) |
225 return "::".join(name) | 225 return "::".join(name) |
226 return '%s%s' % (token, _kind_to_cpp_literal_suffix.get(kind, '')) | 226 return '%s%s' % (token, _kind_to_cpp_literal_suffix.get(kind, '')) |
227 | 227 |
228 def ExpressionToText(value, kind=None): | 228 def ExpressionToText(value, kind=None): |
229 return TranslateConstants(value, kind) | 229 return TranslateConstants(value, kind) |
230 | 230 |
231 def HasCallbacks(interface): | |
232 for method in interface.methods: | |
233 if method.response_parameters != None: | |
234 return True | |
235 return False | |
236 | |
237 def ShouldInlineStruct(struct): | 231 def ShouldInlineStruct(struct): |
238 # TODO(darin): Base this on the size of the wrapper class. | 232 # TODO(darin): Base this on the size of the wrapper class. |
239 if len(struct.fields) > 4: | 233 if len(struct.fields) > 4: |
240 return False | 234 return False |
241 for field in struct.fields: | 235 for field in struct.fields: |
242 if mojom.IsMoveOnlyKind(field.kind): | 236 if mojom.IsMoveOnlyKind(field.kind): |
243 return False | 237 return False |
244 return True | 238 return True |
245 | 239 |
246 _HEADER_SIZE = 8 | 240 _HEADER_SIZE = 8 |
247 | 241 |
248 class Generator(generator.Generator): | 242 class Generator(generator.Generator): |
249 | 243 |
250 cpp_filters = { | 244 cpp_filters = { |
251 "constant_value": ConstantValue, | 245 "constant_value": ConstantValue, |
252 "cpp_const_wrapper_type": GetCppConstWrapperType, | 246 "cpp_const_wrapper_type": GetCppConstWrapperType, |
253 "cpp_field_type": GetCppFieldType, | 247 "cpp_field_type": GetCppFieldType, |
254 "cpp_pod_type": GetCppPodType, | 248 "cpp_pod_type": GetCppPodType, |
255 "cpp_result_type": GetCppResultWrapperType, | 249 "cpp_result_type": GetCppResultWrapperType, |
256 "cpp_type": GetCppType, | 250 "cpp_type": GetCppType, |
257 "cpp_wrapper_type": GetCppWrapperType, | 251 "cpp_wrapper_type": GetCppWrapperType, |
258 "default_value": DefaultValue, | 252 "default_value": DefaultValue, |
259 "expected_array_size": generator.ExpectedArraySize, | 253 "expected_array_size": generator.ExpectedArraySize, |
260 "expression_to_text": ExpressionToText, | 254 "expression_to_text": ExpressionToText, |
261 "get_name_for_kind": GetNameForKind, | 255 "get_name_for_kind": GetNameForKind, |
262 "get_pad": pack.GetPad, | 256 "get_pad": pack.GetPad, |
263 "has_callbacks": HasCallbacks, | 257 "has_callbacks": mojom.HasCallbacks, |
264 "should_inline": ShouldInlineStruct, | 258 "should_inline": ShouldInlineStruct, |
265 "is_any_array_kind": mojom.IsAnyArrayKind, | 259 "is_any_array_kind": mojom.IsAnyArrayKind, |
266 "is_enum_kind": mojom.IsEnumKind, | 260 "is_enum_kind": mojom.IsEnumKind, |
267 "is_move_only_kind": mojom.IsMoveOnlyKind, | 261 "is_move_only_kind": mojom.IsMoveOnlyKind, |
268 "is_any_handle_kind": mojom.IsAnyHandleKind, | 262 "is_any_handle_kind": mojom.IsAnyHandleKind, |
269 "is_interface_kind": mojom.IsInterfaceKind, | 263 "is_interface_kind": mojom.IsInterfaceKind, |
270 "is_interface_request_kind": mojom.IsInterfaceRequestKind, | 264 "is_interface_request_kind": mojom.IsInterfaceRequestKind, |
271 "is_object_kind": mojom.IsObjectKind, | 265 "is_object_kind": mojom.IsObjectKind, |
272 "is_string_kind": mojom.IsStringKind, | 266 "is_string_kind": mojom.IsStringKind, |
273 "is_struct_with_handles": IsStructWithHandles, | 267 "is_struct_with_handles": IsStructWithHandles, |
(...skipping 26 matching lines...) Expand all Loading... |
300 | 294 |
301 @UseJinja("cpp_templates/module.cc.tmpl", filters=cpp_filters) | 295 @UseJinja("cpp_templates/module.cc.tmpl", filters=cpp_filters) |
302 def GenerateModuleSource(self): | 296 def GenerateModuleSource(self): |
303 return self.GetJinjaExports() | 297 return self.GetJinjaExports() |
304 | 298 |
305 def GenerateFiles(self, args): | 299 def GenerateFiles(self, args): |
306 self.Write(self.GenerateModuleHeader(), "%s.h" % self.module.name) | 300 self.Write(self.GenerateModuleHeader(), "%s.h" % self.module.name) |
307 self.Write(self.GenerateModuleInternalHeader(), | 301 self.Write(self.GenerateModuleInternalHeader(), |
308 "%s-internal.h" % self.module.name) | 302 "%s-internal.h" % self.module.name) |
309 self.Write(self.GenerateModuleSource(), "%s.cc" % self.module.name) | 303 self.Write(self.GenerateModuleSource(), "%s.cc" % self.module.name) |
OLD | NEW |