OSDN Git Service

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