コード例 #1
0
def JavaScriptValidateArrayParams(packed_field):
    nullable = JavaScriptNullableParam(packed_field)
    field_offset = JavaScriptFieldOffset(packed_field)
    element_kind = packed_field.field.kind.kind
    element_size = pack.PackedField.GetSizeForKind(element_kind)
    element_count = generator.ExpectedArraySize(packed_field.field.kind)
    element_type = "codec.PackedBool" if mojom.IsBoolKind(element_kind) \
        else CodecType(element_kind)
    return "%s, %s, %s, %s, %s" % \
        (field_offset, element_size, element_count, element_type, nullable)
コード例 #2
0
ファイル: mojom_js_generator.py プロジェクト: dalecurtis/mojo
def JavaScriptValidateArrayParams(packed_field):
    nullable = JavaScriptNullableParam(packed_field)
    field_offset = JavaScriptFieldOffset(packed_field)
    element_kind = packed_field.field.kind.kind
    element_size = pack.PackedField.GetSizeForKind(element_kind)
    expected_dimension_sizes = GetArrayExpectedDimensionSizes(
        packed_field.field.kind)
    element_type = "codec.PackedBool" if mojom.IsBoolKind(element_kind) \
        else CodecType(element_kind)
    return "%s, %s, %s, %s, %s, 0" % \
        (field_offset, element_size, element_type, nullable,
         expected_dimension_sizes)
コード例 #3
0
def JavaScriptEncodeSnippet(kind):
    if kind in mojom.PRIMITIVES:
        return "encodeStruct(%s, " % CodecType(kind)
    if mojom.IsStructKind(kind):
        return "encodeStructPointer(%s, " % CodecType(kind.name)
    if mojom.IsArrayKind(kind) and mojom.IsBoolKind(kind.kind):
        return "encodeArrayPointer(new codec.ArrayOf(codec.PackedBool), "
    if mojom.IsAnyArrayKind(kind):
        return "encodeArrayPointer(%s, " % CodecType(kind.kind)
    if mojom.IsInterfaceKind(kind) or mojom.IsInterfaceRequestKind(kind):
        return JavaScriptEncodeSnippet(mojom.MSGPIPE)
    if mojom.IsEnumKind(kind):
        return JavaScriptEncodeSnippet(mojom.INT32)
コード例 #4
0
def JavaScriptDecodeSnippet(kind):
    if kind in mojom.PRIMITIVES:
        return "decodeStruct(%s)" % CodecType(kind)
    if mojom.IsStructKind(kind):
        return "decodeStructPointer(%s)" % JavaScriptType(kind)
    if mojom.IsAnyArrayKind(kind) and mojom.IsBoolKind(kind.kind):
        return "decodeArrayPointer(codec.PackedBool)"
    if mojom.IsAnyArrayKind(kind):
        return "decodeArrayPointer(%s)" % CodecType(kind.kind)
    if mojom.IsInterfaceKind(kind) or mojom.IsInterfaceRequestKind(kind):
        return JavaScriptDecodeSnippet(mojom.MSGPIPE)
    if mojom.IsEnumKind(kind):
        return JavaScriptDecodeSnippet(mojom.INT32)
コード例 #5
0
def CodecType(kind):
    if kind in mojom.PRIMITIVES:
        return _kind_to_codec_type[kind]
    if mojom.IsStructKind(kind):
        return "new codec.PointerTo(%s)" % CodecType(kind.name)
    if mojom.IsArrayKind(kind) and mojom.IsBoolKind(kind.kind):
        return "new codec.ArrayOf(new codec.ArrayOf(codec.PackedBool))"
    if mojom.IsArrayKind(kind):
        return "new codec.ArrayOf(%s)" % CodecType(kind.kind)
    if mojom.IsInterfaceKind(kind) or mojom.IsInterfaceRequestKind(kind):
        return CodecType(mojom.MSGPIPE)
    if mojom.IsEnumKind(kind):
        return _kind_to_codec_type[mojom.INT32]
    return kind
