1 ------------------------------------------------------------------------------
3 -- GNAT SYSTEM UTILITIES --
9 -- Copyright (C) 1992-2008, 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
27 -- field name usage is consistent and that assertion cross-reference lists
28 -- are correct, as well as making sure that all the comments on field name
29 -- usage are consistent.
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
);
304 Put_Line
("Check for function consistency");
306 -- Loop through field function definitions to make sure they are OK
311 exit when Match
(Line
, " -- Node Update");
313 if Match
(Line
, Get_Funcsyn
)
314 and then not Present
(Special
, Synonym
)
316 if not Present
(Fields1
, Synonym
) then
318 ("function on line " & Lineno
&
319 " is for unused synonym");
325 if not Match
(Line
, Extr_Field
) then
329 if Field
/= Get
(Fields1
, Synonym
) then
330 Put_Line
("Wrong field in function " & Synonym
);
334 Delete
(Fields1
, Synonym
);
341 Put_Line
("Check for missing functions");
344 List
: constant TV
.Table_Array
:= Convert_To_Array
(Fields1
);
347 if List
'Length > 0 then
348 Put_Line
("No function for field synonym " & List
(1).Name
);
353 -- Check field set procedures
357 Put_Line
("Check for set procedure consistency");
362 exit when Match
(Line
, " -- Inline Pragmas");
363 exit when Match
(Line
, " -- Iterator Procedures");
365 if Match
(Line
, Get_Procsyn
)
366 and then not Present
(Special
, Synonym
)
368 if not Present
(Fields1
, Synonym
) then
370 ("procedure on line " & Lineno
& " is for unused synonym");
376 if not Match
(Line
, Extr_Field
) then
380 if Field
/= Get
(Fields1
, Synonym
) then
381 Put_Line
("Wrong field in procedure Set_" & Synonym
);
385 Delete
(Fields1
, Synonym
);
392 Put_Line
("Check for missing set procedures");
395 List
: constant TV
.Table_Array
:= Convert_To_Array
(Fields1
);
398 if List
'Length > 0 then
399 Put_Line
("No procedure for field synonym Set_" & List
(1).Name
);
406 Put_Line
("Check pragma Inlines are all for existing subprograms");
409 while not End_Of_File
(Infil
) loop
412 if Match
(Line
, Get_Inline
)
413 and then not Present
(Special
, Name
)
415 exit when Match
(Name
, Set_Name
);
417 if not Present
(Fields
, Name
) then
419 ("Pragma Inline on line " & Lineno
&
420 " does not correspond to synonym");
424 Set
(Inlines
, Name
, Get
(Inlines
, Name
) & 'r');
431 Put_Line
("Check no pragma Inlines were omitted");
434 List
: constant TV
.Table_Array
:= Convert_To_Array
(Fields
);
435 Nxt
: VString
:= Nul
;
438 for M
in List
'Range loop
439 Nxt
:= List
(M
).Name
;
441 if Get
(Inlines
, Nxt
) /= "r" then
442 Put_Line
("Incorrect pragma Inlines for " & Nxt
);
453 Open
(Infil
, In_File
, "sinfo.adb");
455 Put_Line
("Check references in functions in body");
460 exit when Match
(Line
, " -- Field Access Functions --");
465 exit when Match
(Line
, " -- Field Set Procedures --");
467 if Match
(Line
, Func_Rest
)
468 and then not Present
(Special
, Synonym
)
470 Ref
:= Get
(Refs
, Synonym
);
471 Delete
(Refs
, Synonym
);
475 ("Function on line " & Lineno
& " is for unknown synonym");
479 -- Alpha sort of references for this entry
482 Refa
: VStringA
(1 .. 100);
487 exit when not Match
(Ref
, Get_Nxtref
, Nul
);
492 Sort
(Refa
(1 .. N
));
497 -- Checking references for one entry
502 if not Match
(Line
, Test_Syn
) then
503 Put_Line
("Expecting N_" & Refa
(M
) & " at line " & Lineno
);
507 Match
(Next
, Chop_Comma
);
509 if Next
/= Refa
(M
) then
510 Put_Line
("Expecting N_" & Refa
(M
) & " at line " & Lineno
);
516 Match
(Line
, Return_Fld
);
518 if Field
/= Get
(Fields
, Synonym
) then
520 ("Wrong field for function " & Synonym
& " at line " &
521 Lineno
& " should be " & Get
(Fields
, Synonym
));
530 Put_Line
("Check for missing functions in body");
533 List
: constant TV
.Table_Array
:= Convert_To_Array
(Refs
);
536 if List
'Length /= 0 then
537 Put_Line
("Missing function " & List
(1).Name
& " in body");
544 Put_Line
("Check Set procedures in body");
549 exit when Match
(Line
, "end");
550 exit when Match
(Line
, " -- Iterator Procedures");
552 if Match
(Line
, Set_Syn
)
553 and then not Present
(Special
, Synonym
)
555 Ref
:= Get
(Refs
, Synonym
);
556 Delete
(Refs
, Synonym
);
560 ("Function on line " & Lineno
& " is for unknown synonym");
564 -- Alpha sort of references for this entry
567 Refa
: VStringA
(1 .. 100);
574 exit when not Match
(Ref
, Get_Nxtref
, Nul
);
579 Sort
(Refa
(1 .. N
));
585 -- Checking references for one entry
590 if not Match
(Line
, Test_Syn
)
591 or else Next
/= Refa
(M
)
593 Put_Line
("Expecting N_" & Refa
(M
) & " at line " & Lineno
);
600 exit when Match
(Line
, Set_Fld
);
603 Match
(Field
, Break_With
);
605 if Field
/= Get
(Fields
, Synonym
) then
607 ("Wrong field for procedure Set_" & Synonym
&
608 " at line " & Lineno
& " should be " &
609 Get
(Fields
, Synonym
));
613 Delete
(Fields1
, Synonym
);
620 Put_Line
("Check for missing set procedures in body");
623 List
: constant TV
.Table_Array
:= Convert_To_Array
(Fields1
);
626 if List
'Length /= 0 then
627 Put_Line
("Missing procedure Set_" & List
(1).Name
& " in body");
634 Put_Line
("All tests completed successfully, no errors detected");