1 ------------------------------------------------------------------------------
3 -- GNAT SYSTEM UTILITIES --
11 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
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. --
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). --
27 ------------------------------------------------------------------------------
29 -- Program to check consistency of sinfo.ads and sinfo.adb. Checks that
30 -- field name usage is consistent and that assertion cross-reference lists
31 -- are correct, as well as making sure that all the comments on field name
32 -- usage are consistent.
34 with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
35 with Ada.Strings.Unbounded.Text_IO; use Ada.Strings.Unbounded.Text_IO;
36 with Ada.Strings.Maps; use Ada.Strings.Maps;
37 with Ada.Strings.Maps.Constants; use Ada.Strings.Maps.Constants;
38 with Ada.Text_IO; use Ada.Text_IO;
40 with GNAT.Spitbol; use GNAT.Spitbol;
41 with GNAT.Spitbol.Patterns; use GNAT.Spitbol.Patterns;
42 with GNAT.Spitbol.Table_Boolean;
43 with GNAT.Spitbol.Table_VString;
47 package TB renames GNAT.Spitbol.Table_Boolean;
48 package TV renames GNAT.Spitbol.Table_VString;
52 Lineno : Natural := 0;
55 -- Raised on fatal error
58 -- Raised after error is found to terminate run
60 WSP : Pattern := Span (' ' & ASCII.HT);
62 Fields : TV.Table (300);
63 Fields1 : TV.Table (300);
64 Refs : TV.Table (300);
65 Refscopy : TV.Table (300);
66 Special : TB.Table (50);
67 Inlines : TV.Table (100);
69 -- The following define the standard fields used for binary operator,
70 -- unary operator, and other expression nodes. Numbers in the range 1-5
71 -- refer to the Fieldn fields. Letters D-R refer to flags:
89 Flags : TV.Table (20);
90 -- Maps flag numbers to letters
92 N_Fields : Pattern := BreakX ("JL");
93 E_Fields : Pattern := BreakX ("5EFGHIJLOP");
94 U_Fields : Pattern := BreakX ("1345EFGHIJKLOPQ");
95 B_Fields : Pattern := BreakX ("12345EFGHIJKLOPQ");
100 Field : VString := Nul;
101 Fields_Used : VString := Nul;
102 Name : VString := Nul;
103 Next : VString := Nul;
104 Node : VString := Nul;
105 Ref : VString := Nul;
106 Synonym : VString := Nul;
107 Nxtref : VString := Nul;
109 Which_Field : aliased VString := Nul;
111 Node_Search : Pattern := WSP & "-- N_" & Rest * Node;
112 Break_Punc : Pattern := Break (" .,");
113 Plus_Binary : Pattern := WSP & "-- plus fields for binary operator";
114 Plus_Unary : Pattern := WSP & "-- plus fields for unary operator";
115 Plus_Expr : Pattern := WSP & "-- plus fields for expression";
116 Break_Syn : Pattern := WSP & "-- " & Break (' ') * Synonym &
117 " (" & Break (')') * Field;
118 Break_Field : Pattern := BreakX ('-') * Field;
119 Get_Field : Pattern := BreakX (Decimal_Digit_Set) &
120 Span (Decimal_Digit_Set) * Which_Field;
121 Break_WFld : Pattern := Break (Which_Field'Access);
122 Get_Funcsyn : Pattern := WSP & "function " & Rest * Synonym;
123 Extr_Field : Pattern := BreakX ('-') & "-- " & Rest * Field;
124 Get_Procsyn : Pattern := WSP & "procedure Set_" & Rest * Synonym;
125 Get_Inline : Pattern := WSP & "pragma Inline (" & Break (')') * Name;
126 Set_Name : Pattern := "Set_" & Rest * Name;
127 Func_Rest : Pattern := " function " & Rest * Synonym;
128 Get_Nxtref : Pattern := Break (',') * Nxtref & ',';
129 Test_Syn : Pattern := Break ('=') & "= N_" &
130 (Break (" ,)") or Rest) * Next;
131 Chop_Comma : Pattern := BreakX (',') * Next;
132 Return_Fld : Pattern := WSP & "return " & Break (' ') * Field;
133 Set_Syn : Pattern := " procedure Set_" & Rest * Synonym;
134 Set_Fld : Pattern := WSP & "Set_" & Break (' ') * Field & " (N, Val)";
135 Break_With : Pattern := Break ('_') ** Field & "_With_Parent";
137 type VStringA is array (Natural range <>) of VString;
140 -- Read next line trimmed from Infil into Line and bump Lineno
142 procedure Sort (A : in out VStringA);
143 -- Sort a (small) array of VString's
145 procedure Next_Line is
147 Line := Get_Line (Infil);
149 Lineno := Lineno + 1;
152 procedure Sort (A : in out VStringA) is
157 for J in 1 .. A'Length - 1 loop
158 if A (J) > A (J + 1) then
167 -- Start of processing for CSinfo
170 Anchored_Mode := True;
172 Open (Infil, In_File, "sinfo.ads");
173 Put_Line ("Check for field name consistency");
175 -- Setup table for mapping flag numbers to letters
177 Set (Flags, "4", V ("D"));
178 Set (Flags, "5", V ("E"));
179 Set (Flags, "6", V ("F"));
180 Set (Flags, "7", V ("G"));
181 Set (Flags, "8", V ("H"));
182 Set (Flags, "9", V ("I"));
183 Set (Flags, "10", V ("J"));
184 Set (Flags, "11", V ("K"));
185 Set (Flags, "12", V ("L"));
186 Set (Flags, "13", V ("M"));
187 Set (Flags, "14", V ("N"));
188 Set (Flags, "15", V ("O"));
189 Set (Flags, "16", V ("P"));
190 Set (Flags, "17", V ("Q"));
191 Set (Flags, "18", V ("R"));
193 -- Special fields table. The following fields are not recorded or checked
194 -- by Csinfo, since they are specially handled. This means that he both
195 -- the field definitions, and the corresponding subprograms are ignored.
197 Set (Special, "Analyzed", True);
198 Set (Special, "Assignment_OK", True);
199 Set (Special, "Associated_Node", True);
200 Set (Special, "Cannot_Be_Constant", True);
201 Set (Special, "Chars", True);
202 Set (Special, "Comes_From_Source", True);
203 Set (Special, "Do_Overflow_Check", True);
204 Set (Special, "Do_Range_Check", True);
205 Set (Special, "Entity", True);
206 Set (Special, "Error_Posted", True);
207 Set (Special, "Etype", True);
208 Set (Special, "Evaluate_Once", True);
209 Set (Special, "First_Itype", True);
210 Set (Special, "Has_Dynamic_Itype", True);
211 Set (Special, "Has_Dynamic_Range_Check", True);
212 Set (Special, "Has_Dynamic_Length_Check", True);
213 Set (Special, "Has_Private_View", True);
214 Set (Special, "Is_Controlling_Actual", True);
215 Set (Special, "Is_Overloaded", True);
216 Set (Special, "Is_Static_Expression", True);
217 Set (Special, "Left_Opnd", True);
218 Set (Special, "Must_Not_Freeze", True);
219 Set (Special, "Parens", True);
220 Set (Special, "Raises_Constraint_Error", True);
221 Set (Special, "Right_Opnd", True);
223 -- Loop to acquire information from node definitions in sinfo.ads,
224 -- checking for consistency in Op/Flag assignments to each synonym
229 exit when Match (Line, " -- Node Access Functions");
231 if Match (Line, Node_Search)
232 and then not Match (Node, Break_Punc)
242 elsif Match (Line, Plus_Binary) then
243 Bad := Match (Fields_Used, B_Fields);
245 elsif Match (Line, Plus_Unary) then
246 Bad := Match (Fields_Used, U_Fields);
248 elsif Match (Line, Plus_Expr) then
249 Bad := Match (Fields_Used, E_Fields);
251 elsif not Match (Line, Break_Syn) then
254 elsif Match (Synonym, "plus") then
258 Match (Field, Break_Field);
260 if not Present (Special, Synonym) then
262 if Present (Fields, Synonym) then
263 if Field /= Get (Fields, Synonym) then
265 ("Inconsistent field reference at line" &
266 Lineno'Img & " for " & Synonym);
271 Set (Fields, Synonym, Field);
274 Set (Refs, Synonym, Node & ',' & Get (Refs, Synonym));
275 Match (Field, Get_Field);
277 if Match (Field, "Flag") then
278 Which_Field := Get (Flags, Which_Field);
281 if Match (Fields_Used, Break_WFld) then
283 ("Overlapping field at line " & Lineno'Img &
288 Append (Fields_Used, Which_Field);
289 Bad := Bad or Match (Fields_Used, N_Fields);
294 Put_Line ("fields conflict with standard fields for node " & Node);
300 Put_Line ("Check for function consistency");
302 -- Loop through field function definitions to make sure they are OK
307 exit when Match (Line, " -- Node Update");
309 if Match (Line, Get_Funcsyn)
310 and then not Present (Special, Synonym)
312 if not Present (Fields1, Synonym) then
314 ("function on line " & Lineno &
315 " is for unused synonym");
321 if not Match (Line, Extr_Field) then
325 if Field /= Get (Fields1, Synonym) then
326 Put_Line ("Wrong field in function " & Synonym);
330 Delete (Fields1, Synonym);
337 Put_Line ("Check for missing functions");
340 List : TV.Table_Array := Convert_To_Array (Fields1);
343 if List'Length > 0 then
344 Put_Line ("No function for field synonym " & List (1).Name);
349 -- Check field set procedures
353 Put_Line ("Check for set procedure consistency");
358 exit when Match (Line, " -- Inline Pragmas");
359 exit when Match (Line, " -- Iterator Procedures");
361 if Match (Line, Get_Procsyn)
362 and then not Present (Special, Synonym)
364 if not Present (Fields1, Synonym) then
366 ("procedure on line " & Lineno & " is for unused synonym");
372 if not Match (Line, Extr_Field) then
376 if Field /= Get (Fields1, Synonym) then
377 Put_Line ("Wrong field in procedure Set_" & Synonym);
381 Delete (Fields1, Synonym);
388 Put_Line ("Check for missing set procedures");
391 List : TV.Table_Array := Convert_To_Array (Fields1);
394 if List'Length > 0 then
395 Put_Line ("No procedure for field synonym Set_" & List (1).Name);
402 Put_Line ("Check pragma Inlines are all for existing subprograms");
405 while not End_Of_File (Infil) loop
408 if Match (Line, Get_Inline)
409 and then not Present (Special, Name)
411 exit when Match (Name, Set_Name);
413 if not Present (Fields, Name) then
415 ("Pragma Inline on line " & Lineno &
416 " does not correspond to synonym");
420 Set (Inlines, Name, Get (Inlines, Name) & 'r');
427 Put_Line ("Check no pragma Inlines were omitted");
430 List : TV.Table_Array := Convert_To_Array (Fields);
431 Nxt : VString := Nul;
434 for M in List'Range loop
435 Nxt := List (M).Name;
437 if Get (Inlines, Nxt) /= "r" then
438 Put_Line ("Incorrect pragma Inlines for " & Nxt);
449 Open (Infil, In_File, "sinfo.adb");
451 Put_Line ("Check references in functions in body");
456 exit when Match (Line, " -- Field Access Functions --");
461 exit when Match (Line, " -- Field Set Procedures --");
463 if Match (Line, Func_Rest)
464 and then not Present (Special, Synonym)
466 Ref := Get (Refs, Synonym);
467 Delete (Refs, Synonym);
471 ("Function on line " & Lineno & " is for unknown synonym");
475 -- Alpha sort of references for this entry
478 Refa : VStringA (1 .. 100);
483 exit when not Match (Ref, Get_Nxtref, Nul);
488 Sort (Refa (1 .. N));
493 -- Checking references for one entry
498 if not Match (Line, Test_Syn) then
499 Put_Line ("Expecting N_" & Refa (M) & " at line " & Lineno);
503 Match (Next, Chop_Comma);
505 if Next /= Refa (M) then
506 Put_Line ("Expecting N_" & Refa (M) & " at line " & Lineno);
512 Match (Line, Return_Fld);
514 if Field /= Get (Fields, Synonym) then
516 ("Wrong field for function " & Synonym & " at line " &
517 Lineno & " should be " & Get (Fields, Synonym));
526 Put_Line ("Check for missing functions in body");
529 List : TV.Table_Array := Convert_To_Array (Refs);
532 if List'Length /= 0 then
533 Put_Line ("Missing function " & List (1).Name & " in body");
540 Put_Line ("Check Set procedures in body");
545 exit when Match (Line, "end");
546 exit when Match (Line, " -- Iterator Procedures");
548 if Match (Line, Set_Syn)
549 and then not Present (Special, Synonym)
551 Ref := Get (Refs, Synonym);
552 Delete (Refs, Synonym);
556 ("Function on line " & Lineno & " is for unknown synonym");
560 -- Alpha sort of references for this entry
563 Refa : VStringA (1 .. 100);
570 exit when not Match (Ref, Get_Nxtref, Nul);
575 Sort (Refa (1 .. N));
581 -- Checking references for one entry
586 if not Match (Line, Test_Syn)
587 or else Next /= Refa (M)
589 Put_Line ("Expecting N_" & Refa (M) & " at line " & Lineno);
596 exit when Match (Line, Set_Fld);
599 Match (Field, Break_With);
601 if Field /= Get (Fields, Synonym) then
603 ("Wrong field for procedure Set_" & Synonym &
604 " at line " & Lineno & " should be " &
605 Get (Fields, Synonym));
609 Delete (Fields1, Synonym);
616 Put_Line ("Check for missing set procedures in body");
619 List : TV.Table_Array := Convert_To_Array (Fields1);
622 if List'Length /= 0 then
623 Put_Line ("Missing procedure Set_" & List (1).Name & " in body");
630 Put_Line ("All tests completed successfully, no errors detected");