コード例 #6
0
ファイル: mojom_dart_generator.py プロジェクト: andycall/mojo
def DartDecodeSnippet(kind):
  if kind in mojom.PRIMITIVES:
    return "decodeStruct(%s)" % CodecType(kind)
  if mojom.IsStructKind(kind):
    return "decodeStructPointer(%s)" % DartType(kind)
  if mojom.IsMapKind(kind):
    return "decodeMapPointer(%s, %s)" % \
        (MapCodecType(kind.key_kind), MapCodecType(kind.value_kind))
  if mojom.IsArrayKind(kind) and mojom.IsBoolKind(kind.kind):
    return "decodeArrayPointer(bindings.PackedBool)"
  if mojom.IsArrayKind(kind):
    return "decodeArrayPointer(%s)" % CodecType(kind.kind)
  if mojom.IsInterfaceKind(kind) or mojom.IsInterfaceRequestKind(kind):
    return DartDecodeSnippet(mojom.MSGPIPE)
  if mojom.IsEnumKind(kind):
    return DartDecodeSnippet(mojom.INT32)
コード例 #7
0
ファイル: mojom_js_generator.py プロジェクト: dalecurtis/mojo
def JavaScriptEncodeSnippet(kind):
    if kind in mojom.PRIMITIVES:
        return "encodeStruct(%s, " % CodecType(kind)
    if mojom.IsStructKind(kind):
        return "encodeStructPointer(%s, " % JavaScriptType(kind)
    if mojom.IsMapKind(kind):
        return "encodeMapPointer(%s, %s, " % \
            (MapCodecType(kind.key_kind), MapCodecType(kind.value_kind))
    if mojom.IsArrayKind(kind) and mojom.IsBoolKind(kind.kind):
        return "encodeArrayPointer(codec.PackedBool, "
    if mojom.IsArrayKind(kind):
        return "encodeArrayPointer(%s, " % CodecType(kind.kind)
    if mojom.IsInterfaceKind(kind) or mojom.IsInterfaceRequestKind(kind):
        return JavaScriptEncodeSnippet(mojom.MSGPIPE)
    if mojom.IsEnumKind(kind):
        return JavaScriptEncodeSnippet(mojom.INT32)
コード例 #8
0
def JavaScriptDecodeSnippet(kind):
  if (kind in mojom.PRIMITIVES or mojom.IsUnionKind(kind) or
      mojom.IsAnyInterfaceKind(kind)):
    return "decodeStruct(%s)" % CodecType(kind)
  if mojom.IsStructKind(kind):
    return "decodeStructPointer(%s)" % JavaScriptType(kind)
  if mojom.IsMapKind(kind):
    return "decodeMapPointer(%s, %s)" % \
        (ElementCodecType(kind.key_kind), ElementCodecType(kind.value_kind))
  if mojom.IsArrayKind(kind) and mojom.IsBoolKind(kind.kind):
    return "decodeArrayPointer(codec.PackedBool)"
  if mojom.IsArrayKind(kind):
    return "decodeArrayPointer(%s)" % CodecType(kind.kind)
  if mojom.IsUnionKind(kind):
    return "decodeUnion(%s)" % CodecType(kind)
  if mojom.IsEnumKind(kind):
    return JavaScriptDecodeSnippet(mojom.INT32)
  raise Exception("No decode snippet for %s" % kind)
コード例 #9
0
def CodecType(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, JavaScriptType(kind))
    if mojom.IsAnyArrayKind(kind):
        array_type = "NullableArrayOf" if mojom.IsNullableKind(
            kind) else "ArrayOf"
        element_type = "codec.PackedBool" if mojom.IsBoolKind(kind.kind) \
            else CodecType(kind.kind)
        return "new codec.%s(%s)" % (array_type, element_type)
    if mojom.IsInterfaceKind(kind) or mojom.IsInterfaceRequestKind(kind):
        return CodecType(mojom.MSGPIPE)
    if mojom.IsEnumKind(kind):
        return _kind_to_codec_type[mojom.INT32]
    return kind
