For a program unit that is an executable body (a subprogram body (including generic bodies), task body, entry body or a package body containing its own statement sequence) gnatmetric computes the following complexity metrics:
The McCabe cyclomatic complexity metric is defined in http://www.mccabe.com/pdf/mccabe-nist235r.pdf
According to McCabe, both control statements and short-circuit control forms should be taken into account when computing cyclomatic complexity. For each body, we compute three metric values:
The origin of cyclomatic complexity metric is the need to estimate the number
of independent paths in the control flow graph that in turn gives the number
of tests needed to satisfy paths coverage testing completeness criterion.
Considered from the testing point of view, a static Ada
loop (that is,
loop statement having static subtype in loop parameter
specification) does not add to cyclomatic complexity. By providing
--no-static-loop option a user
may specify that such loops should not be counted when computing the
cyclomatic complexity metric
The Ada essential complexity metric is a McCabe cyclomatic complexity metric
counted for the code that is reduced by excluding all the pure structural Ada
control statements. An compound statement is considered as a non-structural
if it contains a
return statement as it subcomponent,
or if it contains a
goto statement that transfers the control outside
the operator. A selective accept statement with
is considered as non-structural statement. When computing this metric,
exit statements are treated in the same way as
statements unless -ne option is specified.
The Ada essential complexity metric defined here is intended to quantify the extent to which the software is unstructured. It is adapted from the McCabe essential complexity metric defined in http://www.mccabe.com/pdf/nist235r.pdf but is modified to be more suitable for typical Ada usage. For example, short circuit forms are not penalized as unstructured in the Ada essential complexity metric.
When computing cyclomatic and essential complexity, gnatmetric skips the code in the exception handlers and in all the nested program units.
By default, all the complexity metrics are computed and reported. For more fine-grained control you can use the following switches:
gotos when computing Essential Complexity
returnstatements and raise statements in case when the raised exception is not handled in the same body. In case of a function this metric subtracts 1 from the number of exit points, because a function body must contain at least one