Exemplo n.º 1
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)
Exemplo n.º 2
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>'
Exemplo n.º 3
0
  def _GetCppWrapperType(self, kind, add_same_module_namespaces=False):
    def _AddOptional(type_name):
      return "base::Optional<%s>" % type_name

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