Ejemplo n.º 1
0
def GetCppType(kind):
  if mojom.IsStructKind(kind) and kind.native_only:
    raise Exception("Should not be reached!")
  if mojom.IsArrayKind(kind):
    return "mojo::internal::Array_Data<%s>*" % GetCppType(kind.kind)
  if mojom.IsMapKind(kind):
    return "mojo::internal::Map_Data<%s, %s>*" % (
      GetCppType(kind.key_kind), GetCppType(kind.value_kind))
  if mojom.IsStructKind(kind):
    return "%s_Data*" % GetNameForKind(kind, internal=True)
  if mojom.IsUnionKind(kind):
    return "%s_Data" % GetNameForKind(kind, internal=True)
  if mojom.IsInterfaceKind(kind):
    return "mojo::internal::Interface_Data"
  if mojom.IsInterfaceRequestKind(kind):
    return "mojo::MessagePipeHandle"
  if mojom.IsAssociatedInterfaceKind(kind):
    return "mojo::internal::AssociatedInterface_Data"
  if mojom.IsAssociatedInterfaceRequestKind(kind):
    return "mojo::internal::AssociatedInterfaceRequest_Data"
  if mojom.IsEnumKind(kind):
    return "int32_t"
  if mojom.IsStringKind(kind):
    return "mojo::internal::String_Data*"
  return _kind_to_cpp_type[kind]
Ejemplo n.º 2
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.º 3
0
def GetCppFieldType(kind):
    if mojom.IsStructKind(kind):
        return ("mojo::internal::Pointer<%s>" %
                GetNameForKind(kind, internal=True))
    if mojom.IsUnionKind(kind):
        return "%s" % GetNameForKind(kind, internal=True)
    if mojom.IsArrayKind(kind):
        return ("mojo::internal::Pointer<mojo::internal::Array_Data<%s>>" %
                GetCppType(kind.kind))
    if mojom.IsMapKind(kind):
        return ("mojo::internal::Pointer<mojo::internal::Map_Data<%s, %s>>" %
                (GetCppType(kind.key_kind), GetCppType(kind.value_kind)))
    if mojom.IsInterfaceKind(kind):
        return "mojo::internal::Interface_Data"
    if mojom.IsInterfaceRequestKind(kind):
        return "mojo::internal::Handle_Data"
    if mojom.IsAssociatedInterfaceKind(kind):
        return "mojo::internal::AssociatedInterface_Data"
    if mojom.IsAssociatedInterfaceRequestKind(kind):
        return "mojo::internal::AssociatedInterfaceRequest_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]
Ejemplo n.º 4
0
def GetCppType(kind):
    if mojom.IsStructKind(kind) and kind.native_only:
        # A native-only type is just a blob of bytes.
        return "mojo::internal::Array_Data<uint8_t>*"
    if mojom.IsArrayKind(kind):
        return "mojo::internal::Array_Data<%s>*" % GetCppType(kind.kind)
    if mojom.IsMapKind(kind):
        return "mojo::internal::Map_Data<%s, %s>*" % (GetCppType(
            kind.key_kind), GetCppType(kind.value_kind))
    if mojom.IsStructKind(kind):
        return "%s*" % GetNameForKind(kind, internal=True)
    if mojom.IsUnionKind(kind):
        return "%s" % GetNameForKind(kind, internal=True)
    if mojom.IsInterfaceKind(kind):
        return "mojo::internal::Interface_Data"
    if mojom.IsInterfaceRequestKind(kind):
        return "mojo::MessagePipeHandle"
    if mojom.IsAssociatedInterfaceKind(kind):
        return "mojo::internal::AssociatedInterface_Data"
    if mojom.IsAssociatedInterfaceRequestKind(kind):
        return "mojo::internal::AssociatedInterfaceRequest_Data"
    if mojom.IsEnumKind(kind):
        return GetNameForKind(kind, internal=True)
    if mojom.IsStringKind(kind):
        return "mojo::internal::String_Data*"
    return _kind_to_cpp_type[kind]
