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