Ejemplo n.º 1
0
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.IsAssociatedInterfaceKind(kind):
        return "mojo::AssociatedInterfacePtrInfo<%s>" % GetNameForKind(
            kind.kind)
    if mojom.IsAssociatedInterfaceRequestKind(kind):
        return "mojo::AssociatedInterfaceRequest<%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]
Ejemplo n.º 2
0
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]
Ejemplo n.º 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>'
Ejemplo n.º 4
0
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):
        raise Exception("InterfaceRequest fields not 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 GetCppTypeForKind(kind)
Ejemplo n.º 5
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):
        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]
Ejemplo n.º 6
0
def GetCppArrayArgWrapperType(kind):
    if mojom.IsEnumKind(kind):
        return GetNameForKind(kind)
    if mojom.IsStructKind(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.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]
Ejemplo n.º 7
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
Ejemplo n.º 8
0
def GetCppConstWrapperType(kind):
    if mojom.IsStructKind(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.IsEnumKind(kind):
        return GetNameForKind(kind)
    if mojom.IsStringKind(kind):
        return "const 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"
    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)
Ejemplo n.º 10
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):
      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]
Ejemplo n.º 11
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 = 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]
Ejemplo n.º 12
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]
Ejemplo n.º 13
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]
Ejemplo n.º 14
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]
Ejemplo n.º 15
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):
        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 "%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 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]
Ejemplo n.º 16
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]
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]
Ejemplo n.º 18
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]
Ejemplo n.º 19
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]