Ejemplo n.º 5
0
def GetCppFieldType(kind):
  if IsNativeOnlyKind(kind):
    return "mojo::internal::ArrayPointer<uint8_t>"
  if mojom.IsStructKind(kind):
    return ("mojo::internal::StructPointer<%s_Data>" %
        GetNameForKind(kind, internal=True))
  if mojom.IsUnionKind(kind):
    return "%s_Data" % GetNameForKind(kind, internal=True)
  if mojom.IsArrayKind(kind):
    return "mojo::internal::ArrayPointer<%s>" % GetCppType(kind.kind)
  if mojom.IsMapKind(kind):
    return ("mojo::internal::StructPointer<mojo::internal::Map_Data<%s, %s>>" %
            (GetCppType(kind.key_kind), GetCppType(kind.value_kind)))
  if mojom.IsInterfaceKind(kind):
    return "mojo::internal::Interface_Data"
  if mojom.IsInterfaceRequestKind(kind):
    return "mojo::MessagePipeHandle"
  if mojom.IsAssociatedInterfaceKind(kind):
    return "mojo::internal::AssociatedInterface_Data"
  if mojom.IsAssociatedInterfaceRequestKind(kind):
    return "mojo::internal::AssociatedInterfaceRequest_Data"
  if mojom.IsEnumKind(kind):
    return GetNameForKind(kind)
  if mojom.IsStringKind(kind):
    return "mojo::internal::StringPointer"
  return _kind_to_cpp_type[kind]
Ejemplo n.º 6
0
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]
Ejemplo n.º 7
0
    def _ClosureType(self, kind):
        if kind in mojom.PRIMITIVES:
            return _kind_to_closure_type[kind]
        if (mojom.IsStructKind(kind) or mojom.IsInterfaceKind(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):
            return "mojo.InterfaceRequest"
        # TODO(calamity): Support associated interfaces properly.
        if mojom.IsAssociatedInterfaceKind(kind):
            return "mojo.AssociatedInterfacePtrInfo"
        # TODO(calamity): Support associated interface requests properly.
        if mojom.IsAssociatedInterfaceRequestKind(kind):
            return "mojo.AssociatedInterfaceRequest"
        # TODO(calamity): Support enums properly.

        raise Exception("No valid closure type: %s" % kind)
Ejemplo n.º 8
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.º 9
0
def CodecType(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, JavaScriptType(kind))
    if mojom.IsUnionKind(kind):
        return 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 = ElementCodecType(kind.kind)
        return "new codec.%s(%s%s)" % (array_type, element_type, array_length)
    if mojom.IsInterfaceKind(kind):
        return "codec.%s" % ("NullableInterface"
                             if mojom.IsNullableKind(kind) else "Interface")
    if mojom.IsInterfaceRequestKind(kind):
        return CodecType(mojom.MSGPIPE)
    if mojom.IsAssociatedInterfaceKind(kind):
        return "codec.AssociatedInterfaceNotSupported"
    if mojom.IsAssociatedInterfaceRequestKind(kind):
        return "codec.AssociatedInterfaceRequestNotSupported"
    if mojom.IsEnumKind(kind):
        return "new codec.Enum(%s)" % JavaScriptType(kind)
    if mojom.IsMapKind(kind):
        map_type = "NullableMapOf" if mojom.IsNullableKind(kind) else "MapOf"
        key_type = ElementCodecType(kind.key_kind)
        value_type = ElementCodecType(kind.value_kind)
        return "new codec.%s(%s, %s)" % (map_type, key_type, value_type)
    raise Exception("No codec type for %s" % kind)
Ejemplo n.º 10
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.º 11
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]
Ejemplo n.º 12
0
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]
Ejemplo n.º 13
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.IsInterfaceRequestKind(kind):
    return ('org.chromium.mojo.bindings.InterfaceRequest<%s>' %
            GetNameForKind(context, kind.kind))
  if mojom.IsAssociatedInterfaceKind(kind):
    return 'org.chromium.mojo.bindings.AssociatedInterfaceNotSupported'
  if mojom.IsAssociatedInterfaceRequestKind(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]
