File: gnatcheck-output.adb

package info (click to toggle)
asis 2019-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 13,848 kB
  • sloc: ada: 156,772; makefile: 296; sh: 81; xml: 48; csh: 10
file content (346 lines) | stat: -rw-r--r-- 13,427 bytes parent folder | download
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
------------------------------------------------------------------------------
--                                                                          --
--                          GNATCHECK COMPONENTS                            --
--                                                                          --
--                     G N A T C H E C K . O U T P U T                      --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
--                     Copyright (C) 2004-2017, AdaCore                     --
--                                                                          --
-- GNATCHECK  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.  GNATCHECK  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.                                       --
--                                                                          --
-- GNATCHECK is maintained by AdaCore (http://www.adacore.com).             --
--                                                                          --
------------------------------------------------------------------------------

with Ada.Text_IO;                use Ada.Text_IO;

with GNAT.OS_Lib;                use GNAT.OS_Lib;

with ASIS_UL.Common;             use ASIS_UL.Common;
with ASIS_UL.Output;             use ASIS_UL.Output;

with Gnatcheck.Ids;              use Gnatcheck.Ids;
with Gnatcheck.Options;          use Gnatcheck.Options;
with Gnatcheck.Rules;            use Gnatcheck.Rules;
with Gnatcheck.Rules.Rule_Table; use Gnatcheck.Rules.Rule_Table;

package body Gnatcheck.Output is

   Coding_Standard_File_Name : String_Access := new String'("ada.rules");

   Coding_Standard_File : File_Type;
   --  The file to place the sample coding standard into

   procedure Write_GNAT_Coding_Standard;
   procedure Write_HIE_Coding_Standard;
   --  Generates the corresponding coding standards.

   ----------------
   -- Brief_Help --
   ----------------

   procedure Brief_Help is
   begin
      pragma Style_Checks ("M200"); -- Allow long lines

      Info ("gnatcheck: the GNAT rule checking tool");
      Info ("usage: gnatcheck [options] {filename} {-files=filename} [-cargs gcc_switches] -rules rule_switches");
      Info ("options:");
      Info (" --version - Display version and exit");
      Info (" --help    - Display usage and exit");
      Info ("");
      Info (" -Pproject        - Use project file project. Only one such switch can be used");
      Info (" -U               - check all sources of the argument project");
      Info (" -U main          - check the closure of units rooted at unit main");
      Info (" -Xname=value     - specify an external reference for argument project file");
      Info (" --subdirs=dir    - specify subdirectory to place the result files into");
      Info (" --no_objects_dir - place results into current dir instead of project dir");
      Info (" -eL              - follow all symbolic links when processing project files");
      Info ("");
      Info (" -a   - process RTL units");
      Info (" -h   - print out the list of the currently implemented rules");
      Info (" -mn  - n is the maximal number of diagnoses in Stdout");

      Info ("        (n in 0 .. 1000, 0 means no limit)");
      Info (" --incremental -- incremental processing on a per-file basis");
      Info (" -jn  - n is the maximal number of processes");
      Info (" -q   - quiet mode (do not report detections in Stdout)");
      Info (" -t   - report execution time in Stderr");
      Info (" -v   - verbose mode");
      Info (" -log - duplicate all the messages sent to Stderr in log file");
      Info ("        " & Tool_Name.all & ".log");
      Info (" -s   - short form of the report file");
      Info (" -xml - generate report in XML format");
      Info (" -nt  - do not generate text report (enforces '-xml')");
      Info ("");

      Info (" --show-rule - append rule names to diagnoses generated");
      Info ("");

      Info (" --check-redefinition - issue warning if a rule parameter is defined");
      Info ("                        more than once");
      Info ("");

      Info (" --include-file=filename - add the content of filename into generated report");

      Info ("");

      Info (" -o filename   - specify the name of the next report file");
      Info (" -ox filename  - specify the name of the XML report file (enforces '-xml')");
      Info ("");

      Info ("filename                 - the name of the Ada source file to be analyzed.");
      Info ("                           Wildcards are allowed");
      Info ("-files=filename          - the name of the text file containing a list of Ada");
      Info ("                           source files to analyze");
      Info ("--ignore=filename        - do not process sources listed in filename");
      Info ("--write-rules=filename   - the name of a template rule file");
      Info ("");

      Info ("gcc_switches             - switches to be passed to gcc called by " & ASIS_UL.Common.Tool_Name.all);
      Info ("");

      Info ("rule_switches          - a list of the following switches");
      Info ("   -from=filename      - read rule options from filename");
      Info ("   +R<rule_id>[:param] - turn ON a given rule [with given parameter]");
      Info ("   -R<rule_id>         - turn OFF a given rule");
      Info ("   -R<rule_id>:param   - turn OFF some of the checks for a given  rule,");
      Info ("                         depending on the specified parameter");
      Info ("where <rule_id> - ID of one of the currently implemented");
      Info ("                  rules, use '-h' for the full list");
      Info ("      param     - string representing parameter(s) of a given rule, more than ");
      Info ("                  one parameter can be set separated by ','");

      pragma Style_Checks ("M79");
   end Brief_Help;

   ---------------------------
   -- Print_Gnatcheck_Usage --
   ---------------------------

   procedure Print_Gnatcheck_Usage is
   begin
      Set_Error (Standard_Output);
      Brief_Help;

      New_Line;
      New_Line;
      Put_Line ("Report bugs to report@adacore.com");
   end Print_Gnatcheck_Usage;

   -----------------------------------
   -- Set_Coding_Standard_File_Name --
   -----------------------------------

   procedure Set_Coding_Standard_File_Name (Fname : String) is
   begin
      Free (Coding_Standard_File_Name);
      Coding_Standard_File_Name := new String'(Fname);
   end Set_Coding_Standard_File_Name;

   ---------------------------
   -- Write_Coding_Standard --
   ---------------------------

   procedure Write_Coding_Standard is
      Max_Len : Positive := 1;
      Tmp_Max : Positive;
      --  Maximal length of the rule option

   begin
      if Is_Regular_File (Coding_Standard_File_Name.all) then
         Open (Coding_Standard_File, Out_File, Coding_Standard_File_Name.all);
      else
         Create
           (Coding_Standard_File, Out_File, Coding_Standard_File_Name.all);
      end if;

      if Coding_Standard_Kind = Not_A_Coding_Standard then
         Coding_Standard_Kind := Default_Coding_Standard_Kind;
      end if;

      case Coding_Standard_Kind is
         when Template_Coding_Standard_Kinds =>
            --  Compute the maximal length of the rule option:
            for J in First_Rule .. All_Rules.Last loop
               if All_Rules.Table (J).Rule_Status = Fully_Implemented then
                  Tmp_Max :=
                    Rule_Option (All_Rules.Table (J).all,
                                 Coding_Standard_Kind)'Length;

                  if Tmp_Max > Max_Len then
                     Max_Len := Tmp_Max;
                  end if;

               end if;
            end loop;

            Max_Len := Max_Len + 2;

            Put
              (Coding_Standard_File,
               "--  Sample coding standard file, with all available rules ");

            if Coding_Standard_Kind = Template_All_ON then
               Put_Line
                 (Coding_Standard_File,
                  "enabled");
            else
               Put_Line
                 (Coding_Standard_File,
                  "disabled");
            end if;

            Put_Line
              (Coding_Standard_File,
               "--  Should be reviewed and corrected manually");
            New_Line (Coding_Standard_File);

            for J in First_Rule .. All_Rules.Last loop
               if All_Rules.Table (J).Rule_Status = Fully_Implemented then
                  Sample_Image
                    (All_Rules.Table (J).all,
                     Coding_Standard_Kind,
                     Coding_Standard_File,
                     Max_Len);
               end if;
            end loop;

            New_Line (Coding_Standard_File);

            Put_Line
              (Coding_Standard_File,
               "----------------------------");
            Put_Line
              (Coding_Standard_File,
               "--  Compiler-based checks --");
            Put_Line
              (Coding_Standard_File,
               "----------------------------");

            if Coding_Standard_Kind = Template_All_ON then
               Put_Line
                 (Coding_Standard_File,
                  "+R Warnings     : a  --  activate all optional warnings");

               Put_Line
                 (Coding_Standard_File,
                  "+R Style_Checks : y  --  activate all the style checks");

               Put_Line
                 (Coding_Standard_File,
                  "+R Restrictions : No_Obsolescent_Features ");
            else
               Put_Line
                 (Coding_Standard_File,
                  "+R Warnings:s                              --  disable " &
                  "all warnings");

               Put_Line
                 (Coding_Standard_File,
                  "+R Style_Checks:N                          --  disable " &
                  "all style checks");

               Put_Line
                 (Coding_Standard_File,
                  "-R Restrictions : No_Obsolescent_Features  --  disable " &
                  "specific restriction");
            end if;
         when Not_A_Coding_Standard =>
            pragma Assert (False);
            null;
         when Gnatcheck.Options.GNAT =>
            Write_GNAT_Coding_Standard;
         when HIE =>
            Put_Line
              (Coding_Standard_File,
               "--  Generation of this coding standard " &
               "is not implemented yet");

            Write_HIE_Coding_Standard;
      end case;

      Close (Coding_Standard_File);
   exception
      when Status_Error =>
         Error ("can not open the coding standard file, " &
                "the file may be in use");
         raise Fatal_Error;
      when others =>
         Error ("can not open the coding standard file, check the file name");
         raise Fatal_Error;
   end Write_Coding_Standard;

   --------------------------------
   -- Write_GNAT_Coding_Standard --
   --------------------------------

   procedure Write_GNAT_Coding_Standard is
   begin
      Put_Line
        (Coding_Standard_File,
         "--  Generally recommended coding standard --");
      New_Line (Coding_Standard_File);

      Put_Line
        (Coding_Standard_File,
         "+R Anonymous_Arrays");
      Put_Line
        (Coding_Standard_File,
         "+R Boolean_Relational_Operators");
      Put_Line
        (Coding_Standard_File,
         "+R Enumeration_Ranges_In_CASE_Statements");
      Put_Line
        (Coding_Standard_File,
         "+R Exceptions_As_Control_Flow");
      Put_Line
        (Coding_Standard_File,
         "+R Expanded_Loop_Exit_Names");
      Put_Line
        (Coding_Standard_File,
         "+R Explicit_Full_Discrete_Ranges");
      Put_Line
        (Coding_Standard_File,
         "+R Float_Equality_Checks");
      Put_Line
        (Coding_Standard_File,
         "+R Function_Style_Procedures");
      Put_Line
        (Coding_Standard_File,
         "+R Generics_In_Subprograms");
      Put_Line
        (Coding_Standard_File,
         "+R Non_Short_Circuit_Operators");
      Put_Line
        (Coding_Standard_File,
         "+R Non_Visible_Exceptions");
      Put_Line
        (Coding_Standard_File,
         "+R Separate_Numeric_Error_Handlers");
      Put_Line
        (Coding_Standard_File,
         "+R Unassigned_OUT_Parameters");
   end Write_GNAT_Coding_Standard;

   -------------------------------
   -- Write_HIE_Coding_Standard --
   -------------------------------

   procedure Write_HIE_Coding_Standard is
   begin
      null;
   end Write_HIE_Coding_Standard;

end Gnatcheck.Output;