def _GetProtoFieldType(self, kind, quantified=True): # TODO(markbrand): This will not handle array<array> or array<map> # TODO(markbrand): This also will not handle array<x, 10> unquantified = '' if (mojom.IsEnumKind(kind) or mojom.IsStructKind(kind) or mojom.IsUnionKind(kind)): unquantified = self._GetProtoNameForKind(kind) elif mojom.IsArrayKind(kind): return "repeated %sEntry" % self._GetProtoFieldType( kind.kind, quantified=False) elif mojom.IsMapKind(kind): return ( "map<%sKey, %sValue>" % (self._GetProtoFieldType(kind.key_kind, quantified=False), self._GetProtoFieldType(kind.value_kind, quantified=False))) elif mojom.IsInterfaceKind(kind): unquantified = "%s.Ptr" % self._GetProtoNameForKind(kind) elif mojom.IsInterfaceRequestKind(kind): unquantified = "%s.Request" % self._GetProtoNameForKind(kind.kind) elif mojom.IsAssociatedInterfaceKind(kind): unquantified = "%s.AssociatedPtr" % self._GetProtoNameForKind( kind.kind) elif mojom.IsAssociatedInterfaceRequestKind(kind): unquantified = ("%s.AssociatedRequest" % self._GetProtoNameForKind(kind.kind)) elif mojom.IsPendingRemoteKind(kind): unquantified = "%s.PendingRemote" % self._GetProtoNameForKind( kind.kind) elif mojom.IsPendingReceiverKind(kind): unquantified = "%s.PendingReceiver" % self._GetProtoNameForKind( kind.kind) elif mojom.IsPendingAssociatedRemoteKind(kind): unquantified = ("%s.PendingAssociatedRemote" % self._GetProtoNameForKind(kind.kind)) elif mojom.IsPendingAssociatedReceiverKind(kind): unquantified = ("%s.PendingAssociatedReceiver" % self._GetProtoNameForKind(kind.kind)) elif mojom.IsStringKind(kind): unquantified = "string" elif mojom.IsGenericHandleKind(kind): unquantified = "mojolpm.Handle" elif mojom.IsDataPipeConsumerKind(kind): unquantified = "mojolpm.DataPipeConsumerHandle" elif mojom.IsDataPipeProducerKind(kind): unquantified = "mojolpm.DataPipeProducerHandle" elif mojom.IsMessagePipeKind(kind): unquantified = "mojolpm.MessagePipeHandle" elif mojom.IsSharedBufferKind(kind): unquantified = "mojolpm.SharedBufferHandle" elif mojom.IsPlatformHandleKind(kind): unquantified = "mojolpm.PlatformHandle" else: unquantified = _kind_to_proto_type[kind] if quantified and mojom.IsNullableKind(kind): return 'optional %s' % unquantified elif quantified: return 'required %s' % unquantified else: return unquantified
def _GetCppWrapperProtoType(self, kind, add_same_module_namespaces=False): if (mojom.IsEnumKind(kind) or mojom.IsStructKind(kind) or mojom.IsUnionKind(kind)): return self._GetCppProtoNameForKind( kind, add_same_module_namespaces=add_same_module_namespaces) elif mojom.IsPendingRemoteKind(kind): return "%s::PendingRemote" % self._GetCppProtoNameForKind( kind.kind, add_same_module_namespaces=add_same_module_namespaces) elif mojom.IsPendingReceiverKind(kind): return "%s::PendingReceiver" % self._GetCppProtoNameForKind( kind.kind, add_same_module_namespaces=add_same_module_namespaces) elif mojom.IsPendingAssociatedRemoteKind(kind): return "%s::PendingAssociatedRemote" % self._GetCppProtoNameForKind( kind.kind, add_same_module_namespaces=add_same_module_namespaces) elif mojom.IsPendingAssociatedReceiverKind(kind): return "%s::PendingAssociatedReceiver" % self._GetCppProtoNameForKind( kind.kind, add_same_module_namespaces=add_same_module_namespaces) elif mojom.IsStringKind(kind): return "std::string" elif mojom.IsGenericHandleKind(kind): return "mojolpm::Handle" elif mojom.IsDataPipeConsumerKind(kind): return "mojolpm::DataPipeConsumerHandle" elif mojom.IsDataPipeProducerKind(kind): return "mojolpm::DataPipeProducerHandle" elif mojom.IsMessagePipeKind(kind): return "mojolpm::MessagePipeHandle" elif mojom.IsSharedBufferKind(kind): return "mojolpm::SharedBufferHandle" elif mojom.IsPlatformHandleKind(kind): return "mojolpm::PlatformHandle" if not kind in _kind_to_cpp_proto_type: raise Exception("Unrecognized kind %s" % kind.spec) return _kind_to_cpp_proto_type[kind]
def _GetCppDataViewType(self, kind, qualified=False): def _GetName(input_kind): return _NameFormatter(input_kind, None).FormatForCpp( omit_namespace_for_module=(None if qualified else self.module), flatten_nested_kind=True) if mojom.IsEnumKind(kind): return _GetName(kind) if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): return "%sDataView" % _GetName(kind) if mojom.IsArrayKind(kind): return "mojo::ArrayDataView<%s>" % (self._GetCppDataViewType( kind.kind, qualified)) if mojom.IsMapKind(kind): return ("mojo::MapDataView<%s, %s>" % (self._GetCppDataViewType(kind.key_kind, qualified), self._GetCppDataViewType(kind.value_kind, qualified))) if mojom.IsStringKind(kind): return "mojo::StringDataView" if mojom.IsInterfaceKind(kind): return "%sPtrDataView" % _GetName(kind) if mojom.IsInterfaceRequestKind(kind): return "%sRequestDataView" % _GetName(kind.kind) if mojom.IsPendingRemoteKind(kind): return ("mojo::InterfacePtrDataView<%sInterfaceBase>" % _GetName(kind.kind)) if mojom.IsPendingReceiverKind(kind): return ("mojo::InterfaceRequestDataView<%sInterfaceBase>" % _GetName(kind.kind)) if (mojom.IsAssociatedInterfaceKind(kind) or mojom.IsPendingAssociatedRemoteKind(kind)): return "%sAssociatedPtrInfoDataView" % _GetName(kind.kind) if (mojom.IsAssociatedInterfaceRequestKind(kind) or mojom.IsPendingAssociatedReceiverKind(kind)): return "%sAssociatedRequestDataView" % _GetName(kind.kind) if mojom.IsGenericHandleKind(kind): return "mojo::ScopedHandle" if mojom.IsDataPipeConsumerKind(kind): return "mojo::ScopedDataPipeConsumerHandle" if mojom.IsDataPipeProducerKind(kind): return "mojo::ScopedDataPipeProducerHandle" if mojom.IsMessagePipeKind(kind): return "mojo::ScopedMessagePipeHandle" if mojom.IsSharedBufferKind(kind): return "mojo::ScopedSharedBufferHandle" if mojom.IsPlatformHandleKind(kind): return "mojo::PlatformHandle" return _kind_to_cpp_type[kind]
def _GetCppWrapperType(self, kind, add_same_module_namespaces=False, ignore_nullable=False): def _AddOptional(type_name): if ignore_nullable: return type_name return "base::Optional<%s>" % type_name if self._IsTypemappedKind(kind): type_name = self._GetNativeTypeName(kind) if (mojom.IsNullableKind(kind) and not self.typemap[self._GetFullMojomNameForKind( kind)]["nullable_is_same_type"]): type_name = _AddOptional(type_name) return type_name if mojom.IsEnumKind(kind): return self._GetNameForKind( kind, add_same_module_namespaces=add_same_module_namespaces) if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): return "%sPtr" % self._GetNameForKind( kind, add_same_module_namespaces=add_same_module_namespaces) if mojom.IsArrayKind(kind): pattern = "WTF::Vector<%s>" if self.for_blink else "std::vector<%s>" if mojom.IsNullableKind(kind): pattern = _AddOptional(pattern) return pattern % self._GetCppWrapperType( kind.kind, add_same_module_namespaces=add_same_module_namespaces) if mojom.IsMapKind(kind): pattern = ("WTF::HashMap<%s, %s>" if self.for_blink else "base::flat_map<%s, %s>") if mojom.IsNullableKind(kind): pattern = _AddOptional(pattern) return pattern % ( self._GetCppWrapperType( kind.key_kind, add_same_module_namespaces=add_same_module_namespaces), self._GetCppWrapperType( kind.value_kind, add_same_module_namespaces=add_same_module_namespaces)) if mojom.IsInterfaceKind(kind): return "%sPtrInfo" % self._GetNameForKind( kind, add_same_module_namespaces=add_same_module_namespaces) if mojom.IsInterfaceRequestKind(kind): return "%sRequest" % self._GetNameForKind( kind.kind, add_same_module_namespaces=add_same_module_namespaces) if mojom.IsPendingRemoteKind(kind): return "::mojo::PendingRemote<%s>" % self._GetNameForKind( kind.kind, add_same_module_namespaces=add_same_module_namespaces) if mojom.IsPendingReceiverKind(kind): return "::mojo::PendingReceiver<%s>" % self._GetNameForKind( kind.kind, add_same_module_namespaces=add_same_module_namespaces) if mojom.IsPendingAssociatedRemoteKind(kind): return "::mojo::PendingAssociatedRemote<%s>" % self._GetNameForKind( kind.kind, add_same_module_namespaces=add_same_module_namespaces) if mojom.IsPendingAssociatedReceiverKind(kind): return "::mojo::PendingAssociatedReceiver<%s>" % self._GetNameForKind( kind.kind, add_same_module_namespaces=add_same_module_namespaces) if mojom.IsAssociatedInterfaceKind(kind): return "%sAssociatedPtrInfo" % self._GetNameForKind( kind.kind, add_same_module_namespaces=add_same_module_namespaces) if mojom.IsAssociatedInterfaceRequestKind(kind): return "%sAssociatedRequest" % self._GetNameForKind( kind.kind, add_same_module_namespaces=add_same_module_namespaces) if mojom.IsStringKind(kind): if self.for_blink: return "WTF::String" type_name = "std::string" return (_AddOptional(type_name) if mojom.IsNullableKind(kind) else type_name) if mojom.IsGenericHandleKind(kind): return "::mojo::ScopedHandle" if mojom.IsDataPipeConsumerKind(kind): return "::mojo::ScopedDataPipeConsumerHandle" if mojom.IsDataPipeProducerKind(kind): return "::mojo::ScopedDataPipeProducerHandle" if mojom.IsMessagePipeKind(kind): return "::mojo::ScopedMessagePipeHandle" if mojom.IsSharedBufferKind(kind): return "::mojo::ScopedSharedBufferHandle" if mojom.IsPlatformHandleKind(kind): return "::mojo::PlatformHandle" if not kind in _kind_to_cpp_type: raise Exception("Unrecognized kind %s" % kind.spec) return _kind_to_cpp_type[kind]