Пример #1
0
  def _ClosureType(self, kind):
    if kind in mojom.PRIMITIVES:
      return _kind_to_closure_type[kind]
    if mojom.IsInterfaceKind(kind):
      return kind.module.namespace + "." + kind.name + "Ptr"
    if mojom.IsPendingRemoteKind(kind):
      return kind.kind.module.namespace + "." + kind.kind.name + "Ptr"
    if (mojom.IsStructKind(kind) or mojom.IsEnumKind(kind)):
      return kind.module.namespace + "." + kind.name
    # TODO(calamity): Support unions properly.
    if mojom.IsUnionKind(kind):
      return "Object"
    if mojom.IsArrayKind(kind):
      return "Array<%s>" % self._ClosureType(kind.kind)
    if mojom.IsMapKind(kind):
      return "Map<%s, %s>" % (self._ClosureType(
          kind.key_kind), self._ClosureType(kind.value_kind))
    if mojom.IsInterfaceRequestKind(kind) or mojom.IsPendingReceiverKind(kind):
      return "mojo.InterfaceRequest"
    # TODO(calamity): Support associated interfaces properly.
    if (mojom.IsAssociatedInterfaceKind(kind)
        or mojom.IsPendingAssociatedRemoteKind(kind)):
      return "mojo.AssociatedInterfacePtrInfo"
    # TODO(calamity): Support associated interface requests properly.
    if (mojom.IsAssociatedInterfaceRequestKind(kind)
        or mojom.IsPendingAssociatedReceiverKind(kind)):
      return "mojo.AssociatedInterfaceRequest"
    # TODO(calamity): Support enums properly.

    raise Exception("No valid closure type: %s" % kind)
Пример #2
0
 def _JavaScriptDefaultValue(self, field):
   if field.default:
     if mojom.IsStructKind(field.kind):
       assert field.default == "default"
       return "new %s()" % self._JavaScriptType(field.kind)
     return self._ExpressionToText(field.default)
   if field.kind in mojom.PRIMITIVES:
     return _kind_to_javascript_default_value[field.kind]
   if mojom.IsStructKind(field.kind):
     return "null"
   if mojom.IsUnionKind(field.kind):
     return "null"
   if mojom.IsArrayKind(field.kind):
     return "null"
   if mojom.IsMapKind(field.kind):
     return "null"
   if mojom.IsInterfaceKind(field.kind):
     return "new %sPtr()" % self._JavaScriptType(field.kind)
   if mojom.IsPendingRemoteKind(field.kind):
     return "new %sPtr()" % self._JavaScriptType(field.kind.kind)
   if (mojom.IsInterfaceRequestKind(field.kind)
       or mojom.IsPendingReceiverKind(field.kind)):
     return "new bindings.InterfaceRequest()"
   if (mojom.IsAssociatedInterfaceKind(field.kind)
       or mojom.IsPendingAssociatedRemoteKind(field.kind)):
     return "new associatedBindings.AssociatedInterfacePtrInfo()"
   if (mojom.IsAssociatedInterfaceRequestKind(field.kind)
       or mojom.IsPendingAssociatedReceiverKind(field.kind)):
     return "new associatedBindings.AssociatedInterfaceRequest()"
   if mojom.IsEnumKind(field.kind):
     return "0"
   raise Exception("No valid default: %s" % field)
Пример #3
0
 def _FuzzHandleName(self, kind):
     if mojom.IsInterfaceRequestKind(kind) or mojom.IsPendingReceiverKind(
             kind):
         return '{0}.{1}Request'.format(kind.kind.module.namespace,
                                        kind.kind.name)
     elif mojom.IsInterfaceKind(kind):
         return '{0}.{1}Ptr'.format(kind.module.namespace, kind.name)
     elif mojom.IsPendingRemoteKind(kind):
         return '{0}.{1}Ptr'.format(kind.kind.module.namespace,
                                    kind.kind.name)
     elif (mojom.IsAssociatedInterfaceRequestKind(kind)
           or mojom.IsPendingAssociatedReceiverKind(kind)):
         return '{0}.{1}AssociatedRequest'.format(
             kind.kind.module.namespace, kind.kind.name)
     elif (mojom.IsAssociatedInterfaceKind(kind)
           or mojom.IsPendingAssociatedRemoteKind(kind)):
         return '{0}.{1}AssociatedPtr'.format(kind.kind.module.namespace,
                                              kind.kind.name)
     elif mojom.IsSharedBufferKind(kind):
         return 'handle<shared_buffer>'
     elif mojom.IsDataPipeConsumerKind(kind):
         return 'handle<data_pipe_consumer>'
     elif mojom.IsDataPipeProducerKind(kind):
         return 'handle<data_pipe_producer>'
     elif mojom.IsMessagePipeKind(kind):
         return 'handle<message_pipe>'
