14.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:
- McCabe cyclomatic complexity;
- McCabe essential complexity;
- maximal loop nesting level
The McCabe complexity metrics are defined
in http://www.mccabe.com/pdf/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 complexity introduced by control
statements only, without taking into account short-circuit forms,
- the complexity introduced by short-circuit control forms only, and
- the total
cyclomatic complexity, which is the sum of these two values.
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 goto
s when
computing Essential Complexity