summaryrefslogtreecommitdiff
path: root/mojo/public/tools/bindings
diff options
context:
space:
mode:
Diffstat (limited to 'mojo/public/tools/bindings')
-rw-r--r--mojo/public/tools/bindings/generators/cpp_templates/module-shared-internal.h.tmpl7
-rw-r--r--mojo/public/tools/bindings/generators/cpp_templates/module-shared.h.tmpl7
-rw-r--r--mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl9
-rw-r--r--mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl4
-rw-r--r--mojo/public/tools/bindings/generators/mojom_cpp_generator.py8
-rw-r--r--mojo/public/tools/bindings/mojom.gni23
-rwxr-xr-xmojo/public/tools/bindings/mojom_bindings_generator.py8
-rw-r--r--mojo/public/tools/bindings/pylib/mojom/generate/generator.py3
-rw-r--r--mojo/public/tools/bindings/pylib/mojom/generate/module.py4
-rw-r--r--mojo/public/tools/bindings/pylib/mojom/generate/translate.py3
10 files changed, 66 insertions, 10 deletions
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/module-shared-internal.h.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/module-shared-internal.h.tmpl
index 3033a997e0..21e5025843 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/module-shared-internal.h.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/module-shared-internal.h.tmpl
@@ -15,13 +15,16 @@
#include "mojo/public/cpp/bindings/lib/bindings_internal.h"
#include "mojo/public/cpp/bindings/lib/map_data_internal.h"
#include "mojo/public/cpp/bindings/lib/native_enum_data.h"
-#include "mojo/public/cpp/bindings/lib/native_struct_data.h"
#include "mojo/public/cpp/bindings/lib/buffer.h"
{%- for import in imports %}
#include "{{import.path}}-shared-internal.h"
{%- endfor %}
+{%- if allow_native_structs %}
+#include "mojo/public/interfaces/bindings/native_struct.mojom-shared-internal.h"
+{%- endif %}
+
{%- if export_header %}
#include "{{export_header}}"
{%- endif %}
@@ -40,7 +43,7 @@ namespace internal {
{#--- Internal forward declarations #}
{%- for struct in structs %}
{%- if struct|is_native_only_kind %}
-using {{struct.name}}_Data = mojo::internal::NativeStruct_Data;
+using {{struct.name}}_Data = mojo::native::internal::NativeStruct_Data;
{%- else %}
class {{struct.name}}_Data;
{%- endif %}
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/module-shared.h.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/module-shared.h.tmpl
index 148dc7aeb5..58ced630ee 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/module-shared.h.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/module-shared.h.tmpl
@@ -50,13 +50,16 @@ namespace {{namespace}} {
#include "mojo/public/cpp/bindings/lib/serialization.h"
#include "mojo/public/cpp/bindings/map_data_view.h"
#include "mojo/public/cpp/bindings/native_enum.h"
-#include "mojo/public/cpp/bindings/native_struct_data_view.h"
#include "mojo/public/cpp/bindings/string_data_view.h"
#include "{{module.path}}-shared-internal.h"
{%- for import in imports %}
#include "{{import.path}}-shared.h"
{%- endfor %}
+{% if allow_native_structs %}
+#include "mojo/public/cpp/bindings/lib/native_struct_serialization.h"
+{%- endif %}
+
{%- if export_header %}
#include "{{export_header}}"
{%- endif %}
@@ -66,7 +69,7 @@ namespace {{namespace}} {
{#--- Struct Forward Declarations -#}
{%- for struct in structs %}
{%- if struct|is_native_only_kind %}
-using {{struct.name}}DataView = mojo::NativeStructDataView;
+using {{struct.name}}DataView = mojo::native::NativeStructDataView;
{%- else %}
class {{struct.name}}DataView;
{%- endif %}
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl
index 6460ebac40..a90f642281 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl
@@ -52,7 +52,6 @@ namespace {{variant}} {
#include "mojo/public/cpp/bindings/lib/control_message_handler.h"
#include "mojo/public/cpp/bindings/lib/control_message_proxy.h"
#include "mojo/public/cpp/bindings/lib/serialization.h"
-#include "mojo/public/cpp/bindings/native_struct.h"
#include "mojo/public/cpp/bindings/raw_ptr_impl_ref_traits.h"
#include "mojo/public/cpp/bindings/struct_ptr.h"
#include "mojo/public/cpp/bindings/struct_traits.h"
@@ -78,6 +77,10 @@ namespace {{variant}} {
#include "third_party/WebKit/Source/platform/wtf/text/WTFString.h"
{%- endif %}
+{% if allow_native_structs %}
+#include "mojo/public/cpp/bindings/lib/native_struct_serialization.h"
+{%- endif %}
+
{%- for header in extra_public_headers %}
#include "{{header}}"
{%- endfor %}
@@ -131,8 +134,8 @@ using {{interface.name}}AssociatedRequest =
{#--- Struct Forward Declarations -#}
{% for struct in structs %}
{%- if struct|is_native_only_kind %}
-using {{struct.name}} = mojo::NativeStruct;
-using {{struct.name}}Ptr = mojo::NativeStructPtr;
+using {{struct.name}} = mojo::native::NativeStruct;
+using {{struct.name}}Ptr = mojo::native::NativeStructPtr;
{%- else %}
class {{struct.name}};
{%- if struct|should_inline %}
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl
index 61799a8f26..5571e8449f 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl
@@ -2,6 +2,8 @@
{%- set data_view = struct|get_qualified_name_for_kind ~ "DataView" %}
{%- set data_type = struct|get_qualified_name_for_kind(internal=True) %}
+{%- if not struct|use_custom_serializer %}
+
namespace internal {
template <typename MaybeConstUserType>
@@ -35,3 +37,5 @@ struct Serializer<{{data_view}}, MaybeConstUserType> {
};
} // namespace internal
+
+{%- endif %}
diff --git a/mojo/public/tools/bindings/generators/mojom_cpp_generator.py b/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
index 08514cb7b5..c60e36d593 100644
--- a/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
+++ b/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
@@ -134,6 +134,10 @@ def IsNativeOnlyKind(kind):
kind.native_only
+def UseCustomSerializer(kind):
+ return mojom.IsStructKind(kind) and kind.custom_serializer
+
+
def AllEnumValues(enum):
"""Return all enum values associated with an enum.
@@ -286,6 +290,7 @@ class Generator(generator.Generator):
return {
"all_enums": all_enums,
+ "allow_native_structs": self.allow_native_structs,
"enums": self.module.enums,
"export_attribute": self.export_attribute,
"export_header": self.export_header,
@@ -359,6 +364,7 @@ class Generator(generator.Generator):
"struct_constructors": self._GetStructConstructors,
"under_to_camel": generator.ToCamel,
"unmapped_type_for_serializer": self._GetUnmappedTypeForSerializer,
+ "use_custom_serializer": UseCustomSerializer,
"wtf_hash_fn_name_for_enum": GetWtfHashFnNameForEnum,
}
return cpp_filters
@@ -457,6 +463,8 @@ class Generator(generator.Generator):
if mojom.IsNullableKind(kind):
return False
elif mojom.IsStructKind(kind):
+ if kind.native_only:
+ return False
if (self._IsTypemappedKind(kind) and
not self.typemap[self._GetFullMojomNameForKind(kind)]["hashable"]):
return False
diff --git a/mojo/public/tools/bindings/mojom.gni b/mojo/public/tools/bindings/mojom.gni
index 5018a7b093..5fa42bfff9 100644
--- a/mojo/public/tools/bindings/mojom.gni
+++ b/mojo/public/tools/bindings/mojom.gni
@@ -174,6 +174,16 @@ if (enable_mojom_typemapping) {
# deserialization, and validation logic at the expensive of increased
# code size. Defaults to |false|.
#
+# disable_variants (optional)
+# If |true|, no variant sources will be generated for the target. Defaults
+# to |false|.
+#
+# allow_native_structs (optional)
+# If set to |true| (the default), mojoms in this target may apply the
+# [Native] attribute to struct declarations, causing that mojom struct to
+# be serialized and deserialized using a legacy IPC::ParamTraits
+# specialization.
+#
# component_output_prefix (optional)
# The prefix to use for the output_name of any component library emitted
# for generated C++ bindings. If this is omitted, C++ bindings targets are
@@ -313,6 +323,10 @@ template("mojom") {
rebase_path("$root_gen_dir/mojo/public/tools/bindings", root_build_dir),
]
+ if (!defined(invoker.allow_native_structs) || invoker.allow_native_structs) {
+ common_generator_args += [ "--allow_native_structs" ]
+ }
+
if (defined(invoker.import_dirs)) {
foreach(import_dir, invoker.import_dirs) {
common_generator_args += [
@@ -476,7 +490,14 @@ template("mojom") {
}
# Generate code for variants.
- foreach(bindings_configuration, _bindings_configurations) {
+ if (!defined(invoker.disable_variants) || !invoker.disable_variants) {
+ enabled_configurations = _bindings_configurations
+ } else {
+ first_config = _bindings_configurations[0]
+ assert(!defined(first_config.variant))
+ enabled_configurations = [ first_config ]
+ }
+ foreach(bindings_configuration, enabled_configurations) {
cpp_only = false
if (defined(invoker.cpp_only)) {
cpp_only = invoker.cpp_only
diff --git a/mojo/public/tools/bindings/mojom_bindings_generator.py b/mojo/public/tools/bindings/mojom_bindings_generator.py
index cc8101613e..a12f8917b5 100755
--- a/mojo/public/tools/bindings/mojom_bindings_generator.py
+++ b/mojo/public/tools/bindings/mojom_bindings_generator.py
@@ -208,7 +208,8 @@ class MojomProcessor(object):
export_attribute=args.export_attribute,
export_header=args.export_header,
generate_non_variant_code=args.generate_non_variant_code,
- support_lazy_serialization=args.support_lazy_serialization)
+ support_lazy_serialization=args.support_lazy_serialization,
+ allow_native_structs=args.allow_native_structs)
filtered_args = []
if hasattr(generator_module, 'GENERATOR_PREFIX'):
prefix = '--' + generator_module.GENERATOR_PREFIX + '_'
@@ -367,6 +368,11 @@ def main():
"--support_lazy_serialization",
help="If set, generated bindings will serialize lazily when possible.",
action="store_true")
+ generate_parser.add_argument(
+ "--allow_native_structs",
+ help="Allows the [Native] attribute to be specified on structs within "
+ "the mojom file. Must not be specified on internal bindings mojom or "
+ "other dependencies thereof.", action="store_true")
generate_parser.set_defaults(func=_Generate)
precompile_parser = subparsers.add_parser("precompile",
diff --git a/mojo/public/tools/bindings/pylib/mojom/generate/generator.py b/mojo/public/tools/bindings/pylib/mojom/generate/generator.py
index 4d81a13dbd..f59c33db21 100644
--- a/mojo/public/tools/bindings/pylib/mojom/generate/generator.py
+++ b/mojo/public/tools/bindings/pylib/mojom/generate/generator.py
@@ -157,7 +157,7 @@ class Generator(object):
bytecode_path=None, for_blink=False, use_once_callback=False,
js_bindings_mode="new", export_attribute=None,
export_header=None, generate_non_variant_code=False,
- support_lazy_serialization=False):
+ support_lazy_serialization=False, allow_native_structs=False):
self.module = module
self.output_dir = output_dir
self.typemap = typemap or {}
@@ -170,6 +170,7 @@ class Generator(object):
self.export_header = export_header
self.generate_non_variant_code = generate_non_variant_code
self.support_lazy_serialization = support_lazy_serialization
+ self.allow_native_structs = allow_native_structs
def Write(self, contents, filename):
if self.output_dir is None:
diff --git a/mojo/public/tools/bindings/pylib/mojom/generate/module.py b/mojo/public/tools/bindings/pylib/mojom/generate/module.py
index 8208f7b5dd..ebe5601b0a 100644
--- a/mojo/public/tools/bindings/pylib/mojom/generate/module.py
+++ b/mojo/public/tools/bindings/pylib/mojom/generate/module.py
@@ -316,6 +316,8 @@ class Struct(ReferenceKind):
name: {str} The stylized name.
native_only: {bool} Does the struct have a body (i.e. any fields) or is it
purely a native struct.
+ custom_serializer: {bool} Should we generate a serializer for the struct or
+ will one be provided by non-generated code.
fields: {List[StructField]} The members of the struct.
enums: {List[Enum]} The enums defined in the struct scope.
constants: {List[Constant]} The constants defined in the struct scope.
@@ -326,6 +328,7 @@ class Struct(ReferenceKind):
ReferenceKind.AddSharedProperty('mojom_name')
ReferenceKind.AddSharedProperty('name')
ReferenceKind.AddSharedProperty('native_only')
+ ReferenceKind.AddSharedProperty('custom_serializer')
ReferenceKind.AddSharedProperty('fields')
ReferenceKind.AddSharedProperty('enums')
ReferenceKind.AddSharedProperty('constants')
@@ -339,6 +342,7 @@ class Struct(ReferenceKind):
ReferenceKind.__init__(self, spec, False, module)
self.mojom_name = mojom_name
self.native_only = False
+ self.custom_serializer = False
self.fields = []
self.enums = []
self.constants = []
diff --git a/mojo/public/tools/bindings/pylib/mojom/generate/translate.py b/mojo/public/tools/bindings/pylib/mojom/generate/translate.py
index f1d8f4264e..4153e7456c 100644
--- a/mojo/public/tools/bindings/pylib/mojom/generate/translate.py
+++ b/mojo/public/tools/bindings/pylib/mojom/generate/translate.py
@@ -273,6 +273,9 @@ def _Struct(module, parsed_struct):
raise Exception("Native-only struct declarations must include a " +
"Native attribute.")
+ if struct.attributes and struct.attributes.get('CustomSerializer', False):
+ struct.custom_serializer = True
+
return struct
def _Union(module, parsed_union):