File: asis_ul-metrics-definitions.ads

package info (click to toggle)
asis 2015-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 13,640 kB
  • sloc: ada: 140,372; makefile: 260; sh: 50; xml: 48; csh: 10
file content (130 lines) | stat: -rw-r--r-- 5,863 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
------------------------------------------------------------------------------
--                                                                          --
--                     ASIS UTILITY LIBRARY COMPONENTS                      --
--                                                                          --
--          A S I S _ U L . M E T R I C S . D E F I N I T I O N S           --
--                                                                          --
--                                 S p e c                                  --
--                                                                          --
--                     Copyright (C) 2008-2013, AdaCore                     --
--                                                                          --
-- Asis Utility Library (ASIS UL) is free software; you can redistribute it --
-- and/or  modify  it  under  terms  of  the  GNU General Public License as --
-- published by the Free Software Foundation; either version 2, or (at your --
-- option)  any later version.  ASIS UL  is distributed in the hope that it --
-- will  be  useful,  but  WITHOUT  ANY  WARRANTY; without even the implied --
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --
-- GNU  General Public License for more details. You should have received a --
-- copy of the  GNU General Public License  distributed with GNAT; see file --
-- COPYING. If not,  write  to the  Free Software Foundation,  51 Franklin  --
-- Street, Fifth Floor, Boston, MA 02110-1301, USA.                         --
--                                                                          --
-- ASIS UL is maintained by AdaCore (http://www.adacore.com).               --
--                                                                          --
------------------------------------------------------------------------------

--  This package contains various definitions used by metric computing
--  routines.

package ASIS_UL.Metrics.Definitions is

   -----------------------
   -- Basic definitions --
   -----------------------

   Metric_Count_Disabled : constant := -2;
   --  Used to indicate the situation that the given metric should not be
   --  computed and reported

   Metric_Count_Undefined : constant := -1;
   --  Used to indicate the situation that the given metric should be
   --  computed and reported but has not been computed

   Max_Metric_Count : constant := Integer'Last;

   type Metric_Count is range Metric_Count_Disabled .. Max_Metric_Count;

   ------------------------
   -- Complexity metrics --
   ------------------------

   --  Complexity metrics are computed for executable bodies. (See
   --  ASIS_UL.Utilities.Is_Executable_Body as the test if an Element
   --  represents an executable body). The following metric values are
   --  computed:
   --
   --  - statement cyclomatic complexity (that is, cyclomatic complexity
   --    computed without taking into account short circuit control forms;
   --
   --  - expression cyclomatic complexity (that is, value added to cyclomatic
   --    complexity only by expressions - short circuit control forms,
   --    conditional expressions, quantified expressions);
   --
   --  - essential complexity;
   --
   --  - maximum loop nesting level in the body (note, that as a loop nesting
   --    level we are counting all the loops in the loop nest, that is, a loop
   --    statement that does not contain any nested level makes up a loop nest
   --    with nesting level one);

   type Complexity_Metric_Counter is record
      Statement_Complexity     : Metric_Count;
      Expression_Complexity    : Metric_Count;
      Essential_Complexity     : Metric_Count;
      Essential_Complexity_New : Metric_Count;
      --  Not used at the moment, is supposed to be used for McCabe essential
      --  complexity
      Max_Loop_Nesting         : Metric_Count;
      Extra_Exit_Points        : Metric_Count;
   end record;

   Treat_Exit_As_Goto : Boolean := True;
   --  This flag defines if loop exit statements should be treated as
   --  (non-structural) goto statements when computing essential complexity.

   Count_Static_Loop : Boolean := True;
   --  This flag defines if static FOR loops should be counted when computing
   --  cyclomatic complexity. If this flag is OFF they are not counted.

   Check_Predicates : Boolean := False;
   --  If this flag is ON, the computation of cyclomatic complexity takes into
   --  account the code in Pre- and Post-conditions and assertions. Otherwise
   --  this code is ignored.
   --
   --  At the moment this flag is always OFF and we do not have an option or
   --  any other means to set in ON. This may be revised if and when we decide
   --  that complexity metrics should consider the code in predicates and
   --  assertions.

   ---------------------
   -- Element metrics --
   ---------------------

   type Syntax_Metric_Counter is record
      All_Statements : Metric_Count := 0;
      --  The total number of statements;

      All_Declarations : Metric_Count := 0;
      --  The total number of declarations;

      Own_Statements : Metric_Count := 0;
      --  The number of statements from the given unit only, not counting
      --  statements from nested units;

      Own_Declarations : Metric_Count;
      --  The number of declarations from the given unit only, not counting
      --  declarations from nested units and the unit declaration itself;

      Max_Program_Unit_Nesting : Metric_Count := 0;
      --  Maximal number of nesting level of program units nested into the
      --  given element.

      Max_Construct_Nesting : Metric_Count := 0;
      --  Maximal number of construct nesting.

   end record;

   Null_Syntax_Metric_Counter : constant Syntax_Metric_Counter :=
     (others => 0);

end ASIS_UL.Metrics.Definitions;