OSDN Git Service

PR preprocessor/20348
[pf3gnuchains/gcc-fork.git] / gcc / ada / stylesw.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                              S T Y L E S W                               --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2005, 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 Stylesw is
30
31    -------------------------------
32    -- Reset_Style_Check_Options --
33    -------------------------------
34
35    procedure Reset_Style_Check_Options is
36    begin
37       Style_Check_Indentation         := 0;
38       Style_Check_Attribute_Casing    := False;
39       Style_Check_Blanks_At_End       := False;
40       Style_Check_Blank_Lines         := False;
41       Style_Check_Comments            := False;
42       Style_Check_DOS_Line_Terminator := False;
43       Style_Check_End_Labels          := False;
44       Style_Check_Form_Feeds          := False;
45       Style_Check_Horizontal_Tabs     := False;
46       Style_Check_If_Then_Layout      := False;
47       Style_Check_Keyword_Casing      := False;
48       Style_Check_Layout              := False;
49       Style_Check_Max_Line_Length     := False;
50       Style_Check_Max_Nesting_Level   := False;
51       Style_Check_Order_Subprograms   := False;
52       Style_Check_Pragma_Casing       := False;
53       Style_Check_References          := False;
54       Style_Check_Specs               := False;
55       Style_Check_Standard            := False;
56       Style_Check_Tokens              := False;
57       Style_Check_Xtra_Parens         := False;
58    end Reset_Style_Check_Options;
59
60    ------------------------------
61    -- Save_Style_Check_Options --
62    ------------------------------
63
64    procedure Save_Style_Check_Options (Options : out Style_Check_Options) is
65       P : Natural := 0;
66
67       procedure Add (C : Character; S : Boolean);
68       --  Add given character C to string if switch S is true
69
70       procedure Add_Nat (N : Nat);
71       --  Add given natural number to string
72
73       ---------
74       -- Add --
75       ---------
76
77       procedure Add (C : Character; S : Boolean) is
78       begin
79          if S then
80             P := P + 1;
81             Options (P) := C;
82          end if;
83       end Add;
84
85       -------------
86       -- Add_Nat --
87       -------------
88
89       procedure Add_Nat (N : Nat) is
90       begin
91          if N > 9 then
92             Add_Nat (N / 10);
93          end if;
94
95          P := P + 1;
96          Options (P) := Character'Val (Character'Pos ('0') + N mod 10);
97       end Add_Nat;
98
99    --  Start of processing for Save_Style_Check_Options
100
101    begin
102       for K in Options'Range loop
103          Options (K) := ' ';
104       end loop;
105
106       Add (Character'Val (Style_Check_Indentation + Character'Pos ('0')),
107            Style_Check_Indentation /= 0);
108
109       Add ('a', Style_Check_Attribute_Casing);
110       Add ('b', Style_Check_Blanks_At_End);
111       Add ('c', Style_Check_Comments);
112       Add ('d', Style_Check_DOS_Line_Terminator);
113       Add ('e', Style_Check_End_Labels);
114       Add ('f', Style_Check_Form_Feeds);
115       Add ('h', Style_Check_Horizontal_Tabs);
116       Add ('i', Style_Check_If_Then_Layout);
117       Add ('k', Style_Check_Keyword_Casing);
118       Add ('l', Style_Check_Layout);
119       Add ('n', Style_Check_Standard);
120       Add ('o', Style_Check_Order_Subprograms);
121       Add ('p', Style_Check_Pragma_Casing);
122       Add ('r', Style_Check_References);
123       Add ('s', Style_Check_Specs);
124       Add ('t', Style_Check_Tokens);
125       Add ('u', Style_Check_Blank_Lines);
126       Add ('x', Style_Check_Xtra_Parens);
127
128       if Style_Check_Max_Line_Length then
129          P := P + 1;
130          Options (P) := 'M';
131          Add_Nat (Style_Max_Line_Length);
132       end if;
133
134       if Style_Check_Max_Nesting_Level then
135          P := P + 1;
136          Options (P) := 'L';
137          Add_Nat (Style_Max_Nesting_Level);
138       end if;
139
140       pragma Assert (P <= Options'Last);
141
142       while P < Options'Last loop
143          P := P + 1;
144          Options (P) := ' ';
145       end loop;
146    end Save_Style_Check_Options;
147
148    -------------------------------------
149    -- Set_Default_Style_Check_Options --
150    -------------------------------------
151
152    procedure Set_Default_Style_Check_Options is
153    begin
154       Reset_Style_Check_Options;
155       Set_Style_Check_Options ("3abcefhiklmnprst");
156    end Set_Default_Style_Check_Options;
157
158    -----------------------------
159    -- Set_Style_Check_Options --
160    -----------------------------
161
162    --  Version used when no error checking is required
163
164    procedure Set_Style_Check_Options (Options : String) is
165       OK : Boolean;
166       EC : Natural;
167    begin
168       Set_Style_Check_Options (Options, OK, EC);
169    end Set_Style_Check_Options;
170
171    --  Normal version with error checking
172
173    procedure Set_Style_Check_Options
174      (Options  : String;
175       OK       : out Boolean;
176       Err_Col  : out Natural)
177    is
178       J : Natural;
179       C : Character;
180
181    begin
182       J := Options'First;
183       while J <= Options'Last loop
184          C := Options (J);
185          J := J + 1;
186
187          case C is
188             when '1' .. '9' =>
189                Style_Check_Indentation
190                   := Character'Pos (C) - Character'Pos ('0');
191
192             when 'a' =>
193                Style_Check_Attribute_Casing    := True;
194
195             when 'b' =>
196                Style_Check_Blanks_At_End       := True;
197
198             when 'c' =>
199                Style_Check_Comments            := True;
200
201             when 'd' =>
202                Style_Check_DOS_Line_Terminator := True;
203
204             when 'e' =>
205                Style_Check_End_Labels          := True;
206
207             when 'f' =>
208                Style_Check_Form_Feeds          := True;
209
210             when 'h' =>
211                Style_Check_Horizontal_Tabs     := True;
212
213             when 'i' =>
214                Style_Check_If_Then_Layout      := True;
215
216             when 'k' =>
217                Style_Check_Keyword_Casing      := True;
218
219             when 'l' =>
220                Style_Check_Layout              := True;
221
222             when 'L' =>
223                Style_Max_Nesting_Level := 0;
224
225                if J > Options'Last
226                  or else Options (J) not in '0' .. '9'
227                then
228                   OK := False;
229                   Err_Col := J;
230                   return;
231                end if;
232
233                loop
234                   Style_Max_Nesting_Level :=
235                     Style_Max_Nesting_Level * 10 +
236                       Character'Pos (Options (J)) - Character'Pos ('0');
237
238                   if Style_Max_Nesting_Level > 999 then
239                      OK := False;
240                      Err_Col := J;
241                      return;
242                   end if;
243
244                   J := J + 1;
245                   exit when J > Options'Last
246                     or else Options (J) not in '0' .. '9';
247                end loop;
248
249                Style_Check_Max_Nesting_Level := Style_Max_Nesting_Level /= 0;
250
251             when 'm' =>
252                Style_Check_Max_Line_Length     := True;
253                Style_Max_Line_Length           := 79;
254
255             when 'n' =>
256                Style_Check_Standard            := True;
257
258             when 'N' =>
259                Reset_Style_Check_Options;
260
261             when 'M' =>
262                Style_Max_Line_Length := 0;
263
264                if J > Options'Last
265                  or else Options (J) not in '0' .. '9'
266                then
267                   OK := False;
268                   Err_Col := J;
269                   return;
270                end if;
271
272                loop
273                   Style_Max_Line_Length :=
274                     Style_Max_Line_Length * 10 +
275                       Character'Pos (Options (J)) - Character'Pos ('0');
276
277                   if Style_Max_Line_Length > Int (Column_Number'Last) then
278                      OK := False;
279                      Err_Col := J;
280                      return;
281                   end if;
282
283                   J := J + 1;
284                   exit when J > Options'Last
285                     or else Options (J) not in '0' .. '9';
286                end loop;
287
288                Style_Check_Max_Line_Length   := Style_Max_Line_Length /= 0;
289
290             when 'o' =>
291                Style_Check_Order_Subprograms   := True;
292
293             when 'p' =>
294                Style_Check_Pragma_Casing       := True;
295
296             when 'r' =>
297                Style_Check_References          := True;
298
299             when 's' =>
300                Style_Check_Specs               := True;
301
302             when 't' =>
303                Style_Check_Tokens              := True;
304
305             when 'u' =>
306                Style_Check_Blank_Lines         := True;
307
308             when 'x' =>
309                Style_Check_Xtra_Parens         := True;
310
311             when ' ' =>
312                null;
313
314             when others =>
315                OK      := False;
316                Err_Col := J - 1;
317                return;
318          end case;
319       end loop;
320
321       Style_Check := True;
322       OK := True;
323       Err_Col := Options'Last + 1;
324    end Set_Style_Check_Options;
325
326 end Stylesw;