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

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

Issue 2199043002: Mojo C++ bindings: inline struct data view field getters. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@84_counter
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/struct_data_view_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):
372 for field in struct.fields:
373 if mojom.IsReferenceKind(field.kind):
374 return True
375 return False
376
371 def ShouldInlineStruct(struct): 377 def ShouldInlineStruct(struct):
372 # TODO(darin): Base this on the size of the wrapper class. 378 # TODO(darin): Base this on the size of the wrapper class.
373 if len(struct.fields) > 4: 379 if len(struct.fields) > 4:
374 return False 380 return False
375 for field in struct.fields: 381 for field in struct.fields:
376 if mojom.IsReferenceKind(field.kind) and not mojom.IsStringKind(field.kind): 382 if mojom.IsReferenceKind(field.kind) and not mojom.IsStringKind(field.kind):
377 return False 383 return False
378 return True 384 return True
379 385
380 def ShouldInlineUnion(union): 386 def ShouldInlineUnion(union):
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 "cpp_wrapper_type": GetCppWrapperType, 445 "cpp_wrapper_type": GetCppWrapperType,
440 "default_value": DefaultValue, 446 "default_value": DefaultValue,
441 "expression_to_text": ExpressionToText, 447 "expression_to_text": ExpressionToText,
442 "get_container_validate_params_ctor_args": 448 "get_container_validate_params_ctor_args":
443 GetContainerValidateParamsCtorArgs, 449 GetContainerValidateParamsCtorArgs,
444 "get_name_for_kind": GetNameForKind, 450 "get_name_for_kind": GetNameForKind,
445 "get_pad": pack.GetPad, 451 "get_pad": pack.GetPad,
446 "get_qualified_name_for_kind": GetQualifiedNameForKind, 452 "get_qualified_name_for_kind": GetQualifiedNameForKind,
447 "has_callbacks": mojom.HasCallbacks, 453 "has_callbacks": mojom.HasCallbacks,
448 "has_sync_methods": mojom.HasSyncMethods, 454 "has_sync_methods": mojom.HasSyncMethods,
455 "requires_context_for_data_view": RequiresContextForDataView,
449 "should_inline": ShouldInlineStruct, 456 "should_inline": ShouldInlineStruct,
450 "should_inline_union": ShouldInlineUnion, 457 "should_inline_union": ShouldInlineUnion,
451 "is_array_kind": mojom.IsArrayKind, 458 "is_array_kind": mojom.IsArrayKind,
452 "is_enum_kind": mojom.IsEnumKind, 459 "is_enum_kind": mojom.IsEnumKind,
453 "is_integral_kind": mojom.IsIntegralKind, 460 "is_integral_kind": mojom.IsIntegralKind,
454 "is_native_only_kind": IsNativeOnlyKind, 461 "is_native_only_kind": IsNativeOnlyKind,
455 "is_any_handle_or_interface_kind": mojom.IsAnyHandleOrInterfaceKind, 462 "is_any_handle_or_interface_kind": mojom.IsAnyHandleOrInterfaceKind,
456 "is_associated_kind": mojom.IsAssociatedKind, 463 "is_associated_kind": mojom.IsAssociatedKind,
457 "is_map_kind": mojom.IsMapKind, 464 "is_map_kind": mojom.IsMapKind,
458 "is_nullable_kind": mojom.IsNullableKind, 465 "is_nullable_kind": mojom.IsNullableKind,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 _use_new_wrapper_types = self.use_new_wrapper_types 534 _use_new_wrapper_types = self.use_new_wrapper_types
528 global _variant 535 global _variant
529 _variant = self.variant 536 _variant = self.variant
530 suffix = "-%s" % self.variant if self.variant else "" 537 suffix = "-%s" % self.variant if self.variant else ""
531 self.Write(self.GenerateModuleHeader(), 538 self.Write(self.GenerateModuleHeader(),
532 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) 539 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix)))
533 self.Write(self.GenerateModuleInternalHeader(), 540 self.Write(self.GenerateModuleInternalHeader(),
534 self.MatchMojomFilePath("%s%s-internal.h" % (self.module.name, suffix))) 541 self.MatchMojomFilePath("%s%s-internal.h" % (self.module.name, suffix)))
535 self.Write(self.GenerateModuleSource(), 542 self.Write(self.GenerateModuleSource(),
536 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix))) 543 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix)))
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/generators/cpp_templates/struct_data_view_definition.tmpl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698