def GetCppWrapperType(kind): if IsTypemappedKind(kind): return GetNativeTypeName(kind) if mojom.IsEnumKind(kind): return GetNameForKind(kind) if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): return "%sPtr" % GetNameForKind(kind) if mojom.IsArrayKind(kind): pattern = "mojo::WTFArray<%s>" if _for_blink else "mojo::Array<%s>" return pattern % GetCppArrayArgWrapperType(kind.kind) if mojom.IsMapKind(kind): return "mojo::Map<%s, %s>" % (GetCppArrayArgWrapperType( kind.key_kind), GetCppArrayArgWrapperType(kind.value_kind)) if mojom.IsInterfaceKind(kind): return "%sPtr" % GetNameForKind(kind) if mojom.IsInterfaceRequestKind(kind): return "%sRequest" % GetNameForKind(kind.kind) if mojom.IsAssociatedInterfaceKind(kind): return "%sAssociatedPtrInfo" % GetNameForKind(kind.kind) if mojom.IsAssociatedInterfaceRequestKind(kind): return "%sAssociatedRequest" % GetNameForKind(kind.kind) if mojom.IsStringKind(kind): return "WTF::String" if _for_blink else "mojo::String" 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" return _kind_to_cpp_type[kind]
def GetUnmappedTypeForSerializer(kind): if mojom.IsEnumKind(kind): return GetQualifiedNameForKind(kind) if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): return "%sPtr" % GetQualifiedNameForKind(kind) if mojom.IsArrayKind(kind): return "mojo::Array<%s>" % GetUnmappedTypeForSerializer(kind.kind) if mojom.IsMapKind(kind): return "mojo::Map<%s, %s>" % (GetUnmappedTypeForSerializer( kind.key_kind), GetUnmappedTypeForSerializer(kind.value_kind)) if mojom.IsInterfaceKind(kind): return "%sPtr" % GetQualifiedNameForKind(kind) if mojom.IsInterfaceRequestKind(kind): return "%sRequest" % GetQualifiedNameForKind(kind.kind) if mojom.IsAssociatedInterfaceKind(kind): return "%sAssociatedPtrInfo" % GetQualifiedNameForKind(kind.kind) if mojom.IsAssociatedInterfaceRequestKind(kind): return "%sAssociatedRequest" % GetQualifiedNameForKind(kind.kind) if mojom.IsStringKind(kind): return "mojo::String" 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" return _kind_to_cpp_type[kind]
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 GetCppArrayArgWrapperType(kind): if mojom.IsEnumKind(kind): return GetNameForKind(kind) if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): return "%sPtr" % GetNameForKind(kind) if mojom.IsArrayKind(kind): return "mojo::Array<%s> " % GetCppArrayArgWrapperType(kind.kind) if mojom.IsMapKind(kind): return "mojo::Map<%s, %s> " % (GetCppArrayArgWrapperType( kind.key_kind), GetCppArrayArgWrapperType(kind.value_kind)) if mojom.IsInterfaceKind(kind): raise Exception("Arrays of interfaces not yet supported!") if mojom.IsInterfaceRequestKind(kind): raise Exception("Arrays of interface requests not yet supported!") if mojom.IsAssociatedInterfaceKind(kind): raise Exception("Arrays of associated interfaces not yet supported!") if mojom.IsAssociatedInterfaceRequestKind(kind): raise Exception("Arrays of associated interface requests not yet " "supported!") if mojom.IsStringKind(kind): return "mojo::String" 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" return _kind_to_cpp_type[kind]
def GetCppConstWrapperType(kind): if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): return "%sPtr" % GetNameForKind(kind) if mojom.IsArrayKind(kind): return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind) if mojom.IsMapKind(kind): return "mojo::Map<%s, %s>" % (GetCppArrayArgWrapperType( kind.key_kind), GetCppArrayArgWrapperType(kind.value_kind)) if mojom.IsInterfaceKind(kind): return "%sPtr" % GetNameForKind(kind) if mojom.IsInterfaceRequestKind(kind): return "mojo::InterfaceRequest<%s>" % GetNameForKind(kind.kind) if mojom.IsAssociatedInterfaceKind(kind): return "mojo::AssociatedInterfacePtrInfo<%s>" % GetNameForKind( kind.kind) if mojom.IsAssociatedInterfaceRequestKind(kind): return "mojo::AssociatedInterfaceRequest<%s>" % GetNameForKind( kind.kind) if mojom.IsEnumKind(kind): return GetNameForKind(kind) if mojom.IsStringKind(kind): return "const mojo::String&" 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 not kind in _kind_to_cpp_type: print "missing:", kind.spec return _kind_to_cpp_type[kind]
def GetCppResultWrapperType(kind): if mojom.IsEnumKind(kind): return GetNameForKind(kind) if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): return "%sPtr" % GetNameForKind(kind) if mojom.IsArrayKind(kind): return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind) if mojom.IsMapKind(kind): return "mojo::Map<%s, %s>" % (GetCppArrayArgWrapperType( kind.key_kind), GetCppArrayArgWrapperType(kind.value_kind)) if mojom.IsInterfaceKind(kind): return "%sPtr" % GetNameForKind(kind) if mojom.IsInterfaceRequestKind(kind): return "mojo::InterfaceRequest<%s>" % GetNameForKind(kind.kind) if mojom.IsStringKind(kind): return "mojo::String" 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" # TODO(rudominer) After improvements to compiler front end have landed, # revisit strategy used below for emitting a useful error message when an # undefined identifier is referenced. val = _kind_to_cpp_type.get(kind) if (val is not None): return val raise Exception("Unrecognized kind %s" % kind.spec)
def GetCppWrapperType(kind): if mojom.IsEnumKind(kind): return GetNameForKind(kind) if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): return "%sPtr" % GetNameForKind(kind) if mojom.IsArrayKind(kind): return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind) if mojom.IsMapKind(kind): return "mojo::Map<%s, %s>" % (GetCppArrayArgWrapperType( kind.key_kind), GetCppArrayArgWrapperType(kind.value_kind)) if mojom.IsInterfaceKind(kind): return "%sPtr" % GetNameForKind(kind) if mojom.IsInterfaceRequestKind(kind): return "mojo::InterfaceRequest<%s>" % GetNameForKind(kind.kind) if mojom.IsStringKind(kind): return "mojo::String" 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" return _kind_to_cpp_type[kind]
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 GetCppWrapperType(kind): if IsTypemappedKind(kind): return GetNativeTypeName(kind) if mojom.IsEnumKind(kind): return GetNameForKind(kind) if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): return "%sPtr" % GetNameForKind(kind) if mojom.IsArrayKind(kind): pattern = None if _use_new_wrapper_types: if mojom.IsNullableKind(kind): pattern = ("WTF::Optional<WTF::Vector<%s>>" if _for_blink else "base::Optional<std::vector<%s>>") else: pattern = "WTF::Vector<%s>" if _for_blink else "std::vector<%s>" else: pattern = "mojo::WTFArray<%s>" if _for_blink else "mojo::Array<%s>" return pattern % GetCppWrapperType(kind.kind) if mojom.IsMapKind(kind): pattern = None if _use_new_wrapper_types: if mojom.IsNullableKind(kind): pattern = ("WTF::Optional<WTF::HashMap<%s, %s>>" if _for_blink else "base::Optional<std::unordered_map<%s, %s>>") else: pattern = ("WTF::HashMap<%s, %s>" if _for_blink else "std::unordered_map<%s, %s>") else: pattern = "mojo::WTFMap<%s, %s>" if _for_blink else "mojo::Map<%s, %s>" return pattern % (GetCppWrapperType( kind.key_kind), GetCppWrapperType(kind.value_kind)) if mojom.IsInterfaceKind(kind): return "%sPtr" % GetNameForKind(kind) if mojom.IsInterfaceRequestKind(kind): return "%sRequest" % GetNameForKind(kind.kind) if mojom.IsAssociatedInterfaceKind(kind): return "%sAssociatedPtrInfo" % GetNameForKind(kind.kind) if mojom.IsAssociatedInterfaceRequestKind(kind): return "%sAssociatedRequest" % GetNameForKind(kind.kind) if mojom.IsStringKind(kind): if _for_blink: return "WTF::String" if not _use_new_wrapper_types: return "mojo::String" return ("base::Optional<std::string>" if mojom.IsNullableKind(kind) else "std::string") 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 not kind in _kind_to_cpp_type: raise Exception("Unrecognized kind %s" % kind.spec) return _kind_to_cpp_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 GetCppArrayArgWrapperType(kind): if mojom.IsStructKind(kind) and kind.native_only: if IsTypemappedKind(kind): return GetNativeTypeName(kind) else: # Without a relevant typemap to apply, a native-only struct can only be # exposed as a blob of bytes. return "mojo::Array<uint8_t>" if IsTypemappedKind(kind): raise Exception( "Cannot serialize containers of non-native typemapped structs yet!" ) if mojom.IsEnumKind(kind): return GetNameForKind(kind) if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): return "%sPtr" % GetNameForKind(kind) if mojom.IsArrayKind(kind): pattern = "mojo::WTFArray<%s>" if _for_blink else "mojo::Array<%s>" return pattern % GetCppArrayArgWrapperType(kind.kind) if mojom.IsMapKind(kind): return "mojo::Map<%s, %s> " % (GetCppArrayArgWrapperType( kind.key_kind), GetCppArrayArgWrapperType(kind.value_kind)) if mojom.IsInterfaceKind(kind): raise Exception("Arrays of interfaces not yet supported!") if mojom.IsInterfaceRequestKind(kind): raise Exception("Arrays of interface requests not yet supported!") if mojom.IsAssociatedInterfaceKind(kind): raise Exception("Arrays of associated interfaces not yet supported!") if mojom.IsAssociatedInterfaceRequestKind(kind): raise Exception("Arrays of associated interface requests not yet " "supported!") if mojom.IsStringKind(kind): return "WTF::String" if _for_blink else "mojo::String" 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" return _kind_to_cpp_type[kind]
def GetCppConstWrapperType(kind): if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): return "%sPtr" % GetNameForKind(kind) if mojom.IsArrayKind(kind): return "::fidl::Array<%s>" % GetCppArrayArgWrapperType(kind.kind) if mojom.IsMapKind(kind): return "::fidl::Map<%s, %s>" % (GetCppArrayArgWrapperType(kind.key_kind), GetCppArrayArgWrapperType(kind.value_kind)) if mojom.IsInterfaceKind(kind): return "::fidl::InterfaceHandle<%s>" % GetNameForKind(kind) if mojom.IsInterfaceRequestKind(kind): return "::fidl::InterfaceRequest<%s>" % GetNameForKind(kind.kind) if mojom.IsEnumKind(kind): return GetNameForKind(kind) if mojom.IsStringKind(kind): return "const ::fidl::String&" if mojom.IsGenericHandleKind(kind): return "zx::handle" if mojom.IsChannelKind(kind): return "zx::channel" if mojom.IsVMOKind(kind): return "zx::vmo" if mojom.IsProcessKind(kind): return "zx::process" if mojom.IsThreadKind(kind): return "zx::thread" if mojom.IsEventKind(kind): return "zx::event" if mojom.IsPortKind(kind): return "zx::port" if mojom.IsJobKind(kind): return "zx::job" if mojom.IsSocketKind(kind): return "zx::socket" if mojom.IsEventPairKind(kind): return "zx::eventpair" if not kind in _kind_to_cpp_type: print "missing:", kind.spec return GetCppTypeForKind(kind)
def GetCppDataViewType(kind, qualified=False): def _GetName(input_kind): return _NameFormatter(input_kind, None).FormatForCpp( add_same_module_namespaces=qualified, 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>" % GetCppDataViewType( kind.kind, qualified) if mojom.IsMapKind(kind): return ("mojo::MapDataView<%s, %s>" % (GetCppDataViewType(kind.key_kind, qualified), 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.IsAssociatedInterfaceKind(kind): return "%sAssociatedPtrInfoDataView" % _GetName(kind.kind) if mojom.IsAssociatedInterfaceRequestKind(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" return _kind_to_cpp_type[kind]
def _GetCppWrapperType(self, kind, add_same_module_namespaces=False): def _AddOptional(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 not kind in _kind_to_cpp_type: raise Exception("Unrecognized kind %s" % kind.spec) return _kind_to_cpp_type[kind]
def GetCppWrapperType(kind, add_same_module_namespaces=False): def _AddOptional(type_name): pattern = "WTF::Optional<%s>" if _for_blink else "base::Optional<%s>" return pattern % type_name if IsTypemappedKind(kind): type_name = GetNativeTypeName(kind) if (mojom.IsNullableKind(kind) and not _current_typemap[GetFullMojomNameForKind(kind)][ "nullable_is_same_type"]): type_name = _AddOptional(type_name) return type_name if mojom.IsEnumKind(kind): return GetNameForKind( kind, add_same_module_namespaces=add_same_module_namespaces) if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): return "%sPtr" % GetNameForKind( kind, add_same_module_namespaces=add_same_module_namespaces) if mojom.IsArrayKind(kind): pattern = None if _use_new_wrapper_types: pattern = "WTF::Vector<%s>" if _for_blink else "std::vector<%s>" if mojom.IsNullableKind(kind): pattern = _AddOptional(pattern) else: pattern = "mojo::WTFArray<%s>" if _for_blink else "mojo::Array<%s>" return pattern % GetCppWrapperType( kind.kind, add_same_module_namespaces=add_same_module_namespaces) if mojom.IsMapKind(kind): pattern = None if _use_new_wrapper_types: pattern = ("WTF::HashMap<%s, %s>" if _for_blink else "std::unordered_map<%s, %s>") if mojom.IsNullableKind(kind): pattern = _AddOptional(pattern) else: pattern = "mojo::WTFMap<%s, %s>" if _for_blink else "mojo::Map<%s, %s>" return pattern % ( GetCppWrapperType( kind.key_kind, add_same_module_namespaces=add_same_module_namespaces), GetCppWrapperType( kind.value_kind, add_same_module_namespaces=add_same_module_namespaces)) if mojom.IsInterfaceKind(kind): return "%sPtr" % GetNameForKind( kind, add_same_module_namespaces=add_same_module_namespaces) if mojom.IsInterfaceRequestKind(kind): return "%sRequest" % GetNameForKind( kind.kind, add_same_module_namespaces=add_same_module_namespaces) if mojom.IsAssociatedInterfaceKind(kind): return "%sAssociatedPtrInfo" % GetNameForKind( kind.kind, add_same_module_namespaces=add_same_module_namespaces) if mojom.IsAssociatedInterfaceRequestKind(kind): return "%sAssociatedRequest" % GetNameForKind( kind.kind, add_same_module_namespaces=add_same_module_namespaces) if mojom.IsStringKind(kind): if _for_blink: return "WTF::String" if not _use_new_wrapper_types: return "mojo::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 not kind in _kind_to_cpp_type: raise Exception("Unrecognized kind %s" % kind.spec) return _kind_to_cpp_type[kind]