11import stdlib
22
3- fun unconstrained_array_type(type, except_string) =
4- if type is SubtypeDecl
5- then type.f_subtype.f_constraint is not Constraint and
6- unconstrained_array_type(type.p_canonical_type(), except_string)
7- else if type is TypeDecl(f_type_def: DerivedTypeDef)
8- then type.f_type_def.f_subtype_indication.f_constraint is not Constraint and
9- unconstrained_array_type(type.p_base_type(), except_string)
10- else type is TypeDecl(p_is_array_type(): true,
11- f_type_def: ArrayTypeDef(f_indices:
12- UnconstrainedArrayIndices))
13- when not (except_string and
14- type.p_root_type().p_fully_qualified_name()
15- == "Standard.String")
16-
173@check(message="function returns unconstrained array",
184 follow_generic_instantiations=true, category="Feature")
195fun unconstrained_array_returns(node, except_string = false) =
206 |" Flag each function returning an unconstrained array. Function declarations,
217 |" function bodies (and body stubs) having no separate specifications,
228 |" and generic function instantiations are flagged.
23- |" Function calls and function renamings are
24- |" not flagged.
9+ |" Function calls and function renamings are not flagged.
2510 |"
2611 |" Generic function declarations, and function declarations in generic
2712 |" packages, are not flagged. Instead, this rule flags the results of
@@ -45,13 +30,31 @@ fun unconstrained_array_returns(node, except_string = false) =
4530 |"
4631 |" function F1 (I : Integer) return Arr; -- FLAG
4732 |" function F2 (I : Integer) return Arr_S;
48- node is (AbstractSubpDecl | SubpDecl | GenericSubpInternal |
49- BaseSubpBody(p_previous_part(): null) |
50- SubpBodyStub(p_previous_part(): null))
51-
52- 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+ );
5345
54- and node.f_subp_spec is SubpSpec(f_subp_returns:
55- TypeExpr(p_designated_type_decl():
56- t@BaseTypeDecl
57- 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