예제 #1
0
    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)
예제 #2
0
def GetArrayValidateParamsCtorArgs(kind):
    if mojom.IsStringKind(kind):
        expected_num_elements = 0
        element_is_nullable = False
        element_validate_params = "nullptr"
        enum_validate_func = "nullptr"
    elif mojom.IsMapKind(kind):
        expected_num_elements = 0
        element_is_nullable = mojom.IsNullableKind(kind.value_kind)
        element_validate_params = GetNewArrayValidateParams(kind.value_kind)
        enum_validate_func = "nullptr"
    else:
        expected_num_elements = generator.ExpectedArraySize(kind) or 0
        element_is_nullable = mojom.IsNullableKind(kind.kind)
        element_validate_params = GetNewArrayValidateParams(kind.kind)
        if mojom.IsEnumKind(kind.kind):
            enum_validate_func = (
                "%s::Validate" %
                GetQualifiedNameForKind(kind.kind, internal=True))
        else:
            enum_validate_func = "nullptr"

    if enum_validate_func == "nullptr":
        return "%d, %s, %s" % (expected_num_elements,
                               "true" if element_is_nullable else "false",
                               element_validate_params)
    else:
        return "%d, %s" % (expected_num_elements, enum_validate_func)
예제 #3
0
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
예제 #4
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)
예제 #5
0
def GetArrayValidateParamsCtorArgs(kind):
    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 = GetNewArrayValidateParams(kind.value_kind)
    else:
        expected_num_elements = generator.ExpectedArraySize(kind) or 0
        element_is_nullable = mojom.IsNullableKind(kind.kind)
        element_validate_params = GetNewArrayValidateParams(kind.kind)

    return "%d, %s, %s" % (expected_num_elements, "true" if element_is_nullable
                           else "false", element_validate_params)
def GetArrayValidateParams(kind):
    if not mojom.IsAnyArrayKind(kind) and not mojom.IsStringKind(kind):
        return "mojo::internal::NoValidateParams"

    if mojom.IsStringKind(kind):
        expected_num_elements = 0
        element_nullable = False
        element_validate_params = "mojo::internal::NoValidateParams"
    else:
        expected_num_elements = generator.ExpectedArraySize(kind)
        element_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_nullable else 'false',
        element_validate_params)
예제 #7
0
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)