Пример #4
0
def GetJavaType(context, kind, boxed=False, with_generics=True):
    if boxed:
        return GetBoxedJavaType(context, kind)
    if (mojom.IsStructKind(kind) or mojom.IsInterfaceKind(kind)
            or mojom.IsUnionKind(kind)):
        return GetNameForKind(context, kind)
    if mojom.IsPendingRemoteKind(kind):
        return GetNameForKind(context, kind.kind)
    if mojom.IsInterfaceRequestKind(kind) or mojom.IsPendingReceiverKind(kind):
        return ('org.chromium.mojo.bindings.InterfaceRequest<%s>' %
                GetNameForKind(context, kind.kind))
    if (mojom.IsAssociatedInterfaceKind(kind)
            or mojom.IsPendingAssociatedRemoteKind(kind)):
        return 'org.chromium.mojo.bindings.AssociatedInterfaceNotSupported'
    if (mojom.IsAssociatedInterfaceRequestKind(kind)
            or mojom.IsPendingAssociatedReceiverKind(kind)):
        return 'org.chromium.mojo.bindings.AssociatedInterfaceRequestNotSupported'
    if mojom.IsMapKind(kind):
        if with_generics:
            return 'java.util.Map<%s, %s>' % (GetBoxedJavaType(
                context,
                kind.key_kind), GetBoxedJavaType(context, kind.value_kind))
        else:
            return 'java.util.Map'
    if mojom.IsArrayKind(kind):
        return '%s[]' % GetJavaType(context, kind.kind, boxed, with_generics)
    if mojom.IsEnumKind(kind):
        return 'int'
    return _spec_to_java_type[kind.spec]
Пример #5
0
 def _GetCppFieldType(self, kind):
     if mojom.IsStructKind(kind):
         return ("mojo::internal::Pointer<%s>" %
                 self._GetNameForKind(kind, internal=True))
     if mojom.IsUnionKind(kind):
         return "%s" % self._GetNameForKind(kind, internal=True)
     if mojom.IsArrayKind(kind):
         return ("mojo::internal::Pointer<mojo::internal::Array_Data<%s>>" %
                 self._GetCppFieldType(kind.kind))
     if mojom.IsMapKind(kind):
         return (
             "mojo::internal::Pointer<mojo::internal::Map_Data<%s, %s>>" %
             (self._GetCppFieldType(
                 kind.key_kind), self._GetCppFieldType(kind.value_kind)))
     if mojom.IsInterfaceKind(kind) or mojom.IsPendingRemoteKind(kind):
         return "mojo::internal::Interface_Data"
     if mojom.IsInterfaceRequestKind(kind) or mojom.IsPendingReceiverKind(
             kind):
         return "mojo::internal::Handle_Data"
     if (mojom.IsAssociatedInterfaceKind(kind)
             or mojom.IsPendingAssociatedRemoteKind(kind)):
         return "mojo::internal::AssociatedInterface_Data"
     if (mojom.IsAssociatedInterfaceRequestKind(kind)
             or mojom.IsPendingAssociatedReceiverKind(kind)):
         return "mojo::internal::AssociatedEndpointHandle_Data"
     if mojom.IsEnumKind(kind):
         return "int32_t"
     if mojom.IsStringKind(kind):
         return "mojo::internal::Pointer<mojo::internal::String_Data>"
     if mojom.IsAnyHandleKind(kind):
         return "mojo::internal::Handle_Data"
     return _kind_to_cpp_type[kind]
Пример #6
0
    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)
              or mojom.IsPendingReceiverKind(kind)
              or mojom.IsPendingAssociatedRemoteKind(kind)
              or mojom.IsPendingAssociatedReceiverKind(kind)):
            return "uint32_t"
        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]
Пример #7
0
 def AddKind(kind):
     if (mojom.IsIntegralKind(kind) or mojom.IsStringKind(kind)
             or mojom.IsDoubleKind(kind) or mojom.IsFloatKind(kind)):
         pass
     elif (mojom.IsAnyHandleKind(kind)):
         self.needs_mojolpm_proto = True
     elif mojom.IsArrayKind(kind):
         AddKind(kind.kind)
     elif mojom.IsMapKind(kind):
         AddKind(kind.key_kind)
         AddKind(kind.value_kind)
     elif (mojom.IsStructKind(kind) or mojom.IsUnionKind(kind)
           or mojom.IsEnumKind(kind) or mojom.IsInterfaceKind(kind)):
         name = self._GetFullMojomNameForKind(kind)
         if name in seen_types:
             return
         seen_types.add(name)
         if kind.module in all_imports:
             seen_imports.add(kind.module)
     elif (mojom.IsInterfaceRequestKind(kind)
           or mojom.IsAssociatedInterfaceKind(kind)
           or mojom.IsAssociatedInterfaceRequestKind(kind)
           or mojom.IsPendingRemoteKind(kind)
           or mojom.IsPendingReceiverKind(kind)
           or mojom.IsPendingAssociatedRemoteKind(kind)
           or mojom.IsPendingAssociatedReceiverKind(kind)):
         AddKind(kind.kind)
