1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, 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 Atree
; use Atree
;
27 with Debug
; use Debug
;
28 with Sinfo
; use Sinfo
;
29 with Sinput
; use Sinput
;
30 with Output
; use Output
;
32 package body Debug_A
is
34 Debug_A_Depth
: Natural := 0;
35 -- Output for the debug A flag is preceded by a sequence of vertical bar
36 -- characters corresponding to the recursion depth of the actions being
37 -- recorded (analysis, expansion, resolution and evaluation of nodes)
38 -- This variable records the depth.
40 Max_Node_Ids
: constant := 200;
41 -- Maximum number of Node_Id values that get stacked
43 Node_Ids
: array (1 .. Max_Node_Ids
) of Node_Id
;
44 -- A stack used to keep track of Node_Id values for setting the value of
45 -- Current_Error_Node correctly. Note that if we have more than 200
46 -- recursion levels, we just don't reset the right value on exit, which
47 -- is not crucial, since this is only for debugging.
49 -----------------------
50 -- Local Subprograms --
51 -----------------------
53 procedure Debug_Output_Astring
;
54 -- Outputs Debug_A_Depth number of vertical bars, used to preface messages
60 procedure Debug_A_Entry
(S
: String; N
: Node_Id
) is
62 -- Output debugging information if -gnatda flag set
67 Write_Str
("Node_Id = ");
70 Write_Location
(Sloc
(N
));
72 Write_Str
(Node_Kind
'Image (Nkind
(N
)));
76 -- Now push the new element
78 -- Why is this done unconditionally???
80 Debug_A_Depth
:= Debug_A_Depth
+ 1;
82 if Debug_A_Depth
<= Max_Node_Ids
then
83 Node_Ids
(Debug_A_Depth
) := N
;
86 -- Set Current_Error_Node only if the new node has a decent Sloc
87 -- value, since it is for the Sloc value that we set this anyway.
88 -- If we don't have a decent Sloc value, we leave it unchanged.
90 if Sloc
(N
) > No_Location
then
91 Current_Error_Node
:= N
;
99 procedure Debug_A_Exit
(S
: String; N
: Node_Id
; Comment
: String) is
101 Debug_A_Depth
:= Debug_A_Depth
- 1;
103 -- We look down the stack to find something with a decent Sloc. (If
104 -- we find nothing, just leave it unchanged which is not so terrible)
106 -- This seems nasty overhead for the normal case ???
108 for J
in reverse 1 .. Integer'Min (Max_Node_Ids
, Debug_A_Depth
) loop
109 if Sloc
(Node_Ids
(J
)) > No_Location
then
110 Current_Error_Node
:= Node_Ids
(J
);
115 -- Output debugging information if -gnatda flag set
118 Debug_Output_Astring
;
120 Write_Str
("Node_Id = ");
127 --------------------------
128 -- Debug_Output_Astring --
129 --------------------------
131 procedure Debug_Output_Astring
is
132 Vbars
: constant String := "|||||||||||||||||||||||||";
133 -- Should be constant, removed because of GNAT 1.78 bug ???
136 if Debug_A_Depth
> Vbars
'Length then
137 for I
in Vbars
'Length .. Debug_A_Depth
loop
144 Write_Str
(Vbars
(1 .. Debug_A_Depth
));
146 end Debug_Output_Astring
;