OSDN Git Service

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