OSDN Git Service

2008-04-30 Paul Thomas <pault@gcc.gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / ada / sprint.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                               S P R I N T                                --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2008, Free Software Foundation, Inc.         --
10 --                                                                          --
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.          --
20 --                                                                          --
21 -- GNAT was originally developed  by the GNAT team at  New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
23 --                                                                          --
24 ------------------------------------------------------------------------------
25
26 with Atree;    use Atree;
27 with Casing;   use Casing;
28 with Csets;    use Csets;
29 with Debug;    use Debug;
30 with Einfo;    use Einfo;
31 with Fname;    use Fname;
32 with Lib;      use Lib;
33 with Namet;    use Namet;
34 with Nlists;   use Nlists;
35 with Opt;      use Opt;
36 with Output;   use Output;
37 with Rtsfind;  use Rtsfind;
38 with Sem_Util; use Sem_Util;
39 with Sinfo;    use Sinfo;
40 with Sinput;   use Sinput;
41 with Sinput.D; use Sinput.D;
42 with Snames;   use Snames;
43 with Stand;    use Stand;
44 with Stringt;  use Stringt;
45 with Uintp;    use Uintp;
46 with Uname;    use Uname;
47 with Urealp;   use Urealp;
48
49 package body Sprint is
50    Current_Source_File : Source_File_Index;
51    --  Index of source file whose generated code is being dumped
52
53    Dump_Node : Node_Id := Empty;
54    --  This is set to the current node, used for printing line numbers. In
55    --  Debug_Generated_Code mode, Dump_Node is set to the current node
56    --  requiring Sloc fixup, until Set_Debug_Sloc is called to set the proper
57    --  value. The call clears it back to Empty.
58
59    Debug_Sloc : Source_Ptr;
60    --  Sloc of first byte of line currently being written if we are
61    --  generating a source debug file.
62
63    Dump_Original_Only : Boolean;
64    --  Set True if the -gnatdo (dump original tree) flag is set
65
66    Dump_Generated_Only : Boolean;
67    --  Set True if the -gnatG (dump generated tree) debug flag is set
68    --  or for Print_Generated_Code (-gnatG) or Dump_Generated_Code (-gnatD).
69
70    Dump_Freeze_Null : Boolean;
71    --  Set True if freeze nodes and non-source null statements output
72
73    Freeze_Indent : Int := 0;
74    --  Keep track of freeze indent level (controls output of blank lines before
75    --  procedures within expression freeze actions). Relevant only if we are
76    --  not in Dump_Source_Text mode, since in Dump_Source_Text mode we don't
77    --  output these blank lines in any case.
78
79    Indent : Int := 0;
80    --  Number of columns for current line output indentation
81
82    Indent_Annull_Flag : Boolean := False;
83    --  Set True if subsequent Write_Indent call to be ignored, gets reset
84    --  by this call, so it is only active to suppress a single indent call.
85
86    Last_Line_Printed : Physical_Line_Number;
87    --  This keeps track of the physical line number of the last source line
88    --  that has been output. The value is only valid in Dump_Source_Text mode.
89
90    Line_Limit : constant := 72;
91    --  Limit value for chopping long lines
92
93    -------------------------------
94    -- Operator Precedence Table --
95    -------------------------------
96
97    --  This table is used to decide whether a subexpression needs to be
98    --  parenthesized. The rule is that if an operand of an operator (which
99    --  for this purpose includes AND THEN and OR ELSE) is itself an operator
100    --  with a lower precedence than the operator (or equal precedence if
101    --  appearing as the right operand), then parentheses are required.
102
103    Op_Prec : constant array (N_Subexpr) of Short_Short_Integer :=
104                (N_Op_And          => 1,
105                 N_Op_Or           => 1,
106                 N_Op_Xor          => 1,
107                 N_And_Then        => 1,
108                 N_Or_Else         => 1,
109
110                 N_In              => 2,
111                 N_Not_In          => 2,
112                 N_Op_Eq           => 2,
113                 N_Op_Ge           => 2,
114                 N_Op_Gt           => 2,
115                 N_Op_Le           => 2,
116                 N_Op_Lt           => 2,
117                 N_Op_Ne           => 2,
118
119                 N_Op_Add          => 3,
120                 N_Op_Concat       => 3,
121                 N_Op_Subtract     => 3,
122                 N_Op_Plus         => 3,
123                 N_Op_Minus        => 3,
124
125                 N_Op_Divide       => 4,
126                 N_Op_Mod          => 4,
127                 N_Op_Rem          => 4,
128                 N_Op_Multiply     => 4,
129
130                 N_Op_Expon        => 5,
131                 N_Op_Abs          => 5,
132                 N_Op_Not          => 5,
133
134                 others            => 6);
135
136    procedure Sprint_Left_Opnd (N : Node_Id);
137    --  Print left operand of operator, parenthesizing if necessary
138
139    procedure Sprint_Right_Opnd (N : Node_Id);
140    --  Print right operand of operator, parenthesizing if necessary
141
142    -----------------------
143    -- Local Subprograms --
144    -----------------------
145
146    procedure Col_Check (N : Nat);
147    --  Check that at least N characters remain on current line, and if not,
148    --  then start an extra line with two characters extra indentation for
149    --  continuing text on the next line.
150
151    procedure Extra_Blank_Line;
152    --  In some situations we write extra blank lines to separate the generated
153    --  code to make it more readable. However, these extra blank lines are not
154    --  generated in Dump_Source_Text mode, since there the source text lines
155    --  output with preceding blank lines are quite sufficient as separators.
156    --  This procedure writes a blank line if Dump_Source_Text is False.
157
158    procedure Indent_Annull;
159    --  Causes following call to Write_Indent to be ignored. This is used when
160    --  a higher level node wants to stop a lower level node from starting a
161    --  new line, when it would otherwise be inclined to do so (e.g. the case
162    --  of an accept statement called from an accept alternative with a guard)
163
164    procedure Indent_Begin;
165    --  Increase indentation level
166
167    procedure Indent_End;
168    --  Decrease indentation level
169
170    procedure Note_Implicit_Run_Time_Call (N : Node_Id);
171    --  N is the Name field of a function call or procedure statement call.
172    --  The effect of the call is to output a $ if the call is identified as
173    --  an implicit call to a run time routine.
174
175    procedure Print_Debug_Line (S : String);
176    --  Used to print output lines in Debug_Generated_Code mode (this is used
177    --  as the argument for a call to Set_Special_Output in package Output).
178
179    procedure Process_TFAI_RR_Flags (Nod : Node_Id);
180    --  Given a divide, multiplication or division node, check the flags
181    --  Treat_Fixed_As_Integer and Rounded_Flags, and if set, output the
182    --  appropriate special syntax characters (# and @).
183
184    procedure Set_Debug_Sloc;
185    --  If Dump_Node is non-empty, this routine sets the appropriate value
186    --  in its Sloc field, from the current location in the debug source file
187    --  that is currently being written.
188
189    procedure Sprint_And_List (List : List_Id);
190    --  Print the given list with items separated by vertical "and"
191
192    procedure Sprint_Bar_List (List : List_Id);
193    --  Print the given list with items separated by vertical bars
194
195    procedure Sprint_End_Label
196      (Node    : Node_Id;
197       Default : Node_Id);
198    --  Print the end label for a Handled_Sequence_Of_Statements in a body.
199    --  If there is not end label, use the defining identifier of the enclosing
200    --  construct. If the end label is present, treat it as a reference to the
201    --  defining entity of the construct: this guarantees that it carries the
202    --  proper sloc information for debugging purposes.
203
204    procedure Sprint_Node_Actual (Node : Node_Id);
205    --  This routine prints its node argument. It is a lower level routine than
206    --  Sprint_Node, in that it does not bother about rewritten trees.
207
208    procedure Sprint_Node_Sloc (Node : Node_Id);
209    --  Like Sprint_Node, but in addition, in Debug_Generated_Code mode,
210    --  sets the Sloc of the current debug node to be a copy of the Sloc
211    --  of the sprinted node Node. Note that this is done after printing
212    --  Node, so that the Sloc is the proper updated value for the debug file.
213
214    procedure Update_Itype (Node : Node_Id);
215    --  Update the Sloc of an itype that is not attached to the tree, when
216    --  debugging expanded code. This routine is called from nodes whose
217    --  type can be an Itype, such as defining_identifiers that may be of
218    --  an anonymous access type, or ranges in slices.
219
220    procedure Write_Char_Sloc (C : Character);
221    --  Like Write_Char, except that if C is non-blank, Set_Debug_Sloc is
222    --  called to ensure that the current node has a proper Sloc set.
223
224    procedure Write_Condition_And_Reason (Node : Node_Id);
225    --  Write Condition and Reason codes of Raise_xxx_Error node
226
227    procedure Write_Corresponding_Source (S : String);
228    --  If S is a string with a single keyword (possibly followed by a space),
229    --  and if the next non-comment non-blank source line matches this keyword,
230    --  then output all source lines up to this matching line.
231
232    procedure Write_Discr_Specs (N : Node_Id);
233    --  Output discriminant specification for node, which is any of the type
234    --  declarations that can have discriminants.
235
236    procedure Write_Ekind (E : Entity_Id);
237    --  Write the String corresponding to the Ekind without "E_"
238
239    procedure Write_Id (N : Node_Id);
240    --  N is a node with a Chars field. This procedure writes the name that
241    --  will be used in the generated code associated with the name. For a
242    --  node with no associated entity, this is simply the Chars field. For
243    --  the case where there is an entity associated with the node, we print
244    --  the name associated with the entity (since it may have been encoded).
245    --  One other special case is that an entity has an active external name
246    --  (i.e. an external name present with no address clause), then this
247    --  external name is output. This procedure also deals with outputting
248    --  declarations of referenced itypes, if not output earlier.
249
250    function Write_Identifiers (Node : Node_Id) return Boolean;
251    --  Handle node where the grammar has a list of defining identifiers, but
252    --  the tree has a separate declaration for each identifier. Handles the
253    --  printing of the defining identifier, and returns True if the type and
254    --  initialization information is to be printed, False if it is to be
255    --  skipped (the latter case happens when printing defining identifiers
256    --  other than the first in the original tree output case).
257
258    procedure Write_Implicit_Def (E : Entity_Id);
259    pragma Warnings (Off, Write_Implicit_Def);
260    --  Write the definition of the implicit type E according to its Ekind
261    --  For now a debugging procedure, but might be used in the future.
262
263    procedure Write_Indent;
264    --  Start a new line and write indentation spacing
265
266    function Write_Indent_Identifiers (Node : Node_Id) return Boolean;
267    --  Like Write_Identifiers except that each new printed declaration
268    --  is at the start of a new line.
269
270    function Write_Indent_Identifiers_Sloc (Node : Node_Id) return Boolean;
271    --  Like Write_Indent_Identifiers except that in Debug_Generated_Code
272    --  mode, the Sloc of the current debug node is set to point to the
273    --  first output identifier.
274
275    procedure Write_Indent_Str (S : String);
276    --  Start a new line and write indent spacing followed by given string
277
278    procedure Write_Indent_Str_Sloc (S : String);
279    --  Like Write_Indent_Str, but in addition, in Debug_Generated_Code mode,
280    --  the Sloc of the current node is set to the first non-blank character
281    --  in the string S.
282
283    procedure Write_Itype (Typ : Entity_Id);
284    --  If Typ is an Itype that has not been written yet, write it. If Typ is
285    --  any other kind of entity or tree node, the call is ignored.
286
287    procedure Write_Name_With_Col_Check (N : Name_Id);
288    --  Write name (using Write_Name) with initial column check, and possible
289    --  initial Write_Indent (to get new line) if current line is too full.
290
291    procedure Write_Name_With_Col_Check_Sloc (N : Name_Id);
292    --  Like Write_Name_With_Col_Check but in addition, in Debug_Generated_Code
293    --  mode, sets Sloc of current debug node to first character of name.
294
295    procedure Write_Operator (N : Node_Id; S : String);
296    --  Like Write_Str_Sloc, used for operators, encloses the string in
297    --  characters {} if the Do_Overflow flag is set on the node N.
298
299    procedure Write_Param_Specs (N : Node_Id);
300    --  Output parameter specifications for node (which is either a function
301    --  or procedure specification with a Parameter_Specifications field)
302
303    procedure Write_Rewrite_Str (S : String);
304    --  Writes out a string (typically containing <<< or >>>}) for a node
305    --  created by rewriting the tree. Suppressed if we are outputting the
306    --  generated code only, since in this case we don't specially mark nodes
307    --  created by rewriting).
308
309    procedure Write_Source_Line (L : Physical_Line_Number);
310    --  If writing of interspersed source lines is enabled, then write the given
311    --  line from the source file, preceded by Eol, then an extra blank line if
312    --  the line has at least one blank, is not a comment and is not line one,
313    --  then "--" and the line number followed by period followed by text of the
314    --  source line (without terminating Eol). If interspersed source line
315    --  output not enabled, then the call has no effect.
316
317    procedure Write_Source_Lines (L : Physical_Line_Number);
318    --  If writing of interspersed source lines is enabled, then writes source
319    --  lines Last_Line_Printed + 1 .. L, and updates Last_Line_Printed. If
320    --  interspersed source line output not enabled, then call has no effect.
321
322    procedure Write_Str_Sloc (S : String);
323    --  Like Write_Str, but sets debug Sloc of current debug node to first
324    --  non-blank character if a current debug node is active.
325
326    procedure Write_Str_With_Col_Check (S : String);
327    --  Write string (using Write_Str) with initial column check, and possible
328    --  initial Write_Indent (to get new line) if current line is too full.
329
330    procedure Write_Str_With_Col_Check_Sloc (S : String);
331    --  Like Write_Str_With_Col_Check, but sets debug Sloc of current debug
332    --  node to first non-blank character if a current debug node is active.
333
334    procedure Write_Uint_With_Col_Check (U : Uint; Format : UI_Format);
335    --  Write Uint (using UI_Write) with initial column check, and possible
336    --  initial Write_Indent (to get new line) if current line is too full.
337    --  The format parameter determines the output format (see UI_Write).
338
339    procedure Write_Uint_With_Col_Check_Sloc (U : Uint; Format : UI_Format);
340    --  Write Uint (using UI_Write) with initial column check, and possible
341    --  initial Write_Indent (to get new line) if current line is too full.
342    --  The format parameter determines the output format (see UI_Write).
343    --  In addition, in Debug_Generated_Code mode, sets the current node
344    --  Sloc to the first character of the output value.
345
346    procedure Write_Ureal_With_Col_Check_Sloc (U : Ureal);
347    --  Write Ureal (using same output format as UR_Write) with column checks
348    --  and a possible initial Write_Indent (to get new line) if current line
349    --  is too full. In addition, in Debug_Generated_Code mode, sets the
350    --  current node Sloc to the first character of the output value.
351
352    ---------------
353    -- Col_Check --
354    ---------------
355
356    procedure Col_Check (N : Nat) is
357    begin
358       if N + Column > Line_Limit then
359          Write_Indent_Str ("  ");
360       end if;
361    end Col_Check;
362
363    ----------------------
364    -- Extra_Blank_Line --
365    ----------------------
366
367    procedure Extra_Blank_Line is
368    begin
369       if not Dump_Source_Text then
370          Write_Indent;
371       end if;
372    end Extra_Blank_Line;
373
374    -------------------
375    -- Indent_Annull --
376    -------------------
377
378    procedure Indent_Annull is
379    begin
380       Indent_Annull_Flag := True;
381    end Indent_Annull;
382
383    ------------------
384    -- Indent_Begin --
385    ------------------
386
387    procedure Indent_Begin is
388    begin
389       Indent := Indent + 3;
390    end Indent_Begin;
391
392    ----------------
393    -- Indent_End --
394    ----------------
395
396    procedure Indent_End is
397    begin
398       Indent := Indent - 3;
399    end Indent_End;
400
401    ---------------------------------
402    -- Note_Implicit_Run_Time_Call --
403    ---------------------------------
404
405    procedure Note_Implicit_Run_Time_Call (N : Node_Id) is
406    begin
407       if not Comes_From_Source (N)
408         and then Is_Entity_Name (N)
409       then
410          declare
411             Ent : constant Entity_Id := Entity (N);
412          begin
413             if not In_Extended_Main_Source_Unit (Ent)
414               and then
415                 Is_Predefined_File_Name
416                   (Unit_File_Name (Get_Source_Unit (Ent)))
417             then
418                Col_Check (Length_Of_Name (Chars (Ent)));
419                Write_Char ('$');
420             end if;
421          end;
422       end if;
423    end Note_Implicit_Run_Time_Call;
424
425    --------
426    -- pg --
427    --------
428
429    procedure pg (Arg : Union_Id) is
430    begin
431       Dump_Generated_Only := True;
432       Dump_Original_Only := False;
433       Current_Source_File := No_Source_File;
434
435       if Arg in List_Range then
436          Sprint_Node_List (List_Id (Arg));
437
438       elsif Arg in Node_Range then
439          Sprint_Node (Node_Id (Arg));
440
441       else
442          null;
443       end if;
444
445       Write_Eol;
446    end pg;
447
448    --------
449    -- po --
450    --------
451
452    procedure po (Arg : Union_Id) is
453    begin
454       Dump_Generated_Only := False;
455       Dump_Original_Only := True;
456       Current_Source_File := No_Source_File;
457
458       if Arg in List_Range then
459          Sprint_Node_List (List_Id (Arg));
460
461       elsif Arg in Node_Range then
462          Sprint_Node (Node_Id (Arg));
463
464       else
465          null;
466       end if;
467
468       Write_Eol;
469    end po;
470
471    ----------------------
472    -- Print_Debug_Line --
473    ----------------------
474
475    procedure Print_Debug_Line (S : String) is
476    begin
477       Write_Debug_Line (S, Debug_Sloc);
478    end Print_Debug_Line;
479
480    ---------------------------
481    -- Process_TFAI_RR_Flags --
482    ---------------------------
483
484    procedure Process_TFAI_RR_Flags (Nod : Node_Id) is
485    begin
486       if Treat_Fixed_As_Integer (Nod) then
487          Write_Char ('#');
488       end if;
489
490       if Rounded_Result (Nod) then
491          Write_Char ('@');
492       end if;
493    end Process_TFAI_RR_Flags;
494
495    --------
496    -- ps --
497    --------
498
499    procedure ps (Arg : Union_Id) is
500    begin
501       Dump_Generated_Only := False;
502       Dump_Original_Only := False;
503       Current_Source_File := No_Source_File;
504
505       if Arg in List_Range then
506          Sprint_Node_List (List_Id (Arg));
507
508       elsif Arg in Node_Range then
509          Sprint_Node (Node_Id (Arg));
510
511       else
512          null;
513       end if;
514
515       Write_Eol;
516    end ps;
517
518    --------------------
519    -- Set_Debug_Sloc --
520    --------------------
521
522    procedure Set_Debug_Sloc is
523    begin
524       if Debug_Generated_Code and then Present (Dump_Node) then
525          Set_Sloc (Dump_Node, Debug_Sloc + Source_Ptr (Column - 1));
526          Dump_Node := Empty;
527       end if;
528    end Set_Debug_Sloc;
529
530    -----------------
531    -- Source_Dump --
532    -----------------
533
534    procedure Source_Dump is
535
536       procedure Underline;
537       --  Put underline under string we just printed
538
539       ---------------
540       -- Underline --
541       ---------------
542
543       procedure Underline is
544          Col : constant Int := Column;
545
546       begin
547          Write_Eol;
548
549          while Col > Column loop
550             Write_Char ('-');
551          end loop;
552
553          Write_Eol;
554       end Underline;
555
556    --  Start of processing for Tree_Dump
557
558    begin
559       Dump_Generated_Only := Debug_Flag_G or
560                              Print_Generated_Code or
561                              Debug_Generated_Code;
562       Dump_Original_Only  := Debug_Flag_O;
563       Dump_Freeze_Null    := Debug_Flag_S or Debug_Flag_G;
564
565       --  Note that we turn off the tree dump flags immediately, before
566       --  starting the dump. This avoids generating two copies of the dump
567       --  if an abort occurs after printing the dump, and more importantly,
568       --  avoids an infinite loop if an abort occurs during the dump.
569
570       if Debug_Flag_Z then
571          Current_Source_File := No_Source_File;
572          Debug_Flag_Z := False;
573          Write_Eol;
574          Write_Eol;
575          Write_Str ("Source recreated from tree of Standard (spec)");
576          Underline;
577          Sprint_Node (Standard_Package_Node);
578          Write_Eol;
579          Write_Eol;
580       end if;
581
582       if Debug_Flag_S or Dump_Generated_Only or Dump_Original_Only then
583          Debug_Flag_G := False;
584          Debug_Flag_O := False;
585          Debug_Flag_S := False;
586
587          --  Dump requested units
588
589          for U in Main_Unit .. Last_Unit loop
590             Current_Source_File := Source_Index (U);
591
592             --  Dump all units if -gnatdf set, otherwise we dump only
593             --  the source files that are in the extended main source.
594
595             if Debug_Flag_F
596               or else In_Extended_Main_Source_Unit (Cunit_Entity (U))
597             then
598                --  If we are generating debug files, setup to write them
599
600                if Debug_Generated_Code then
601                   Set_Special_Output (Print_Debug_Line'Access);
602                   Create_Debug_Source (Source_Index (U), Debug_Sloc);
603                   Write_Source_Line (1);
604                   Last_Line_Printed := 1;
605                   Sprint_Node (Cunit (U));
606                   Write_Source_Lines (Last_Source_Line (Current_Source_File));
607                   Write_Eol;
608                   Close_Debug_Source;
609                   Set_Special_Output (null);
610
611                --  Normal output to standard output file
612
613                else
614                   Write_Str ("Source recreated from tree for ");
615                   Write_Unit_Name (Unit_Name (U));
616                   Underline;
617                   Write_Source_Line (1);
618                   Last_Line_Printed := 1;
619                   Sprint_Node (Cunit (U));
620                   Write_Source_Lines (Last_Source_Line (Current_Source_File));
621                   Write_Eol;
622                   Write_Eol;
623                end if;
624             end if;
625          end loop;
626       end if;
627    end Source_Dump;
628
629    ---------------------
630    -- Sprint_And_List --
631    ---------------------
632
633    procedure Sprint_And_List (List : List_Id) is
634       Node : Node_Id;
635    begin
636       if Is_Non_Empty_List (List) then
637          Node := First (List);
638          loop
639             Sprint_Node (Node);
640             Next (Node);
641             exit when Node = Empty;
642             Write_Str (" and ");
643          end loop;
644       end if;
645    end Sprint_And_List;
646
647    ---------------------
648    -- Sprint_Bar_List --
649    ---------------------
650
651    procedure Sprint_Bar_List (List : List_Id) is
652       Node : Node_Id;
653    begin
654       if Is_Non_Empty_List (List) then
655          Node := First (List);
656          loop
657             Sprint_Node (Node);
658             Next (Node);
659             exit when Node = Empty;
660             Write_Str (" | ");
661          end loop;
662       end if;
663    end Sprint_Bar_List;
664
665    ----------------------
666    -- Sprint_End_Label --
667    ----------------------
668
669    procedure Sprint_End_Label
670      (Node    : Node_Id;
671       Default : Node_Id)
672    is
673    begin
674       if Present (Node)
675         and then Present (End_Label (Node))
676         and then Is_Entity_Name (End_Label (Node))
677       then
678          Set_Entity (End_Label (Node), Default);
679
680          --  For a function whose name is an operator, use the qualified name
681          --  created for the defining entity.
682
683          if Nkind (End_Label (Node)) = N_Operator_Symbol then
684             Set_Chars (End_Label (Node), Chars (Default));
685          end if;
686
687          Sprint_Node (End_Label (Node));
688       else
689          Sprint_Node (Default);
690       end if;
691    end Sprint_End_Label;
692
693    -----------------------
694    -- Sprint_Comma_List --
695    -----------------------
696
697    procedure Sprint_Comma_List (List : List_Id) is
698       Node : Node_Id;
699
700    begin
701       if Is_Non_Empty_List (List) then
702          Node := First (List);
703          loop
704             Sprint_Node (Node);
705             Next (Node);
706             exit when Node = Empty;
707
708             if not Is_Rewrite_Insertion (Node)
709               or else not Dump_Original_Only
710             then
711                Write_Str (", ");
712             end if;
713          end loop;
714       end if;
715    end Sprint_Comma_List;
716
717    --------------------------
718    -- Sprint_Indented_List --
719    --------------------------
720
721    procedure Sprint_Indented_List (List : List_Id) is
722    begin
723       Indent_Begin;
724       Sprint_Node_List (List);
725       Indent_End;
726    end Sprint_Indented_List;
727
728    ---------------------
729    -- Sprint_Left_Opnd --
730    ---------------------
731
732    procedure Sprint_Left_Opnd (N : Node_Id) is
733       Opnd : constant Node_Id := Left_Opnd (N);
734
735    begin
736       if Paren_Count (Opnd) /= 0
737         or else Op_Prec (Nkind (Opnd)) >= Op_Prec (Nkind (N))
738       then
739          Sprint_Node (Opnd);
740
741       else
742          Write_Char ('(');
743          Sprint_Node (Opnd);
744          Write_Char (')');
745       end if;
746    end Sprint_Left_Opnd;
747
748    -----------------
749    -- Sprint_Node --
750    -----------------
751
752    procedure Sprint_Node (Node : Node_Id) is
753    begin
754       if Is_Rewrite_Insertion (Node) then
755          if not Dump_Original_Only then
756
757             --  For special cases of nodes that always output <<< >>>
758             --  do not duplicate the output at this point.
759
760             if Nkind (Node) = N_Freeze_Entity
761               or else Nkind (Node) = N_Implicit_Label_Declaration
762             then
763                Sprint_Node_Actual (Node);
764
765             --  Normal case where <<< >>> may be required
766
767             else
768                Write_Rewrite_Str ("<<<");
769                Sprint_Node_Actual (Node);
770                Write_Rewrite_Str (">>>");
771             end if;
772          end if;
773
774       elsif Is_Rewrite_Substitution (Node) then
775
776          --  Case of dump generated only
777
778          if Dump_Generated_Only then
779             Sprint_Node_Actual (Node);
780
781          --  Case of dump original only
782
783          elsif Dump_Original_Only then
784             Sprint_Node_Actual (Original_Node (Node));
785
786          --  Case of both being dumped
787
788          else
789             Sprint_Node_Actual (Original_Node (Node));
790             Write_Rewrite_Str ("<<<");
791             Sprint_Node_Actual (Node);
792             Write_Rewrite_Str (">>>");
793          end if;
794
795       else
796          Sprint_Node_Actual (Node);
797       end if;
798    end Sprint_Node;
799
800    ------------------------
801    -- Sprint_Node_Actual --
802    ------------------------
803
804    procedure Sprint_Node_Actual (Node : Node_Id) is
805       Save_Dump_Node : constant Node_Id := Dump_Node;
806
807    begin
808       if Node = Empty then
809          return;
810       end if;
811
812       for J in 1 .. Paren_Count (Node) loop
813          Write_Str_With_Col_Check ("(");
814       end loop;
815
816       --  Setup current dump node
817
818       Dump_Node := Node;
819
820       if Nkind (Node) in N_Subexpr
821         and then Do_Range_Check (Node)
822       then
823          Write_Str_With_Col_Check ("{");
824       end if;
825
826       --  Select print circuit based on node kind
827
828       case Nkind (Node) is
829
830          when N_Abort_Statement =>
831             Write_Indent_Str_Sloc ("abort ");
832             Sprint_Comma_List (Names (Node));
833             Write_Char (';');
834
835          when N_Abortable_Part =>
836             Set_Debug_Sloc;
837             Write_Str_Sloc ("abort ");
838             Sprint_Indented_List (Statements (Node));
839
840          when N_Abstract_Subprogram_Declaration =>
841             Write_Indent;
842             Sprint_Node (Specification (Node));
843             Write_Str_With_Col_Check (" is ");
844             Write_Str_Sloc ("abstract;");
845
846          when N_Accept_Alternative =>
847             Sprint_Node_List (Pragmas_Before (Node));
848
849             if Present (Condition (Node)) then
850                Write_Indent_Str ("when ");
851                Sprint_Node (Condition (Node));
852                Write_Str (" => ");
853                Indent_Annull;
854             end if;
855
856             Sprint_Node_Sloc (Accept_Statement (Node));
857             Sprint_Node_List (Statements (Node));
858
859          when N_Accept_Statement =>
860             Write_Indent_Str_Sloc ("accept ");
861             Write_Id (Entry_Direct_Name (Node));
862
863             if Present (Entry_Index (Node)) then
864                Write_Str_With_Col_Check (" (");
865                Sprint_Node (Entry_Index (Node));
866                Write_Char (')');
867             end if;
868
869             Write_Param_Specs (Node);
870
871             if Present (Handled_Statement_Sequence (Node)) then
872                Write_Str_With_Col_Check (" do");
873                Sprint_Node (Handled_Statement_Sequence (Node));
874                Write_Indent_Str ("end ");
875                Write_Id (Entry_Direct_Name (Node));
876             end if;
877
878             Write_Char (';');
879
880          when N_Access_Definition =>
881
882             --  Ada 2005 (AI-254)
883
884             if Present (Access_To_Subprogram_Definition (Node)) then
885                Sprint_Node (Access_To_Subprogram_Definition (Node));
886             else
887                --  Ada 2005 (AI-231)
888
889                if Null_Exclusion_Present (Node) then
890                   Write_Str ("not null ");
891                end if;
892
893                Write_Str_With_Col_Check_Sloc ("access ");
894
895                if All_Present (Node) then
896                   Write_Str ("all ");
897                elsif Constant_Present (Node) then
898                   Write_Str ("constant ");
899                end if;
900
901                Sprint_Node (Subtype_Mark (Node));
902             end if;
903
904          when N_Access_Function_Definition =>
905
906             --  Ada 2005 (AI-231)
907
908             if Null_Exclusion_Present (Node) then
909                Write_Str ("not null ");
910             end if;
911
912             Write_Str_With_Col_Check_Sloc ("access ");
913
914             if Protected_Present (Node) then
915                Write_Str_With_Col_Check ("protected ");
916             end if;
917
918             Write_Str_With_Col_Check ("function");
919             Write_Param_Specs (Node);
920             Write_Str_With_Col_Check (" return ");
921             Sprint_Node (Result_Definition (Node));
922
923          when N_Access_Procedure_Definition =>
924
925             --  Ada 2005 (AI-231)
926
927             if Null_Exclusion_Present (Node) then
928                Write_Str ("not null ");
929             end if;
930
931             Write_Str_With_Col_Check_Sloc ("access ");
932
933             if Protected_Present (Node) then
934                Write_Str_With_Col_Check ("protected ");
935             end if;
936
937             Write_Str_With_Col_Check ("procedure");
938             Write_Param_Specs (Node);
939
940          when N_Access_To_Object_Definition =>
941             Write_Str_With_Col_Check_Sloc ("access ");
942
943             if All_Present (Node) then
944                Write_Str_With_Col_Check ("all ");
945             elsif Constant_Present (Node) then
946                Write_Str_With_Col_Check ("constant ");
947             end if;
948
949             --  Ada 2005 (AI-231)
950
951             if Null_Exclusion_Present (Node) then
952                Write_Str ("not null ");
953             end if;
954
955             Sprint_Node (Subtype_Indication (Node));
956
957          when N_Aggregate =>
958             if Null_Record_Present (Node) then
959                Write_Str_With_Col_Check_Sloc ("(null record)");
960
961             else
962                Write_Str_With_Col_Check_Sloc ("(");
963
964                if Present (Expressions (Node)) then
965                   Sprint_Comma_List (Expressions (Node));
966
967                   if Present (Component_Associations (Node)) then
968                      Write_Str (", ");
969                   end if;
970                end if;
971
972                if Present (Component_Associations (Node)) then
973                   Indent_Begin;
974
975                   declare
976                      Nd : Node_Id;
977
978                   begin
979                      Nd := First (Component_Associations (Node));
980
981                      loop
982                         Write_Indent;
983                         Sprint_Node (Nd);
984                         Next (Nd);
985                         exit when No (Nd);
986
987                         if not Is_Rewrite_Insertion (Nd)
988                           or else not Dump_Original_Only
989                         then
990                            Write_Str (", ");
991                         end if;
992                      end loop;
993                   end;
994
995                   Indent_End;
996                end if;
997
998                Write_Char (')');
999             end if;
1000
1001          when N_Allocator =>
1002             Write_Str_With_Col_Check_Sloc ("new ");
1003
1004             --  Ada 2005 (AI-231)
1005
1006             if Null_Exclusion_Present (Node) then
1007                Write_Str ("not null ");
1008             end if;
1009
1010             Sprint_Node (Expression (Node));
1011
1012             if Present (Storage_Pool (Node)) then
1013                Write_Str_With_Col_Check ("[storage_pool = ");
1014                Sprint_Node (Storage_Pool (Node));
1015                Write_Char (']');
1016             end if;
1017
1018          when N_And_Then =>
1019             Sprint_Left_Opnd (Node);
1020             Write_Str_Sloc (" and then ");
1021             Sprint_Right_Opnd (Node);
1022
1023          when N_At_Clause =>
1024             Write_Indent_Str_Sloc ("for ");
1025             Write_Id (Identifier (Node));
1026             Write_Str_With_Col_Check (" use at ");
1027             Sprint_Node (Expression (Node));
1028             Write_Char (';');
1029
1030          when N_Assignment_Statement =>
1031             Write_Indent;
1032             Sprint_Node (Name (Node));
1033             Write_Str_Sloc (" := ");
1034             Sprint_Node (Expression (Node));
1035             Write_Char (';');
1036
1037          when N_Asynchronous_Select =>
1038             Write_Indent_Str_Sloc ("select");
1039             Indent_Begin;
1040             Sprint_Node (Triggering_Alternative (Node));
1041             Indent_End;
1042
1043             --  Note: let the printing of Abortable_Part handle outputting
1044             --  the ABORT keyword, so that the Sloc can be set correctly.
1045
1046             Write_Indent_Str ("then ");
1047             Sprint_Node (Abortable_Part (Node));
1048             Write_Indent_Str ("end select;");
1049
1050          when N_Attribute_Definition_Clause =>
1051             Write_Indent_Str_Sloc ("for ");
1052             Sprint_Node (Name (Node));
1053             Write_Char (''');
1054             Write_Name_With_Col_Check (Chars (Node));
1055             Write_Str_With_Col_Check (" use ");
1056             Sprint_Node (Expression (Node));
1057             Write_Char (';');
1058
1059          when N_Attribute_Reference =>
1060             if Is_Procedure_Attribute_Name (Attribute_Name (Node)) then
1061                Write_Indent;
1062             end if;
1063
1064             Sprint_Node (Prefix (Node));
1065             Write_Char_Sloc (''');
1066             Write_Name_With_Col_Check (Attribute_Name (Node));
1067             Sprint_Paren_Comma_List (Expressions (Node));
1068
1069             if Is_Procedure_Attribute_Name (Attribute_Name (Node)) then
1070                Write_Char (';');
1071             end if;
1072
1073          when N_Block_Statement =>
1074             Write_Indent;
1075
1076             if Present (Identifier (Node))
1077               and then (not Has_Created_Identifier (Node)
1078                           or else not Dump_Original_Only)
1079             then
1080                Write_Rewrite_Str ("<<<");
1081                Write_Id (Identifier (Node));
1082                Write_Str (" : ");
1083                Write_Rewrite_Str (">>>");
1084             end if;
1085
1086             if Present (Declarations (Node)) then
1087                Write_Str_With_Col_Check_Sloc ("declare");
1088                Sprint_Indented_List (Declarations (Node));
1089                Write_Indent;
1090             end if;
1091
1092             Write_Str_With_Col_Check_Sloc ("begin");
1093             Sprint_Node (Handled_Statement_Sequence (Node));
1094             Write_Indent_Str ("end");
1095
1096             if Present (Identifier (Node))
1097               and then (not Has_Created_Identifier (Node)
1098                           or else not Dump_Original_Only)
1099             then
1100                Write_Rewrite_Str ("<<<");
1101                Write_Char (' ');
1102                Write_Id (Identifier (Node));
1103                Write_Rewrite_Str (">>>");
1104             end if;
1105
1106             Write_Char (';');
1107
1108          when N_Case_Statement =>
1109             Write_Indent_Str_Sloc ("case ");
1110             Sprint_Node (Expression (Node));
1111             Write_Str (" is");
1112             Sprint_Indented_List (Alternatives (Node));
1113             Write_Indent_Str ("end case;");
1114
1115          when N_Case_Statement_Alternative =>
1116             Write_Indent_Str_Sloc ("when ");
1117             Sprint_Bar_List (Discrete_Choices (Node));
1118             Write_Str (" => ");
1119             Sprint_Indented_List (Statements (Node));
1120
1121          when N_Character_Literal =>
1122             if Column > 70 then
1123                Write_Indent_Str ("  ");
1124             end if;
1125
1126             Write_Char_Sloc (''');
1127             Write_Char_Code (UI_To_CC (Char_Literal_Value (Node)));
1128             Write_Char (''');
1129
1130          when N_Code_Statement =>
1131             Write_Indent;
1132             Set_Debug_Sloc;
1133             Sprint_Node (Expression (Node));
1134             Write_Char (';');
1135
1136          when N_Compilation_Unit =>
1137             Sprint_Node_List (Context_Items (Node));
1138             Sprint_Opt_Node_List (Declarations (Aux_Decls_Node (Node)));
1139
1140             if Private_Present (Node) then
1141                Write_Indent_Str ("private ");
1142                Indent_Annull;
1143             end if;
1144
1145             Sprint_Node_Sloc (Unit (Node));
1146
1147             if Present (Actions (Aux_Decls_Node (Node)))
1148                  or else
1149                Present (Pragmas_After (Aux_Decls_Node (Node)))
1150             then
1151                Write_Indent;
1152             end if;
1153
1154             Sprint_Opt_Node_List (Actions (Aux_Decls_Node (Node)));
1155             Sprint_Opt_Node_List (Pragmas_After (Aux_Decls_Node (Node)));
1156
1157          when N_Compilation_Unit_Aux =>
1158             null; -- nothing to do, never used, see above
1159
1160          when N_Component_Association =>
1161             Set_Debug_Sloc;
1162             Sprint_Bar_List (Choices (Node));
1163             Write_Str (" => ");
1164
1165             --  Ada 2005 (AI-287): Print the box if present
1166
1167             if Box_Present (Node) then
1168                Write_Str_With_Col_Check ("<>");
1169             else
1170                Sprint_Node (Expression (Node));
1171             end if;
1172
1173          when N_Component_Clause =>
1174             Write_Indent;
1175             Sprint_Node (Component_Name (Node));
1176             Write_Str_Sloc (" at ");
1177             Sprint_Node (Position (Node));
1178             Write_Char (' ');
1179             Write_Str_With_Col_Check ("range ");
1180             Sprint_Node (First_Bit (Node));
1181             Write_Str (" .. ");
1182             Sprint_Node (Last_Bit (Node));
1183             Write_Char (';');
1184
1185          when N_Component_Definition =>
1186             Set_Debug_Sloc;
1187
1188             --  Ada 2005 (AI-230): Access definition components
1189
1190             if Present (Access_Definition (Node)) then
1191                Sprint_Node (Access_Definition (Node));
1192
1193             elsif Present (Subtype_Indication (Node)) then
1194                if Aliased_Present (Node) then
1195                   Write_Str_With_Col_Check ("aliased ");
1196                end if;
1197
1198                --  Ada 2005 (AI-231)
1199
1200                if Null_Exclusion_Present (Node) then
1201                   Write_Str (" not null ");
1202                end if;
1203
1204                Sprint_Node (Subtype_Indication (Node));
1205
1206             else
1207                Write_Str (" ??? ");
1208             end if;
1209
1210          when N_Component_Declaration =>
1211             if Write_Indent_Identifiers_Sloc (Node) then
1212                Write_Str (" : ");
1213                Sprint_Node (Component_Definition (Node));
1214
1215                if Present (Expression (Node)) then
1216                   Write_Str (" := ");
1217                   Sprint_Node (Expression (Node));
1218                end if;
1219
1220                Write_Char (';');
1221             end if;
1222
1223          when N_Component_List =>
1224             if Null_Present (Node) then
1225                Indent_Begin;
1226                Write_Indent_Str_Sloc ("null");
1227                Write_Char (';');
1228                Indent_End;
1229
1230             else
1231                Set_Debug_Sloc;
1232                Sprint_Indented_List (Component_Items (Node));
1233                Sprint_Node (Variant_Part (Node));
1234             end if;
1235
1236          when N_Conditional_Entry_Call =>
1237             Write_Indent_Str_Sloc ("select");
1238             Indent_Begin;
1239             Sprint_Node (Entry_Call_Alternative (Node));
1240             Indent_End;
1241             Write_Indent_Str ("else");
1242             Sprint_Indented_List (Else_Statements (Node));
1243             Write_Indent_Str ("end select;");
1244
1245          when N_Conditional_Expression =>
1246             declare
1247                Condition : constant Node_Id := First (Expressions (Node));
1248                Then_Expr : constant Node_Id := Next (Condition);
1249                Else_Expr : constant Node_Id := Next (Then_Expr);
1250             begin
1251                Write_Str_With_Col_Check_Sloc ("(if ");
1252                Sprint_Node (Condition);
1253                Write_Str_With_Col_Check (" then ");
1254                Sprint_Node (Then_Expr);
1255                Write_Str_With_Col_Check (" else ");
1256                Sprint_Node (Else_Expr);
1257                Write_Char (')');
1258             end;
1259
1260          when N_Constrained_Array_Definition =>
1261             Write_Str_With_Col_Check_Sloc ("array ");
1262             Sprint_Paren_Comma_List (Discrete_Subtype_Definitions (Node));
1263             Write_Str (" of ");
1264
1265             Sprint_Node (Component_Definition (Node));
1266
1267          when N_Decimal_Fixed_Point_Definition =>
1268             Write_Str_With_Col_Check_Sloc (" delta ");
1269             Sprint_Node (Delta_Expression (Node));
1270             Write_Str_With_Col_Check ("digits ");
1271             Sprint_Node (Digits_Expression (Node));
1272             Sprint_Opt_Node (Real_Range_Specification (Node));
1273
1274          when N_Defining_Character_Literal =>
1275             Write_Name_With_Col_Check_Sloc (Chars (Node));
1276
1277          when N_Defining_Identifier =>
1278             Set_Debug_Sloc;
1279             Write_Id (Node);
1280
1281          when N_Defining_Operator_Symbol =>
1282             Write_Name_With_Col_Check_Sloc (Chars (Node));
1283
1284          when N_Defining_Program_Unit_Name =>
1285             Set_Debug_Sloc;
1286             Sprint_Node (Name (Node));
1287             Write_Char ('.');
1288             Write_Id (Defining_Identifier (Node));
1289
1290          when N_Delay_Alternative =>
1291             Sprint_Node_List (Pragmas_Before (Node));
1292
1293             if Present (Condition (Node)) then
1294                Write_Indent;
1295                Write_Str_With_Col_Check ("when ");
1296                Sprint_Node (Condition (Node));
1297                Write_Str (" => ");
1298                Indent_Annull;
1299             end if;
1300
1301             Sprint_Node_Sloc (Delay_Statement (Node));
1302             Sprint_Node_List (Statements (Node));
1303
1304          when N_Delay_Relative_Statement =>
1305             Write_Indent_Str_Sloc ("delay ");
1306             Sprint_Node (Expression (Node));
1307             Write_Char (';');
1308
1309          when N_Delay_Until_Statement =>
1310             Write_Indent_Str_Sloc ("delay until ");
1311             Sprint_Node (Expression (Node));
1312             Write_Char (';');
1313
1314          when N_Delta_Constraint =>
1315             Write_Str_With_Col_Check_Sloc ("delta ");
1316             Sprint_Node (Delta_Expression (Node));
1317             Sprint_Opt_Node (Range_Constraint (Node));
1318
1319          when N_Derived_Type_Definition =>
1320             if Abstract_Present (Node) then
1321                Write_Str_With_Col_Check ("abstract ");
1322             end if;
1323
1324             Write_Str_With_Col_Check_Sloc ("new ");
1325
1326             --  Ada 2005 (AI-231)
1327
1328             if Null_Exclusion_Present (Node) then
1329                Write_Str_With_Col_Check ("not null ");
1330             end if;
1331
1332             Sprint_Node (Subtype_Indication (Node));
1333
1334             if Present (Interface_List (Node)) then
1335                Write_Str_With_Col_Check (" and ");
1336                Sprint_And_List (Interface_List (Node));
1337                Write_Str_With_Col_Check (" with ");
1338             end if;
1339
1340             if Present (Record_Extension_Part (Node)) then
1341                if No (Interface_List (Node)) then
1342                   Write_Str_With_Col_Check (" with ");
1343                end if;
1344
1345                Sprint_Node (Record_Extension_Part (Node));
1346             end if;
1347
1348          when N_Designator =>
1349             Sprint_Node (Name (Node));
1350             Write_Char_Sloc ('.');
1351             Write_Id (Identifier (Node));
1352
1353          when N_Digits_Constraint =>
1354             Write_Str_With_Col_Check_Sloc ("digits ");
1355             Sprint_Node (Digits_Expression (Node));
1356             Sprint_Opt_Node (Range_Constraint (Node));
1357
1358          when N_Discriminant_Association =>
1359             Set_Debug_Sloc;
1360
1361             if Present (Selector_Names (Node)) then
1362                Sprint_Bar_List (Selector_Names (Node));
1363                Write_Str (" => ");
1364             end if;
1365
1366             Set_Debug_Sloc;
1367             Sprint_Node (Expression (Node));
1368
1369          when N_Discriminant_Specification =>
1370             Set_Debug_Sloc;
1371
1372             if Write_Identifiers (Node) then
1373                Write_Str (" : ");
1374
1375                if Null_Exclusion_Present (Node) then
1376                   Write_Str ("not null ");
1377                end if;
1378
1379                Sprint_Node (Discriminant_Type (Node));
1380
1381                if Present (Expression (Node)) then
1382                   Write_Str (" := ");
1383                   Sprint_Node (Expression (Node));
1384                end if;
1385             else
1386                Write_Str (", ");
1387             end if;
1388
1389          when N_Elsif_Part =>
1390             Write_Indent_Str_Sloc ("elsif ");
1391             Sprint_Node (Condition (Node));
1392             Write_Str_With_Col_Check (" then");
1393             Sprint_Indented_List (Then_Statements (Node));
1394
1395          when N_Empty =>
1396             null;
1397
1398          when N_Entry_Body =>
1399             Write_Indent_Str_Sloc ("entry ");
1400             Write_Id (Defining_Identifier (Node));
1401             Sprint_Node (Entry_Body_Formal_Part (Node));
1402             Write_Str_With_Col_Check (" is");
1403             Sprint_Indented_List (Declarations (Node));
1404             Write_Indent_Str ("begin");
1405             Sprint_Node (Handled_Statement_Sequence (Node));
1406             Write_Indent_Str ("end ");
1407             Write_Id (Defining_Identifier (Node));
1408             Write_Char (';');
1409
1410          when N_Entry_Body_Formal_Part =>
1411             if Present (Entry_Index_Specification (Node)) then
1412                Write_Str_With_Col_Check_Sloc (" (");
1413                Sprint_Node (Entry_Index_Specification (Node));
1414                Write_Char (')');
1415             end if;
1416
1417             Write_Param_Specs (Node);
1418             Write_Str_With_Col_Check_Sloc (" when ");
1419             Sprint_Node (Condition (Node));
1420
1421          when N_Entry_Call_Alternative =>
1422             Sprint_Node_List (Pragmas_Before (Node));
1423             Sprint_Node_Sloc (Entry_Call_Statement (Node));
1424             Sprint_Node_List (Statements (Node));
1425
1426          when N_Entry_Call_Statement =>
1427             Write_Indent;
1428             Sprint_Node_Sloc (Name (Node));
1429             Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
1430             Write_Char (';');
1431
1432          when N_Entry_Declaration =>
1433             Write_Indent_Str_Sloc ("entry ");
1434             Write_Id (Defining_Identifier (Node));
1435
1436             if Present (Discrete_Subtype_Definition (Node)) then
1437                Write_Str_With_Col_Check (" (");
1438                Sprint_Node (Discrete_Subtype_Definition (Node));
1439                Write_Char (')');
1440             end if;
1441
1442             Write_Param_Specs (Node);
1443             Write_Char (';');
1444
1445          when N_Entry_Index_Specification =>
1446             Write_Str_With_Col_Check_Sloc ("for ");
1447             Write_Id (Defining_Identifier (Node));
1448             Write_Str_With_Col_Check (" in ");
1449             Sprint_Node (Discrete_Subtype_Definition (Node));
1450
1451          when N_Enumeration_Representation_Clause =>
1452             Write_Indent_Str_Sloc ("for ");
1453             Write_Id (Identifier (Node));
1454             Write_Str_With_Col_Check (" use ");
1455             Sprint_Node (Array_Aggregate (Node));
1456             Write_Char (';');
1457
1458          when N_Enumeration_Type_Definition =>
1459             Set_Debug_Sloc;
1460
1461             --  Skip attempt to print Literals field if it's not there and
1462             --  we are in package Standard (case of Character, which is
1463             --  handled specially (without an explicit literals list).
1464
1465             if Sloc (Node) > Standard_Location
1466               or else Present (Literals (Node))
1467             then
1468                Sprint_Paren_Comma_List (Literals (Node));
1469             end if;
1470
1471          when N_Error =>
1472             Write_Str_With_Col_Check_Sloc ("<error>");
1473
1474          when N_Exception_Declaration =>
1475             if Write_Indent_Identifiers (Node) then
1476                Write_Str_With_Col_Check (" : ");
1477
1478                if Is_Statically_Allocated (Defining_Identifier (Node)) then
1479                   Write_Str_With_Col_Check ("static ");
1480                end if;
1481
1482                Write_Str_Sloc ("exception");
1483
1484                if Present (Expression (Node)) then
1485                   Write_Str (" := ");
1486                   Sprint_Node (Expression (Node));
1487                end if;
1488
1489                Write_Char (';');
1490             end if;
1491
1492          when N_Exception_Handler =>
1493             Write_Indent_Str_Sloc ("when ");
1494
1495             if Present (Choice_Parameter (Node)) then
1496                Sprint_Node (Choice_Parameter (Node));
1497                Write_Str (" : ");
1498             end if;
1499
1500             Sprint_Bar_List (Exception_Choices (Node));
1501             Write_Str (" => ");
1502             Sprint_Indented_List (Statements (Node));
1503
1504          when N_Exception_Renaming_Declaration =>
1505             Write_Indent;
1506             Set_Debug_Sloc;
1507             Sprint_Node (Defining_Identifier (Node));
1508             Write_Str_With_Col_Check (" : exception renames ");
1509             Sprint_Node (Name (Node));
1510             Write_Char (';');
1511
1512          when N_Exit_Statement =>
1513             Write_Indent_Str_Sloc ("exit");
1514             Sprint_Opt_Node (Name (Node));
1515
1516             if Present (Condition (Node)) then
1517                Write_Str_With_Col_Check (" when ");
1518                Sprint_Node (Condition (Node));
1519             end if;
1520
1521             Write_Char (';');
1522
1523          when N_Expanded_Name =>
1524             Sprint_Node (Prefix (Node));
1525             Write_Char_Sloc ('.');
1526             Sprint_Node (Selector_Name (Node));
1527
1528          when N_Explicit_Dereference =>
1529             Sprint_Node (Prefix (Node));
1530             Write_Char_Sloc ('.');
1531             Write_Str_Sloc ("all");
1532
1533          when N_Extended_Return_Statement =>
1534             Write_Indent_Str_Sloc ("return ");
1535             Sprint_Node_List (Return_Object_Declarations (Node));
1536
1537             if Present (Handled_Statement_Sequence (Node)) then
1538                Write_Str_With_Col_Check (" do");
1539                Sprint_Node (Handled_Statement_Sequence (Node));
1540                Write_Indent_Str ("end return;");
1541             else
1542                Write_Indent_Str (";");
1543             end if;
1544
1545          when N_Extension_Aggregate =>
1546             Write_Str_With_Col_Check_Sloc ("(");
1547             Sprint_Node (Ancestor_Part (Node));
1548             Write_Str_With_Col_Check (" with ");
1549
1550             if Null_Record_Present (Node) then
1551                Write_Str_With_Col_Check ("null record");
1552             else
1553                if Present (Expressions (Node)) then
1554                   Sprint_Comma_List (Expressions (Node));
1555
1556                   if Present (Component_Associations (Node)) then
1557                      Write_Str (", ");
1558                   end if;
1559                end if;
1560
1561                if Present (Component_Associations (Node)) then
1562                   Sprint_Comma_List (Component_Associations (Node));
1563                end if;
1564             end if;
1565
1566             Write_Char (')');
1567
1568          when N_Floating_Point_Definition =>
1569             Write_Str_With_Col_Check_Sloc ("digits ");
1570             Sprint_Node (Digits_Expression (Node));
1571             Sprint_Opt_Node (Real_Range_Specification (Node));
1572
1573          when N_Formal_Decimal_Fixed_Point_Definition =>
1574             Write_Str_With_Col_Check_Sloc ("delta <> digits <>");
1575
1576          when N_Formal_Derived_Type_Definition =>
1577             Write_Str_With_Col_Check_Sloc ("new ");
1578             Sprint_Node (Subtype_Mark (Node));
1579
1580             if Private_Present (Node) then
1581                Write_Str_With_Col_Check (" with private");
1582             end if;
1583
1584          when N_Formal_Abstract_Subprogram_Declaration =>
1585             Write_Indent_Str_Sloc ("with ");
1586             Sprint_Node (Specification (Node));
1587
1588             Write_Str_With_Col_Check (" is abstract");
1589
1590             if Box_Present (Node) then
1591                Write_Str_With_Col_Check (" <>");
1592             elsif Present (Default_Name (Node)) then
1593                Write_Str_With_Col_Check (" ");
1594                Sprint_Node (Default_Name (Node));
1595             end if;
1596
1597             Write_Char (';');
1598
1599          when N_Formal_Concrete_Subprogram_Declaration =>
1600             Write_Indent_Str_Sloc ("with ");
1601             Sprint_Node (Specification (Node));
1602
1603             if Box_Present (Node) then
1604                Write_Str_With_Col_Check (" is <>");
1605             elsif Present (Default_Name (Node)) then
1606                Write_Str_With_Col_Check (" is ");
1607                Sprint_Node (Default_Name (Node));
1608             end if;
1609
1610             Write_Char (';');
1611
1612          when N_Formal_Discrete_Type_Definition =>
1613             Write_Str_With_Col_Check_Sloc ("<>");
1614
1615          when N_Formal_Floating_Point_Definition =>
1616             Write_Str_With_Col_Check_Sloc ("digits <>");
1617
1618          when N_Formal_Modular_Type_Definition =>
1619             Write_Str_With_Col_Check_Sloc ("mod <>");
1620
1621          when N_Formal_Object_Declaration =>
1622             Set_Debug_Sloc;
1623
1624             if Write_Indent_Identifiers (Node) then
1625                Write_Str (" : ");
1626
1627                if In_Present (Node) then
1628                   Write_Str_With_Col_Check ("in ");
1629                end if;
1630
1631                if Out_Present (Node) then
1632                   Write_Str_With_Col_Check ("out ");
1633                end if;
1634
1635                if Present (Subtype_Mark (Node)) then
1636
1637                   --  Ada 2005 (AI-423): Formal object with null exclusion
1638
1639                   if Null_Exclusion_Present (Node) then
1640                      Write_Str ("not null ");
1641                   end if;
1642
1643                   Sprint_Node (Subtype_Mark (Node));
1644
1645                --  Ada 2005 (AI-423): Formal object with access definition
1646
1647                else
1648                   pragma Assert (Present (Access_Definition (Node)));
1649
1650                   Sprint_Node (Access_Definition (Node));
1651                end if;
1652
1653                if Present (Default_Expression (Node)) then
1654                   Write_Str (" := ");
1655                   Sprint_Node (Default_Expression (Node));
1656                end if;
1657
1658                Write_Char (';');
1659             end if;
1660
1661          when N_Formal_Ordinary_Fixed_Point_Definition =>
1662             Write_Str_With_Col_Check_Sloc ("delta <>");
1663
1664          when N_Formal_Package_Declaration =>
1665             Write_Indent_Str_Sloc ("with package ");
1666             Write_Id (Defining_Identifier (Node));
1667             Write_Str_With_Col_Check (" is new ");
1668             Sprint_Node (Name (Node));
1669             Write_Str_With_Col_Check (" (<>);");
1670
1671          when N_Formal_Private_Type_Definition =>
1672             if Abstract_Present (Node) then
1673                Write_Str_With_Col_Check ("abstract ");
1674             end if;
1675
1676             if Tagged_Present (Node) then
1677                Write_Str_With_Col_Check ("tagged ");
1678             end if;
1679
1680             if Limited_Present (Node) then
1681                Write_Str_With_Col_Check ("limited ");
1682             end if;
1683
1684             Write_Str_With_Col_Check_Sloc ("private");
1685
1686          when N_Formal_Signed_Integer_Type_Definition =>
1687             Write_Str_With_Col_Check_Sloc ("range <>");
1688
1689          when N_Formal_Type_Declaration =>
1690             Write_Indent_Str_Sloc ("type ");
1691             Write_Id (Defining_Identifier (Node));
1692
1693             if Present (Discriminant_Specifications (Node)) then
1694                Write_Discr_Specs (Node);
1695             elsif Unknown_Discriminants_Present (Node) then
1696                Write_Str_With_Col_Check ("(<>)");
1697             end if;
1698
1699             Write_Str_With_Col_Check (" is ");
1700             Sprint_Node (Formal_Type_Definition (Node));
1701             Write_Char (';');
1702
1703          when N_Free_Statement =>
1704             Write_Indent_Str_Sloc ("free ");
1705             Sprint_Node (Expression (Node));
1706             Write_Char (';');
1707
1708          when N_Freeze_Entity =>
1709             if Dump_Original_Only then
1710                null;
1711
1712             elsif Present (Actions (Node)) or else Dump_Freeze_Null then
1713                Write_Indent;
1714                Write_Rewrite_Str ("<<<");
1715                Write_Str_With_Col_Check_Sloc ("freeze ");
1716                Write_Id (Entity (Node));
1717                Write_Str (" [");
1718
1719                if No (Actions (Node)) then
1720                   Write_Char (']');
1721
1722                else
1723                   --  Output freeze actions. We increment Freeze_Indent during
1724                   --  this output to avoid generating extra blank lines before
1725                   --  any procedures included in the freeze actions.
1726
1727                   Freeze_Indent := Freeze_Indent + 1;
1728                   Sprint_Indented_List (Actions (Node));
1729                   Freeze_Indent := Freeze_Indent - 1;
1730                   Write_Indent_Str ("]");
1731                end if;
1732
1733                Write_Rewrite_Str (">>>");
1734             end if;
1735
1736          when N_Full_Type_Declaration =>
1737             Write_Indent_Str_Sloc ("type ");
1738             Sprint_Node (Defining_Identifier (Node));
1739             Write_Discr_Specs (Node);
1740             Write_Str_With_Col_Check (" is ");
1741             Sprint_Node (Type_Definition (Node));
1742             Write_Char (';');
1743
1744          when N_Function_Call =>
1745             Set_Debug_Sloc;
1746             Note_Implicit_Run_Time_Call (Name (Node));
1747             Sprint_Node (Name (Node));
1748             Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
1749
1750          when N_Function_Instantiation =>
1751             Write_Indent_Str_Sloc ("function ");
1752             Sprint_Node (Defining_Unit_Name (Node));
1753             Write_Str_With_Col_Check (" is new ");
1754             Sprint_Node (Name (Node));
1755             Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
1756             Write_Char (';');
1757
1758          when N_Function_Specification =>
1759             Write_Str_With_Col_Check_Sloc ("function ");
1760             Sprint_Node (Defining_Unit_Name (Node));
1761             Write_Param_Specs (Node);
1762             Write_Str_With_Col_Check (" return ");
1763
1764             --  Ada 2005 (AI-231)
1765
1766             if Nkind (Result_Definition (Node)) /= N_Access_Definition
1767               and then Null_Exclusion_Present (Node)
1768             then
1769                Write_Str (" not null ");
1770             end if;
1771
1772             Sprint_Node (Result_Definition (Node));
1773
1774          when N_Generic_Association =>
1775             Set_Debug_Sloc;
1776
1777             if Present (Selector_Name (Node)) then
1778                Sprint_Node (Selector_Name (Node));
1779                Write_Str (" => ");
1780             end if;
1781
1782             Sprint_Node (Explicit_Generic_Actual_Parameter (Node));
1783
1784          when N_Generic_Function_Renaming_Declaration =>
1785             Write_Indent_Str_Sloc ("generic function ");
1786             Sprint_Node (Defining_Unit_Name (Node));
1787             Write_Str_With_Col_Check (" renames ");
1788             Sprint_Node (Name (Node));
1789             Write_Char (';');
1790
1791          when N_Generic_Package_Declaration =>
1792             Extra_Blank_Line;
1793             Write_Indent_Str_Sloc ("generic ");
1794             Sprint_Indented_List (Generic_Formal_Declarations (Node));
1795             Write_Indent;
1796             Sprint_Node (Specification (Node));
1797             Write_Char (';');
1798
1799          when N_Generic_Package_Renaming_Declaration =>
1800             Write_Indent_Str_Sloc ("generic package ");
1801             Sprint_Node (Defining_Unit_Name (Node));
1802             Write_Str_With_Col_Check (" renames ");
1803             Sprint_Node (Name (Node));
1804             Write_Char (';');
1805
1806          when N_Generic_Procedure_Renaming_Declaration =>
1807             Write_Indent_Str_Sloc ("generic procedure ");
1808             Sprint_Node (Defining_Unit_Name (Node));
1809             Write_Str_With_Col_Check (" renames ");
1810             Sprint_Node (Name (Node));
1811             Write_Char (';');
1812
1813          when N_Generic_Subprogram_Declaration =>
1814             Extra_Blank_Line;
1815             Write_Indent_Str_Sloc ("generic ");
1816             Sprint_Indented_List (Generic_Formal_Declarations (Node));
1817             Write_Indent;
1818             Sprint_Node (Specification (Node));
1819             Write_Char (';');
1820
1821          when N_Goto_Statement =>
1822             Write_Indent_Str_Sloc ("goto ");
1823             Sprint_Node (Name (Node));
1824             Write_Char (';');
1825
1826             if Nkind (Next (Node)) = N_Label then
1827                Write_Indent;
1828             end if;
1829
1830          when N_Handled_Sequence_Of_Statements =>
1831             Set_Debug_Sloc;
1832             Sprint_Indented_List (Statements (Node));
1833
1834             if Present (Exception_Handlers (Node)) then
1835                Write_Indent_Str ("exception");
1836                Indent_Begin;
1837                Sprint_Node_List (Exception_Handlers (Node));
1838                Indent_End;
1839             end if;
1840
1841             if Present (At_End_Proc (Node)) then
1842                Write_Indent_Str ("at end");
1843                Indent_Begin;
1844                Write_Indent;
1845                Sprint_Node (At_End_Proc (Node));
1846                Write_Char (';');
1847                Indent_End;
1848             end if;
1849
1850          when N_Identifier =>
1851             Set_Debug_Sloc;
1852             Write_Id (Node);
1853
1854          when N_If_Statement =>
1855             Write_Indent_Str_Sloc ("if ");
1856             Sprint_Node (Condition (Node));
1857             Write_Str_With_Col_Check (" then");
1858             Sprint_Indented_List (Then_Statements (Node));
1859             Sprint_Opt_Node_List (Elsif_Parts (Node));
1860
1861             if Present (Else_Statements (Node)) then
1862                Write_Indent_Str ("else");
1863                Sprint_Indented_List (Else_Statements (Node));
1864             end if;
1865
1866             Write_Indent_Str ("end if;");
1867
1868          when N_Implicit_Label_Declaration =>
1869             if not Dump_Original_Only then
1870                Write_Indent;
1871                Write_Rewrite_Str ("<<<");
1872                Set_Debug_Sloc;
1873                Write_Id (Defining_Identifier (Node));
1874                Write_Str (" : ");
1875                Write_Str_With_Col_Check ("label");
1876                Write_Rewrite_Str (">>>");
1877             end if;
1878
1879          when N_In =>
1880             Sprint_Left_Opnd (Node);
1881             Write_Str_Sloc (" in ");
1882             Sprint_Right_Opnd (Node);
1883
1884          when N_Incomplete_Type_Declaration =>
1885             Write_Indent_Str_Sloc ("type ");
1886             Write_Id (Defining_Identifier (Node));
1887
1888             if Present (Discriminant_Specifications (Node)) then
1889                Write_Discr_Specs (Node);
1890             elsif Unknown_Discriminants_Present (Node) then
1891                Write_Str_With_Col_Check ("(<>)");
1892             end if;
1893
1894             Write_Char (';');
1895
1896          when N_Index_Or_Discriminant_Constraint =>
1897             Set_Debug_Sloc;
1898             Sprint_Paren_Comma_List (Constraints (Node));
1899
1900          when N_Indexed_Component =>
1901             Sprint_Node_Sloc (Prefix (Node));
1902             Sprint_Opt_Paren_Comma_List (Expressions (Node));
1903
1904          when N_Integer_Literal =>
1905             if Print_In_Hex (Node) then
1906                Write_Uint_With_Col_Check_Sloc (Intval (Node), Hex);
1907             else
1908                Write_Uint_With_Col_Check_Sloc (Intval (Node), Auto);
1909             end if;
1910
1911          when N_Iteration_Scheme =>
1912             if Present (Condition (Node)) then
1913                Write_Str_With_Col_Check_Sloc ("while ");
1914                Sprint_Node (Condition (Node));
1915             else
1916                Write_Str_With_Col_Check_Sloc ("for ");
1917                Sprint_Node (Loop_Parameter_Specification (Node));
1918             end if;
1919
1920             Write_Char (' ');
1921
1922          when N_Itype_Reference =>
1923             Write_Indent_Str_Sloc ("reference ");
1924             Write_Id (Itype (Node));
1925
1926          when N_Label =>
1927             Write_Indent_Str_Sloc ("<<");
1928             Write_Id (Identifier (Node));
1929             Write_Str (">>");
1930
1931          when N_Loop_Parameter_Specification =>
1932             Set_Debug_Sloc;
1933             Write_Id (Defining_Identifier (Node));
1934             Write_Str_With_Col_Check (" in ");
1935
1936             if Reverse_Present (Node) then
1937                Write_Str_With_Col_Check ("reverse ");
1938             end if;
1939
1940             Sprint_Node (Discrete_Subtype_Definition (Node));
1941
1942          when N_Loop_Statement =>
1943             Write_Indent;
1944
1945             if Present (Identifier (Node))
1946               and then (not Has_Created_Identifier (Node)
1947                           or else not Dump_Original_Only)
1948             then
1949                Write_Rewrite_Str ("<<<");
1950                Write_Id (Identifier (Node));
1951                Write_Str (" : ");
1952                Write_Rewrite_Str (">>>");
1953                Sprint_Node (Iteration_Scheme (Node));
1954                Write_Str_With_Col_Check_Sloc ("loop");
1955                Sprint_Indented_List (Statements (Node));
1956                Write_Indent_Str ("end loop ");
1957                Write_Rewrite_Str ("<<<");
1958                Write_Id (Identifier (Node));
1959                Write_Rewrite_Str (">>>");
1960                Write_Char (';');
1961
1962             else
1963                Sprint_Node (Iteration_Scheme (Node));
1964                Write_Str_With_Col_Check_Sloc ("loop");
1965                Sprint_Indented_List (Statements (Node));
1966                Write_Indent_Str ("end loop;");
1967             end if;
1968
1969          when N_Mod_Clause =>
1970             Sprint_Node_List (Pragmas_Before (Node));
1971             Write_Str_With_Col_Check_Sloc ("at mod ");
1972             Sprint_Node (Expression (Node));
1973
1974          when N_Modular_Type_Definition =>
1975             Write_Str_With_Col_Check_Sloc ("mod ");
1976             Sprint_Node (Expression (Node));
1977
1978          when N_Not_In =>
1979             Sprint_Left_Opnd (Node);
1980             Write_Str_Sloc (" not in ");
1981             Sprint_Right_Opnd (Node);
1982
1983          when N_Null =>
1984             Write_Str_With_Col_Check_Sloc ("null");
1985
1986          when N_Null_Statement =>
1987             if Comes_From_Source (Node)
1988               or else Dump_Freeze_Null
1989               or else not Is_List_Member (Node)
1990               or else (No (Prev (Node)) and then No (Next (Node)))
1991             then
1992                Write_Indent_Str_Sloc ("null;");
1993             end if;
1994
1995          when N_Number_Declaration =>
1996             Set_Debug_Sloc;
1997
1998             if Write_Indent_Identifiers (Node) then
1999                Write_Str_With_Col_Check (" : constant ");
2000                Write_Str (" := ");
2001                Sprint_Node (Expression (Node));
2002                Write_Char (';');
2003             end if;
2004
2005          when N_Object_Declaration =>
2006             Set_Debug_Sloc;
2007
2008             if Write_Indent_Identifiers (Node) then
2009                declare
2010                   Def_Id : constant Entity_Id := Defining_Identifier (Node);
2011
2012                begin
2013                   Write_Str_With_Col_Check (" : ");
2014
2015                   if Is_Statically_Allocated (Def_Id) then
2016                      Write_Str_With_Col_Check ("static ");
2017                   end if;
2018
2019                   if Aliased_Present (Node) then
2020                      Write_Str_With_Col_Check ("aliased ");
2021                   end if;
2022
2023                   if Constant_Present (Node) then
2024                      Write_Str_With_Col_Check ("constant ");
2025                   end if;
2026
2027                   --  Ada 2005 (AI-231)
2028
2029                   if Null_Exclusion_Present (Node) then
2030                      Write_Str_With_Col_Check ("not null ");
2031                   end if;
2032
2033                   Sprint_Node (Object_Definition (Node));
2034
2035                   if Present (Expression (Node)) then
2036                      Write_Str (" := ");
2037                      Sprint_Node (Expression (Node));
2038                   end if;
2039
2040                   Write_Char (';');
2041
2042                   --  Handle implicit importation and implicit exportation of
2043                   --  object declarations:
2044                   --    $pragma import (Convention_Id, Def_Id, "...");
2045                   --    $pragma export (Convention_Id, Def_Id, "...");
2046
2047                   if Is_Internal (Def_Id)
2048                     and then Present (Interface_Name (Def_Id))
2049                   then
2050                      Write_Indent_Str_Sloc ("$pragma ");
2051
2052                      if Is_Imported (Def_Id) then
2053                         Write_Str ("import (");
2054
2055                      else pragma Assert (Is_Exported (Def_Id));
2056                         Write_Str ("export (");
2057                      end if;
2058
2059                      declare
2060                         Prefix : constant String  := "Convention_";
2061                         S      : constant String  := Convention (Def_Id)'Img;
2062
2063                      begin
2064                         Name_Len := S'Last - Prefix'Last;
2065                         Name_Buffer (1 .. Name_Len) :=
2066                           S (Prefix'Last + 1 .. S'Last);
2067                         Set_Casing (All_Lower_Case);
2068                         Write_Str (Name_Buffer (1 .. Name_Len));
2069                      end;
2070
2071                      Write_Str (", ");
2072                      Write_Id  (Def_Id);
2073                      Write_Str (", ");
2074                      Write_String_Table_Entry
2075                        (Strval (Interface_Name (Def_Id)));
2076                      Write_Str (");");
2077                   end if;
2078                end;
2079             end if;
2080
2081          when N_Object_Renaming_Declaration =>
2082             Write_Indent;
2083             Set_Debug_Sloc;
2084             Sprint_Node (Defining_Identifier (Node));
2085             Write_Str (" : ");
2086
2087             --  Ada 2005 (AI-230): Access renamings
2088
2089             if Present (Access_Definition (Node)) then
2090                Sprint_Node (Access_Definition (Node));
2091
2092             elsif Present (Subtype_Mark (Node)) then
2093
2094                --  Ada 2005 (AI-423): Object renaming with a null exclusion
2095
2096                if Null_Exclusion_Present (Node) then
2097                   Write_Str ("not null ");
2098                end if;
2099
2100                Sprint_Node (Subtype_Mark (Node));
2101
2102             else
2103                Write_Str (" ??? ");
2104             end if;
2105
2106             Write_Str_With_Col_Check (" renames ");
2107             Sprint_Node (Name (Node));
2108             Write_Char (';');
2109
2110          when N_Op_Abs =>
2111             Write_Operator (Node, "abs ");
2112             Sprint_Right_Opnd (Node);
2113
2114          when N_Op_Add =>
2115             Sprint_Left_Opnd (Node);
2116             Write_Operator (Node, " + ");
2117             Sprint_Right_Opnd (Node);
2118
2119          when N_Op_And =>
2120             Sprint_Left_Opnd (Node);
2121             Write_Operator (Node, " and ");
2122             Sprint_Right_Opnd (Node);
2123
2124          when N_Op_Concat =>
2125             Sprint_Left_Opnd (Node);
2126             Write_Operator (Node, " & ");
2127             Sprint_Right_Opnd (Node);
2128
2129          when N_Op_Divide =>
2130             Sprint_Left_Opnd (Node);
2131             Write_Char (' ');
2132             Process_TFAI_RR_Flags (Node);
2133             Write_Operator (Node, "/ ");
2134             Sprint_Right_Opnd (Node);
2135
2136          when N_Op_Eq =>
2137             Sprint_Left_Opnd (Node);
2138             Write_Operator (Node, " = ");
2139             Sprint_Right_Opnd (Node);
2140
2141          when N_Op_Expon =>
2142             Sprint_Left_Opnd (Node);
2143             Write_Operator (Node, " ** ");
2144             Sprint_Right_Opnd (Node);
2145
2146          when N_Op_Ge =>
2147             Sprint_Left_Opnd (Node);
2148             Write_Operator (Node, " >= ");
2149             Sprint_Right_Opnd (Node);
2150
2151          when N_Op_Gt =>
2152             Sprint_Left_Opnd (Node);
2153             Write_Operator (Node, " > ");
2154             Sprint_Right_Opnd (Node);
2155
2156          when N_Op_Le =>
2157             Sprint_Left_Opnd (Node);
2158             Write_Operator (Node, " <= ");
2159             Sprint_Right_Opnd (Node);
2160
2161          when N_Op_Lt =>
2162             Sprint_Left_Opnd (Node);
2163             Write_Operator (Node, " < ");
2164             Sprint_Right_Opnd (Node);
2165
2166          when N_Op_Minus =>
2167             Write_Operator (Node, "-");
2168             Sprint_Right_Opnd (Node);
2169
2170          when N_Op_Mod =>
2171             Sprint_Left_Opnd (Node);
2172
2173             if Treat_Fixed_As_Integer (Node) then
2174                Write_Str (" #");
2175             end if;
2176
2177             Write_Operator (Node, " mod ");
2178             Sprint_Right_Opnd (Node);
2179
2180          when N_Op_Multiply =>
2181             Sprint_Left_Opnd (Node);
2182             Write_Char (' ');
2183             Process_TFAI_RR_Flags (Node);
2184             Write_Operator (Node, "* ");
2185             Sprint_Right_Opnd (Node);
2186
2187          when N_Op_Ne =>
2188             Sprint_Left_Opnd (Node);
2189             Write_Operator (Node, " /= ");
2190             Sprint_Right_Opnd (Node);
2191
2192          when N_Op_Not =>
2193             Write_Operator (Node, "not ");
2194             Sprint_Right_Opnd (Node);
2195
2196          when N_Op_Or =>
2197             Sprint_Left_Opnd (Node);
2198             Write_Operator (Node, " or ");
2199             Sprint_Right_Opnd (Node);
2200
2201          when N_Op_Plus =>
2202             Write_Operator (Node, "+");
2203             Sprint_Right_Opnd (Node);
2204
2205          when N_Op_Rem =>
2206             Sprint_Left_Opnd (Node);
2207
2208             if Treat_Fixed_As_Integer (Node) then
2209                Write_Str (" #");
2210             end if;
2211
2212             Write_Operator (Node, " rem ");
2213             Sprint_Right_Opnd (Node);
2214
2215          when N_Op_Shift =>
2216             Set_Debug_Sloc;
2217             Write_Id (Node);
2218             Write_Char ('!');
2219             Write_Str_With_Col_Check ("(");
2220             Sprint_Node (Left_Opnd (Node));
2221             Write_Str (", ");
2222             Sprint_Node (Right_Opnd (Node));
2223             Write_Char (')');
2224
2225          when N_Op_Subtract =>
2226             Sprint_Left_Opnd (Node);
2227             Write_Operator (Node, " - ");
2228             Sprint_Right_Opnd (Node);
2229
2230          when N_Op_Xor =>
2231             Sprint_Left_Opnd (Node);
2232             Write_Operator (Node, " xor ");
2233             Sprint_Right_Opnd (Node);
2234
2235          when N_Operator_Symbol =>
2236             Write_Name_With_Col_Check_Sloc (Chars (Node));
2237
2238          when N_Ordinary_Fixed_Point_Definition =>
2239             Write_Str_With_Col_Check_Sloc ("delta ");
2240             Sprint_Node (Delta_Expression (Node));
2241             Sprint_Opt_Node (Real_Range_Specification (Node));
2242
2243          when N_Or_Else =>
2244             Sprint_Left_Opnd (Node);
2245             Write_Str_Sloc (" or else ");
2246             Sprint_Right_Opnd (Node);
2247
2248          when N_Others_Choice =>
2249             if All_Others (Node) then
2250                Write_Str_With_Col_Check ("all ");
2251             end if;
2252
2253             Write_Str_With_Col_Check_Sloc ("others");
2254
2255          when N_Package_Body =>
2256             Extra_Blank_Line;
2257             Write_Indent_Str_Sloc ("package body ");
2258             Sprint_Node (Defining_Unit_Name (Node));
2259             Write_Str (" is");
2260             Sprint_Indented_List (Declarations (Node));
2261
2262             if Present (Handled_Statement_Sequence (Node)) then
2263                Write_Indent_Str ("begin");
2264                Sprint_Node (Handled_Statement_Sequence (Node));
2265             end if;
2266
2267             Write_Indent_Str ("end ");
2268             Sprint_End_Label
2269               (Handled_Statement_Sequence (Node), Defining_Unit_Name (Node));
2270             Write_Char (';');
2271
2272          when N_Package_Body_Stub =>
2273             Write_Indent_Str_Sloc ("package body ");
2274             Sprint_Node (Defining_Identifier (Node));
2275             Write_Str_With_Col_Check (" is separate;");
2276
2277          when N_Package_Declaration =>
2278             Extra_Blank_Line;
2279             Write_Indent;
2280             Sprint_Node_Sloc (Specification (Node));
2281             Write_Char (';');
2282
2283          when N_Package_Instantiation =>
2284             Extra_Blank_Line;
2285             Write_Indent_Str_Sloc ("package ");
2286             Sprint_Node (Defining_Unit_Name (Node));
2287             Write_Str (" is new ");
2288             Sprint_Node (Name (Node));
2289             Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
2290             Write_Char (';');
2291
2292          when N_Package_Renaming_Declaration =>
2293             Write_Indent_Str_Sloc ("package ");
2294             Sprint_Node (Defining_Unit_Name (Node));
2295             Write_Str_With_Col_Check (" renames ");
2296             Sprint_Node (Name (Node));
2297             Write_Char (';');
2298
2299          when N_Package_Specification =>
2300             Write_Str_With_Col_Check_Sloc ("package ");
2301             Sprint_Node (Defining_Unit_Name (Node));
2302             Write_Str (" is");
2303             Sprint_Indented_List (Visible_Declarations (Node));
2304
2305             if Present (Private_Declarations (Node)) then
2306                Write_Indent_Str ("private");
2307                Sprint_Indented_List (Private_Declarations (Node));
2308             end if;
2309
2310             Write_Indent_Str ("end ");
2311             Sprint_Node (Defining_Unit_Name (Node));
2312
2313          when N_Parameter_Association =>
2314             Sprint_Node_Sloc (Selector_Name (Node));
2315             Write_Str (" => ");
2316             Sprint_Node (Explicit_Actual_Parameter (Node));
2317
2318          when N_Parameter_Specification =>
2319             Set_Debug_Sloc;
2320
2321             if Write_Identifiers (Node) then
2322                Write_Str (" : ");
2323
2324                if In_Present (Node) then
2325                   Write_Str_With_Col_Check ("in ");
2326                end if;
2327
2328                if Out_Present (Node) then
2329                   Write_Str_With_Col_Check ("out ");
2330                end if;
2331
2332                --  Ada 2005 (AI-231) parameter specification may carry
2333                --  null exclusion. Do not print it now if this is an
2334                --  access parameter, it is emitted when the access
2335                --  definition is displayed.
2336
2337                if Null_Exclusion_Present (Node)
2338                  and then Nkind (Parameter_Type (Node))
2339                    /= N_Access_Definition
2340                then
2341                   Write_Str ("not null ");
2342                end if;
2343
2344                Sprint_Node (Parameter_Type (Node));
2345
2346                if Present (Expression (Node)) then
2347                   Write_Str (" := ");
2348                   Sprint_Node (Expression (Node));
2349                end if;
2350             else
2351                Write_Str (", ");
2352             end if;
2353
2354          when N_Pop_Constraint_Error_Label =>
2355             Write_Indent_Str ("%pop_constraint_error_label");
2356
2357          when N_Pop_Program_Error_Label =>
2358             Write_Indent_Str ("%pop_program_error_label");
2359
2360          when N_Pop_Storage_Error_Label =>
2361             Write_Indent_Str ("%pop_storage_error_label");
2362
2363          when N_Push_Constraint_Error_Label =>
2364             Write_Indent_Str ("%push_constraint_error_label (");
2365
2366             if Present (Exception_Label (Node)) then
2367                Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2368             end if;
2369
2370             Write_Str (")");
2371
2372          when N_Push_Program_Error_Label =>
2373             Write_Indent_Str ("%push_program_error_label (");
2374
2375             if Present (Exception_Label (Node)) then
2376                Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2377             end if;
2378
2379             Write_Str (")");
2380
2381          when N_Push_Storage_Error_Label =>
2382             Write_Indent_Str ("%push_storage_error_label (");
2383
2384             if Present (Exception_Label (Node)) then
2385                Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2386             end if;
2387
2388             Write_Str (")");
2389
2390          when N_Pragma =>
2391             Write_Indent_Str_Sloc ("pragma ");
2392             Write_Name_With_Col_Check (Pragma_Name (Node));
2393
2394             if Present (Pragma_Argument_Associations (Node)) then
2395                Sprint_Opt_Paren_Comma_List
2396                  (Pragma_Argument_Associations (Node));
2397             end if;
2398
2399             Write_Char (';');
2400
2401          when N_Pragma_Argument_Association =>
2402             Set_Debug_Sloc;
2403
2404             if Chars (Node) /= No_Name then
2405                Write_Name_With_Col_Check (Chars (Node));
2406                Write_Str (" => ");
2407             end if;
2408
2409             Sprint_Node (Expression (Node));
2410
2411          when N_Private_Type_Declaration =>
2412             Write_Indent_Str_Sloc ("type ");
2413             Write_Id (Defining_Identifier (Node));
2414
2415             if Present (Discriminant_Specifications (Node)) then
2416                Write_Discr_Specs (Node);
2417             elsif Unknown_Discriminants_Present (Node) then
2418                Write_Str_With_Col_Check ("(<>)");
2419             end if;
2420
2421             Write_Str (" is ");
2422
2423             if Tagged_Present (Node) then
2424                Write_Str_With_Col_Check ("tagged ");
2425             end if;
2426
2427             if Limited_Present (Node) then
2428                Write_Str_With_Col_Check ("limited ");
2429             end if;
2430
2431             Write_Str_With_Col_Check ("private;");
2432
2433          when N_Private_Extension_Declaration =>
2434             Write_Indent_Str_Sloc ("type ");
2435             Write_Id (Defining_Identifier (Node));
2436
2437             if Present (Discriminant_Specifications (Node)) then
2438                Write_Discr_Specs (Node);
2439             elsif Unknown_Discriminants_Present (Node) then
2440                Write_Str_With_Col_Check ("(<>)");
2441             end if;
2442
2443             Write_Str_With_Col_Check (" is new ");
2444             Sprint_Node (Subtype_Indication (Node));
2445             Write_Str_With_Col_Check (" with private;");
2446
2447          when N_Procedure_Call_Statement =>
2448             Write_Indent;
2449             Set_Debug_Sloc;
2450             Note_Implicit_Run_Time_Call (Name (Node));
2451             Sprint_Node (Name (Node));
2452             Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
2453             Write_Char (';');
2454
2455          when N_Procedure_Instantiation =>
2456             Write_Indent_Str_Sloc ("procedure ");
2457             Sprint_Node (Defining_Unit_Name (Node));
2458             Write_Str_With_Col_Check (" is new ");
2459             Sprint_Node (Name (Node));
2460             Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
2461             Write_Char (';');
2462
2463          when N_Procedure_Specification =>
2464             Write_Str_With_Col_Check_Sloc ("procedure ");
2465             Sprint_Node (Defining_Unit_Name (Node));
2466             Write_Param_Specs (Node);
2467
2468          when N_Protected_Body =>
2469             Write_Indent_Str_Sloc ("protected body ");
2470             Write_Id (Defining_Identifier (Node));
2471             Write_Str (" is");
2472             Sprint_Indented_List (Declarations (Node));
2473             Write_Indent_Str ("end ");
2474             Write_Id (Defining_Identifier (Node));
2475             Write_Char (';');
2476
2477          when N_Protected_Body_Stub =>
2478             Write_Indent_Str_Sloc ("protected body ");
2479             Write_Id (Defining_Identifier (Node));
2480             Write_Str_With_Col_Check (" is separate;");
2481
2482          when N_Protected_Definition =>
2483             Set_Debug_Sloc;
2484             Sprint_Indented_List (Visible_Declarations (Node));
2485
2486             if Present (Private_Declarations (Node)) then
2487                Write_Indent_Str ("private");
2488                Sprint_Indented_List (Private_Declarations (Node));
2489             end if;
2490
2491             Write_Indent_Str ("end ");
2492
2493          when N_Protected_Type_Declaration =>
2494             Write_Indent_Str_Sloc ("protected type ");
2495             Sprint_Node (Defining_Identifier (Node));
2496             Write_Discr_Specs (Node);
2497
2498             if Present (Interface_List (Node)) then
2499                Write_Str (" is new ");
2500                Sprint_And_List (Interface_List (Node));
2501                Write_Str (" with ");
2502             else
2503                Write_Str (" is");
2504             end if;
2505
2506             Sprint_Node (Protected_Definition (Node));
2507             Write_Id (Defining_Identifier (Node));
2508             Write_Char (';');
2509
2510          when N_Qualified_Expression =>
2511             Sprint_Node (Subtype_Mark (Node));
2512             Write_Char_Sloc (''');
2513
2514             --  Print expression, make sure we have at least one level of
2515             --  parentheses around the expression. For cases of qualified
2516             --  expressions in the source, this is always the case, but
2517             --  for generated qualifications, there may be no explicit
2518             --  parentheses present.
2519
2520             if Paren_Count (Expression (Node)) /= 0 then
2521                Sprint_Node (Expression (Node));
2522             else
2523                Write_Char ('(');
2524                Sprint_Node (Expression (Node));
2525                Write_Char (')');
2526             end if;
2527
2528          when N_Raise_Constraint_Error =>
2529
2530             --  This node can be used either as a subexpression or as a
2531             --  statement form. The following test is a reasonably reliable
2532             --  way to distinguish the two cases.
2533
2534             if Is_List_Member (Node)
2535               and then Nkind (Parent (Node)) not in N_Subexpr
2536             then
2537                Write_Indent;
2538             end if;
2539
2540             Write_Str_With_Col_Check_Sloc ("[constraint_error");
2541             Write_Condition_And_Reason (Node);
2542
2543          when N_Raise_Program_Error =>
2544
2545             --  This node can be used either as a subexpression or as a
2546             --  statement form. The following test is a reasonably reliable
2547             --  way to distinguish the two cases.
2548
2549             if Is_List_Member (Node)
2550               and then Nkind (Parent (Node)) not in N_Subexpr
2551             then
2552                Write_Indent;
2553             end if;
2554
2555             Write_Str_With_Col_Check_Sloc ("[program_error");
2556             Write_Condition_And_Reason (Node);
2557
2558          when N_Raise_Storage_Error =>
2559
2560             --  This node can be used either as a subexpression or as a
2561             --  statement form. The following test is a reasonably reliable
2562             --  way to distinguish the two cases.
2563
2564             if Is_List_Member (Node)
2565               and then Nkind (Parent (Node)) not in N_Subexpr
2566             then
2567                Write_Indent;
2568             end if;
2569
2570             Write_Str_With_Col_Check_Sloc ("[storage_error");
2571             Write_Condition_And_Reason (Node);
2572
2573          when N_Raise_Statement =>
2574             Write_Indent_Str_Sloc ("raise ");
2575             Sprint_Node (Name (Node));
2576             Write_Char (';');
2577
2578          when N_Range =>
2579             Sprint_Node (Low_Bound (Node));
2580             Write_Str_Sloc (" .. ");
2581             Sprint_Node (High_Bound (Node));
2582             Update_Itype (Node);
2583
2584          when N_Range_Constraint =>
2585             Write_Str_With_Col_Check_Sloc ("range ");
2586             Sprint_Node (Range_Expression (Node));
2587
2588          when N_Real_Literal =>
2589             Write_Ureal_With_Col_Check_Sloc (Realval (Node));
2590
2591          when N_Real_Range_Specification =>
2592             Write_Str_With_Col_Check_Sloc ("range ");
2593             Sprint_Node (Low_Bound (Node));
2594             Write_Str (" .. ");
2595             Sprint_Node (High_Bound (Node));
2596
2597          when N_Record_Definition =>
2598             if Abstract_Present (Node) then
2599                Write_Str_With_Col_Check ("abstract ");
2600             end if;
2601
2602             if Tagged_Present (Node) then
2603                Write_Str_With_Col_Check ("tagged ");
2604             end if;
2605
2606             if Limited_Present (Node) then
2607                Write_Str_With_Col_Check ("limited ");
2608             end if;
2609
2610             if Null_Present (Node) then
2611                Write_Str_With_Col_Check_Sloc ("null record");
2612
2613             else
2614                Write_Str_With_Col_Check_Sloc ("record");
2615                Sprint_Node (Component_List (Node));
2616                Write_Indent_Str ("end record");
2617             end if;
2618
2619          when N_Record_Representation_Clause =>
2620             Write_Indent_Str_Sloc ("for ");
2621             Sprint_Node (Identifier (Node));
2622             Write_Str_With_Col_Check (" use record ");
2623
2624             if Present (Mod_Clause (Node)) then
2625                Sprint_Node (Mod_Clause (Node));
2626             end if;
2627
2628             Sprint_Indented_List (Component_Clauses (Node));
2629             Write_Indent_Str ("end record;");
2630
2631          when N_Reference =>
2632             Sprint_Node (Prefix (Node));
2633             Write_Str_With_Col_Check_Sloc ("'reference");
2634
2635          when N_Requeue_Statement =>
2636             Write_Indent_Str_Sloc ("requeue ");
2637             Sprint_Node (Name (Node));
2638
2639             if Abort_Present (Node) then
2640                Write_Str_With_Col_Check (" with abort");
2641             end if;
2642
2643             Write_Char (';');
2644
2645          when N_Simple_Return_Statement =>
2646             if Present (Expression (Node)) then
2647                Write_Indent_Str_Sloc ("return ");
2648                Sprint_Node (Expression (Node));
2649                Write_Char (';');
2650             else
2651                Write_Indent_Str_Sloc ("return;");
2652             end if;
2653
2654          when N_Selective_Accept =>
2655             Write_Indent_Str_Sloc ("select");
2656
2657             declare
2658                Alt_Node : Node_Id;
2659             begin
2660                Alt_Node := First (Select_Alternatives (Node));
2661                loop
2662                   Indent_Begin;
2663                   Sprint_Node (Alt_Node);
2664                   Indent_End;
2665                   Next (Alt_Node);
2666                   exit when No (Alt_Node);
2667                   Write_Indent_Str ("or");
2668                end loop;
2669             end;
2670
2671             if Present (Else_Statements (Node)) then
2672                Write_Indent_Str ("else");
2673                Sprint_Indented_List (Else_Statements (Node));
2674             end if;
2675
2676             Write_Indent_Str ("end select;");
2677
2678          when N_Signed_Integer_Type_Definition =>
2679             Write_Str_With_Col_Check_Sloc ("range ");
2680             Sprint_Node (Low_Bound (Node));
2681             Write_Str (" .. ");
2682             Sprint_Node (High_Bound (Node));
2683
2684          when N_Single_Protected_Declaration =>
2685             Write_Indent_Str_Sloc ("protected ");
2686             Write_Id (Defining_Identifier (Node));
2687             Write_Str (" is");
2688             Sprint_Node (Protected_Definition (Node));
2689             Write_Id (Defining_Identifier (Node));
2690             Write_Char (';');
2691
2692          when N_Single_Task_Declaration =>
2693             Write_Indent_Str_Sloc ("task ");
2694             Sprint_Node (Defining_Identifier (Node));
2695
2696             if Present (Task_Definition (Node)) then
2697                Write_Str (" is");
2698                Sprint_Node (Task_Definition (Node));
2699             end if;
2700
2701             Write_Char (';');
2702
2703          when N_Selected_Component =>
2704             Sprint_Node (Prefix (Node));
2705             Write_Char_Sloc ('.');
2706             Sprint_Node (Selector_Name (Node));
2707
2708          when N_Slice =>
2709             Set_Debug_Sloc;
2710             Sprint_Node (Prefix (Node));
2711             Write_Str_With_Col_Check (" (");
2712             Sprint_Node (Discrete_Range (Node));
2713             Write_Char (')');
2714
2715          when N_String_Literal =>
2716             if String_Length (Strval (Node)) + Column > 75 then
2717                Write_Indent_Str ("  ");
2718             end if;
2719
2720             Set_Debug_Sloc;
2721             Write_String_Table_Entry (Strval (Node));
2722
2723          when N_Subprogram_Body =>
2724
2725             --  Output extra blank line unless we are in freeze actions
2726
2727             if Freeze_Indent = 0 then
2728                Extra_Blank_Line;
2729             end if;
2730
2731             Write_Indent;
2732             Sprint_Node_Sloc (Specification (Node));
2733             Write_Str (" is");
2734
2735             Sprint_Indented_List (Declarations (Node));
2736             Write_Indent_Str ("begin");
2737             Sprint_Node (Handled_Statement_Sequence (Node));
2738
2739             Write_Indent_Str ("end ");
2740
2741             Sprint_End_Label
2742               (Handled_Statement_Sequence (Node),
2743                  Defining_Unit_Name (Specification (Node)));
2744             Write_Char (';');
2745
2746             if Is_List_Member (Node)
2747               and then Present (Next (Node))
2748               and then Nkind (Next (Node)) /= N_Subprogram_Body
2749             then
2750                Write_Indent;
2751             end if;
2752
2753          when N_Subprogram_Body_Stub =>
2754             Write_Indent;
2755             Sprint_Node_Sloc (Specification (Node));
2756             Write_Str_With_Col_Check (" is separate;");
2757
2758          when N_Subprogram_Declaration =>
2759             Write_Indent;
2760             Sprint_Node_Sloc (Specification (Node));
2761
2762             if Nkind (Specification (Node)) = N_Procedure_Specification
2763               and then Null_Present (Specification (Node))
2764             then
2765                Write_Str_With_Col_Check (" is null");
2766             end if;
2767
2768             Write_Char (';');
2769
2770          when N_Subprogram_Info =>
2771             Sprint_Node (Identifier (Node));
2772             Write_Str_With_Col_Check_Sloc ("'subprogram_info");
2773
2774          when N_Subprogram_Renaming_Declaration =>
2775             Write_Indent;
2776             Sprint_Node (Specification (Node));
2777             Write_Str_With_Col_Check_Sloc (" renames ");
2778             Sprint_Node (Name (Node));
2779             Write_Char (';');
2780
2781          when N_Subtype_Declaration =>
2782             Write_Indent_Str_Sloc ("subtype ");
2783             Sprint_Node (Defining_Identifier (Node));
2784             Write_Str (" is ");
2785
2786             --  Ada 2005 (AI-231)
2787
2788             if Null_Exclusion_Present (Node) then
2789                Write_Str ("not null ");
2790             end if;
2791
2792             Sprint_Node (Subtype_Indication (Node));
2793             Write_Char (';');
2794
2795          when N_Subtype_Indication =>
2796             Sprint_Node_Sloc (Subtype_Mark (Node));
2797             Write_Char (' ');
2798             Sprint_Node (Constraint (Node));
2799
2800          when N_Subunit =>
2801             Write_Indent_Str_Sloc ("separate (");
2802             Sprint_Node (Name (Node));
2803             Write_Char (')');
2804             Extra_Blank_Line;
2805             Sprint_Node (Proper_Body (Node));
2806
2807          when N_Task_Body =>
2808             Write_Indent_Str_Sloc ("task body ");
2809             Write_Id (Defining_Identifier (Node));
2810             Write_Str (" is");
2811             Sprint_Indented_List (Declarations (Node));
2812             Write_Indent_Str ("begin");
2813             Sprint_Node (Handled_Statement_Sequence (Node));
2814             Write_Indent_Str ("end ");
2815             Sprint_End_Label
2816               (Handled_Statement_Sequence (Node), Defining_Identifier (Node));
2817             Write_Char (';');
2818
2819          when N_Task_Body_Stub =>
2820             Write_Indent_Str_Sloc ("task body ");
2821             Write_Id (Defining_Identifier (Node));
2822             Write_Str_With_Col_Check (" is separate;");
2823
2824          when N_Task_Definition =>
2825             Set_Debug_Sloc;
2826             Sprint_Indented_List (Visible_Declarations (Node));
2827
2828             if Present (Private_Declarations (Node)) then
2829                Write_Indent_Str ("private");
2830                Sprint_Indented_List (Private_Declarations (Node));
2831             end if;
2832
2833             Write_Indent_Str ("end ");
2834             Sprint_End_Label (Node, Defining_Identifier (Parent (Node)));
2835
2836          when N_Task_Type_Declaration =>
2837             Write_Indent_Str_Sloc ("task type ");
2838             Sprint_Node (Defining_Identifier (Node));
2839             Write_Discr_Specs (Node);
2840
2841             if Present (Interface_List (Node)) then
2842                Write_Str (" is new ");
2843                Sprint_And_List (Interface_List (Node));
2844             end if;
2845
2846             if Present (Task_Definition (Node)) then
2847                if No (Interface_List (Node)) then
2848                   Write_Str (" is");
2849                else
2850                   Write_Str (" with ");
2851                end if;
2852
2853                Sprint_Node (Task_Definition (Node));
2854             end if;
2855
2856             Write_Char (';');
2857
2858          when N_Terminate_Alternative =>
2859             Sprint_Node_List (Pragmas_Before (Node));
2860
2861             Write_Indent;
2862
2863             if Present (Condition (Node)) then
2864                Write_Str_With_Col_Check ("when ");
2865                Sprint_Node (Condition (Node));
2866                Write_Str (" => ");
2867             end if;
2868
2869             Write_Str_With_Col_Check_Sloc ("terminate;");
2870             Sprint_Node_List (Pragmas_After (Node));
2871
2872          when N_Timed_Entry_Call =>
2873             Write_Indent_Str_Sloc ("select");
2874             Indent_Begin;
2875             Sprint_Node (Entry_Call_Alternative (Node));
2876             Indent_End;
2877             Write_Indent_Str ("or");
2878             Indent_Begin;
2879             Sprint_Node (Delay_Alternative (Node));
2880             Indent_End;
2881             Write_Indent_Str ("end select;");
2882
2883          when N_Triggering_Alternative =>
2884             Sprint_Node_List (Pragmas_Before (Node));
2885             Sprint_Node_Sloc (Triggering_Statement (Node));
2886             Sprint_Node_List (Statements (Node));
2887
2888          when N_Type_Conversion =>
2889             Set_Debug_Sloc;
2890             Sprint_Node (Subtype_Mark (Node));
2891             Col_Check (4);
2892
2893             if Conversion_OK (Node) then
2894                Write_Char ('?');
2895             end if;
2896
2897             if Float_Truncate (Node) then
2898                Write_Char ('^');
2899             end if;
2900
2901             if Rounded_Result (Node) then
2902                Write_Char ('@');
2903             end if;
2904
2905             Write_Char ('(');
2906             Sprint_Node (Expression (Node));
2907             Write_Char (')');
2908
2909          when N_Unchecked_Expression =>
2910             Col_Check (10);
2911             Write_Str ("`(");
2912             Sprint_Node_Sloc (Expression (Node));
2913             Write_Char (')');
2914
2915          when N_Unchecked_Type_Conversion =>
2916             Sprint_Node (Subtype_Mark (Node));
2917             Write_Char ('!');
2918             Write_Str_With_Col_Check ("(");
2919             Sprint_Node_Sloc (Expression (Node));
2920             Write_Char (')');
2921
2922          when N_Unconstrained_Array_Definition =>
2923             Write_Str_With_Col_Check_Sloc ("array (");
2924
2925             declare
2926                Node1 : Node_Id;
2927             begin
2928                Node1 := First (Subtype_Marks (Node));
2929                loop
2930                   Sprint_Node (Node1);
2931                   Write_Str_With_Col_Check (" range <>");
2932                   Next (Node1);
2933                   exit when Node1 = Empty;
2934                   Write_Str (", ");
2935                end loop;
2936             end;
2937
2938             Write_Str (") of ");
2939             Sprint_Node (Component_Definition (Node));
2940
2941          when N_Unused_At_Start | N_Unused_At_End =>
2942             Write_Indent_Str ("***** Error, unused node encountered *****");
2943             Write_Eol;
2944
2945          when N_Use_Package_Clause =>
2946             Write_Indent_Str_Sloc ("use ");
2947             Sprint_Comma_List (Names (Node));
2948             Write_Char (';');
2949
2950          when N_Use_Type_Clause =>
2951             Write_Indent_Str_Sloc ("use type ");
2952             Sprint_Comma_List (Subtype_Marks (Node));
2953             Write_Char (';');
2954
2955          when N_Validate_Unchecked_Conversion =>
2956             Write_Indent_Str_Sloc ("validate unchecked_conversion (");
2957             Sprint_Node (Source_Type (Node));
2958             Write_Str (", ");
2959             Sprint_Node (Target_Type (Node));
2960             Write_Str (");");
2961
2962          when N_Variant =>
2963             Write_Indent_Str_Sloc ("when ");
2964             Sprint_Bar_List (Discrete_Choices (Node));
2965             Write_Str (" => ");
2966             Sprint_Node (Component_List (Node));
2967
2968          when N_Variant_Part =>
2969             Indent_Begin;
2970             Write_Indent_Str_Sloc ("case ");
2971             Sprint_Node (Name (Node));
2972             Write_Str (" is ");
2973             Sprint_Indented_List (Variants (Node));
2974             Write_Indent_Str ("end case");
2975             Indent_End;
2976
2977          when N_With_Clause =>
2978
2979             --  Special test, if we are dumping the original tree only,
2980             --  then we want to eliminate the bogus with clauses that
2981             --  correspond to the non-existent children of Text_IO.
2982
2983             if Dump_Original_Only
2984               and then Is_Text_IO_Kludge_Unit (Name (Node))
2985             then
2986                null;
2987
2988             --  Normal case, output the with clause
2989
2990             else
2991                if First_Name (Node) or else not Dump_Original_Only then
2992
2993                   --  Ada 2005 (AI-50217): Print limited with_clauses
2994
2995                   if Private_Present (Node) and Limited_Present (Node) then
2996                      Write_Indent_Str ("limited private with ");
2997
2998                   elsif Private_Present (Node) then
2999                      Write_Indent_Str ("private with ");
3000
3001                   elsif Limited_Present (Node) then
3002                      Write_Indent_Str ("limited with ");
3003
3004                   else
3005                      Write_Indent_Str ("with ");
3006                   end if;
3007
3008                else
3009                   Write_Str (", ");
3010                end if;
3011
3012                Sprint_Node_Sloc (Name (Node));
3013
3014                if Last_Name (Node) or else not Dump_Original_Only then
3015                   Write_Char (';');
3016                end if;
3017             end if;
3018
3019       end case;
3020
3021       if Nkind (Node) in N_Subexpr
3022         and then Do_Range_Check (Node)
3023       then
3024          Write_Str ("}");
3025       end if;
3026
3027       for J in 1 .. Paren_Count (Node) loop
3028          Write_Char (')');
3029       end loop;
3030
3031       Dump_Node := Save_Dump_Node;
3032    end Sprint_Node_Actual;
3033
3034    ----------------------
3035    -- Sprint_Node_List --
3036    ----------------------
3037
3038    procedure Sprint_Node_List (List : List_Id) is
3039       Node : Node_Id;
3040
3041    begin
3042       if Is_Non_Empty_List (List) then
3043          Node := First (List);
3044
3045          loop
3046             Sprint_Node (Node);
3047             Next (Node);
3048             exit when Node = Empty;
3049          end loop;
3050       end if;
3051    end Sprint_Node_List;
3052
3053    ----------------------
3054    -- Sprint_Node_Sloc --
3055    ----------------------
3056
3057    procedure Sprint_Node_Sloc (Node : Node_Id) is
3058    begin
3059       Sprint_Node (Node);
3060
3061       if Debug_Generated_Code and then Present (Dump_Node) then
3062          Set_Sloc (Dump_Node, Sloc (Node));
3063          Dump_Node := Empty;
3064       end if;
3065    end Sprint_Node_Sloc;
3066
3067    ---------------------
3068    -- Sprint_Opt_Node --
3069    ---------------------
3070
3071    procedure Sprint_Opt_Node (Node : Node_Id) is
3072    begin
3073       if Present (Node) then
3074          Write_Char (' ');
3075          Sprint_Node (Node);
3076       end if;
3077    end Sprint_Opt_Node;
3078
3079    --------------------------
3080    -- Sprint_Opt_Node_List --
3081    --------------------------
3082
3083    procedure Sprint_Opt_Node_List (List : List_Id) is
3084    begin
3085       if Present (List) then
3086          Sprint_Node_List (List);
3087       end if;
3088    end Sprint_Opt_Node_List;
3089
3090    ---------------------------------
3091    -- Sprint_Opt_Paren_Comma_List --
3092    ---------------------------------
3093
3094    procedure Sprint_Opt_Paren_Comma_List (List : List_Id) is
3095    begin
3096       if Is_Non_Empty_List (List) then
3097          Write_Char (' ');
3098          Sprint_Paren_Comma_List (List);
3099       end if;
3100    end Sprint_Opt_Paren_Comma_List;
3101
3102    -----------------------------
3103    -- Sprint_Paren_Comma_List --
3104    -----------------------------
3105
3106    procedure Sprint_Paren_Comma_List (List : List_Id) is
3107       N           : Node_Id;
3108       Node_Exists : Boolean := False;
3109
3110    begin
3111
3112       if Is_Non_Empty_List (List) then
3113
3114          if Dump_Original_Only then
3115             N := First (List);
3116             while Present (N) loop
3117                if not Is_Rewrite_Insertion (N) then
3118                   Node_Exists := True;
3119                   exit;
3120                end if;
3121
3122                Next (N);
3123             end loop;
3124
3125             if not Node_Exists then
3126                return;
3127             end if;
3128          end if;
3129
3130          Write_Str_With_Col_Check ("(");
3131          Sprint_Comma_List (List);
3132          Write_Char (')');
3133       end if;
3134    end Sprint_Paren_Comma_List;
3135
3136    ----------------------
3137    -- Sprint_Right_Opnd --
3138    ----------------------
3139
3140    procedure Sprint_Right_Opnd (N : Node_Id) is
3141       Opnd : constant Node_Id := Right_Opnd (N);
3142
3143    begin
3144       if Paren_Count (Opnd) /= 0
3145         or else Op_Prec (Nkind (Opnd)) > Op_Prec (Nkind (N))
3146       then
3147          Sprint_Node (Opnd);
3148
3149       else
3150          Write_Char ('(');
3151          Sprint_Node (Opnd);
3152          Write_Char (')');
3153       end if;
3154    end Sprint_Right_Opnd;
3155
3156    ------------------
3157    -- Update_Itype --
3158    ------------------
3159
3160    procedure Update_Itype (Node : Node_Id) is
3161    begin
3162       if Present (Etype (Node))
3163         and then Is_Itype (Etype (Node))
3164         and then Debug_Generated_Code
3165       then
3166          Set_Sloc (Etype (Node), Sloc (Node));
3167       end if;
3168    end Update_Itype;
3169
3170    ---------------------
3171    -- Write_Char_Sloc --
3172    ---------------------
3173
3174    procedure Write_Char_Sloc (C : Character) is
3175    begin
3176       if Debug_Generated_Code and then C /= ' ' then
3177          Set_Debug_Sloc;
3178       end if;
3179
3180       Write_Char (C);
3181    end Write_Char_Sloc;
3182
3183    --------------------------------
3184    -- Write_Condition_And_Reason --
3185    --------------------------------
3186
3187    procedure Write_Condition_And_Reason (Node : Node_Id) is
3188       Cond  : constant Node_Id := Condition (Node);
3189       Image : constant String  := RT_Exception_Code'Image
3190                                     (RT_Exception_Code'Val
3191                                        (UI_To_Int (Reason (Node))));
3192
3193    begin
3194       if Present (Cond) then
3195
3196          --  If condition is a single entity, or NOT with a single entity,
3197          --  output all on one line, since it will likely fit just fine.
3198
3199          if Is_Entity_Name (Cond)
3200            or else (Nkind (Cond) = N_Op_Not
3201                      and then Is_Entity_Name (Right_Opnd (Cond)))
3202          then
3203             Write_Str_With_Col_Check (" when ");
3204             Sprint_Node (Cond);
3205             Write_Char (' ');
3206
3207             --  Otherwise for more complex condition, multiple lines
3208
3209          else
3210             Write_Str_With_Col_Check (" when");
3211             Indent := Indent + 2;
3212             Write_Indent;
3213             Sprint_Node (Cond);
3214             Write_Indent;
3215             Indent := Indent - 2;
3216          end if;
3217
3218       --  If no condition, just need a space (all on one line)
3219
3220       else
3221          Write_Char (' ');
3222       end if;
3223
3224       --  Write the reason
3225
3226       Write_Char ('"');
3227
3228       for J in 4 .. Image'Last loop
3229          if Image (J) = '_' then
3230             Write_Char (' ');
3231          else
3232             Write_Char (Fold_Lower (Image (J)));
3233          end if;
3234       end loop;
3235
3236       Write_Str ("""]");
3237    end Write_Condition_And_Reason;
3238
3239    --------------------------------
3240    -- Write_Corresponding_Source --
3241    --------------------------------
3242
3243    procedure Write_Corresponding_Source (S : String) is
3244       Loc : Source_Ptr;
3245       Src : Source_Buffer_Ptr;
3246
3247    begin
3248       --  Ignore if not in dump source text mode, or if in freeze actions
3249
3250       if Dump_Source_Text and then Freeze_Indent = 0 then
3251
3252          --  Ignore null string
3253
3254          if S = "" then
3255             return;
3256          end if;
3257
3258          --  Ignore space or semicolon at end of given string
3259
3260          if S (S'Last) = ' ' or else S (S'Last) = ';' then
3261             Write_Corresponding_Source (S (S'First .. S'Last - 1));
3262             return;
3263          end if;
3264
3265          --  Loop to look at next lines not yet printed in source file
3266
3267          for L in
3268            Last_Line_Printed + 1 .. Last_Source_Line (Current_Source_File)
3269          loop
3270             Src := Source_Text (Current_Source_File);
3271             Loc := Line_Start (L, Current_Source_File);
3272
3273             --  If comment, keep looking
3274
3275             if Src (Loc .. Loc + 1) = "--" then
3276                null;
3277
3278             --  Search to first non-blank
3279
3280             else
3281                while Src (Loc) not in Line_Terminator loop
3282
3283                   --  Non-blank found
3284
3285                   if Src (Loc) /= ' ' and then Src (Loc) /= ASCII.HT then
3286
3287                      --  Loop through characters in string to see if we match
3288
3289                      for J in S'Range loop
3290
3291                         --  If mismatch, then not the case we are looking for
3292
3293                         if Src (Loc) /= S (J) then
3294                            return;
3295                         end if;
3296
3297                         Loc := Loc + 1;
3298                      end loop;
3299
3300                      --  If we fall through, string matched, if white space or
3301                      --  semicolon after the matched string, this is the case
3302                      --  we are looking for.
3303
3304                      if Src (Loc) in Line_Terminator
3305                        or else Src (Loc) = ' '
3306                        or else Src (Loc) = ASCII.HT
3307                        or else Src (Loc) = ';'
3308                      then
3309                         --  So output source lines up to and including this one
3310
3311                         Write_Source_Lines (L);
3312                         return;
3313                      end if;
3314                   end if;
3315
3316                   Loc := Loc + 1;
3317                end loop;
3318             end if;
3319
3320          --  Line was all blanks, or a comment line, keep looking
3321
3322          end loop;
3323       end if;
3324    end Write_Corresponding_Source;
3325
3326    -----------------------
3327    -- Write_Discr_Specs --
3328    -----------------------
3329
3330    procedure Write_Discr_Specs (N : Node_Id) is
3331       Specs : List_Id;
3332       Spec  : Node_Id;
3333
3334    begin
3335       Specs := Discriminant_Specifications (N);
3336
3337       if Present (Specs) then
3338          Write_Str_With_Col_Check (" (");
3339          Spec := First (Specs);
3340
3341          loop
3342             Sprint_Node (Spec);
3343             Next (Spec);
3344             exit when Spec = Empty;
3345
3346             --  Add semicolon, unless we are printing original tree and the
3347             --  next specification is part of a list (but not the first
3348             --  element of that list)
3349
3350             if not Dump_Original_Only or else not Prev_Ids (Spec) then
3351                Write_Str ("; ");
3352             end if;
3353          end loop;
3354
3355          Write_Char (')');
3356       end if;
3357    end Write_Discr_Specs;
3358
3359    -----------------
3360    -- Write_Ekind --
3361    -----------------
3362
3363    procedure Write_Ekind (E : Entity_Id) is
3364       S : constant String := Entity_Kind'Image (Ekind (E));
3365
3366    begin
3367       Name_Len := S'Length;
3368       Name_Buffer (1 .. Name_Len) := S;
3369       Set_Casing (Mixed_Case);
3370       Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
3371    end Write_Ekind;
3372
3373    --------------
3374    -- Write_Id --
3375    --------------
3376
3377    procedure Write_Id (N : Node_Id) is
3378    begin
3379       --  Deal with outputting Itype
3380
3381       --  Note: if we are printing the full tree with -gnatds, then we may
3382       --  end up picking up the Associated_Node link from a generic template
3383       --  here which overlaps the Entity field, but as documented, Write_Itype
3384       --  is defended against junk calls.
3385
3386       if Nkind (N) in N_Entity then
3387          Write_Itype (N);
3388       elsif Nkind (N) in N_Has_Entity then
3389          Write_Itype (Entity (N));
3390       end if;
3391
3392       --  Case of a defining identifier
3393
3394       if Nkind (N) = N_Defining_Identifier then
3395
3396          --  If defining identifier has an interface name (and no
3397          --  address clause), then we output the interface name.
3398
3399          if (Is_Imported (N) or else Is_Exported (N))
3400            and then Present (Interface_Name (N))
3401            and then No (Address_Clause (N))
3402          then
3403             String_To_Name_Buffer (Strval (Interface_Name (N)));
3404             Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
3405
3406          --  If no interface name (or inactive because there was
3407          --  an address clause), then just output the Chars name.
3408
3409          else
3410             Write_Name_With_Col_Check (Chars (N));
3411          end if;
3412
3413       --  Case of selector of an expanded name where the expanded name
3414       --  has an associated entity, output this entity.
3415
3416       elsif Nkind (Parent (N)) = N_Expanded_Name
3417         and then Selector_Name (Parent (N)) = N
3418         and then Present (Entity (Parent (N)))
3419       then
3420          Write_Id (Entity (Parent (N)));
3421
3422       --  For any other node with an associated entity, output it
3423
3424       elsif Nkind (N) in N_Has_Entity
3425         and then Present (Entity_Or_Associated_Node (N))
3426         and then Nkind (Entity_Or_Associated_Node (N)) in N_Entity
3427       then
3428          Write_Id (Entity (N));
3429
3430       --  All other cases, we just print the Chars field
3431
3432       else
3433          Write_Name_With_Col_Check (Chars (N));
3434       end if;
3435    end Write_Id;
3436
3437    -----------------------
3438    -- Write_Identifiers --
3439    -----------------------
3440
3441    function Write_Identifiers (Node : Node_Id) return Boolean is
3442    begin
3443       Sprint_Node (Defining_Identifier (Node));
3444       Update_Itype (Defining_Identifier (Node));
3445
3446       --  The remainder of the declaration must be printed unless we are
3447       --  printing the original tree and this is not the last identifier
3448
3449       return
3450          not Dump_Original_Only or else not More_Ids (Node);
3451
3452    end Write_Identifiers;
3453
3454    ------------------------
3455    -- Write_Implicit_Def --
3456    ------------------------
3457
3458    procedure Write_Implicit_Def (E : Entity_Id) is
3459       Ind : Node_Id;
3460
3461    begin
3462       case Ekind (E) is
3463          when E_Array_Subtype =>
3464             Write_Str_With_Col_Check ("subtype ");
3465             Write_Id (E);
3466             Write_Str_With_Col_Check (" is ");
3467             Write_Id (Base_Type (E));
3468             Write_Str_With_Col_Check (" (");
3469
3470             Ind := First_Index (E);
3471             while Present (Ind) loop
3472                Sprint_Node (Ind);
3473                Next_Index (Ind);
3474
3475                if Present (Ind) then
3476                   Write_Str (", ");
3477                end if;
3478             end loop;
3479
3480             Write_Str (");");
3481
3482          when E_Signed_Integer_Subtype | E_Enumeration_Subtype =>
3483             Write_Str_With_Col_Check ("subtype ");
3484             Write_Id (E);
3485             Write_Str (" is ");
3486             Write_Id (Etype (E));
3487             Write_Str_With_Col_Check (" range ");
3488             Sprint_Node (Scalar_Range (E));
3489             Write_Str (";");
3490
3491          when others =>
3492             Write_Str_With_Col_Check ("type ");
3493             Write_Id (E);
3494             Write_Str_With_Col_Check (" is <");
3495             Write_Ekind (E);
3496             Write_Str (">;");
3497       end case;
3498
3499    end Write_Implicit_Def;
3500
3501    ------------------
3502    -- Write_Indent --
3503    ------------------
3504
3505    procedure Write_Indent is
3506       Loc : constant Source_Ptr := Sloc (Dump_Node);
3507
3508    begin
3509       if Indent_Annull_Flag then
3510          Indent_Annull_Flag := False;
3511       else
3512          --  Deal with Dump_Source_Text output. Note that we ignore implicit
3513          --  label declarations, since they typically have the sloc of the
3514          --  corresponding label, which really messes up the -gnatL output.
3515
3516          if Dump_Source_Text
3517            and then Loc > No_Location
3518            and then Nkind (Dump_Node) /= N_Implicit_Label_Declaration
3519          then
3520             if Get_Source_File_Index (Loc) = Current_Source_File then
3521                Write_Source_Lines
3522                  (Get_Physical_Line_Number (Sloc (Dump_Node)));
3523             end if;
3524          end if;
3525
3526          Write_Eol;
3527
3528          for J in 1 .. Indent loop
3529             Write_Char (' ');
3530          end loop;
3531       end if;
3532    end Write_Indent;
3533
3534    ------------------------------
3535    -- Write_Indent_Identifiers --
3536    ------------------------------
3537
3538    function Write_Indent_Identifiers (Node : Node_Id) return Boolean is
3539    begin
3540       --  We need to start a new line for every node, except in the case
3541       --  where we are printing the original tree and this is not the first
3542       --  defining identifier in the list.
3543
3544       if not Dump_Original_Only or else not Prev_Ids (Node) then
3545          Write_Indent;
3546
3547       --  If printing original tree and this is not the first defining
3548       --  identifier in the list, then the previous call to this procedure
3549       --  printed only the name, and we add a comma to separate the names.
3550
3551       else
3552          Write_Str (", ");
3553       end if;
3554
3555       Sprint_Node (Defining_Identifier (Node));
3556
3557       --  The remainder of the declaration must be printed unless we are
3558       --  printing the original tree and this is not the last identifier
3559
3560       return
3561          not Dump_Original_Only or else not More_Ids (Node);
3562    end Write_Indent_Identifiers;
3563
3564    -----------------------------------
3565    -- Write_Indent_Identifiers_Sloc --
3566    -----------------------------------
3567
3568    function Write_Indent_Identifiers_Sloc (Node : Node_Id) return Boolean is
3569    begin
3570       --  We need to start a new line for every node, except in the case
3571       --  where we are printing the original tree and this is not the first
3572       --  defining identifier in the list.
3573
3574       if not Dump_Original_Only or else not Prev_Ids (Node) then
3575          Write_Indent;
3576
3577       --  If printing original tree and this is not the first defining
3578       --  identifier in the list, then the previous call to this procedure
3579       --  printed only the name, and we add a comma to separate the names.
3580
3581       else
3582          Write_Str (", ");
3583       end if;
3584
3585       Set_Debug_Sloc;
3586       Sprint_Node (Defining_Identifier (Node));
3587
3588       --  The remainder of the declaration must be printed unless we are
3589       --  printing the original tree and this is not the last identifier
3590
3591       return not Dump_Original_Only or else not More_Ids (Node);
3592    end Write_Indent_Identifiers_Sloc;
3593
3594    ----------------------
3595    -- Write_Indent_Str --
3596    ----------------------
3597
3598    procedure Write_Indent_Str (S : String) is
3599    begin
3600       Write_Corresponding_Source (S);
3601       Write_Indent;
3602       Write_Str (S);
3603    end Write_Indent_Str;
3604
3605    ---------------------------
3606    -- Write_Indent_Str_Sloc --
3607    ---------------------------
3608
3609    procedure Write_Indent_Str_Sloc (S : String) is
3610    begin
3611       Write_Corresponding_Source (S);
3612       Write_Indent;
3613       Write_Str_Sloc (S);
3614    end Write_Indent_Str_Sloc;
3615
3616    -----------------
3617    -- Write_Itype --
3618    -----------------
3619
3620    procedure Write_Itype (Typ : Entity_Id) is
3621
3622       procedure Write_Header (T : Boolean := True);
3623       --  Write type if T is True, subtype if T is false
3624
3625       ------------------
3626       -- Write_Header --
3627       ------------------
3628
3629       procedure Write_Header (T : Boolean := True) is
3630       begin
3631          if T then
3632             Write_Str ("[type ");
3633          else
3634             Write_Str ("[subtype ");
3635          end if;
3636
3637          Write_Name_With_Col_Check (Chars (Typ));
3638          Write_Str (" is ");
3639       end Write_Header;
3640
3641    --  Start of processing for Write_Itype
3642
3643    begin
3644       if Nkind (Typ) in N_Entity
3645         and then Is_Itype (Typ)
3646         and then not Itype_Printed (Typ)
3647       then
3648          --  Itype to be printed
3649
3650          declare
3651             B : constant Node_Id := Etype (Typ);
3652             X : Node_Id;
3653             P : constant Node_Id := Parent (Typ);
3654
3655             S : constant Saved_Output_Buffer := Save_Output_Buffer;
3656             --  Save current output buffer
3657
3658             Old_Sloc : Source_Ptr;
3659             --  Save sloc of related node, so it is not modified when
3660             --  printing with -gnatD.
3661
3662          begin
3663             --  Write indentation at start of line
3664
3665             for J in 1 .. Indent loop
3666                Write_Char (' ');
3667             end loop;
3668
3669             --  If we have a constructed declaration for the itype, print it
3670
3671             if Present (P)
3672               and then Nkind (P) in N_Declaration
3673               and then Defining_Entity (P) = Typ
3674             then
3675                --  We must set Itype_Printed true before the recursive call to
3676                --  print the node, otherwise we get an infinite recursion!
3677
3678                Set_Itype_Printed (Typ, True);
3679
3680                --  Write the declaration enclosed in [], avoiding new line
3681                --  at start of declaration, and semicolon at end.
3682
3683                --  Note: The itype may be imported from another unit, in which
3684                --  case we do not want to modify the Sloc of the declaration.
3685                --  Otherwise the itype may appear to be in the current unit,
3686                --  and the back-end will reject a reference out of scope.
3687
3688                Write_Char ('[');
3689                Indent_Annull_Flag := True;
3690                Old_Sloc := Sloc (P);
3691                Sprint_Node (P);
3692                Set_Sloc (P, Old_Sloc);
3693                Write_Erase_Char (';');
3694
3695             --  If no constructed declaration, then we have to concoct the
3696             --  source corresponding to the type entity that we have at hand.
3697
3698             else
3699                case Ekind (Typ) is
3700
3701                   --  Access types and subtypes
3702
3703                   when Access_Kind =>
3704                      Write_Header (Ekind (Typ) = E_Access_Type);
3705                      Write_Str ("access ");
3706
3707                      if Is_Access_Constant (Typ) then
3708                         Write_Str ("constant ");
3709                      elsif Can_Never_Be_Null (Typ) then
3710                         Write_Str ("not null ");
3711                      end if;
3712
3713                      Write_Id (Directly_Designated_Type (Typ));
3714
3715                      --  Array types and string types
3716
3717                   when E_Array_Type | E_String_Type =>
3718                      Write_Header;
3719                      Write_Str ("array (");
3720
3721                      X := First_Index (Typ);
3722                      loop
3723                         Sprint_Node (X);
3724
3725                         if not Is_Constrained (Typ) then
3726                            Write_Str (" range <>");
3727                         end if;
3728
3729                         Next_Index (X);
3730                         exit when No (X);
3731                         Write_Str (", ");
3732                      end loop;
3733
3734                      Write_Str (") of ");
3735                      Sprint_Node (Component_Type (Typ));
3736
3737                      --  Array subtypes and string subtypes
3738
3739                   when E_Array_Subtype | E_String_Subtype =>
3740                      Write_Header (False);
3741                      Write_Id (Etype (Typ));
3742                      Write_Str (" (");
3743
3744                      X := First_Index (Typ);
3745                      loop
3746                         Sprint_Node (X);
3747                         Next_Index (X);
3748                         exit when No (X);
3749                         Write_Str (", ");
3750                      end loop;
3751
3752                      Write_Char (')');
3753
3754                      --  Signed integer types, and modular integer subtypes
3755
3756                   when E_Signed_Integer_Type     |
3757                        E_Signed_Integer_Subtype  |
3758                        E_Modular_Integer_Subtype =>
3759
3760                      Write_Header (Ekind (Typ) = E_Signed_Integer_Type);
3761
3762                      if Ekind (Typ) = E_Signed_Integer_Type then
3763                         Write_Str ("new ");
3764                      end if;
3765
3766                      Write_Id (B);
3767
3768                      --  Print bounds if different from base type
3769
3770                      declare
3771                         L  : constant Node_Id := Type_Low_Bound (Typ);
3772                         H  : constant Node_Id := Type_High_Bound (Typ);
3773                         LE : Node_Id;
3774                         HE : Node_Id;
3775
3776                      begin
3777                         --  B can either be a scalar type, in which case the
3778                         --  declaration of Typ may constrain it with different
3779                         --  bounds, or a private type, in which case we know
3780                         --  that the declaration of Typ cannot have a scalar
3781                         --  constraint.
3782
3783                         if Is_Scalar_Type (B) then
3784                            LE := Type_Low_Bound (B);
3785                            HE := Type_High_Bound (B);
3786                         else
3787                            LE := Empty;
3788                            HE := Empty;
3789                         end if;
3790
3791                         if No (LE)
3792                           or else (True
3793                             and then Nkind (L) = N_Integer_Literal
3794                             and then Nkind (H) = N_Integer_Literal
3795                             and then Nkind (LE) = N_Integer_Literal
3796                             and then Nkind (HE) = N_Integer_Literal
3797                             and then UI_Eq (Intval (L), Intval (LE))
3798                             and then UI_Eq (Intval (H), Intval (HE)))
3799                         then
3800                            null;
3801
3802                         else
3803                            Write_Str (" range ");
3804                            Sprint_Node (Type_Low_Bound (Typ));
3805                            Write_Str (" .. ");
3806                            Sprint_Node (Type_High_Bound (Typ));
3807                         end if;
3808                      end;
3809
3810                      --  Modular integer types
3811
3812                   when E_Modular_Integer_Type =>
3813                      Write_Header;
3814                      Write_Str (" mod ");
3815                      Write_Uint_With_Col_Check (Modulus (Typ), Auto);
3816
3817                      --  Floating point types and subtypes
3818
3819                   when E_Floating_Point_Type    |
3820                        E_Floating_Point_Subtype =>
3821
3822                      Write_Header (Ekind (Typ) = E_Floating_Point_Type);
3823
3824                      if Ekind (Typ) = E_Floating_Point_Type then
3825                         Write_Str ("new ");
3826                      end if;
3827
3828                      Write_Id (Etype (Typ));
3829
3830                      if Digits_Value (Typ) /= Digits_Value (Etype (Typ)) then
3831                         Write_Str (" digits ");
3832                         Write_Uint_With_Col_Check
3833                           (Digits_Value (Typ), Decimal);
3834                      end if;
3835
3836                      --  Print bounds if not different from base type
3837
3838                      declare
3839                         L  : constant Node_Id := Type_Low_Bound (Typ);
3840                         H  : constant Node_Id := Type_High_Bound (Typ);
3841                         LE : constant Node_Id := Type_Low_Bound (B);
3842                         HE : constant Node_Id := Type_High_Bound (B);
3843
3844                      begin
3845                         if Nkind (L) = N_Real_Literal
3846                           and then Nkind (H) = N_Real_Literal
3847                           and then Nkind (LE) = N_Real_Literal
3848                           and then Nkind (HE) = N_Real_Literal
3849                           and then UR_Eq (Realval (L), Realval (LE))
3850                           and then UR_Eq (Realval (H), Realval (HE))
3851                         then
3852                            null;
3853
3854                         else
3855                            Write_Str (" range ");
3856                            Sprint_Node (Type_Low_Bound (Typ));
3857                            Write_Str (" .. ");
3858                            Sprint_Node (Type_High_Bound (Typ));
3859                         end if;
3860                      end;
3861
3862                   --  Record subtypes
3863
3864                   when E_Record_Subtype =>
3865                      Write_Header (False);
3866                      Write_Str ("record");
3867                      Indent_Begin;
3868
3869                      declare
3870                         C : Entity_Id;
3871                      begin
3872                         C := First_Entity (Typ);
3873                         while Present (C) loop
3874                            Write_Indent;
3875                            Write_Id (C);
3876                            Write_Str (" : ");
3877                            Write_Id (Etype (C));
3878                            Next_Entity (C);
3879                         end loop;
3880                      end;
3881
3882                      Indent_End;
3883                      Write_Indent_Str (" end record");
3884
3885                   --  Class-Wide types
3886
3887                   when E_Class_Wide_Type    |
3888                        E_Class_Wide_Subtype =>
3889                      Write_Header;
3890                      Write_Name_With_Col_Check (Chars (Etype (Typ)));
3891                      Write_Str ("'Class");
3892
3893                   --  Subprogram types
3894
3895                   when E_Subprogram_Type =>
3896                      Write_Header;
3897
3898                      if Etype (Typ) = Standard_Void_Type then
3899                         Write_Str ("procedure");
3900                      else
3901                         Write_Str ("function");
3902                      end if;
3903
3904                      if Present (First_Entity (Typ)) then
3905                         Write_Str (" (");
3906
3907                         declare
3908                            Param : Entity_Id;
3909
3910                         begin
3911                            Param := First_Entity (Typ);
3912                            loop
3913                               Write_Id (Param);
3914                               Write_Str (" : ");
3915
3916                               if Ekind (Param) = E_In_Out_Parameter then
3917                                  Write_Str ("in out ");
3918                               elsif Ekind (Param) = E_Out_Parameter then
3919                                  Write_Str ("out ");
3920                               end if;
3921
3922                               Write_Id (Etype (Param));
3923                               Next_Entity (Param);
3924                               exit when No (Param);
3925                               Write_Str (", ");
3926                            end loop;
3927
3928                            Write_Char (')');
3929                         end;
3930                      end if;
3931
3932                      if Etype (Typ) /= Standard_Void_Type then
3933                         Write_Str (" return ");
3934                         Write_Id (Etype (Typ));
3935                      end if;
3936
3937                   when E_String_Literal_Subtype =>
3938                      declare
3939                         LB  : constant Uint :=
3940                                 Intval (String_Literal_Low_Bound (Typ));
3941                         Len : constant Uint :=
3942                                 String_Literal_Length (Typ);
3943                      begin
3944                         Write_Str ("String (");
3945                         Write_Int (UI_To_Int (LB));
3946                         Write_Str (" .. ");
3947                         Write_Int (UI_To_Int (LB + Len) - 1);
3948                         Write_Str (");");
3949                      end;
3950
3951                   --  For all other Itypes, print ??? (fill in later)
3952
3953                   when others =>
3954                      Write_Header (True);
3955                      Write_Str ("???");
3956
3957                end case;
3958             end if;
3959
3960             --  Add terminating bracket and restore output buffer
3961
3962             Write_Char (']');
3963             Write_Eol;
3964             Restore_Output_Buffer (S);
3965          end;
3966
3967          Set_Itype_Printed (Typ);
3968       end if;
3969    end Write_Itype;
3970
3971    -------------------------------
3972    -- Write_Name_With_Col_Check --
3973    -------------------------------
3974
3975    procedure Write_Name_With_Col_Check (N : Name_Id) is
3976       J : Natural;
3977       K : Natural;
3978       L : Natural;
3979
3980    begin
3981       Get_Name_String (N);
3982
3983       --  Deal with -gnatdI which replaces any sequence Cnnnb where C is an
3984       --  upper case letter, nnn is one or more digits and b is a lower case
3985       --  letter by C...b, so that listings do not depend on serial numbers.
3986
3987       if Debug_Flag_II then
3988          J := 1;
3989          while J < Name_Len - 1 loop
3990             if Name_Buffer (J) in 'A' .. 'Z'
3991               and then Name_Buffer (J + 1) in '0' .. '9'
3992             then
3993                K := J + 1;
3994                while K < Name_Len loop
3995                   exit when Name_Buffer (K) not in '0' .. '9';
3996                   K := K + 1;
3997                end loop;
3998
3999                if Name_Buffer (K) in 'a' .. 'z' then
4000                   L := Name_Len - K + 1;
4001
4002                   Name_Buffer (J + 4 .. J + L + 3) :=
4003                     Name_Buffer (K .. Name_Len);
4004                   Name_Buffer (J + 1 .. J + 3) := "...";
4005                   Name_Len := J + L + 3;
4006                   J := J + 5;
4007
4008                else
4009                   J := K;
4010                end if;
4011
4012             else
4013                J := J + 1;
4014             end if;
4015          end loop;
4016       end if;
4017
4018       --  Fall through for normal case
4019
4020       Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
4021    end Write_Name_With_Col_Check;
4022
4023    ------------------------------------
4024    -- Write_Name_With_Col_Check_Sloc --
4025    ------------------------------------
4026
4027    procedure Write_Name_With_Col_Check_Sloc (N : Name_Id) is
4028    begin
4029       Get_Name_String (N);
4030       Write_Str_With_Col_Check_Sloc (Name_Buffer (1 .. Name_Len));
4031    end Write_Name_With_Col_Check_Sloc;
4032
4033    --------------------
4034    -- Write_Operator --
4035    --------------------
4036
4037    procedure Write_Operator (N : Node_Id; S : String) is
4038       F : Natural := S'First;
4039       T : Natural := S'Last;
4040
4041    begin
4042       --  If no overflow check, just write string out, and we are done
4043
4044       if not Do_Overflow_Check (N) then
4045          Write_Str_Sloc (S);
4046
4047       --  If overflow check, we want to surround the operator with curly
4048       --  brackets, but not include spaces within the brackets.
4049
4050       else
4051          if S (F) = ' ' then
4052             Write_Char (' ');
4053             F := F + 1;
4054          end if;
4055
4056          if S (T) = ' ' then
4057             T := T - 1;
4058          end if;
4059
4060          Write_Char ('{');
4061          Write_Str_Sloc (S (F .. T));
4062          Write_Char ('}');
4063
4064          if S (S'Last) = ' ' then
4065             Write_Char (' ');
4066          end if;
4067       end if;
4068    end Write_Operator;
4069
4070    -----------------------
4071    -- Write_Param_Specs --
4072    -----------------------
4073
4074    procedure Write_Param_Specs (N : Node_Id) is
4075       Specs  : List_Id;
4076       Spec   : Node_Id;
4077       Formal : Node_Id;
4078
4079    begin
4080       Specs := Parameter_Specifications (N);
4081
4082       if Is_Non_Empty_List (Specs) then
4083          Write_Str_With_Col_Check (" (");
4084          Spec := First (Specs);
4085
4086          loop
4087             Sprint_Node (Spec);
4088             Formal := Defining_Identifier (Spec);
4089             Next (Spec);
4090             exit when Spec = Empty;
4091
4092             --  Add semicolon, unless we are printing original tree and the
4093             --  next specification is part of a list (but not the first
4094             --  element of that list)
4095
4096             if not Dump_Original_Only or else not Prev_Ids (Spec) then
4097                Write_Str ("; ");
4098             end if;
4099          end loop;
4100
4101          --  Write out any extra formals
4102
4103          while Present (Extra_Formal (Formal)) loop
4104             Formal := Extra_Formal (Formal);
4105             Write_Str ("; ");
4106             Write_Name_With_Col_Check (Chars (Formal));
4107             Write_Str (" : ");
4108             Write_Name_With_Col_Check (Chars (Etype (Formal)));
4109          end loop;
4110
4111          Write_Char (')');
4112       end if;
4113    end Write_Param_Specs;
4114
4115    -----------------------
4116    -- Write_Rewrite_Str --
4117    -----------------------
4118
4119    procedure Write_Rewrite_Str (S : String) is
4120    begin
4121       if not Dump_Generated_Only then
4122          if S'Length = 3 and then S = ">>>" then
4123             Write_Str (">>>");
4124          else
4125             Write_Str_With_Col_Check (S);
4126          end if;
4127       end if;
4128    end Write_Rewrite_Str;
4129
4130    -----------------------
4131    -- Write_Source_Line --
4132    -----------------------
4133
4134    procedure Write_Source_Line (L : Physical_Line_Number) is
4135       Loc : Source_Ptr;
4136       Src : Source_Buffer_Ptr;
4137       Scn : Source_Ptr;
4138
4139    begin
4140       if Dump_Source_Text then
4141          Src := Source_Text (Current_Source_File);
4142          Loc := Line_Start (L, Current_Source_File);
4143          Write_Eol;
4144
4145          --  See if line is a comment line, if not, and if not line one,
4146          --  precede with blank line.
4147
4148          Scn := Loc;
4149          while Src (Scn) = ' ' or else Src (Scn) = ASCII.HT loop
4150             Scn := Scn + 1;
4151          end loop;
4152
4153          if (Src (Scn) in Line_Terminator
4154               or else Src (Scn .. Scn + 1) /= "--")
4155            and then L /= 1
4156          then
4157             Write_Eol;
4158          end if;
4159
4160          --  Now write the source text of the line
4161
4162          Write_Str ("-- ");
4163          Write_Int (Int (L));
4164          Write_Str (": ");
4165
4166          while Src (Loc) not in Line_Terminator loop
4167             Write_Char (Src (Loc));
4168             Loc := Loc + 1;
4169          end loop;
4170       end if;
4171    end Write_Source_Line;
4172
4173    ------------------------
4174    -- Write_Source_Lines --
4175    ------------------------
4176
4177    procedure Write_Source_Lines (L : Physical_Line_Number) is
4178    begin
4179       while Last_Line_Printed < L loop
4180          Last_Line_Printed := Last_Line_Printed + 1;
4181          Write_Source_Line (Last_Line_Printed);
4182       end loop;
4183    end Write_Source_Lines;
4184
4185    --------------------
4186    -- Write_Str_Sloc --
4187    --------------------
4188
4189    procedure Write_Str_Sloc (S : String) is
4190    begin
4191       for J in S'Range loop
4192          Write_Char_Sloc (S (J));
4193       end loop;
4194    end Write_Str_Sloc;
4195
4196    ------------------------------
4197    -- Write_Str_With_Col_Check --
4198    ------------------------------
4199
4200    procedure Write_Str_With_Col_Check (S : String) is
4201    begin
4202       if Int (S'Last) + Column > Line_Limit then
4203          Write_Indent_Str ("  ");
4204
4205          if S (S'First) = ' ' then
4206             Write_Str (S (S'First + 1 .. S'Last));
4207          else
4208             Write_Str (S);
4209          end if;
4210
4211       else
4212          Write_Str (S);
4213       end if;
4214    end Write_Str_With_Col_Check;
4215
4216    -----------------------------------
4217    -- Write_Str_With_Col_Check_Sloc --
4218    -----------------------------------
4219
4220    procedure Write_Str_With_Col_Check_Sloc (S : String) is
4221    begin
4222       if Int (S'Last) + Column > Line_Limit then
4223          Write_Indent_Str ("  ");
4224
4225          if S (S'First) = ' ' then
4226             Write_Str_Sloc (S (S'First + 1 .. S'Last));
4227          else
4228             Write_Str_Sloc (S);
4229          end if;
4230
4231       else
4232          Write_Str_Sloc (S);
4233       end if;
4234    end Write_Str_With_Col_Check_Sloc;
4235
4236    -------------------------------
4237    -- Write_Uint_With_Col_Check --
4238    -------------------------------
4239
4240    procedure Write_Uint_With_Col_Check (U : Uint; Format : UI_Format) is
4241    begin
4242       Col_Check (UI_Decimal_Digits_Hi (U));
4243       UI_Write (U, Format);
4244    end Write_Uint_With_Col_Check;
4245
4246    ------------------------------------
4247    -- Write_Uint_With_Col_Check_Sloc --
4248    ------------------------------------
4249
4250    procedure Write_Uint_With_Col_Check_Sloc (U : Uint; Format : UI_Format) is
4251    begin
4252       Col_Check (UI_Decimal_Digits_Hi (U));
4253       Set_Debug_Sloc;
4254       UI_Write (U, Format);
4255    end Write_Uint_With_Col_Check_Sloc;
4256
4257    -------------------------------------
4258    -- Write_Ureal_With_Col_Check_Sloc --
4259    -------------------------------------
4260
4261    procedure Write_Ureal_With_Col_Check_Sloc (U : Ureal) is
4262       D : constant Uint := Denominator (U);
4263       N : constant Uint := Numerator (U);
4264
4265    begin
4266       Col_Check
4267         (UI_Decimal_Digits_Hi (D) + UI_Decimal_Digits_Hi (N) + 4);
4268       Set_Debug_Sloc;
4269       UR_Write (U);
4270    end Write_Ureal_With_Col_Check_Sloc;
4271
4272 end Sprint;