Ejemplo n.º 14
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.IsInterfaceRequestKind(field.kind):
         return "new bindings.InterfaceRequest()"
     if mojom.IsAssociatedInterfaceKind(field.kind):
         return "new associatedBindings.AssociatedInterfacePtrInfo()"
     if mojom.IsAssociatedInterfaceRequestKind(field.kind):
         return "new associatedBindings.AssociatedInterfaceRequest()"
     if mojom.IsEnumKind(field.kind):
         return "0"
     raise Exception("No valid default: %s" % field)
Ejemplo n.º 15
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)
Ejemplo n.º 16
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.º 17
0
        def get_type_name(kind):
            if kind == mojom.INT64 or kind == mojom.UINT64:
                return "bigint"
            if kind in mojom.PRIMITIVES:
                return _kind_to_closure_type[kind]
            if mojom.IsArrayKind(kind):
                return "Array<%s>" % recurse_with_nullability(kind.kind)
            if mojom.IsMapKind(kind) and self._IsStringableKind(kind.key_kind):
                return "Object<%s, %s>" % (recurse_with_nullability(
                    kind.key_kind), recurse_with_nullability(kind.value_kind))
            if mojom.IsMapKind(kind):
                return "Map<%s, %s>" % (recurse_with_nullability(
                    kind.key_kind), recurse_with_nullability(kind.value_kind))

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

            name = []
            qualified = (not for_module) or (self.module
                                             is not named_kind.module)
            if qualified and 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 for_module:
                name = name.replace(".", "_")

            if (mojom.IsStructKind(kind) or mojom.IsUnionKind(kind)
                    or mojom.IsEnumKind(kind)):
                return name
            if mojom.IsInterfaceKind(kind) or mojom.IsPendingRemoteKind(kind):
                return name + "Remote"
            if mojom.IsInterfaceRequestKind(
                    kind) or mojom.IsPendingReceiverKind(kind):
                return name + "PendingReceiver"
            # 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)
Ejemplo n.º 18
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.º 19
0
        def get_spec(kind):
            if self._IsPrimitiveKind(kind):
                return _kind_to_lite_js_type[kind]
            if mojom.IsArrayKind(kind):
                return "mojo.internal.Array(%s, %s)" % (get_spec(
                    kind.kind), "true" if mojom.IsNullableKind(kind.kind) else
                                                        "false")
            if mojom.IsMapKind(kind):
                return "mojo.internal.Map(%s, %s, %s)" % (
                    get_spec(kind.key_kind), get_spec(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)
                    or mojom.IsPendingAssociatedRemoteKind(kind)
                    or mojom.IsPendingAssociatedReceiverKind(kind)):
                named_kind = kind.kind
            else:
                named_kind = kind

            name = []
            qualified = (not for_module) or (self.module
                                             is not named_kind.module)
            if qualified and 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) and not for_module:
                    parent_name += "Spec"
                name.append(parent_name)
            name.append(named_kind.name)
            name = ".".join(name)
            if for_module:
                name = name.replace(".", "_")

            if (mojom.IsStructKind(kind) or mojom.IsUnionKind(kind)
                    or mojom.IsEnumKind(kind)):
                return "%sSpec.$" % name
            if mojom.IsInterfaceKind(kind) or mojom.IsPendingRemoteKind(kind):
                return "mojo.internal.InterfaceProxy(%sRemote)" % name
            if mojom.IsInterfaceRequestKind(
                    kind) or mojom.IsPendingReceiverKind(kind):
                return "mojo.internal.InterfaceRequest(%sPendingReceiver)" % name
            if (mojom.IsAssociatedInterfaceKind(kind)
                    or mojom.IsPendingAssociatedRemoteKind(kind)):
                # TODO(rockot): Implement associated interfaces.
                return "mojo.internal.AssociatedInterfaceProxy(%sRemote)" % (
                    name)
            if (mojom.IsAssociatedInterfaceRequestKind(kind)
                    or mojom.IsPendingAssociatedReceiverKind(kind)):
                return "mojo.internal.AssociatedInterfaceRequest(%sPendingReceiver)" % (
                    name)

            return name
