1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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 -- This package (source print) contains routines for printing the source
28 -- program corresponding to a specified syntax tree. These routines are
29 -- intended for debugging use in the compiler (not as a user level pretty
30 -- print tool). Only information present in the tree is output (e.g. no
31 -- comments are present in the output), and as far as possible we avoid
32 -- making any assumptions about the correctness of the tree, so a bad
33 -- tree may either blow up on a debugging check, or list incorrect source.
35 with Types; use Types;
38 -----------------------
39 -- Syntax Extensions --
40 -----------------------
42 -- When the generated tree is printed, it contains constructs that are not
43 -- pure Ada. For convenience, syntactic extensions to Ada have been defined
44 -- purely for the purposes of this printout (they are not recognized by the
47 -- Could use more documentation for all of these ???
49 -- Allocator new xxx [storage_pool = xxx]
50 -- Cleanup action at end procedure name;
51 -- Conditional expression (if expr then expr else expr)
52 -- Conversion wi Float_Truncate target^(source)
53 -- Convert wi Conversion_OK target?(source)
54 -- Convert wi Rounded_Result target@(source)
55 -- Divide wi Treat_Fixed_As_Integer x #/ y
56 -- Divide wi Rounded_Result x @/ y
57 -- Expression with range check {expression}
58 -- Operator with range check {operator} (e.g. {+})
59 -- Free statement free expr [storage_pool = xxx]
60 -- Freeze entity with freeze actions freeze entityname [ actions ]
61 -- Implicit call to run time routine $routine-name
62 -- Interpretation interpretation type [, entity]
63 -- Intrinsic calls function-name!(arg, arg, arg)
64 -- Itype declaration [(sub)type declaration without ;]
65 -- Itype reference reference itype
66 -- Label declaration labelname : label
67 -- Mod wi Treat_Fixed_As_Integer x #mod y
68 -- Multiple concatenation expr && expr && expr ... && expr
69 -- Multiply wi Treat_Fixed_As_Integer x #* y
70 -- Multiply wi Rounded_Result x @* y
71 -- Others choice for cleanup when all others
72 -- Pop exception label %pop_xxx_exception_label
73 -- Push exception label %push_xxx_exception_label (label)
74 -- Raise xxx error [xxx_error [when cond]]
75 -- Raise xxx error with msg [xxx_error [when cond], "msg"]
76 -- Rational literal See UR_Write for details
77 -- Rem wi Treat_Fixed_As_Integer x #rem y
78 -- Reference expression'reference
79 -- Shift nodes shift_name!(expr, count)
80 -- Static declaration name : static xxx
81 -- Subprogram_Info subprog'Subprogram_Info
82 -- Unchecked conversion target_type!(source_expression)
83 -- Unchecked expression `(expression)
84 -- Validate_Unchecked_Conversion validate unchecked_conversion
85 -- (src-type, target-typ);
87 -- Note: the storage_pool parameters for allocators and the free node
88 -- are omitted if the Storage_Pool field is Empty, indicating use of
89 -- the standard default pool.
95 procedure Source_Dump;
96 -- This routine is called from the GNAT main program to dump source as
97 -- requested by debug options. The relevant debug options are:
98 -- -ds print source from tree, both original and generated code
99 -- -dg print source from tree, including only the generated code
100 -- -do print source from tree, including only the original code
101 -- -df modify the above to include all units, not just the main unit
102 -- -sz print source from tree for package Standard
104 procedure Sprint_Comma_List (List : List_Id);
105 -- Prints the nodes in a list, with separating commas. If the list
106 -- is empty then no output is generated.
108 procedure Sprint_Paren_Comma_List (List : List_Id);
109 -- Prints the nodes in a list, surrounded by parentheses, and separated
110 -- by comas. If the list is empty, then no output is generated. A blank
111 -- is output before the initial left parenthesis.
113 procedure Sprint_Opt_Paren_Comma_List (List : List_Id);
114 -- Same as normal Sprint_Paren_Comma_List procedure, except that
115 -- an extra blank is output if List is non-empty, and nothing at all is
116 -- printed it the argument is No_List.
118 procedure Sprint_Node_List (List : List_Id);
119 -- Prints the nodes in a list with no separating characters. This is used
120 -- in the case of lists of items which are printed on separate lines using
121 -- the current indentation amount. Note that Sprint_Node_List itself
122 -- does not generate any New_Line calls.
124 procedure Sprint_Opt_Node_List (List : List_Id);
125 -- Like Sprint_Node_List, but prints nothing if List = No_List
127 procedure Sprint_Indented_List (List : List_Id);
128 -- Like Sprint_Line_List, except that the indentation level is
129 -- increased before outputting the list of items, and then decremented
130 -- (back to its original level) before returning to the caller.
132 procedure Sprint_Node (Node : Node_Id);
133 -- Prints a single node. No new lines are output, except as required for
134 -- splitting lines that are too long to fit on a single physical line.
135 -- No output is generated at all if Node is Empty. No trailing or leading
136 -- blank characters are generated.
138 procedure Sprint_Opt_Node (Node : Node_Id);
139 -- Same as normal Sprint_Node procedure, except that one leading
140 -- blank is output before the node if it is non-empty.
142 procedure pg (Arg : Union_Id);
143 pragma Export (Ada, pg);
144 -- Print generated source for argument N (like -gnatdg output). Intended
145 -- only for use from gdb for debugging purposes. Currently, Arg may be a
146 -- List_Id or a Node_Id (anything else outputs a blank line).
148 procedure po (Arg : Union_Id);
149 pragma Export (Ada, po);
150 -- Like pg, but prints original source for the argument (like -gnatdo
151 -- output). Intended only for use from gdb for debugging purposes.
153 procedure ps (Arg : Union_Id);
154 pragma Export (Ada, ps);
155 -- Like pg, but prints generated and original source for the argument (like
156 -- -gnatds output). Intended only for use from gdb for debugging purposes.