OSDN Git Service

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