OSDN Git Service

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