1 ------------------------------------------------------------------------------
3 -- GNAT SYSTEM UTILITIES --
9 -- Copyright (C) 1992-2001 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 -- Program to check consistency of sinfo.ads and sinfo.adb. Checks that
28 -- field name usage is consistent and that assertion cross-reference lists
29 -- are correct, as well as making sure that all the comments on field name
30 -- usage are consistent.
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
.Strings
.Maps
; use Ada
.Strings
.Maps
;
35 with Ada
.Strings
.Maps
.Constants
; use Ada
.Strings
.Maps
.Constants
;
36 with Ada
.Text_IO
; use Ada
.Text_IO
;
38 with GNAT
.Spitbol
; use GNAT
.Spitbol
;
39 with GNAT
.Spitbol
.Patterns
; use GNAT
.Spitbol
.Patterns
;
40 with GNAT
.Spitbol
.Table_Boolean
;
41 with GNAT
.Spitbol
.Table_VString
;
45 package TB
renames GNAT
.Spitbol
.Table_Boolean
;
46 package TV
renames GNAT
.Spitbol
.Table_VString
;
50 Lineno
: Natural := 0;
53 -- Raised on fatal error
56 -- Raised after error is found to terminate run
58 WSP
: Pattern
:= Span
(' ' & ASCII
.HT
);
60 Fields
: TV
.Table
(300);
61 Fields1
: TV
.Table
(300);
62 Refs
: TV
.Table
(300);
63 Refscopy
: TV
.Table
(300);
64 Special
: TB
.Table
(50);
65 Inlines
: TV
.Table
(100);
67 -- The following define the standard fields used for binary operator,
68 -- unary operator, and other expression nodes. Numbers in the range 1-5
69 -- refer to the Fieldn fields. Letters D-R refer to flags:
87 Flags
: TV
.Table
(20);
88 -- Maps flag numbers to letters
90 N_Fields
: Pattern
:= BreakX
("JL");
91 E_Fields
: Pattern
:= BreakX
("5EFGHIJLOP");
92 U_Fields
: Pattern
:= BreakX
("1345EFGHIJKLOPQ");
93 B_Fields
: Pattern
:= BreakX
("12345EFGHIJKLOPQ");
98 Field
: VString
:= Nul
;
99 Fields_Used
: VString
:= Nul
;
100 Name
: VString
:= Nul
;
101 Next
: VString
:= Nul
;
102 Node
: VString
:= Nul
;
103 Ref
: VString
:= Nul
;
104 Synonym
: VString
:= Nul
;
105 Nxtref
: VString
:= Nul
;
107 Which_Field
: aliased VString
:= Nul
;
109 Node_Search
: Pattern
:= WSP
& "-- N_" & Rest
* Node
;
110 Break_Punc
: Pattern
:= Break
(" .,");
111 Plus_Binary
: Pattern
:= WSP
& "-- plus fields for binary operator";
112 Plus_Unary
: Pattern
:= WSP
& "-- plus fields for unary operator";
113 Plus_Expr
: Pattern
:= WSP
& "-- plus fields for expression";
114 Break_Syn
: Pattern
:= WSP
& "-- " & Break
(' ') * Synonym
&
115 " (" & Break
(')') * Field
;
116 Break_Field
: Pattern
:= BreakX
('-') * Field
;
117 Get_Field
: Pattern
:= BreakX
(Decimal_Digit_Set
) &
118 Span
(Decimal_Digit_Set
) * Which_Field
;
119 Break_WFld
: Pattern
:= Break
(Which_Field
'Access);
120 Get_Funcsyn
: Pattern
:= WSP
& "function " & Rest
* Synonym
;
121 Extr_Field
: Pattern
:= BreakX
('-') & "-- " & Rest
* Field
;
122 Get_Procsyn
: Pattern
:= WSP
& "procedure Set_" & Rest
* Synonym
;
123 Get_Inline
: Pattern
:= WSP
& "pragma Inline (" & Break
(')') * Name
;
124 Set_Name
: Pattern
:= "Set_" & Rest
* Name
;
125 Func_Rest
: Pattern
:= " function " & Rest
* Synonym
;
126 Get_Nxtref
: Pattern
:= Break
(',') * Nxtref
& ',';
127 Test_Syn
: Pattern
:= Break
('=') & "= N_" &
128 (Break
(" ,)") or Rest
) * Next
;
129 Chop_Comma
: Pattern
:= BreakX
(',') * Next
;
130 Return_Fld
: Pattern
:= WSP
& "return " & Break
(' ') * Field
;
131 Set_Syn
: Pattern
:= " procedure Set_" & Rest
* Synonym
;
132 Set_Fld
: Pattern
:= WSP
& "Set_" & Break
(' ') * Field
& " (N, Val)";
133 Break_With
: Pattern
:= Break
('_') ** Field
& "_With_Parent";
135 type VStringA
is array (Natural range <>) of VString
;
138 -- Read next line trimmed from Infil into Line and bump Lineno
140 procedure Sort
(A
: in out VStringA
);
141 -- Sort a (small) array of VString's
143 procedure Next_Line
is
145 Line
:= Get_Line
(Infil
);
147 Lineno
:= Lineno
+ 1;
150 procedure Sort
(A
: in out VStringA
) is
155 for J
in 1 .. A
'Length - 1 loop
156 if A
(J
) > A
(J
+ 1) then
165 -- Start of processing for CSinfo
168 Anchored_Mode
:= True;
170 Open
(Infil
, In_File
, "sinfo.ads");
171 Put_Line
("Check for field name consistency");
173 -- Setup table for mapping flag numbers to letters
175 Set
(Flags
, "4", V
("D"));
176 Set
(Flags
, "5", V
("E"));
177 Set
(Flags
, "6", V
("F"));
178 Set
(Flags
, "7", V
("G"));
179 Set
(Flags
, "8", V
("H"));
180 Set
(Flags
, "9", V
("I"));
181 Set
(Flags
, "10", V
("J"));
182 Set
(Flags
, "11", V
("K"));
183 Set
(Flags
, "12", V
("L"));
184 Set
(Flags
, "13", V
("M"));
185 Set
(Flags
, "14", V
("N"));
186 Set
(Flags
, "15", V
("O"));
187 Set
(Flags
, "16", V
("P"));
188 Set
(Flags
, "17", V
("Q"));
189 Set
(Flags
, "18", V
("R"));
191 -- Special fields table. The following fields are not recorded or checked
192 -- by Csinfo, since they are specially handled. This means that he both
193 -- the field definitions, and the corresponding subprograms are ignored.
195 Set
(Special
, "Analyzed", True);
196 Set
(Special
, "Assignment_OK", True);
197 Set
(Special
, "Associated_Node", True);
198 Set
(Special
, "Cannot_Be_Constant", True);
199 Set
(Special
, "Chars", True);
200 Set
(Special
, "Comes_From_Source", True);
201 Set
(Special
, "Do_Overflow_Check", True);
202 Set
(Special
, "Do_Range_Check", True);
203 Set
(Special
, "Entity", True);
204 Set
(Special
, "Error_Posted", True);
205 Set
(Special
, "Etype", True);
206 Set
(Special
, "Evaluate_Once", True);
207 Set
(Special
, "First_Itype", True);
208 Set
(Special
, "Has_Dynamic_Itype", True);
209 Set
(Special
, "Has_Dynamic_Range_Check", True);
210 Set
(Special
, "Has_Dynamic_Length_Check", True);
211 Set
(Special
, "Has_Private_View", True);
212 Set
(Special
, "Is_Controlling_Actual", True);
213 Set
(Special
, "Is_Overloaded", True);
214 Set
(Special
, "Is_Static_Expression", True);
215 Set
(Special
, "Left_Opnd", True);
216 Set
(Special
, "Must_Not_Freeze", True);
217 Set
(Special
, "Parens", True);
218 Set
(Special
, "Raises_Constraint_Error", True);
219 Set
(Special
, "Right_Opnd", True);
221 -- Loop to acquire information from node definitions in sinfo.ads,
222 -- checking for consistency in Op/Flag assignments to each synonym
227 exit when Match
(Line
, " -- Node Access Functions");
229 if Match
(Line
, Node_Search
)
230 and then not Match
(Node
, Break_Punc
)
240 elsif Match
(Line
, Plus_Binary
) then
241 Bad
:= Match
(Fields_Used
, B_Fields
);
243 elsif Match
(Line
, Plus_Unary
) then
244 Bad
:= Match
(Fields_Used
, U_Fields
);
246 elsif Match
(Line
, Plus_Expr
) then
247 Bad
:= Match
(Fields_Used
, E_Fields
);
249 elsif not Match
(Line
, Break_Syn
) then
252 elsif Match
(Synonym
, "plus") then
256 Match
(Field
, Break_Field
);
258 if not Present
(Special
, Synonym
) then
260 if Present
(Fields
, Synonym
) then
261 if Field
/= Get
(Fields
, Synonym
) then
263 ("Inconsistent field reference at line" &
264 Lineno
'Img & " for " & Synonym
);
269 Set
(Fields
, Synonym
, Field
);
272 Set
(Refs
, Synonym
, Node
& ',' & Get
(Refs
, Synonym
));
273 Match
(Field
, Get_Field
);
275 if Match
(Field
, "Flag") then
276 Which_Field
:= Get
(Flags
, Which_Field
);
279 if Match
(Fields_Used
, Break_WFld
) then
281 ("Overlapping field at line " & Lineno
'Img &
286 Append
(Fields_Used
, Which_Field
);
287 Bad
:= Bad
or Match
(Fields_Used
, N_Fields
);
292 Put_Line
("fields conflict with standard fields for node " & Node
);
298 Put_Line
("Check for function consistency");
300 -- Loop through field function definitions to make sure they are OK
305 exit when Match
(Line
, " -- Node Update");
307 if Match
(Line
, Get_Funcsyn
)
308 and then not Present
(Special
, Synonym
)
310 if not Present
(Fields1
, Synonym
) then
312 ("function on line " & Lineno
&
313 " is for unused synonym");
319 if not Match
(Line
, Extr_Field
) then
323 if Field
/= Get
(Fields1
, Synonym
) then
324 Put_Line
("Wrong field in function " & Synonym
);
328 Delete
(Fields1
, Synonym
);
335 Put_Line
("Check for missing functions");
338 List
: TV
.Table_Array
:= Convert_To_Array
(Fields1
);
341 if List
'Length > 0 then
342 Put_Line
("No function for field synonym " & List
(1).Name
);
347 -- Check field set procedures
351 Put_Line
("Check for set procedure consistency");
356 exit when Match
(Line
, " -- Inline Pragmas");
357 exit when Match
(Line
, " -- Iterator Procedures");
359 if Match
(Line
, Get_Procsyn
)
360 and then not Present
(Special
, Synonym
)
362 if not Present
(Fields1
, Synonym
) then
364 ("procedure on line " & Lineno
& " is for unused synonym");
370 if not Match
(Line
, Extr_Field
) then
374 if Field
/= Get
(Fields1
, Synonym
) then
375 Put_Line
("Wrong field in procedure Set_" & Synonym
);
379 Delete
(Fields1
, Synonym
);
386 Put_Line
("Check for missing set procedures");
389 List
: TV
.Table_Array
:= Convert_To_Array
(Fields1
);
392 if List
'Length > 0 then
393 Put_Line
("No procedure for field synonym Set_" & List
(1).Name
);
400 Put_Line
("Check pragma Inlines are all for existing subprograms");
403 while not End_Of_File
(Infil
) loop
406 if Match
(Line
, Get_Inline
)
407 and then not Present
(Special
, Name
)
409 exit when Match
(Name
, Set_Name
);
411 if not Present
(Fields
, Name
) then
413 ("Pragma Inline on line " & Lineno
&
414 " does not correspond to synonym");
418 Set
(Inlines
, Name
, Get
(Inlines
, Name
) & 'r');
425 Put_Line
("Check no pragma Inlines were omitted");
428 List
: TV
.Table_Array
:= Convert_To_Array
(Fields
);
429 Nxt
: VString
:= Nul
;
432 for M
in List
'Range loop
433 Nxt
:= List
(M
).Name
;
435 if Get
(Inlines
, Nxt
) /= "r" then
436 Put_Line
("Incorrect pragma Inlines for " & Nxt
);
447 Open
(Infil
, In_File
, "sinfo.adb");
449 Put_Line
("Check references in functions in body");
454 exit when Match
(Line
, " -- Field Access Functions --");
459 exit when Match
(Line
, " -- Field Set Procedures --");
461 if Match
(Line
, Func_Rest
)
462 and then not Present
(Special
, Synonym
)
464 Ref
:= Get
(Refs
, Synonym
);
465 Delete
(Refs
, Synonym
);
469 ("Function on line " & Lineno
& " is for unknown synonym");
473 -- Alpha sort of references for this entry
476 Refa
: VStringA
(1 .. 100);
481 exit when not Match
(Ref
, Get_Nxtref
, Nul
);
486 Sort
(Refa
(1 .. N
));
491 -- Checking references for one entry
496 if not Match
(Line
, Test_Syn
) then
497 Put_Line
("Expecting N_" & Refa
(M
) & " at line " & Lineno
);
501 Match
(Next
, Chop_Comma
);
503 if Next
/= Refa
(M
) then
504 Put_Line
("Expecting N_" & Refa
(M
) & " at line " & Lineno
);
510 Match
(Line
, Return_Fld
);
512 if Field
/= Get
(Fields
, Synonym
) then
514 ("Wrong field for function " & Synonym
& " at line " &
515 Lineno
& " should be " & Get
(Fields
, Synonym
));
524 Put_Line
("Check for missing functions in body");
527 List
: TV
.Table_Array
:= Convert_To_Array
(Refs
);
530 if List
'Length /= 0 then
531 Put_Line
("Missing function " & List
(1).Name
& " in body");
538 Put_Line
("Check Set procedures in body");
543 exit when Match
(Line
, "end");
544 exit when Match
(Line
, " -- Iterator Procedures");
546 if Match
(Line
, Set_Syn
)
547 and then not Present
(Special
, Synonym
)
549 Ref
:= Get
(Refs
, Synonym
);
550 Delete
(Refs
, Synonym
);
554 ("Function on line " & Lineno
& " is for unknown synonym");
558 -- Alpha sort of references for this entry
561 Refa
: VStringA
(1 .. 100);
568 exit when not Match
(Ref
, Get_Nxtref
, Nul
);
573 Sort
(Refa
(1 .. N
));
579 -- Checking references for one entry
584 if not Match
(Line
, Test_Syn
)
585 or else Next
/= Refa
(M
)
587 Put_Line
("Expecting N_" & Refa
(M
) & " at line " & Lineno
);
594 exit when Match
(Line
, Set_Fld
);
597 Match
(Field
, Break_With
);
599 if Field
/= Get
(Fields
, Synonym
) then
601 ("Wrong field for procedure Set_" & Synonym
&
602 " at line " & Lineno
& " should be " &
603 Get
(Fields
, Synonym
));
607 Delete
(Fields1
, Synonym
);
614 Put_Line
("Check for missing set procedures in body");
617 List
: TV
.Table_Array
:= Convert_To_Array
(Fields1
);
620 if List
'Length /= 0 then
621 Put_Line
("Missing procedure Set_" & List
(1).Name
& " in body");
628 Put_Line
("All tests completed successfully, no errors detected");