1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2020, 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 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Csets
; use Csets
;
29 with Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Elists
; use Elists
;
33 with Namet
; use Namet
;
34 with Nlists
; use Nlists
;
35 with Output
; use Output
;
36 with Sem_Mech
; use Sem_Mech
;
37 with Sinfo
; use Sinfo
;
38 with Snames
; use Snames
;
39 with Sinput
; use Sinput
;
40 with Stand
; use Stand
;
41 with Stringt
; use Stringt
;
42 with SCIL_LL
; use SCIL_LL
;
43 with Treeprs
; use Treeprs
;
44 with Uintp
; use Uintp
;
45 with Urealp
; use Urealp
;
46 with Uname
; use Uname
;
47 with Unchecked_Deallocation
;
49 package body Treepr
is
51 use Atree
.Unchecked_Access
;
52 -- This module uses the unchecked access functions in package Atree
53 -- since it does an untyped traversal of the tree (we do not want to
54 -- count on the structure of the tree being correct in this routine).
56 ----------------------------------
57 -- Approach Used for Tree Print --
58 ----------------------------------
60 -- When a complete subtree is being printed, a trace phase first marks
61 -- the nodes and lists to be printed. This trace phase allocates logical
62 -- numbers corresponding to the order in which the nodes and lists will
63 -- be printed. The Node_Id, List_Id and Elist_Id values are mapped to
64 -- logical node numbers using a hash table. Output is done using a set
65 -- of Print_xxx routines, which are similar to the Write_xxx routines
66 -- with the same name, except that they do not generate any output in
67 -- the marking phase. This allows identical logic to be used in the
70 -- Note that the hash table not only holds the serial numbers, but also
71 -- acts as a record of which nodes have already been visited. In the
72 -- marking phase, a node has been visited if it is already in the hash
73 -- table, and in the printing phase, we can tell whether a node has
74 -- already been printed by looking at the value of the serial number.
76 ----------------------
77 -- Global Variables --
78 ----------------------
80 type Hash_Record
is record
82 -- Serial number for hash table entry. A value of zero means that
83 -- the entry is currently unused.
86 -- If serial number field is non-zero, contains corresponding Id value
89 type Hash_Table_Type
is array (Nat
range <>) of Hash_Record
;
90 type Access_Hash_Table_Type
is access Hash_Table_Type
;
91 Hash_Table
: Access_Hash_Table_Type
;
92 -- The hash table itself, see Serial_Number function for details of use
95 -- Range of Hash_Table is from 0 .. Hash_Table_Len - 1 so that dividing
96 -- by Hash_Table_Len gives a remainder that is in Hash_Table'Range.
98 Next_Serial_Number
: Nat
;
99 -- Number of last visited node or list. Used during the marking phase to
100 -- set proper node numbers in the hash table, and during the printing
101 -- phase to make sure that a given node is not printed more than once.
102 -- (nodes are printed in order during the printing phase, that's the
103 -- point of numbering them in the first place).
105 Printing_Descendants
: Boolean;
106 -- True if descendants are being printed, False if not. In the false case,
107 -- only node Id's are printed. In the true case, node numbers as well as
108 -- node Id's are printed, as described above.
110 type Phase_Type
is (Marking
, Printing
);
111 -- Type for Phase variable
114 -- When an entire tree is being printed, the traversal operates in two
115 -- phases. The first phase marks the nodes in use by installing node
116 -- numbers in the node number table. The second phase prints the nodes.
117 -- This variable indicates the current phase.
119 ----------------------
120 -- Local Procedures --
121 ----------------------
123 procedure Print_End_Span
(N
: Node_Id
);
124 -- Special routine to print contents of End_Span field of node N.
125 -- The format includes the implicit source location as well as the
126 -- value of the field.
128 procedure Print_Init
;
129 -- Initialize for printing of tree with descendants
131 procedure Print_Term
;
132 -- Clean up after printing of tree with descendants
134 procedure Print_Char
(C
: Character);
135 -- Print character C if currently in print phase, noop if in marking phase
137 procedure Print_Name
(N
: Name_Id
);
138 -- Print name from names table if currently in print phase, noop if in
139 -- marking phase. Note that the name is output in mixed case mode.
141 procedure Print_Node_Header
(N
: Node_Id
);
142 -- Print header line used by Print_Node and Print_Node_Briefly
144 procedure Print_Node_Kind
(N
: Node_Id
);
145 -- Print node kind name in mixed case if in print phase, noop if in
148 procedure Print_Str
(S
: String);
149 -- Print string S if currently in print phase, noop if in marking phase
151 procedure Print_Str_Mixed_Case
(S
: String);
152 -- Like Print_Str, except that the string is printed in mixed case mode
154 procedure Print_Int
(I
: Int
);
155 -- Print integer I if currently in print phase, noop if in marking phase
158 -- Print end of line if currently in print phase, noop if in marking phase
160 procedure Print_Node_Ref
(N
: Node_Id
);
161 -- Print "<empty>", "<error>" or "Node #nnn" with additional information
162 -- in the latter case, including the Id and the Nkind of the node.
164 procedure Print_List_Ref
(L
: List_Id
);
165 -- Print "<no list>", or "<empty node list>" or "Node list #nnn"
167 procedure Print_Elist_Ref
(E
: Elist_Id
);
168 -- Print "<no elist>", or "<empty element list>" or "Element list #nnn"
170 procedure Print_Entity_Info
(Ent
: Entity_Id
; Prefix
: String);
171 -- Called if the node being printed is an entity. Prints fields from the
172 -- extension, using routines in Einfo to get the field names and flags.
174 procedure Print_Field
(Val
: Union_Id
; Format
: UI_Format
:= Auto
);
175 -- Print representation of Field value (name, tree, string, uint, charcode)
176 -- The format parameter controls the format of printing in the case of an
177 -- integer value (see UI_Write for details).
179 procedure Print_Flag
(F
: Boolean);
180 -- Print True or False
185 Prefix_Char
: Character);
186 -- This is the internal routine used to print a single node. Each line of
187 -- output is preceded by Prefix_Str (which is used to set the indentation
188 -- level and the bars used to link list elements). In addition, for lines
189 -- other than the first, an additional character Prefix_Char is output.
191 function Serial_Number
(Id
: Int
) return Nat
;
192 -- Given a Node_Id, List_Id or Elist_Id, returns the previously assigned
193 -- serial number, or zero if no serial number has yet been assigned.
195 procedure Set_Serial_Number
;
196 -- Can be called only immediately following a call to Serial_Number that
197 -- returned a value of zero. Causes the value of Next_Serial_Number to be
198 -- placed in the hash table (corresponding to the Id argument used in the
199 -- Serial_Number call), and increments Next_Serial_Number.
204 Prefix_Char
: Character);
205 -- Called to process a single node in the case where descendants are to
206 -- be printed before every line, and Prefix_Char added to all lines
207 -- except the header line for the node.
209 procedure Visit_List
(L
: List_Id
; Prefix_Str
: String);
210 -- Visit_List is called to process a list in the case where descendants
211 -- are to be printed. Prefix_Str is to be added to all printed lines.
213 procedure Visit_Elist
(E
: Elist_Id
; Prefix_Str
: String);
214 -- Visit_Elist is called to process an element list in the case where
215 -- descendants are to be printed. Prefix_Str is to be added to all
222 function p
(N
: Union_Id
) return Node_Or_Entity_Id
is
225 when List_Low_Bound
.. List_High_Bound
- 1 =>
226 return Nlists
.Parent
(List_Id
(N
));
229 return Atree
.Parent
(Node_Or_Entity_Id
(N
));
233 Write_Str
(" is not a Node_Id or List_Id value");
243 function par
(N
: Union_Id
) return Node_Or_Entity_Id
renames p
;
245 procedure ppar
(N
: Union_Id
) is
247 if N
/= Empty_List_Or_Node
then
249 ppar
(Union_Id
(p
(N
)));
257 procedure pe
(N
: Union_Id
) renames pn
;
263 procedure pl
(L
: Int
) is
273 -- This is the case where we transform e.g. +36 to -99999936
277 Lid
:= -(99999990 + L
);
279 Lid
:= -(99999900 + L
);
281 Lid
:= -(99999000 + L
);
283 Lid
:= -(99990000 + L
);
284 elsif L
<= 99999 then
285 Lid
:= -(99900000 + L
);
286 elsif L
<= 999999 then
287 Lid
:= -(99000000 + L
);
288 elsif L
<= 9999999 then
289 Lid
:= -(90000000 + L
);
295 -- Now output the list
297 Print_Tree_List
(List_Id
(Lid
));
305 procedure pn
(N
: Union_Id
) is
311 when List_Low_Bound
.. List_High_Bound
- 1 =>
314 Print_Tree_Node
(Node_Id
(N
));
316 Print_Tree_Elist
(Elist_Id
(N
));
319 Id
: constant Elmt_Id
:= Elmt_Id
(N
);
322 Write_Str
("No_Elmt");
325 Write_Str
("Elmt_Id --> ");
326 Print_Tree_Node
(Node
(Id
));
330 Namet
.wn
(Name_Id
(N
));
331 when Strings_Range
=>
332 Write_String_Table_Entry
(String_Id
(N
));
334 Uintp
.pid
(From_Union
(N
));
336 Urealp
.pr
(From_Union
(N
));
338 Write_Str
("Invalid Union_Id: ");
350 procedure pp
(N
: Union_Id
) renames pn
;
356 procedure ppp
(N
: Union_Id
) renames pt
;
362 procedure Print_Char
(C
: Character) is
364 if Phase
= Printing
then
369 ---------------------
370 -- Print_Elist_Ref --
371 ---------------------
373 procedure Print_Elist_Ref
(E
: Elist_Id
) is
375 if Phase
/= Printing
then
380 Write_Str
("<no elist>");
382 elsif Is_Empty_Elmt_List
(E
) then
383 Write_Str
("Empty elist, (Elist_Id=");
388 Write_Str
("(Elist_Id=");
392 if Printing_Descendants
then
394 Write_Int
(Serial_Number
(Int
(E
)));
399 -------------------------
400 -- Print_Elist_Subtree --
401 -------------------------
403 procedure Print_Elist_Subtree
(E
: Elist_Id
) is
407 Next_Serial_Number
:= 1;
411 Next_Serial_Number
:= 1;
416 end Print_Elist_Subtree
;
422 procedure Print_End_Span
(N
: Node_Id
) is
423 Val
: constant Uint
:= End_Span
(N
);
427 Write_Str
(" (Uint = ");
428 Write_Int
(Int
(Field5
(N
)));
431 if Val
/= No_Uint
then
432 Write_Location
(End_Location
(N
));
436 -----------------------
437 -- Print_Entity_Info --
438 -----------------------
440 procedure Print_Entity_Info
(Ent
: Entity_Id
; Prefix
: String) is
441 function Field_Present
(U
: Union_Id
) return Boolean;
442 -- Returns False unless the value U represents a missing value
443 -- (Empty, No_Elist, No_Uint, No_Ureal or No_String)
445 function Field_Present
(U
: Union_Id
) return Boolean is
448 U
/= Union_Id
(Empty
) and then
449 U
/= Union_Id
(No_Elist
) and then
450 U
/= To_Union
(No_Uint
) and then
451 U
/= To_Union
(No_Ureal
) and then
452 U
/= Union_Id
(No_String
);
455 -- Start of processing for Print_Entity_Info
459 Print_Str
("Ekind = ");
460 Print_Str_Mixed_Case
(Entity_Kind
'Image (Ekind
(Ent
)));
464 Print_Str
("Etype = ");
465 Print_Node_Ref
(Etype
(Ent
));
468 if Convention
(Ent
) /= Convention_Ada
then
470 Print_Str
("Convention = ");
472 -- Print convention name skipping the Convention_ at the start
475 S
: constant String := Convention_Id
'Image (Convention
(Ent
));
478 Print_Str_Mixed_Case
(S
(12 .. S
'Last));
483 if Field_Present
(Field6
(Ent
)) then
485 Write_Field6_Name
(Ent
);
487 Print_Field
(Field6
(Ent
));
491 if Field_Present
(Field7
(Ent
)) then
493 Write_Field7_Name
(Ent
);
495 Print_Field
(Field7
(Ent
));
499 if Field_Present
(Field8
(Ent
)) then
501 Write_Field8_Name
(Ent
);
503 Print_Field
(Field8
(Ent
));
507 if Field_Present
(Field9
(Ent
)) then
509 Write_Field9_Name
(Ent
);
511 Print_Field
(Field9
(Ent
));
515 if Field_Present
(Field10
(Ent
)) then
517 Write_Field10_Name
(Ent
);
519 Print_Field
(Field10
(Ent
));
523 if Field_Present
(Field11
(Ent
)) then
525 Write_Field11_Name
(Ent
);
527 Print_Field
(Field11
(Ent
));
531 if Field_Present
(Field12
(Ent
)) then
533 Write_Field12_Name
(Ent
);
535 Print_Field
(Field12
(Ent
));
539 if Field_Present
(Field13
(Ent
)) then
541 Write_Field13_Name
(Ent
);
543 Print_Field
(Field13
(Ent
));
547 if Field_Present
(Field14
(Ent
)) then
549 Write_Field14_Name
(Ent
);
551 Print_Field
(Field14
(Ent
));
555 if Field_Present
(Field15
(Ent
)) then
557 Write_Field15_Name
(Ent
);
559 Print_Field
(Field15
(Ent
));
563 if Field_Present
(Field16
(Ent
)) then
565 Write_Field16_Name
(Ent
);
567 Print_Field
(Field16
(Ent
));
571 if Field_Present
(Field17
(Ent
)) then
573 Write_Field17_Name
(Ent
);
575 Print_Field
(Field17
(Ent
));
579 if Field_Present
(Field18
(Ent
)) then
581 Write_Field18_Name
(Ent
);
583 Print_Field
(Field18
(Ent
));
587 if Field_Present
(Field19
(Ent
)) then
589 Write_Field19_Name
(Ent
);
591 Print_Field
(Field19
(Ent
));
595 if Field_Present
(Field20
(Ent
)) then
597 Write_Field20_Name
(Ent
);
599 Print_Field
(Field20
(Ent
));
603 if Field_Present
(Field21
(Ent
)) then
605 Write_Field21_Name
(Ent
);
607 Print_Field
(Field21
(Ent
));
611 if Field_Present
(Field22
(Ent
)) then
613 Write_Field22_Name
(Ent
);
616 -- Mechanism case has to be handled specially
618 if Ekind
(Ent
) = E_Function
or else Is_Formal
(Ent
) then
620 M
: constant Mechanism_Type
:= Mechanism
(Ent
);
624 when Default_Mechanism
=>
625 Write_Str
("Default");
628 Write_Str
("By_Copy");
631 Write_Str
("By_Reference");
633 when 1 .. Mechanism_Type
'Last =>
634 Write_Str
("By_Copy if size <= ");
639 -- Normal case (not Mechanism)
642 Print_Field
(Field22
(Ent
));
648 if Field_Present
(Field23
(Ent
)) then
650 Write_Field23_Name
(Ent
);
652 Print_Field
(Field23
(Ent
));
656 if Field_Present
(Field24
(Ent
)) then
658 Write_Field24_Name
(Ent
);
660 Print_Field
(Field24
(Ent
));
664 if Field_Present
(Field25
(Ent
)) then
666 Write_Field25_Name
(Ent
);
668 Print_Field
(Field25
(Ent
));
672 if Field_Present
(Field26
(Ent
)) then
674 Write_Field26_Name
(Ent
);
676 Print_Field
(Field26
(Ent
));
680 if Field_Present
(Field27
(Ent
)) then
682 Write_Field27_Name
(Ent
);
684 Print_Field
(Field27
(Ent
));
688 if Field_Present
(Field28
(Ent
)) then
690 Write_Field28_Name
(Ent
);
692 Print_Field
(Field28
(Ent
));
696 if Field_Present
(Field29
(Ent
)) then
698 Write_Field29_Name
(Ent
);
700 Print_Field
(Field29
(Ent
));
704 if Field_Present
(Field30
(Ent
)) then
706 Write_Field30_Name
(Ent
);
708 Print_Field
(Field30
(Ent
));
712 if Field_Present
(Field31
(Ent
)) then
714 Write_Field31_Name
(Ent
);
716 Print_Field
(Field31
(Ent
));
720 if Field_Present
(Field32
(Ent
)) then
722 Write_Field32_Name
(Ent
);
724 Print_Field
(Field32
(Ent
));
728 if Field_Present
(Field33
(Ent
)) then
730 Write_Field33_Name
(Ent
);
732 Print_Field
(Field33
(Ent
));
736 if Field_Present
(Field34
(Ent
)) then
738 Write_Field34_Name
(Ent
);
740 Print_Field
(Field34
(Ent
));
744 if Field_Present
(Field35
(Ent
)) then
746 Write_Field35_Name
(Ent
);
748 Print_Field
(Field35
(Ent
));
752 if Field_Present
(Field36
(Ent
)) then
754 Write_Field36_Name
(Ent
);
756 Print_Field
(Field36
(Ent
));
760 if Field_Present
(Field37
(Ent
)) then
762 Write_Field37_Name
(Ent
);
764 Print_Field
(Field37
(Ent
));
768 if Field_Present
(Field38
(Ent
)) then
770 Write_Field38_Name
(Ent
);
772 Print_Field
(Field38
(Ent
));
776 if Field_Present
(Field39
(Ent
)) then
778 Write_Field39_Name
(Ent
);
780 Print_Field
(Field39
(Ent
));
784 if Field_Present
(Field40
(Ent
)) then
786 Write_Field40_Name
(Ent
);
788 Print_Field
(Field40
(Ent
));
792 if Field_Present
(Field41
(Ent
)) then
794 Write_Field41_Name
(Ent
);
796 Print_Field
(Field41
(Ent
));
800 Write_Entity_Flags
(Ent
, Prefix
);
801 end Print_Entity_Info
;
807 procedure Print_Eol
is
809 if Phase
= Printing
then
818 procedure Print_Field
(Val
: Union_Id
; Format
: UI_Format
:= Auto
) is
820 if Phase
/= Printing
then
824 if Val
in Node_Range
then
825 Print_Node_Ref
(Node_Id
(Val
));
827 elsif Val
in List_Range
then
828 Print_List_Ref
(List_Id
(Val
));
830 elsif Val
in Elist_Range
then
831 Print_Elist_Ref
(Elist_Id
(Val
));
833 elsif Val
in Names_Range
then
834 Print_Name
(Name_Id
(Val
));
835 Write_Str
(" (Name_Id=");
836 Write_Int
(Int
(Val
));
839 elsif Val
in Strings_Range
then
840 Write_String_Table_Entry
(String_Id
(Val
));
841 Write_Str
(" (String_Id=");
842 Write_Int
(Int
(Val
));
845 elsif Val
in Uint_Range
then
846 UI_Write
(From_Union
(Val
), Format
);
847 Write_Str
(" (Uint = ");
848 Write_Int
(Int
(Val
));
851 elsif Val
in Ureal_Range
then
852 UR_Write
(From_Union
(Val
));
853 Write_Str
(" (Ureal = ");
854 Write_Int
(Int
(Val
));
858 Print_Str
("****** Incorrect value = ");
859 Print_Int
(Int
(Val
));
867 procedure Print_Flag
(F
: Boolean) is
880 procedure Print_Init
is
881 Max_Hash_Entries
: constant Nat
:=
882 Approx_Num_Nodes_And_Entities
+ Num_Lists
+ Num_Elists
;
884 Printing_Descendants
:= True;
887 -- Allocate and clear serial number hash table. The size is 150% of
888 -- the maximum possible number of entries, so that the hash table
889 -- cannot get significantly overloaded.
891 Hash_Table_Len
:= (150 * Max_Hash_Entries
) / 100;
892 Hash_Table
:= new Hash_Table_Type
(0 .. Hash_Table_Len
- 1);
894 for J
in Hash_Table
'Range loop
895 Hash_Table
(J
).Serial
:= 0;
904 procedure Print_Int
(I
: Int
) is
906 if Phase
= Printing
then
915 procedure Print_List_Ref
(L
: List_Id
) is
917 if Phase
/= Printing
then
922 Write_Str
("<no list>");
924 elsif Is_Empty_List
(L
) then
925 Write_Str
("<empty list> (List_Id=");
932 if Printing_Descendants
then
934 Write_Int
(Serial_Number
(Int
(L
)));
937 Write_Str
(" (List_Id=");
943 ------------------------
944 -- Print_List_Subtree --
945 ------------------------
947 procedure Print_List_Subtree
(L
: List_Id
) is
951 Next_Serial_Number
:= 1;
955 Next_Serial_Number
:= 1;
960 end Print_List_Subtree
;
966 procedure Print_Name
(N
: Name_Id
) is
968 if Phase
= Printing
then
970 Print_Str
("<No_Name>");
972 elsif N
= Error_Name
then
973 Print_Str
("<Error_Name>");
975 elsif Is_Valid_Name
(N
) then
982 Print_Str
("<invalid name ???>");
994 Prefix_Char
: Character)
999 Field_To_Be_Printed
: Boolean;
1000 Prefix_Str_Char
: String (Prefix_Str
'First .. Prefix_Str
'Last + 1);
1002 Sfile
: Source_File_Index
;
1006 if Phase
/= Printing
then
1010 -- If there is no such node, indicate that. Skip the rest, so we don't
1011 -- crash getting fields of the nonexistent node.
1013 if N
> Atree_Private_Part
.Nodes
.Last
then
1014 Print_Str
("No such node: ");
1015 Print_Int
(Int
(N
));
1020 -- Similarly, if N points to an extension, avoid crashing
1022 if Atree_Private_Part
.Nodes
.Table
(N
).Is_Extension
then
1023 Print_Int
(Int
(N
));
1024 Print_Str
(" is an extension, not a node");
1029 Prefix_Str_Char
(Prefix_Str
'Range) := Prefix_Str
;
1030 Prefix_Str_Char
(Prefix_Str
'Last + 1) := Prefix_Char
;
1032 -- Print header line
1034 Print_Str
(Prefix_Str
);
1035 Print_Node_Header
(N
);
1037 if Is_Rewrite_Substitution
(N
) then
1038 Print_Str
(Prefix_Str
);
1039 Print_Str
(" Rewritten: original node = ");
1040 Print_Node_Ref
(Original_Node
(N
));
1048 if not Is_List_Member
(N
) then
1049 Print_Str
(Prefix_Str
);
1050 Print_Str
(" Parent = ");
1051 Print_Node_Ref
(Parent
(N
));
1055 -- Print Sloc field if it is set
1057 if Sloc
(N
) /= No_Location
then
1058 Print_Str
(Prefix_Str_Char
);
1059 Print_Str
("Sloc = ");
1061 if Sloc
(N
) = Standard_Location
then
1062 Print_Str
("Standard_Location");
1064 elsif Sloc
(N
) = Standard_ASCII_Location
then
1065 Print_Str
("Standard_ASCII_Location");
1068 Sfile
:= Get_Source_File_Index
(Sloc
(N
));
1069 Print_Int
(Int
(Sloc
(N
)) - Int
(Source_Text
(Sfile
)'First));
1071 Write_Location
(Sloc
(N
));
1077 -- Print Chars field if present
1079 if Nkind
(N
) in N_Has_Chars
and then Chars
(N
) /= No_Name
then
1080 Print_Str
(Prefix_Str_Char
);
1081 Print_Str
("Chars = ");
1082 Print_Name
(Chars
(N
));
1083 Write_Str
(" (Name_Id=");
1084 Write_Int
(Int
(Chars
(N
)));
1089 -- Special field print operations for non-entity nodes
1091 if Nkind
(N
) not in N_Entity
then
1093 -- Deal with Left_Opnd and Right_Opnd fields
1095 if Nkind
(N
) in N_Op
1096 or else Nkind
(N
) in N_Short_Circuit
1097 or else Nkind
(N
) in N_Membership_Test
1099 -- Print Left_Opnd if present
1101 if Nkind
(N
) not in N_Unary_Op
then
1102 Print_Str
(Prefix_Str_Char
);
1103 Print_Str
("Left_Opnd = ");
1104 Print_Node_Ref
(Left_Opnd
(N
));
1110 Print_Str
(Prefix_Str_Char
);
1111 Print_Str
("Right_Opnd = ");
1112 Print_Node_Ref
(Right_Opnd
(N
));
1116 -- Print Entity field if operator (other cases of Entity
1117 -- are in the table, so are handled in the normal circuit)
1119 if Nkind
(N
) in N_Op
and then Present
(Entity
(N
)) then
1120 Print_Str
(Prefix_Str_Char
);
1121 Print_Str
("Entity = ");
1122 Print_Node_Ref
(Entity
(N
));
1126 -- Print special fields if we have a subexpression
1128 if Nkind
(N
) in N_Subexpr
then
1130 if Assignment_OK
(N
) then
1131 Print_Str
(Prefix_Str_Char
);
1132 Print_Str
("Assignment_OK = True");
1136 if Do_Range_Check
(N
) then
1137 Print_Str
(Prefix_Str_Char
);
1138 Print_Str
("Do_Range_Check = True");
1142 if Has_Dynamic_Length_Check
(N
) then
1143 Print_Str
(Prefix_Str_Char
);
1144 Print_Str
("Has_Dynamic_Length_Check = True");
1148 if Has_Aspects
(N
) then
1149 Print_Str
(Prefix_Str_Char
);
1150 Print_Str
("Has_Aspects = True");
1154 if Is_Controlling_Actual
(N
) then
1155 Print_Str
(Prefix_Str_Char
);
1156 Print_Str
("Is_Controlling_Actual = True");
1160 if Is_Overloaded
(N
) then
1161 Print_Str
(Prefix_Str_Char
);
1162 Print_Str
("Is_Overloaded = True");
1166 if Is_Static_Expression
(N
) then
1167 Print_Str
(Prefix_Str_Char
);
1168 Print_Str
("Is_Static_Expression = True");
1172 if Must_Not_Freeze
(N
) then
1173 Print_Str
(Prefix_Str_Char
);
1174 Print_Str
("Must_Not_Freeze = True");
1178 if Paren_Count
(N
) /= 0 then
1179 Print_Str
(Prefix_Str_Char
);
1180 Print_Str
("Paren_Count = ");
1181 Print_Int
(Int
(Paren_Count
(N
)));
1185 if Raises_Constraint_Error
(N
) then
1186 Print_Str
(Prefix_Str_Char
);
1187 Print_Str
("Raises_Constraint_Error = True");
1193 -- Print Do_Overflow_Check field if present
1195 if Nkind
(N
) in N_Op
and then Do_Overflow_Check
(N
) then
1196 Print_Str
(Prefix_Str_Char
);
1197 Print_Str
("Do_Overflow_Check = True");
1201 -- Print Etype field if present (printing of this field for entities
1202 -- is handled by the Print_Entity_Info procedure).
1204 if Nkind
(N
) in N_Has_Etype
and then Present
(Etype
(N
)) then
1205 Print_Str
(Prefix_Str_Char
);
1206 Print_Str
("Etype = ");
1207 Print_Node_Ref
(Etype
(N
));
1212 -- Loop to print fields included in Pchars array
1214 P
:= Pchar_Pos
(Nkind
(N
));
1216 if Nkind
(N
) = N_Integer_Literal
and then Print_In_Hex
(N
) then
1222 while P
< Pchar_Pos
(Node_Kind
'Succ (Nkind
(N
))) loop
1226 -- Check for case of False flag, which we never print, or an Empty
1227 -- field, which is also never printed.
1231 Field_To_Be_Printed
:= Field1
(N
) /= Union_Id
(Empty
);
1234 Field_To_Be_Printed
:= Field2
(N
) /= Union_Id
(Empty
);
1237 Field_To_Be_Printed
:= Field3
(N
) /= Union_Id
(Empty
);
1240 Field_To_Be_Printed
:= Field4
(N
) /= Union_Id
(Empty
);
1243 Field_To_Be_Printed
:= Field5
(N
) /= Union_Id
(Empty
);
1245 when F_Flag1
=> Field_To_Be_Printed
:= Flag1
(N
);
1246 when F_Flag2
=> Field_To_Be_Printed
:= Flag2
(N
);
1247 when F_Flag3
=> Field_To_Be_Printed
:= Flag3
(N
);
1248 when F_Flag4
=> Field_To_Be_Printed
:= Flag4
(N
);
1249 when F_Flag5
=> Field_To_Be_Printed
:= Flag5
(N
);
1250 when F_Flag6
=> Field_To_Be_Printed
:= Flag6
(N
);
1251 when F_Flag7
=> Field_To_Be_Printed
:= Flag7
(N
);
1252 when F_Flag8
=> Field_To_Be_Printed
:= Flag8
(N
);
1253 when F_Flag9
=> Field_To_Be_Printed
:= Flag9
(N
);
1254 when F_Flag10
=> Field_To_Be_Printed
:= Flag10
(N
);
1255 when F_Flag11
=> Field_To_Be_Printed
:= Flag11
(N
);
1256 when F_Flag12
=> Field_To_Be_Printed
:= Flag12
(N
);
1257 when F_Flag13
=> Field_To_Be_Printed
:= Flag13
(N
);
1258 when F_Flag14
=> Field_To_Be_Printed
:= Flag14
(N
);
1259 when F_Flag15
=> Field_To_Be_Printed
:= Flag15
(N
);
1260 when F_Flag16
=> Field_To_Be_Printed
:= Flag16
(N
);
1261 when F_Flag17
=> Field_To_Be_Printed
:= Flag17
(N
);
1262 when F_Flag18
=> Field_To_Be_Printed
:= Flag18
(N
);
1265 -- Print field if it is to be printed
1267 if Field_To_Be_Printed
then
1268 Print_Str
(Prefix_Str_Char
);
1270 while P
< Pchar_Pos
(Node_Kind
'Succ (Nkind
(N
)))
1271 and then Pchars
(P
) not in Fchar
1273 Print_Char
(Pchars
(P
));
1280 when F_Field1
=> Print_Field
(Field1
(N
), Fmt
);
1281 when F_Field2
=> Print_Field
(Field2
(N
), Fmt
);
1282 when F_Field3
=> Print_Field
(Field3
(N
), Fmt
);
1283 when F_Field4
=> Print_Field
(Field4
(N
), Fmt
);
1285 -- Special case End_Span = Uint5
1288 if Nkind
(N
) in N_Case_Statement | N_If_Statement
then
1291 Print_Field
(Field5
(N
), Fmt
);
1294 when F_Flag1
=> Print_Flag
(Flag1
(N
));
1295 when F_Flag2
=> Print_Flag
(Flag2
(N
));
1296 when F_Flag3
=> Print_Flag
(Flag3
(N
));
1297 when F_Flag4
=> Print_Flag
(Flag4
(N
));
1298 when F_Flag5
=> Print_Flag
(Flag5
(N
));
1299 when F_Flag6
=> Print_Flag
(Flag6
(N
));
1300 when F_Flag7
=> Print_Flag
(Flag7
(N
));
1301 when F_Flag8
=> Print_Flag
(Flag8
(N
));
1302 when F_Flag9
=> Print_Flag
(Flag9
(N
));
1303 when F_Flag10
=> Print_Flag
(Flag10
(N
));
1304 when F_Flag11
=> Print_Flag
(Flag11
(N
));
1305 when F_Flag12
=> Print_Flag
(Flag12
(N
));
1306 when F_Flag13
=> Print_Flag
(Flag13
(N
));
1307 when F_Flag14
=> Print_Flag
(Flag14
(N
));
1308 when F_Flag15
=> Print_Flag
(Flag15
(N
));
1309 when F_Flag16
=> Print_Flag
(Flag16
(N
));
1310 when F_Flag17
=> Print_Flag
(Flag17
(N
));
1311 when F_Flag18
=> Print_Flag
(Flag18
(N
));
1316 -- Field is not to be printed (False flag field)
1319 while P
< Pchar_Pos
(Node_Kind
'Succ (Nkind
(N
)))
1320 and then Pchars
(P
) not in Fchar
1327 -- Print aspects if present
1329 if Has_Aspects
(N
) then
1330 Print_Str
(Prefix_Str_Char
);
1331 Print_Str
("Aspect_Specifications = ");
1332 Print_Field
(Union_Id
(Aspect_Specifications
(N
)));
1336 -- Print entity information for entities
1338 if Nkind
(N
) in N_Entity
then
1339 Print_Entity_Info
(N
, Prefix_Str_Char
);
1342 -- Print the SCIL node (if available)
1344 if Present
(Get_SCIL_Node
(N
)) then
1345 Print_Str
(Prefix_Str_Char
);
1346 Print_Str
("SCIL_Node = ");
1347 Print_Node_Ref
(Get_SCIL_Node
(N
));
1352 ------------------------
1353 -- Print_Node_Briefly --
1354 ------------------------
1356 procedure Print_Node_Briefly
(N
: Node_Id
) is
1358 Printing_Descendants
:= False;
1360 Print_Node_Header
(N
);
1361 end Print_Node_Briefly
;
1363 -----------------------
1364 -- Print_Node_Header --
1365 -----------------------
1367 procedure Print_Node_Header
(N
: Node_Id
) is
1368 Enumerate
: Boolean := False;
1369 -- Flag set when enumerating multiple header flags
1371 procedure Print_Header_Flag
(Flag
: String);
1372 -- Output one of the flags that appears in a node header. The routine
1373 -- automatically handles enumeration of multiple flags.
1375 -----------------------
1376 -- Print_Header_Flag --
1377 -----------------------
1379 procedure Print_Header_Flag
(Flag
: String) is
1389 end Print_Header_Flag
;
1391 -- Start of processing for Print_Node_Header
1396 if N
> Atree_Private_Part
.Nodes
.Last
then
1397 Print_Str
(" (no such node)");
1404 if Comes_From_Source
(N
) then
1405 Print_Header_Flag
("source");
1408 if Analyzed
(N
) then
1409 Print_Header_Flag
("analyzed");
1412 if Error_Posted
(N
) then
1413 Print_Header_Flag
("posted");
1416 if Is_Ignored_Ghost_Node
(N
) then
1417 Print_Header_Flag
("ignored ghost");
1420 if Check_Actuals
(N
) then
1421 Print_Header_Flag
("check actuals");
1429 end Print_Node_Header
;
1431 ---------------------
1432 -- Print_Node_Kind --
1433 ---------------------
1435 procedure Print_Node_Kind
(N
: Node_Id
) is
1437 S
: constant String := Node_Kind
'Image (Nkind
(N
));
1440 if Phase
= Printing
then
1443 -- Note: the call to Fold_Upper in this loop is to get past the GNAT
1444 -- bug of 'Image returning lower case instead of upper case.
1446 for J
in S
'Range loop
1448 Write_Char
(Fold_Upper
(S
(J
)));
1450 Write_Char
(Fold_Lower
(S
(J
)));
1453 Ucase
:= (S
(J
) = '_');
1456 end Print_Node_Kind
;
1458 --------------------
1459 -- Print_Node_Ref --
1460 --------------------
1462 procedure Print_Node_Ref
(N
: Node_Id
) is
1466 if Phase
/= Printing
then
1471 Write_Str
("<empty>");
1473 elsif N
= Error
then
1474 Write_Str
("<error>");
1477 if Printing_Descendants
then
1478 S
:= Serial_Number
(Int
(N
));
1488 Print_Node_Kind
(N
);
1490 if Nkind
(N
) in N_Has_Chars
then
1492 Print_Name
(Chars
(N
));
1495 if Nkind
(N
) in N_Entity
then
1496 Write_Str
(" (Entity_Id=");
1498 Write_Str
(" (Node_Id=");
1501 Write_Int
(Int
(N
));
1503 if Sloc
(N
) <= Standard_Location
then
1512 ------------------------
1513 -- Print_Node_Subtree --
1514 ------------------------
1516 procedure Print_Node_Subtree
(N
: Node_Id
) is
1520 Next_Serial_Number
:= 1;
1522 Visit_Node
(N
, "", ' ');
1524 Next_Serial_Number
:= 1;
1526 Visit_Node
(N
, "", ' ');
1529 end Print_Node_Subtree
;
1535 procedure Print_Str
(S
: String) is
1537 if Phase
= Printing
then
1542 --------------------------
1543 -- Print_Str_Mixed_Case --
1544 --------------------------
1546 procedure Print_Str_Mixed_Case
(S
: String) is
1550 if Phase
= Printing
then
1553 for J
in S
'Range loop
1557 Write_Char
(Fold_Lower
(S
(J
)));
1560 Ucase
:= (S
(J
) = '_');
1563 end Print_Str_Mixed_Case
;
1569 procedure Print_Term
is
1570 procedure Free
is new Unchecked_Deallocation
1571 (Hash_Table_Type
, Access_Hash_Table_Type
);
1577 ---------------------
1578 -- Print_Tree_Elist --
1579 ---------------------
1581 procedure Print_Tree_Elist
(E
: Elist_Id
) is
1585 Printing_Descendants
:= False;
1588 Print_Elist_Ref
(E
);
1591 if Present
(E
) and then not Is_Empty_Elmt_List
(E
) then
1592 M
:= First_Elmt
(E
);
1597 exit when No
(Next_Elmt
(M
));
1598 Print_Node
(Node
(M
), "", '|');
1602 Print_Node
(Node
(M
), "", ' ');
1605 end Print_Tree_Elist
;
1607 ---------------------
1608 -- Print_Tree_List --
1609 ---------------------
1611 procedure Print_Tree_List
(L
: List_Id
) is
1615 Printing_Descendants
:= False;
1619 Print_Str
(" List_Id=");
1620 Print_Int
(Int
(L
));
1626 Print_Str
("<empty node list>");
1633 exit when Next
(N
) = Empty
;
1634 Print_Node
(N
, "", '|');
1638 Print_Node
(N
, "", ' ');
1641 end Print_Tree_List
;
1643 ---------------------
1644 -- Print_Tree_Node --
1645 ---------------------
1647 procedure Print_Tree_Node
(N
: Node_Id
; Label
: String := "") is
1649 Printing_Descendants
:= False;
1651 Print_Node
(N
, Label
, ' ');
1652 end Print_Tree_Node
;
1658 procedure pt
(N
: Union_Id
) is
1661 when List_Low_Bound
.. List_High_Bound
- 1 =>
1662 Print_List_Subtree
(List_Id
(N
));
1665 Print_Node_Subtree
(Node_Id
(N
));
1668 Print_Elist_Subtree
(Elist_Id
(N
));
1679 -- The hashing algorithm is to use the remainder of the ID value divided
1680 -- by the hash table length as the starting point in the table, and then
1681 -- handle collisions by serial searching wrapping at the end of the table.
1684 -- Set by an unsuccessful call to Serial_Number (one which returns zero)
1685 -- to save the slot that should be used if Set_Serial_Number is called.
1687 function Serial_Number
(Id
: Int
) return Nat
is
1688 H
: Int
:= Id
mod Hash_Table_Len
;
1691 while Hash_Table
(H
).Serial
/= 0 loop
1693 if Id
= Hash_Table
(H
).Id
then
1694 return Hash_Table
(H
).Serial
;
1699 if H
> Hash_Table
'Last then
1704 -- Entry was not found, save slot number for possible subsequent call
1705 -- to Set_Serial_Number, and unconditionally save the Id in this slot
1706 -- in case of such a call (the Id field is never read if the serial
1707 -- number of the slot is zero, so this is harmless in the case where
1708 -- Set_Serial_Number is not subsequently called).
1711 Hash_Table
(H
).Id
:= Id
;
1715 -----------------------
1716 -- Set_Serial_Number --
1717 -----------------------
1719 procedure Set_Serial_Number
is
1721 Hash_Table
(Hash_Slot
).Serial
:= Next_Serial_Number
;
1722 Next_Serial_Number
:= Next_Serial_Number
+ 1;
1723 end Set_Serial_Number
;
1729 procedure Tree_Dump
is
1730 procedure Underline
;
1731 -- Put underline under string we just printed
1733 procedure Underline
is
1734 Col
: constant Int
:= Column
;
1739 while Col
> Column
loop
1746 -- Start of processing for Tree_Dump. Note that we turn off the tree dump
1747 -- flags immediately, before starting the dump. This avoids generating two
1748 -- copies of the dump if an abort occurs after printing the dump, and more
1749 -- importantly, avoids an infinite loop if an abort occurs during the dump.
1751 -- Note: unlike in the source print case (in Sprint), we do not output
1752 -- separate trees for each unit. Instead the -df debug switch causes the
1753 -- tree that is output from the main unit to trace references into other
1754 -- units (normally such references are not traced). Since all other units
1755 -- are linked to the main unit by at least one reference, this causes all
1756 -- tree nodes to be included in the output tree.
1759 if Debug_Flag_Y
then
1760 Debug_Flag_Y
:= False;
1762 Write_Str
("Tree created for Standard (spec) ");
1764 Print_Node_Subtree
(Standard_Package_Node
);
1768 if Debug_Flag_T
then
1769 Debug_Flag_T
:= False;
1772 Write_Str
("Tree created for ");
1773 Write_Unit_Name
(Unit_Name
(Main_Unit
));
1775 Print_Node_Subtree
(Cunit
(Main_Unit
));
1784 procedure Visit_Elist
(E
: Elist_Id
; Prefix_Str
: String) is
1787 S
: constant Nat
:= Serial_Number
(Int
(E
));
1790 -- In marking phase, return if already marked, otherwise set next
1791 -- serial number in hash table for later reference.
1793 if Phase
= Marking
then
1795 return; -- already visited
1800 -- In printing phase, if already printed, then return, otherwise we
1801 -- are printing the next item, so increment the serial number.
1804 if S
< Next_Serial_Number
then
1805 return; -- already printed
1807 Next_Serial_Number
:= Next_Serial_Number
+ 1;
1811 -- Now process the list (Print calls have no effect in marking phase)
1813 Print_Str
(Prefix_Str
);
1814 Print_Elist_Ref
(E
);
1817 if Is_Empty_Elmt_List
(E
) then
1818 Print_Str
(Prefix_Str
);
1819 Print_Str
("(Empty element list)");
1824 if Phase
= Printing
then
1825 M
:= First_Elmt
(E
);
1826 while Present
(M
) loop
1828 Print_Str
(Prefix_Str
);
1835 Print_Str
(Prefix_Str
);
1839 M
:= First_Elmt
(E
);
1840 while Present
(M
) loop
1841 Visit_Node
(Node
(M
), Prefix_Str
, ' ');
1851 procedure Visit_List
(L
: List_Id
; Prefix_Str
: String) is
1853 S
: constant Nat
:= Serial_Number
(Int
(L
));
1856 -- In marking phase, return if already marked, otherwise set next
1857 -- serial number in hash table for later reference.
1859 if Phase
= Marking
then
1866 -- In printing phase, if already printed, then return, otherwise we
1867 -- are printing the next item, so increment the serial number.
1870 if S
< Next_Serial_Number
then
1871 return; -- already printed
1873 Next_Serial_Number
:= Next_Serial_Number
+ 1;
1877 -- Now process the list (Print calls have no effect in marking phase)
1879 Print_Str
(Prefix_Str
);
1883 Print_Str
(Prefix_Str
);
1884 Print_Str
("|Parent = ");
1885 Print_Node_Ref
(Parent
(L
));
1891 Print_Str
(Prefix_Str
);
1892 Print_Str
("(Empty list)");
1897 Print_Str
(Prefix_Str
);
1901 while Next
(N
) /= Empty
loop
1902 Visit_Node
(N
, Prefix_Str
, '|');
1907 Visit_Node
(N
, Prefix_Str
, ' ');
1914 procedure Visit_Node
1916 Prefix_Str
: String;
1917 Prefix_Char
: Character)
1919 New_Prefix
: String (Prefix_Str
'First .. Prefix_Str
'Last + 2);
1920 -- Prefix string for printing referenced fields
1922 procedure Visit_Descendant
1924 No_Indent
: Boolean := False);
1925 -- This procedure tests the given value of one of the Fields referenced
1926 -- by the current node to determine whether to visit it recursively.
1927 -- Normally No_Indent is false, which means that the visited node will
1928 -- be indented using New_Prefix. If No_Indent is set to True, then
1929 -- this indentation is skipped, and Prefix_Str is used for the call
1930 -- to print the descendant. No_Indent is effective only if the
1931 -- referenced descendant is a node.
1933 ----------------------
1934 -- Visit_Descendant --
1935 ----------------------
1937 procedure Visit_Descendant
1939 No_Indent
: Boolean := False)
1942 -- Case of descendant is a node
1944 if D
in Node_Range
then
1946 -- Don't bother about Empty or Error descendants
1948 if D
<= Union_Id
(Empty_Or_Error
) then
1953 Nod
: constant Node_Or_Entity_Id
:= Node_Or_Entity_Id
(D
);
1956 -- Descendants in one of the standardly compiled internal
1957 -- packages are normally ignored, unless the parent is also
1958 -- in such a package (happens when Standard itself is output)
1959 -- or if the -df switch is set which causes all links to be
1960 -- followed, even into package standard.
1962 if Sloc
(Nod
) <= Standard_Location
then
1963 if Sloc
(N
) > Standard_Location
1964 and then not Debug_Flag_F
1969 -- Don't bother about a descendant in a different unit than
1970 -- the node we came from unless the -df switch is set. Note
1971 -- that we know at this point that Sloc (D) > Standard_Location
1973 -- Note: the tests for No_Location here just make sure that we
1974 -- don't blow up on a node which is missing an Sloc value. This
1975 -- should not normally happen.
1978 if (Sloc
(N
) <= Standard_Location
1979 or else Sloc
(N
) = No_Location
1980 or else Sloc
(Nod
) = No_Location
1981 or else not In_Same_Source_Unit
(Nod
, N
))
1982 and then not Debug_Flag_F
1988 -- Don't bother visiting a source node that has a parent which
1989 -- is not the node we came from. We prefer to trace such nodes
1990 -- from their real parents. This causes the tree to be printed
1991 -- in a more coherent order, e.g. a defining identifier listed
1992 -- next to its corresponding declaration, instead of next to
1993 -- some semantic reference.
1995 -- This test is skipped for nodes in standard packages unless
1996 -- the -dy option is set (which outputs the tree for standard)
1998 -- Also, always follow pointers to Is_Itype entities,
1999 -- since we want to list these when they are first referenced.
2001 if Parent
(Nod
) /= Empty
2002 and then Comes_From_Source
(Nod
)
2003 and then Parent
(Nod
) /= N
2004 and then (Sloc
(N
) > Standard_Location
or else Debug_Flag_Y
)
2009 -- If we successfully fall through all the above tests (which
2010 -- execute a return if the node is not to be visited), we can
2011 -- go ahead and visit the node.
2014 Visit_Node
(Nod
, Prefix_Str
, Prefix_Char
);
2016 Visit_Node
(Nod
, New_Prefix
, ' ');
2020 -- Case of descendant is a list
2022 elsif D
in List_Range
then
2024 -- Don't bother with a missing list, empty list or error list
2026 pragma Assert
(D
/= Union_Id
(No_List
));
2027 -- Because No_List = Empty, which is in Node_Range above
2029 if D
= Union_Id
(Error_List
)
2030 or else Is_Empty_List
(List_Id
(D
))
2034 -- Otherwise we can visit the list. Note that we don't bother to
2035 -- do the parent test that we did for the node case, because it
2036 -- just does not happen that lists are referenced more than one
2037 -- place in the tree. We aren't counting on this being the case
2038 -- to generate valid output, it is just that we don't need in
2039 -- practice to worry about listing the list at a place that is
2043 Visit_List
(List_Id
(D
), New_Prefix
);
2046 -- Case of descendant is an element list
2048 elsif D
in Elist_Range
then
2050 -- Don't bother with a missing list, or an empty list
2052 if D
= Union_Id
(No_Elist
)
2053 or else Is_Empty_Elmt_List
(Elist_Id
(D
))
2057 -- Otherwise, visit the referenced element list
2060 Visit_Elist
(Elist_Id
(D
), New_Prefix
);
2063 -- For all other kinds of descendants (strings, names, uints etc),
2064 -- there is nothing to visit (the contents of the field will be
2065 -- printed when we print the containing node, but what concerns
2066 -- us now is looking for descendants in the tree.
2071 end Visit_Descendant
;
2073 -- Start of processing for Visit_Node
2080 -- Set fatal error node in case we get a blow up during the trace
2082 Current_Error_Node
:= N
;
2084 New_Prefix
(Prefix_Str
'Range) := Prefix_Str
;
2085 New_Prefix
(Prefix_Str
'Last + 1) := Prefix_Char
;
2086 New_Prefix
(Prefix_Str
'Last + 2) := ' ';
2088 -- In the marking phase, all we do is to set the serial number
2090 if Phase
= Marking
then
2091 if Serial_Number
(Int
(N
)) /= 0 then
2092 return; -- already visited
2097 -- In the printing phase, we print the node
2100 if Serial_Number
(Int
(N
)) < Next_Serial_Number
then
2102 -- Here we have already visited the node, but if it is in a list,
2103 -- we still want to print the reference, so that it is clear that
2104 -- it belongs to the list.
2106 if Is_List_Member
(N
) then
2107 Print_Str
(Prefix_Str
);
2110 Print_Str
(Prefix_Str
);
2111 Print_Char
(Prefix_Char
);
2112 Print_Str
("(already output)");
2114 Print_Str
(Prefix_Str
);
2115 Print_Char
(Prefix_Char
);
2122 Print_Node
(N
, Prefix_Str
, Prefix_Char
);
2123 Print_Str
(Prefix_Str
);
2124 Print_Char
(Prefix_Char
);
2126 Next_Serial_Number
:= Next_Serial_Number
+ 1;
2130 -- Visit all descendants of this node
2132 if Nkind
(N
) not in N_Entity
then
2133 Visit_Descendant
(Field1
(N
));
2134 Visit_Descendant
(Field2
(N
));
2135 Visit_Descendant
(Field3
(N
));
2136 Visit_Descendant
(Field4
(N
));
2137 Visit_Descendant
(Field5
(N
));
2139 if Has_Aspects
(N
) then
2140 Visit_Descendant
(Union_Id
(Aspect_Specifications
(N
)));
2146 Visit_Descendant
(Field1
(N
));
2147 Visit_Descendant
(Field3
(N
));
2148 Visit_Descendant
(Field4
(N
));
2149 Visit_Descendant
(Field5
(N
));
2150 Visit_Descendant
(Field6
(N
));
2151 Visit_Descendant
(Field7
(N
));
2152 Visit_Descendant
(Field8
(N
));
2153 Visit_Descendant
(Field9
(N
));
2154 Visit_Descendant
(Field10
(N
));
2155 Visit_Descendant
(Field11
(N
));
2156 Visit_Descendant
(Field12
(N
));
2157 Visit_Descendant
(Field13
(N
));
2158 Visit_Descendant
(Field14
(N
));
2159 Visit_Descendant
(Field15
(N
));
2160 Visit_Descendant
(Field16
(N
));
2161 Visit_Descendant
(Field17
(N
));
2162 Visit_Descendant
(Field18
(N
));
2163 Visit_Descendant
(Field19
(N
));
2164 Visit_Descendant
(Field20
(N
));
2165 Visit_Descendant
(Field21
(N
));
2166 Visit_Descendant
(Field22
(N
));
2167 Visit_Descendant
(Field23
(N
));
2169 -- Now an interesting special case. Normally parents are always
2170 -- printed since we traverse the tree in a downwards direction.
2171 -- However, there is an exception to this rule, which is the
2172 -- case where a parent is constructed by the compiler and is not
2173 -- referenced elsewhere in the tree. The following catches this case.
2175 if not Comes_From_Source
(N
) then
2176 Visit_Descendant
(Union_Id
(Parent
(N
)));
2179 -- You may be wondering why we omitted Field2 above. The answer
2180 -- is that this is the Next_Entity field, and we want to treat
2181 -- it rather specially. Why? Because a Next_Entity link does not
2182 -- correspond to a level deeper in the tree, and we do not want
2183 -- the tree to march off to the right of the page due to bogus
2184 -- indentations coming from this effect.
2186 -- To prevent this, what we do is to control references via
2187 -- Next_Entity only from the first entity on a given scope chain,
2188 -- and we keep them all at the same level. Of course if an entity
2189 -- has already been referenced it is not printed.
2191 if Present
(Next_Entity
(N
))
2192 and then Present
(Scope
(N
))
2193 and then First_Entity
(Scope
(N
)) = N
2200 while Present
(Nod
) loop
2201 Visit_Descendant
(Union_Id
(Next_Entity
(Nod
)));