ada: Update printing container aggregates for debugging
[official-gcc.git] / gcc / ada / sprint.adb
blobf54d409ef96d606210060349dea4815a541a9ad1
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-2023, 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 Aspects; use Aspects;
27 with Atree; use Atree;
28 with Casing; use Casing;
29 with Csets; use Csets;
30 with Debug; use Debug;
31 with Einfo; use Einfo;
32 with Einfo.Entities; use Einfo.Entities;
33 with Einfo.Utils; use Einfo.Utils;
34 with Lib; use Lib;
35 with Namet; use Namet;
36 with Nlists; use Nlists;
37 with Opt; use Opt;
38 with Output; use Output;
39 with Rtsfind; use Rtsfind;
40 with Sem_Eval; use Sem_Eval;
41 with Sem_Util; use Sem_Util;
42 with Sinfo; use Sinfo;
43 with Sinfo.Nodes; use Sinfo.Nodes;
44 with Sinfo.Utils; use Sinfo.Utils;
45 with Sinput; use Sinput;
46 with Sinput.D; use Sinput.D;
47 with Snames; use Snames;
48 with Stand; use Stand;
49 with Stringt; use Stringt;
50 with Uintp; use Uintp;
51 with Uname; use Uname;
52 with Urealp; use Urealp;
54 package body Sprint is
55 Current_Source_File : Source_File_Index;
56 -- Index of source file whose generated code is being dumped
58 Dump_Node : Node_Id := Empty;
59 -- This is set to the current node, used for printing line numbers. In
60 -- Debug_Generated_Code mode, Dump_Node is set to the current node
61 -- requiring Sloc fixup, until Set_Debug_Sloc is called to set the proper
62 -- value. The call clears it back to Empty.
64 First_Debug_Sloc : Source_Ptr;
65 -- Sloc of first byte of the current output file if we are generating a
66 -- source debug file.
68 Debug_Sloc : Source_Ptr;
69 -- Sloc of first byte of line currently being written if we are
70 -- generating a source debug file.
72 Dump_Original_Only : Boolean;
73 -- Set True if the -gnatdo (dump original tree) flag is set
75 Dump_Generated_Only : Boolean;
76 -- Set True if the -gnatdG (dump generated tree) debug flag is set
77 -- or for Print_Generated_Code (-gnatG) or Dump_Generated_Code (-gnatD).
79 Dump_Freeze_Null : Boolean;
80 -- Set True if empty freeze nodes and non-source null statements output.
81 -- Note that freeze nodes containing freeze actions are always output,
82 -- as are freeze nodes for itypes, which in general have the effect of
83 -- causing elaboration of the itype.
85 Freeze_Indent : Int := 0;
86 -- Keep track of freeze indent level (controls output of blank lines before
87 -- procedures within expression freeze actions). Relevant only if we are
88 -- not in Dump_Source_Text mode, since in Dump_Source_Text mode we don't
89 -- output these blank lines in any case.
91 Indent : Int := 0;
92 -- Number of columns for current line output indentation
94 Indent_Annull_Flag : Boolean := False;
95 -- Set True if subsequent Write_Indent call to be ignored, gets reset
96 -- by this call, so it is only active to suppress a single indent call.
98 Last_Line_Printed : Physical_Line_Number;
99 -- This keeps track of the physical line number of the last source line
100 -- that has been output. The value is only valid in Dump_Source_Text mode.
102 -------------------------------
103 -- Operator Precedence Table --
104 -------------------------------
106 -- This table is used to decide whether a subexpression needs to be
107 -- parenthesized. The rule is that if an operand of an operator (which
108 -- for this purpose includes AND THEN and OR ELSE) is itself an operator
109 -- with a lower precedence than the operator (or equal precedence if
110 -- appearing as the right operand), then parentheses are required.
112 Op_Prec : constant array (N_Subexpr) of Short_Short_Integer :=
113 (N_Op_And => 1,
114 N_Op_Or => 1,
115 N_Op_Xor => 1,
116 N_And_Then => 1,
117 N_Or_Else => 1,
119 N_In => 2,
120 N_Not_In => 2,
121 N_Op_Eq => 2,
122 N_Op_Ge => 2,
123 N_Op_Gt => 2,
124 N_Op_Le => 2,
125 N_Op_Lt => 2,
126 N_Op_Ne => 2,
128 N_Op_Add => 3,
129 N_Op_Concat => 3,
130 N_Op_Subtract => 3,
131 N_Op_Plus => 3,
132 N_Op_Minus => 3,
134 N_Op_Divide => 4,
135 N_Op_Mod => 4,
136 N_Op_Rem => 4,
137 N_Op_Multiply => 4,
139 N_Op_Expon => 5,
140 N_Op_Abs => 5,
141 N_Op_Not => 5,
143 others => 6);
145 procedure Sprint_Left_Opnd (N : Node_Id);
146 -- Print left operand of operator, parenthesizing if necessary
148 procedure Sprint_Right_Opnd (N : Node_Id);
149 -- Print right operand of operator, parenthesizing if necessary
151 -----------------------
152 -- Local Subprograms --
153 -----------------------
155 procedure Col_Check (N : Nat);
156 -- Check that at least N characters remain on current line, and if not,
157 -- then start an extra line with two characters extra indentation for
158 -- continuing text on the next line.
160 procedure Extra_Blank_Line;
161 -- In some situations we write extra blank lines to separate the generated
162 -- code to make it more readable. However, these extra blank lines are not
163 -- generated in Dump_Source_Text mode, since there the source text lines
164 -- output with preceding blank lines are quite sufficient as separators.
165 -- This procedure writes a blank line if Dump_Source_Text is False.
167 procedure Indent_Annull;
168 -- Causes following call to Write_Indent to be ignored. This is used when
169 -- a higher level node wants to stop a lower level node from starting a
170 -- new line, when it would otherwise be inclined to do so (e.g. the case
171 -- of an accept statement called from an accept alternative with a guard)
173 procedure Indent_Begin;
174 -- Increase indentation level
176 procedure Indent_End;
177 -- Decrease indentation level
179 procedure Print_Debug_Line (S : String);
180 -- Used to print output lines in Debug_Generated_Code mode (this is used
181 -- as the argument for a call to Set_Special_Output in package Output).
183 procedure Set_Debug_Sloc;
184 -- If Dump_Node is non-empty, this routine sets the appropriate value
185 -- in its Sloc field, from the current location in the debug source file
186 -- that is currently being written.
188 procedure Sprint_And_List (List : List_Id);
189 -- Print the given list with items separated by vertical "and"
191 procedure Sprint_Aspect_Specifications
192 (Node : Node_Id;
193 Semicolon : Boolean);
194 -- Node is a declaration node that has aspect specifications (Has_Aspects
195 -- flag set True). It outputs the aspect specifications. For the case
196 -- of Semicolon = True, it is called after outputting the terminating
197 -- semicolon for the related node. The effect is to remove the semicolon
198 -- and print the aspect specifications followed by a terminating semicolon.
199 -- For the case of Semicolon False, no semicolon is removed or output, and
200 -- all the aspects are printed on a single line.
202 procedure Sprint_At_End_Proc (Node : Node_Id);
203 -- Print At_End_Proc attribute if present
205 procedure Sprint_Bar_List (List : List_Id);
206 -- Print the given list with items separated by vertical bars
208 procedure Sprint_End_Label
209 (Node : Node_Id;
210 Default : Node_Id);
211 -- Print the end label for a Handled_Sequence_Of_Statements in a body.
212 -- If there is no end label, use the defining identifier of the enclosing
213 -- construct. If the end label is present, treat it as a reference to the
214 -- defining entity of the construct: this guarantees that it carries the
215 -- proper sloc information for debugging purposes.
217 procedure Sprint_Node_Actual (Node : Node_Id);
218 -- This routine prints its node argument. It is a lower level routine than
219 -- Sprint_Node, in that it does not bother about rewritten trees.
221 procedure Sprint_Node_Sloc (Node : Node_Id);
222 -- Like Sprint_Node, but in addition, in Debug_Generated_Code mode,
223 -- sets the Sloc of the current debug node to be a copy of the Sloc
224 -- of the sprinted node Node. Note that this is done after printing
225 -- Node, so that the Sloc is the proper updated value for the debug file.
227 procedure Update_Itype (Node : Node_Id);
228 -- Update the Sloc of an itype that is not attached to the tree, when
229 -- debugging expanded code. This routine is called from nodes whose
230 -- type can be an Itype, such as defining_identifiers that may be of
231 -- an anonymous access type, or ranges in slices.
233 procedure Write_Char_Sloc (C : Character);
234 -- Like Write_Char, except that if C is non-blank, Set_Debug_Sloc is
235 -- called to ensure that the current node has a proper Sloc set.
237 procedure Write_Condition_And_Reason (Node : Node_Id);
238 -- Write Condition and Reason codes of Raise_xxx_Error node
240 procedure Write_Corresponding_Source (S : String);
241 -- If S is a string with a single keyword (possibly followed by a space),
242 -- and if the next non-comment non-blank source line matches this keyword,
243 -- then output all source lines up to this matching line.
245 procedure Write_Discr_Specs (N : Node_Id);
246 -- Output discriminant specification for node, which is any of the type
247 -- declarations that can have discriminants.
249 procedure Write_Ekind (E : Entity_Id);
250 -- Write the String corresponding to the Ekind without "E_"
252 procedure Write_Id (N : Node_Id);
253 -- N is a node with a Chars field. This procedure writes the name that
254 -- will be used in the generated code associated with the name. For a
255 -- node with no associated entity, this is simply the Chars field. For
256 -- the case where there is an entity associated with the node, we print
257 -- the name associated with the entity (since it may have been encoded).
258 -- One other special case is that an entity has an active external name
259 -- (i.e. an external name present with no address clause), then this
260 -- external name is output. This procedure also deals with outputting
261 -- declarations of referenced itypes, if not output earlier.
263 function Write_Identifiers (Node : Node_Id) return Boolean;
264 -- Handle node where the grammar has a list of defining identifiers, but
265 -- the tree has a separate declaration for each identifier. Handles the
266 -- printing of the defining identifier, and returns True if the type and
267 -- initialization information is to be printed, False if it is to be
268 -- skipped (the latter case happens when printing defining identifiers
269 -- other than the first in the original tree output case).
271 procedure Write_Implicit_Def (E : Entity_Id);
272 pragma Warnings (Off, Write_Implicit_Def);
273 -- Write the definition of the implicit type E according to its Ekind
274 -- For now a debugging procedure, but might be used in the future.
276 procedure Write_Indent;
277 -- Start a new line and write indentation spacing
279 function Write_Indent_Identifiers (Node : Node_Id) return Boolean;
280 -- Like Write_Identifiers except that each new printed declaration
281 -- is at the start of a new line.
283 function Write_Indent_Identifiers_Sloc (Node : Node_Id) return Boolean;
284 -- Like Write_Indent_Identifiers except that in Debug_Generated_Code
285 -- mode, the Sloc of the current debug node is set to point to the
286 -- first output identifier.
288 procedure Write_Indent_Str (S : String);
289 -- Start a new line and write indent spacing followed by given string
291 procedure Write_Indent_Str_Sloc (S : String);
292 -- Like Write_Indent_Str, but in addition, in Debug_Generated_Code mode,
293 -- the Sloc of the current node is set to the first non-blank character
294 -- in the string S.
296 procedure Write_Itype (Typ : Entity_Id);
297 -- If Typ is an Itype that has not been written yet, write it. If Typ is
298 -- any other kind of entity or tree node, the call is ignored.
300 procedure Write_Name_With_Col_Check (N : Name_Id);
301 -- Write name (using Write_Name) with initial column check, and possible
302 -- initial Write_Indent (to get new line) if current line is too full.
304 procedure Write_Name_With_Col_Check_Sloc (N : Name_Id);
305 -- Like Write_Name_With_Col_Check but in addition, in Debug_Generated_Code
306 -- mode, sets Sloc of current debug node to first character of name.
308 procedure Write_Operator (N : Node_Id; S : String);
309 -- Like Write_Str_Sloc, used for operators, encloses the string in
310 -- characters {} if the Do_Overflow flag is set on the node N.
312 procedure Write_Param_Specs (N : Node_Id);
313 -- Output parameter specifications for node N (which is a subprogram, or
314 -- entry or entry family or access-subprogram-definition, all of which
315 -- have a Parameter_Specifications field).
317 procedure Write_Rewrite_Str (S : String);
318 -- Writes out a string (typically containing <<< or >>>}) for a node
319 -- created by rewriting the tree. Suppressed if we are outputting the
320 -- generated code only, since in this case we don't specially mark nodes
321 -- created by rewriting).
323 procedure Write_Source_Line (L : Physical_Line_Number);
324 -- If writing of interspersed source lines is enabled, then write the given
325 -- line from the source file, preceded by Eol, then an extra blank line if
326 -- the line has at least one blank, is not a comment and is not line one,
327 -- then "--" and the line number followed by period followed by text of the
328 -- source line (without terminating Eol). If interspersed source line
329 -- output not enabled, then the call has no effect.
331 procedure Write_Source_Lines (L : Physical_Line_Number);
332 -- If writing of interspersed source lines is enabled, then writes source
333 -- lines Last_Line_Printed + 1 .. L, and updates Last_Line_Printed. If
334 -- interspersed source line output not enabled, then call has no effect.
336 procedure Write_Str_Sloc (S : String);
337 -- Like Write_Str, but sets debug Sloc of current debug node to first
338 -- non-blank character if a current debug node is active.
340 procedure Write_Str_With_Col_Check (S : String);
341 -- Write string (using Write_Str) with initial column check, and possible
342 -- initial Write_Indent (to get new line) if current line is too full.
344 procedure Write_Str_With_Col_Check_Sloc (S : String);
345 -- Like Write_Str_With_Col_Check, but sets debug Sloc of current debug
346 -- node to first non-blank character if a current debug node is active.
348 procedure Write_Subprogram_Name (N : Node_Id);
349 -- N is the Name field of a function call or procedure statement call.
350 -- The effect of the call is to output the name, preceded by a $ if the
351 -- call is identified as an implicit call to a run time routine.
353 procedure Write_Uint_With_Col_Check (U : Uint; Format : UI_Format);
354 -- Write Uint (using UI_Write) with initial column check, and possible
355 -- initial Write_Indent (to get new line) if current line is too full.
356 -- The format parameter determines the output format (see UI_Write).
358 procedure Write_Uint_With_Col_Check_Sloc (U : Uint; Format : UI_Format);
359 -- Write Uint (using UI_Write) with initial column check, and possible
360 -- initial Write_Indent (to get new line) if current line is too full.
361 -- The format parameter determines the output format (see UI_Write).
362 -- In addition, in Debug_Generated_Code mode, sets the current node
363 -- Sloc to the first character of the output value.
365 procedure Write_Ureal_With_Col_Check_Sloc (U : Ureal);
366 -- Write Ureal (using same output format as UR_Write) with column checks
367 -- and a possible initial Write_Indent (to get new line) if current line
368 -- is too full. In addition, in Debug_Generated_Code mode, sets the
369 -- current node Sloc to the first character of the output value.
371 ---------------
372 -- Col_Check --
373 ---------------
375 procedure Col_Check (N : Nat) is
376 begin
377 if N + Column > Sprint_Line_Limit then
378 Write_Indent_Str (" ");
379 end if;
380 end Col_Check;
382 ----------------------
383 -- Extra_Blank_Line --
384 ----------------------
386 procedure Extra_Blank_Line is
387 begin
388 if not Dump_Source_Text then
389 Write_Indent;
390 end if;
391 end Extra_Blank_Line;
393 -------------------
394 -- Indent_Annull --
395 -------------------
397 procedure Indent_Annull is
398 begin
399 Indent_Annull_Flag := True;
400 end Indent_Annull;
402 ------------------
403 -- Indent_Begin --
404 ------------------
406 procedure Indent_Begin is
407 begin
408 Indent := Indent + 3;
409 end Indent_Begin;
411 ----------------
412 -- Indent_End --
413 ----------------
415 procedure Indent_End is
416 begin
417 Indent := Indent - 3;
418 end Indent_End;
420 --------
421 -- pg --
422 --------
424 procedure pg (Arg : Union_Id) is
425 begin
426 Dump_Generated_Only := True;
427 Dump_Original_Only := False;
428 Dump_Freeze_Null := True;
429 Current_Source_File := No_Source_File;
430 Push_Output;
431 Set_Standard_Output;
433 if Arg in List_Range then
434 Sprint_Node_List (List_Id (Arg), New_Lines => True);
436 elsif Arg in Node_Range then
437 Sprint_Node (Node_Id (Arg));
439 else
440 null;
441 end if;
443 Write_Eol;
444 Pop_Output;
445 end pg;
447 --------
448 -- po --
449 --------
451 procedure po (Arg : Union_Id) is
452 begin
453 Dump_Generated_Only := False;
454 Dump_Original_Only := True;
455 Dump_Freeze_Null := False;
456 Current_Source_File := No_Source_File;
457 Push_Output;
458 Set_Standard_Output;
460 if Arg in List_Range then
461 Sprint_Node_List (List_Id (Arg), New_Lines => True);
463 elsif Arg in Node_Range then
464 Sprint_Node (Node_Id (Arg));
466 else
467 null;
468 end if;
470 Write_Eol;
471 Pop_Output;
472 end po;
474 ----------------------
475 -- Print_Debug_Line --
476 ----------------------
478 procedure Print_Debug_Line (S : String) is
479 begin
480 Write_Debug_Line (S, Debug_Sloc);
481 end Print_Debug_Line;
483 --------
484 -- ps --
485 --------
487 procedure ps (Arg : Union_Id) is
488 begin
489 Dump_Generated_Only := False;
490 Dump_Original_Only := False;
491 Dump_Freeze_Null := False;
492 Current_Source_File := No_Source_File;
493 Push_Output;
494 Set_Standard_Output;
496 if Arg in List_Range then
497 Sprint_Node_List (List_Id (Arg), New_Lines => True);
499 elsif Arg in Node_Range then
500 Sprint_Node (Node_Id (Arg));
502 else
503 null;
504 end if;
506 Write_Eol;
507 Pop_Output;
508 end ps;
510 --------------------
511 -- Set_Debug_Sloc --
512 --------------------
514 procedure Set_Debug_Sloc is
515 begin
516 if Debug_Generated_Code and then Present (Dump_Node) then
517 declare
518 Loc : constant Source_Ptr := Sloc (Dump_Node);
520 begin
521 -- Do not change the location of nodes defined in package Standard
522 -- and nodes of pragmas scanned by Targparm.
524 if Loc <= Standard_Location then
525 null;
527 -- Update the location of a node which is part of the current .dg
528 -- output. This situation occurs in comma separated parameter
529 -- declarations since each parameter references the same parameter
530 -- type node (ie. obj1, obj2 : <param-type>).
532 -- Note: This case is needed here since we cannot use the routine
533 -- In_Extended_Main_Code_Unit with nodes whose location is a .dg
534 -- file.
536 elsif Loc >= First_Debug_Sloc then
537 Set_Sloc (Dump_Node, Debug_Sloc + Source_Ptr (Column - 1));
539 -- Do not change the location of nodes which are not part of the
540 -- generated code
542 elsif not In_Extended_Main_Code_Unit (Loc) then
543 null;
545 else
546 Set_Sloc (Dump_Node, Debug_Sloc + Source_Ptr (Column - 1));
547 end if;
548 end;
550 -- We do not know the actual end location in the generated code and
551 -- it could be much closer than in the source code, so play safe.
553 if Nkind (Dump_Node) in N_Case_Statement | N_If_Statement then
554 Set_End_Location (Dump_Node, Debug_Sloc + Source_Ptr (Column - 1));
555 end if;
557 Dump_Node := Empty;
558 end if;
559 end Set_Debug_Sloc;
561 -----------------
562 -- Source_Dump --
563 -----------------
565 procedure Source_Dump is
567 procedure Underline;
568 -- Put underline under string we just printed
570 ---------------
571 -- Underline --
572 ---------------
574 procedure Underline is
575 Col : constant Int := Column;
577 begin
578 Write_Eol;
580 while Col > Column loop
581 Write_Char ('-');
582 end loop;
584 Write_Eol;
585 end Underline;
587 -- Start of processing for Source_Dump
589 begin
590 Dump_Generated_Only := Debug_Flag_G or
591 Print_Generated_Code or
592 Debug_Generated_Code;
593 Dump_Original_Only := Debug_Flag_O;
594 Dump_Freeze_Null := Debug_Flag_S or Dump_Generated_Only;
596 -- Note that we turn off the tree dump flags immediately, before
597 -- starting the dump. This avoids generating two copies of the dump
598 -- if an abort occurs after printing the dump, and more importantly,
599 -- avoids an infinite loop if an abort occurs during the dump.
601 if Debug_Flag_Z then
602 Current_Source_File := No_Source_File;
603 Debug_Flag_Z := False;
604 Write_Eol;
605 Write_Eol;
606 Write_Str ("Source recreated from tree of Standard (spec)");
607 Underline;
608 Sprint_Node (Standard_Package_Node);
609 Write_Eol;
610 Write_Eol;
611 end if;
613 if Debug_Flag_S or Dump_Generated_Only or Dump_Original_Only then
614 Debug_Flag_G := False;
615 Debug_Flag_O := False;
616 Debug_Flag_S := False;
617 First_Debug_Sloc := No_Location;
619 -- Dump requested units
621 for U in Main_Unit .. Last_Unit loop
622 Current_Source_File := Source_Index (U);
624 -- Dump all units if -gnatdf set, otherwise dump only the source
625 -- files that are in the extended main source. Note that, if we
626 -- are generating debug files, generating that of the main unit
627 -- has an effect on the outcome of In_Extended_Main_Source_Unit
628 -- because slocs are rewritten, so we also test for equality of
629 -- Cunit_Entity to work around this effect.
631 if Debug_Flag_F
632 or else In_Extended_Main_Source_Unit (Cunit_Entity (U))
633 or else Cunit_Entity (U) = Cunit_Entity (Main_Unit)
634 then
635 -- If we are generating debug files, setup to write them
637 if Debug_Generated_Code then
638 Set_Special_Output (Print_Debug_Line'Access);
639 Create_Debug_Source (Source_Index (U), Debug_Sloc);
640 First_Debug_Sloc := Debug_Sloc;
641 Write_Source_Line (1);
642 Last_Line_Printed := 1;
644 -- If this unit has the same entity as the main unit, for
645 -- example is the spec of a stand-alone instantiation of
646 -- a package and the main unit is the body, its debug file
647 -- will also be the same. Therefore, we need to print again
648 -- the main unit to have both units in the debug file.
650 if U /= Main_Unit
651 and then Cunit_Entity (U) = Cunit_Entity (Main_Unit)
652 then
653 Sprint_Node (Cunit (Main_Unit));
654 Write_Eol;
655 end if;
657 Sprint_Node (Cunit (U));
658 Write_Source_Lines (Last_Source_Line (Current_Source_File));
659 Write_Eol;
660 Close_Debug_Source;
661 Cancel_Special_Output;
663 -- Normal output to standard output file
665 else
666 Write_Str ("Source recreated from tree for ");
667 Write_Unit_Name (Unit_Name (U));
668 Underline;
669 Write_Source_Line (1);
670 Last_Line_Printed := 1;
671 Sprint_Node (Cunit (U));
672 Write_Source_Lines (Last_Source_Line (Current_Source_File));
673 Write_Eol;
674 Write_Eol;
675 end if;
676 end if;
677 end loop;
678 end if;
680 -- See above for the rationale, but we cannot do it earlier for them
682 Print_Generated_Code := False;
683 Debug_Generated_Code := False;
684 end Source_Dump;
686 ---------------------
687 -- Sprint_And_List --
688 ---------------------
690 procedure Sprint_And_List (List : List_Id) is
691 Node : Node_Id;
692 begin
693 if Is_Non_Empty_List (List) then
694 Node := First (List);
695 loop
696 Sprint_Node (Node);
697 Next (Node);
698 exit when Node = Empty;
699 Write_Str (" and ");
700 end loop;
701 end if;
702 end Sprint_And_List;
704 ----------------------------------
705 -- Sprint_Aspect_Specifications --
706 ----------------------------------
708 procedure Sprint_Aspect_Specifications
709 (Node : Node_Id;
710 Semicolon : Boolean)
712 AS : constant List_Id := Aspect_Specifications (Node);
713 A : Node_Id;
715 begin
716 if Semicolon then
717 Write_Erase_Char (';');
718 Indent := Indent + 2;
719 Write_Indent;
720 Write_Str ("with ");
721 Indent := Indent + 5;
723 else
724 Write_Str (" with ");
725 end if;
727 A := First (AS);
728 loop
729 Sprint_Node (Identifier (A));
731 if Class_Present (A) then
732 Write_Str ("'Class");
733 end if;
735 if Present (Expression (A)) then
736 Write_Str (" => ");
737 Sprint_Node (Expression (A));
738 end if;
740 Next (A);
742 exit when No (A);
743 Write_Char (',');
745 if Semicolon then
746 Write_Indent;
747 end if;
748 end loop;
750 if Semicolon then
751 Indent := Indent - 7;
752 Write_Char (';');
753 end if;
754 end Sprint_Aspect_Specifications;
756 ------------------------
757 -- Sprint_At_End_Proc --
758 ------------------------
760 procedure Sprint_At_End_Proc (Node : Node_Id) is
761 begin
762 if Present (At_End_Proc (Node)) then
763 Write_Indent_Str ("at end");
764 Indent_Begin;
765 Write_Indent;
766 Sprint_Node (At_End_Proc (Node));
767 Write_Char (';');
768 Indent_End;
769 end if;
770 end Sprint_At_End_Proc;
772 ---------------------
773 -- Sprint_Bar_List --
774 ---------------------
776 procedure Sprint_Bar_List (List : List_Id) is
777 Node : Node_Id;
778 begin
779 if Is_Non_Empty_List (List) then
780 Node := First (List);
781 loop
782 Sprint_Node (Node);
783 Next (Node);
784 exit when Node = Empty;
785 Write_Str (" | ");
786 end loop;
787 end if;
788 end Sprint_Bar_List;
790 ----------------------
791 -- Sprint_End_Label --
792 ----------------------
794 procedure Sprint_End_Label
795 (Node : Node_Id;
796 Default : Node_Id)
798 begin
799 if Present (Node)
800 and then Present (End_Label (Node))
801 and then Is_Entity_Name (End_Label (Node))
802 then
803 Set_Entity (End_Label (Node), Default);
805 -- For a function whose name is an operator, use the qualified name
806 -- created for the defining entity.
808 if Nkind (End_Label (Node)) = N_Operator_Symbol then
809 Set_Chars (End_Label (Node), Chars (Default));
810 end if;
812 Sprint_Node (End_Label (Node));
813 else
814 Sprint_Node (Default);
815 end if;
816 end Sprint_End_Label;
818 -----------------------
819 -- Sprint_Comma_List --
820 -----------------------
822 procedure Sprint_Comma_List (List : List_Id) is
823 Node : Node_Id;
825 begin
826 if Is_Non_Empty_List (List) then
827 Node := First (List);
828 loop
829 Sprint_Node (Node);
830 Next (Node);
831 exit when Node = Empty;
833 if not Is_Rewrite_Insertion (Node)
834 or else not Dump_Original_Only
835 then
836 Write_Str (", ");
837 end if;
838 end loop;
839 end if;
840 end Sprint_Comma_List;
842 --------------------------
843 -- Sprint_Indented_List --
844 --------------------------
846 procedure Sprint_Indented_List (List : List_Id) is
847 begin
848 Indent_Begin;
849 Sprint_Node_List (List);
850 Indent_End;
851 end Sprint_Indented_List;
853 ---------------------
854 -- Sprint_Left_Opnd --
855 ---------------------
857 procedure Sprint_Left_Opnd (N : Node_Id) is
858 Opnd : constant Node_Id := Left_Opnd (N);
860 begin
861 if Paren_Count (Opnd) /= 0
862 or else Op_Prec (Nkind (Opnd)) >= Op_Prec (Nkind (N))
863 then
864 Sprint_Node (Opnd);
866 else
867 Write_Char ('(');
868 Sprint_Node (Opnd);
869 Write_Char (')');
870 end if;
871 end Sprint_Left_Opnd;
873 -----------------
874 -- Sprint_Node --
875 -----------------
877 procedure Sprint_Node (Node : Node_Id) is
878 begin
879 if Is_Rewrite_Insertion (Node) then
880 if not Dump_Original_Only then
882 -- For special cases of nodes that always output <<< >>>
883 -- do not duplicate the output at this point.
885 if Nkind (Node) = N_Freeze_Entity
886 or else Nkind (Node) = N_Freeze_Generic_Entity
887 or else Nkind (Node) = N_Implicit_Label_Declaration
888 then
889 Sprint_Node_Actual (Node);
891 -- Normal case where <<< >>> may be required
893 else
894 Write_Rewrite_Str ("<<<");
895 Sprint_Node_Actual (Node);
896 Write_Rewrite_Str (">>>");
897 end if;
898 end if;
900 elsif Is_Rewrite_Substitution (Node) then
902 -- Case of dump generated only
904 if Dump_Generated_Only then
905 Sprint_Node_Actual (Node);
907 -- Case of dump original only
909 elsif Dump_Original_Only then
910 Sprint_Node_Actual (Original_Node (Node));
912 -- Case of both being dumped
914 else
915 Sprint_Node_Actual (Original_Node (Node));
916 Write_Rewrite_Str ("<<<");
917 Sprint_Node_Actual (Node);
918 Write_Rewrite_Str (">>>");
919 end if;
921 else
922 Sprint_Node_Actual (Node);
923 end if;
924 end Sprint_Node;
926 ------------------------
927 -- Sprint_Node_Actual --
928 ------------------------
930 procedure Sprint_Node_Actual (Node : Node_Id) is
931 Save_Dump_Node : constant Node_Id := Dump_Node;
933 begin
934 if Node = Empty then
935 return;
936 end if;
938 for J in 1 .. Paren_Count (Node) loop
939 Write_Str_With_Col_Check ("(");
940 end loop;
942 -- Setup current dump node
944 Dump_Node := Node;
946 if Nkind (Node) in N_Subexpr
947 and then Do_Range_Check (Node)
948 then
949 Write_Str_With_Col_Check ("{");
950 end if;
952 -- Select print circuit based on node kind
954 case Nkind (Node) is
955 when N_Abort_Statement =>
956 Write_Indent_Str_Sloc ("abort ");
957 Sprint_Comma_List (Names (Node));
958 Write_Char (';');
960 when N_Abortable_Part =>
961 Set_Debug_Sloc;
962 Write_Str_Sloc ("abort ");
963 Sprint_Indented_List (Statements (Node));
965 when N_Abstract_Subprogram_Declaration =>
966 Write_Indent;
967 Sprint_Node (Specification (Node));
968 Write_Str_With_Col_Check (" is ");
969 Write_Str_Sloc ("abstract;");
971 when N_Accept_Alternative =>
972 Sprint_Node_List (Pragmas_Before (Node));
974 if Present (Condition (Node)) then
975 Write_Indent_Str ("when ");
976 Sprint_Node (Condition (Node));
977 Write_Str (" => ");
978 Indent_Annull;
979 end if;
981 Sprint_Node_Sloc (Accept_Statement (Node));
982 Sprint_Node_List (Statements (Node));
984 when N_Accept_Statement =>
985 Write_Indent_Str_Sloc ("accept ");
986 Write_Id (Entry_Direct_Name (Node));
988 if Present (Entry_Index (Node)) then
989 Write_Str_With_Col_Check (" (");
990 Sprint_Node (Entry_Index (Node));
991 Write_Char (')');
992 end if;
994 Write_Param_Specs (Node);
996 if Present (Handled_Statement_Sequence (Node)) then
997 Write_Str_With_Col_Check (" do");
998 Sprint_Node (Handled_Statement_Sequence (Node));
999 Write_Indent_Str ("end ");
1000 Write_Id (Entry_Direct_Name (Node));
1001 end if;
1003 Write_Char (';');
1005 when N_Access_Definition =>
1007 -- Ada 2005 (AI-254)
1009 if Present (Access_To_Subprogram_Definition (Node)) then
1010 Sprint_Node (Access_To_Subprogram_Definition (Node));
1011 else
1012 -- Ada 2005 (AI-231)
1014 if Null_Exclusion_Present (Node) then
1015 Write_Str ("not null ");
1016 end if;
1018 Write_Str_With_Col_Check_Sloc ("access ");
1020 if All_Present (Node) then
1021 Write_Str ("all ");
1022 elsif Constant_Present (Node) then
1023 Write_Str ("constant ");
1024 end if;
1026 Sprint_Node (Subtype_Mark (Node));
1027 end if;
1029 when N_Access_Function_Definition =>
1031 -- Ada 2005 (AI-231)
1033 if Null_Exclusion_Present (Node) then
1034 Write_Str ("not null ");
1035 end if;
1037 Write_Str_With_Col_Check_Sloc ("access ");
1039 if Protected_Present (Node) then
1040 Write_Str_With_Col_Check ("protected ");
1041 end if;
1043 Write_Str_With_Col_Check ("function");
1044 Write_Param_Specs (Node);
1045 Write_Str_With_Col_Check (" return ");
1046 Sprint_Node (Result_Definition (Node));
1048 when N_Access_Procedure_Definition =>
1050 -- Ada 2005 (AI-231)
1052 if Null_Exclusion_Present (Node) then
1053 Write_Str ("not null ");
1054 end if;
1056 Write_Str_With_Col_Check_Sloc ("access ");
1058 if Protected_Present (Node) then
1059 Write_Str_With_Col_Check ("protected ");
1060 end if;
1062 Write_Str_With_Col_Check ("procedure");
1063 Write_Param_Specs (Node);
1065 when N_Access_To_Object_Definition =>
1066 Write_Str_With_Col_Check_Sloc ("access ");
1068 if All_Present (Node) then
1069 Write_Str_With_Col_Check ("all ");
1070 elsif Constant_Present (Node) then
1071 Write_Str_With_Col_Check ("constant ");
1072 end if;
1074 -- Ada 2005 (AI-231)
1076 if Null_Exclusion_Present (Node) then
1077 Write_Str ("not null ");
1078 end if;
1080 Sprint_Node (Subtype_Indication (Node));
1082 when N_Aggregate =>
1083 if Null_Record_Present (Node) then
1084 Write_Str_With_Col_Check_Sloc ("(null record)");
1086 else
1087 Write_Str_With_Col_Check_Sloc
1088 (if Is_Homogeneous_Aggregate (Node) then "[" else "(");
1090 if Present (Expressions (Node)) then
1091 Sprint_Comma_List (Expressions (Node));
1093 if not Is_Empty_List (Component_Associations (Node)) then
1094 Write_Str (", ");
1095 end if;
1096 end if;
1098 if not Is_Empty_List (Component_Associations (Node)) then
1099 Indent_Begin;
1101 declare
1102 Nd : Node_Id;
1104 begin
1105 Nd := First (Component_Associations (Node));
1107 loop
1108 Write_Indent;
1109 Sprint_Node (Nd);
1110 Next (Nd);
1111 exit when No (Nd);
1113 if not Is_Rewrite_Insertion (Nd)
1114 or else not Dump_Original_Only
1115 then
1116 Write_Str (", ");
1117 end if;
1118 end loop;
1119 end;
1121 Indent_End;
1122 end if;
1124 Write_Char
1125 (if Is_Homogeneous_Aggregate (Node) then ']' else ')');
1126 end if;
1128 when N_Allocator =>
1129 Write_Str_With_Col_Check_Sloc ("new ");
1131 -- Ada 2005 (AI-231)
1133 if Null_Exclusion_Present (Node) then
1134 Write_Str ("not null ");
1135 end if;
1137 Sprint_Node (Expression (Node));
1139 if Present (Storage_Pool (Node)) then
1140 Write_Str_With_Col_Check ("[storage_pool = ");
1141 Sprint_Node (Storage_Pool (Node));
1142 Write_Char (']');
1143 end if;
1145 if Present (Procedure_To_Call (Node)) then
1146 Write_Str_With_Col_Check ("[procedure_to_call = ");
1147 Sprint_Node (Procedure_To_Call (Node));
1148 Write_Char (']');
1149 end if;
1151 when N_And_Then =>
1152 Sprint_Left_Opnd (Node);
1153 Write_Str_Sloc (" and then ");
1154 Sprint_Right_Opnd (Node);
1156 -- Note: the following code for N_Aspect_Specification is not
1157 -- normally used, since we deal with aspects as part of a
1158 -- declaration, but it is here in case we deliberately try
1159 -- to print an N_Aspect_Specification node (e.g. from GDB).
1161 when N_Aspect_Specification =>
1162 Sprint_Node (Identifier (Node));
1163 Write_Str (" => ");
1164 Sprint_Node (Expression (Node));
1166 when N_Assignment_Statement =>
1167 Write_Indent;
1168 Sprint_Node (Name (Node));
1169 Write_Str_Sloc (" := ");
1170 Sprint_Node (Expression (Node));
1171 Write_Char (';');
1173 when N_Asynchronous_Select =>
1174 Write_Indent_Str_Sloc ("select");
1175 Indent_Begin;
1176 Sprint_Node (Triggering_Alternative (Node));
1177 Indent_End;
1179 -- Note: let the printing of Abortable_Part handle outputting
1180 -- the ABORT keyword, so that the Sloc can be set correctly.
1182 Write_Indent_Str ("then ");
1183 Sprint_Node (Abortable_Part (Node));
1184 Write_Indent_Str ("end select;");
1186 when N_At_Clause =>
1187 Write_Indent_Str_Sloc ("for ");
1188 Write_Id (Identifier (Node));
1189 Write_Str_With_Col_Check (" use at ");
1190 Sprint_Node (Expression (Node));
1191 Write_Char (';');
1193 when N_Attribute_Definition_Clause =>
1194 Write_Indent_Str_Sloc ("for ");
1195 Sprint_Node (Name (Node));
1196 Write_Char (''');
1197 Write_Name_With_Col_Check (Chars (Node));
1198 Write_Str_With_Col_Check (" use ");
1199 Sprint_Node (Expression (Node));
1200 Write_Char (';');
1202 when N_Attribute_Reference =>
1203 if Is_Procedure_Attribute_Name (Attribute_Name (Node)) then
1204 Write_Indent;
1205 end if;
1207 Sprint_Node (Prefix (Node));
1208 Write_Char_Sloc (''');
1209 Write_Name_With_Col_Check (Attribute_Name (Node));
1210 Sprint_Paren_Comma_List (Expressions (Node));
1212 if Is_Procedure_Attribute_Name (Attribute_Name (Node)) then
1213 Write_Char (';');
1214 end if;
1216 when N_Block_Statement =>
1217 Write_Indent;
1219 if Present (Identifier (Node))
1220 and then (not Has_Created_Identifier (Node)
1221 or else not Dump_Original_Only)
1222 then
1223 Write_Rewrite_Str ("<<<");
1224 Write_Id (Identifier (Node));
1225 Write_Str (" : ");
1226 Write_Rewrite_Str (">>>");
1227 end if;
1229 if Present (Declarations (Node)) then
1230 Write_Str_With_Col_Check_Sloc ("declare");
1231 Sprint_Indented_List (Declarations (Node));
1232 Write_Indent;
1233 end if;
1235 Write_Str_With_Col_Check_Sloc ("begin");
1236 Sprint_Node (Handled_Statement_Sequence (Node));
1237 Write_Indent_Str ("end");
1239 if Present (Identifier (Node))
1240 and then (not Has_Created_Identifier (Node)
1241 or else not Dump_Original_Only)
1242 then
1243 Write_Rewrite_Str ("<<<");
1244 Write_Char (' ');
1245 Write_Id (Identifier (Node));
1246 Write_Rewrite_Str (">>>");
1247 end if;
1249 Write_Char (';');
1250 Sprint_At_End_Proc (Node);
1252 when N_Call_Marker =>
1253 null;
1255 -- Enable the following code for debugging purposes only
1257 -- Write_Indent_Str ("#");
1258 -- Write_Id (Target (Node));
1259 -- Write_Char ('#');
1261 when N_Case_Expression =>
1262 declare
1263 Has_Parens : constant Boolean := Paren_Count (Node) > 0;
1264 Alt : Node_Id;
1266 begin
1267 -- The syntax for case_expression does not include parentheses,
1268 -- but sometimes parentheses are required, so unconditionally
1269 -- generate them here unless already present.
1271 if not Has_Parens then
1272 Write_Char ('(');
1273 end if;
1275 Write_Str_With_Col_Check_Sloc ("case ");
1276 Sprint_Node (Expression (Node));
1277 Write_Str_With_Col_Check (" is");
1279 Alt := First (Alternatives (Node));
1280 loop
1281 Sprint_Node (Alt);
1282 Next (Alt);
1283 exit when No (Alt);
1284 Write_Char (',');
1285 end loop;
1287 if not Has_Parens then
1288 Write_Char (')');
1289 end if;
1290 end;
1292 when N_Case_Expression_Alternative =>
1293 Write_Str_With_Col_Check (" when ");
1294 Sprint_Bar_List (Discrete_Choices (Node));
1295 Write_Str (" => ");
1296 Sprint_Node (Expression (Node));
1298 when N_Case_Statement =>
1299 Write_Indent_Str_Sloc ("case ");
1300 Sprint_Node (Expression (Node));
1301 Write_Str (" is");
1302 Sprint_Indented_List (Alternatives (Node));
1303 Write_Indent_Str ("end case;");
1305 when N_Case_Statement_Alternative =>
1306 Write_Indent_Str_Sloc ("when ");
1307 Sprint_Bar_List (Discrete_Choices (Node));
1308 Write_Str (" => ");
1309 Sprint_Indented_List (Statements (Node));
1311 when N_Character_Literal =>
1312 if Column > Sprint_Line_Limit - 2 then
1313 Write_Indent_Str (" ");
1314 end if;
1316 Write_Char_Sloc (''');
1317 Write_Char_Code (UI_To_CC (Char_Literal_Value (Node)));
1318 Write_Char (''');
1320 when N_Code_Statement =>
1321 Write_Indent;
1322 Set_Debug_Sloc;
1323 Sprint_Node (Expression (Node));
1324 Write_Char (';');
1326 when N_Compilation_Unit =>
1327 Sprint_Node_List (Context_Items (Node));
1328 Sprint_Opt_Node_List (Declarations (Aux_Decls_Node (Node)));
1330 if Private_Present (Node) then
1331 Write_Indent_Str ("private ");
1332 Indent_Annull;
1333 end if;
1335 Sprint_Node_Sloc (Unit (Node));
1337 if Present (Actions (Aux_Decls_Node (Node)))
1338 or else
1339 Present (Pragmas_After (Aux_Decls_Node (Node)))
1340 then
1341 Write_Indent;
1342 end if;
1344 Sprint_Opt_Node_List (Actions (Aux_Decls_Node (Node)));
1345 Sprint_Opt_Node_List (Pragmas_After (Aux_Decls_Node (Node)));
1347 when N_Compilation_Unit_Aux =>
1348 null; -- nothing to do, never used, see above
1350 when N_Component_Association =>
1351 Set_Debug_Sloc;
1352 Sprint_Bar_List (Choices (Node));
1353 Write_Str (" => ");
1355 -- Ada 2005 (AI-287): Print the box if present
1357 if Box_Present (Node) then
1358 Write_Str_With_Col_Check ("<>");
1359 else
1360 Sprint_Node (Expression (Node));
1361 end if;
1363 when N_Iterated_Component_Association =>
1364 Set_Debug_Sloc;
1365 Write_Str (" for ");
1366 if Present (Iterator_Specification (Node)) then
1367 Sprint_Node (Iterator_Specification (Node));
1368 else
1369 Write_Id (Defining_Identifier (Node));
1370 Write_Str (" in ");
1371 Sprint_Bar_List (Discrete_Choices (Node));
1372 end if;
1373 Write_Str (" => ");
1374 Sprint_Node (Expression (Node));
1376 when N_Iterated_Element_Association =>
1377 Set_Debug_Sloc;
1378 if Present (Iterator_Specification (Node)) then
1379 Sprint_Node (Iterator_Specification (Node));
1380 else
1381 Sprint_Node (Loop_Parameter_Specification (Node));
1382 end if;
1384 if Present (Key_Expression (Node)) then
1385 Write_Str (" use ");
1386 Sprint_Node (Key_Expression (Node));
1387 end if;
1389 Write_Str (" => ");
1390 Sprint_Node (Expression (Node));
1392 when N_Component_Clause =>
1393 Write_Indent;
1394 Sprint_Node (Component_Name (Node));
1395 Write_Str_Sloc (" at ");
1396 Sprint_Node (Position (Node));
1397 Write_Char (' ');
1398 Write_Str_With_Col_Check ("range ");
1399 Sprint_Node (First_Bit (Node));
1400 Write_Str (" .. ");
1401 Sprint_Node (Last_Bit (Node));
1402 Write_Char (';');
1404 when N_Component_Definition =>
1405 Set_Debug_Sloc;
1407 -- Ada 2005 (AI-230): Access definition components
1409 if Present (Access_Definition (Node)) then
1410 Sprint_Node (Access_Definition (Node));
1412 elsif Present (Subtype_Indication (Node)) then
1413 if Aliased_Present (Node) then
1414 Write_Str_With_Col_Check ("aliased ");
1415 end if;
1417 -- Ada 2005 (AI-231)
1419 if Null_Exclusion_Present (Node) then
1420 Write_Str (" not null ");
1421 end if;
1423 Sprint_Node (Subtype_Indication (Node));
1425 else
1426 Write_Str (" ??? ");
1427 end if;
1429 when N_Component_Declaration =>
1430 if Write_Indent_Identifiers_Sloc (Node) then
1431 Write_Str (" : ");
1432 Sprint_Node (Component_Definition (Node));
1434 if Present (Expression (Node)) then
1435 Write_Str (" := ");
1436 Sprint_Node (Expression (Node));
1437 end if;
1439 Write_Char (';');
1440 end if;
1442 when N_Component_List =>
1443 if Null_Present (Node) then
1444 Indent_Begin;
1445 Write_Indent_Str_Sloc ("null");
1446 Write_Char (';');
1447 Indent_End;
1449 else
1450 Set_Debug_Sloc;
1451 Sprint_Indented_List (Component_Items (Node));
1452 Sprint_Node (Variant_Part (Node));
1453 end if;
1455 when N_Compound_Statement =>
1456 Write_Indent_Str ("do");
1457 Indent_Begin;
1458 Sprint_Node_List (Actions (Node));
1459 Indent_End;
1460 Write_Indent_Str ("end;");
1462 when N_Conditional_Entry_Call =>
1463 Write_Indent_Str_Sloc ("select");
1464 Indent_Begin;
1465 Sprint_Node (Entry_Call_Alternative (Node));
1466 Indent_End;
1467 Write_Indent_Str ("else");
1468 Sprint_Indented_List (Else_Statements (Node));
1469 Write_Indent_Str ("end select;");
1471 when N_Constrained_Array_Definition =>
1472 Write_Str_With_Col_Check_Sloc ("array ");
1473 Sprint_Paren_Comma_List (Discrete_Subtype_Definitions (Node));
1474 Write_Str (" of ");
1476 Sprint_Node (Component_Definition (Node));
1478 -- A contract node should not appear in the tree. It is a semantic
1479 -- node attached to entry and [generic] subprogram entities. But we
1480 -- still provide meaningful output, in case called from the debugger.
1482 when N_Contract =>
1483 declare
1484 P : Node_Id;
1486 begin
1487 Indent_Begin;
1488 Write_Str ("N_Contract node");
1489 Write_Eol;
1491 Write_Indent_Str ("Pre_Post_Conditions");
1492 Indent_Begin;
1494 P := Pre_Post_Conditions (Node);
1495 while Present (P) loop
1496 Sprint_Node (P);
1497 P := Next_Pragma (P);
1498 end loop;
1500 Write_Eol;
1501 Indent_End;
1503 Write_Indent_Str ("Contract_Test_Cases");
1504 Indent_Begin;
1506 P := Contract_Test_Cases (Node);
1507 while Present (P) loop
1508 Sprint_Node (P);
1509 P := Next_Pragma (P);
1510 end loop;
1512 Write_Eol;
1513 Indent_End;
1515 Write_Indent_Str ("Classifications");
1516 Indent_Begin;
1518 P := Classifications (Node);
1519 while Present (P) loop
1520 Sprint_Node (P);
1521 P := Next_Pragma (P);
1522 end loop;
1524 Write_Eol;
1525 Indent_End;
1526 Indent_End;
1527 end;
1529 when N_Decimal_Fixed_Point_Definition =>
1530 Write_Str_With_Col_Check_Sloc ("delta ");
1531 Sprint_Node (Delta_Expression (Node));
1532 Write_Str_With_Col_Check (" digits ");
1533 Sprint_Node (Digits_Expression (Node));
1534 Sprint_Opt_Node (Real_Range_Specification (Node));
1536 when N_Defining_Character_Literal =>
1537 Write_Name_With_Col_Check_Sloc (Chars (Node));
1539 when N_Defining_Identifier =>
1540 Set_Debug_Sloc;
1541 Write_Id (Node);
1543 when N_Defining_Operator_Symbol =>
1544 Write_Name_With_Col_Check_Sloc (Chars (Node));
1546 when N_Defining_Program_Unit_Name =>
1547 Set_Debug_Sloc;
1548 Sprint_Node (Name (Node));
1549 Write_Char ('.');
1550 Write_Id (Defining_Identifier (Node));
1552 when N_Delay_Alternative =>
1553 Sprint_Node_List (Pragmas_Before (Node));
1555 if Present (Condition (Node)) then
1556 Write_Indent;
1557 Write_Str_With_Col_Check ("when ");
1558 Sprint_Node (Condition (Node));
1559 Write_Str (" => ");
1560 Indent_Annull;
1561 end if;
1563 Sprint_Node_Sloc (Delay_Statement (Node));
1564 Sprint_Node_List (Statements (Node));
1566 when N_Delay_Relative_Statement =>
1567 Write_Indent_Str_Sloc ("delay ");
1568 Sprint_Node (Expression (Node));
1569 Write_Char (';');
1571 when N_Delay_Until_Statement =>
1572 Write_Indent_Str_Sloc ("delay until ");
1573 Sprint_Node (Expression (Node));
1574 Write_Char (';');
1576 when N_Delta_Constraint =>
1577 Write_Str_With_Col_Check_Sloc ("delta ");
1578 Sprint_Node (Delta_Expression (Node));
1579 Sprint_Opt_Node (Range_Constraint (Node));
1581 when N_Derived_Type_Definition =>
1582 if Abstract_Present (Node) then
1583 Write_Str_With_Col_Check ("abstract ");
1584 end if;
1586 Write_Str_With_Col_Check ("new ");
1588 -- Ada 2005 (AI-231)
1590 if Null_Exclusion_Present (Node) then
1591 Write_Str_With_Col_Check ("not null ");
1592 end if;
1594 Sprint_Node (Subtype_Indication (Node));
1596 if Present (Interface_List (Node)) then
1597 Write_Str_With_Col_Check (" and ");
1598 Sprint_And_List (Interface_List (Node));
1599 Write_Str_With_Col_Check (" with ");
1600 end if;
1602 if Present (Record_Extension_Part (Node)) then
1603 if No (Interface_List (Node)) then
1604 Write_Str_With_Col_Check (" with ");
1605 end if;
1607 Sprint_Node (Record_Extension_Part (Node));
1608 end if;
1610 when N_Designator =>
1611 Sprint_Node (Name (Node));
1612 Write_Char_Sloc ('.');
1613 Write_Id (Identifier (Node));
1615 when N_Digits_Constraint =>
1616 Write_Str_With_Col_Check_Sloc ("digits ");
1617 Sprint_Node (Digits_Expression (Node));
1618 Sprint_Opt_Node (Range_Constraint (Node));
1620 when N_Discriminant_Association =>
1621 Set_Debug_Sloc;
1623 if Present (Selector_Names (Node)) then
1624 Sprint_Bar_List (Selector_Names (Node));
1625 Write_Str (" => ");
1626 end if;
1628 Set_Debug_Sloc;
1629 Sprint_Node (Expression (Node));
1631 when N_Discriminant_Specification =>
1632 Set_Debug_Sloc;
1634 if Write_Identifiers (Node) then
1635 Write_Str (" : ");
1637 if Null_Exclusion_Present (Node) then
1638 Write_Str ("not null ");
1639 end if;
1641 Sprint_Node (Discriminant_Type (Node));
1643 if Present (Expression (Node)) then
1644 Write_Str (" := ");
1645 Sprint_Node (Expression (Node));
1646 end if;
1647 else
1648 Write_Str (", ");
1649 end if;
1651 when N_Elsif_Part =>
1652 Write_Indent_Str_Sloc ("elsif ");
1653 Sprint_Node (Condition (Node));
1654 Write_Str_With_Col_Check (" then");
1655 Sprint_Indented_List (Then_Statements (Node));
1657 when N_Empty =>
1658 null;
1660 when N_Entry_Body =>
1661 Write_Indent_Str_Sloc ("entry ");
1662 Write_Id (Defining_Identifier (Node));
1663 Sprint_Node (Entry_Body_Formal_Part (Node));
1664 Write_Str_With_Col_Check (" is");
1665 Sprint_Indented_List (Declarations (Node));
1666 Write_Indent_Str ("begin");
1667 Sprint_Node (Handled_Statement_Sequence (Node));
1668 Write_Indent_Str ("end ");
1669 Write_Id (Defining_Identifier (Node));
1670 Write_Char (';');
1671 Sprint_At_End_Proc (Node);
1673 when N_Entry_Body_Formal_Part =>
1674 if Present (Entry_Index_Specification (Node)) then
1675 Write_Str_With_Col_Check_Sloc (" (");
1676 Sprint_Node (Entry_Index_Specification (Node));
1677 Write_Char (')');
1678 end if;
1680 Write_Param_Specs (Node);
1681 Write_Str_With_Col_Check_Sloc (" when ");
1682 Sprint_Node (Condition (Node));
1684 when N_Entry_Call_Alternative =>
1685 Sprint_Node_List (Pragmas_Before (Node));
1686 Sprint_Node_Sloc (Entry_Call_Statement (Node));
1687 Sprint_Node_List (Statements (Node));
1689 when N_Entry_Call_Statement =>
1690 Write_Indent;
1691 Sprint_Node_Sloc (Name (Node));
1692 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
1693 Write_Char (';');
1695 when N_Entry_Declaration =>
1696 Write_Indent_Str_Sloc ("entry ");
1697 Write_Id (Defining_Identifier (Node));
1699 if Present (Discrete_Subtype_Definition (Node)) then
1700 Write_Str_With_Col_Check (" (");
1701 Sprint_Node (Discrete_Subtype_Definition (Node));
1702 Write_Char (')');
1703 end if;
1705 Write_Param_Specs (Node);
1706 Write_Char (';');
1708 when N_Entry_Index_Specification =>
1709 Write_Str_With_Col_Check_Sloc ("for ");
1710 Write_Id (Defining_Identifier (Node));
1711 Write_Str_With_Col_Check (" in ");
1712 Sprint_Node (Discrete_Subtype_Definition (Node));
1714 when N_Enumeration_Representation_Clause =>
1715 Write_Indent_Str_Sloc ("for ");
1716 Write_Id (Identifier (Node));
1717 Write_Str_With_Col_Check (" use ");
1718 Sprint_Node (Array_Aggregate (Node));
1719 Write_Char (';');
1721 when N_Enumeration_Type_Definition =>
1722 Set_Debug_Sloc;
1724 -- Skip attempt to print Literals field if it's not there and
1725 -- we are in package Standard (case of Character, which is
1726 -- handled specially (without an explicit literals list).
1728 if Sloc (Node) > Standard_Location
1729 or else Present (Literals (Node))
1730 then
1731 Sprint_Paren_Comma_List (Literals (Node));
1732 end if;
1734 when N_Error =>
1735 Write_Str_With_Col_Check_Sloc ("<error>");
1737 when N_Exception_Declaration =>
1738 if Write_Indent_Identifiers (Node) then
1739 Write_Str_With_Col_Check (" : ");
1741 if Is_Statically_Allocated (Defining_Identifier (Node)) then
1742 Write_Str_With_Col_Check ("static ");
1743 end if;
1745 Write_Str_Sloc ("exception");
1747 if Present (Expression (Node)) then
1748 Write_Str (" := ");
1749 Sprint_Node (Expression (Node));
1750 end if;
1752 Write_Char (';');
1753 end if;
1755 when N_Exception_Handler =>
1756 Write_Indent_Str_Sloc ("when ");
1758 if Present (Choice_Parameter (Node)) then
1759 Sprint_Node (Choice_Parameter (Node));
1760 Write_Str (" : ");
1761 end if;
1763 Sprint_Bar_List (Exception_Choices (Node));
1764 Write_Str (" => ");
1765 Sprint_Indented_List (Statements (Node));
1767 when N_Exception_Renaming_Declaration =>
1768 Write_Indent;
1769 Set_Debug_Sloc;
1770 Sprint_Node (Defining_Identifier (Node));
1771 Write_Str_With_Col_Check (" : exception renames ");
1772 Sprint_Node (Name (Node));
1773 Write_Char (';');
1775 when N_Exit_Statement =>
1776 Write_Indent_Str_Sloc ("exit");
1777 Sprint_Opt_Node (Name (Node));
1779 if Present (Condition (Node)) then
1780 Write_Str_With_Col_Check (" when ");
1781 Sprint_Node (Condition (Node));
1782 end if;
1784 Write_Char (';');
1786 when N_Expanded_Name =>
1787 Sprint_Node (Prefix (Node));
1788 Write_Char_Sloc ('.');
1789 Sprint_Node (Selector_Name (Node));
1791 when N_Explicit_Dereference =>
1792 Sprint_Node (Prefix (Node));
1793 Write_Char_Sloc ('.');
1794 Write_Str_Sloc ("all");
1796 when N_Expression_With_Actions =>
1797 Indent_Begin;
1798 Write_Indent_Str_Sloc ("do ");
1799 Indent_Begin;
1800 Sprint_Node_List (Actions (Node));
1801 Indent_End;
1802 Write_Indent;
1803 Write_Str_With_Col_Check_Sloc ("in ");
1804 Sprint_Node (Expression (Node));
1805 Write_Str_With_Col_Check (" end");
1806 Indent_End;
1807 Write_Indent;
1809 when N_Expression_Function =>
1810 Write_Indent;
1811 Sprint_Node_Sloc (Specification (Node));
1812 Write_Str (" is");
1813 Indent_Begin;
1814 Write_Indent;
1815 Sprint_Node (Expression (Node));
1816 Write_Char (';');
1817 Indent_End;
1819 when N_Extended_Return_Statement =>
1820 Write_Indent_Str_Sloc ("return ");
1821 Sprint_Node_List (Return_Object_Declarations (Node));
1823 if Present (Handled_Statement_Sequence (Node)) then
1824 Write_Str_With_Col_Check (" do");
1825 Sprint_Node (Handled_Statement_Sequence (Node));
1826 Write_Indent_Str ("end return");
1827 end if;
1829 if Present (Storage_Pool (Node)) then
1830 Write_Str_With_Col_Check ("[storage_pool = ");
1831 Sprint_Node (Storage_Pool (Node));
1832 Write_Char (']');
1833 end if;
1835 if Present (Procedure_To_Call (Node)) then
1836 Write_Str_With_Col_Check ("[procedure_to_call = ");
1837 Sprint_Node (Procedure_To_Call (Node));
1838 Write_Char (']');
1839 end if;
1841 Write_Char (';');
1843 when N_Delta_Aggregate =>
1844 Write_Str_With_Col_Check_Sloc ("(");
1845 Sprint_Node (Expression (Node));
1846 Write_Str_With_Col_Check (" with delta ");
1847 Sprint_Comma_List (Component_Associations (Node));
1848 Write_Char (')');
1850 when N_Extension_Aggregate =>
1851 Write_Str_With_Col_Check_Sloc ("(");
1852 Sprint_Node (Ancestor_Part (Node));
1853 Write_Str_With_Col_Check (" with ");
1855 if Null_Record_Present (Node) then
1856 Write_Str_With_Col_Check ("null record");
1857 else
1858 if Present (Expressions (Node)) then
1859 Sprint_Comma_List (Expressions (Node));
1861 if Present (Component_Associations (Node)) then
1862 Write_Str (", ");
1863 end if;
1864 end if;
1866 if Present (Component_Associations (Node)) then
1867 Sprint_Comma_List (Component_Associations (Node));
1868 end if;
1869 end if;
1871 Write_Char (')');
1873 when N_Floating_Point_Definition =>
1874 Write_Str_With_Col_Check_Sloc ("digits ");
1875 Sprint_Node (Digits_Expression (Node));
1876 Sprint_Opt_Node (Real_Range_Specification (Node));
1878 when N_Formal_Decimal_Fixed_Point_Definition =>
1879 Write_Str_With_Col_Check_Sloc ("delta <> digits <>");
1881 when N_Formal_Derived_Type_Definition =>
1882 Write_Str_With_Col_Check_Sloc ("new ");
1883 Sprint_Node (Subtype_Mark (Node));
1885 if Present (Interface_List (Node)) then
1886 Write_Str_With_Col_Check (" and ");
1887 Sprint_And_List (Interface_List (Node));
1888 end if;
1890 if Private_Present (Node) then
1891 Write_Str_With_Col_Check (" with private");
1892 end if;
1894 when N_Formal_Abstract_Subprogram_Declaration =>
1895 Write_Indent_Str_Sloc ("with ");
1896 Sprint_Node (Specification (Node));
1898 Write_Str_With_Col_Check (" is abstract");
1900 if Box_Present (Node) then
1901 Write_Str_With_Col_Check (" <>");
1902 elsif Present (Default_Name (Node)) then
1903 Write_Str_With_Col_Check (" ");
1904 Sprint_Node (Default_Name (Node));
1905 end if;
1907 Write_Char (';');
1909 when N_Formal_Concrete_Subprogram_Declaration =>
1910 Write_Indent_Str_Sloc ("with ");
1911 Sprint_Node (Specification (Node));
1913 if Box_Present (Node) then
1914 Write_Str_With_Col_Check (" is <>");
1915 elsif Present (Default_Name (Node)) then
1916 Write_Str_With_Col_Check (" is ");
1917 Sprint_Node (Default_Name (Node));
1918 end if;
1920 Write_Char (';');
1922 when N_Formal_Discrete_Type_Definition =>
1923 Write_Str_With_Col_Check_Sloc ("<>");
1925 when N_Formal_Floating_Point_Definition =>
1926 Write_Str_With_Col_Check_Sloc ("digits <>");
1928 when N_Formal_Modular_Type_Definition =>
1929 Write_Str_With_Col_Check_Sloc ("mod <>");
1931 when N_Formal_Object_Declaration =>
1932 Set_Debug_Sloc;
1934 if Write_Indent_Identifiers (Node) then
1935 Write_Str (" : ");
1937 if In_Present (Node) then
1938 Write_Str_With_Col_Check ("in ");
1939 end if;
1941 if Out_Present (Node) then
1942 Write_Str_With_Col_Check ("out ");
1943 end if;
1945 if Present (Subtype_Mark (Node)) then
1947 -- Ada 2005 (AI-423): Formal object with null exclusion
1949 if Null_Exclusion_Present (Node) then
1950 Write_Str ("not null ");
1951 end if;
1953 Sprint_Node (Subtype_Mark (Node));
1955 -- Ada 2005 (AI-423): Formal object with access definition
1957 else
1958 pragma Assert (Present (Access_Definition (Node)));
1960 Sprint_Node (Access_Definition (Node));
1961 end if;
1963 if Present (Default_Expression (Node)) then
1964 Write_Str (" := ");
1965 Sprint_Node (Default_Expression (Node));
1966 end if;
1968 Write_Char (';');
1969 end if;
1971 when N_Formal_Ordinary_Fixed_Point_Definition =>
1972 Write_Str_With_Col_Check_Sloc ("delta <>");
1974 when N_Formal_Package_Declaration =>
1975 Write_Indent_Str_Sloc ("with package ");
1976 Write_Id (Defining_Identifier (Node));
1977 Write_Str_With_Col_Check (" is new ");
1978 Sprint_Node (Name (Node));
1979 Write_Str_With_Col_Check (" (<>);");
1981 when N_Formal_Private_Type_Definition =>
1982 if Abstract_Present (Node) then
1983 Write_Str_With_Col_Check ("abstract ");
1984 end if;
1986 if Tagged_Present (Node) then
1987 Write_Str_With_Col_Check ("tagged ");
1988 end if;
1990 if Limited_Present (Node) then
1991 Write_Str_With_Col_Check ("limited ");
1992 end if;
1994 Write_Str_With_Col_Check_Sloc ("private");
1996 when N_Formal_Incomplete_Type_Definition =>
1997 if Tagged_Present (Node) then
1998 Write_Str_With_Col_Check ("is tagged ");
1999 end if;
2001 when N_Formal_Signed_Integer_Type_Definition =>
2002 Write_Str_With_Col_Check_Sloc ("range <>");
2004 when N_Formal_Type_Declaration =>
2005 Write_Indent_Str_Sloc ("type ");
2006 Write_Id (Defining_Identifier (Node));
2008 if Present (Discriminant_Specifications (Node)) then
2009 Write_Discr_Specs (Node);
2010 elsif Unknown_Discriminants_Present (Node) then
2011 Write_Str_With_Col_Check ("(<>)");
2012 end if;
2014 if Nkind (Formal_Type_Definition (Node)) /=
2015 N_Formal_Incomplete_Type_Definition
2016 then
2017 Write_Str_With_Col_Check (" is ");
2018 end if;
2020 Sprint_Node (Formal_Type_Definition (Node));
2021 Write_Char (';');
2023 when N_Free_Statement =>
2024 Write_Indent_Str_Sloc ("free ");
2025 Sprint_Node (Expression (Node));
2027 if Present (Storage_Pool (Node)) then
2028 Write_Str_With_Col_Check ("[storage_pool = ");
2029 Sprint_Node (Storage_Pool (Node));
2030 Write_Char (']');
2031 end if;
2033 if Present (Procedure_To_Call (Node)) then
2034 Write_Str_With_Col_Check ("[procedure_to_call = ");
2035 Sprint_Node (Procedure_To_Call (Node));
2036 Write_Char (']');
2037 end if;
2039 Write_Char (';');
2041 when N_Freeze_Entity =>
2042 if Dump_Original_Only then
2043 null;
2045 -- A freeze node is output if it has some effect (i.e. non-empty
2046 -- actions, or freeze node for an itype, which causes elaboration
2047 -- of the itype), and is also always output if Dump_Freeze_Null
2048 -- is set True.
2050 elsif Present (Actions (Node))
2051 or else Is_Itype (Entity (Node))
2052 or else Dump_Freeze_Null
2053 then
2054 Write_Indent;
2055 Write_Rewrite_Str ("<<<");
2056 Write_Str_With_Col_Check_Sloc ("freeze ");
2057 Write_Id (Entity (Node));
2058 Write_Str (" [");
2060 if No (Actions (Node)) then
2061 Write_Char (']');
2063 else
2064 -- Output freeze actions. We increment Freeze_Indent during
2065 -- this output to avoid generating extra blank lines before
2066 -- any procedures included in the freeze actions.
2068 Freeze_Indent := Freeze_Indent + 1;
2069 Sprint_Indented_List (Actions (Node));
2070 Freeze_Indent := Freeze_Indent - 1;
2071 Write_Indent_Str ("]");
2072 end if;
2074 Write_Rewrite_Str (">>>");
2075 end if;
2077 when N_Freeze_Generic_Entity =>
2078 if Dump_Original_Only then
2079 null;
2081 else
2082 Write_Indent;
2083 Write_Str_With_Col_Check_Sloc ("freeze_generic ");
2084 Write_Id (Entity (Node));
2085 end if;
2087 when N_Full_Type_Declaration =>
2088 Write_Indent_Str_Sloc ("type ");
2089 Sprint_Node (Defining_Identifier (Node));
2090 Write_Discr_Specs (Node);
2091 Write_Str_With_Col_Check (" is ");
2092 Sprint_Node (Type_Definition (Node));
2093 Write_Char (';');
2095 when N_Function_Call =>
2096 Set_Debug_Sloc;
2097 Write_Subprogram_Name (Name (Node));
2098 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
2100 when N_Function_Instantiation =>
2101 Write_Indent_Str_Sloc ("function ");
2102 Sprint_Node (Defining_Unit_Name (Node));
2103 Write_Str_With_Col_Check (" is new ");
2104 Sprint_Node (Name (Node));
2105 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
2106 Write_Char (';');
2108 when N_Function_Specification =>
2109 Write_Str_With_Col_Check_Sloc ("function ");
2110 Sprint_Node (Defining_Unit_Name (Node));
2111 Write_Param_Specs (Node);
2112 Write_Str_With_Col_Check (" return ");
2114 -- Ada 2005 (AI-231)
2116 if Nkind (Result_Definition (Node)) /= N_Access_Definition
2117 and then Null_Exclusion_Present (Node)
2118 then
2119 Write_Str (" not null ");
2120 end if;
2122 Sprint_Node (Result_Definition (Node));
2124 when N_Generic_Association =>
2125 Set_Debug_Sloc;
2127 if Present (Selector_Name (Node)) then
2128 Sprint_Node (Selector_Name (Node));
2129 Write_Str (" => ");
2130 end if;
2132 Sprint_Node (Explicit_Generic_Actual_Parameter (Node));
2134 when N_Generic_Function_Renaming_Declaration =>
2135 Write_Indent_Str_Sloc ("generic function ");
2136 Sprint_Node (Defining_Unit_Name (Node));
2137 Write_Str_With_Col_Check (" renames ");
2138 Sprint_Node (Name (Node));
2139 Write_Char (';');
2141 when N_Generic_Declaration =>
2142 Extra_Blank_Line;
2143 Write_Indent_Str_Sloc ("generic ");
2144 Sprint_Indented_List (Generic_Formal_Declarations (Node));
2145 Write_Indent;
2146 Sprint_Node (Specification (Node));
2147 Write_Char (';');
2149 when N_Generic_Package_Renaming_Declaration =>
2150 Write_Indent_Str_Sloc ("generic package ");
2151 Sprint_Node (Defining_Unit_Name (Node));
2152 Write_Str_With_Col_Check (" renames ");
2153 Sprint_Node (Name (Node));
2154 Write_Char (';');
2156 when N_Generic_Procedure_Renaming_Declaration =>
2157 Write_Indent_Str_Sloc ("generic procedure ");
2158 Sprint_Node (Defining_Unit_Name (Node));
2159 Write_Str_With_Col_Check (" renames ");
2160 Sprint_Node (Name (Node));
2161 Write_Char (';');
2163 when N_Goto_Statement =>
2164 Write_Indent_Str_Sloc ("goto ");
2165 Sprint_Node (Name (Node));
2166 Write_Char (';');
2168 if Nkind (Next (Node)) = N_Label then
2169 Write_Indent;
2170 end if;
2172 when N_Goto_When_Statement =>
2173 Write_Indent_Str_Sloc ("goto ");
2174 Sprint_Node (Name (Node));
2175 Write_Str (" when ");
2176 Sprint_Node (Condition (Node));
2177 Write_Char (';');
2179 when N_Handled_Sequence_Of_Statements =>
2180 Set_Debug_Sloc;
2181 Sprint_Indented_List (Statements (Node));
2183 if Present (Exception_Handlers (Node)) then
2184 Write_Indent_Str ("exception");
2185 Indent_Begin;
2186 Sprint_Node_List (Exception_Handlers (Node));
2187 Indent_End;
2188 end if;
2190 Sprint_At_End_Proc (Node);
2192 when N_Identifier =>
2193 Set_Debug_Sloc;
2194 Write_Id (Node);
2196 when N_If_Expression =>
2197 declare
2198 Has_Parens : constant Boolean := Paren_Count (Node) > 0;
2199 Condition : constant Node_Id := First (Expressions (Node));
2200 Then_Expr : constant Node_Id := Next (Condition);
2202 begin
2203 -- The syntax for if_expression does not include parentheses,
2204 -- but sometimes parentheses are required, so unconditionally
2205 -- generate them here unless already present.
2207 if not Has_Parens then
2208 Write_Char ('(');
2209 end if;
2211 Write_Str_With_Col_Check_Sloc ("if ");
2212 Sprint_Node (Condition);
2213 Write_Str_With_Col_Check (" then ");
2215 -- Defense against junk here
2217 if Present (Then_Expr) then
2218 Sprint_Node (Then_Expr);
2220 if Present (Next (Then_Expr)) then
2221 Write_Str_With_Col_Check (" else ");
2222 Sprint_Node (Next (Then_Expr));
2223 end if;
2224 end if;
2226 if not Has_Parens then
2227 Write_Char (')');
2228 end if;
2229 end;
2231 when N_If_Statement =>
2232 Write_Indent_Str_Sloc ("if ");
2233 Sprint_Node (Condition (Node));
2234 Write_Str_With_Col_Check (" then");
2235 Sprint_Indented_List (Then_Statements (Node));
2236 Sprint_Opt_Node_List (Elsif_Parts (Node));
2238 if Present (Else_Statements (Node)) then
2239 Write_Indent_Str ("else");
2240 Sprint_Indented_List (Else_Statements (Node));
2241 end if;
2243 Write_Indent_Str ("end if;");
2245 when N_Implicit_Label_Declaration =>
2246 if not Dump_Original_Only then
2247 Write_Indent;
2248 Write_Rewrite_Str ("<<<");
2249 Set_Debug_Sloc;
2250 Write_Id (Defining_Identifier (Node));
2251 Write_Str (" : ");
2252 Write_Str_With_Col_Check ("label");
2253 Write_Rewrite_Str (">>>");
2254 end if;
2256 when N_In =>
2257 Sprint_Left_Opnd (Node);
2258 Write_Str_Sloc (" in ");
2260 if Present (Right_Opnd (Node)) then
2261 Sprint_Right_Opnd (Node);
2262 else
2263 Sprint_Bar_List (Alternatives (Node));
2264 end if;
2266 when N_Incomplete_Type_Declaration =>
2267 Write_Indent_Str_Sloc ("type ");
2268 Write_Id (Defining_Identifier (Node));
2270 if Present (Discriminant_Specifications (Node)) then
2271 Write_Discr_Specs (Node);
2272 elsif Unknown_Discriminants_Present (Node) then
2273 Write_Str_With_Col_Check ("(<>)");
2274 end if;
2276 Write_Char (';');
2278 when N_Index_Or_Discriminant_Constraint =>
2279 Set_Debug_Sloc;
2280 Sprint_Paren_Comma_List (Constraints (Node));
2282 when N_Indexed_Component =>
2283 Sprint_Node_Sloc (Prefix (Node));
2284 Sprint_Opt_Paren_Comma_List (Expressions (Node));
2286 when N_Integer_Literal =>
2287 if Print_In_Hex (Node) then
2288 Write_Uint_With_Col_Check_Sloc (Intval (Node), Hex);
2289 else
2290 Write_Uint_With_Col_Check_Sloc (Intval (Node), Auto);
2291 end if;
2293 when N_Iteration_Scheme =>
2294 if Present (Condition (Node)) then
2295 Write_Str_With_Col_Check_Sloc ("while ");
2296 Sprint_Node (Condition (Node));
2297 else
2298 Write_Str_With_Col_Check_Sloc ("for ");
2300 if Present (Iterator_Specification (Node)) then
2301 Sprint_Node (Iterator_Specification (Node));
2302 else
2303 Sprint_Node (Loop_Parameter_Specification (Node));
2304 end if;
2305 end if;
2307 Write_Char (' ');
2309 when N_Iterator_Specification =>
2310 Set_Debug_Sloc;
2311 Write_Id (Defining_Identifier (Node));
2313 if Present (Subtype_Indication (Node)) then
2314 Write_Str_With_Col_Check (" : ");
2315 Sprint_Node (Subtype_Indication (Node));
2316 end if;
2318 if Of_Present (Node) then
2319 Write_Str_With_Col_Check (" of ");
2320 else
2321 Write_Str_With_Col_Check (" in ");
2322 end if;
2324 if Reverse_Present (Node) then
2325 Write_Str_With_Col_Check ("reverse ");
2326 end if;
2328 Sprint_Node (Name (Node));
2330 if Present (Iterator_Filter (Node)) then
2331 Write_Str (" when ");
2332 Sprint_Node (Iterator_Filter (Node));
2333 end if;
2335 when N_Itype_Reference =>
2336 Write_Indent_Str_Sloc ("reference ");
2337 Write_Id (Itype (Node));
2339 when N_Label =>
2340 Write_Indent_Str_Sloc ("<<");
2341 Write_Id (Identifier (Node));
2342 Write_Str (">>");
2344 when N_Loop_Parameter_Specification =>
2345 Set_Debug_Sloc;
2346 Write_Id (Defining_Identifier (Node));
2347 Write_Str_With_Col_Check (" in ");
2349 if Reverse_Present (Node) then
2350 Write_Str_With_Col_Check ("reverse ");
2351 end if;
2353 Sprint_Node (Discrete_Subtype_Definition (Node));
2355 when N_Loop_Statement =>
2356 Write_Indent;
2358 if Present (Identifier (Node))
2359 and then (not Has_Created_Identifier (Node)
2360 or else not Dump_Original_Only)
2361 then
2362 Write_Rewrite_Str ("<<<");
2363 Write_Id (Identifier (Node));
2364 Write_Str (" : ");
2365 Write_Rewrite_Str (">>>");
2366 Sprint_Node (Iteration_Scheme (Node));
2367 Write_Str_With_Col_Check_Sloc ("loop");
2368 Sprint_Indented_List (Statements (Node));
2369 Write_Indent_Str ("end loop ");
2370 Write_Rewrite_Str ("<<<");
2371 Write_Id (Identifier (Node));
2372 Write_Rewrite_Str (">>>");
2373 Write_Char (';');
2375 else
2376 Sprint_Node (Iteration_Scheme (Node));
2377 Write_Str_With_Col_Check_Sloc ("loop");
2378 Sprint_Indented_List (Statements (Node));
2379 Write_Indent_Str ("end loop;");
2380 end if;
2382 when N_Mod_Clause =>
2383 Sprint_Node_List (Pragmas_Before (Node));
2384 Write_Str_With_Col_Check_Sloc ("at mod ");
2385 Sprint_Node (Expression (Node));
2387 when N_Modular_Type_Definition =>
2388 Write_Str_With_Col_Check_Sloc ("mod ");
2389 Sprint_Node (Expression (Node));
2391 when N_Not_In =>
2392 Sprint_Left_Opnd (Node);
2393 Write_Str_Sloc (" not in ");
2395 if Present (Right_Opnd (Node)) then
2396 Sprint_Right_Opnd (Node);
2397 else
2398 Sprint_Bar_List (Alternatives (Node));
2399 end if;
2401 when N_Null =>
2402 Write_Str_With_Col_Check_Sloc ("null");
2404 when N_Null_Statement =>
2405 if Comes_From_Source (Node)
2406 or else Dump_Freeze_Null
2407 or else not Is_List_Member (Node)
2408 or else (No (Prev (Node)) and then No (Next (Node)))
2409 then
2410 Write_Indent_Str_Sloc ("null;");
2411 end if;
2413 when N_Number_Declaration =>
2414 Set_Debug_Sloc;
2416 if Write_Indent_Identifiers (Node) then
2417 Write_Str_With_Col_Check (" : constant ");
2418 Write_Str (" := ");
2419 Sprint_Node (Expression (Node));
2420 Write_Char (';');
2421 end if;
2423 when N_Object_Declaration =>
2424 Set_Debug_Sloc;
2426 if Write_Indent_Identifiers (Node) then
2427 declare
2428 Def_Id : constant Entity_Id := Defining_Identifier (Node);
2430 begin
2431 Write_Str_With_Col_Check (" : ");
2433 if Is_Statically_Allocated (Def_Id) then
2434 Write_Str_With_Col_Check ("static ");
2435 end if;
2437 if Aliased_Present (Node) then
2438 Write_Str_With_Col_Check ("aliased ");
2439 end if;
2441 if Constant_Present (Node) then
2442 Write_Str_With_Col_Check ("constant ");
2443 end if;
2445 -- Ada 2005 (AI-231)
2447 if Null_Exclusion_Present (Node) then
2448 Write_Str_With_Col_Check ("not null ");
2449 end if;
2451 -- Print type. We used to print the Object_Definition from
2452 -- the node, but it is much more useful to print the Etype
2453 -- of the defining identifier for the case where the nominal
2454 -- type is an unconstrained array type. For example, this
2455 -- will be a clear reference to the Itype with the bounds
2456 -- in the case of a type like String. The object after
2457 -- all is constrained, even if its nominal subtype is
2458 -- unconstrained.
2460 declare
2461 Odef : constant Node_Id := Object_Definition (Node);
2463 begin
2464 if Nkind (Odef) = N_Identifier
2465 and then Present (Etype (Odef))
2466 and then Is_Array_Type (Etype (Odef))
2467 and then not Is_Constrained (Etype (Odef))
2468 and then Present (Etype (Def_Id))
2469 then
2470 Sprint_Node (Etype (Def_Id));
2472 -- In other cases, the nominal type is fine to print
2474 else
2475 Sprint_Node (Odef);
2476 end if;
2477 end;
2479 if Present (Expression (Node))
2480 and then Expression (Node) /= Error
2481 and then not No_Initialization (Node)
2482 then
2483 Write_Str (" := ");
2484 Sprint_Node (Expression (Node));
2485 end if;
2487 Write_Char (';');
2489 -- Handle implicit importation and implicit exportation of
2490 -- object declarations:
2491 -- $pragma import (Convention_Id, Def_Id, "...");
2492 -- $pragma export (Convention_Id, Def_Id, "...");
2494 if Is_Internal (Def_Id)
2495 and then Present (Interface_Name (Def_Id))
2496 then
2497 Write_Indent_Str_Sloc ("$pragma ");
2499 if Is_Imported (Def_Id) then
2500 Write_Str ("import (");
2502 else pragma Assert (Is_Exported (Def_Id));
2503 Write_Str ("export (");
2504 end if;
2506 declare
2507 Prefix : constant String := "Convention_";
2508 S : constant String := Convention (Def_Id)'Img;
2510 begin
2511 Name_Len := S'Last - Prefix'Last;
2512 Name_Buffer (1 .. Name_Len) :=
2513 S (Prefix'Last + 1 .. S'Last);
2514 Set_Casing (All_Lower_Case);
2515 Write_Str (Name_Buffer (1 .. Name_Len));
2516 end;
2518 Write_Str (", ");
2519 Write_Id (Def_Id);
2520 Write_Str (", ");
2521 Write_String_Table_Entry
2522 (Strval (Interface_Name (Def_Id)));
2523 Write_Str (");");
2524 end if;
2525 end;
2526 end if;
2528 when N_Object_Renaming_Declaration =>
2529 Write_Indent;
2530 Set_Debug_Sloc;
2531 Sprint_Node (Defining_Identifier (Node));
2533 -- Ada 2005 (AI-230): Access renamings
2535 if Present (Access_Definition (Node)) then
2536 Write_Str (" : ");
2537 Sprint_Node (Access_Definition (Node));
2539 elsif Present (Subtype_Mark (Node)) then
2540 Write_Str (" : ");
2542 -- Ada 2005 (AI-423): Object renaming with a null exclusion
2544 if Null_Exclusion_Present (Node) then
2545 Write_Str ("not null ");
2546 end if;
2548 Sprint_Node (Subtype_Mark (Node));
2550 -- AI12-0275: Object_Renaming_Declaration without explicit subtype
2552 elsif Ada_Version >= Ada_2022 then
2553 null;
2555 else
2556 Write_Str (" : ??? ");
2557 end if;
2559 Write_Str_With_Col_Check (" renames ");
2560 Sprint_Node (Name (Node));
2561 Write_Char (';');
2563 when N_Op_Abs =>
2564 Write_Operator (Node, "abs ");
2565 Sprint_Right_Opnd (Node);
2567 when N_Op_Add =>
2568 Sprint_Left_Opnd (Node);
2569 Write_Operator (Node, " + ");
2570 Sprint_Right_Opnd (Node);
2572 when N_Op_And =>
2573 Sprint_Left_Opnd (Node);
2574 Write_Operator (Node, " and ");
2575 Sprint_Right_Opnd (Node);
2577 when N_Op_Concat =>
2578 Sprint_Left_Opnd (Node);
2579 Write_Operator (Node, " & ");
2580 Sprint_Right_Opnd (Node);
2582 when N_Op_Divide =>
2583 Sprint_Left_Opnd (Node);
2584 Write_Char (' ');
2585 if Rounded_Result (Node) then
2586 Write_Char ('@');
2587 end if;
2588 Write_Operator (Node, "/ ");
2589 Sprint_Right_Opnd (Node);
2591 when N_Op_Eq =>
2592 Sprint_Left_Opnd (Node);
2593 Write_Operator (Node, " = ");
2594 Sprint_Right_Opnd (Node);
2596 when N_Op_Expon =>
2597 Sprint_Left_Opnd (Node);
2598 Write_Operator (Node, " ** ");
2599 Sprint_Right_Opnd (Node);
2601 when N_Op_Ge =>
2602 Sprint_Left_Opnd (Node);
2603 Write_Operator (Node, " >= ");
2604 Sprint_Right_Opnd (Node);
2606 when N_Op_Gt =>
2607 Sprint_Left_Opnd (Node);
2608 Write_Operator (Node, " > ");
2609 Sprint_Right_Opnd (Node);
2611 when N_Op_Le =>
2612 Sprint_Left_Opnd (Node);
2613 Write_Operator (Node, " <= ");
2614 Sprint_Right_Opnd (Node);
2616 when N_Op_Lt =>
2617 Sprint_Left_Opnd (Node);
2618 Write_Operator (Node, " < ");
2619 Sprint_Right_Opnd (Node);
2621 when N_Op_Minus =>
2622 Write_Operator (Node, "-");
2623 Sprint_Right_Opnd (Node);
2625 when N_Op_Mod =>
2626 Sprint_Left_Opnd (Node);
2627 Write_Operator (Node, " mod ");
2628 Sprint_Right_Opnd (Node);
2630 when N_Op_Multiply =>
2631 Sprint_Left_Opnd (Node);
2632 Write_Char (' ');
2633 if Rounded_Result (Node) then
2634 Write_Char ('@');
2635 end if;
2636 Write_Operator (Node, "* ");
2637 Sprint_Right_Opnd (Node);
2639 when N_Op_Ne =>
2640 Sprint_Left_Opnd (Node);
2641 Write_Operator (Node, " /= ");
2642 Sprint_Right_Opnd (Node);
2644 when N_Op_Not =>
2645 Write_Operator (Node, "not ");
2646 Sprint_Right_Opnd (Node);
2648 when N_Op_Or =>
2649 Sprint_Left_Opnd (Node);
2650 Write_Operator (Node, " or ");
2651 Sprint_Right_Opnd (Node);
2653 when N_Op_Plus =>
2654 Write_Operator (Node, "+");
2655 Sprint_Right_Opnd (Node);
2657 when N_Op_Rem =>
2658 Sprint_Left_Opnd (Node);
2659 Write_Operator (Node, " rem ");
2660 Sprint_Right_Opnd (Node);
2662 when N_Op_Shift =>
2663 Set_Debug_Sloc;
2664 Write_Id (Node);
2665 Write_Char ('!');
2666 Write_Str_With_Col_Check ("(");
2667 Sprint_Node (Left_Opnd (Node));
2668 Write_Str (", ");
2669 Sprint_Node (Right_Opnd (Node));
2670 Write_Char (')');
2672 when N_Op_Subtract =>
2673 Sprint_Left_Opnd (Node);
2674 Write_Operator (Node, " - ");
2675 Sprint_Right_Opnd (Node);
2677 when N_Op_Xor =>
2678 Sprint_Left_Opnd (Node);
2679 Write_Operator (Node, " xor ");
2680 Sprint_Right_Opnd (Node);
2682 when N_Operator_Symbol =>
2683 Write_Name_With_Col_Check_Sloc (Chars (Node));
2685 when N_Ordinary_Fixed_Point_Definition =>
2686 Write_Str_With_Col_Check_Sloc ("delta ");
2687 Sprint_Node (Delta_Expression (Node));
2688 Sprint_Opt_Node (Real_Range_Specification (Node));
2690 when N_Or_Else =>
2691 Sprint_Left_Opnd (Node);
2692 Write_Str_Sloc (" or else ");
2693 Sprint_Right_Opnd (Node);
2695 when N_Others_Choice =>
2696 if All_Others (Node) then
2697 Write_Str_With_Col_Check ("all ");
2698 end if;
2700 Write_Str_With_Col_Check_Sloc ("others");
2702 when N_Package_Body =>
2703 Extra_Blank_Line;
2704 Write_Indent_Str_Sloc ("package body ");
2705 Sprint_Node (Defining_Unit_Name (Node));
2706 Write_Str (" is");
2707 Sprint_Indented_List (Declarations (Node));
2709 if Present (Handled_Statement_Sequence (Node)) then
2710 Write_Indent_Str ("begin");
2711 Sprint_Node (Handled_Statement_Sequence (Node));
2712 end if;
2714 Write_Indent_Str ("end ");
2715 Sprint_End_Label
2716 (Handled_Statement_Sequence (Node), Defining_Unit_Name (Node));
2717 Write_Char (';');
2718 Sprint_At_End_Proc (Node);
2720 when N_Package_Body_Stub =>
2721 Write_Indent_Str_Sloc ("package body ");
2722 Sprint_Node (Defining_Identifier (Node));
2723 Write_Str_With_Col_Check (" is separate;");
2725 when N_Package_Declaration =>
2726 Extra_Blank_Line;
2727 Write_Indent;
2728 Sprint_Node_Sloc (Specification (Node));
2729 Write_Char (';');
2731 -- If this is an instantiation, get the aspects from the original
2732 -- instantiation node.
2734 if Is_Generic_Instance (Defining_Entity (Node))
2735 and then Has_Aspects
2736 (Package_Instantiation (Defining_Entity (Node)))
2737 then
2738 Sprint_Aspect_Specifications
2739 (Package_Instantiation (Defining_Entity (Node)),
2740 Semicolon => True);
2741 end if;
2743 when N_Package_Instantiation =>
2744 Extra_Blank_Line;
2745 Write_Indent_Str_Sloc ("package ");
2746 Sprint_Node (Defining_Unit_Name (Node));
2747 Write_Str (" is new ");
2748 Sprint_Node (Name (Node));
2749 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
2750 Write_Char (';');
2752 when N_Package_Renaming_Declaration =>
2753 Write_Indent_Str_Sloc ("package ");
2754 Sprint_Node (Defining_Unit_Name (Node));
2755 Write_Str_With_Col_Check (" renames ");
2756 Sprint_Node (Name (Node));
2757 Write_Char (';');
2759 when N_Package_Specification =>
2760 Write_Str_With_Col_Check_Sloc ("package ");
2761 Sprint_Node (Defining_Unit_Name (Node));
2763 if Nkind (Parent (Node)) = N_Generic_Package_Declaration
2764 and then Has_Aspects (Parent (Node))
2765 then
2766 Sprint_Aspect_Specifications
2767 (Parent (Node), Semicolon => False);
2769 -- An instantiation is rewritten as a package declaration, but
2770 -- the aspects belong to the instantiation node.
2772 elsif Nkind (Parent (Node)) = N_Package_Declaration then
2773 declare
2774 Pack : constant Entity_Id := Defining_Entity (Node);
2776 begin
2777 if not Is_Generic_Instance (Pack) then
2778 if Has_Aspects (Parent (Node)) then
2779 Sprint_Aspect_Specifications
2780 (Parent (Node), Semicolon => False);
2781 end if;
2782 end if;
2783 end;
2784 end if;
2786 Write_Str (" is");
2787 Sprint_Indented_List (Visible_Declarations (Node));
2789 if Present (Private_Declarations (Node)) then
2790 Write_Indent_Str ("private");
2791 Sprint_Indented_List (Private_Declarations (Node));
2792 end if;
2794 Write_Indent_Str ("end ");
2795 Sprint_Node (Defining_Unit_Name (Node));
2797 when N_Parameter_Association =>
2798 Sprint_Node_Sloc (Selector_Name (Node));
2799 Write_Str (" => ");
2800 Sprint_Node (Explicit_Actual_Parameter (Node));
2802 when N_Parameter_Specification =>
2803 Set_Debug_Sloc;
2805 if Write_Identifiers (Node) then
2806 Write_Str (" : ");
2808 if In_Present (Node) then
2809 Write_Str_With_Col_Check ("in ");
2810 end if;
2812 if Out_Present (Node) then
2813 Write_Str_With_Col_Check ("out ");
2814 end if;
2816 -- Ada 2005 (AI-231): Parameter specification may carry null
2817 -- exclusion. Do not print it now if this is an access formal,
2818 -- it is emitted when the access definition is displayed.
2820 if Null_Exclusion_Present (Node)
2821 and then Nkind (Parameter_Type (Node)) /= N_Access_Definition
2822 then
2823 Write_Str ("not null ");
2824 end if;
2826 if Aliased_Present (Node) then
2827 Write_Str ("aliased ");
2828 end if;
2830 Sprint_Node (Parameter_Type (Node));
2832 if Present (Expression (Node)) then
2833 Write_Str (" := ");
2834 Sprint_Node (Expression (Node));
2835 end if;
2836 else
2837 Write_Str (", ");
2838 end if;
2840 when N_Pop_Constraint_Error_Label =>
2841 Write_Indent_Str ("%pop_constraint_error_label");
2843 when N_Pop_Program_Error_Label =>
2844 Write_Indent_Str ("%pop_program_error_label");
2846 when N_Pop_Storage_Error_Label =>
2847 Write_Indent_Str ("%pop_storage_error_label");
2849 when N_Private_Extension_Declaration =>
2850 Write_Indent_Str_Sloc ("type ");
2851 Write_Id (Defining_Identifier (Node));
2853 if Present (Discriminant_Specifications (Node)) then
2854 Write_Discr_Specs (Node);
2855 elsif Unknown_Discriminants_Present (Node) then
2856 Write_Str_With_Col_Check ("(<>)");
2857 end if;
2859 Write_Str_With_Col_Check (" is new ");
2860 Sprint_Node (Subtype_Indication (Node));
2862 if Present (Interface_List (Node)) then
2863 Write_Str_With_Col_Check (" and ");
2864 Sprint_And_List (Interface_List (Node));
2865 end if;
2867 Write_Str_With_Col_Check (" with private;");
2869 when N_Private_Type_Declaration =>
2870 Write_Indent_Str_Sloc ("type ");
2871 Write_Id (Defining_Identifier (Node));
2873 if Present (Discriminant_Specifications (Node)) then
2874 Write_Discr_Specs (Node);
2875 elsif Unknown_Discriminants_Present (Node) then
2876 Write_Str_With_Col_Check ("(<>)");
2877 end if;
2879 Write_Str (" is ");
2881 if Tagged_Present (Node) then
2882 Write_Str_With_Col_Check ("tagged ");
2883 end if;
2885 if Limited_Present (Node) then
2886 Write_Str_With_Col_Check ("limited ");
2887 end if;
2889 Write_Str_With_Col_Check ("private;");
2891 when N_Push_Constraint_Error_Label =>
2892 Write_Indent_Str ("%push_constraint_error_label (");
2894 if Present (Exception_Label (Node)) then
2895 Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2896 end if;
2898 Write_Str (")");
2900 when N_Push_Program_Error_Label =>
2901 Write_Indent_Str ("%push_program_error_label (");
2903 if Present (Exception_Label (Node)) then
2904 Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2905 end if;
2907 Write_Str (")");
2909 when N_Push_Storage_Error_Label =>
2910 Write_Indent_Str ("%push_storage_error_label (");
2912 if Present (Exception_Label (Node)) then
2913 Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2914 end if;
2916 Write_Str (")");
2918 when N_Pragma =>
2919 Write_Indent_Str_Sloc ("pragma ");
2920 Write_Name_With_Col_Check (Pragma_Name_Unmapped (Node));
2922 if Present (Pragma_Argument_Associations (Node)) then
2923 Sprint_Opt_Paren_Comma_List
2924 (Pragma_Argument_Associations (Node));
2925 end if;
2927 Write_Char (';');
2929 when N_Pragma_Argument_Association =>
2930 Set_Debug_Sloc;
2932 if Chars (Node) /= No_Name then
2933 Write_Name_With_Col_Check (Chars (Node));
2934 Write_Str (" => ");
2935 end if;
2937 Sprint_Node (Expression (Node));
2939 when N_Procedure_Call_Statement =>
2940 Write_Indent;
2941 Set_Debug_Sloc;
2942 Write_Subprogram_Name (Name (Node));
2943 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
2944 Write_Char (';');
2946 when N_Procedure_Instantiation =>
2947 Write_Indent_Str_Sloc ("procedure ");
2948 Sprint_Node (Defining_Unit_Name (Node));
2949 Write_Str_With_Col_Check (" is new ");
2950 Sprint_Node (Name (Node));
2951 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
2952 Write_Char (';');
2954 when N_Procedure_Specification =>
2955 Write_Str_With_Col_Check_Sloc ("procedure ");
2956 Sprint_Node (Defining_Unit_Name (Node));
2957 Write_Param_Specs (Node);
2959 when N_Protected_Body =>
2960 Write_Indent_Str_Sloc ("protected body ");
2961 Write_Id (Defining_Identifier (Node));
2962 Write_Str (" is");
2963 Sprint_Indented_List (Declarations (Node));
2964 Write_Indent_Str ("end ");
2965 Write_Id (Defining_Identifier (Node));
2966 Write_Char (';');
2968 when N_Protected_Body_Stub =>
2969 Write_Indent_Str_Sloc ("protected body ");
2970 Write_Id (Defining_Identifier (Node));
2971 Write_Str_With_Col_Check (" is separate;");
2973 when N_Protected_Definition =>
2974 Set_Debug_Sloc;
2975 Sprint_Indented_List (Visible_Declarations (Node));
2977 if Present (Private_Declarations (Node)) then
2978 Write_Indent_Str ("private");
2979 Sprint_Indented_List (Private_Declarations (Node));
2980 end if;
2982 Write_Indent_Str ("end ");
2984 when N_Protected_Type_Declaration =>
2985 Write_Indent_Str_Sloc ("protected type ");
2986 Sprint_Node (Defining_Identifier (Node));
2987 Write_Discr_Specs (Node);
2989 if Present (Interface_List (Node)) then
2990 Write_Str (" is new ");
2991 Sprint_And_List (Interface_List (Node));
2992 Write_Str (" with ");
2993 else
2994 Write_Str (" is");
2995 end if;
2997 Sprint_Node (Protected_Definition (Node));
2998 Write_Id (Defining_Identifier (Node));
2999 Write_Char (';');
3001 when N_Qualified_Expression =>
3002 Sprint_Node (Subtype_Mark (Node));
3003 Write_Char_Sloc (''');
3005 -- Print expression, make sure we have at least one level of
3006 -- parentheses around the expression. For cases of qualified
3007 -- expressions in the source, this is always the case, but
3008 -- for generated qualifications, there may be no explicit
3009 -- parentheses present.
3011 if Paren_Count (Expression (Node)) /= 0 then
3012 Sprint_Node (Expression (Node));
3014 else
3015 Write_Char ('(');
3016 Sprint_Node (Expression (Node));
3018 -- Odd case, for the qualified expressions used in machine
3019 -- code the argument may be a procedure call, resulting in
3020 -- a junk semicolon before the right parent, get rid of it.
3022 Write_Erase_Char (';');
3024 -- Now we can add the terminating right paren
3026 Write_Char (')');
3027 end if;
3029 when N_Quantified_Expression =>
3030 Write_Str (" for");
3032 if All_Present (Node) then
3033 Write_Str (" all ");
3034 else
3035 Write_Str (" some ");
3036 end if;
3038 if Present (Iterator_Specification (Node)) then
3039 Sprint_Node (Iterator_Specification (Node));
3040 else
3041 Sprint_Node (Loop_Parameter_Specification (Node));
3042 end if;
3044 Write_Str (" => ");
3045 Sprint_Node (Condition (Node));
3047 when N_Raise_Expression =>
3048 declare
3049 Has_Parens : constant Boolean := Paren_Count (Node) > 0;
3051 begin
3052 -- The syntax for raise_expression does not include parentheses
3053 -- but sometimes parentheses are required, so unconditionally
3054 -- generate them here unless already present.
3056 if not Has_Parens then
3057 Write_Char ('(');
3058 end if;
3060 Write_Str_With_Col_Check_Sloc ("raise ");
3061 Sprint_Node (Name (Node));
3063 if Present (Expression (Node)) then
3064 Write_Str_With_Col_Check (" with ");
3065 Sprint_Node (Expression (Node));
3066 end if;
3068 if not Has_Parens then
3069 Write_Char (')');
3070 end if;
3071 end;
3073 when N_Raise_Constraint_Error =>
3075 -- This node can be used either as a subexpression or as a
3076 -- statement form. The following test is a reasonably reliable
3077 -- way to distinguish the two cases.
3079 if Is_List_Member (Node)
3080 and then Nkind (Parent (Node)) not in N_Subexpr
3081 then
3082 Write_Indent;
3083 end if;
3085 Write_Str_With_Col_Check_Sloc ("[constraint_error");
3086 Write_Condition_And_Reason (Node);
3088 when N_Raise_Program_Error =>
3090 -- This node can be used either as a subexpression or as a
3091 -- statement form. The following test is a reasonably reliable
3092 -- way to distinguish the two cases.
3094 if Is_List_Member (Node)
3095 and then Nkind (Parent (Node)) not in N_Subexpr
3096 then
3097 Write_Indent;
3098 end if;
3100 Write_Str_With_Col_Check_Sloc ("[program_error");
3101 Write_Condition_And_Reason (Node);
3103 when N_Raise_Storage_Error =>
3105 -- This node can be used either as a subexpression or as a
3106 -- statement form. The following test is a reasonably reliable
3107 -- way to distinguish the two cases.
3109 if Is_List_Member (Node)
3110 and then Nkind (Parent (Node)) not in N_Subexpr
3111 then
3112 Write_Indent;
3113 end if;
3115 Write_Str_With_Col_Check_Sloc ("[storage_error");
3116 Write_Condition_And_Reason (Node);
3118 when N_Raise_Statement =>
3119 Write_Indent_Str_Sloc ("raise ");
3120 Sprint_Node (Name (Node));
3122 if Present (Expression (Node)) then
3123 Write_Str_With_Col_Check_Sloc (" with ");
3124 Sprint_Node (Expression (Node));
3125 end if;
3127 Write_Char (';');
3129 when N_Raise_When_Statement =>
3130 Write_Indent_Str_Sloc ("raise ");
3131 Sprint_Node (Name (Node));
3132 Write_Str (" when ");
3133 Sprint_Node (Condition (Node));
3135 if Present (Expression (Node)) then
3136 Write_Str_With_Col_Check_Sloc (" with ");
3137 Sprint_Node (Expression (Node));
3138 end if;
3140 Write_Char (';');
3142 when N_Range =>
3143 Sprint_Node (Low_Bound (Node));
3144 Write_Str_Sloc (" .. ");
3145 if Present (Etype (Node))
3146 and then Is_Fixed_Lower_Bound_Index_Subtype (Etype (Node))
3147 then
3148 Write_Str ("<>");
3149 else
3150 Sprint_Node (High_Bound (Node));
3151 end if;
3152 Update_Itype (Node);
3154 when N_Range_Constraint =>
3155 Write_Str_With_Col_Check_Sloc ("range ");
3156 Sprint_Node (Range_Expression (Node));
3158 when N_Real_Literal =>
3159 Write_Ureal_With_Col_Check_Sloc (Realval (Node));
3161 when N_Real_Range_Specification
3162 | N_Signed_Integer_Type_Definition
3164 Write_Str_With_Col_Check_Sloc ("range ");
3165 Sprint_Node (Low_Bound (Node));
3166 Write_Str (" .. ");
3167 Sprint_Node (High_Bound (Node));
3169 when N_Record_Definition =>
3170 if Abstract_Present (Node) then
3171 Write_Str_With_Col_Check ("abstract ");
3172 end if;
3174 if Tagged_Present (Node) then
3175 Write_Str_With_Col_Check ("tagged ");
3176 end if;
3178 if Limited_Present (Node) then
3179 Write_Str_With_Col_Check ("limited ");
3180 end if;
3182 if Null_Present (Node) then
3183 Write_Str_With_Col_Check_Sloc ("null record");
3185 else
3186 Write_Str_With_Col_Check_Sloc ("record");
3187 Sprint_Node (Component_List (Node));
3188 Write_Indent_Str ("end record");
3189 end if;
3191 when N_Record_Representation_Clause =>
3192 Write_Indent_Str_Sloc ("for ");
3193 Sprint_Node (Identifier (Node));
3194 Write_Str_With_Col_Check (" use record ");
3196 if Present (Mod_Clause (Node)) then
3197 Sprint_Node (Mod_Clause (Node));
3198 end if;
3200 Sprint_Indented_List (Component_Clauses (Node));
3201 Write_Indent_Str ("end record;");
3203 when N_Reference =>
3204 Sprint_Node (Prefix (Node));
3205 Write_Str_With_Col_Check_Sloc ("'reference");
3207 when N_Requeue_Statement =>
3208 Write_Indent_Str_Sloc ("requeue ");
3209 Sprint_Node (Name (Node));
3211 if Abort_Present (Node) then
3212 Write_Str_With_Col_Check (" with abort");
3213 end if;
3215 Write_Char (';');
3217 when N_Return_When_Statement =>
3218 Write_Indent_Str_Sloc ("return ");
3219 Sprint_Node (Expression (Node));
3220 Write_Str (" when ");
3221 Sprint_Node (Condition (Node));
3222 Write_Char (';');
3224 when N_SCIL_Dispatch_Table_Tag_Init =>
3225 Write_Indent_Str ("[N_SCIL_Dispatch_Table_Tag_Init]");
3227 when N_SCIL_Dispatching_Call =>
3228 Write_Indent_Str ("[N_SCIL_Dispatching_Node]");
3230 when N_SCIL_Membership_Test =>
3231 Write_Indent_Str ("[N_SCIL_Membership_Test]");
3233 when N_Simple_Return_Statement =>
3234 if Present (Expression (Node)) then
3235 Write_Indent_Str_Sloc ("return ");
3236 Sprint_Node (Expression (Node));
3237 else
3238 Write_Indent_Str_Sloc ("return");
3239 end if;
3241 if Present (Storage_Pool (Node)) then
3242 Write_Str_With_Col_Check ("[storage_pool = ");
3243 Sprint_Node (Storage_Pool (Node));
3244 Write_Char (']');
3245 end if;
3247 if Present (Procedure_To_Call (Node)) then
3248 Write_Str_With_Col_Check ("[procedure_to_call = ");
3249 Sprint_Node (Procedure_To_Call (Node));
3250 Write_Char (']');
3251 end if;
3253 Write_Char (';');
3255 when N_Selective_Accept =>
3256 Write_Indent_Str_Sloc ("select");
3258 declare
3259 Alt_Node : Node_Id;
3260 begin
3261 Alt_Node := First (Select_Alternatives (Node));
3262 loop
3263 Indent_Begin;
3264 Sprint_Node (Alt_Node);
3265 Indent_End;
3266 Next (Alt_Node);
3267 exit when No (Alt_Node);
3268 Write_Indent_Str ("or");
3269 end loop;
3270 end;
3272 if Present (Else_Statements (Node)) then
3273 Write_Indent_Str ("else");
3274 Sprint_Indented_List (Else_Statements (Node));
3275 end if;
3277 Write_Indent_Str ("end select;");
3279 when N_Single_Protected_Declaration =>
3280 Write_Indent_Str_Sloc ("protected ");
3281 Write_Id (Defining_Identifier (Node));
3282 Write_Str (" is");
3283 Sprint_Node (Protected_Definition (Node));
3284 Write_Id (Defining_Identifier (Node));
3285 Write_Char (';');
3287 when N_Single_Task_Declaration =>
3288 Write_Indent_Str_Sloc ("task ");
3289 Sprint_Node (Defining_Identifier (Node));
3291 if Present (Task_Definition (Node)) then
3292 Write_Str (" is");
3293 Sprint_Node (Task_Definition (Node));
3294 end if;
3296 Write_Char (';');
3298 when N_Selected_Component =>
3299 Sprint_Node (Prefix (Node));
3300 Write_Char_Sloc ('.');
3301 Sprint_Node (Selector_Name (Node));
3303 when N_Slice =>
3304 Set_Debug_Sloc;
3305 Sprint_Node (Prefix (Node));
3306 Write_Str_With_Col_Check (" (");
3307 Sprint_Node (Discrete_Range (Node));
3308 Write_Char (')');
3310 when N_String_Literal =>
3311 if String_Length (Strval (Node)) + Column > Sprint_Line_Limit then
3312 Write_Indent_Str (" ");
3313 end if;
3315 Set_Debug_Sloc;
3316 Write_String_Table_Entry (Strval (Node));
3318 when N_Interpolated_String_Literal =>
3319 Write_Char ('{');
3321 declare
3322 Str_Elem : Node_Id := First (Expressions (Node));
3323 Is_First : Boolean := True;
3325 begin
3326 while Present (Str_Elem) loop
3327 if not Is_First then
3328 Write_Str (" & ");
3329 end if;
3331 if Nkind (Str_Elem) = N_String_Literal then
3332 Sprint_Node (Str_Elem);
3334 else
3335 Write_Char ('"');
3336 Write_Char ('{');
3337 Sprint_Node (Str_Elem);
3338 Write_Char ('}');
3339 Write_Char ('"');
3340 end if;
3342 Is_First := False;
3344 Next (Str_Elem);
3345 end loop;
3346 end;
3348 Write_Char ('}');
3350 when N_Subprogram_Body =>
3352 -- Output extra blank line unless we are in freeze actions
3354 if Freeze_Indent = 0 then
3355 Extra_Blank_Line;
3356 end if;
3358 Write_Indent;
3360 if Present (Corresponding_Spec (Node)) then
3361 Sprint_Node_Sloc (Parent (Corresponding_Spec (Node)));
3362 else
3363 Sprint_Node_Sloc (Specification (Node));
3364 end if;
3366 Write_Str (" is");
3368 Sprint_Indented_List (Declarations (Node));
3369 Write_Indent_Str ("begin");
3370 Sprint_Node (Handled_Statement_Sequence (Node));
3372 Write_Indent_Str ("end ");
3374 Sprint_End_Label
3375 (Handled_Statement_Sequence (Node),
3376 Defining_Unit_Name (Specification (Node)));
3377 Write_Char (';');
3378 Sprint_At_End_Proc (Node);
3380 if Is_List_Member (Node)
3381 and then Present (Next (Node))
3382 and then Nkind (Next (Node)) /= N_Subprogram_Body
3383 then
3384 Write_Indent;
3385 end if;
3387 when N_Subprogram_Body_Stub =>
3388 Write_Indent;
3389 Sprint_Node_Sloc (Specification (Node));
3390 Write_Str_With_Col_Check (" is separate;");
3392 when N_Subprogram_Declaration =>
3393 Write_Indent;
3394 Sprint_Node_Sloc (Specification (Node));
3396 if Nkind (Specification (Node)) = N_Procedure_Specification
3397 and then Null_Present (Specification (Node))
3398 then
3399 Write_Str_With_Col_Check (" is null");
3400 end if;
3402 Write_Char (';');
3404 when N_Subprogram_Renaming_Declaration =>
3405 Write_Indent;
3406 Sprint_Node (Specification (Node));
3407 Write_Str_With_Col_Check_Sloc (" renames ");
3408 Sprint_Node (Name (Node));
3409 Write_Char (';');
3411 when N_Subtype_Declaration =>
3412 Write_Indent_Str_Sloc ("subtype ");
3413 Sprint_Node (Defining_Identifier (Node));
3414 Write_Str (" is ");
3416 -- Ada 2005 (AI-231)
3418 if Null_Exclusion_Present (Node) then
3419 Write_Str ("not null ");
3420 end if;
3422 Sprint_Node (Subtype_Indication (Node));
3423 Write_Char (';');
3425 when N_Subtype_Indication =>
3426 Sprint_Node_Sloc (Subtype_Mark (Node));
3427 Write_Char (' ');
3428 Sprint_Node (Constraint (Node));
3430 when N_Subunit =>
3431 Write_Indent_Str_Sloc ("separate (");
3432 Sprint_Node (Name (Node));
3433 Write_Char (')');
3434 Extra_Blank_Line;
3435 Sprint_Node (Proper_Body (Node));
3437 when N_Target_Name =>
3438 Write_Char ('@');
3440 when N_Task_Body =>
3441 Write_Indent_Str_Sloc ("task body ");
3442 Write_Id (Defining_Identifier (Node));
3443 Write_Str (" is");
3444 Sprint_Indented_List (Declarations (Node));
3445 Write_Indent_Str ("begin");
3446 Sprint_Node (Handled_Statement_Sequence (Node));
3447 Write_Indent_Str ("end ");
3448 Sprint_End_Label
3449 (Handled_Statement_Sequence (Node), Defining_Identifier (Node));
3450 Write_Char (';');
3451 Sprint_At_End_Proc (Node);
3453 when N_Task_Body_Stub =>
3454 Write_Indent_Str_Sloc ("task body ");
3455 Write_Id (Defining_Identifier (Node));
3456 Write_Str_With_Col_Check (" is separate;");
3458 when N_Task_Definition =>
3459 Set_Debug_Sloc;
3460 Sprint_Indented_List (Visible_Declarations (Node));
3462 if Present (Private_Declarations (Node)) then
3463 Write_Indent_Str ("private");
3464 Sprint_Indented_List (Private_Declarations (Node));
3465 end if;
3467 Write_Indent_Str ("end ");
3468 Sprint_End_Label (Node, Defining_Identifier (Parent (Node)));
3470 when N_Task_Type_Declaration =>
3471 Write_Indent_Str_Sloc ("task type ");
3472 Sprint_Node (Defining_Identifier (Node));
3473 Write_Discr_Specs (Node);
3475 if Present (Interface_List (Node)) then
3476 Write_Str (" is new ");
3477 Sprint_And_List (Interface_List (Node));
3478 end if;
3480 if Present (Task_Definition (Node)) then
3481 if No (Interface_List (Node)) then
3482 Write_Str (" is");
3483 else
3484 Write_Str (" with ");
3485 end if;
3487 Sprint_Node (Task_Definition (Node));
3488 end if;
3490 Write_Char (';');
3492 when N_Terminate_Alternative =>
3493 Sprint_Node_List (Pragmas_Before (Node));
3494 Write_Indent;
3496 if Present (Condition (Node)) then
3497 Write_Str_With_Col_Check ("when ");
3498 Sprint_Node (Condition (Node));
3499 Write_Str (" => ");
3500 end if;
3502 Write_Str_With_Col_Check_Sloc ("terminate;");
3503 Sprint_Node_List (Pragmas_After (Node));
3505 when N_Timed_Entry_Call =>
3506 Write_Indent_Str_Sloc ("select");
3507 Indent_Begin;
3508 Sprint_Node (Entry_Call_Alternative (Node));
3509 Indent_End;
3510 Write_Indent_Str ("or");
3511 Indent_Begin;
3512 Sprint_Node (Delay_Alternative (Node));
3513 Indent_End;
3514 Write_Indent_Str ("end select;");
3516 when N_Triggering_Alternative =>
3517 Sprint_Node_List (Pragmas_Before (Node));
3518 Sprint_Node_Sloc (Triggering_Statement (Node));
3519 Sprint_Node_List (Statements (Node));
3521 when N_Type_Conversion =>
3522 Set_Debug_Sloc;
3523 Sprint_Node (Subtype_Mark (Node));
3524 Col_Check (4);
3526 if Conversion_OK (Node) then
3527 Write_Char ('?');
3528 end if;
3530 if Float_Truncate (Node) then
3531 Write_Char ('^');
3532 end if;
3534 if Rounded_Result (Node) then
3535 Write_Char ('@');
3536 end if;
3538 Write_Char ('(');
3539 Sprint_Node (Expression (Node));
3540 Write_Char (')');
3542 when N_Unchecked_Expression =>
3543 Col_Check (10);
3544 Write_Str ("`(");
3545 Sprint_Node_Sloc (Expression (Node));
3546 Write_Char (')');
3548 when N_Unchecked_Type_Conversion =>
3549 Sprint_Node (Subtype_Mark (Node));
3550 Write_Char ('!');
3551 Write_Str_With_Col_Check ("(");
3552 Sprint_Node_Sloc (Expression (Node));
3553 Write_Char (')');
3555 when N_Unconstrained_Array_Definition =>
3556 Write_Str_With_Col_Check_Sloc ("array (");
3558 declare
3559 Node1 : Node_Id;
3560 begin
3561 Node1 := First (Subtype_Marks (Node));
3562 loop
3563 Sprint_Node (Node1);
3564 Write_Str_With_Col_Check (" range <>");
3565 Next (Node1);
3566 exit when Node1 = Empty;
3567 Write_Str (", ");
3568 end loop;
3569 end;
3571 Write_Str (") of ");
3572 Sprint_Node (Component_Definition (Node));
3574 when N_Unused_At_Start | N_Unused_At_End =>
3575 Write_Indent_Str ("***** Error, unused node encountered *****");
3576 Write_Eol;
3578 when N_Use_Package_Clause =>
3579 Write_Indent_Str_Sloc ("use ");
3580 Sprint_Node_Sloc (Name (Node));
3581 Write_Char (';');
3583 when N_Use_Type_Clause =>
3584 Write_Indent_Str_Sloc ("use type ");
3585 Sprint_Node_Sloc (Subtype_Mark (Node));
3586 Write_Char (';');
3588 when N_Validate_Unchecked_Conversion =>
3589 Write_Indent_Str_Sloc ("validate unchecked_conversion (");
3590 Sprint_Node (Source_Type (Node));
3591 Write_Str (", ");
3592 Sprint_Node (Target_Type (Node));
3593 Write_Str (");");
3595 when N_Variable_Reference_Marker =>
3596 null;
3598 -- Enable the following code for debugging purposes only
3600 -- if Is_Read (Node) and then Is_Write (Node) then
3601 -- Write_Indent_Str ("rw#");
3603 -- elsif Is_Read (Node) then
3604 -- Write_Indent_Str ("r#");
3606 -- else
3607 -- pragma Assert (Is_Write (Node));
3608 -- Write_Indent_Str ("w#");
3609 -- end if;
3611 -- Write_Id (Target (Node));
3612 -- Write_Char ('#');
3614 when N_Variant =>
3615 Write_Indent_Str_Sloc ("when ");
3616 Sprint_Bar_List (Discrete_Choices (Node));
3617 Write_Str (" => ");
3618 Sprint_Node (Component_List (Node));
3620 when N_Variant_Part =>
3621 Indent_Begin;
3622 Write_Indent_Str_Sloc ("case ");
3623 Sprint_Node (Name (Node));
3624 Write_Str (" is ");
3625 Sprint_Indented_List (Variants (Node));
3626 Write_Indent_Str ("end case");
3627 Indent_End;
3629 when N_With_Clause =>
3631 -- Special test, if we are dumping the original tree only,
3632 -- then we want to eliminate the bogus with clauses that
3633 -- correspond to the non-existent children of Text_IO.
3635 if Dump_Original_Only
3636 and then Is_Text_IO_Special_Unit (Name (Node))
3637 then
3638 null;
3640 -- Normal case, output the with clause
3642 else
3643 if First_Name (Node) or else not Dump_Original_Only then
3645 -- Ada 2005 (AI-50217): Print limited with_clauses
3647 if Private_Present (Node) and Limited_Present (Node) then
3648 Write_Indent_Str ("limited private with ");
3650 elsif Private_Present (Node) then
3651 Write_Indent_Str ("private with ");
3653 elsif Limited_Present (Node) then
3654 Write_Indent_Str ("limited with ");
3656 else
3657 Write_Indent_Str ("with ");
3658 end if;
3660 else
3661 Write_Str (", ");
3662 end if;
3664 Sprint_Node_Sloc (Name (Node));
3666 if Last_Name (Node) or else not Dump_Original_Only then
3667 Write_Char (';');
3668 end if;
3669 end if;
3670 end case;
3672 -- Print aspects, except for special case of package declaration,
3673 -- where the aspects are printed inside the package specification.
3675 if Has_Aspects (Node)
3676 and then Nkind (Node) not in
3677 N_Generic_Package_Declaration | N_Package_Declaration
3678 and then not Is_Empty_List (Aspect_Specifications (Node))
3679 then
3680 Sprint_Aspect_Specifications (Node, Semicolon => True);
3681 end if;
3683 if Nkind (Node) in N_Subexpr and then Do_Range_Check (Node) then
3684 Write_Str ("}");
3685 end if;
3687 for J in 1 .. Paren_Count (Node) loop
3688 Write_Char (')');
3689 end loop;
3691 Dump_Node := Save_Dump_Node;
3692 end Sprint_Node_Actual;
3694 ----------------------
3695 -- Sprint_Node_List --
3696 ----------------------
3698 procedure Sprint_Node_List (List : List_Id; New_Lines : Boolean := False) is
3699 Node : Node_Id;
3701 begin
3702 if Is_Non_Empty_List (List) then
3703 Node := First (List);
3705 loop
3706 Sprint_Node (Node);
3707 Next (Node);
3708 exit when Node = Empty;
3709 end loop;
3710 end if;
3712 if New_Lines and then Column /= 1 then
3713 Write_Eol;
3714 end if;
3715 end Sprint_Node_List;
3717 ----------------------
3718 -- Sprint_Node_Sloc --
3719 ----------------------
3721 procedure Sprint_Node_Sloc (Node : Node_Id) is
3722 begin
3723 Sprint_Node (Node);
3725 if Debug_Generated_Code and then Present (Dump_Node) then
3726 Set_Sloc (Dump_Node, Sloc (Node));
3727 Dump_Node := Empty;
3728 end if;
3729 end Sprint_Node_Sloc;
3731 ---------------------
3732 -- Sprint_Opt_Node --
3733 ---------------------
3735 procedure Sprint_Opt_Node (Node : Node_Id) is
3736 begin
3737 if Present (Node) then
3738 Write_Char (' ');
3739 Sprint_Node (Node);
3740 end if;
3741 end Sprint_Opt_Node;
3743 --------------------------
3744 -- Sprint_Opt_Node_List --
3745 --------------------------
3747 procedure Sprint_Opt_Node_List (List : List_Id) is
3748 begin
3749 if Present (List) then
3750 Sprint_Node_List (List);
3751 end if;
3752 end Sprint_Opt_Node_List;
3754 ---------------------------------
3755 -- Sprint_Opt_Paren_Comma_List --
3756 ---------------------------------
3758 procedure Sprint_Opt_Paren_Comma_List (List : List_Id) is
3759 begin
3760 if Is_Non_Empty_List (List) then
3761 Write_Char (' ');
3762 Sprint_Paren_Comma_List (List);
3763 end if;
3764 end Sprint_Opt_Paren_Comma_List;
3766 -----------------------------
3767 -- Sprint_Paren_Comma_List --
3768 -----------------------------
3770 procedure Sprint_Paren_Comma_List (List : List_Id) is
3771 N : Node_Id;
3772 Node_Exists : Boolean := False;
3774 begin
3776 if Is_Non_Empty_List (List) then
3778 if Dump_Original_Only then
3779 N := First (List);
3780 while Present (N) loop
3781 if not Is_Rewrite_Insertion (N) then
3782 Node_Exists := True;
3783 exit;
3784 end if;
3786 Next (N);
3787 end loop;
3789 if not Node_Exists then
3790 return;
3791 end if;
3792 end if;
3794 Write_Str_With_Col_Check ("(");
3795 Sprint_Comma_List (List);
3796 Write_Char (')');
3797 end if;
3798 end Sprint_Paren_Comma_List;
3800 ----------------------
3801 -- Sprint_Right_Opnd --
3802 ----------------------
3804 procedure Sprint_Right_Opnd (N : Node_Id) is
3805 Opnd : constant Node_Id := Right_Opnd (N);
3807 begin
3808 if Paren_Count (Opnd) /= 0
3809 or else Op_Prec (Nkind (Opnd)) > Op_Prec (Nkind (N))
3810 then
3811 Sprint_Node (Opnd);
3813 else
3814 Write_Char ('(');
3815 Sprint_Node (Opnd);
3816 Write_Char (')');
3817 end if;
3818 end Sprint_Right_Opnd;
3820 ------------------
3821 -- Update_Itype --
3822 ------------------
3824 procedure Update_Itype (Node : Node_Id) is
3825 begin
3826 if Present (Etype (Node))
3827 and then Is_Itype (Etype (Node))
3828 and then Debug_Generated_Code
3829 then
3830 Set_Sloc (Etype (Node), Sloc (Node));
3831 end if;
3832 end Update_Itype;
3834 ---------------------
3835 -- Write_Char_Sloc --
3836 ---------------------
3838 procedure Write_Char_Sloc (C : Character) is
3839 begin
3840 if Debug_Generated_Code and then C /= ' ' then
3841 Set_Debug_Sloc;
3842 end if;
3844 Write_Char (C);
3845 end Write_Char_Sloc;
3847 --------------------------------
3848 -- Write_Condition_And_Reason --
3849 --------------------------------
3851 procedure Write_Condition_And_Reason (Node : Node_Id) is
3852 Cond : constant Node_Id := Condition (Node);
3853 Image : constant String := RT_Exception_Code'Image
3854 (RT_Exception_Code'Val
3855 (UI_To_Int (Reason (Node))));
3857 begin
3858 if Present (Cond) then
3860 -- If condition is a single entity, or NOT with a single entity,
3861 -- output all on one line, since it will likely fit just fine.
3863 if Is_Entity_Name (Cond)
3864 or else (Nkind (Cond) = N_Op_Not
3865 and then Is_Entity_Name (Right_Opnd (Cond)))
3866 then
3867 Write_Str_With_Col_Check (" when ");
3868 Sprint_Node (Cond);
3869 Write_Char (' ');
3871 -- Otherwise for more complex condition, multiple lines
3873 else
3874 Write_Str_With_Col_Check (" when");
3875 Indent := Indent + 2;
3876 Write_Indent;
3877 Sprint_Node (Cond);
3878 Write_Indent;
3879 Indent := Indent - 2;
3880 end if;
3882 -- If no condition, just need a space (all on one line)
3884 else
3885 Write_Char (' ');
3886 end if;
3888 -- Write the reason
3890 Write_Char ('"');
3892 for J in 4 .. Image'Last loop
3893 if Image (J) = '_' then
3894 Write_Char (' ');
3895 else
3896 Write_Char (Fold_Lower (Image (J)));
3897 end if;
3898 end loop;
3900 Write_Str ("""]");
3901 end Write_Condition_And_Reason;
3903 --------------------------------
3904 -- Write_Corresponding_Source --
3905 --------------------------------
3907 procedure Write_Corresponding_Source (S : String) is
3908 Loc : Source_Ptr;
3909 Src : Source_Buffer_Ptr;
3911 begin
3912 -- Ignore if there is no current source file, or we're not in dump
3913 -- source text mode, or if in freeze actions.
3915 if Current_Source_File > No_Source_File
3916 and then Dump_Source_Text
3917 and then Freeze_Indent = 0
3918 then
3920 -- Ignore null string
3922 if S = "" then
3923 return;
3924 end if;
3926 -- Ignore space or semicolon at end of given string
3928 if S (S'Last) = ' ' or else S (S'Last) = ';' then
3929 Write_Corresponding_Source (S (S'First .. S'Last - 1));
3930 return;
3931 end if;
3933 -- Loop to look at next lines not yet printed in source file
3935 for L in
3936 Last_Line_Printed + 1 .. Last_Source_Line (Current_Source_File)
3937 loop
3938 Src := Source_Text (Current_Source_File);
3939 Loc := Line_Start (L, Current_Source_File);
3941 -- If comment, keep looking
3943 if Src (Loc .. Loc + 1) = "--" then
3944 null;
3946 -- Search to first non-blank
3948 else
3949 while Src (Loc) not in Line_Terminator loop
3951 -- Non-blank found
3953 if Src (Loc) /= ' ' and then Src (Loc) /= ASCII.HT then
3955 -- Loop through characters in string to see if we match
3957 for J in S'Range loop
3959 -- If mismatch, then not the case we are looking for
3961 if Src (Loc) /= S (J) then
3962 return;
3963 end if;
3965 Loc := Loc + 1;
3966 end loop;
3968 -- If we fall through, string matched, if white space or
3969 -- semicolon after the matched string, this is the case
3970 -- we are looking for.
3972 if Src (Loc) in Line_Terminator
3973 or else Src (Loc) = ' '
3974 or else Src (Loc) = ASCII.HT
3975 or else Src (Loc) = ';'
3976 then
3977 -- So output source lines up to and including this one
3979 Write_Source_Lines (L);
3980 return;
3981 end if;
3982 end if;
3984 Loc := Loc + 1;
3985 end loop;
3986 end if;
3988 -- Line was all blanks, or a comment line, keep looking
3990 end loop;
3991 end if;
3992 end Write_Corresponding_Source;
3994 -----------------------
3995 -- Write_Discr_Specs --
3996 -----------------------
3998 procedure Write_Discr_Specs (N : Node_Id) is
3999 Specs : List_Id;
4000 Spec : Node_Id;
4002 begin
4003 Specs := Discriminant_Specifications (N);
4005 if Present (Specs) then
4006 Write_Str_With_Col_Check (" (");
4007 Spec := First (Specs);
4009 loop
4010 Sprint_Node (Spec);
4011 Next (Spec);
4012 exit when Spec = Empty;
4014 -- Add semicolon, unless we are printing original tree and the
4015 -- next specification is part of a list (but not the first
4016 -- element of that list)
4018 if not Dump_Original_Only or else not Prev_Ids (Spec) then
4019 Write_Str ("; ");
4020 end if;
4021 end loop;
4023 Write_Char (')');
4024 end if;
4025 end Write_Discr_Specs;
4027 -----------------
4028 -- Write_Ekind --
4029 -----------------
4031 procedure Write_Ekind (E : Entity_Id) is
4032 S : constant String := Entity_Kind'Image (Ekind (E));
4034 begin
4035 Name_Len := S'Length;
4036 Name_Buffer (1 .. Name_Len) := S;
4037 Set_Casing (Mixed_Case);
4038 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
4039 end Write_Ekind;
4041 --------------
4042 -- Write_Id --
4043 --------------
4045 procedure Write_Id (N : Node_Id) is
4046 begin
4047 -- Deal with outputting Itype
4049 -- Note: if we are printing the full tree with -gnatds, then we may
4050 -- end up picking up the Associated_Node link from a generic template
4051 -- here which overlaps the Entity field, but as documented, Write_Itype
4052 -- is defended against junk calls.
4054 if Nkind (N) in N_Entity then
4055 Write_Itype (N);
4056 elsif Nkind (N) in N_Has_Entity then
4057 Write_Itype (Entity (N));
4058 end if;
4060 -- Case of a defining identifier
4062 if Nkind (N) = N_Defining_Identifier then
4064 -- If defining identifier has an interface name (and no
4065 -- address clause), then we output the interface name.
4067 if (Is_Imported (N) or else Is_Exported (N))
4068 and then Present (Interface_Name (N))
4069 and then No (Address_Clause (N))
4070 then
4071 String_To_Name_Buffer (Strval (Interface_Name (N)));
4072 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
4074 -- If no interface name (or inactive because there was
4075 -- an address clause), then just output the Chars name.
4077 else
4078 Write_Name_With_Col_Check (Chars (N));
4079 end if;
4081 -- Case of selector of an expanded name where the expanded name
4082 -- has an associated entity, output this entity. Check that the
4083 -- entity or associated node is of the right kind, see above.
4085 elsif Nkind (Parent (N)) = N_Expanded_Name
4086 and then Selector_Name (Parent (N)) = N
4087 and then Present (Entity_Or_Associated_Node (Parent (N)))
4088 and then Nkind (Entity (Parent (N))) in N_Entity
4089 then
4090 Write_Id (Entity (Parent (N)));
4092 -- For any other node with an associated entity, output it
4094 elsif Nkind (N) in N_Has_Entity
4095 and then Present (Entity_Or_Associated_Node (N))
4096 and then Nkind (Entity_Or_Associated_Node (N)) in N_Entity
4097 then
4098 Write_Id (Entity (N));
4100 -- All other cases, we just print the Chars field
4102 else
4103 Write_Name_With_Col_Check (Chars (N));
4104 end if;
4105 end Write_Id;
4107 -----------------------
4108 -- Write_Identifiers --
4109 -----------------------
4111 function Write_Identifiers (Node : Node_Id) return Boolean is
4112 begin
4113 Sprint_Node (Defining_Identifier (Node));
4114 Update_Itype (Defining_Identifier (Node));
4116 -- The remainder of the declaration must be printed unless we are
4117 -- printing the original tree and this is not the last identifier
4119 return
4120 not Dump_Original_Only or else not More_Ids (Node);
4122 end Write_Identifiers;
4124 ------------------------
4125 -- Write_Implicit_Def --
4126 ------------------------
4128 procedure Write_Implicit_Def (E : Entity_Id) is
4129 Ind : Node_Id;
4131 begin
4132 case Ekind (E) is
4133 when E_Array_Subtype =>
4134 Write_Str_With_Col_Check ("subtype ");
4135 Write_Id (E);
4136 Write_Str_With_Col_Check (" is ");
4137 Write_Id (Base_Type (E));
4138 Write_Str_With_Col_Check (" (");
4140 Ind := First_Index (E);
4141 while Present (Ind) loop
4142 Sprint_Node (Ind);
4143 Next_Index (Ind);
4145 if Present (Ind) then
4146 Write_Str (", ");
4147 end if;
4148 end loop;
4150 Write_Str (");");
4152 when E_Enumeration_Subtype
4153 | E_Signed_Integer_Subtype
4155 Write_Str_With_Col_Check ("subtype ");
4156 Write_Id (E);
4157 Write_Str (" is ");
4158 Write_Id (Etype (E));
4159 Write_Str_With_Col_Check (" range ");
4160 Sprint_Node (Scalar_Range (E));
4161 Write_Str (";");
4163 when others =>
4164 Write_Str_With_Col_Check ("type ");
4165 Write_Id (E);
4166 Write_Str_With_Col_Check (" is <");
4167 Write_Ekind (E);
4168 Write_Str (">;");
4169 end case;
4170 end Write_Implicit_Def;
4172 ------------------
4173 -- Write_Indent --
4174 ------------------
4176 procedure Write_Indent is
4177 Loc : constant Source_Ptr := Sloc (Dump_Node);
4179 begin
4180 if Indent_Annull_Flag then
4181 Indent_Annull_Flag := False;
4182 else
4183 -- Deal with Dump_Source_Text output. Note that we ignore implicit
4184 -- label declarations, since they typically have the sloc of the
4185 -- corresponding label, which really messes up the -gnatL output.
4187 if Dump_Source_Text
4188 and then Loc > No_Location
4189 and then Nkind (Dump_Node) /= N_Implicit_Label_Declaration
4190 then
4191 if Get_Source_File_Index (Loc) = Current_Source_File then
4192 Write_Source_Lines
4193 (Get_Physical_Line_Number (Sloc (Dump_Node)));
4194 end if;
4195 end if;
4197 Write_Eol;
4199 for J in 1 .. Indent loop
4200 Write_Char (' ');
4201 end loop;
4202 end if;
4203 end Write_Indent;
4205 ------------------------------
4206 -- Write_Indent_Identifiers --
4207 ------------------------------
4209 function Write_Indent_Identifiers (Node : Node_Id) return Boolean is
4210 begin
4211 -- We need to start a new line for every node, except in the case
4212 -- where we are printing the original tree and this is not the first
4213 -- defining identifier in the list.
4215 if not Dump_Original_Only or else not Prev_Ids (Node) then
4216 Write_Indent;
4218 -- If printing original tree and this is not the first defining
4219 -- identifier in the list, then the previous call to this procedure
4220 -- printed only the name, and we add a comma to separate the names.
4222 else
4223 Write_Str (", ");
4224 end if;
4226 Sprint_Node (Defining_Identifier (Node));
4228 -- The remainder of the declaration must be printed unless we are
4229 -- printing the original tree and this is not the last identifier
4231 return
4232 not Dump_Original_Only or else not More_Ids (Node);
4233 end Write_Indent_Identifiers;
4235 -----------------------------------
4236 -- Write_Indent_Identifiers_Sloc --
4237 -----------------------------------
4239 function Write_Indent_Identifiers_Sloc (Node : Node_Id) return Boolean is
4240 begin
4241 -- We need to start a new line for every node, except in the case
4242 -- where we are printing the original tree and this is not the first
4243 -- defining identifier in the list.
4245 if not Dump_Original_Only or else not Prev_Ids (Node) then
4246 Write_Indent;
4248 -- If printing original tree and this is not the first defining
4249 -- identifier in the list, then the previous call to this procedure
4250 -- printed only the name, and we add a comma to separate the names.
4252 else
4253 Write_Str (", ");
4254 end if;
4256 Set_Debug_Sloc;
4257 Sprint_Node (Defining_Identifier (Node));
4259 -- The remainder of the declaration must be printed unless we are
4260 -- printing the original tree and this is not the last identifier
4262 return not Dump_Original_Only or else not More_Ids (Node);
4263 end Write_Indent_Identifiers_Sloc;
4265 ----------------------
4266 -- Write_Indent_Str --
4267 ----------------------
4269 procedure Write_Indent_Str (S : String) is
4270 begin
4271 Write_Corresponding_Source (S);
4272 Write_Indent;
4273 Write_Str (S);
4274 end Write_Indent_Str;
4276 ---------------------------
4277 -- Write_Indent_Str_Sloc --
4278 ---------------------------
4280 procedure Write_Indent_Str_Sloc (S : String) is
4281 begin
4282 Write_Corresponding_Source (S);
4283 Write_Indent;
4284 Write_Str_Sloc (S);
4285 end Write_Indent_Str_Sloc;
4287 -----------------
4288 -- Write_Itype --
4289 -----------------
4291 procedure Write_Itype (Typ : Entity_Id) is
4293 procedure Write_Header (T : Boolean := True);
4294 -- Write type if T is True, subtype if T is false
4296 ------------------
4297 -- Write_Header --
4298 ------------------
4300 procedure Write_Header (T : Boolean := True) is
4301 begin
4302 if T then
4303 Write_Str ("[type ");
4304 else
4305 Write_Str ("[subtype ");
4306 end if;
4308 Write_Name_With_Col_Check (Chars (Typ));
4309 Write_Str (" is ");
4310 end Write_Header;
4312 -- Start of processing for Write_Itype
4314 begin
4315 if Nkind (Typ) in N_Entity
4316 and then Is_Itype (Typ)
4317 and then not Itype_Printed (Typ)
4318 then
4319 -- Itype to be printed
4321 declare
4322 B : constant Entity_Id := Etype (Typ);
4323 P : constant Node_Id := Parent (Typ);
4324 S : constant Saved_Output_Buffer := Save_Output_Buffer;
4325 -- Save current output buffer
4327 Old_Sloc : Source_Ptr;
4328 -- Save sloc of related node, so it is not modified when
4329 -- printing with -gnatD.
4331 X : Node_Id;
4333 begin
4334 -- Write indentation at start of line
4336 for J in 1 .. Indent loop
4337 Write_Char (' ');
4338 end loop;
4340 -- If we have a constructed declaration for the itype, print it
4342 if Present (P)
4343 and then Nkind (P) in N_Declaration
4344 and then Defining_Entity (P) = Typ
4345 then
4346 -- We must set Itype_Printed true before the recursive call to
4347 -- print the node, otherwise we get an infinite recursion.
4349 Set_Itype_Printed (Typ, True);
4351 -- Write the declaration enclosed in [], avoiding new line
4352 -- at start of declaration, and semicolon at end.
4354 -- Note: The itype may be imported from another unit, in which
4355 -- case we do not want to modify the Sloc of the declaration.
4356 -- Otherwise the itype may appear to be in the current unit,
4357 -- and the back-end will reject a reference out of scope.
4359 Write_Char ('[');
4360 Indent_Annull_Flag := True;
4361 Old_Sloc := Sloc (P);
4362 Sprint_Node (P);
4363 Set_Sloc (P, Old_Sloc);
4364 Write_Erase_Char (';');
4366 -- If no constructed declaration, then we have to concoct the
4367 -- source corresponding to the type entity that we have at hand.
4369 else
4370 case Ekind (Typ) is
4372 -- Access types and subtypes
4374 when Access_Kind =>
4375 Write_Header (Ekind (Typ) = E_Access_Type);
4377 if Can_Never_Be_Null (Typ) then
4378 Write_Str ("not null ");
4379 end if;
4381 Write_Str ("access ");
4383 if Is_Access_Constant (Typ) then
4384 Write_Str ("constant ");
4385 end if;
4387 Write_Id (Directly_Designated_Type (Typ));
4389 -- Array types
4391 when E_Array_Type =>
4392 Write_Header;
4393 Write_Str ("array (");
4395 X := First_Index (Typ);
4396 loop
4397 Sprint_Node (X);
4399 if not Is_Constrained (Typ) then
4400 Write_Str (" range <>");
4401 end if;
4403 Next_Index (X);
4404 exit when No (X);
4405 Write_Str (", ");
4406 end loop;
4408 Write_Str (") of ");
4409 X := Component_Type (Typ);
4411 -- Preserve sloc of component type, which is defined
4412 -- elsewhere than the itype (see comment above).
4414 Old_Sloc := Sloc (X);
4415 Sprint_Node (X);
4416 Set_Sloc (X, Old_Sloc);
4418 -- Array subtypes
4420 -- Preserve Sloc of index subtypes, as above
4422 when E_Array_Subtype =>
4423 Write_Header (False);
4424 Write_Id (Etype (Typ));
4425 Write_Str (" (");
4427 X := First_Index (Typ);
4428 loop
4429 Old_Sloc := Sloc (X);
4430 Sprint_Node (X);
4431 Set_Sloc (X, Old_Sloc);
4432 Next_Index (X);
4433 exit when No (X);
4434 Write_Str (", ");
4435 end loop;
4437 Write_Char (')');
4439 -- Signed integer types, and modular integer subtypes,
4440 -- and also enumeration subtypes.
4442 when E_Enumeration_Subtype
4443 | E_Modular_Integer_Subtype
4444 | E_Signed_Integer_Subtype
4445 | E_Signed_Integer_Type
4447 Write_Header (Ekind (Typ) = E_Signed_Integer_Type);
4449 if Ekind (Typ) = E_Signed_Integer_Type then
4450 Write_Str ("new ");
4451 end if;
4453 Write_Id (B);
4455 -- Print bounds if different from base type
4457 declare
4458 L : constant Node_Id := Type_Low_Bound (Typ);
4459 H : constant Node_Id := Type_High_Bound (Typ);
4460 BL : Node_Id;
4461 BH : Node_Id;
4463 begin
4464 -- B can either be a scalar type, in which case the
4465 -- declaration of Typ may constrain it with different
4466 -- bounds, or a private type, in which case we know
4467 -- that the declaration of Typ cannot have a scalar
4468 -- constraint.
4470 if Is_Scalar_Type (B) then
4471 BL := Type_Low_Bound (B);
4472 BH := Type_High_Bound (B);
4473 else
4474 BL := Empty;
4475 BH := Empty;
4476 end if;
4478 if No (BL)
4479 or else (True
4480 and then Nkind (L) = N_Integer_Literal
4481 and then Nkind (H) = N_Integer_Literal
4482 and then Nkind (BL) = N_Integer_Literal
4483 and then Nkind (BH) = N_Integer_Literal
4484 and then UI_Eq (Intval (L), Intval (BL))
4485 and then UI_Eq (Intval (H), Intval (BH)))
4486 then
4487 null;
4489 else
4490 Write_Str (" range ");
4491 Sprint_Node (L);
4492 Write_Str (" .. ");
4493 Sprint_Node (H);
4494 end if;
4495 end;
4497 -- Modular integer types
4499 when E_Modular_Integer_Type =>
4500 Write_Header;
4501 Write_Str ("mod ");
4503 if No (Modulus (Typ)) then
4504 Write_Uint_With_Col_Check (Uint_0, Auto);
4505 else
4506 Write_Uint_With_Col_Check (Modulus (Typ), Auto);
4507 end if;
4509 -- Floating-point types and subtypes
4511 when E_Floating_Point_Subtype
4512 | E_Floating_Point_Type
4514 Write_Header (Ekind (Typ) = E_Floating_Point_Type);
4516 if Ekind (Typ) = E_Floating_Point_Type then
4517 Write_Str ("new ");
4518 end if;
4520 Write_Id (B);
4522 if Digits_Value (Typ) /= Digits_Value (B) then
4523 Write_Str (" digits ");
4524 Write_Uint_With_Col_Check
4525 (Digits_Value (Typ), Decimal);
4526 end if;
4528 -- Print bounds if not different from base type
4530 declare
4531 L : constant Node_Id := Type_Low_Bound (Typ);
4532 H : constant Node_Id := Type_High_Bound (Typ);
4533 BL : constant Node_Id := Type_Low_Bound (B);
4534 BH : constant Node_Id := Type_High_Bound (B);
4536 begin
4537 if True
4538 and then Nkind (L) = N_Real_Literal
4539 and then Nkind (H) = N_Real_Literal
4540 and then Nkind (BL) = N_Real_Literal
4541 and then Nkind (BH) = N_Real_Literal
4542 and then UR_Eq (Realval (L), Realval (BL))
4543 and then UR_Eq (Realval (H), Realval (BH))
4544 then
4545 null;
4547 else
4548 Write_Str (" range ");
4549 Sprint_Node (L);
4550 Write_Str (" .. ");
4551 Sprint_Node (H);
4552 end if;
4553 end;
4555 -- Ordinary fixed-point types and subtypes
4557 when E_Ordinary_Fixed_Point_Subtype
4558 | E_Ordinary_Fixed_Point_Type
4560 Write_Header (Ekind (Typ) = E_Ordinary_Fixed_Point_Type);
4562 Write_Str ("delta ");
4563 Write_Ureal_With_Col_Check_Sloc (Delta_Value (Typ));
4564 Write_Str (" range ");
4565 Sprint_Node (Type_Low_Bound (Typ));
4566 Write_Str (" .. ");
4567 Sprint_Node (Type_High_Bound (Typ));
4569 -- Decimal fixed-point types and subtypes
4571 when E_Decimal_Fixed_Point_Subtype
4572 | E_Decimal_Fixed_Point_Type
4574 Write_Header (Ekind (Typ) = E_Decimal_Fixed_Point_Type);
4576 Write_Str ("delta ");
4577 Write_Ureal_With_Col_Check_Sloc (Delta_Value (Typ));
4578 Write_Str (" digits ");
4579 Write_Uint_With_Col_Check (Digits_Value (Typ), Decimal);
4581 -- Record subtypes
4583 when E_Record_Subtype
4584 | E_Record_Subtype_With_Private
4586 Write_Header (False);
4587 Write_Str ("record");
4588 Indent_Begin;
4590 declare
4591 C : Entity_Id;
4592 begin
4593 C := First_Entity (Typ);
4594 while Present (C) loop
4595 Write_Indent;
4596 Write_Id (C);
4597 Write_Str (" : ");
4598 Write_Id (Etype (C));
4599 Next_Entity (C);
4600 end loop;
4601 end;
4603 Indent_End;
4604 Write_Indent_Str (" end record");
4606 -- Class-Wide types
4608 when E_Class_Wide_Subtype
4609 | E_Class_Wide_Type
4611 Write_Header (Ekind (Typ) = E_Class_Wide_Type);
4612 Write_Name_With_Col_Check (Chars (Etype (Typ)));
4613 Write_Str ("'Class");
4615 -- Subprogram types
4617 when E_Subprogram_Type =>
4618 Write_Header;
4620 if Etype (Typ) = Standard_Void_Type then
4621 Write_Str ("procedure");
4622 else
4623 Write_Str ("function");
4624 end if;
4626 if Present (First_Entity (Typ)) then
4627 Write_Str (" (");
4629 declare
4630 Param : Entity_Id;
4632 begin
4633 Param := First_Entity (Typ);
4634 loop
4635 Write_Id (Param);
4636 Write_Str (" : ");
4638 if Ekind (Param) = E_In_Out_Parameter then
4639 Write_Str ("in out ");
4640 elsif Ekind (Param) = E_Out_Parameter then
4641 Write_Str ("out ");
4642 end if;
4644 Write_Id (Etype (Param));
4645 Next_Entity (Param);
4646 exit when No (Param);
4647 Write_Str (", ");
4648 end loop;
4650 if Present (Extra_Formals (Typ)) then
4651 Param := Extra_Formals (Typ);
4653 while Present (Param) loop
4654 Write_Str (", ");
4655 Write_Id (Param);
4656 Write_Str (" : ");
4657 Write_Id (Etype (Param));
4659 Param := Extra_Formal (Param);
4660 end loop;
4661 end if;
4663 Write_Char (')');
4664 end;
4666 elsif Present (Extra_Formals (Typ)) then
4667 declare
4668 Param : Entity_Id;
4670 begin
4671 Write_Str (" (");
4673 Param := Extra_Formals (Typ);
4675 while Present (Param) loop
4676 Write_Id (Param);
4677 Write_Str (" : ");
4678 Write_Id (Etype (Param));
4680 if Present (Extra_Formal (Param)) then
4681 Write_Str (", ");
4682 end if;
4684 Param := Extra_Formal (Param);
4685 end loop;
4687 Write_Char (')');
4688 end;
4689 end if;
4691 if Etype (Typ) /= Standard_Void_Type then
4692 Write_Str (" return ");
4693 Write_Id (Etype (Typ));
4694 end if;
4696 when E_String_Literal_Subtype =>
4697 declare
4698 L : constant Uint :=
4699 Expr_Value (String_Literal_Low_Bound (Typ));
4700 Len : constant Uint :=
4701 String_Literal_Length (Typ);
4702 begin
4703 Write_Header (False);
4704 Write_Str ("String (");
4705 Write_Int (UI_To_Int (L));
4706 Write_Str (" .. ");
4707 Write_Int (UI_To_Int (L + Len) - 1);
4708 Write_Str (");");
4709 end;
4711 -- For all other Itypes, print a triple ? (fill in later
4712 -- if needed).
4714 when others =>
4715 Write_Header (True);
4716 Write_Str ("???");
4717 end case;
4718 end if;
4720 -- Add terminating bracket and restore output buffer
4722 Write_Char (']');
4723 Write_Eol;
4724 Restore_Output_Buffer (S);
4725 end;
4727 Set_Itype_Printed (Typ);
4728 end if;
4729 end Write_Itype;
4731 -------------------------------
4732 -- Write_Name_With_Col_Check --
4733 -------------------------------
4735 procedure Write_Name_With_Col_Check (N : Name_Id) is
4736 J : Natural;
4737 K : Natural;
4738 L : Natural;
4740 begin
4741 -- Avoid crashing on invalid Name_Ids
4743 if not Is_Valid_Name (N) then
4744 Write_Str ("<invalid name ");
4745 Write_Int (Int (N));
4746 Write_Str (">");
4747 return;
4748 end if;
4750 Get_Name_String (N);
4752 -- Deal with -gnatdI which replaces any sequence Cnnnb where C is an
4753 -- upper case letter, nnn is one or more digits and b is a lower case
4754 -- letter by C...b, so that listings do not depend on serial numbers.
4756 if Debug_Flag_II then
4757 J := 1;
4758 while J < Name_Len - 1 loop
4759 if Name_Buffer (J) in 'A' .. 'Z'
4760 and then Name_Buffer (J + 1) in '0' .. '9'
4761 then
4762 K := J + 1;
4763 while K < Name_Len loop
4764 exit when Name_Buffer (K) not in '0' .. '9';
4765 K := K + 1;
4766 end loop;
4768 if Name_Buffer (K) in 'a' .. 'z' then
4769 L := Name_Len - K + 1;
4771 Name_Buffer (J + 4 .. J + L + 3) :=
4772 Name_Buffer (K .. Name_Len);
4773 Name_Buffer (J + 1 .. J + 3) := "...";
4774 Name_Len := J + L + 3;
4775 J := J + 5;
4777 else
4778 J := K;
4779 end if;
4781 else
4782 J := J + 1;
4783 end if;
4784 end loop;
4785 end if;
4787 -- Fall through for normal case
4789 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
4790 end Write_Name_With_Col_Check;
4792 ------------------------------------
4793 -- Write_Name_With_Col_Check_Sloc --
4794 ------------------------------------
4796 procedure Write_Name_With_Col_Check_Sloc (N : Name_Id) is
4797 begin
4798 -- Avoid crashing on invalid Name_Ids
4800 if not Is_Valid_Name (N) then
4801 Write_Str ("<invalid name ");
4802 Write_Int (Int (N));
4803 Write_Str (">");
4804 return;
4805 end if;
4807 Get_Name_String (N);
4808 Write_Str_With_Col_Check_Sloc (Name_Buffer (1 .. Name_Len));
4809 end Write_Name_With_Col_Check_Sloc;
4811 --------------------
4812 -- Write_Operator --
4813 --------------------
4815 procedure Write_Operator (N : Node_Id; S : String) is
4816 F : Natural := S'First;
4817 T : Natural := S'Last;
4819 begin
4820 -- If no overflow check, just write string out, and we are done
4822 if not Do_Overflow_Check (N) then
4823 Write_Str_Sloc (S);
4825 -- If overflow check, we want to surround the operator with curly
4826 -- brackets, but not include spaces within the brackets.
4828 else
4829 if S (F) = ' ' then
4830 Write_Char (' ');
4831 F := F + 1;
4832 end if;
4834 if S (T) = ' ' then
4835 T := T - 1;
4836 end if;
4838 Write_Char ('{');
4839 Write_Str_Sloc (S (F .. T));
4840 Write_Char ('}');
4842 if S (S'Last) = ' ' then
4843 Write_Char (' ');
4844 end if;
4845 end if;
4846 end Write_Operator;
4848 -----------------------
4849 -- Write_Param_Specs --
4850 -----------------------
4852 procedure Write_Param_Specs (N : Node_Id) is
4853 Specs : constant List_Id := Parameter_Specifications (N);
4854 Specs_Present : constant Boolean := Is_Non_Empty_List (Specs);
4856 Ent : Entity_Id;
4857 Extras : Node_Id;
4858 Spec : Node_Id;
4859 Formal : Node_Id;
4861 Output : Boolean := False;
4862 -- Set true if we output at least one parameter
4864 begin
4865 -- Write out explicit specs from Parameter_Specifications list
4867 if Specs_Present then
4868 Write_Str_With_Col_Check (" (");
4869 Output := True;
4871 Spec := First (Specs);
4872 loop
4873 Sprint_Node (Spec);
4874 Formal := Defining_Identifier (Spec);
4875 Next (Spec);
4876 exit when Spec = Empty;
4878 -- Add semicolon, unless we are printing original tree and the
4879 -- next specification is part of a list (but not the first element
4880 -- of that list).
4882 if not Dump_Original_Only or else not Prev_Ids (Spec) then
4883 Write_Str ("; ");
4884 end if;
4885 end loop;
4886 end if;
4888 -- See if we have extra formals
4890 if Nkind (N) in N_Function_Specification | N_Procedure_Specification then
4891 Ent := Defining_Entity (N);
4893 -- Loop to write extra formals (if any)
4895 if Present (Ent) and then Is_Subprogram (Ent) then
4896 Extras := Extra_Formals (Ent);
4898 if Present (Extras) then
4899 if not Specs_Present then
4900 Write_Str_With_Col_Check (" (");
4901 Output := True;
4902 end if;
4904 Formal := Extras;
4905 while Present (Formal) loop
4906 if Specs_Present or else Formal /= Extras then
4907 Write_Str ("; ");
4908 end if;
4910 Write_Name_With_Col_Check (Chars (Formal));
4911 Write_Str (" : ");
4912 Write_Name_With_Col_Check (Chars (Etype (Formal)));
4913 Formal := Extra_Formal (Formal);
4914 end loop;
4915 end if;
4916 end if;
4917 end if;
4919 if Output then
4920 Write_Char (')');
4921 end if;
4922 end Write_Param_Specs;
4924 -----------------------
4925 -- Write_Rewrite_Str --
4926 -----------------------
4928 procedure Write_Rewrite_Str (S : String) is
4929 begin
4930 if not Dump_Generated_Only then
4931 if S'Length = 3 and then S = ">>>" then
4932 Write_Str (">>>");
4933 else
4934 Write_Str_With_Col_Check (S);
4935 end if;
4936 end if;
4937 end Write_Rewrite_Str;
4939 -----------------------
4940 -- Write_Source_Line --
4941 -----------------------
4943 procedure Write_Source_Line (L : Physical_Line_Number) is
4944 Loc : Source_Ptr;
4945 Src : Source_Buffer_Ptr;
4946 Scn : Source_Ptr;
4948 begin
4949 if Dump_Source_Text then
4950 Src := Source_Text (Current_Source_File);
4951 Loc := Line_Start (L, Current_Source_File);
4952 Write_Eol;
4954 -- See if line is a comment line, if not, and if not line one,
4955 -- precede with blank line.
4957 Scn := Loc;
4958 while Src (Scn) = ' ' or else Src (Scn) = ASCII.HT loop
4959 Scn := Scn + 1;
4960 end loop;
4962 if (Src (Scn) in Line_Terminator
4963 or else Src (Scn .. Scn + 1) /= "--")
4964 and then L /= 1
4965 then
4966 Write_Eol;
4967 end if;
4969 -- Now write the source text of the line
4971 Write_Str ("-- ");
4972 Write_Int (Int (L));
4973 Write_Str (": ");
4975 -- We need to check for EOF here, in case the last line of the source
4976 -- file does not have a Line_Terminator.
4978 while Src (Loc) not in Line_Terminator | EOF loop
4979 Write_Char (Src (Loc));
4980 Loc := Loc + 1;
4981 end loop;
4982 end if;
4983 end Write_Source_Line;
4985 ------------------------
4986 -- Write_Source_Lines --
4987 ------------------------
4989 procedure Write_Source_Lines (L : Physical_Line_Number) is
4990 begin
4991 while Last_Line_Printed < L loop
4992 Last_Line_Printed := Last_Line_Printed + 1;
4993 Write_Source_Line (Last_Line_Printed);
4994 end loop;
4995 end Write_Source_Lines;
4997 --------------------
4998 -- Write_Str_Sloc --
4999 --------------------
5001 procedure Write_Str_Sloc (S : String) is
5002 begin
5003 for J in S'Range loop
5004 Write_Char_Sloc (S (J));
5005 end loop;
5006 end Write_Str_Sloc;
5008 ------------------------------
5009 -- Write_Str_With_Col_Check --
5010 ------------------------------
5012 procedure Write_Str_With_Col_Check (S : String) is
5013 begin
5014 if Int (S'Last) + Column > Sprint_Line_Limit then
5015 Write_Indent_Str (" ");
5017 if S (S'First) = ' ' then
5018 Write_Str (S (S'First + 1 .. S'Last));
5019 else
5020 Write_Str (S);
5021 end if;
5023 else
5024 Write_Str (S);
5025 end if;
5026 end Write_Str_With_Col_Check;
5028 -----------------------------------
5029 -- Write_Str_With_Col_Check_Sloc --
5030 -----------------------------------
5032 procedure Write_Str_With_Col_Check_Sloc (S : String) is
5033 begin
5034 if Int (S'Last) + Column > Sprint_Line_Limit then
5035 Write_Indent_Str (" ");
5037 if S (S'First) = ' ' then
5038 Write_Str_Sloc (S (S'First + 1 .. S'Last));
5039 else
5040 Write_Str_Sloc (S);
5041 end if;
5043 else
5044 Write_Str_Sloc (S);
5045 end if;
5046 end Write_Str_With_Col_Check_Sloc;
5048 ---------------------------
5049 -- Write_Subprogram_Name --
5050 ---------------------------
5052 procedure Write_Subprogram_Name (N : Node_Id) is
5053 begin
5054 if not Comes_From_Source (N)
5055 and then Is_Entity_Name (N)
5056 then
5057 declare
5058 Ent : constant Entity_Id := Entity (N);
5059 begin
5060 if not In_Extended_Main_Source_Unit (Ent)
5061 and then In_Predefined_Unit (Ent)
5062 then
5063 -- Run-time routine name, output name with a preceding dollar
5064 -- making sure that we do not get a line split between them.
5066 Col_Check (Length_Of_Name (Chars (Ent)) + 1);
5067 Write_Char ('$');
5068 Write_Name (Chars (Ent));
5069 return;
5070 end if;
5071 end;
5072 end if;
5074 -- Normal case, not a run-time routine name
5076 Sprint_Node (N);
5077 end Write_Subprogram_Name;
5079 -------------------------------
5080 -- Write_Uint_With_Col_Check --
5081 -------------------------------
5083 procedure Write_Uint_With_Col_Check (U : Uint; Format : UI_Format) is
5084 begin
5085 Col_Check (UI_Decimal_Digits_Hi (U));
5086 UI_Write (U, Format);
5087 end Write_Uint_With_Col_Check;
5089 ------------------------------------
5090 -- Write_Uint_With_Col_Check_Sloc --
5091 ------------------------------------
5093 procedure Write_Uint_With_Col_Check_Sloc (U : Uint; Format : UI_Format) is
5094 begin
5095 Col_Check (UI_Decimal_Digits_Hi (U));
5096 Set_Debug_Sloc;
5097 UI_Write (U, Format);
5098 end Write_Uint_With_Col_Check_Sloc;
5100 -------------------------------------
5101 -- Write_Ureal_With_Col_Check_Sloc --
5102 -------------------------------------
5104 procedure Write_Ureal_With_Col_Check_Sloc (U : Ureal) is
5105 D : constant Uint := Denominator (U);
5106 N : constant Uint := Numerator (U);
5107 begin
5108 Col_Check (UI_Decimal_Digits_Hi (D) + UI_Decimal_Digits_Hi (N) + 4);
5109 Set_Debug_Sloc;
5110 UR_Write (U, Brackets => True);
5111 end Write_Ureal_With_Col_Check_Sloc;
5113 end Sprint;