Example #1
0
    def _KindMustBeSerialized(self, kind, processed_kinds=None):
        if not processed_kinds:
            processed_kinds = set()
        if kind in processed_kinds:
            return False

        if (self._IsTypemappedKind(kind) and self.typemap[
                self._GetFullMojomNameForKind(kind)]["force_serialize"]):
            return True

        processed_kinds.add(kind)

        if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind):
            return any(
                self._KindMustBeSerialized(field.kind,
                                           processed_kinds=processed_kinds)
                for field in kind.fields)

        return False
Example #2
0
    def _IsFullHeaderRequiredForImport(self, imported_module):
        """Determines whether a given import module requires a full header include,
    or if the forward header is sufficient."""

        # Type-mapped kinds may not have forward declarations, and nested kinds
        # cannot be forward declared.
        if any(kind.module == imported_module and ((self._IsTypemappedKind(
                kind) and not self._GetTypemappedForwardDeclaration(kind))
                                                   or kind.parent_kind != None)
               for kind in self.module.imported_kinds.values()):
            return True

        # For most kinds, whether or not a full definition is needed depends on how
        # the kind is used.
        for kind in self.module.structs + self.module.unions:
            for field in kind.fields:

                # Peel array kinds.
                kind = field.kind
                while mojom.IsArrayKind(kind):
                    kind = kind.kind

                if kind.module == imported_module:
                    # Need full def for struct/union fields, even when not inlined.
                    if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind):
                        return True

        for kind in self.module.kinds.values():
            if mojom.IsMapKind(kind):
                if kind.key_kind.module == imported_module:
                    # Map keys need the full definition.
                    return True
                if self.for_blink and kind.value_kind.module == imported_module:
                    # For Blink, map values need the full definition for tracing.
                    return True

        for constant in self.module.constants:
            # Constants referencing enums need the full definition.
            if mojom.IsEnumKind(constant.kind
                                ) and constant.value.module == imported_module:
                return True

        return False
Example #3
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):
            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)
def DartDeclType(kind):
    if kind in mojom.PRIMITIVES:
        return _kind_to_dart_decl_type[kind]
    if mojom.IsStructKind(kind):
        return GetDartType(kind)
    if mojom.IsUnionKind(kind):
        return GetDartType(kind)
    if mojom.IsArrayKind(kind):
        array_type = DartDeclType(kind.kind)
        return "List<" + array_type + ">"
    if mojom.IsMapKind(kind):
        key_type = DartDeclType(kind.key_kind)
        value_type = DartDeclType(kind.value_kind)
        return "Map<" + key_type + ", " + value_type + ">"
    if mojom.IsInterfaceKind(kind) or \
       mojom.IsInterfaceRequestKind(kind):
        return "Object"
    if mojom.IsEnumKind(kind):
        return GetDartType(kind)
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)
Example #6
0
        def AddKind(kind):
            if IsBasicKind(kind):
                pass
            elif mojom.IsArrayKind(kind):
                AddKind(kind.kind)
            elif mojom.IsMapKind(kind):
                AddKind(kind.key_kind)
                AddKind(kind.value_kind)
            else:
                name = self._GetFullMojomNameForKind(kind)
                if name in seen_types:
                    return
                seen_types.add(name)

                typemap = self.typemap.get(name, None)
                if typemap:
                    used_typemaps.append(typemap)
                if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind):
                    for field in kind.fields:
                        AddKind(field.kind)
Example #7
0
    def _GetImportsForKind(self, kind):
        qualified_name = self._GetNameInJsModule(kind)

        def make_import(name, suffix=''):
            class ImportInfo(object):
                def __init__(self, name, alias):
                    self.name = name
                    self.alias = alias

            return ImportInfo(name + suffix, qualified_name + suffix)

        if (mojom.IsEnumKind(kind) or mojom.IsStructKind(kind)
                or mojom.IsUnionKind(kind)):
            return [make_import(kind.name), make_import(kind.name, 'Spec')]
        if mojom.IsInterfaceKind(kind):
            return [
                make_import(kind.name, 'Remote'),
                make_import(kind.name, 'PendingReceiver')
            ]
        assert False, kind.name
