File: metrics-metric_definitions.adb

package info (click to toggle)
asis 2007-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 7,832 kB
  • ctags: 34
  • sloc: ada: 93,665; makefile: 225
file content (227 lines) | stat: -rw-r--r-- 8,013 bytes parent folder | download | duplicates (2)
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
------------------------------------------------------------------------------
--                                                                          --
--                      GNAT METRICS TOOLS COMPONENTS                       --
--                                                                          --
--           M E T R I C S . M E T R I C _ D E F I N I T I O N S            --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
--                  Copyright (C) 2002-2004, ACT Europe                     --
--                                                                          --
-- GNAT Metrics Toolset  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.  GNAT Metrics Toolset is  distributed in the hope that it --
-- will be useful, but  WITHOUT ANY WARRANTY; without even the implied war- --
-- ranty 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,   59 Temple --
-- Place - Suite 330, Boston,                                               --
--                                                                          --
-- GNAT Metrics Toolset is maintained by ACT Europe                         --
-- (http://www.act-europe.fr).                                              --
--                                                                          --
------------------------------------------------------------------------------

with Asis;            use Asis;

with METRICS.Options; use METRICS.Options;
with METRICS.Common;  use METRICS.Common;

package body METRICS.Metric_Definitions is

   ------------------------------
   -- Add_Public_Types_Details --
   ------------------------------

   procedure Add_Public_Types_Details (Value : Public_Types_Details) is
      ITD : Public_Types_Details
        renames Global_Statistics.Public_Types_Detailed;
   begin
      ITD.Abstract_Types  := ITD.Abstract_Types  + Value.Abstract_Types;
      ITD.Tagged_Types    := ITD.Tagged_Types    + Value.Tagged_Types;
      ITD.Private_Types   := ITD.Private_Types   + Value.Private_Types;
      ITD.Task_Types      := ITD.Task_Types      + Value.Task_Types;
      ITD.Protected_Types := ITD.Protected_Types + Value.Protected_Types;

   end Add_Public_Types_Details;

   --------------
   -- Computed --
   --------------

   function Computed (Value : Metric_Count) return Boolean is
   begin
      return Value > Metric_Count_Undefined;
   end Computed;

   ---------------------
   -- Details_Present --
   ---------------------

   function Details_Present (Value : Public_Types_Details) return Boolean is
   begin

      return False
        or else Value.Abstract_Types  > 0
        or else Value.Tagged_Types    > 0
        or else Value.Private_Types   > 0
        or else Value.Task_Types      > 0
        or else Value.Protected_Types > 0;

   end Details_Present;

   ----------------------------
   -- Init_Global_Statistics --
   ----------------------------

   procedure Init_Global_Statistics is
   begin

      Global_Statistics.Computed_Line_Metrics       := 0;
      Global_Statistics.Computed_Element_Metrics    := 0;
      Global_Statistics.Computed_Public_Subprograms := 0;
      Global_Statistics.Computed_All_Subprograms    := 0;
      Global_Statistics.Computed_Public_Types       := 0;
      Global_Statistics.Computed_All_Types          := 0;

      if Compute_All_Lines then
         Global_Statistics.Line_Metrics.All_Lines := 0;
      else
         Global_Statistics.Line_Metrics.All_Lines := Metric_Count_Disabled;
      end if;

      if Compute_Code_Lines then
         Global_Statistics.Line_Metrics.Code_Lines := 0;
      else
         Global_Statistics.Line_Metrics.Code_Lines := Metric_Count_Disabled;
      end if;

      if Compute_Comment_Lines then
         Global_Statistics.Line_Metrics.Comment_Lines := 0;
      else
         Global_Statistics.Line_Metrics.Comment_Lines := Metric_Count_Disabled;
      end if;

      if Compute_EOL_Comments then
         Global_Statistics.Line_Metrics.EOL_Comments := 0;
      else
         Global_Statistics.Line_Metrics.EOL_Comments := Metric_Count_Disabled;
      end if;

      if Compute_Blank_Lines then
         Global_Statistics.Line_Metrics.Blank_Lines := 0;
      else
         Global_Statistics.Line_Metrics.Blank_Lines := Metric_Count_Disabled;
      end if;

      if Compute_All_Statements then
         Global_Statistics.Element_Metrics.All_Statements := 0;
      else
         Global_Statistics.Element_Metrics.All_Statements :=
           Metric_Count_Disabled;
      end if;

      if Compute_All_Declarations then
         Global_Statistics.Element_Metrics.All_Declarations := 0;
      else
         Global_Statistics.Element_Metrics.All_Declarations :=
           Metric_Count_Disabled;
      end if;

      if Compute_Public_Subprograms then
         Global_Statistics.Public_Subprograms := 0;
      else
         Global_Statistics.Public_Subprograms := Metric_Count_Disabled;
      end if;

      if Compute_All_Subprograms then
         Global_Statistics.All_Subprograms := 0;
      else
         Global_Statistics.All_Subprograms := Metric_Count_Disabled;
      end if;

      if Compute_Public_Types then
         Global_Statistics.Public_Types := 0;
         Global_Statistics.Public_Types_Detailed := (others => 0);
      else
         Global_Statistics.Public_Types := Metric_Count_Disabled;
      end if;

      if Compute_All_Types then
         Global_Statistics.All_Types := 0;
      else
         Global_Statistics.All_Types := Metric_Count_Disabled;
      end if;

   end Init_Global_Statistics;

   ------------------------------
   -- Set_Global_Metrics_Flags --
   ------------------------------

   procedure Set_Global_Metrics_Flags is
   begin
      May_Have_Public_Subprograms := False;
      May_Have_Subprogram_Bodies  := False;
      May_Have_Public_Types       := False;
      May_Have_Type_Definitions   := False;

      if Compute_Public_Subprograms and then
         CU_Class not in A_Private_Declaration .. A_Separate_Body
      then

         case CU_Kind is
            when A_Procedure .. A_Generic_Package =>
               May_Have_Public_Subprograms := True;
            when A_Procedure_Body .. A_Function_Body =>

               if CU_Class = A_Public_Declaration_And_Body then
                  May_Have_Public_Subprograms := True;
               end if;

            when others =>
               null;
         end case;

      end if;

      if Compute_All_Subprograms
        and then
         (CU_Kind in A_Library_Unit_Body or else
          CU_Kind in A_Subunit)
      then
         May_Have_Subprogram_Bodies := True;
      end if;

      if Compute_Public_Types and then
         CU_Class not in A_Private_Declaration .. A_Separate_Body
      then

         case CU_Kind is
            when A_Package         |
                 A_Generic_Package =>
               May_Have_Public_Types := True;
            when others =>
               null;
         end case;

      end if;

      if Compute_All_Types then

         case CU_Kind is
            when A_Package                                    |
                 A_Generic_Package                            |
                 A_Procedure_Body .. A_Protected_Body_Subunit =>
               May_Have_Type_Definitions := True;
            when others =>
               null;
         end case;

      end if;

   end Set_Global_Metrics_Flags;

end METRICS.Metric_Definitions;