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

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

Issue 1518293002: [mojo] Add Mojo bindings support for IPC::ParamTraits (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pickle4
Patch Set: Created 5 years 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
« no previous file with comments | « mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_definition.tmpl ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 f5219a3a3e1cf07e5b20428dabad720fff4cc4b7..6b2322eaf54b64544701bb682f243caba16a92dd 100644
--- a/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
+++ b/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
@@ -42,9 +42,25 @@ _kind_to_cpp_literal_suffix = {
mojom.UINT64: "ULL",
}
+
_current_variant = None
+_variant_metadata_attributes = {
+ "chromium": {
+ "typename": "ChromiumType",
+ "headers": "ChromiumHeaders",
+ },
+ "blink": {
+ "typename": "BlinkType",
+ "headers": "BlinkHeaders",
+ }
+}
+
+
+_variant_typemap = {}
+
+
def ConstantValue(constant):
return ExpressionToText(constant.value, kind=constant.kind)
@@ -56,6 +72,13 @@ def DefaultValue(field):
return ExpressionToText(field.default, kind=field.kind)
return ""
+def IsNativeKind(kind):
+ if hasattr(kind, "name") and kind.name in _variant_typemap:
+ return True
+
+def GetNativeTypeName(kind):
+ return _variant_typemap[kind.name]
+
def NamespaceToArray(namespace):
return namespace.split(".") if namespace else []
@@ -72,6 +95,11 @@ def GetNameForKind(kind, internal = False):
parts.append(kind.name)
return "::".join(parts)
+def GetQualifiedGenericInterfaceName(interface_kind):
+ parts = NamespaceToArray(interface_kind.module.namespace)
+ parts.append(interface_kind.name)
+ return "::".join(parts)
+
def GetCppType(kind):
if mojom.IsArrayKind(kind):
return "mojo::internal::Array_Data<%s>*" % GetCppType(kind.kind)
@@ -135,6 +163,8 @@ def GetCppArrayArgWrapperType(kind):
return _kind_to_cpp_type[kind]
def GetCppResultWrapperType(kind):
+ if IsNativeKind(kind):
+ return "const %s&" % GetNativeTypeName(kind)
if mojom.IsEnumKind(kind):
return GetNameForKind(kind)
if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind):
@@ -173,6 +203,8 @@ def GetCppResultWrapperType(kind):
raise Exception("Unrecognized kind %s" % kind.spec)
def GetCppWrapperType(kind):
+ if IsNativeKind(kind):
+ return GetNativeTypeName(kind)
if mojom.IsEnumKind(kind):
return GetNameForKind(kind)
if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind):
@@ -205,6 +237,8 @@ def GetCppWrapperType(kind):
return _kind_to_cpp_type.get(kind)
def GetCppConstWrapperType(kind):
+ if IsNativeKind(kind):
+ return "const %s&" % GetNativeTypeName(kind)
if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind):
return "%sPtr" % GetNameForKind(kind)
if mojom.IsArrayKind(kind):
@@ -239,6 +273,8 @@ def GetCppConstWrapperType(kind):
return _kind_to_cpp_type[kind]
def GetCppFieldType(kind):
+ if IsNativeKind(kind):
+ return "mojo::internal::NativePointer<%s>" % GetNativeTypeName(kind)
if mojom.IsStructKind(kind):
return ("mojo::internal::StructPointer<%s_Data>" %
GetNameForKind(kind, internal=True))
@@ -397,6 +433,7 @@ class Generator(generator.Generator):
"get_map_validate_params_ctor_args": GetMapValidateParamsCtorArgs,
"get_name_for_kind": GetNameForKind,
"get_pad": pack.GetPad,
+ "get_qualified_generic_interface_name": GetQualifiedGenericInterfaceName,
"has_callbacks": mojom.HasCallbacks,
"should_inline": ShouldInlineStruct,
"should_inline_union": ShouldInlineUnion,
@@ -405,6 +442,7 @@ class Generator(generator.Generator):
"is_enum_kind": mojom.IsEnumKind,
"is_integral_kind": mojom.IsIntegralKind,
"is_move_only_kind": mojom.IsMoveOnlyKind,
+ "is_native_kind": IsNativeKind,
"is_any_handle_kind": mojom.IsAnyHandleKind,
"is_interface_kind": mojom.IsInterfaceKind,
"is_interface_request_kind": mojom.IsInterfaceRequestKind,
@@ -428,7 +466,30 @@ class Generator(generator.Generator):
chromium_cpp_filters = dict(cpp_filters)
blink_cpp_filters = dict(cpp_filters)
+ def GetExtraHeaders(self):
+ if not _current_variant:
+ return []
+ extra_headers = []
+ headers_attribute = \
+ _variant_metadata_attributes[_current_variant]["headers"]
+ for struct in self.GetStructs():
+ if struct.attributes:
+ headers = struct.attributes.get(headers_attribute, [])
+ extra_headers.extend(headers)
+ return extra_headers
+
def GetJinjaExports(self):
+ global _variant_typemap
+ _variant_typemap = {}
+ if _current_variant:
+ typename_attribute = \
+ _variant_metadata_attributes[_current_variant]["typename"]
+ for struct in self.GetStructs():
+ if struct.attributes:
+ typename = struct.attributes.get(typename_attribute)
+ if typename:
+ _variant_typemap[struct.name] = typename
+
return {
"module": self.module,
"namespace": self.module.namespace,
@@ -440,6 +501,7 @@ class Generator(generator.Generator):
"unions": self.GetUnions(),
"interfaces": self.GetInterfaces(),
"variant": _current_variant,
+ "extra_headers": self.GetExtraHeaders(),
}
@UseJinja("cpp_templates/module.h.tmpl", filters=cpp_filters)
« no previous file with comments | « mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_definition.tmpl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698