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

Unified Diff: mojo/public/tools/bindings/generators/mojom_cpp_generator.py

Issue 2689513003: Add field-initializing constructors to generated mojo structs. (Closed)
Patch Set: Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/tools/bindings/generators/mojom_cpp_generator.py
diff --git a/mojo/public/tools/bindings/generators/mojom_cpp_generator.py b/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
index c75013badf88a19cab5a678a1b77174e20c877fc..a780e880cbf67c52d44d8d42efd643358e445360 100644
--- a/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
+++ b/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
@@ -482,6 +482,17 @@ def ShouldInlineUnion(union):
mojom.IsReferenceKind(field.kind) and not mojom.IsStringKind(field.kind)
for field in union.fields)
+
+def GetNumConstructorParams(kind):
+ for i, field in enumerate(kind.fields):
+ # Types that are neither copyable nor movable can't be passed to a struct
+ # constructor so any constructors containing such a kind are skipped.
+ if (mojom.IsStructKind(field.kind) and IsTypemappedKind(field.kind) and
yzshen1 2017/02/14 17:21:53 I think there is no need to check IsStructKind(),
Sam McNally 2017/02/15 06:35:49 Done.
+ _current_typemap[GetFullMojomNameForKind(field.kind)]["emplace_only"]):
+ return i
+ return len(kind.fields) + 1
+
+
def GetContainerValidateParamsCtorArgs(kind):
if mojom.IsStringKind(kind):
expected_num_elements = 0
@@ -571,6 +582,7 @@ class Generator(generator.Generator):
"is_struct_kind": mojom.IsStructKind,
"is_typemapped_kind": IsTypemappedKind,
"is_union_kind": mojom.IsUnionKind,
+ "num_constructor_params": GetNumConstructorParams,
"passes_associated_kinds": mojom.PassesAssociatedKinds,
"stylize_method": generator.StudlyCapsToCamel,
"under_to_camel": generator.UnderToCamel,

Powered by Google App Engine
This is Rietveld 408576698