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"
    return _kind_to_cpp_type[kind]
示例#2
0
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]
示例#3
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.IsPendingRemoteKind(kind)
              or mojom.IsPendingReceiverKind(kind)
              or mojom.IsPendingAssociatedRemoteKind(kind)
              or mojom.IsPendingAssociatedReceiverKind(kind)):
            unquantified = "uint32"
        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
示例#4
0
def GetCppResultWrapperType(kind):
    if IsTypemappedKind(kind):
        return "const %s&" % GetNativeTypeName(kind)
    if mojom.IsStructKind(kind) and kind.native_only:
        return "mojo::Array<uint8_t>"
    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"
    # 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)
示例#5
0
 def _FuzzHandleName(self, kind):
     if mojom.IsInterfaceRequestKind(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.IsAssociatedInterfaceRequestKind(kind):
         return '{0}.{1}AssociatedRequest'.format(
             kind.kind.module.namespace, kind.kind.name)
     elif mojom.IsAssociatedInterfaceKind(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>'
示例#6
0
def GetCppConstWrapperType(kind):
    if IsTypemappedKind(kind):
        return "const %s&" % GetNativeTypeName(kind)
    if mojom.IsStructKind(kind) and kind.native_only:
        return "mojo::Array<uint8_t>"
    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.IsEnumKind(kind):
        return GetNameForKind(kind)
    if mojom.IsStringKind(kind):
        return "const WTF::String&" if _for_blink else "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]
示例#7
0
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]
示例#8
0
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):
        pattern = "mojo::WTFMap<%s, %s>" if _for_blink else "mojo::Map<%s, %s>"
        return pattern % (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"
    if not kind in _kind_to_cpp_type:
        raise Exception("Unrecognized kind %s" % kind.spec)
    return _kind_to_cpp_type[kind]
示例#9
0
def GetCppArrayArgWrapperType(kind):
  if mojom.IsStructKind(kind) and kind.native_only:
    raise Exception("Cannot serialize containers of native-only types yet!")
  if IsTypemappedKind(kind):
    raise Exception("Cannot serialize containers of 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):
    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]
示例#10
0
def GetCppArrayArgWrapperType(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):
        pattern = "mojo::WTFMap<%s, %s>" if _for_blink else "mojo::Map<%s, %s>"
        return pattern % (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 GetCppArrayArgWrapperType(kind):
    if mojom.IsEnumKind(kind):
        return GetNameForKind(kind)
    if mojom.IsStructKind(kind):
        return "%sPtr" % GetNameForKind(kind)
    if mojom.IsAnyArrayKind(kind):
        return "mojo::Array<%s> " % GetCppArrayArgWrapperType(kind.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.IsStringKind(kind):
        return "mojo::String"
    if mojom.IsHandleKind(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 GetCppResultWrapperType(kind):
    if mojom.IsEnumKind(kind):
        return GetNameForKind(kind)
    if mojom.IsStructKind(kind):
        return "%sPtr" % GetNameForKind(kind)
    if mojom.IsAnyArrayKind(kind):
        return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.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.IsHandleKind(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]
示例#13
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]
示例#14
0
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]