コード例 #10
0
 def _JavaScriptEncodeSnippet(self, kind):
     if (kind in mojom.PRIMITIVES or mojom.IsUnionKind(kind)
             or mojom.IsAnyInterfaceKind(kind)):
         return "encodeStruct(%s, " % self._CodecType(kind)
     if mojom.IsUnionKind(kind):
         return "encodeStruct(%s, " % self._JavaScriptType(kind)
     if mojom.IsStructKind(kind):
         return "encodeStructPointer(%s, " % self._JavaScriptType(kind)
     if mojom.IsMapKind(kind):
         return "encodeMapPointer(%s, %s, " % (self._ElementCodecType(
             kind.key_kind), self._ElementCodecType(kind.value_kind))
     if mojom.IsArrayKind(kind) and mojom.IsBoolKind(kind.kind):
         return "encodeArrayPointer(codec.PackedBool, "
     if mojom.IsArrayKind(kind):
         return "encodeArrayPointer(%s, " % self._CodecType(kind.kind)
     if mojom.IsEnumKind(kind):
         return self._JavaScriptEncodeSnippet(mojom.INT32)
     raise Exception("No encode snippet for %s" % kind)
コード例 #11
0
ファイル: mojom_dart_generator.py プロジェクト: andycall/mojo
def CodecType(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 bindings.%s(%s)" % (pointer_type, DartType(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 = "bindings.PackedBool" if mojom.IsBoolKind(kind.kind) \
        else CodecType(kind.kind)
    return "new bindings.%s(%s%s)" % (array_type, element_type, array_length)
  if mojom.IsInterfaceKind(kind) or mojom.IsInterfaceRequestKind(kind):
    return CodecType(mojom.MSGPIPE)
  if mojom.IsEnumKind(kind):
    return _kind_to_codec_type[mojom.INT32]
  return kind
コード例 #12
0
ファイル: translate.py プロジェクト: zhangxq0521/libcamera
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
コード例 #13
0
def JavaScriptEncodeSnippet(kind):
    if (kind in mojom.PRIMITIVES or mojom.IsUnionKind(kind)
            or mojom.IsInterfaceKind(kind) or mojom.IsAssociatedKind(kind)):
        return "encodeStruct(%s, " % CodecType(kind)
    if mojom.IsUnionKind(kind):
        return "encodeStruct(%s, " % JavaScriptType(kind)
    if mojom.IsStructKind(kind):
        return "encodeStructPointer(%s, " % JavaScriptType(kind)
    if mojom.IsMapKind(kind):
        return "encodeMapPointer(%s, %s, " % \
            (ElementCodecType(kind.key_kind), ElementCodecType(kind.value_kind))
    if mojom.IsArrayKind(kind) and mojom.IsBoolKind(kind.kind):
        return "encodeArrayPointer(codec.PackedBool, "
    if mojom.IsArrayKind(kind):
        return "encodeArrayPointer(%s, " % CodecType(kind.kind)
    if mojom.IsInterfaceRequestKind(kind):
        return JavaScriptEncodeSnippet(mojom.MSGPIPE)
    if mojom.IsEnumKind(kind):
        return JavaScriptEncodeSnippet(mojom.INT32)
    raise Exception("No encode snippet for %s" % kind)
コード例 #14
0
 def _ElementCodecType(self, kind):
     return ("codec.PackedBool"
             if mojom.IsBoolKind(kind) else self._CodecType(kind))
コード例 #15
0
def ElementCodecType(kind):
    return "bindings.PackedBool" if mojom.IsBoolKind(kind) else CodecType(kind)
コード例 #16
0
def ElementCodecType(kind):
    if mojom.IsUnionKind(kind):
        wrapper_type = "NullableUnionWrapper" if mojom.IsNullableKind(kind) \
            else "UnionWrapper"
        return "new codec.%s(%s)" % (wrapper_type, JavaScriptType(kind))
    return "codec.PackedBool" if mojom.IsBoolKind(kind) else CodecType(kind)
コード例 #17
0
ファイル: mojom_js_generator.py プロジェクト: dalecurtis/mojo
def MapCodecType(kind):
    return "codec.PackedBool" if mojom.IsBoolKind(kind) else CodecType(kind)
コード例 #18
0
def IsBoolField(field):
    return mojom.IsBoolKind(field.kind)