PR c++/3637
[official-gcc.git] / gcc / ada / ceinfo.adb
blobe5ab95c61bb3a61738deae2082ec973d86c7dfdc
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT SYSTEM UTILITIES --
4 -- --
5 -- C E I N F O --
6 -- --
7 -- B o d y --
8 -- --
9 -- $Revision$ --
10 -- --
11 -- Copyright (C) 1998 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 ------------------------------------------------------------------------------
29 -- Program to check consistency of einfo.ads and einfo.adb. Checks that
30 -- field name usage is consistent, including comments mentioning fields.
32 with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
33 with Ada.Strings.Unbounded.Text_IO; use Ada.Strings.Unbounded.Text_IO;
34 with Ada.Text_IO; use Ada.Text_IO;
36 with GNAT.Spitbol; use GNAT.Spitbol;
37 with GNAT.Spitbol.Patterns; use GNAT.Spitbol.Patterns;
38 with GNAT.Spitbol.Table_VString;
40 procedure CEinfo is
42 package TV renames GNAT.Spitbol.Table_VString;
43 use TV;
45 Infil : File_Type;
46 Lineno : Natural := 0;
48 Err : exception;
49 -- Raised on fatal error
51 Fieldnm : VString;
52 Accessfunc : VString;
53 Line : VString;
55 Fields : GNAT.Spitbol.Table_VString.Table (500);
56 -- Maps field names to underlying field access name
58 UC : Pattern := Any ("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
60 Fnam : Pattern := (UC & Break (' ')) * Fieldnm;
62 Field_Def : Pattern := "-- " & Fnam & " (" & Break (')') * Accessfunc;
64 Field_Ref : Pattern := " -- " & Fnam & Break ('(') & Len (1) &
65 Break (')') * Accessfunc;
67 Field_Com : Pattern := " -- " & Fnam & Span (' ') &
68 (Break (' ') or Rest) * Accessfunc;
70 Func_Hedr : Pattern := " function " & Fnam;
72 Func_Retn : Pattern := " return " & Break (' ') * Accessfunc;
74 Proc_Hedr : Pattern := " procedure " & Fnam;
76 Proc_Setf : Pattern := " Set_" & Break (' ') * Accessfunc;
78 procedure Next_Line;
79 -- Read next line trimmed from Infil into Line and bump Lineno
81 procedure Next_Line is
82 begin
83 Line := Get_Line (Infil);
84 Trim (Line);
85 Lineno := Lineno + 1;
86 end Next_Line;
88 -- Start of processing for CEinfo
90 begin
91 Anchored_Mode := True;
92 New_Line;
93 Open (Infil, In_File, "einfo.ads");
95 Put_Line ("Acquiring field names from spec");
97 loop
98 Next_Line;
99 exit when Match (Line, " -- Access Kinds --");
101 if Match (Line, Field_Def) then
102 Set (Fields, Fieldnm, Accessfunc);
103 end if;
104 end loop;
106 Put_Line ("Checking consistent references in spec");
108 loop
109 Next_Line;
110 exit when Match (Line, " -- Description of Defined");
111 end loop;
113 loop
114 Next_Line;
115 exit when Match (Line, " -- Component_Alignment Control");
117 if Match (Line, Field_Ref) then
118 if Accessfunc /= "synth"
119 and then
120 Accessfunc /= "special"
121 and then
122 Accessfunc /= Get (Fields, Fieldnm)
123 then
124 if Present (Fields, Fieldnm) then
125 Put_Line ("*** field name incorrect at line " & Lineno);
126 Put_Line (" found field " & Accessfunc);
127 Put_Line (" expecting field " & Get (Fields, Fieldnm));
129 else
130 Put_Line
131 ("*** unknown field name " & Fieldnm & " at line " & Lineno);
132 end if;
133 end if;
134 end if;
135 end loop;
137 Close (Infil);
138 Open (Infil, In_File, "einfo.adb");
139 Lineno := 0;
141 Put_Line ("Check listing of fields in body");
143 loop
144 Next_Line;
145 exit when Match (Line, " -- Attribute Access Functions --");
147 if Match (Line, Field_Com)
148 and then Fieldnm /= "(unused)"
149 and then Accessfunc /= Get (Fields, Fieldnm)
150 then
151 if Present (Fields, Fieldnm) then
152 Put_Line ("*** field name incorrect at line " & Lineno);
153 Put_Line (" found field " & Accessfunc);
154 Put_Line (" expecting field " & Get (Fields, Fieldnm));
156 else
157 Put_Line
158 ("*** unknown field name " & Fieldnm & " at line " & Lineno);
159 end if;
160 end if;
161 end loop;
163 Put_Line ("Check references in access routines in body");
165 loop
166 Next_Line;
167 exit when Match (Line, " -- Classification Functions --");
169 if Match (Line, Func_Hedr) then
170 null;
172 elsif Match (Line, Func_Retn)
173 and then Accessfunc /= Get (Fields, Fieldnm)
174 and then Fieldnm /= "Mechanism"
175 then
176 Put_Line ("*** incorrect field at line " & Lineno);
177 Put_Line (" found field " & Accessfunc);
178 Put_Line (" expecting field " & Get (Fields, Fieldnm));
179 end if;
180 end loop;
182 Put_Line ("Check references in set routines in body");
184 loop
185 Next_Line;
186 exit when Match (Line, " -- Attribute Set Procedures");
187 end loop;
189 loop
190 Next_Line;
191 exit when Match (Line, " ------------");
193 if Match (Line, Proc_Hedr) then
194 null;
196 elsif Match (Line, Proc_Setf)
197 and then Accessfunc /= Get (Fields, Fieldnm)
198 and then Fieldnm /= "Mechanism"
199 then
200 Put_Line ("*** incorrect field at line " & Lineno);
201 Put_Line (" found field " & Accessfunc);
202 Put_Line (" expecting field " & Get (Fields, Fieldnm));
203 end if;
204 end loop;
206 Put_Line ("All tests completed successfully, no errors detected");
208 end CEinfo;