Пример #8
0
  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
Пример #9
0
    def _LiteJavaScriptType(self, kind):
        if self._IsPrimitiveKind(kind):
            return _kind_to_lite_js_type[kind]
        if mojom.IsArrayKind(kind):
            return "mojo.internal.Array(%s, %s)" % (self._LiteJavaScriptType(
                kind.kind), "true" if mojom.IsNullableKind(kind.kind) else
                                                    "false")
        if mojom.IsMapKind(kind):
            return "mojo.internal.Map(%s, %s, %s)" % (self._LiteJavaScriptType(
                kind.key_kind), self._LiteJavaScriptType(
                    kind.value_kind), "true" if mojom.IsNullableKind(
                        kind.value_kind) else "false")

        if (mojom.IsAssociatedKind(kind) or mojom.IsInterfaceRequestKind(kind)
                or mojom.IsPendingRemoteKind(kind)
                or mojom.IsPendingReceiverKind(kind)):
            named_kind = kind.kind
        else:
            named_kind = kind

        name = []
        if named_kind.module:
            name.append(named_kind.module.namespace)
        if named_kind.parent_kind:
            parent_name = named_kind.parent_kind.name
            if mojom.IsStructKind(named_kind.parent_kind):
                parent_name += "Spec"
            name.append(parent_name)
        name.append(named_kind.name)
        name = ".".join(name)

        if (mojom.IsStructKind(kind) or mojom.IsUnionKind(kind)
                or mojom.IsEnumKind(kind)):
            return "%sSpec.$" % name
        if mojom.IsInterfaceKind(kind) or mojom.IsPendingRemoteKind(kind):
            remote_name = name + self._GetPrimitivesNames()["remote"]
            return "mojo.internal.InterfaceProxy(%s)" % remote_name
        if mojom.IsInterfaceRequestKind(kind) or mojom.IsPendingReceiverKind(
                kind):
            request_name = name + self._GetPrimitivesNames(
            )["pending_receiver"]
            return "mojo.internal.InterfaceRequest(%s)" % request_name
        if (mojom.IsAssociatedInterfaceKind(kind)
                or mojom.IsPendingAssociatedRemoteKind(kind)):
            remote_name = name + self._GetPrimitivesNames()["remote"]
            # TODO(rockot): Implement associated interfaces.
            return "mojo.internal.AssociatedInterfaceProxy(%s)" % (remote_name)
        if (mojom.IsAssociatedInterfaceRequestKind(kind)
                or mojom.IsPendingAssociatedReceiverKind(kind)):
            request_name = name + self._GetPrimitivesNames(
            )["pending_receiver"]
            return "mojo.internal.AssociatedInterfaceRequest(%s)" % request_name

        return name
Пример #10
0
    def _LiteClosureType(self, kind):
        if kind in mojom.PRIMITIVES:
            return _kind_to_closure_type[kind]
        if mojom.IsArrayKind(kind):
            return "Array<%s>" % self._LiteClosureTypeWithNullability(
                kind.kind)
        if mojom.IsMapKind(kind) and self._IsStringableKind(kind.key_kind):
            return "Object<%s, %s>" % (
                self._LiteClosureTypeWithNullability(kind.key_kind),
                self._LiteClosureTypeWithNullability(kind.value_kind))
        if mojom.IsMapKind(kind):
            return "Map<%s, %s>" % (
                self._LiteClosureTypeWithNullability(kind.key_kind),
                self._LiteClosureTypeWithNullability(kind.value_kind))

        if (mojom.IsAssociatedKind(kind) or mojom.IsInterfaceRequestKind(kind)
                or mojom.IsPendingRemoteKind(kind)
                or mojom.IsPendingReceiverKind(kind)):
            named_kind = kind.kind
        else:
            named_kind = kind

        name = []
        if named_kind.module:
            name.append(named_kind.module.namespace)
        if named_kind.parent_kind:
            name.append(named_kind.parent_kind.name)

        if mojom.IsEnumKind(kind) and named_kind.parent_kind:
            name = ".".join(name)
            name += "_" + named_kind.name
        else:
            name.append("" + named_kind.name)
            name = ".".join(name)

        if (mojom.IsStructKind(kind) or mojom.IsUnionKind(kind)
                or mojom.IsEnumKind(kind)):
            return name
        if mojom.IsInterfaceKind(kind) or mojom.IsPendingRemoteKind(kind):
            return name + "Proxy"
        if mojom.IsInterfaceRequestKind(kind) or mojom.IsPendingReceiverKind(
                kind):
            return name + "Request"
        # TODO(calamity): Support associated interfaces properly.
        if (mojom.IsAssociatedInterfaceKind(kind)
                or mojom.IsPendingAssociatedRemoteKind(kind)):
            return "Object"
        # TODO(calamity): Support associated interface requests properly.
        if (mojom.IsAssociatedInterfaceRequestKind(kind)
                or mojom.IsPendingAssociatedReceiverKind(kind)):
            return "Object"

        raise Exception("No valid closure type: %s" % kind)
