OSDN Git Service

Nathanael Nerode <neroden@gcc.gnu.org>
[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 --                                                                          --
10 --          Copyright (C) 1992-2001, Free Software Foundation, Inc.         --
11 --                                                                          --
12 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
13 -- terms of the  GNU General Public License as published  by the Free Soft- --
14 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
15 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
18 -- for  more details.  You should have  received  a copy of the GNU General --
19 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
20 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
21 -- MA 02111-1307, USA.                                                      --
22 --                                                                          --
23 -- GNAT was originally developed  by the GNAT team at  New York University. --
24 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
25 --                                                                          --
26 ------------------------------------------------------------------------------
27
28 with Hostparm; use Hostparm;
29 with Opt;      use Opt;
30
31 package body Stylesw is
32
33    -------------------------------
34    -- Reset_Style_Check_Options --
35    -------------------------------
36
37    procedure Reset_Style_Check_Options is
38    begin
39       Style_Check_Indentation      := 0;
40       Style_Check_Attribute_Casing := False;
41       Style_Check_Blanks_At_End    := False;
42       Style_Check_Comments         := 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_Pragma_Casing    := False;
51       Style_Check_References       := False;
52       Style_Check_Specs            := False;
53       Style_Check_Standard         := False;
54       Style_Check_Subprogram_Order := False;
55       Style_Check_Tokens           := False;
56    end Reset_Style_Check_Options;
57
58    ------------------------------
59    -- Save_Style_Check_Options --
60    ------------------------------
61
62    procedure Save_Style_Check_Options (Options : out Style_Check_Options) is
63       P : Natural := 0;
64       J : Natural;
65
66       procedure Add (C : Character; S : Boolean);
67       --  Add given character C to string if switch S is true
68
69       procedure Add (C : Character; S : Boolean) is
70       begin
71          if S then
72             P := P + 1;
73             Options (P) := C;
74          end if;
75       end Add;
76
77    --  Start of processing for Save_Style_Check_Options
78
79    begin
80       for K in Options'Range loop
81          Options (K) := ' ';
82       end loop;
83
84       Add (Character'Val (Style_Check_Indentation + Character'Pos ('0')),
85            Style_Check_Indentation /= 0);
86
87       Add ('a', Style_Check_Attribute_Casing);
88       Add ('b', Style_Check_Blanks_At_End);
89       Add ('c', Style_Check_Comments);
90       Add ('e', Style_Check_End_Labels);
91       Add ('f', Style_Check_Form_Feeds);
92       Add ('h', Style_Check_Horizontal_Tabs);
93       Add ('i', Style_Check_If_Then_Layout);
94       Add ('k', Style_Check_Keyword_Casing);
95       Add ('l', Style_Check_Layout);
96       Add ('m', Style_Check_Max_Line_Length);
97       Add ('n', Style_Check_Standard);
98       Add ('o', Style_Check_Subprogram_Order);
99       Add ('p', Style_Check_Pragma_Casing);
100       Add ('r', Style_Check_References);
101       Add ('s', Style_Check_Specs);
102       Add ('t', Style_Check_Tokens);
103
104       if Style_Check_Max_Line_Length then
105          P := Options'Last;
106          J := Natural (Style_Max_Line_Length);
107
108          loop
109             Options (P) := Character'Val (J mod 10 + Character'Pos ('0'));
110             P := P - 1;
111             J := J / 10;
112             exit when J = 0;
113          end loop;
114
115          Options (P) := 'M';
116       end if;
117
118    end Save_Style_Check_Options;
119
120    -------------------------------------
121    -- Set_Default_Style_Check_Options --
122    -------------------------------------
123
124    procedure Set_Default_Style_Check_Options is
125    begin
126       Reset_Style_Check_Options;
127       Set_Style_Check_Options ("3abcefhiklmnprst");
128    end Set_Default_Style_Check_Options;
129
130    -----------------------------
131    -- Set_Style_Check_Options --
132    -----------------------------
133
134    --  Version used when no error checking is required
135
136    procedure Set_Style_Check_Options (Options : String) is
137       OK : Boolean;
138       EC : Natural;
139
140    begin
141       Set_Style_Check_Options (Options, OK, EC);
142    end Set_Style_Check_Options;
143
144    --  Normal version with error checking
145
146    procedure Set_Style_Check_Options
147      (Options  : String;
148       OK       : out Boolean;
149       Err_Col  : out Natural)
150    is
151       J : Natural;
152       C : Character;
153
154    begin
155       J := Options'First;
156       while J <= Options'Last loop
157          C := Options (J);
158          J := J + 1;
159
160          case C is
161             when '1' .. '9' =>
162                Style_Check_Indentation
163                   := Character'Pos (C) - Character'Pos ('0');
164
165             when 'a' =>
166                Style_Check_Attribute_Casing := True;
167
168             when 'b' =>
169                Style_Check_Blanks_At_End    := True;
170
171             when 'c' =>
172                Style_Check_Comments         := True;
173
174             when 'e' =>
175                Style_Check_End_Labels       := True;
176
177             when 'f' =>
178                Style_Check_Form_Feeds       := True;
179
180             when 'h' =>
181                Style_Check_Horizontal_Tabs  := True;
182
183             when 'i' =>
184                Style_Check_If_Then_Layout   := True;
185
186             when 'k' =>
187                Style_Check_Keyword_Casing   := True;
188
189             when 'l' =>
190                Style_Check_Layout           := True;
191
192             when 'm' =>
193                Style_Check_Max_Line_Length  := True;
194                Style_Max_Line_Length        := 79;
195
196             when 'n' =>
197                Style_Check_Standard         := True;
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                   J := J + 1;
215                   exit when J > Options'Last
216                     or else Options (J) not in '0' .. '9';
217                end loop;
218
219                Style_Max_Line_Length :=
220                   Int'Min (Style_Max_Line_Length, Hostparm.Max_Line_Length);
221
222                Style_Check_Max_Line_Length := Style_Max_Line_Length /= 0;
223
224             when 'o' =>
225                Style_Check_Subprogram_Order := True;
226
227             when 'p' =>
228                Style_Check_Pragma_Casing    := True;
229
230             when 'r' =>
231                Style_Check_References       := True;
232
233             when 's' =>
234                Style_Check_Specs            := True;
235
236             when 't' =>
237                Style_Check_Tokens           := True;
238
239             when ' ' =>
240                null;
241
242             when others =>
243                OK      := False;
244                Err_Col := J - 1;
245                return;
246          end case;
247       end loop;
248
249       Style_Check := True;
250       OK := True;
251       Err_Col := Options'Last + 1;
252    end Set_Style_Check_Options;
253
254 end Stylesw;