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

Unified Diff: third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/union_declaration.tmpl

Issue 910883002: Update mojo sdk to rev 8af2ccff2eee4bfca1043015abee30482a030b30 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Apply 9f87aeadbda22441b7d469e596f7bd7d0d73e2a8 (https://codereview.chromium.org/908973002/) Created 5 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: third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/union_declaration.tmpl
diff --git a/third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/union_declaration.tmpl b/third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/union_declaration.tmpl
new file mode 100644
index 0000000000000000000000000000000000000000..6e6fe95a74c1dc207af7f5d252494a1936fd7e14
--- /dev/null
+++ b/third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/union_declaration.tmpl
@@ -0,0 +1,50 @@
+{%- set class_name = union.name ~ "_Data" -%}
+{%- set enum_name = union.name ~ "_Tag" -%}
+{%- import "struct_macros.tmpl" as struct_macros %}
+
+class {{class_name}} {
+ public:
+ static {{class_name}}* New(mojo::internal::Buffer* buf);
+
+ static bool Validate(const void* data,
+ mojo::internal::BoundsChecker* bounds_checker);
+
+ enum class {{enum_name}} : uint32_t {
+{% for field in union.fields %}
+ {{field.name|upper}},
+{%- endfor %}
+ };
+
+ // A note on layout:
+ // "Each non-static data member is allocated as if it were the sole member of
+ // a struct." - Section 9.5.2 ISO/IEC 14882:2011 (The C++ Spec)
+ union MOJO_ALIGNAS(8) Union_ {
+{%- for field in union.fields %}
+{%- if field.kind|is_string_kind %}
+ uint64_t f_{{field.name}};
+{%- elif field.kind.spec == 'b' %}
+ uint8_t f_{{field.name}} : 1;
+{%- elif field.kind|is_enum_kind %}
+ int32_t f_{{field.name}};
+{%- else %}
+ {{field.kind|cpp_pod_type}} f_{{field.name}};
+{%- endif %}
+{%- endfor %}
+ uint64_t unknown;
+ };
+
+ uint32_t reserved;
+ {{enum_name}} tag;
+ Union_ data;
+
+ void EncodePointersAndHandles(std::vector<mojo::Handle>* handles);
+ void DecodePointersAndHandles(std::vector<mojo::Handle>* handles);
+
+ private:
+ {{class_name}}();
+ ~{{class_name}}() = delete;
+};
+static_assert(sizeof({{class_name}}) == 16,
+ "Bad sizeof({{class_name}})");
+static_assert(sizeof({{class_name}}::Union_) == 8,
+ "Bad sizeof({{class_name}}::Union_)");

Powered by Google App Engine
This is Rietveld 408576698