OSDN Git Service

* Makefile.in (reload1.o-warn): Remove.
[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-2007, 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 Hostparm; use Hostparm;
28 with Opt;      use Opt;
29
30 package body Stylesw is
31
32    -------------------------------
33    -- Reset_Style_Check_Options --
34    -------------------------------
35
36    procedure Reset_Style_Check_Options is
37    begin
38       Style_Check_Indentation           := 0;
39       Style_Check_Array_Attribute_Index := False;
40       Style_Check_Attribute_Casing      := False;
41       Style_Check_Blanks_At_End         := False;
42       Style_Check_Blank_Lines           := False;
43       Style_Check_Comments              := False;
44       Style_Check_DOS_Line_Terminator   := False;
45       Style_Check_End_Labels            := False;
46       Style_Check_Form_Feeds            := False;
47       Style_Check_Horizontal_Tabs       := False;
48       Style_Check_If_Then_Layout        := False;
49       Style_Check_Keyword_Casing        := False;
50       Style_Check_Layout                := False;
51       Style_Check_Max_Line_Length       := False;
52       Style_Check_Max_Nesting_Level     := False;
53       Style_Check_Mode_In               := False;
54       Style_Check_Order_Subprograms     := False;
55       Style_Check_Pragma_Casing         := False;
56       Style_Check_References            := False;
57       Style_Check_Specs                 := False;
58       Style_Check_Standard              := False;
59       Style_Check_Tokens                := False;
60       Style_Check_Xtra_Parens           := False;
61    end Reset_Style_Check_Options;
62
63    ------------------------------
64    -- Save_Style_Check_Options --
65    ------------------------------
66
67    procedure Save_Style_Check_Options (Options : out Style_Check_Options) is
68       P : Natural   := 0;
69
70       procedure Add (C : Character; S : Boolean);
71       --  Add given character C to string if switch S is true
72
73       procedure Add_Nat (N : Nat);
74       --  Add given natural number to string
75
76       ---------
77       -- Add --
78       ---------
79
80       procedure Add (C : Character; S : Boolean) is
81       begin
82          if S then
83             P := P + 1;
84             Options (P) := C;
85          end if;
86       end Add;
87
88       -------------
89       -- Add_Nat --
90       -------------
91
92       procedure Add_Nat (N : Nat) is
93       begin
94          if N > 9 then
95             Add_Nat (N / 10);
96          end if;
97
98          P := P + 1;
99          Options (P) := Character'Val (Character'Pos ('0') + N mod 10);
100       end Add_Nat;
101
102    --  Start of processing for Save_Style_Check_Options
103
104    begin
105       for K in Options'Range loop
106          Options (K) := ' ';
107       end loop;
108
109       Add (Character'Val (Style_Check_Indentation + Character'Pos ('0')),
110            Style_Check_Indentation /= 0);
111
112       Add ('a', Style_Check_Attribute_Casing);
113       Add ('A', Style_Check_Array_Attribute_Index);
114       Add ('b', Style_Check_Blanks_At_End);
115       Add ('c', Style_Check_Comments);
116       Add ('d', Style_Check_DOS_Line_Terminator);
117       Add ('e', Style_Check_End_Labels);
118       Add ('f', Style_Check_Form_Feeds);
119       Add ('h', Style_Check_Horizontal_Tabs);
120       Add ('i', Style_Check_If_Then_Layout);
121       Add ('I', Style_Check_Mode_In);
122       Add ('k', Style_Check_Keyword_Casing);
123       Add ('l', Style_Check_Layout);
124       Add ('n', Style_Check_Standard);
125       Add ('o', Style_Check_Order_Subprograms);
126       Add ('p', Style_Check_Pragma_Casing);
127       Add ('r', Style_Check_References);
128       Add ('s', Style_Check_Specs);
129       Add ('t', Style_Check_Tokens);
130       Add ('u', Style_Check_Blank_Lines);
131       Add ('x', Style_Check_Xtra_Parens);
132
133       if Style_Check_Max_Line_Length then
134          P := P + 1;
135          Options (P) := 'M';
136          Add_Nat (Style_Max_Line_Length);
137       end if;
138
139       if Style_Check_Max_Nesting_Level then
140          P := P + 1;
141          Options (P) := 'L';
142          Add_Nat (Style_Max_Nesting_Level);
143       end if;
144
145       pragma Assert (P <= Options'Last);
146
147       while P < Options'Last loop
148          P := P + 1;
149          Options (P) := ' ';
150       end loop;
151    end Save_Style_Check_Options;
152
153    -------------------------------------
154    -- Set_Default_Style_Check_Options --
155    -------------------------------------
156
157    procedure Set_Default_Style_Check_Options is
158    begin
159       Reset_Style_Check_Options;
160       Set_Style_Check_Options ("3aAbcefhiklmnprst");
161    end Set_Default_Style_Check_Options;
162
163    ----------------------------------
164    -- Set_GNAT_Style_Check_Options --
165    ----------------------------------
166
167    procedure Set_GNAT_Style_Check_Options is
168    begin
169       Reset_Style_Check_Options;
170       Set_Style_Check_Options ("3aAbcdefhiklmnprstux");
171    end Set_GNAT_Style_Check_Options;
172
173    -----------------------------
174    -- Set_Style_Check_Options --
175    -----------------------------
176
177    --  Version used when no error checking is required
178
179    procedure Set_Style_Check_Options (Options : String) is
180       OK : Boolean;
181       EC : Natural;
182    begin
183       Set_Style_Check_Options (Options, OK, EC);
184       pragma Assert (OK);
185    end Set_Style_Check_Options;
186
187    --  Normal version with error checking
188
189    procedure Set_Style_Check_Options
190      (Options  : String;
191       OK       : out Boolean;
192       Err_Col  : out Natural)
193    is
194       C : Character;
195
196       procedure Add_Img (N : Natural);
197       --  Concatenates image of N at end of Style_Msg_Buf
198
199       procedure Bad_Style_Switch (Msg : String);
200       --  Called if bad style switch found. Msg is mset in Style_Msg_Buf and
201       --  Style_Msg_Len. OK is set False.
202
203       -------------
204       -- Add_Img --
205       -------------
206
207       procedure Add_Img (N : Natural) is
208       begin
209          if N >= 10 then
210             Add_Img (N / 10);
211          end if;
212
213          Style_Msg_Len := Style_Msg_Len + 1;
214          Style_Msg_Buf (Style_Msg_Len) :=
215            Character'Val (N mod 10 + Character'Pos ('0'));
216       end Add_Img;
217
218       ----------------------
219       -- Bad_Style_Switch --
220       ----------------------
221
222       procedure Bad_Style_Switch (Msg : String) is
223       begin
224          OK := False;
225          Style_Msg_Len := Msg'Length;
226          Style_Msg_Buf (1 .. Style_Msg_Len) := Msg;
227       end Bad_Style_Switch;
228
229    --  Start of processing for Set_Style_Check_Options
230
231    begin
232       Err_Col := Options'First;
233       while Err_Col <= Options'Last loop
234          C := Options (Err_Col);
235          Err_Col := Err_Col + 1;
236
237          case C is
238             when '1' .. '9' =>
239                Style_Check_Indentation :=
240                  Character'Pos (C) - Character'Pos ('0');
241
242             when 'a' =>
243                Style_Check_Attribute_Casing      := True;
244
245             when 'A' =>
246                Style_Check_Array_Attribute_Index := True;
247
248             when 'b' =>
249                Style_Check_Blanks_At_End         := True;
250
251             when 'c' =>
252                Style_Check_Comments              := True;
253
254             when 'd' =>
255                Style_Check_DOS_Line_Terminator   := True;
256
257             when 'e' =>
258                Style_Check_End_Labels            := True;
259
260             when 'f' =>
261                Style_Check_Form_Feeds            := True;
262
263             when 'g' =>
264                Set_GNAT_Style_Check_Options;
265
266             when 'h' =>
267                Style_Check_Horizontal_Tabs       := True;
268
269             when 'i' =>
270                Style_Check_If_Then_Layout        := True;
271
272             when 'I' =>
273                Style_Check_Mode_In               := True;
274
275             when 'k' =>
276                Style_Check_Keyword_Casing        := True;
277
278             when 'l' =>
279                Style_Check_Layout                := True;
280
281             when 'L' =>
282                Style_Max_Nesting_Level := 0;
283
284                if Err_Col > Options'Last
285                  or else Options (Err_Col) not in '0' .. '9'
286                then
287                   Bad_Style_Switch ("invalid nesting level");
288                   return;
289                end if;
290
291                loop
292                   Style_Max_Nesting_Level :=
293                     Style_Max_Nesting_Level * 10 +
294                       Character'Pos (Options (Err_Col)) - Character'Pos ('0');
295
296                   if Style_Max_Nesting_Level > 999 then
297                      Bad_Style_Switch
298                        ("max nesting level (999) exceeded in style check");
299                      return;
300                   end if;
301
302                   Err_Col := Err_Col + 1;
303                   exit when Err_Col > Options'Last
304                     or else Options (Err_Col) not in '0' .. '9';
305                end loop;
306
307                Style_Check_Max_Nesting_Level := Style_Max_Nesting_Level /= 0;
308
309             when 'm' =>
310                Style_Check_Max_Line_Length       := True;
311                Style_Max_Line_Length             := 79;
312
313             when 'M' =>
314                Style_Max_Line_Length             := 0;
315
316                if Err_Col > Options'Last
317                  or else Options (Err_Col) not in '0' .. '9'
318                then
319                   Bad_Style_Switch
320                     ("invalid line length in style check");
321                   return;
322                end if;
323
324                loop
325                   Style_Max_Line_Length :=
326                     Style_Max_Line_Length * 10 +
327                       Character'Pos (Options (Err_Col)) - Character'Pos ('0');
328
329                   if Style_Max_Line_Length > Int (Max_Line_Length) then
330                      OK := False;
331                      Style_Msg_Buf (1 .. 27) := "max line length allowed is ";
332                      Style_Msg_Len := 27;
333                      Add_Img (Natural (Max_Line_Length));
334                      return;
335                   end if;
336
337                   Err_Col := Err_Col + 1;
338                   exit when Err_Col > Options'Last
339                     or else Options (Err_Col) not in '0' .. '9';
340                end loop;
341
342                Style_Check_Max_Line_Length       := Style_Max_Line_Length /= 0;
343
344             when 'n' =>
345                Style_Check_Standard              := True;
346
347             when 'N' =>
348                Reset_Style_Check_Options;
349
350             when 'o' =>
351                Style_Check_Order_Subprograms     := True;
352
353             when 'p' =>
354                Style_Check_Pragma_Casing         := True;
355
356             when 'r' =>
357                Style_Check_References            := True;
358
359             when 's' =>
360                Style_Check_Specs                 := True;
361
362             when 't' =>
363                Style_Check_Tokens                := True;
364
365             when 'u' =>
366                Style_Check_Blank_Lines           := True;
367
368             when 'x' =>
369                Style_Check_Xtra_Parens           := True;
370
371             when ' ' =>
372                null;
373
374             when others =>
375                Err_Col := Err_Col - 1;
376                Style_Msg_Buf (1 .. 22) := "invalid style switch: ";
377                Style_Msg_Len := 23;
378                Style_Msg_Buf (Style_Msg_Len) := C;
379                OK := False;
380                return;
381          end case;
382       end loop;
383
384       Style_Check := True;
385       OK := True;
386    end Set_Style_Check_Options;
387 end Stylesw;