OSDN Git Service

gcc/
[pf3gnuchains/gcc-fork.git] / gcc / ada / validsw.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                              V A L I D S W                               --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 2001-2003 Free Software Foundation, Inc.          --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
19 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
20 -- Boston, MA 02110-1301, USA.                                              --
21 --                                                                          --
22 -- GNAT was originally developed  by the GNAT team at  New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
24 --                                                                          --
25 ------------------------------------------------------------------------------
26
27 with Opt; use Opt;
28
29 package body Validsw is
30
31    ----------------------------------
32    -- Reset_Validity_Check_Options --
33    ----------------------------------
34
35    procedure Reset_Validity_Check_Options is
36    begin
37       Validity_Check_Copies         := False;
38       Validity_Check_Default        := True;
39       Validity_Check_Floating_Point := False;
40       Validity_Check_In_Out_Params  := False;
41       Validity_Check_In_Params      := False;
42       Validity_Check_Operands       := False;
43       Validity_Check_Returns        := False;
44       Validity_Check_Subscripts     := False;
45       Validity_Check_Tests          := False;
46    end Reset_Validity_Check_Options;
47
48    ---------------------------------
49    -- Save_Validity_Check_Options --
50    ---------------------------------
51
52    procedure Save_Validity_Check_Options
53      (Options : out Validity_Check_Options)
54    is
55       P : Natural := 0;
56
57       procedure Add (C : Character; S : Boolean);
58       --  Add given character C to string if switch S is true
59
60       procedure Add (C : Character; S : Boolean) is
61       begin
62          if S then
63             P := P + 1;
64             Options (P) := C;
65          end if;
66       end Add;
67
68    --  Start of processing for Save_Validity_Check_Options
69
70    begin
71       for K in Options'Range loop
72          Options (K) := ' ';
73       end loop;
74
75       Add ('n', not Validity_Check_Default);
76
77       Add ('c', Validity_Check_Copies);
78       Add ('f', Validity_Check_Floating_Point);
79       Add ('i', Validity_Check_In_Params);
80       Add ('m', Validity_Check_In_Out_Params);
81       Add ('o', Validity_Check_Operands);
82       Add ('r', Validity_Check_Returns);
83       Add ('s', Validity_Check_Subscripts);
84       Add ('t', Validity_Check_Tests);
85    end Save_Validity_Check_Options;
86
87    ----------------------------------------
88    -- Set_Default_Validity_Check_Options --
89    ----------------------------------------
90
91    procedure Set_Default_Validity_Check_Options is
92    begin
93       Reset_Validity_Check_Options;
94       Set_Validity_Check_Options ("d");
95    end Set_Default_Validity_Check_Options;
96
97    --------------------------------
98    -- Set_Validity_Check_Options --
99    --------------------------------
100
101    --  Version used when no error checking is required
102
103    procedure Set_Validity_Check_Options (Options : String) is
104       OK : Boolean;
105       EC : Natural;
106
107    begin
108       Set_Validity_Check_Options (Options, OK, EC);
109    end Set_Validity_Check_Options;
110
111    --  Normal version with error checking
112
113    procedure Set_Validity_Check_Options
114      (Options  : String;
115       OK       : out Boolean;
116       Err_Col  : out Natural)
117    is
118       J : Natural;
119       C : Character;
120
121    begin
122       J := Options'First;
123       while J <= Options'Last loop
124          C := Options (J);
125          J := J + 1;
126
127          --  Turn on validity checking (gets turned off by Vn)
128
129          Validity_Checks_On := True;
130
131          case C is
132
133             when 'c' =>
134                Validity_Check_Copies         := True;
135
136             when 'd' =>
137                Validity_Check_Default        := True;
138
139             when 'f' =>
140                Validity_Check_Floating_Point := True;
141
142             when 'i' =>
143                Validity_Check_In_Params      := True;
144
145             when 'm' =>
146                Validity_Check_In_Out_Params  := True;
147
148             when 'o' =>
149                Validity_Check_Operands       := True;
150
151             when 'p' =>
152                Validity_Check_Parameters     := True;
153
154             when 'r' =>
155                Validity_Check_Returns        := True;
156
157             when 's' =>
158                Validity_Check_Subscripts     := True;
159
160             when 't' =>
161                Validity_Check_Tests          := True;
162
163             when 'C' =>
164                Validity_Check_Copies         := False;
165
166             when 'D' =>
167                Validity_Check_Default        := False;
168
169             when 'I' =>
170                Validity_Check_In_Params      := False;
171
172             when 'F' =>
173                Validity_Check_Floating_Point := False;
174
175             when 'M' =>
176                Validity_Check_In_Out_Params  := False;
177
178             when 'O' =>
179                Validity_Check_Operands       := False;
180
181             when 'P' =>
182                Validity_Check_Parameters     := False;
183
184             when 'R' =>
185                Validity_Check_Returns        := False;
186
187             when 'S' =>
188                Validity_Check_Subscripts     := False;
189
190             when 'T' =>
191                Validity_Check_Tests          := False;
192
193             when 'a' =>
194                Validity_Check_Copies         := True;
195                Validity_Check_Default        := True;
196                Validity_Check_Floating_Point := True;
197                Validity_Check_In_Out_Params  := True;
198                Validity_Check_In_Params      := True;
199                Validity_Check_Operands       := True;
200                Validity_Check_Parameters     := True;
201                Validity_Check_Returns        := True;
202                Validity_Check_Subscripts     := True;
203                Validity_Check_Tests          := True;
204
205             when 'n' =>
206                Validity_Check_Copies         := False;
207                Validity_Check_Default        := False;
208                Validity_Check_Floating_Point := False;
209                Validity_Check_In_Out_Params  := False;
210                Validity_Check_In_Params      := False;
211                Validity_Check_Operands       := False;
212                Validity_Check_Parameters     := False;
213                Validity_Check_Returns        := False;
214                Validity_Check_Subscripts     := False;
215                Validity_Check_Tests          := False;
216                Validity_Checks_On            := False;
217
218             when ' ' =>
219                null;
220
221             when others =>
222                OK      := False;
223                Err_Col := J - 1;
224                return;
225          end case;
226       end loop;
227
228       OK := True;
229       Err_Col := Options'Last + 1;
230    end Set_Validity_Check_Options;
231
232 end Validsw;