11import stdlib
22
3- fun unconstrained_array_type(type, except_string) =
4- match type
5- | SubtypeDecl => (
6- type.f_subtype.f_constraint is not Constraint and
7- unconstrained_array_type(type.p_canonical_type(), except_string)
8- )
9- | TypeDecl(f_type_def: def@DerivedTypeDef) => (
10- def.f_subtype_indication.f_constraint is not Constraint and
11- unconstrained_array_type(type.p_base_type(), except_string)
12- )
13- | TypeDecl(
14- p_is_array_type(): true,
15- f_type_def: ArrayTypeDef(f_indices: UnconstrainedArrayIndices)
16- ) => if except_string then type.p_root_type().p_fully_qualified_name().to_lower_case != "standard.string"
17-
183@check(message="function returns unconstrained array",
194 follow_generic_instantiations=true, category="Feature")
205fun unconstrained_array_returns(node, except_string = false) =
216 |" Flag each function returning an unconstrained array. Function declarations,
227 |" function bodies (and body stubs) having no separate specifications,
238 |" and generic function instantiations are flagged.
24- |" Function calls and function renamings are
25- |" not flagged.
9+ |" Function calls and function renamings are not flagged.
2610 |"
2711 |" Generic function declarations, and function declarations in generic
2812 |" packages, are not flagged. Instead, this rule flags the results of
@@ -46,13 +30,31 @@ fun unconstrained_array_returns(node, except_string = false) =
4630 |"
4731 |" function F1 (I : Integer) return Arr; -- FLAG
4832 |" function F2 (I : Integer) return Arr_S;
49- node is (AbstractSubpDecl | SubpDecl | GenericSubpInternal |
50- BaseSubpBody(p_previous_part(): null) |
51- SubpBodyStub(p_previous_part(): null))
52-
53- when (not stdlib.in_generic_template(node))
33+ {
34+ fun is_unconstrained_array(type_decl) =
35+ |" Get whether the provided TypeDecl is declaring an unconstrained array type.
36+ |" If `type_decl` designate the "standard.string" type and `except_string` is
37+ |" `true`, the result of this function is `false`.
38+ type_decl is TypeDecl(
39+ p_is_array_type(): true,
40+ f_type_def: ArrayTypeDef(f_indices: UnconstrainedArrayIndices)
41+ ) when (
42+ if except_string
43+ then type_decl.p_fully_qualified_name().to_lower_case != "standard.string"
44+ );
5445
55- and node.f_subp_spec is SubpSpec(f_subp_returns:
56- TypeExpr(p_designated_type_decl():
57- t@BaseTypeDecl
58- when unconstrained_array_type(t, except_string)))
46+ node is (
47+ AbstractSubpDecl |
48+ SubpDecl |
49+ GenericSubpInternal |
50+ BaseSubpBody(p_previous_part(): null) |
51+ SubpBodyStub(p_previous_part(): null)
52+ )
53+ and (not stdlib.in_generic_template(node))
54+ and node.f_subp_spec is SubpSpec(
55+ f_subp_returns: TypeExpr(
56+ p_is_definite_subtype(): false,
57+ p_designated_type_decl(): t@BaseTypeDecl when is_unconstrained_array(t.p_root_type())
58+ )
59+ )
60+ }
0 commit comments