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)
Exemple #2
0
def GetMojomTypeValue(kind, typepkg=''):
  if not kind in _kind_infos:
    return ''

  nullable = 'true' if mojom.IsNullableKind(kind) else 'false'
  if kind == mojom.BOOL or kind == mojom.FLOAT or kind == mojom.DOUBLE or \
    mojom.IsIntegralKind(kind):

    kind_name = UpperCamelCase(_kind_infos[kind].decode_suffix.upper())
    if kind == mojom.FLOAT:
      kind_name = "Float"
    elif kind == mojom.DOUBLE:
      kind_name = "Double"
    return '%sTypeSimpleType{%sSimpleType_%s}' % (typepkg, typepkg, kind_name)
  elif mojom.IsAnyHandleKind(kind):
    kind_name = 'Unspecified'
    if kind == mojom.DCPIPE:
      kind_name = 'DataPipeConsumer'
    elif kind == mojom.DPPIPE:
      kind_name = 'DataPipeProducer'
    elif kind == mojom.MSGPIPE:
      kind_name = 'MessagePipe'
    elif kind == mojom.SHAREDBUFFER:
      kind_name = 'SharedBuffer'
    return '%sTypeHandleType{%sHandleType{' \
      'Nullable: %s, Kind: %sHandleType_Kind_%s}}' % \
      (typepkg, typepkg, nullable, typepkg, kind_name)
  elif mojom.IsStringKind(kind):
    return '%sTypeStringType{%sStringType{%s}}' % (typepkg, typepkg, nullable)
  else:
    raise Exception('Missing case for kind: %s' % 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 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)
Exemple #5
0
 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))
Exemple #6
0
 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))
Exemple #7
0
def _ResolveNumericEnumValues(enum):
    """
  Given a reference to a mojom.Enum, resolves and assigns the numeric value of
  each field, and also computes the min_value and max_value of the enum.
  """

    # map of <mojom_name> -> integral value
    prev_value = -1
    min_value = None
    max_value = None
    for field in enum.fields:
        # This enum value is +1 the previous enum value (e.g: BEGIN).
        if field.value is None:
            prev_value += 1

        # Integral value (e.g: BEGIN = -0x1).
        elif _IsStrOrUnicode(field.value):
            prev_value = int(field.value, 0)

        # Reference to a previous enum value (e.g: INIT = BEGIN).
        elif isinstance(field.value, mojom.EnumValue):
            prev_value = field.value.field.numeric_value
        elif isinstance(field.value, mojom.ConstantValue):
            constant = field.value.constant
            kind = constant.kind
            if not mojom.IsIntegralKind(kind) or mojom.IsBoolKind(kind):
                raise ValueError(
                    'Enum values must be integers. %s is not an integer.' %
                    constant.mojom_name)
            prev_value = int(constant.value, 0)
        else:
            raise Exception('Unresolved enum value for %s' %
                            field.value.GetSpec())

        #resolved_enum_values[field.mojom_name] = prev_value
        field.numeric_value = prev_value
        if min_value is None or prev_value < min_value:
            min_value = prev_value
        if max_value is None or prev_value > max_value:
            max_value = prev_value

    enum.min_value = min_value
    enum.max_value = max_value
Exemple #8
0
 def _IsObjCNumberKind(self, kind):
     return (mojom.IsIntegralKind(kind) or mojom.IsDoubleKind(kind)
             or mojom.IsFloatKind(kind))