OSDN Git Service

2004-05-17 Steve Kargl <kargls@comcast.net>
[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-2004, 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,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, 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_Comments         := False;
41       Style_Check_End_Labels       := False;
42       Style_Check_Form_Feeds       := False;
43       Style_Check_Horizontal_Tabs  := False;
44       Style_Check_If_Then_Layout   := False;
45       Style_Check_Keyword_Casing   := False;
46       Style_Check_Layout           := False;
47       Style_Check_Max_Line_Length  := False;
48       Style_Check_Pragma_Casing    := False;
49       Style_Check_References       := False;
50       Style_Check_Specs            := False;
51       Style_Check_Standard         := False;
52       Style_Check_Subprogram_Order := False;
53       Style_Check_Tokens           := False;
54    end Reset_Style_Check_Options;
55
56    ------------------------------
57    -- Save_Style_Check_Options --
58    ------------------------------
59
60    procedure Save_Style_Check_Options (Options : out Style_Check_Options) is
61       P : Natural := 0;
62       J : Natural;
63
64       procedure Add (C : Character; S : Boolean);
65       --  Add given character C to string if switch S is true
66
67       procedure Add (C : Character; S : Boolean) is
68       begin
69          if S then
70             P := P + 1;
71             Options (P) := C;
72          end if;
73       end Add;
74
75    --  Start of processing for Save_Style_Check_Options
76
77    begin
78       for K in Options'Range loop
79          Options (K) := ' ';
80       end loop;
81
82       Add (Character'Val (Style_Check_Indentation + Character'Pos ('0')),
83            Style_Check_Indentation /= 0);
84
85       Add ('a', Style_Check_Attribute_Casing);
86       Add ('b', Style_Check_Blanks_At_End);
87       Add ('c', Style_Check_Comments);
88       Add ('e', Style_Check_End_Labels);
89       Add ('f', Style_Check_Form_Feeds);
90       Add ('h', Style_Check_Horizontal_Tabs);
91       Add ('i', Style_Check_If_Then_Layout);
92       Add ('k', Style_Check_Keyword_Casing);
93       Add ('l', Style_Check_Layout);
94       Add ('m', Style_Check_Max_Line_Length);
95       Add ('n', Style_Check_Standard);
96       Add ('o', Style_Check_Subprogram_Order);
97       Add ('p', Style_Check_Pragma_Casing);
98       Add ('r', Style_Check_References);
99       Add ('s', Style_Check_Specs);
100       Add ('t', Style_Check_Tokens);
101
102       if Style_Check_Max_Line_Length then
103          P := Options'Last;
104          J := Natural (Style_Max_Line_Length);
105
106          loop
107             Options (P) := Character'Val (J mod 10 + Character'Pos ('0'));
108             P := P - 1;
109             J := J / 10;
110             exit when J = 0;
111          end loop;
112
113          Options (P) := 'M';
114       end if;
115
116    end Save_Style_Check_Options;
117
118    -------------------------------------
119    -- Set_Default_Style_Check_Options --
120    -------------------------------------
121
122    procedure Set_Default_Style_Check_Options is
123    begin
124       Reset_Style_Check_Options;
125       Set_Style_Check_Options ("3abcefhiklmnprst");
126    end Set_Default_Style_Check_Options;
127
128    -----------------------------
129    -- Set_Style_Check_Options --
130    -----------------------------
131
132    --  Version used when no error checking is required
133
134    procedure Set_Style_Check_Options (Options : String) is
135       OK : Boolean;
136       EC : Natural;
137    begin
138       Set_Style_Check_Options (Options, OK, EC);
139    end Set_Style_Check_Options;
140
141    --  Normal version with error checking
142
143    procedure Set_Style_Check_Options
144      (Options  : String;
145       OK       : out Boolean;
146       Err_Col  : out Natural)
147    is
148       J : Natural;
149       C : Character;
150
151    begin
152       J := Options'First;
153       while J <= Options'Last loop
154          C := Options (J);
155          J := J + 1;
156
157          case C is
158             when '1' .. '9' =>
159                Style_Check_Indentation
160                   := Character'Pos (C) - Character'Pos ('0');
161
162             when 'a' =>
163                Style_Check_Attribute_Casing := True;
164
165             when 'b' =>
166                Style_Check_Blanks_At_End    := True;
167
168             when 'c' =>
169                Style_Check_Comments         := True;
170
171             when 'e' =>
172                Style_Check_End_Labels       := True;
173
174             when 'f' =>
175                Style_Check_Form_Feeds       := True;
176
177             when 'h' =>
178                Style_Check_Horizontal_Tabs  := True;
179
180             when 'i' =>
181                Style_Check_If_Then_Layout   := True;
182
183             when 'k' =>
184                Style_Check_Keyword_Casing   := True;
185
186             when 'l' =>
187                Style_Check_Layout           := True;
188
189             when 'm' =>
190                Style_Check_Max_Line_Length  := True;
191                Style_Max_Line_Length        := 79;
192
193             when 'n' =>
194                Style_Check_Standard         := True;
195
196             when 'N' =>
197                Reset_Style_Check_Options;
198
199             when 'M' =>
200                Style_Max_Line_Length := 0;
201
202                if J > Options'Last
203                  or else Options (J) not in '0' .. '9'
204                then
205                   OK := False;
206                   Err_Col := J;
207                   return;
208                end if;
209
210                loop
211                   Style_Max_Line_Length :=
212                     Style_Max_Line_Length * 10 +
213                       Character'Pos (Options (J)) - Character'Pos ('0');
214
215                   if Style_Max_Line_Length > Int (Column_Number'Last) then
216                      OK := False;
217                      Err_Col := J;
218                      return;
219                   end if;
220
221                   J := J + 1;
222                   exit when J > Options'Last
223                     or else Options (J) not in '0' .. '9';
224                end loop;
225
226                Style_Check_Max_Line_Length := Style_Max_Line_Length /= 0;
227
228             when 'o' =>
229                Style_Check_Subprogram_Order := True;
230
231             when 'p' =>
232                Style_Check_Pragma_Casing    := True;
233
234             when 'r' =>
235                Style_Check_References       := True;
236
237             when 's' =>
238                Style_Check_Specs            := True;
239
240             when 't' =>
241                Style_Check_Tokens           := True;
242
243             when ' ' =>
244                null;
245
246             when others =>
247                OK      := False;
248                Err_Col := J - 1;
249                return;
250          end case;
251       end loop;
252
253       Style_Check := True;
254       OK := True;
255       Err_Col := Options'Last + 1;
256    end Set_Style_Check_Options;
257
258 end Stylesw;