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

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

Issue 2244363003: Mojo C++ bindings: disallow copy and assign for generated classes when necessary. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: the actual fix Created 4 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
« no previous file with comments | « mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 376
377 def ShouldInlineStruct(struct): 377 def ShouldInlineStruct(struct):
378 # TODO(darin): Base this on the size of the wrapper class. 378 # TODO(darin): Base this on the size of the wrapper class.
379 if len(struct.fields) > 4: 379 if len(struct.fields) > 4:
380 return False 380 return False
381 for field in struct.fields: 381 for field in struct.fields:
382 if mojom.IsReferenceKind(field.kind) and not mojom.IsStringKind(field.kind): 382 if mojom.IsReferenceKind(field.kind) and not mojom.IsStringKind(field.kind):
383 return False 383 return False
384 return True 384 return True
385 385
386 def ContainsMoveOnlyMembers(struct):
387 for field in struct.fields:
388 if IsMoveOnlyKind(field.kind):
389 return True
390 return False
391
386 def ShouldInlineUnion(union): 392 def ShouldInlineUnion(union):
387 return not any( 393 return not any(
388 mojom.IsReferenceKind(field.kind) and not mojom.IsStringKind(field.kind) 394 mojom.IsReferenceKind(field.kind) and not mojom.IsStringKind(field.kind)
389 for field in union.fields) 395 for field in union.fields)
390 396
391 def GetContainerValidateParamsCtorArgs(kind): 397 def GetContainerValidateParamsCtorArgs(kind):
392 if mojom.IsStringKind(kind): 398 if mojom.IsStringKind(kind):
393 expected_num_elements = 0 399 expected_num_elements = 0
394 element_is_nullable = False 400 element_is_nullable = False
395 key_validate_params = "nullptr" 401 key_validate_params = "nullptr"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 not mojom.IsStringKind(kind)): 435 not mojom.IsStringKind(kind)):
430 return "nullptr" 436 return "nullptr"
431 437
432 return "new mojo::internal::ContainerValidateParams(%s)" % ( 438 return "new mojo::internal::ContainerValidateParams(%s)" % (
433 GetContainerValidateParamsCtorArgs(kind)) 439 GetContainerValidateParamsCtorArgs(kind))
434 440
435 class Generator(generator.Generator): 441 class Generator(generator.Generator):
436 442
437 cpp_filters = { 443 cpp_filters = {
438 "constant_value": ConstantValue, 444 "constant_value": ConstantValue,
445 "contains_move_only_members": ContainsMoveOnlyMembers,
439 "cpp_wrapper_param_type": GetCppWrapperParamType, 446 "cpp_wrapper_param_type": GetCppWrapperParamType,
440 "cpp_data_view_type": GetCppDataViewType, 447 "cpp_data_view_type": GetCppDataViewType,
441 "cpp_field_type": GetCppFieldType, 448 "cpp_field_type": GetCppFieldType,
442 "cpp_union_field_type": GetCppUnionFieldType, 449 "cpp_union_field_type": GetCppUnionFieldType,
443 "cpp_pod_type": GetCppPodType, 450 "cpp_pod_type": GetCppPodType,
444 "cpp_union_getter_return_type": GetUnionGetterReturnType, 451 "cpp_union_getter_return_type": GetUnionGetterReturnType,
445 "cpp_wrapper_type": GetCppWrapperType, 452 "cpp_wrapper_type": GetCppWrapperType,
446 "default_value": DefaultValue, 453 "default_value": DefaultValue,
447 "expression_to_text": ExpressionToText, 454 "expression_to_text": ExpressionToText,
448 "get_container_validate_params_ctor_args": 455 "get_container_validate_params_ctor_args":
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 _variant = self.variant 566 _variant = self.variant
560 suffix = "-%s" % self.variant if self.variant else "" 567 suffix = "-%s" % self.variant if self.variant else ""
561 self.Write(self.GenerateModuleHeader(), 568 self.Write(self.GenerateModuleHeader(),
562 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) 569 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix)))
563 self.Write(self.GenerateModuleInternalHeader(), 570 self.Write(self.GenerateModuleInternalHeader(),
564 self.MatchMojomFilePath("%s%s-internal.h" % 571 self.MatchMojomFilePath("%s%s-internal.h" %
565 (self.module.name, suffix))) 572 (self.module.name, suffix)))
566 self.Write( 573 self.Write(
567 self.GenerateModuleSource(), 574 self.GenerateModuleSource(),
568 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix))) 575 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix)))
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698