| 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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 235 |
| 236 def ShouldPassParamByValue(kind): | 236 def ShouldPassParamByValue(kind): |
| 237 return ((not mojom.IsReferenceKind(kind)) or IsMoveOnlyKind(kind) or | 237 return ((not mojom.IsReferenceKind(kind)) or IsMoveOnlyKind(kind) or |
| 238 IsCopyablePassByValue(kind)) | 238 IsCopyablePassByValue(kind)) |
| 239 | 239 |
| 240 def GetCppWrapperParamType(kind): | 240 def GetCppWrapperParamType(kind): |
| 241 cpp_wrapper_type = GetCppWrapperType(kind) | 241 cpp_wrapper_type = GetCppWrapperType(kind) |
| 242 return (cpp_wrapper_type if ShouldPassParamByValue(kind) | 242 return (cpp_wrapper_type if ShouldPassParamByValue(kind) |
| 243 else "const %s&" % cpp_wrapper_type) | 243 else "const %s&" % cpp_wrapper_type) |
| 244 | 244 |
| 245 def GetCppDataViewType(kind): |
| 246 if mojom.IsEnumKind(kind): |
| 247 return GetNameForKind(kind) |
| 248 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): |
| 249 return "%sDataView" % GetNameForKind(kind) |
| 250 if mojom.IsArrayKind(kind): |
| 251 return "mojo::ArrayDataView<%s>" % GetCppDataViewType(kind.kind) |
| 252 if mojom.IsMapKind(kind): |
| 253 return ("mojo::MapDataView<%s, %s>" % (GetCppDataViewType(kind.key_kind), |
| 254 GetCppDataViewType(kind.value_kind))) |
| 255 if mojom.IsStringKind(kind): |
| 256 return "mojo::StringDataView" |
| 257 return GetCppWrapperType(kind) |
| 258 |
| 245 def GetCppFieldType(kind): | 259 def GetCppFieldType(kind): |
| 246 if mojom.IsStructKind(kind): | 260 if mojom.IsStructKind(kind): |
| 247 return ("mojo::internal::Pointer<%s>" % | 261 return ("mojo::internal::Pointer<%s>" % |
| 248 GetNameForKind(kind, internal=True)) | 262 GetNameForKind(kind, internal=True)) |
| 249 if mojom.IsUnionKind(kind): | 263 if mojom.IsUnionKind(kind): |
| 250 return "%s" % GetNameForKind(kind, internal=True) | 264 return "%s" % GetNameForKind(kind, internal=True) |
| 251 if mojom.IsArrayKind(kind): | 265 if mojom.IsArrayKind(kind): |
| 252 return ("mojo::internal::Pointer<mojo::internal::Array_Data<%s>>" % | 266 return ("mojo::internal::Pointer<mojo::internal::Array_Data<%s>>" % |
| 253 GetCppFieldType(kind.kind)) | 267 GetCppFieldType(kind.kind)) |
| 254 if mojom.IsMapKind(kind): | 268 if mojom.IsMapKind(kind): |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 return "nullptr" | 419 return "nullptr" |
| 406 | 420 |
| 407 return "new mojo::internal::ContainerValidateParams(%s)" % ( | 421 return "new mojo::internal::ContainerValidateParams(%s)" % ( |
| 408 GetContainerValidateParamsCtorArgs(kind)) | 422 GetContainerValidateParamsCtorArgs(kind)) |
| 409 | 423 |
| 410 class Generator(generator.Generator): | 424 class Generator(generator.Generator): |
| 411 | 425 |
| 412 cpp_filters = { | 426 cpp_filters = { |
| 413 "constant_value": ConstantValue, | 427 "constant_value": ConstantValue, |
| 414 "cpp_wrapper_param_type": GetCppWrapperParamType, | 428 "cpp_wrapper_param_type": GetCppWrapperParamType, |
| 429 "cpp_data_view_type": GetCppDataViewType, |
| 415 "cpp_field_type": GetCppFieldType, | 430 "cpp_field_type": GetCppFieldType, |
| 416 "cpp_union_field_type": GetCppUnionFieldType, | 431 "cpp_union_field_type": GetCppUnionFieldType, |
| 417 "cpp_pod_type": GetCppPodType, | 432 "cpp_pod_type": GetCppPodType, |
| 418 "cpp_union_getter_return_type": GetUnionGetterReturnType, | 433 "cpp_union_getter_return_type": GetUnionGetterReturnType, |
| 419 "cpp_wrapper_type": GetCppWrapperType, | 434 "cpp_wrapper_type": GetCppWrapperType, |
| 420 "default_value": DefaultValue, | 435 "default_value": DefaultValue, |
| 421 "expression_to_text": ExpressionToText, | 436 "expression_to_text": ExpressionToText, |
| 422 "get_container_validate_params_ctor_args": | 437 "get_container_validate_params_ctor_args": |
| 423 GetContainerValidateParamsCtorArgs, | 438 GetContainerValidateParamsCtorArgs, |
| 424 "get_name_for_kind": GetNameForKind, | 439 "get_name_for_kind": GetNameForKind, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 _use_new_wrapper_types = self.use_new_wrapper_types | 522 _use_new_wrapper_types = self.use_new_wrapper_types |
| 508 global _variant | 523 global _variant |
| 509 _variant = self.variant | 524 _variant = self.variant |
| 510 suffix = "-%s" % self.variant if self.variant else "" | 525 suffix = "-%s" % self.variant if self.variant else "" |
| 511 self.Write(self.GenerateModuleHeader(), | 526 self.Write(self.GenerateModuleHeader(), |
| 512 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) | 527 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) |
| 513 self.Write(self.GenerateModuleInternalHeader(), | 528 self.Write(self.GenerateModuleInternalHeader(), |
| 514 self.MatchMojomFilePath("%s%s-internal.h" % (self.module.name, suffix))) | 529 self.MatchMojomFilePath("%s%s-internal.h" % (self.module.name, suffix))) |
| 515 self.Write(self.GenerateModuleSource(), | 530 self.Write(self.GenerateModuleSource(), |
| 516 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix))) | 531 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix))) |
| OLD | NEW |