Exemplo n.º 1
0
def KindFromData(kinds, data, scope):
    kind = LookupKind(kinds, data, scope)
    if kind:
        return kind

    if data.startswith('?'):
        kind = KindFromData(kinds, data[1:], scope).MakeNullableKind()
    elif data.startswith('a:'):
        kind = mojom.Array(KindFromData(kinds, data[2:], scope))
    elif data.startswith('a'):
        colon = data.find(':')
        length = int(data[1:colon])
        kind = mojom.Array(KindFromData(kinds, data[colon + 1:], scope),
                           length)
    elif data.startswith('r:'):
        kind = mojom.InterfaceRequest(KindFromData(kinds, data[2:], scope))
    elif data.startswith('m['):
        # Isolate the two types from their brackets.

        # It is not allowed to use map as key, so there shouldn't be nested ']'s
        # inside the key type spec.
        key_end = data.find(']')
        assert key_end != -1 and key_end < len(data) - 1
        assert data[key_end + 1] == '[' and data[-1] == ']'

        first_kind = data[2:key_end]
        second_kind = data[key_end + 2:-1]

        kind = mojom.Map(KindFromData(kinds, first_kind, scope),
                         KindFromData(kinds, second_kind, scope))
    else:
        kind = mojom.Kind(data)

    kinds[data] = kind
    return kind
Exemplo n.º 2
0
def KindFromData(kinds, data, scope):
    kind = LookupKind(kinds, data, scope)
    if kind:
        return kind

    if data.startswith('?'):
        kind = KindFromData(kinds, data[1:], scope).MakeNullableKind()
    elif data.startswith('a:'):
        kind = mojom.Array(KindFromData(kinds, data[2:], scope))
    elif data.startswith('a'):
        colon = data.find(':')
        length = int(data[1:colon])
        kind = mojom.Array(KindFromData(kinds, data[colon + 1:], scope),
                           length)
    elif data.startswith('r:'):
        kind = mojom.InterfaceRequest(KindFromData(kinds, data[2:], scope))
    elif data.startswith('m['):
        # Isolate the two types from their brackets
        first_kind = data[2:data.find(']')]
        second_kind = data[data.rfind('[') + 1:data.rfind(']')]
        kind = mojom.Map(KindFromData(kinds, first_kind, scope),
                         KindFromData(kinds, second_kind, scope))
    else:
        kind = mojom.Kind(data)

    kinds[data] = kind
    return kind
Exemplo n.º 3
0
def _Kind(kinds, spec, scope):
    """Convert a type name into a mojom.Kind object.

  As a side-effect this function adds the result to 'kinds'.

  Args:
    kinds: {Dict[str, mojom.Kind]} All known kinds up to this point, indexed by
        their names.
    spec: {str} A name uniquely identifying a type.
    scope: {Tuple[str, str]} A tuple that looks like (namespace,
        struct/interface), referring to the location where the type is
        referenced.

  Returns:
    {mojom.Kind} The type corresponding to 'spec'.
  """
    kind = _LookupKind(kinds, spec, scope)
    if kind:
        return kind

    if spec.startswith('?'):
        kind = _Kind(kinds, spec[1:], scope).MakeNullableKind()
    elif spec.startswith('a:'):
        kind = mojom.Array(_Kind(kinds, spec[2:], scope))
    elif spec.startswith('asso:'):
        inner_kind = _Kind(kinds, spec[5:], scope)
        if isinstance(inner_kind, mojom.InterfaceRequest):
            kind = mojom.AssociatedInterfaceRequest(inner_kind)
        else:
            kind = mojom.AssociatedInterface(inner_kind)
    elif spec.startswith('a'):
        colon = spec.find(':')
        length = int(spec[1:colon])
        kind = mojom.Array(_Kind(kinds, spec[colon + 1:], scope), length)
    elif spec.startswith('r:'):
        kind = mojom.InterfaceRequest(_Kind(kinds, spec[2:], scope))
    elif spec.startswith('rmt:'):
        kind = mojom.PendingRemote(_Kind(kinds, spec[4:], scope))
    elif spec.startswith('rcv:'):
        kind = mojom.PendingReceiver(_Kind(kinds, spec[4:], scope))
    elif spec.startswith('m['):
        # Isolate the two types from their brackets.

        # It is not allowed to use map as key, so there shouldn't be nested ']'s
        # inside the key type spec.
        key_end = spec.find(']')
        assert key_end != -1 and key_end < len(spec) - 1
        assert spec[key_end + 1] == '[' and spec[-1] == ']'

        first_kind = spec[2:key_end]
        second_kind = spec[key_end + 2:-1]

        kind = mojom.Map(_Kind(kinds, first_kind, scope),
                         _Kind(kinds, second_kind, scope))
    else:
        kind = mojom.Kind(spec)

    kinds[spec] = kind
    return kind