Пример #11
0
    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]
Пример #12
0
 def _CodecType(self, kind):
     if kind in mojom.PRIMITIVES:
         return _kind_to_codec_type[kind]
     if mojom.IsStructKind(kind):
         pointer_type = "NullablePointerTo" if mojom.IsNullableKind(kind) \
             else "PointerTo"
         return "new codec.%s(%s)" % (pointer_type,
                                      self._JavaScriptType(kind))
     if mojom.IsUnionKind(kind):
         return self._JavaScriptType(kind)
     if mojom.IsArrayKind(kind):
         array_type = ("NullableArrayOf"
                       if mojom.IsNullableKind(kind) else "ArrayOf")
         array_length = "" if kind.length is None else ", %d" % kind.length
         element_type = self._ElementCodecType(kind.kind)
         return "new codec.%s(%s%s)" % (array_type, element_type,
                                        array_length)
     if mojom.IsInterfaceKind(kind):
         return "new codec.%s(%sPtr)" % (
             "NullableInterface" if mojom.IsNullableKind(kind) else
             "Interface", self._JavaScriptType(kind))
     if mojom.IsPendingRemoteKind(kind):
         return "new codec.%s(%sPtr)" % (
             "NullableInterface" if mojom.IsNullableKind(kind) else
             "Interface", self._JavaScriptType(kind.kind))
     if mojom.IsInterfaceRequestKind(kind) or mojom.IsPendingReceiverKind(
             kind):
         return "codec.%s" % ("NullableInterfaceRequest" if mojom.
                              IsNullableKind(kind) else "InterfaceRequest")
     if (mojom.IsAssociatedInterfaceKind(kind)
             or mojom.IsPendingAssociatedRemoteKind(kind)):
         return "codec.%s" % ("NullableAssociatedInterfacePtrInfo"
                              if mojom.IsNullableKind(kind) else
                              "AssociatedInterfacePtrInfo")
     if (mojom.IsAssociatedInterfaceRequestKind(kind)
             or mojom.IsPendingAssociatedReceiverKind(kind)):
         return "codec.%s" % ("NullableAssociatedInterfaceRequest"
                              if mojom.IsNullableKind(kind) else
                              "AssociatedInterfaceRequest")
     if mojom.IsEnumKind(kind):
         return "new codec.Enum(%s)" % self._JavaScriptType(kind)
     if mojom.IsMapKind(kind):
         map_type = "NullableMapOf" if mojom.IsNullableKind(
             kind) else "MapOf"
         key_type = self._ElementCodecType(kind.key_kind)
         value_type = self._ElementCodecType(kind.value_kind)
         return "new codec.%s(%s, %s)" % (map_type, key_type, value_type)
     raise Exception("No codec type for %s" % kind)
Пример #13
0
 def _DecodeMethodName(kind):
   if mojom.IsArrayKind(kind):
     return _DecodeMethodName(kind.kind) + 's'
   if mojom.IsEnumKind(kind):
     return _DecodeMethodName(mojom.INT32)
   if mojom.IsInterfaceRequestKind(kind) or mojom.IsPendingReceiverKind(kind):
     return 'readInterfaceRequest'
   if mojom.IsInterfaceKind(kind) or mojom.IsPendingRemoteKind(kind):
     return 'readServiceInterface'
   if (mojom.IsAssociatedInterfaceRequestKind(kind) or
       mojom.IsPendingAssociatedReceiverKind(kind)):
     return 'readAssociatedInterfaceRequestNotSupported'
   if (mojom.IsAssociatedInterfaceKind(kind) or
       mojom.IsPendingAssociatedRemoteKind(kind)):
     return 'readAssociatedServiceInterfaceNotSupported'
   return _spec_to_decode_method[kind.spec]
Пример #14
0
  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]