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

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

Issue 2146153002: Mojo typemap config: support "copyable_pass_by_value" attribute. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@69_change_move_only
Patch Set: . Created 4 years, 5 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/generate_type_mappings.py ('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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): 220 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind):
221 return True 221 return True
222 if mojom.IsArrayKind(kind): 222 if mojom.IsArrayKind(kind):
223 return IsMoveOnlyKind(kind.kind) if _use_new_wrapper_types else True 223 return IsMoveOnlyKind(kind.kind) if _use_new_wrapper_types else True
224 if mojom.IsMapKind(kind): 224 if mojom.IsMapKind(kind):
225 return IsMoveOnlyKind(kind.value_kind) if _use_new_wrapper_types else True 225 return IsMoveOnlyKind(kind.value_kind) if _use_new_wrapper_types else True
226 if mojom.IsAnyHandleOrInterfaceKind(kind): 226 if mojom.IsAnyHandleOrInterfaceKind(kind):
227 return True 227 return True
228 return False 228 return False
229 229
230 def IsCopyablePassByValue(kind):
231 if not IsTypemappedKind(kind):
232 return False
233 return _current_typemap[GetFullMojomNameForKind(kind)][
234 "copyable_pass_by_value"]
235
230 def ShouldPassParamByValue(kind): 236 def ShouldPassParamByValue(kind):
231 return (not mojom.IsReferenceKind(kind)) or IsMoveOnlyKind(kind) 237 return ((not mojom.IsReferenceKind(kind)) or IsMoveOnlyKind(kind) or
238 IsCopyablePassByValue(kind))
232 239
233 def GetCppWrapperParamType(kind): 240 def GetCppWrapperParamType(kind):
234 cpp_wrapper_type = GetCppWrapperType(kind) 241 cpp_wrapper_type = GetCppWrapperType(kind)
235 return (cpp_wrapper_type if ShouldPassParamByValue(kind) 242 return (cpp_wrapper_type if ShouldPassParamByValue(kind)
236 else "const %s&" % cpp_wrapper_type) 243 else "const %s&" % cpp_wrapper_type)
237 244
238 def GetCppFieldType(kind): 245 def GetCppFieldType(kind):
239 if mojom.IsStructKind(kind): 246 if mojom.IsStructKind(kind):
240 return ("mojo::internal::Pointer<%s>" % 247 return ("mojo::internal::Pointer<%s>" %
241 GetNameForKind(kind, internal=True)) 248 GetNameForKind(kind, internal=True))
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 _use_new_wrapper_types = self.use_new_wrapper_types 507 _use_new_wrapper_types = self.use_new_wrapper_types
501 global _variant 508 global _variant
502 _variant = self.variant 509 _variant = self.variant
503 suffix = "-%s" % self.variant if self.variant else "" 510 suffix = "-%s" % self.variant if self.variant else ""
504 self.Write(self.GenerateModuleHeader(), 511 self.Write(self.GenerateModuleHeader(),
505 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) 512 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix)))
506 self.Write(self.GenerateModuleInternalHeader(), 513 self.Write(self.GenerateModuleInternalHeader(),
507 self.MatchMojomFilePath("%s%s-internal.h" % (self.module.name, suffix))) 514 self.MatchMojomFilePath("%s%s-internal.h" % (self.module.name, suffix)))
508 self.Write(self.GenerateModuleSource(), 515 self.Write(self.GenerateModuleSource(),
509 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix))) 516 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix)))
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/generate_type_mappings.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698