Exemplo n.º 4
0
def TestAllTypes():
    struct = mojom.Struct('test')
    array = mojom.Array()
    return TestSequence(
        (mojom.BOOL, mojom.INT8, mojom.STRING, mojom.UINT8, mojom.INT16,
         mojom.DOUBLE, mojom.UINT16, mojom.INT32, mojom.UINT32, mojom.INT64,
         mojom.FLOAT, mojom.STRING, mojom.HANDLE, mojom.UINT64,
         mojom.Struct('test'), mojom.Array()),
        (1, 2, 4, 5, 7, 3, 6, 8, 9, 10, 11, 13, 12, 14, 15, 16, 17),
        (0, 1, 2, 4, 6, 8, 16, 24, 28, 32, 40, 44, 48, 56, 64, 72, 80))
Exemplo n.º 5
0
def BuildTestModule():
    module = mojom.Module('test', 'testspace')
    struct = module.AddStruct('teststruct')
    struct.AddField('testfield1', mojom.INT32)
    struct.AddField('testfield2', mojom.Array(mojom.INT32), 42)

    interface = module.AddInterface('Server')
    method = interface.AddMethod('Foo', 42)
    method.AddParameter('foo', mojom.INT32)
    method.AddParameter('bar', mojom.Array(struct))

    return module
Exemplo n.º 6
0
def TestNullableTypes():
    kinds = (mojom.STRING.MakeNullableKind(), mojom.HANDLE.MakeNullableKind(),
             mojom.Struct('test_struct').MakeNullableKind(),
             mojom.DCPIPE.MakeNullableKind(), mojom.Array().MakeNullableKind(),
             mojom.DPPIPE.MakeNullableKind(),
             mojom.Array(length=5).MakeNullableKind(),
             mojom.MSGPIPE.MakeNullableKind(),
             mojom.Interface('test_inteface').MakeNullableKind(),
             mojom.SHAREDBUFFER.MakeNullableKind(),
             mojom.InterfaceRequest().MakeNullableKind())
    fields = (1, 2, 4, 3, 5, 6, 8, 7, 9, 10, 11)
    offsets = (0, 8, 12, 16, 24, 32, 36, 40, 48, 52, 56)
    return TestSequence(kinds, fields, offsets)
Exemplo n.º 7
0
def TestAllTypes():
    return TestSequence(
        (mojom.BOOL, mojom.INT8, mojom.STRING, mojom.UINT8, mojom.INT16,
         mojom.DOUBLE, mojom.UINT16, mojom.INT32, mojom.UINT32, mojom.INT64,
         mojom.FLOAT, mojom.STRING, mojom.HANDLE, mojom.UINT64,
         mojom.Struct('test'), mojom.Array(), mojom.STRING.MakeNullableKind()),
        (1, 2, 4, 5, 7, 3, 6, 8, 9, 10, 11, 13, 12, 14, 15, 16, 17, 18),
        (0, 1, 2, 4, 6, 8, 16, 24, 28, 32, 40, 44, 48, 56, 64, 72, 80, 88))
Exemplo n.º 8
0
def KindFromData(kinds, data, scope):
  kind = LookupKind(kinds, data, scope)
  if kind:
    return kind
  if data.startswith('a:'):
    kind = mojom.Array()
    kind.kind = KindFromData(kinds, data[2:], scope)
  else:
    kind = mojom.Kind()
  kind.spec = data
  kinds[data] = kind
  return kind
Exemplo n.º 9
0
    def ArrayFromMojom(self, mojom_type):
        """Translates an array type to its module equivalent.

    Args:
      mojom_type: {fidl_types_fidl.Type} with its array_type field set to be
        translated.

    Returns:
      {module.Array} translated from mojom_type.
    """
        array = module.Array(
            kind=self.KindFromMojom(mojom_type.array_type.element_type))
        if mojom_type.array_type.fixed_length > 0:
            array.length = mojom_type.array_type.fixed_length
        if mojom_type.array_type.nullable:
            return array.MakeNullableKind()
        return array
Exemplo n.º 10
0
def KindFromData(kinds, data, scope):
    kind = LookupKind(kinds, data, scope)
    if kind:
        return kind

    if data.startswith('?'):
        kind = KindFromData(kinds, data[1:], scope).MakeNullableKind()
    elif data.startswith('a:'):
        kind = mojom.Array(KindFromData(kinds, data[2:], scope))
    elif data.startswith('r:'):
        kind = mojom.InterfaceRequest(KindFromData(kinds, data[2:], scope))
    elif data.startswith('a'):
        colon = data.find(':')
        length = int(data[1:colon])
        kind = mojom.FixedArray(length,
                                KindFromData(kinds, data[colon + 1:], scope))
    else:
        kind = mojom.Kind(data)

    kinds[data] = kind
    return kind