Example #8
0
def GetCppFieldType(kind):
  if mojom.IsStructKind(kind):
    return ("::fidl::internal::StructPointer<%s_Data>" %
        GetNameForKind(kind, internal=True))
  if mojom.IsUnionKind(kind):
    return "%s_Data" % GetNameForKind(kind, internal=True)
  if mojom.IsArrayKind(kind):
    return "::fidl::internal::ArrayPointer<%s>" % GetCppType(kind.kind)
  if mojom.IsMapKind(kind):
    return ("::fidl::internal::StructPointer<::fidl::internal::Map_Data<%s, %s>>" %
            (GetCppType(kind.key_kind), GetCppType(kind.value_kind)))
  if mojom.IsInterfaceKind(kind):
    return "::fidl::internal::Interface_Data"
  if mojom.IsInterfaceRequestKind(kind):
    return "::fidl::internal::WrappedHandle"
  if mojom.IsEnumKind(kind):
    return GetNameForKind(kind)
  if mojom.IsStringKind(kind):
    return "::fidl::internal::StringPointer"
  return GetCppTypeForKind(kind)
Example #9
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.IsInterfaceRequestKind(kind):
         return "codec.%s" % ("NullableInterfaceRequest" if mojom.
                              IsNullableKind(kind) else "InterfaceRequest")
     if mojom.IsAssociatedInterfaceKind(kind):
         return "codec.%s" % ("NullableAssociatedInterfacePtrInfo"
                              if mojom.IsNullableKind(kind) else
                              "AssociatedInterfacePtrInfo")
     if mojom.IsAssociatedInterfaceRequestKind(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)
Example #10
0
def GetNameForElement(element):
    if (mojom.IsEnumKind(element) or mojom.IsInterfaceKind(element)
            or mojom.IsStructKind(element) or mojom.IsUnionKind(element)):
        name = UpperCamelCase(element.name)
        if name in _java_reserved_types:
            return name + '_'
        return name
    if (mojom.IsInterfaceRequestKind(element)
            or mojom.IsAssociatedKind(element)
            or mojom.IsPendingRemoteKind(element)
            or mojom.IsPendingReceiverKind(element)):
        return GetNameForElement(element.kind)
    if isinstance(element, (mojom.Method, mojom.Parameter, mojom.Field)):
        return CamelCase(element.name)
    if isinstance(element, mojom.EnumValue):
        return (GetNameForElement(element.enum) + '.' +
                ConstantStyle(element.name))
    if isinstance(element,
                  (mojom.NamedValue, mojom.Constant, mojom.EnumField)):
        return ConstantStyle(element.name)
    raise Exception('Unexpected element: %s' % element)
Example #11
0
def DartDefaultValue(field):
    if field.default:
        if mojom.IsStructKind(field.kind):
            assert field.default == "default"
            return "new %s()" % GetDartType(field.kind)
        return ExpressionToText(field.default)
    if field.kind in mojom.PRIMITIVES:
        return _kind_to_dart_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) or \
       mojom.IsInterfaceRequestKind(field.kind):
        return "null"
    if mojom.IsEnumKind(field.kind):
        return "0"
def GetCppFieldType(kind):
    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.IsEnumKind(kind):
        return GetNameForKind(kind)
    if mojom.IsStringKind(kind):
        return "mojo::internal::StringPointer"
    return _kind_to_cpp_type[kind]
Example #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.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]
Example #14
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
Example #15
0
def JavaScriptDefaultValue(field):
    if field.default:
        if mojom.IsStructKind(field.kind):
            assert field.default == "default"
            return "new %s()" % JavaScriptType(field.kind)
        return 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) or \
       mojom.IsInterfaceRequestKind(field.kind):
        return _kind_to_javascript_default_value[mojom.MSGPIPE]
    if mojom.IsEnumKind(field.kind):
        return "0"
    raise Exception("No valid default: %s" % field)
