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

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..311916a56a199c962f9fc0ef2160c63cc3051c7b 100644
--- a/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
+++ b/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
@@ -482,6 +482,18 @@ 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):
+ # mojo.common.mojom.LegacyListValue is neither copyable nor movable so can't
yzshen1 2017/02/13 17:45:53 It is unfortunate to have a special case for this.
Sam McNally 2017/02/14 02:32:24 Done.
+ # be passed to a struct constructor so any constructors containing this
+ # struct are skipped.
+ if (mojom.IsStructKind(field.kind) and GetFullMojomNameForKind(
+ field.kind) == "mojo.common.mojom.LegacyListValue"):
+ return i
+ return len(kind.fields) + 1
+
+
def GetContainerValidateParamsCtorArgs(kind):
if mojom.IsStringKind(kind):
expected_num_elements = 0
@@ -571,6 +583,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