|
| 1 | +import stdlib |
| 2 | + |
| 3 | +@check(message="function has output parameter(s)", |
| 4 | + category="Style", |
| 5 | + subcategory="Programming Practice", |
| 6 | + rule_name="Function_OUT_Parameters") |
| 7 | +fun function_out_parameters(node) = |
| 8 | + |" Flag any function declaration, function body declaration, expression function |
| 9 | + |" declaration, function body stub, or generic function declaration which has at |
| 10 | + |" least one formal parameter of mode ``out`` or ``in out``. |
| 11 | + |" |
| 12 | + |" A function body declaration or function body stub is only flagged if there is |
| 13 | + |" no separate declaration for this function. |
| 14 | + |" |
| 15 | + |" .. rubric:: Example |
| 16 | + |" |
| 17 | + |" .. code-block:: ada |
| 18 | + |" :emphasize-lines: 2, 3, 4 |
| 19 | + |" |
| 20 | + |" function F_1 (I : Integer) return Integer; |
| 21 | + |" function F_2 (I : out Integer) return Integer; -- FLAG |
| 22 | + |" function F_3 (I : in out Integer) return Integer; -- FLAG |
| 23 | + |" function F_4 (I : in out Integer) return Integer is -- FLAG |
| 24 | + |" (I + 42); |
| 25 | + |" |
| 26 | + |" function F_2 (I : out Integer) return Integer is -- NOFLAG (declaration has already been flagged) |
| 27 | + |" begin |
| 28 | + |" return 0; |
| 29 | + |" end F_2; |
| 30 | + node is (SubpBody | ExprFunction | SubpBodyStub | ClassicSubpDecl | GenericSubpInternal) |
| 31 | + when (if not node is (ClassicSubpDecl | GenericSubpInternal) |
| 32 | + then not node.p_previous_part()) |
| 33 | + and node.f_subp_spec.f_subp_kind is SubpKindFunction |
| 34 | + and stdlib.any([ |
| 35 | + p |
| 36 | + for p in node.f_subp_spec.p_params() |
| 37 | + if p.f_mode is (ModeInOut | ModeOut) |
| 38 | + ]) |
0 commit comments