Example #16
0
def GetCppConstWrapperType(kind):
  if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind):
    return "%sPtr" % GetNameForKind(kind)
  if mojom.IsArrayKind(kind):
    return "::fidl::Array<%s>" % GetCppArrayArgWrapperType(kind.kind)
  if mojom.IsMapKind(kind):
    return "::fidl::Map<%s, %s>" % (GetCppArrayArgWrapperType(kind.key_kind),
                                  GetCppArrayArgWrapperType(kind.value_kind))
  if mojom.IsInterfaceKind(kind):
    return "::fidl::InterfaceHandle<%s>" % GetNameForKind(kind)
  if mojom.IsInterfaceRequestKind(kind):
    return "::fidl::InterfaceRequest<%s>" % GetNameForKind(kind.kind)
  if mojom.IsEnumKind(kind):
    return GetNameForKind(kind)
  if mojom.IsStringKind(kind):
    return "const ::fidl::String&"
  if mojom.IsGenericHandleKind(kind):
    return "zx::handle"
  if mojom.IsChannelKind(kind):
    return "zx::channel"
  if mojom.IsVMOKind(kind):
    return "zx::vmo"
  if mojom.IsProcessKind(kind):
    return "zx::process"
  if mojom.IsThreadKind(kind):
    return "zx::thread"
  if mojom.IsEventKind(kind):
    return "zx::event"
  if mojom.IsPortKind(kind):
    return "zx::port"
  if mojom.IsJobKind(kind):
    return "zx::job"
  if mojom.IsSocketKind(kind):
    return "zx::socket"
  if mojom.IsEventPairKind(kind):
    return "zx::eventpair"
  if not kind in _kind_to_cpp_type:
    print "missing:", kind.spec
  return GetCppTypeForKind(kind)
    def _GetCppDataViewType(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.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]
Example #18
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]
Example #19
0
def GetNameForElement(element):
  if (mojom.IsInterfaceKind(element) or mojom.IsStructKind(element) or
      mojom.IsUnionKind(element)):
    return UpperCamelCase(element.name)
  if mojom.IsEnumKind(element):
    if element.parent_kind:
      return ("%s%s" % (UpperCamelCase(element.parent_kind.name),
                        UpperCamelCase(element.name)))
    return UpperCamelCase(element.name)
  if mojom.IsInterfaceRequestKind(element):
    return GetNameForElement(element.kind)
  if isinstance(element, (mojom.Method,
                          mojom.Parameter,
                          mojom.Field)):
    return CamelCase(element.name)
  if isinstance(element, mojom.EnumValue):
    return (GetNameForElement(element.enum) + '.' +
            ConstantStyle(element.name))
  if isinstance(element, (mojom.NamedValue,
                          mojom.Constant,
                          mojom.EnumField)):
    return ConstantStyle(element.name)
  raise Exception('Unexpected element: %s' % element)
Example #20
0
def GetCppType(kind):
    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]
Example #21
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]
Example #22
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]
Example #23
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]
Example #24
0
def GetCppUnionFieldType(kind):
    if mojom.IsUnionKind(kind):
        return ("mojo::internal::Pointer<%s>" %
                GetNameForKind(kind, internal=True))
    return GetCppFieldType(kind)
Example #25
0
 def _JavaScriptUnionEncodeSnippet(self, kind):
     if mojom.IsUnionKind(kind):
         return "encodeStructPointer(%s, " % self._JavaScriptType(kind)
     return self._JavaScriptEncodeSnippet(kind)