Ejemplo n.º 20
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)
                or mojom.IsPendingAssociatedRemoteKind(kind)
                or mojom.IsPendingAssociatedReceiverKind(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
Ejemplo n.º 21
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)
                or mojom.IsPendingAssociatedRemoteKind(kind)
                or mojom.IsPendingAssociatedReceiverKind(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 + self._GetPrimitivesNames()["remote"]
        if mojom.IsInterfaceRequestKind(kind) or mojom.IsPendingReceiverKind(
                kind):
            return name + self._GetPrimitivesNames()["pending_receiver"]
        # 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)
Ejemplo n.º 22
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.IsInterfaceKind(kind):
            return '%s::Ptr' % self._GetCppProtoNameForKind(
                kind, add_same_module_namespaces=add_same_module_namespaces)
        elif mojom.IsInterfaceRequestKind(kind):
            return '%s::Request' % self._GetCppProtoNameForKind(
                kind.kind,
                add_same_module_namespaces=add_same_module_namespaces)
        elif mojom.IsAssociatedInterfaceKind(kind):
            return '%s::AssociatedPtr' % self._GetCppProtoNameForKind(
                kind.kind,
                add_same_module_namespaces=add_same_module_namespaces)
        elif mojom.IsAssociatedInterfaceRequestKind(kind):
            return '%s::AssociatedRequest' % self._GetCppProtoNameForKind(
                kind.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.º 23
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):
     return 'readInterfaceRequest'
   if mojom.IsInterfaceKind(kind):
     return 'readServiceInterface'
   if mojom.IsAssociatedInterfaceRequestKind(kind):
     return 'readAssociatedInterfaceRequestNotSupported'
   if mojom.IsAssociatedInterfaceKind(kind):
     return 'readAssociatedServiceInterfaceNotSupported'
   return _spec_to_decode_method[kind.spec]
Ejemplo n.º 24
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.º 25
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)
Ejemplo n.º 26
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.º 27
0
    def _LiteClosureType(self, kind):
        if kind in mojom.PRIMITIVES:
            return _kind_to_closure_type[kind]
        if mojom.IsArrayKind(kind):
            return "Array<%s>" % self._ClosureType(kind.kind)
        if mojom.IsMapKind(kind) and self._IsStringableKind(kind.key_kind):
            return "Map<%s, %s>|Object<%s, %s>" % (self._LiteClosureType(
                kind.key_kind), self._LiteClosureType(
                    kind.value_kind), self._LiteClosureType(
                        kind.key_kind), self._LiteClosureType(kind.value_kind))
        if mojom.IsMapKind(kind):
            return "Map<%s, %s>" % (self._LiteClosureType(
                kind.key_kind), self._LiteClosureType(kind.value_kind))

        if mojom.IsAssociatedKind(kind) or mojom.IsInterfaceRequestKind(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)
        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):
            return name + "Proxy"
        if mojom.IsInterfaceRequestKind(kind):
            return name + "Request"
        # TODO(calamity): Support associated interfaces properly.
        if mojom.IsAssociatedInterfaceKind(kind):
            return "Object"
        # TODO(calamity): Support associated interface requests properly.
        if mojom.IsAssociatedInterfaceRequestKind(kind):
            return "Object"

        raise Exception("No valid closure type: %s" % kind)
Ejemplo n.º 28
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)
Ejemplo n.º 29
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):
            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)
        name.append(named_kind.name)
        name = ".".join(name)

        if (mojom.IsStructKind(kind) or mojom.IsUnionKind(kind)
                or mojom.IsEnumKind(kind)):
            return "%s.$" % name
        if mojom.IsInterfaceKind(kind):
            return "mojo.internal.InterfaceProxy(%sProxy)" % name
        if mojom.IsInterfaceRequestKind(kind):
            return "mojo.internal.InterfaceRequest(%sRequest)" % name
        if mojom.IsAssociatedInterfaceKind(kind):
            return "mojo.internal.AssociatedInterfaceProxy(%sAssociatedProxy)" % (
                name)
        if mojom.IsAssociatedInterfaceRequestKind(kind):
            return "mojo.internal.AssociatedInterfaceRequest(%s)" % name

        return name
Ejemplo n.º 30
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]