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