Next: , Previous: Syntax Metrics Control, Up: Specifying a set of metrics to compute


15.1.3.3 Complexity Metrics Control

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, the 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 raise or return statement as it subcomponent, or if it contains a goto statement that transfers the control outside the operator. A selective accept statement with terminate alternative is considered as non-structural statement. When computing this metric, exit statements are treated in the same way as goto 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:

--complexity-all
Report all the complexity metrics
--no-complexity-all
Do not report any of complexity metrics
--complexity-cyclomatic
Report the McCabe Cyclomatic Complexity
--no-complexity-cyclomatic
Do not report the McCabe Cyclomatic Complexity
--complexity-essential
Report the Essential Complexity
--no-complexity-essential
Do not report the Essential Complexity
--loop-nesting
Report maximal loop nesting level
--no-loop-nesting
Do not report maximal loop nesting level
--complexity-average
Report the average McCabe Cyclomatic Complexity for all the subprogram bodies, task bodies, entry bodies and statement sequences in package bodies. The metric is computed and reported for whole set of processed Ada sources only.
--no-complexity-average
Do not report the average McCabe Cyclomatic Complexity for all the subprogram bodies, task bodies, entry bodies and statement sequences in package bodies


-ne
Do not consider exit statements as gotos when computing Essential Complexity


--no-static-loop
Do not consider static loops when computing cyclomatic complexity
--extra-exit-points
Report the extra exit points for subprogram bodies. As an exit point, this metric counts return statements 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 return statement.
--no-extra-exit-points
Do not report the extra exit points for subprogram bodies