| 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 def GetArrayValidateParams(kind): | 240 def GetArrayValidateParams(kind): |
| (...skipping 25 matching lines...) Expand all Loading... |
| 272 "cpp_pod_type": GetCppPodType, | 266 "cpp_pod_type": GetCppPodType, |
| 273 "cpp_result_type": GetCppResultWrapperType, | 267 "cpp_result_type": GetCppResultWrapperType, |
| 274 "cpp_type": GetCppType, | 268 "cpp_type": GetCppType, |
| 275 "cpp_wrapper_type": GetCppWrapperType, | 269 "cpp_wrapper_type": GetCppWrapperType, |
| 276 "default_value": DefaultValue, | 270 "default_value": DefaultValue, |
| 277 "expected_array_size": generator.ExpectedArraySize, | 271 "expected_array_size": generator.ExpectedArraySize, |
| 278 "expression_to_text": ExpressionToText, | 272 "expression_to_text": ExpressionToText, |
| 279 "get_array_validate_params": GetArrayValidateParams, | 273 "get_array_validate_params": GetArrayValidateParams, |
| 280 "get_name_for_kind": GetNameForKind, | 274 "get_name_for_kind": GetNameForKind, |
| 281 "get_pad": pack.GetPad, | 275 "get_pad": pack.GetPad, |
| 282 "has_callbacks": HasCallbacks, | 276 "has_callbacks": mojom.HasCallbacks, |
| 283 "should_inline": ShouldInlineStruct, | 277 "should_inline": ShouldInlineStruct, |
| 284 "is_any_array_kind": mojom.IsAnyArrayKind, | 278 "is_any_array_kind": mojom.IsAnyArrayKind, |
| 285 "is_enum_kind": mojom.IsEnumKind, | 279 "is_enum_kind": mojom.IsEnumKind, |
| 286 "is_move_only_kind": mojom.IsMoveOnlyKind, | 280 "is_move_only_kind": mojom.IsMoveOnlyKind, |
| 287 "is_any_handle_kind": mojom.IsAnyHandleKind, | 281 "is_any_handle_kind": mojom.IsAnyHandleKind, |
| 288 "is_interface_kind": mojom.IsInterfaceKind, | 282 "is_interface_kind": mojom.IsInterfaceKind, |
| 289 "is_interface_request_kind": mojom.IsInterfaceRequestKind, | 283 "is_interface_request_kind": mojom.IsInterfaceRequestKind, |
| 290 "is_nullable_kind": mojom.IsNullableKind, | 284 "is_nullable_kind": mojom.IsNullableKind, |
| 291 "is_object_kind": mojom.IsObjectKind, | 285 "is_object_kind": mojom.IsObjectKind, |
| 292 "is_string_kind": mojom.IsStringKind, | 286 "is_string_kind": mojom.IsStringKind, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 320 | 314 |
| 321 @UseJinja("cpp_templates/module.cc.tmpl", filters=cpp_filters) | 315 @UseJinja("cpp_templates/module.cc.tmpl", filters=cpp_filters) |
| 322 def GenerateModuleSource(self): | 316 def GenerateModuleSource(self): |
| 323 return self.GetJinjaExports() | 317 return self.GetJinjaExports() |
| 324 | 318 |
| 325 def GenerateFiles(self, args): | 319 def GenerateFiles(self, args): |
| 326 self.Write(self.GenerateModuleHeader(), "%s.h" % self.module.name) | 320 self.Write(self.GenerateModuleHeader(), "%s.h" % self.module.name) |
| 327 self.Write(self.GenerateModuleInternalHeader(), | 321 self.Write(self.GenerateModuleInternalHeader(), |
| 328 "%s-internal.h" % self.module.name) | 322 "%s-internal.h" % self.module.name) |
| 329 self.Write(self.GenerateModuleSource(), "%s.cc" % self.module.name) | 323 self.Write(self.GenerateModuleSource(), "%s.cc" % self.module.name) |
| OLD | NEW |