Example #26
0
 def _JavaScriptUnionDecodeSnippet(self, kind):
     if mojom.IsUnionKind(kind):
         return "decodeStructPointer(%s)" % self._JavaScriptType(kind)
     return self._JavaScriptDecodeSnippet(kind)
  def _GetCppWrapperType(self, kind, add_same_module_namespaces=False):
    def _AddOptional(type_name):
      return "base::Optional<%s>" % type_name

    if self._IsTypemappedKind(kind):
      type_name = self._GetNativeTypeName(kind)
      if (mojom.IsNullableKind(kind) and
          not self.typemap[self._GetFullMojomNameForKind(kind)][
             "nullable_is_same_type"]):
        type_name = _AddOptional(type_name)
      return type_name
    if mojom.IsEnumKind(kind):
      return self._GetNameForKind(
          kind, add_same_module_namespaces=add_same_module_namespaces)
    if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind):
      return "%sPtr" % self._GetNameForKind(
          kind, add_same_module_namespaces=add_same_module_namespaces)
    if mojom.IsArrayKind(kind):
      pattern = "WTF::Vector<%s>" if self.for_blink else "std::vector<%s>"
      if mojom.IsNullableKind(kind):
        pattern = _AddOptional(pattern)
      return pattern % self._GetCppWrapperType(
          kind.kind, add_same_module_namespaces=add_same_module_namespaces)
    if mojom.IsMapKind(kind):
      pattern = ("WTF::HashMap<%s, %s>" if self.for_blink else
                 "base::flat_map<%s, %s>")
      if mojom.IsNullableKind(kind):
        pattern = _AddOptional(pattern)
      return pattern % (
          self._GetCppWrapperType(
              kind.key_kind,
              add_same_module_namespaces=add_same_module_namespaces),
          self._GetCppWrapperType(
              kind.value_kind,
              add_same_module_namespaces=add_same_module_namespaces))
    if mojom.IsInterfaceKind(kind):
      return "%sPtrInfo" % self._GetNameForKind(
          kind, add_same_module_namespaces=add_same_module_namespaces)
    if mojom.IsInterfaceRequestKind(kind):
      return "%sRequest" % self._GetNameForKind(
          kind.kind, add_same_module_namespaces=add_same_module_namespaces)
    if mojom.IsPendingRemoteKind(kind):
      return "mojo::PendingRemote<%s>" % self._GetNameForKind(
          kind.kind, add_same_module_namespaces=add_same_module_namespaces)
    if mojom.IsPendingReceiverKind(kind):
      return "mojo::PendingReceiver<%s>" % self._GetNameForKind(
          kind.kind, add_same_module_namespaces=add_same_module_namespaces)
    if mojom.IsPendingAssociatedRemoteKind(kind):
      return "mojo::PendingAssociatedRemote<%s>" % self._GetNameForKind(
          kind.kind, add_same_module_namespaces=add_same_module_namespaces)
    if mojom.IsPendingAssociatedReceiverKind(kind):
      return "mojo::PendingAssociatedReceiver<%s>" % self._GetNameForKind(
          kind.kind, add_same_module_namespaces=add_same_module_namespaces)
    if mojom.IsAssociatedInterfaceKind(kind):
      return "%sAssociatedPtrInfo" % self._GetNameForKind(
          kind.kind, add_same_module_namespaces=add_same_module_namespaces)
    if mojom.IsAssociatedInterfaceRequestKind(kind):
      return "%sAssociatedRequest" % self._GetNameForKind(
          kind.kind, add_same_module_namespaces=add_same_module_namespaces)
    if mojom.IsStringKind(kind):
      if self.for_blink:
        return "WTF::String"
      type_name = "std::string"
      return (_AddOptional(type_name) if mojom.IsNullableKind(kind)
                                      else type_name)
    if mojom.IsGenericHandleKind(kind):
      return "mojo::ScopedHandle"
    if mojom.IsDataPipeConsumerKind(kind):
      return "mojo::ScopedDataPipeConsumerHandle"
    if mojom.IsDataPipeProducerKind(kind):
      return "mojo::ScopedDataPipeProducerHandle"
    if mojom.IsMessagePipeKind(kind):
      return "mojo::ScopedMessagePipeHandle"
    if mojom.IsSharedBufferKind(kind):
      return "mojo::ScopedSharedBufferHandle"
    if not kind in _kind_to_cpp_type:
      raise Exception("Unrecognized kind %s" % kind.spec)
    return _kind_to_cpp_type[kind]
Example #28
0
def IsUnionArrayKind(kind):
  if not mojom.IsArrayKind(kind):
    return False
  sub_kind = kind.kind
  return mojom.IsUnionKind(sub_kind)
Example #29
0
def IsPointerArrayKind(kind):
  if not mojom.IsArrayKind(kind):
    return False
  sub_kind = kind.kind
  return mojom.IsObjectKind(sub_kind) and not mojom.IsUnionKind(sub_kind)
Example #30
0
def GetGoType(kind, nullable = True):
  if nullable and mojom.IsNullableKind(kind) and not mojom.IsUnionKind(kind):
    return '*%s' % GetNonNullableGoType(kind)
  return GetNonNullableGoType(kind)