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

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

Issue 2226853002: Mojo C++ bindings: add support for UnionTraits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@85_10_inline_more
Patch Set: . 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_union_class_definition.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 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 # minus operator doesn't make sense on unsigned types. Doh! 361 # minus operator doesn't make sense on unsigned types. Doh!
362 if kind == mojom.INT32 and token == "-2147483648": 362 if kind == mojom.INT32 and token == "-2147483648":
363 return "(-%d - 1) /* %s */" % ( 363 return "(-%d - 1) /* %s */" % (
364 2**31 - 1, "Workaround for MSVC bug; see https://crbug.com/445618") 364 2**31 - 1, "Workaround for MSVC bug; see https://crbug.com/445618")
365 365
366 return "%s%s" % (token, _kind_to_cpp_literal_suffix.get(kind, "")) 366 return "%s%s" % (token, _kind_to_cpp_literal_suffix.get(kind, ""))
367 367
368 def ExpressionToText(value, kind=None): 368 def ExpressionToText(value, kind=None):
369 return TranslateConstants(value, kind) 369 return TranslateConstants(value, kind)
370 370
371 def RequiresContextForDataView(struct): 371 def RequiresContextForDataView(kind):
372 for field in struct.fields: 372 for field in kind.fields:
373 if mojom.IsReferenceKind(field.kind): 373 if mojom.IsReferenceKind(field.kind):
374 return True 374 return True
375 return False 375 return False
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):
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 _use_new_wrapper_types = self.use_new_wrapper_types 536 _use_new_wrapper_types = self.use_new_wrapper_types
537 global _variant 537 global _variant
538 _variant = self.variant 538 _variant = self.variant
539 suffix = "-%s" % self.variant if self.variant else "" 539 suffix = "-%s" % self.variant if self.variant else ""
540 self.Write(self.GenerateModuleHeader(), 540 self.Write(self.GenerateModuleHeader(),
541 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) 541 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix)))
542 self.Write(self.GenerateModuleInternalHeader(), 542 self.Write(self.GenerateModuleInternalHeader(),
543 self.MatchMojomFilePath("%s%s-internal.h" % (self.module.name, suffix))) 543 self.MatchMojomFilePath("%s%s-internal.h" % (self.module.name, suffix)))
544 self.Write(self.GenerateModuleSource(), 544 self.Write(self.GenerateModuleSource(),
545 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix))) 545 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix)))
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/generators/cpp_templates/wrapper_union_class_definition.tmpl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698