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]
def _GetNewContainerValidateParams(self, kind): if (not mojom.IsArrayKind(kind) and not mojom.IsMapKind(kind) and not mojom.IsStringKind(kind)): return "nullptr" return "new mojo::internal::ContainerValidateParams(%s)" % ( self._GetContainerValidateParamsCtorArgs(kind))
def AddKind(kind): if (mojom.IsIntegralKind(kind) or mojom.IsStringKind(kind) or mojom.IsDoubleKind(kind) or mojom.IsFloatKind(kind) or mojom.IsAnyHandleKind(kind) or mojom.IsInterfaceKind(kind) or mojom.IsInterfaceRequestKind(kind) or mojom.IsAssociatedKind(kind) or mojom.IsPendingRemoteKind(kind) or mojom.IsPendingReceiverKind(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)
def _IsStringableKind(self, kind): # Indicates whether a kind of suitable to stringify and use as an Object # property name. This is checked for map key types to allow most kinds of # mojom maps to be represented as either a Map or an Object. return (mojom.IsIntegralKind(kind) or mojom.IsFloatKind(kind) or mojom.IsDoubleKind(kind) or mojom.IsStringKind(kind) or mojom.IsEnumKind(kind))
def _GetContainerValidateParamsCtorArgs(self, kind): if mojom.IsStringKind(kind): expected_num_elements = 0 element_is_nullable = False key_validate_params = "nullptr" element_validate_params = "nullptr" enum_validate_func = "nullptr" elif mojom.IsMapKind(kind): expected_num_elements = 0 element_is_nullable = False key_validate_params = self._GetNewContainerValidateParams( mojom.Array(kind=kind.key_kind)) element_validate_params = self._GetNewContainerValidateParams( mojom.Array(kind=kind.value_kind)) enum_validate_func = "nullptr" else: # mojom.IsArrayKind(kind) expected_num_elements = generator.ExpectedArraySize(kind) or 0 element_is_nullable = mojom.IsNullableKind(kind.kind) key_validate_params = "nullptr" element_validate_params = self._GetNewContainerValidateParams( kind.kind) if mojom.IsEnumKind(kind.kind): enum_validate_func = ( "%s::Validate" % self._GetQualifiedNameForKind( kind.kind, internal=True, flatten_nested_kind=True)) else: enum_validate_func = "nullptr" if enum_validate_func == "nullptr": if key_validate_params == "nullptr": return "%d, %s, %s" % (expected_num_elements, "true" if element_is_nullable else "false", element_validate_params) return "%s, %s" % (key_validate_params, element_validate_params) return "%d, %s" % (expected_num_elements, enum_validate_func)
def IsBasicKind(kind): return (mojom.IsIntegralKind(kind) or mojom.IsStringKind(kind) or mojom.IsDoubleKind(kind) or mojom.IsFloatKind(kind) or mojom.IsAnyHandleKind(kind) or mojom.IsInterfaceKind(kind) or mojom.IsInterfaceRequestKind(kind) or mojom.IsAssociatedKind(kind))
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>>" % GetCppFieldType(kind.kind)) if mojom.IsMapKind(kind): return ( "mojo::internal::Pointer<mojo::internal::Map_Data<%s, %s>>" % (GetCppFieldType(kind.key_kind), GetCppFieldType(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]
def FormatConstantDeclaration(constant, nested=False): if mojom.IsStringKind(constant.kind): if nested: return "const char %s[]" % constant.name return "extern const char %s[]" % constant.name return "constexpr %s %s = %s" % (GetCppPodType( constant.kind), constant.name, ConstantValue(constant))
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]
def _GetObjCPropertyModifiers(self, kind): modifiers = ['nonatomic'] if (mojom.IsArrayKind(kind) or mojom.IsStringKind(kind) or mojom.IsMapKind(kind) or self._IsMojomStruct(kind)): modifiers.append('copy') if mojom.IsNullableKind(kind): modifiers.append('nullable') return ', '.join(modifiers)
def GetNewArrayValidateParams(kind): if (not mojom.IsArrayKind(kind) and not mojom.IsMapKind(kind) and not mojom.IsStringKind(kind) and not (mojom.IsStructKind(kind) and kind.native_only)): return "nullptr" return "new mojo::internal::ArrayValidateParams(%s)" % ( GetArrayValidateParamsCtorArgs(kind))
def FormatConstantDeclaration(constant, nested=False): if mojom.IsStringKind(constant.kind): if nested: return "const char %s[]" % constant.name return "%sextern const char %s[]" % \ ((_export_attribute + " ") if _export_attribute else "", constant.name) return "constexpr %s %s = %s" % (GetCppPodType( constant.kind), constant.name, ConstantValue(constant))
def ShouldInlineStruct(struct): # TODO(darin): Base this on the size of the wrapper class. if len(struct.fields) > 4: return False for field in struct.fields: if mojom.IsReferenceKind(field.kind) and not mojom.IsStringKind(field.kind): return False return True
def _WriteInputParamForTracing(self, kind, mojo_prefix, parameter_name, value): """Generates lines of C++ to log parameter |parameter_name| into TracedValue |value|. Args: kind: {Kind} The kind of the parameter (corresponds to its C++ type). mojo_prefix: {string} The prefix of the auto-generated parameter. parameter_name: {string} The mojom parameter name to be logged (auto-generated C++ parameter name is |mojo_prefix+parameter_name|). value: {string} The C++ TracedValue* variable name to be logged into. Yields: {string} C++ lines of code that trace |parameter_name| into |value|. """ cpp_parameter_name = mojo_prefix + parameter_name value_name_cppname = (value, parameter_name, cpp_parameter_name) # TODO(crbug.com/1103623): Support more involved types. if mojom.IsEnumKind(kind): # TODO(crbug.com/1103623): Pretty-print enums. yield '%s->SetInteger("%s", static_cast<int>(%s));' % value_name_cppname return if mojom.IsStringKind(kind): if self.for_blink: # WTF::String is nullable on its own. yield '%s->SetString("%s", %s.Utf8());' % value_name_cppname return if mojom.IsNullableKind(kind): # base::Optional<std::string> yield 'if (%s.has_value()) {' % cpp_parameter_name yield ' %s->SetString("%s", %s.value());' % value_name_cppname yield '} else {' yield ' %s->SetString("%s", "base::nullopt");' % ( value, parameter_name) yield '}' return else: yield '%s->SetString("%s", %s);' % value_name_cppname return if kind == mojom.BOOL: yield '%s->SetBoolean("%s", %s);' % value_name_cppname return # TODO(crbug.com/1103623): Make TracedValue support int64_t, then move to # mojom.IsIntegralKind. if kind in [ mojom.INT8, mojom.UINT8, mojom.INT16, mojom.UINT16, mojom.INT32 ]: # Parameter is representable as 32bit int. yield '%s->SetInteger("%s", %s);' % value_name_cppname return if kind in [mojom.UINT32, mojom.INT64, mojom.UINT64]: yield '%s->SetString("%s", std::to_string(%s));' % value_name_cppname return if mojom.IsFloatKind(kind) or mojom.IsDoubleKind(kind): yield '%s->SetDouble("%s", %s);' % value_name_cppname return yield '%s->SetString("%s", "<value of type %s>");' % ( value, parameter_name, self._GetCppWrapperParamType(kind))
def _GetObjCPropertyModifiers(self, kind, inside_union=False): modifiers = ['nonatomic'] if (mojom.IsArrayKind(kind) or mojom.IsStringKind(kind) or mojom.IsMapKind(kind) or mojom.IsStructKind(kind)): modifiers.append('copy') if ((inside_union and mojom.IsObjectKind(kind)) or mojom.IsNullableKind(kind)): modifiers.append('nullable') return ', '.join(modifiers)
def GetArrayExpectedDimensionSizes(kind): expected_dimension_sizes = [] while mojom.IsArrayKind(kind): expected_dimension_sizes.append(generator.ExpectedArraySize(kind) or 0) kind = kind.kind # Strings are serialized as variable-length arrays. if (mojom.IsStringKind(kind)): expected_dimension_sizes.append(0) return expected_dimension_sizes
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
def DefaultValue(field): if field.default: if mojom.IsStructKind(field.kind): assert field.default == "default" return "%s::New()" % GetNameForKind(field.kind) return ExpressionToText(field.default, kind=field.kind) if (mojom.IsStringKind(field.kind) or mojom.IsArrayKind(field.kind) or mojom.IsMapKind(field.kind)): return "nullptr" return ""
def _ConstObjCAssign(self, constant): kind = constant.kind # Obj-C only supports a handful of constant types if mojom.IsStringKind(kind): # string constant value come with quotes already return '@%s' % constant.value if kind in _kind_to_nsnumber_getter: return constant.value raise Exception( "Obj-C constant cannot be generated for the given kind: %s" % kind)
def _FormatConstantDeclaration(self, constant, nested=False): if mojom.IsStringKind(constant.kind): if nested: return "const char %s[]" % constant.name return "%sextern const char %s[]" % \ ((self.export_attribute + " ") if self.export_attribute else "", constant.name) return "const %s %s_%s = %s" % (GetCppPodType( constant.kind), self.module.namespace, constant.name, self._ConstantValue(constant))
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]
def _IsStringableKind(self, kind): # Indicates whether a kind of suitable to stringify and use as an Object # property name. This is checked for map key types to allow most kinds of # mojom maps to be represented as either a Map or an Object. if kind == mojom.INT64 or kind == mojom.UINT64: # JS BigInts are not stringable and cannot be used as Object property # names. return False return (mojom.IsIntegralKind(kind) or mojom.IsFloatKind(kind) or mojom.IsDoubleKind(kind) or mojom.IsStringKind(kind) or mojom.IsEnumKind(kind))
def GetArrayValidateParams(kind): if (not mojom.IsArrayKind(kind) and not mojom.IsMapKind(kind) and not mojom.IsStringKind(kind)): return "mojo::internal::NoValidateParams" if mojom.IsStringKind(kind): expected_num_elements = 0 element_is_nullable = False element_validate_params = "mojo::internal::NoValidateParams" elif mojom.IsMapKind(kind): expected_num_elements = 0 element_is_nullable = mojom.IsNullableKind(kind.value_kind) element_validate_params = GetArrayValidateParams(kind.value_kind) else: expected_num_elements = generator.ExpectedArraySize(kind) or 0 element_is_nullable = mojom.IsNullableKind(kind.kind) element_validate_params = GetArrayValidateParams(kind.kind) return "mojo::internal::ArrayValidateParams<%d, %s,\n%s> " % ( expected_num_elements, 'true' if element_is_nullable else 'false', element_validate_params)
def _NullableIsSameKind(self, kind): if self._IsTypemappedKind(kind): if not self.typemap[self._GetFullMojomNameForKind( kind)]["nullable_is_same_type"]: return False if mojom.IsArrayKind(kind): return False if mojom.IsMapKind(kind): return False if mojom.IsStringKind(kind): return False return True
def GetCppType(kind): if mojom.IsStructKind(kind): return "%s_Data*" % GetNameForKind(kind, internal=True) if mojom.IsAnyArrayKind(kind): return "mojo::internal::Array_Data<%s>*" % GetCppType(kind.kind) if mojom.IsInterfaceKind(kind) or mojom.IsInterfaceRequestKind(kind): return "mojo::MessagePipeHandle" if mojom.IsEnumKind(kind): return "int32_t" if mojom.IsStringKind(kind): return "mojo::internal::String_Data*" return _kind_to_cpp_type[kind]
def DefaultValue(field): if field.default: if mojom.IsStructKind(field.kind): assert field.default == "default" if not IsTypemappedKind(field.kind): return "%s::New()" % GetNameForKind(field.kind) return ExpressionToText(field.default, kind=field.kind) if not _use_new_wrapper_types: if mojom.IsArrayKind(field.kind) or mojom.IsMapKind(field.kind): return "nullptr"; if mojom.IsStringKind(field.kind): return "" if _for_blink else "nullptr" return ""
def GetCppFieldType(kind): if mojom.IsStructKind(kind): return ("mojo::internal::StructPointer<%s_Data>" % GetNameForKind(kind, internal=True)) if mojom.IsAnyArrayKind(kind): return "mojo::internal::ArrayPointer<%s>" % GetCppType(kind.kind) if mojom.IsInterfaceKind(kind) or 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]
def _ObjcPropertyNeedsDefaultValueAssignment(self, field): kind = field.kind if not field.default: # If there's no specified default, only make defaults for required types return (not mojom.IsNullableKind(kind) and (mojom.IsStringKind(kind) or mojom.IsArrayKind(kind) or mojom.IsMapKind(kind) or self._IsMojomStruct(kind))) if self._IsObjCNumberKind(kind) and field.default == 0: # 0 by default anyways return False return True
def GetArrayValidateParams(kind, new=False): if (not mojom.IsArrayKind(kind) and not mojom.IsMapKind(kind) and not mojom.IsStringKind(kind)): return "nullptr" if mojom.IsStringKind(kind): expected_num_elements = 0 element_is_nullable = False element_validate_params = "nullptr" elif mojom.IsMapKind(kind): expected_num_elements = 0 element_is_nullable = mojom.IsNullableKind(kind.value_kind) element_validate_params = GetArrayValidateParams(kind.value_kind, new=True) else: expected_num_elements = generator.ExpectedArraySize(kind) or 0 element_is_nullable = mojom.IsNullableKind(kind.kind) element_validate_params = GetArrayValidateParams(kind.kind, new=True) return "%smojo::internal::ArrayValidateParams(%d, %s,\n%s) " % ( 'new ' if new else '', expected_num_elements, 'true' if element_is_nullable else 'false', element_validate_params)
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]