1 ------------------------------------------------------------------------------
3 -- GNAT SYSTEM UTILITIES --
9 -- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
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 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- Program to check consistency of sinfo.ads and sinfo.adb. Checks that field
27 -- name usage is consistent and that assertion cross-reference lists are
28 -- correct, as well as making sure that all the comments on field name usage
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.Strings.Maps; use Ada.Strings.Maps;
34 with Ada.Strings.Maps.Constants; use Ada.Strings.Maps.Constants;
35 with Ada.Text_IO; use Ada.Text_IO;
37 with GNAT.Spitbol; use GNAT.Spitbol;
38 with GNAT.Spitbol.Patterns; use GNAT.Spitbol.Patterns;
39 with GNAT.Spitbol.Table_Boolean;
40 with GNAT.Spitbol.Table_VString;
44 package TB renames GNAT.Spitbol.Table_Boolean;
45 package TV renames GNAT.Spitbol.Table_VString;
49 Lineno : Natural := 0;
52 -- Raised on fatal error
55 -- Raised after error is found to terminate run
57 WSP : constant Pattern := Span (' ' & ASCII.HT);
59 Fields : TV.Table (300);
60 Fields1 : TV.Table (300);
61 Refs : TV.Table (300);
62 Refscopy : TV.Table (300);
63 Special : TB.Table (50);
64 Inlines : TV.Table (100);
66 -- The following define the standard fields used for binary operator,
67 -- unary operator, and other expression nodes. Numbers in the range 1-5
68 -- refer to the Fieldn fields. Letters D-R refer to flags:
86 Flags : TV.Table (20);
87 -- Maps flag numbers to letters
89 N_Fields : constant Pattern := BreakX ("JL");
90 E_Fields : constant Pattern := BreakX ("5EFGHIJLOP");
91 U_Fields : constant Pattern := BreakX ("1345EFGHIJKLOPQ");
92 B_Fields : constant Pattern := BreakX ("12345EFGHIJKLOPQ");
97 Field : constant VString := Nul;
98 Fields_Used : VString := Nul;
99 Name : constant VString := Nul;
100 Next : constant VString := Nul;
101 Node : VString := Nul;
102 Ref : VString := Nul;
103 Synonym : constant VString := Nul;
104 Nxtref : constant VString := Nul;
106 Which_Field : aliased VString := Nul;
108 Node_Search : constant Pattern := WSP & "-- N_" & Rest * Node;
109 Break_Punc : constant Pattern := Break (" .,");
110 Plus_Binary : constant Pattern := WSP
111 & "-- plus fields for binary operator";
112 Plus_Unary : constant Pattern := WSP
113 & "-- plus fields for unary operator";
114 Plus_Expr : constant Pattern := WSP
115 & "-- plus fields for expression";
116 Break_Syn : constant Pattern := WSP & "-- "
117 & Break (' ') * Synonym
118 & " (" & Break (')') * Field;
119 Break_Field : constant Pattern := BreakX ('-') * Field;
120 Get_Field : constant Pattern := BreakX (Decimal_Digit_Set)
121 & Span (Decimal_Digit_Set) * Which_Field;
122 Break_WFld : constant Pattern := Break (Which_Field'Access);
123 Get_Funcsyn : constant Pattern := WSP & "function " & Rest * Synonym;
124 Extr_Field : constant Pattern := BreakX ('-') & "-- " & Rest * Field;
125 Get_Procsyn : constant Pattern := WSP & "procedure Set_" & Rest * Synonym;
126 Get_Inline : constant Pattern := WSP & "pragma Inline ("
127 & Break (')') * Name;
128 Set_Name : constant Pattern := "Set_" & Rest * Name;
129 Func_Rest : constant Pattern := " function " & Rest * Synonym;
130 Get_Nxtref : constant Pattern := Break (',') * Nxtref & ',';
131 Test_Syn : constant Pattern := Break ('=') & "= N_"
132 & (Break (" ,)") or Rest) * Next;
133 Chop_Comma : constant Pattern := BreakX (',') * Next;
134 Return_Fld : constant Pattern := WSP & "return " & Break (' ') * Field;
135 Set_Syn : constant Pattern := " procedure Set_" & Rest * Synonym;
136 Set_Fld : constant Pattern := WSP & "Set_" & Break (' ') * Field
138 Break_With : constant Pattern := Break ('_') ** Field & "_With_Parent";
140 type VStringA is array (Natural range <>) of VString;
143 -- Read next line trimmed from Infil into Line and bump Lineno
145 procedure Sort (A : in out VStringA);
146 -- Sort a (small) array of VString's
148 procedure Next_Line is
150 Line := Get_Line (Infil);
152 Lineno := Lineno + 1;
155 procedure Sort (A : in out VStringA) is
159 for J in 1 .. A'Length - 1 loop
160 if A (J) > A (J + 1) then
169 -- Start of processing for CSinfo
172 Anchored_Mode := True;
174 Open (Infil, In_File, "sinfo.ads");
175 Put_Line ("Check for field name consistency");
177 -- Setup table for mapping flag numbers to letters
179 Set (Flags, "4", V ("D"));
180 Set (Flags, "5", V ("E"));
181 Set (Flags, "6", V ("F"));
182 Set (Flags, "7", V ("G"));
183 Set (Flags, "8", V ("H"));
184 Set (Flags, "9", V ("I"));
185 Set (Flags, "10", V ("J"));
186 Set (Flags, "11", V ("K"));
187 Set (Flags, "12", V ("L"));
188 Set (Flags, "13", V ("M"));
189 Set (Flags, "14", V ("N"));
190 Set (Flags, "15", V ("O"));
191 Set (Flags, "16", V ("P"));
192 Set (Flags, "17", V ("Q"));
193 Set (Flags, "18", V ("R"));
195 -- Special fields table. The following names are not recorded or checked
196 -- by Csinfo, since they are specially handled. This means that any field
197 -- definition or subprogram with a matching name is ignored.
199 Set (Special, "Analyzed", True);
200 Set (Special, "Assignment_OK", True);
201 Set (Special, "Associated_Node", True);
202 Set (Special, "Cannot_Be_Constant", True);
203 Set (Special, "Chars", True);
204 Set (Special, "Comes_From_Source", True);
205 Set (Special, "Do_Overflow_Check", True);
206 Set (Special, "Do_Range_Check", True);
207 Set (Special, "Entity", True);
208 Set (Special, "Entity_Or_Associated_Node", True);
209 Set (Special, "Error_Posted", True);
210 Set (Special, "Etype", True);
211 Set (Special, "Evaluate_Once", True);
212 Set (Special, "First_Itype", True);
213 Set (Special, "Has_Dynamic_Itype", True);
214 Set (Special, "Has_Dynamic_Range_Check", True);
215 Set (Special, "Has_Dynamic_Length_Check", True);
216 Set (Special, "Has_Private_View", True);
217 Set (Special, "Is_Controlling_Actual", True);
218 Set (Special, "Is_Overloaded", True);
219 Set (Special, "Is_Static_Expression", True);
220 Set (Special, "Left_Opnd", True);
221 Set (Special, "Must_Not_Freeze", True);
222 Set (Special, "Nkind_In", True);
223 Set (Special, "Parens", True);
224 Set (Special, "Pragma_Name", True);
225 Set (Special, "Raises_Constraint_Error", True);
226 Set (Special, "Right_Opnd", True);
228 -- Loop to acquire information from node definitions in sinfo.ads,
229 -- checking for consistency in Op/Flag assignments to each synonym
234 exit when Match (Line, " -- Node Access Functions");
236 if Match (Line, Node_Search)
237 and then not Match (Node, Break_Punc)
247 elsif Match (Line, Plus_Binary) then
248 Bad := Match (Fields_Used, B_Fields);
250 elsif Match (Line, Plus_Unary) then
251 Bad := Match (Fields_Used, U_Fields);
253 elsif Match (Line, Plus_Expr) then
254 Bad := Match (Fields_Used, E_Fields);
256 elsif not Match (Line, Break_Syn) then
259 elsif Match (Synonym, "plus") then
263 Match (Field, Break_Field);
265 if not Present (Special, Synonym) then
266 if Present (Fields, Synonym) then
267 if Field /= Get (Fields, Synonym) then
269 ("Inconsistent field reference at line" &
270 Lineno'Img & " for " & Synonym);
275 Set (Fields, Synonym, Field);
278 Set (Refs, Synonym, Node & ',' & Get (Refs, Synonym));
279 Match (Field, Get_Field);
281 if Match (Field, "Flag") then
282 Which_Field := Get (Flags, Which_Field);
285 if Match (Fields_Used, Break_WFld) then
287 ("Overlapping field at line " & Lineno'Img &
292 Append (Fields_Used, Which_Field);
293 Bad := Bad or Match (Fields_Used, N_Fields);
298 Put_Line ("fields conflict with standard fields for node " & Node);
305 Put_Line ("Check for function consistency");
307 -- Loop through field function definitions to make sure they are OK
312 exit when Match (Line, " -- Node Update");
314 if Match (Line, Get_Funcsyn)
315 and then not Present (Special, Synonym)
317 if not Present (Fields1, Synonym) then
319 ("function on line " & Lineno &
320 " is for unused synonym");
326 if not Match (Line, Extr_Field) then
330 if Field /= Get (Fields1, Synonym) then
331 Put_Line ("Wrong field in function " & Synonym);
335 Delete (Fields1, Synonym);
342 Put_Line ("Check for missing functions");
345 List : constant TV.Table_Array := Convert_To_Array (Fields1);
348 if List'Length > 0 then
349 Put_Line ("No function for field synonym " & List (1).Name);
354 -- Check field set procedures
358 Put_Line ("Check for set procedure consistency");
363 exit when Match (Line, " -- Inline Pragmas");
364 exit when Match (Line, " -- Iterator Procedures");
366 if Match (Line, Get_Procsyn)
367 and then not Present (Special, Synonym)
369 if not Present (Fields1, Synonym) then
371 ("procedure on line " & Lineno & " is for unused synonym");
377 if not Match (Line, Extr_Field) then
381 if Field /= Get (Fields1, Synonym) then
382 Put_Line ("Wrong field in procedure Set_" & Synonym);
386 Delete (Fields1, Synonym);
393 Put_Line ("Check for missing set procedures");
396 List : constant TV.Table_Array := Convert_To_Array (Fields1);
399 if List'Length > 0 then
400 Put_Line ("No procedure for field synonym Set_" & List (1).Name);
407 Put_Line ("Check pragma Inlines are all for existing subprograms");
410 while not End_Of_File (Infil) loop
413 if Match (Line, Get_Inline)
414 and then not Present (Special, Name)
416 exit when Match (Name, Set_Name);
418 if not Present (Fields, Name) then
420 ("Pragma Inline on line " & Lineno &
421 " does not correspond to synonym");
425 Set (Inlines, Name, Get (Inlines, Name) & 'r');
432 Put_Line ("Check no pragma Inlines were omitted");
435 List : constant TV.Table_Array := Convert_To_Array (Fields);
436 Nxt : VString := Nul;
439 for M in List'Range loop
440 Nxt := List (M).Name;
442 if Get (Inlines, Nxt) /= "r" then
443 Put_Line ("Incorrect pragma Inlines for " & Nxt);
454 Open (Infil, In_File, "sinfo.adb");
456 Put_Line ("Check references in functions in body");
461 exit when Match (Line, " -- Field Access Functions --");
466 exit when Match (Line, " -- Field Set Procedures --");
468 if Match (Line, Func_Rest)
469 and then not Present (Special, Synonym)
471 Ref := Get (Refs, Synonym);
472 Delete (Refs, Synonym);
476 ("Function on line " & Lineno & " is for unknown synonym");
480 -- Alpha sort of references for this entry
483 Refa : VStringA (1 .. 100);
488 exit when not Match (Ref, Get_Nxtref, Nul);
493 Sort (Refa (1 .. N));
498 -- Checking references for one entry
503 if not Match (Line, Test_Syn) then
504 Put_Line ("Expecting N_" & Refa (M) & " at line " & Lineno);
508 Match (Next, Chop_Comma);
510 if Next /= Refa (M) then
511 Put_Line ("Expecting N_" & Refa (M) & " at line " & Lineno);
517 Match (Line, Return_Fld);
519 if Field /= Get (Fields, Synonym) then
521 ("Wrong field for function " & Synonym & " at line " &
522 Lineno & " should be " & Get (Fields, Synonym));
531 Put_Line ("Check for missing functions in body");
534 List : constant TV.Table_Array := Convert_To_Array (Refs);
537 if List'Length /= 0 then
538 Put_Line ("Missing function " & List (1).Name & " in body");
545 Put_Line ("Check Set procedures in body");
550 exit when Match (Line, "end");
551 exit when Match (Line, " -- Iterator Procedures");
553 if Match (Line, Set_Syn)
554 and then not Present (Special, Synonym)
556 Ref := Get (Refs, Synonym);
557 Delete (Refs, Synonym);
561 ("Function on line " & Lineno & " is for unknown synonym");
565 -- Alpha sort of references for this entry
568 Refa : VStringA (1 .. 100);
575 exit when not Match (Ref, Get_Nxtref, Nul);
580 Sort (Refa (1 .. N));
586 -- Checking references for one entry
591 if not Match (Line, Test_Syn)
592 or else Next /= Refa (M)
594 Put_Line ("Expecting N_" & Refa (M) & " at line " & Lineno);
601 exit when Match (Line, Set_Fld);
604 Match (Field, Break_With);
606 if Field /= Get (Fields, Synonym) then
608 ("Wrong field for procedure Set_" & Synonym &
609 " at line " & Lineno & " should be " &
610 Get (Fields, Synonym));
614 Delete (Fields1, Synonym);
621 Put_Line ("Check for missing set procedures in body");
624 List : constant TV.Table_Array := Convert_To_Array (Fields1);
627 if List'Length /= 0 then
628 Put_Line ("Missing procedure Set_" & List (1).Name & " in body");
635 Put_Line ("All tests completed successfully, no errors detected");