File: asis_ul-environment-check_parameters.adb

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 (254 lines) | stat: -rw-r--r-- 8,963 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
------------------------------------------------------------------------------
--                                                                          --
--                          GNATCHECK COMPONENTS                            --
--                                                                          --
-- A S I S _ U L . E N V I R O N M E N T . C H E C K  _ P A R A M E T E R S --
--                                                                          --
--            (adapted for gnatcheck from ASIS Utility Library)             --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
--                     Copyright (C) 2005-2014, 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 3, 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 --
-- COPYING3. If not,  go to http://www.gnu.org/licenses for a complete copy --
-- of the license.                                                          --
--                                                                          --
-- ASIS UL is maintained by AdaCore (http://www.adacore.com).               --
--                                                                          --
------------------------------------------------------------------------------

pragma Ada_2012;

with ASIS_UL.Output;
with ASIS_UL.Projects;
with ASIS_UL.Source_Table;
with ASIS_UL.Tree_Creation;

with Gnatcheck.Categories;
with Gnatcheck.Compiler;         use Gnatcheck.Compiler;
with Gnatcheck.Ids;              use Gnatcheck.Ids;
with Gnatcheck.Options;
with Gnatcheck.Output;           use Gnatcheck.Output;
with Gnatcheck.Projects;         use Gnatcheck.Projects;
with Gnatcheck.Rules;            use Gnatcheck.Rules;
with Gnatcheck.Rules.Rule_Table; use Gnatcheck.Rules.Rule_Table;

separate (ASIS_UL.Environment)
procedure Check_Parameters is
begin
   if Verbose_Mode and then not Mimic_gcc then
      --  In incremental mode, we want Verbose_Mode to print this only in the
      --  outer invocation.
      Print_Version_Info (2004);
   end if;

   if Print_Version then
      Print_Tool_Version (2004);
      Nothing_To_Do := True;
      return;
   end if;

   if Print_Usage then
      Print_Gnatcheck_Usage;
      Nothing_To_Do := True;
      return;
   end if;

   --  We generate the rule help inconditionally.
   if Gnatcheck.Options.Generate_Rules_Help then
      Rules_Help;
   end if;

   if Gnatcheck.Options.Generate_Category_Help then
      Gnatcheck.Categories.Category_Help
        (Category_Name => "", --  Root category
         From_Status   => Gnatcheck.Options.Rule_Report_Status,
         Recursively   => Gnatcheck.Options.Recursive_Help,
         Level         => 0);
   end if;

   if ASIS_UL.Options.Generate_XML_Help then
      Gnatcheck.Categories.XML_Categories_Help;
   end if;

   if Gnatcheck.Options.Generate_Coding_Standard then
      Gnatcheck.Output.Write_Coding_Standard;
   end if;

   --  Now check if we have anything to do:

   if ASIS_UL.Options.No_Argument_File_Specified then

      if Gnatcheck.Options.Generate_Rules_Help
       or else
         Gnatcheck.Options.Generate_Category_Help
       or else
         ASIS_UL.Options.Generate_XML_Help
       or else
         Gnatcheck.Options.Generate_Coding_Standard
      then
         Nothing_To_Do := True;
         return;
      else
         Error ("No input source file set");
         raise Parameter_Error;
      end if;

   end if;

   Read_Args_From_Temp_Storage
     (Duplication_Report =>
        not Gnatcheck.Projects.Is_Specified (Gnatcheck.Options.Gnatcheck_Prj),
      Arg_Project => Gnatcheck.Options.Gnatcheck_Prj);

   Nothing_To_Do := Last_Source < First_SF_Id;

   if Nothing_To_Do then
      Error ("No existing file to process");
      --  All the rest does not make any sense
      return;
   end if;

   if Gnatcheck.Options.Gnatcheck_Prj.Is_Specified then
      Gnatcheck.Projects.Set_Global_Result_Dirs
        (Gnatcheck.Options.Gnatcheck_Prj);
      Gnatcheck.Projects.Set_Individual_Source_Options
        (Gnatcheck.Options.Gnatcheck_Prj);
   end if;

   Set_Compiler_Checks;

   Analyze_Compiler_Output :=
     Use_gnaty_Option or else Use_gnatw_Option or else Check_Restrictions;

   if Analyze_Compiler_Output then
      if Use_gnatw_Option
        or else
         Check_Restrictions
         --  We may change settings for Check_Restrictions mode if and when
         --  we have an option to turn off all the compiler warnings except
         --  those that are related to restrictions only
      then
         Store_Option ("-gnatwn");
         Store_Option (Get_Warning_Option);
      else
         --  '-gnatws' disables all the warnings except style-related
         Store_Option ("-gnatws");
      end if;

      Store_Option ("-gnatyN");
   end if;

   if Use_gnaty_Option then
      Store_Option (Get_Style_Option);
   end if;

   --  In Mimic_gcc mode, we need to use the full path name of the
   --  Gnatcheck_Config_File, because the current directory when running the
   --  compiler is Tool_Current_Dir. We need to set Tool_Temp_Dir first,
   --  because that's where the file will be, and Go_To_Temp_Dir sets
   --  Tool_Temp_Dir as a side effect.

   if Check_Restrictions or else Use_gnatw_Option then
      Go_To_Temp_Dir;
      GNAT.Directory_Operations.Change_Dir (Tool_Current_Dir);
      Store_Option
        ("-gnatec=" &
           (if Mimic_gcc
              then Compose (Tool_Temp_Dir.all, Gnatcheck_Config_File)
              else Gnatcheck_Config_File));
   end if;

   Suppess_Compiler_Check := not (Use_gnatw_Option
                                or else
                                  Use_gnaty_Option
                                or else
                                  Check_Restrictions);

   for Rule in All_Rules.First .. All_Rules.Last loop

      if All_Rules.Table (Rule).Diagnosis /= null
       and then
         Is_Enable (All_Rules.Table (Rule).all)
      then
         --  Note, that if a rule does not have its own diagnoses, this
         --  means that it is implemented by some other rules, so it
         --  should not go into the report
         Gnatcheck.Options.Active_Rule_Present := True;
         exit;
      end if;
   end loop;

   if not (Gnatcheck.Options.Active_Rule_Present
           or else
             Analyze_Compiler_Output)
   then
      if ASIS_UL.Options.Test_Mode then
         Activate_Rules_In_Test_Mode;
         Process_RTL_Units := True;
      else
         --  Here we have some sources specified, so this situation definitely
         --  is wrong!
         Error ("No rule to check specified");
         raise Parameter_Error;
      end if;
   end if;

   --  If we are here - we have sources to check and rules to apply
   Total_Sources := Natural (Last_Source);
   Sources_Left  := Total_Sources;

   --  Check is the active set of rules requires building the global
   --  structure

   for J in First_Rule .. All_Rules.Last loop

      if All_Rules.Table (J).Rule_State = Enabled then

         if All_Rules.Table (J).all in Global_Rule_Template'Class then
            ASIS_UL.Options.Buld_Call_Graph         := True;
            Gnatcheck.Options.Analyse_Expanded_Code := True;
            Init_Global_Structure
              (Global_Rule_Template'Class (All_Rules.Table (J).all));
         end if;

         if Checked_On_Expanded_Code (All_Rules.Table (J).all) then
            Gnatcheck.Options.Analyse_Expanded_Code := True;
         end if;

         if All_Rules.Table (J).all in Text_Rule_Template'Class then
            Gnatcheck.Options.Analyse_Source_Text := True;
         end if;

      end if;

   end loop;

   --  We need to reset the argument list, because new warning and style
   --  control options may be extracted from the corresponding rules

   Set_Arg_List;

   ASIS_UL.Output.Set_Report_File;

   --  Check for non-documented --no-column option:

   if Gnatcheck.Options.Full_Source_Locations
     and then
       Gnatcheck.Options.No_Column_Num_In_Diagnoses
   then
      Error ("-l and --no-column cannot be set together");
      raise Parameter_Error;
   end if;

   ASIS_UL.Tree_Creation.Set_Max_Processes;

end Check_Parameters;