Add assember CFI directives to millicode division and remainder routines.
[official-gcc.git] / gcc / ada / sprint.adb
blobdd4f420af352e0f282c745053717f0b67c94628c
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 ("(");
1089 if Present (Expressions (Node)) then
1090 Sprint_Comma_List (Expressions (Node));
1092 if not Is_Empty_List (Component_Associations (Node)) then
1093 Write_Str (", ");
1094 end if;
1095 end if;
1097 if not Is_Empty_List (Component_Associations (Node)) then
1098 Indent_Begin;
1100 declare
1101 Nd : Node_Id;
1103 begin
1104 Nd := First (Component_Associations (Node));
1106 loop
1107 Write_Indent;
1108 Sprint_Node (Nd);
1109 Next (Nd);
1110 exit when No (Nd);
1112 if not Is_Rewrite_Insertion (Nd)
1113 or else not Dump_Original_Only
1114 then
1115 Write_Str (", ");
1116 end if;
1117 end loop;
1118 end;
1120 Indent_End;
1121 end if;
1123 Write_Char (')');
1124 end if;
1126 when N_Allocator =>
1127 Write_Str_With_Col_Check_Sloc ("new ");
1129 -- Ada 2005 (AI-231)
1131 if Null_Exclusion_Present (Node) then
1132 Write_Str ("not null ");
1133 end if;
1135 Sprint_Node (Expression (Node));
1137 if Present (Storage_Pool (Node)) then
1138 Write_Str_With_Col_Check ("[storage_pool = ");
1139 Sprint_Node (Storage_Pool (Node));
1140 Write_Char (']');
1141 end if;
1143 if Present (Procedure_To_Call (Node)) then
1144 Write_Str_With_Col_Check ("[procedure_to_call = ");
1145 Sprint_Node (Procedure_To_Call (Node));
1146 Write_Char (']');
1147 end if;
1149 when N_And_Then =>
1150 Sprint_Left_Opnd (Node);
1151 Write_Str_Sloc (" and then ");
1152 Sprint_Right_Opnd (Node);
1154 -- Note: the following code for N_Aspect_Specification is not
1155 -- normally used, since we deal with aspects as part of a
1156 -- declaration, but it is here in case we deliberately try
1157 -- to print an N_Aspect_Specification node (e.g. from GDB).
1159 when N_Aspect_Specification =>
1160 Sprint_Node (Identifier (Node));
1161 Write_Str (" => ");
1162 Sprint_Node (Expression (Node));
1164 when N_Assignment_Statement =>
1165 Write_Indent;
1166 Sprint_Node (Name (Node));
1167 Write_Str_Sloc (" := ");
1168 Sprint_Node (Expression (Node));
1169 Write_Char (';');
1171 when N_Asynchronous_Select =>
1172 Write_Indent_Str_Sloc ("select");
1173 Indent_Begin;
1174 Sprint_Node (Triggering_Alternative (Node));
1175 Indent_End;
1177 -- Note: let the printing of Abortable_Part handle outputting
1178 -- the ABORT keyword, so that the Sloc can be set correctly.
1180 Write_Indent_Str ("then ");
1181 Sprint_Node (Abortable_Part (Node));
1182 Write_Indent_Str ("end select;");
1184 when N_At_Clause =>
1185 Write_Indent_Str_Sloc ("for ");
1186 Write_Id (Identifier (Node));
1187 Write_Str_With_Col_Check (" use at ");
1188 Sprint_Node (Expression (Node));
1189 Write_Char (';');
1191 when N_Attribute_Definition_Clause =>
1192 Write_Indent_Str_Sloc ("for ");
1193 Sprint_Node (Name (Node));
1194 Write_Char (''');
1195 Write_Name_With_Col_Check (Chars (Node));
1196 Write_Str_With_Col_Check (" use ");
1197 Sprint_Node (Expression (Node));
1198 Write_Char (';');
1200 when N_Attribute_Reference =>
1201 if Is_Procedure_Attribute_Name (Attribute_Name (Node)) then
1202 Write_Indent;
1203 end if;
1205 Sprint_Node (Prefix (Node));
1206 Write_Char_Sloc (''');
1207 Write_Name_With_Col_Check (Attribute_Name (Node));
1208 Sprint_Paren_Comma_List (Expressions (Node));
1210 if Is_Procedure_Attribute_Name (Attribute_Name (Node)) then
1211 Write_Char (';');
1212 end if;
1214 when N_Block_Statement =>
1215 Write_Indent;
1217 if Present (Identifier (Node))
1218 and then (not Has_Created_Identifier (Node)
1219 or else not Dump_Original_Only)
1220 then
1221 Write_Rewrite_Str ("<<<");
1222 Write_Id (Identifier (Node));
1223 Write_Str (" : ");
1224 Write_Rewrite_Str (">>>");
1225 end if;
1227 if Present (Declarations (Node)) then
1228 Write_Str_With_Col_Check_Sloc ("declare");
1229 Sprint_Indented_List (Declarations (Node));
1230 Write_Indent;
1231 end if;
1233 Write_Str_With_Col_Check_Sloc ("begin");
1234 Sprint_Node (Handled_Statement_Sequence (Node));
1235 Write_Indent_Str ("end");
1237 if Present (Identifier (Node))
1238 and then (not Has_Created_Identifier (Node)
1239 or else not Dump_Original_Only)
1240 then
1241 Write_Rewrite_Str ("<<<");
1242 Write_Char (' ');
1243 Write_Id (Identifier (Node));
1244 Write_Rewrite_Str (">>>");
1245 end if;
1247 Write_Char (';');
1248 Sprint_At_End_Proc (Node);
1250 when N_Call_Marker =>
1251 null;
1253 -- Enable the following code for debugging purposes only
1255 -- Write_Indent_Str ("#");
1256 -- Write_Id (Target (Node));
1257 -- Write_Char ('#');
1259 when N_Case_Expression =>
1260 declare
1261 Has_Parens : constant Boolean := Paren_Count (Node) > 0;
1262 Alt : Node_Id;
1264 begin
1265 -- The syntax for case_expression does not include parentheses,
1266 -- but sometimes parentheses are required, so unconditionally
1267 -- generate them here unless already present.
1269 if not Has_Parens then
1270 Write_Char ('(');
1271 end if;
1273 Write_Str_With_Col_Check_Sloc ("case ");
1274 Sprint_Node (Expression (Node));
1275 Write_Str_With_Col_Check (" is");
1277 Alt := First (Alternatives (Node));
1278 loop
1279 Sprint_Node (Alt);
1280 Next (Alt);
1281 exit when No (Alt);
1282 Write_Char (',');
1283 end loop;
1285 if not Has_Parens then
1286 Write_Char (')');
1287 end if;
1288 end;
1290 when N_Case_Expression_Alternative =>
1291 Write_Str_With_Col_Check (" when ");
1292 Sprint_Bar_List (Discrete_Choices (Node));
1293 Write_Str (" => ");
1294 Sprint_Node (Expression (Node));
1296 when N_Case_Statement =>
1297 Write_Indent_Str_Sloc ("case ");
1298 Sprint_Node (Expression (Node));
1299 Write_Str (" is");
1300 Sprint_Indented_List (Alternatives (Node));
1301 Write_Indent_Str ("end case;");
1303 when N_Case_Statement_Alternative =>
1304 Write_Indent_Str_Sloc ("when ");
1305 Sprint_Bar_List (Discrete_Choices (Node));
1306 Write_Str (" => ");
1307 Sprint_Indented_List (Statements (Node));
1309 when N_Character_Literal =>
1310 if Column > Sprint_Line_Limit - 2 then
1311 Write_Indent_Str (" ");
1312 end if;
1314 Write_Char_Sloc (''');
1315 Write_Char_Code (UI_To_CC (Char_Literal_Value (Node)));
1316 Write_Char (''');
1318 when N_Code_Statement =>
1319 Write_Indent;
1320 Set_Debug_Sloc;
1321 Sprint_Node (Expression (Node));
1322 Write_Char (';');
1324 when N_Compilation_Unit =>
1325 Sprint_Node_List (Context_Items (Node));
1326 Sprint_Opt_Node_List (Declarations (Aux_Decls_Node (Node)));
1328 if Private_Present (Node) then
1329 Write_Indent_Str ("private ");
1330 Indent_Annull;
1331 end if;
1333 Sprint_Node_Sloc (Unit (Node));
1335 if Present (Actions (Aux_Decls_Node (Node)))
1336 or else
1337 Present (Pragmas_After (Aux_Decls_Node (Node)))
1338 then
1339 Write_Indent;
1340 end if;
1342 Sprint_Opt_Node_List (Actions (Aux_Decls_Node (Node)));
1343 Sprint_Opt_Node_List (Pragmas_After (Aux_Decls_Node (Node)));
1345 when N_Compilation_Unit_Aux =>
1346 null; -- nothing to do, never used, see above
1348 when N_Component_Association =>
1349 Set_Debug_Sloc;
1350 Sprint_Bar_List (Choices (Node));
1351 Write_Str (" => ");
1353 -- Ada 2005 (AI-287): Print the box if present
1355 if Box_Present (Node) then
1356 Write_Str_With_Col_Check ("<>");
1357 else
1358 Sprint_Node (Expression (Node));
1359 end if;
1361 when N_Iterated_Component_Association =>
1362 Set_Debug_Sloc;
1363 Write_Str (" for ");
1364 if Present (Iterator_Specification (Node)) then
1365 Sprint_Node (Iterator_Specification (Node));
1366 else
1367 Write_Id (Defining_Identifier (Node));
1368 Write_Str (" in ");
1369 Sprint_Bar_List (Discrete_Choices (Node));
1370 end if;
1371 Write_Str (" => ");
1372 Sprint_Node (Expression (Node));
1374 when N_Iterated_Element_Association =>
1375 Set_Debug_Sloc;
1376 if Present (Iterator_Specification (Node)) then
1377 Sprint_Node (Iterator_Specification (Node));
1378 else
1379 Sprint_Node (Loop_Parameter_Specification (Node));
1380 end if;
1382 if Present (Key_Expression (Node)) then
1383 Write_Str (" use ");
1384 Sprint_Node (Key_Expression (Node));
1385 end if;
1387 Write_Str (" => ");
1388 Sprint_Node (Expression (Node));
1390 when N_Component_Clause =>
1391 Write_Indent;
1392 Sprint_Node (Component_Name (Node));
1393 Write_Str_Sloc (" at ");
1394 Sprint_Node (Position (Node));
1395 Write_Char (' ');
1396 Write_Str_With_Col_Check ("range ");
1397 Sprint_Node (First_Bit (Node));
1398 Write_Str (" .. ");
1399 Sprint_Node (Last_Bit (Node));
1400 Write_Char (';');
1402 when N_Component_Definition =>
1403 Set_Debug_Sloc;
1405 -- Ada 2005 (AI-230): Access definition components
1407 if Present (Access_Definition (Node)) then
1408 Sprint_Node (Access_Definition (Node));
1410 elsif Present (Subtype_Indication (Node)) then
1411 if Aliased_Present (Node) then
1412 Write_Str_With_Col_Check ("aliased ");
1413 end if;
1415 -- Ada 2005 (AI-231)
1417 if Null_Exclusion_Present (Node) then
1418 Write_Str (" not null ");
1419 end if;
1421 Sprint_Node (Subtype_Indication (Node));
1423 else
1424 Write_Str (" ??? ");
1425 end if;
1427 when N_Component_Declaration =>
1428 if Write_Indent_Identifiers_Sloc (Node) then
1429 Write_Str (" : ");
1430 Sprint_Node (Component_Definition (Node));
1432 if Present (Expression (Node)) then
1433 Write_Str (" := ");
1434 Sprint_Node (Expression (Node));
1435 end if;
1437 Write_Char (';');
1438 end if;
1440 when N_Component_List =>
1441 if Null_Present (Node) then
1442 Indent_Begin;
1443 Write_Indent_Str_Sloc ("null");
1444 Write_Char (';');
1445 Indent_End;
1447 else
1448 Set_Debug_Sloc;
1449 Sprint_Indented_List (Component_Items (Node));
1450 Sprint_Node (Variant_Part (Node));
1451 end if;
1453 when N_Compound_Statement =>
1454 Write_Indent_Str ("do");
1455 Indent_Begin;
1456 Sprint_Node_List (Actions (Node));
1457 Indent_End;
1458 Write_Indent_Str ("end;");
1460 when N_Conditional_Entry_Call =>
1461 Write_Indent_Str_Sloc ("select");
1462 Indent_Begin;
1463 Sprint_Node (Entry_Call_Alternative (Node));
1464 Indent_End;
1465 Write_Indent_Str ("else");
1466 Sprint_Indented_List (Else_Statements (Node));
1467 Write_Indent_Str ("end select;");
1469 when N_Constrained_Array_Definition =>
1470 Write_Str_With_Col_Check_Sloc ("array ");
1471 Sprint_Paren_Comma_List (Discrete_Subtype_Definitions (Node));
1472 Write_Str (" of ");
1474 Sprint_Node (Component_Definition (Node));
1476 -- A contract node should not appear in the tree. It is a semantic
1477 -- node attached to entry and [generic] subprogram entities. But we
1478 -- still provide meaningful output, in case called from the debugger.
1480 when N_Contract =>
1481 declare
1482 P : Node_Id;
1484 begin
1485 Indent_Begin;
1486 Write_Str ("N_Contract node");
1487 Write_Eol;
1489 Write_Indent_Str ("Pre_Post_Conditions");
1490 Indent_Begin;
1492 P := Pre_Post_Conditions (Node);
1493 while Present (P) loop
1494 Sprint_Node (P);
1495 P := Next_Pragma (P);
1496 end loop;
1498 Write_Eol;
1499 Indent_End;
1501 Write_Indent_Str ("Contract_Test_Cases");
1502 Indent_Begin;
1504 P := Contract_Test_Cases (Node);
1505 while Present (P) loop
1506 Sprint_Node (P);
1507 P := Next_Pragma (P);
1508 end loop;
1510 Write_Eol;
1511 Indent_End;
1513 Write_Indent_Str ("Classifications");
1514 Indent_Begin;
1516 P := Classifications (Node);
1517 while Present (P) loop
1518 Sprint_Node (P);
1519 P := Next_Pragma (P);
1520 end loop;
1522 Write_Eol;
1523 Indent_End;
1524 Indent_End;
1525 end;
1527 when N_Decimal_Fixed_Point_Definition =>
1528 Write_Str_With_Col_Check_Sloc ("delta ");
1529 Sprint_Node (Delta_Expression (Node));
1530 Write_Str_With_Col_Check (" digits ");
1531 Sprint_Node (Digits_Expression (Node));
1532 Sprint_Opt_Node (Real_Range_Specification (Node));
1534 when N_Defining_Character_Literal =>
1535 Write_Name_With_Col_Check_Sloc (Chars (Node));
1537 when N_Defining_Identifier =>
1538 Set_Debug_Sloc;
1539 Write_Id (Node);
1541 when N_Defining_Operator_Symbol =>
1542 Write_Name_With_Col_Check_Sloc (Chars (Node));
1544 when N_Defining_Program_Unit_Name =>
1545 Set_Debug_Sloc;
1546 Sprint_Node (Name (Node));
1547 Write_Char ('.');
1548 Write_Id (Defining_Identifier (Node));
1550 when N_Delay_Alternative =>
1551 Sprint_Node_List (Pragmas_Before (Node));
1553 if Present (Condition (Node)) then
1554 Write_Indent;
1555 Write_Str_With_Col_Check ("when ");
1556 Sprint_Node (Condition (Node));
1557 Write_Str (" => ");
1558 Indent_Annull;
1559 end if;
1561 Sprint_Node_Sloc (Delay_Statement (Node));
1562 Sprint_Node_List (Statements (Node));
1564 when N_Delay_Relative_Statement =>
1565 Write_Indent_Str_Sloc ("delay ");
1566 Sprint_Node (Expression (Node));
1567 Write_Char (';');
1569 when N_Delay_Until_Statement =>
1570 Write_Indent_Str_Sloc ("delay until ");
1571 Sprint_Node (Expression (Node));
1572 Write_Char (';');
1574 when N_Delta_Constraint =>
1575 Write_Str_With_Col_Check_Sloc ("delta ");
1576 Sprint_Node (Delta_Expression (Node));
1577 Sprint_Opt_Node (Range_Constraint (Node));
1579 when N_Derived_Type_Definition =>
1580 if Abstract_Present (Node) then
1581 Write_Str_With_Col_Check ("abstract ");
1582 end if;
1584 Write_Str_With_Col_Check ("new ");
1586 -- Ada 2005 (AI-231)
1588 if Null_Exclusion_Present (Node) then
1589 Write_Str_With_Col_Check ("not null ");
1590 end if;
1592 Sprint_Node (Subtype_Indication (Node));
1594 if Present (Interface_List (Node)) then
1595 Write_Str_With_Col_Check (" and ");
1596 Sprint_And_List (Interface_List (Node));
1597 Write_Str_With_Col_Check (" with ");
1598 end if;
1600 if Present (Record_Extension_Part (Node)) then
1601 if No (Interface_List (Node)) then
1602 Write_Str_With_Col_Check (" with ");
1603 end if;
1605 Sprint_Node (Record_Extension_Part (Node));
1606 end if;
1608 when N_Designator =>
1609 Sprint_Node (Name (Node));
1610 Write_Char_Sloc ('.');
1611 Write_Id (Identifier (Node));
1613 when N_Digits_Constraint =>
1614 Write_Str_With_Col_Check_Sloc ("digits ");
1615 Sprint_Node (Digits_Expression (Node));
1616 Sprint_Opt_Node (Range_Constraint (Node));
1618 when N_Discriminant_Association =>
1619 Set_Debug_Sloc;
1621 if Present (Selector_Names (Node)) then
1622 Sprint_Bar_List (Selector_Names (Node));
1623 Write_Str (" => ");
1624 end if;
1626 Set_Debug_Sloc;
1627 Sprint_Node (Expression (Node));
1629 when N_Discriminant_Specification =>
1630 Set_Debug_Sloc;
1632 if Write_Identifiers (Node) then
1633 Write_Str (" : ");
1635 if Null_Exclusion_Present (Node) then
1636 Write_Str ("not null ");
1637 end if;
1639 Sprint_Node (Discriminant_Type (Node));
1641 if Present (Expression (Node)) then
1642 Write_Str (" := ");
1643 Sprint_Node (Expression (Node));
1644 end if;
1645 else
1646 Write_Str (", ");
1647 end if;
1649 when N_Elsif_Part =>
1650 Write_Indent_Str_Sloc ("elsif ");
1651 Sprint_Node (Condition (Node));
1652 Write_Str_With_Col_Check (" then");
1653 Sprint_Indented_List (Then_Statements (Node));
1655 when N_Empty =>
1656 null;
1658 when N_Entry_Body =>
1659 Write_Indent_Str_Sloc ("entry ");
1660 Write_Id (Defining_Identifier (Node));
1661 Sprint_Node (Entry_Body_Formal_Part (Node));
1662 Write_Str_With_Col_Check (" is");
1663 Sprint_Indented_List (Declarations (Node));
1664 Write_Indent_Str ("begin");
1665 Sprint_Node (Handled_Statement_Sequence (Node));
1666 Write_Indent_Str ("end ");
1667 Write_Id (Defining_Identifier (Node));
1668 Write_Char (';');
1669 Sprint_At_End_Proc (Node);
1671 when N_Entry_Body_Formal_Part =>
1672 if Present (Entry_Index_Specification (Node)) then
1673 Write_Str_With_Col_Check_Sloc (" (");
1674 Sprint_Node (Entry_Index_Specification (Node));
1675 Write_Char (')');
1676 end if;
1678 Write_Param_Specs (Node);
1679 Write_Str_With_Col_Check_Sloc (" when ");
1680 Sprint_Node (Condition (Node));
1682 when N_Entry_Call_Alternative =>
1683 Sprint_Node_List (Pragmas_Before (Node));
1684 Sprint_Node_Sloc (Entry_Call_Statement (Node));
1685 Sprint_Node_List (Statements (Node));
1687 when N_Entry_Call_Statement =>
1688 Write_Indent;
1689 Sprint_Node_Sloc (Name (Node));
1690 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
1691 Write_Char (';');
1693 when N_Entry_Declaration =>
1694 Write_Indent_Str_Sloc ("entry ");
1695 Write_Id (Defining_Identifier (Node));
1697 if Present (Discrete_Subtype_Definition (Node)) then
1698 Write_Str_With_Col_Check (" (");
1699 Sprint_Node (Discrete_Subtype_Definition (Node));
1700 Write_Char (')');
1701 end if;
1703 Write_Param_Specs (Node);
1704 Write_Char (';');
1706 when N_Entry_Index_Specification =>
1707 Write_Str_With_Col_Check_Sloc ("for ");
1708 Write_Id (Defining_Identifier (Node));
1709 Write_Str_With_Col_Check (" in ");
1710 Sprint_Node (Discrete_Subtype_Definition (Node));
1712 when N_Enumeration_Representation_Clause =>
1713 Write_Indent_Str_Sloc ("for ");
1714 Write_Id (Identifier (Node));
1715 Write_Str_With_Col_Check (" use ");
1716 Sprint_Node (Array_Aggregate (Node));
1717 Write_Char (';');
1719 when N_Enumeration_Type_Definition =>
1720 Set_Debug_Sloc;
1722 -- Skip attempt to print Literals field if it's not there and
1723 -- we are in package Standard (case of Character, which is
1724 -- handled specially (without an explicit literals list).
1726 if Sloc (Node) > Standard_Location
1727 or else Present (Literals (Node))
1728 then
1729 Sprint_Paren_Comma_List (Literals (Node));
1730 end if;
1732 when N_Error =>
1733 Write_Str_With_Col_Check_Sloc ("<error>");
1735 when N_Exception_Declaration =>
1736 if Write_Indent_Identifiers (Node) then
1737 Write_Str_With_Col_Check (" : ");
1739 if Is_Statically_Allocated (Defining_Identifier (Node)) then
1740 Write_Str_With_Col_Check ("static ");
1741 end if;
1743 Write_Str_Sloc ("exception");
1745 if Present (Expression (Node)) then
1746 Write_Str (" := ");
1747 Sprint_Node (Expression (Node));
1748 end if;
1750 Write_Char (';');
1751 end if;
1753 when N_Exception_Handler =>
1754 Write_Indent_Str_Sloc ("when ");
1756 if Present (Choice_Parameter (Node)) then
1757 Sprint_Node (Choice_Parameter (Node));
1758 Write_Str (" : ");
1759 end if;
1761 Sprint_Bar_List (Exception_Choices (Node));
1762 Write_Str (" => ");
1763 Sprint_Indented_List (Statements (Node));
1765 when N_Exception_Renaming_Declaration =>
1766 Write_Indent;
1767 Set_Debug_Sloc;
1768 Sprint_Node (Defining_Identifier (Node));
1769 Write_Str_With_Col_Check (" : exception renames ");
1770 Sprint_Node (Name (Node));
1771 Write_Char (';');
1773 when N_Exit_Statement =>
1774 Write_Indent_Str_Sloc ("exit");
1775 Sprint_Opt_Node (Name (Node));
1777 if Present (Condition (Node)) then
1778 Write_Str_With_Col_Check (" when ");
1779 Sprint_Node (Condition (Node));
1780 end if;
1782 Write_Char (';');
1784 when N_Expanded_Name =>
1785 Sprint_Node (Prefix (Node));
1786 Write_Char_Sloc ('.');
1787 Sprint_Node (Selector_Name (Node));
1789 when N_Explicit_Dereference =>
1790 Sprint_Node (Prefix (Node));
1791 Write_Char_Sloc ('.');
1792 Write_Str_Sloc ("all");
1794 when N_Expression_With_Actions =>
1795 Indent_Begin;
1796 Write_Indent_Str_Sloc ("do ");
1797 Indent_Begin;
1798 Sprint_Node_List (Actions (Node));
1799 Indent_End;
1800 Write_Indent;
1801 Write_Str_With_Col_Check_Sloc ("in ");
1802 Sprint_Node (Expression (Node));
1803 Write_Str_With_Col_Check (" end");
1804 Indent_End;
1805 Write_Indent;
1807 when N_Expression_Function =>
1808 Write_Indent;
1809 Sprint_Node_Sloc (Specification (Node));
1810 Write_Str (" is");
1811 Indent_Begin;
1812 Write_Indent;
1813 Sprint_Node (Expression (Node));
1814 Write_Char (';');
1815 Indent_End;
1817 when N_Extended_Return_Statement =>
1818 Write_Indent_Str_Sloc ("return ");
1819 Sprint_Node_List (Return_Object_Declarations (Node));
1821 if Present (Handled_Statement_Sequence (Node)) then
1822 Write_Str_With_Col_Check (" do");
1823 Sprint_Node (Handled_Statement_Sequence (Node));
1824 Write_Indent_Str ("end return");
1825 end if;
1827 if Present (Storage_Pool (Node)) then
1828 Write_Str_With_Col_Check ("[storage_pool = ");
1829 Sprint_Node (Storage_Pool (Node));
1830 Write_Char (']');
1831 end if;
1833 if Present (Procedure_To_Call (Node)) then
1834 Write_Str_With_Col_Check ("[procedure_to_call = ");
1835 Sprint_Node (Procedure_To_Call (Node));
1836 Write_Char (']');
1837 end if;
1839 Write_Char (';');
1841 when N_Delta_Aggregate =>
1842 Write_Str_With_Col_Check_Sloc ("(");
1843 Sprint_Node (Expression (Node));
1844 Write_Str_With_Col_Check (" with delta ");
1845 Sprint_Comma_List (Component_Associations (Node));
1846 Write_Char (')');
1848 when N_Extension_Aggregate =>
1849 Write_Str_With_Col_Check_Sloc ("(");
1850 Sprint_Node (Ancestor_Part (Node));
1851 Write_Str_With_Col_Check (" with ");
1853 if Null_Record_Present (Node) then
1854 Write_Str_With_Col_Check ("null record");
1855 else
1856 if Present (Expressions (Node)) then
1857 Sprint_Comma_List (Expressions (Node));
1859 if Present (Component_Associations (Node)) then
1860 Write_Str (", ");
1861 end if;
1862 end if;
1864 if Present (Component_Associations (Node)) then
1865 Sprint_Comma_List (Component_Associations (Node));
1866 end if;
1867 end if;
1869 Write_Char (')');
1871 when N_Floating_Point_Definition =>
1872 Write_Str_With_Col_Check_Sloc ("digits ");
1873 Sprint_Node (Digits_Expression (Node));
1874 Sprint_Opt_Node (Real_Range_Specification (Node));
1876 when N_Formal_Decimal_Fixed_Point_Definition =>
1877 Write_Str_With_Col_Check_Sloc ("delta <> digits <>");
1879 when N_Formal_Derived_Type_Definition =>
1880 Write_Str_With_Col_Check_Sloc ("new ");
1881 Sprint_Node (Subtype_Mark (Node));
1883 if Present (Interface_List (Node)) then
1884 Write_Str_With_Col_Check (" and ");
1885 Sprint_And_List (Interface_List (Node));
1886 end if;
1888 if Private_Present (Node) then
1889 Write_Str_With_Col_Check (" with private");
1890 end if;
1892 when N_Formal_Abstract_Subprogram_Declaration =>
1893 Write_Indent_Str_Sloc ("with ");
1894 Sprint_Node (Specification (Node));
1896 Write_Str_With_Col_Check (" is abstract");
1898 if Box_Present (Node) then
1899 Write_Str_With_Col_Check (" <>");
1900 elsif Present (Default_Name (Node)) then
1901 Write_Str_With_Col_Check (" ");
1902 Sprint_Node (Default_Name (Node));
1903 end if;
1905 Write_Char (';');
1907 when N_Formal_Concrete_Subprogram_Declaration =>
1908 Write_Indent_Str_Sloc ("with ");
1909 Sprint_Node (Specification (Node));
1911 if Box_Present (Node) then
1912 Write_Str_With_Col_Check (" is <>");
1913 elsif Present (Default_Name (Node)) then
1914 Write_Str_With_Col_Check (" is ");
1915 Sprint_Node (Default_Name (Node));
1916 end if;
1918 Write_Char (';');
1920 when N_Formal_Discrete_Type_Definition =>
1921 Write_Str_With_Col_Check_Sloc ("<>");
1923 when N_Formal_Floating_Point_Definition =>
1924 Write_Str_With_Col_Check_Sloc ("digits <>");
1926 when N_Formal_Modular_Type_Definition =>
1927 Write_Str_With_Col_Check_Sloc ("mod <>");
1929 when N_Formal_Object_Declaration =>
1930 Set_Debug_Sloc;
1932 if Write_Indent_Identifiers (Node) then
1933 Write_Str (" : ");
1935 if In_Present (Node) then
1936 Write_Str_With_Col_Check ("in ");
1937 end if;
1939 if Out_Present (Node) then
1940 Write_Str_With_Col_Check ("out ");
1941 end if;
1943 if Present (Subtype_Mark (Node)) then
1945 -- Ada 2005 (AI-423): Formal object with null exclusion
1947 if Null_Exclusion_Present (Node) then
1948 Write_Str ("not null ");
1949 end if;
1951 Sprint_Node (Subtype_Mark (Node));
1953 -- Ada 2005 (AI-423): Formal object with access definition
1955 else
1956 pragma Assert (Present (Access_Definition (Node)));
1958 Sprint_Node (Access_Definition (Node));
1959 end if;
1961 if Present (Default_Expression (Node)) then
1962 Write_Str (" := ");
1963 Sprint_Node (Default_Expression (Node));
1964 end if;
1966 Write_Char (';');
1967 end if;
1969 when N_Formal_Ordinary_Fixed_Point_Definition =>
1970 Write_Str_With_Col_Check_Sloc ("delta <>");
1972 when N_Formal_Package_Declaration =>
1973 Write_Indent_Str_Sloc ("with package ");
1974 Write_Id (Defining_Identifier (Node));
1975 Write_Str_With_Col_Check (" is new ");
1976 Sprint_Node (Name (Node));
1977 Write_Str_With_Col_Check (" (<>);");
1979 when N_Formal_Private_Type_Definition =>
1980 if Abstract_Present (Node) then
1981 Write_Str_With_Col_Check ("abstract ");
1982 end if;
1984 if Tagged_Present (Node) then
1985 Write_Str_With_Col_Check ("tagged ");
1986 end if;
1988 if Limited_Present (Node) then
1989 Write_Str_With_Col_Check ("limited ");
1990 end if;
1992 Write_Str_With_Col_Check_Sloc ("private");
1994 when N_Formal_Incomplete_Type_Definition =>
1995 if Tagged_Present (Node) then
1996 Write_Str_With_Col_Check ("is tagged ");
1997 end if;
1999 when N_Formal_Signed_Integer_Type_Definition =>
2000 Write_Str_With_Col_Check_Sloc ("range <>");
2002 when N_Formal_Type_Declaration =>
2003 Write_Indent_Str_Sloc ("type ");
2004 Write_Id (Defining_Identifier (Node));
2006 if Present (Discriminant_Specifications (Node)) then
2007 Write_Discr_Specs (Node);
2008 elsif Unknown_Discriminants_Present (Node) then
2009 Write_Str_With_Col_Check ("(<>)");
2010 end if;
2012 if Nkind (Formal_Type_Definition (Node)) /=
2013 N_Formal_Incomplete_Type_Definition
2014 then
2015 Write_Str_With_Col_Check (" is ");
2016 end if;
2018 Sprint_Node (Formal_Type_Definition (Node));
2019 Write_Char (';');
2021 when N_Free_Statement =>
2022 Write_Indent_Str_Sloc ("free ");
2023 Sprint_Node (Expression (Node));
2025 if Present (Storage_Pool (Node)) then
2026 Write_Str_With_Col_Check ("[storage_pool = ");
2027 Sprint_Node (Storage_Pool (Node));
2028 Write_Char (']');
2029 end if;
2031 if Present (Procedure_To_Call (Node)) then
2032 Write_Str_With_Col_Check ("[procedure_to_call = ");
2033 Sprint_Node (Procedure_To_Call (Node));
2034 Write_Char (']');
2035 end if;
2037 Write_Char (';');
2039 when N_Freeze_Entity =>
2040 if Dump_Original_Only then
2041 null;
2043 -- A freeze node is output if it has some effect (i.e. non-empty
2044 -- actions, or freeze node for an itype, which causes elaboration
2045 -- of the itype), and is also always output if Dump_Freeze_Null
2046 -- is set True.
2048 elsif Present (Actions (Node))
2049 or else Is_Itype (Entity (Node))
2050 or else Dump_Freeze_Null
2051 then
2052 Write_Indent;
2053 Write_Rewrite_Str ("<<<");
2054 Write_Str_With_Col_Check_Sloc ("freeze ");
2055 Write_Id (Entity (Node));
2056 Write_Str (" [");
2058 if No (Actions (Node)) then
2059 Write_Char (']');
2061 else
2062 -- Output freeze actions. We increment Freeze_Indent during
2063 -- this output to avoid generating extra blank lines before
2064 -- any procedures included in the freeze actions.
2066 Freeze_Indent := Freeze_Indent + 1;
2067 Sprint_Indented_List (Actions (Node));
2068 Freeze_Indent := Freeze_Indent - 1;
2069 Write_Indent_Str ("]");
2070 end if;
2072 Write_Rewrite_Str (">>>");
2073 end if;
2075 when N_Freeze_Generic_Entity =>
2076 if Dump_Original_Only then
2077 null;
2079 else
2080 Write_Indent;
2081 Write_Str_With_Col_Check_Sloc ("freeze_generic ");
2082 Write_Id (Entity (Node));
2083 end if;
2085 when N_Full_Type_Declaration =>
2086 Write_Indent_Str_Sloc ("type ");
2087 Sprint_Node (Defining_Identifier (Node));
2088 Write_Discr_Specs (Node);
2089 Write_Str_With_Col_Check (" is ");
2090 Sprint_Node (Type_Definition (Node));
2091 Write_Char (';');
2093 when N_Function_Call =>
2094 Set_Debug_Sloc;
2095 Write_Subprogram_Name (Name (Node));
2096 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
2098 when N_Function_Instantiation =>
2099 Write_Indent_Str_Sloc ("function ");
2100 Sprint_Node (Defining_Unit_Name (Node));
2101 Write_Str_With_Col_Check (" is new ");
2102 Sprint_Node (Name (Node));
2103 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
2104 Write_Char (';');
2106 when N_Function_Specification =>
2107 Write_Str_With_Col_Check_Sloc ("function ");
2108 Sprint_Node (Defining_Unit_Name (Node));
2109 Write_Param_Specs (Node);
2110 Write_Str_With_Col_Check (" return ");
2112 -- Ada 2005 (AI-231)
2114 if Nkind (Result_Definition (Node)) /= N_Access_Definition
2115 and then Null_Exclusion_Present (Node)
2116 then
2117 Write_Str (" not null ");
2118 end if;
2120 Sprint_Node (Result_Definition (Node));
2122 when N_Generic_Association =>
2123 Set_Debug_Sloc;
2125 if Present (Selector_Name (Node)) then
2126 Sprint_Node (Selector_Name (Node));
2127 Write_Str (" => ");
2128 end if;
2130 Sprint_Node (Explicit_Generic_Actual_Parameter (Node));
2132 when N_Generic_Function_Renaming_Declaration =>
2133 Write_Indent_Str_Sloc ("generic function ");
2134 Sprint_Node (Defining_Unit_Name (Node));
2135 Write_Str_With_Col_Check (" renames ");
2136 Sprint_Node (Name (Node));
2137 Write_Char (';');
2139 when N_Generic_Declaration =>
2140 Extra_Blank_Line;
2141 Write_Indent_Str_Sloc ("generic ");
2142 Sprint_Indented_List (Generic_Formal_Declarations (Node));
2143 Write_Indent;
2144 Sprint_Node (Specification (Node));
2145 Write_Char (';');
2147 when N_Generic_Package_Renaming_Declaration =>
2148 Write_Indent_Str_Sloc ("generic package ");
2149 Sprint_Node (Defining_Unit_Name (Node));
2150 Write_Str_With_Col_Check (" renames ");
2151 Sprint_Node (Name (Node));
2152 Write_Char (';');
2154 when N_Generic_Procedure_Renaming_Declaration =>
2155 Write_Indent_Str_Sloc ("generic procedure ");
2156 Sprint_Node (Defining_Unit_Name (Node));
2157 Write_Str_With_Col_Check (" renames ");
2158 Sprint_Node (Name (Node));
2159 Write_Char (';');
2161 when N_Goto_Statement =>
2162 Write_Indent_Str_Sloc ("goto ");
2163 Sprint_Node (Name (Node));
2164 Write_Char (';');
2166 if Nkind (Next (Node)) = N_Label then
2167 Write_Indent;
2168 end if;
2170 when N_Goto_When_Statement =>
2171 Write_Indent_Str_Sloc ("goto ");
2172 Sprint_Node (Name (Node));
2173 Write_Str (" when ");
2174 Sprint_Node (Condition (Node));
2175 Write_Char (';');
2177 when N_Handled_Sequence_Of_Statements =>
2178 Set_Debug_Sloc;
2179 Sprint_Indented_List (Statements (Node));
2181 if Present (Exception_Handlers (Node)) then
2182 Write_Indent_Str ("exception");
2183 Indent_Begin;
2184 Sprint_Node_List (Exception_Handlers (Node));
2185 Indent_End;
2186 end if;
2188 Sprint_At_End_Proc (Node);
2190 when N_Identifier =>
2191 Set_Debug_Sloc;
2192 Write_Id (Node);
2194 when N_If_Expression =>
2195 declare
2196 Has_Parens : constant Boolean := Paren_Count (Node) > 0;
2197 Condition : constant Node_Id := First (Expressions (Node));
2198 Then_Expr : constant Node_Id := Next (Condition);
2200 begin
2201 -- The syntax for if_expression does not include parentheses,
2202 -- but sometimes parentheses are required, so unconditionally
2203 -- generate them here unless already present.
2205 if not Has_Parens then
2206 Write_Char ('(');
2207 end if;
2209 Write_Str_With_Col_Check_Sloc ("if ");
2210 Sprint_Node (Condition);
2211 Write_Str_With_Col_Check (" then ");
2213 -- Defense against junk here
2215 if Present (Then_Expr) then
2216 Sprint_Node (Then_Expr);
2218 if Present (Next (Then_Expr)) then
2219 Write_Str_With_Col_Check (" else ");
2220 Sprint_Node (Next (Then_Expr));
2221 end if;
2222 end if;
2224 if not Has_Parens then
2225 Write_Char (')');
2226 end if;
2227 end;
2229 when N_If_Statement =>
2230 Write_Indent_Str_Sloc ("if ");
2231 Sprint_Node (Condition (Node));
2232 Write_Str_With_Col_Check (" then");
2233 Sprint_Indented_List (Then_Statements (Node));
2234 Sprint_Opt_Node_List (Elsif_Parts (Node));
2236 if Present (Else_Statements (Node)) then
2237 Write_Indent_Str ("else");
2238 Sprint_Indented_List (Else_Statements (Node));
2239 end if;
2241 Write_Indent_Str ("end if;");
2243 when N_Implicit_Label_Declaration =>
2244 if not Dump_Original_Only then
2245 Write_Indent;
2246 Write_Rewrite_Str ("<<<");
2247 Set_Debug_Sloc;
2248 Write_Id (Defining_Identifier (Node));
2249 Write_Str (" : ");
2250 Write_Str_With_Col_Check ("label");
2251 Write_Rewrite_Str (">>>");
2252 end if;
2254 when N_In =>
2255 Sprint_Left_Opnd (Node);
2256 Write_Str_Sloc (" in ");
2258 if Present (Right_Opnd (Node)) then
2259 Sprint_Right_Opnd (Node);
2260 else
2261 Sprint_Bar_List (Alternatives (Node));
2262 end if;
2264 when N_Incomplete_Type_Declaration =>
2265 Write_Indent_Str_Sloc ("type ");
2266 Write_Id (Defining_Identifier (Node));
2268 if Present (Discriminant_Specifications (Node)) then
2269 Write_Discr_Specs (Node);
2270 elsif Unknown_Discriminants_Present (Node) then
2271 Write_Str_With_Col_Check ("(<>)");
2272 end if;
2274 Write_Char (';');
2276 when N_Index_Or_Discriminant_Constraint =>
2277 Set_Debug_Sloc;
2278 Sprint_Paren_Comma_List (Constraints (Node));
2280 when N_Indexed_Component =>
2281 Sprint_Node_Sloc (Prefix (Node));
2282 Sprint_Opt_Paren_Comma_List (Expressions (Node));
2284 when N_Integer_Literal =>
2285 if Print_In_Hex (Node) then
2286 Write_Uint_With_Col_Check_Sloc (Intval (Node), Hex);
2287 else
2288 Write_Uint_With_Col_Check_Sloc (Intval (Node), Auto);
2289 end if;
2291 when N_Iteration_Scheme =>
2292 if Present (Condition (Node)) then
2293 Write_Str_With_Col_Check_Sloc ("while ");
2294 Sprint_Node (Condition (Node));
2295 else
2296 Write_Str_With_Col_Check_Sloc ("for ");
2298 if Present (Iterator_Specification (Node)) then
2299 Sprint_Node (Iterator_Specification (Node));
2300 else
2301 Sprint_Node (Loop_Parameter_Specification (Node));
2302 end if;
2303 end if;
2305 Write_Char (' ');
2307 when N_Iterator_Specification =>
2308 Set_Debug_Sloc;
2309 Write_Id (Defining_Identifier (Node));
2311 if Present (Subtype_Indication (Node)) then
2312 Write_Str_With_Col_Check (" : ");
2313 Sprint_Node (Subtype_Indication (Node));
2314 end if;
2316 if Of_Present (Node) then
2317 Write_Str_With_Col_Check (" of ");
2318 else
2319 Write_Str_With_Col_Check (" in ");
2320 end if;
2322 if Reverse_Present (Node) then
2323 Write_Str_With_Col_Check ("reverse ");
2324 end if;
2326 Sprint_Node (Name (Node));
2328 if Present (Iterator_Filter (Node)) then
2329 Write_Str (" when ");
2330 Sprint_Node (Iterator_Filter (Node));
2331 end if;
2333 when N_Itype_Reference =>
2334 Write_Indent_Str_Sloc ("reference ");
2335 Write_Id (Itype (Node));
2337 when N_Label =>
2338 Write_Indent_Str_Sloc ("<<");
2339 Write_Id (Identifier (Node));
2340 Write_Str (">>");
2342 when N_Loop_Parameter_Specification =>
2343 Set_Debug_Sloc;
2344 Write_Id (Defining_Identifier (Node));
2345 Write_Str_With_Col_Check (" in ");
2347 if Reverse_Present (Node) then
2348 Write_Str_With_Col_Check ("reverse ");
2349 end if;
2351 Sprint_Node (Discrete_Subtype_Definition (Node));
2353 when N_Loop_Statement =>
2354 Write_Indent;
2356 if Present (Identifier (Node))
2357 and then (not Has_Created_Identifier (Node)
2358 or else not Dump_Original_Only)
2359 then
2360 Write_Rewrite_Str ("<<<");
2361 Write_Id (Identifier (Node));
2362 Write_Str (" : ");
2363 Write_Rewrite_Str (">>>");
2364 Sprint_Node (Iteration_Scheme (Node));
2365 Write_Str_With_Col_Check_Sloc ("loop");
2366 Sprint_Indented_List (Statements (Node));
2367 Write_Indent_Str ("end loop ");
2368 Write_Rewrite_Str ("<<<");
2369 Write_Id (Identifier (Node));
2370 Write_Rewrite_Str (">>>");
2371 Write_Char (';');
2373 else
2374 Sprint_Node (Iteration_Scheme (Node));
2375 Write_Str_With_Col_Check_Sloc ("loop");
2376 Sprint_Indented_List (Statements (Node));
2377 Write_Indent_Str ("end loop;");
2378 end if;
2380 when N_Mod_Clause =>
2381 Sprint_Node_List (Pragmas_Before (Node));
2382 Write_Str_With_Col_Check_Sloc ("at mod ");
2383 Sprint_Node (Expression (Node));
2385 when N_Modular_Type_Definition =>
2386 Write_Str_With_Col_Check_Sloc ("mod ");
2387 Sprint_Node (Expression (Node));
2389 when N_Not_In =>
2390 Sprint_Left_Opnd (Node);
2391 Write_Str_Sloc (" not in ");
2393 if Present (Right_Opnd (Node)) then
2394 Sprint_Right_Opnd (Node);
2395 else
2396 Sprint_Bar_List (Alternatives (Node));
2397 end if;
2399 when N_Null =>
2400 Write_Str_With_Col_Check_Sloc ("null");
2402 when N_Null_Statement =>
2403 if Comes_From_Source (Node)
2404 or else Dump_Freeze_Null
2405 or else not Is_List_Member (Node)
2406 or else (No (Prev (Node)) and then No (Next (Node)))
2407 then
2408 Write_Indent_Str_Sloc ("null;");
2409 end if;
2411 when N_Number_Declaration =>
2412 Set_Debug_Sloc;
2414 if Write_Indent_Identifiers (Node) then
2415 Write_Str_With_Col_Check (" : constant ");
2416 Write_Str (" := ");
2417 Sprint_Node (Expression (Node));
2418 Write_Char (';');
2419 end if;
2421 when N_Object_Declaration =>
2422 Set_Debug_Sloc;
2424 if Write_Indent_Identifiers (Node) then
2425 declare
2426 Def_Id : constant Entity_Id := Defining_Identifier (Node);
2428 begin
2429 Write_Str_With_Col_Check (" : ");
2431 if Is_Statically_Allocated (Def_Id) then
2432 Write_Str_With_Col_Check ("static ");
2433 end if;
2435 if Aliased_Present (Node) then
2436 Write_Str_With_Col_Check ("aliased ");
2437 end if;
2439 if Constant_Present (Node) then
2440 Write_Str_With_Col_Check ("constant ");
2441 end if;
2443 -- Ada 2005 (AI-231)
2445 if Null_Exclusion_Present (Node) then
2446 Write_Str_With_Col_Check ("not null ");
2447 end if;
2449 -- Print type. We used to print the Object_Definition from
2450 -- the node, but it is much more useful to print the Etype
2451 -- of the defining identifier for the case where the nominal
2452 -- type is an unconstrained array type. For example, this
2453 -- will be a clear reference to the Itype with the bounds
2454 -- in the case of a type like String. The object after
2455 -- all is constrained, even if its nominal subtype is
2456 -- unconstrained.
2458 declare
2459 Odef : constant Node_Id := Object_Definition (Node);
2461 begin
2462 if Nkind (Odef) = N_Identifier
2463 and then Present (Etype (Odef))
2464 and then Is_Array_Type (Etype (Odef))
2465 and then not Is_Constrained (Etype (Odef))
2466 and then Present (Etype (Def_Id))
2467 then
2468 Sprint_Node (Etype (Def_Id));
2470 -- In other cases, the nominal type is fine to print
2472 else
2473 Sprint_Node (Odef);
2474 end if;
2475 end;
2477 if Present (Expression (Node))
2478 and then Expression (Node) /= Error
2479 and then not No_Initialization (Node)
2480 then
2481 Write_Str (" := ");
2482 Sprint_Node (Expression (Node));
2483 end if;
2485 Write_Char (';');
2487 -- Handle implicit importation and implicit exportation of
2488 -- object declarations:
2489 -- $pragma import (Convention_Id, Def_Id, "...");
2490 -- $pragma export (Convention_Id, Def_Id, "...");
2492 if Is_Internal (Def_Id)
2493 and then Present (Interface_Name (Def_Id))
2494 then
2495 Write_Indent_Str_Sloc ("$pragma ");
2497 if Is_Imported (Def_Id) then
2498 Write_Str ("import (");
2500 else pragma Assert (Is_Exported (Def_Id));
2501 Write_Str ("export (");
2502 end if;
2504 declare
2505 Prefix : constant String := "Convention_";
2506 S : constant String := Convention (Def_Id)'Img;
2508 begin
2509 Name_Len := S'Last - Prefix'Last;
2510 Name_Buffer (1 .. Name_Len) :=
2511 S (Prefix'Last + 1 .. S'Last);
2512 Set_Casing (All_Lower_Case);
2513 Write_Str (Name_Buffer (1 .. Name_Len));
2514 end;
2516 Write_Str (", ");
2517 Write_Id (Def_Id);
2518 Write_Str (", ");
2519 Write_String_Table_Entry
2520 (Strval (Interface_Name (Def_Id)));
2521 Write_Str (");");
2522 end if;
2523 end;
2524 end if;
2526 when N_Object_Renaming_Declaration =>
2527 Write_Indent;
2528 Set_Debug_Sloc;
2529 Sprint_Node (Defining_Identifier (Node));
2531 -- Ada 2005 (AI-230): Access renamings
2533 if Present (Access_Definition (Node)) then
2534 Write_Str (" : ");
2535 Sprint_Node (Access_Definition (Node));
2537 elsif Present (Subtype_Mark (Node)) then
2538 Write_Str (" : ");
2540 -- Ada 2005 (AI-423): Object renaming with a null exclusion
2542 if Null_Exclusion_Present (Node) then
2543 Write_Str ("not null ");
2544 end if;
2546 Sprint_Node (Subtype_Mark (Node));
2548 -- AI12-0275: Object_Renaming_Declaration without explicit subtype
2550 elsif Ada_Version >= Ada_2022 then
2551 null;
2553 else
2554 Write_Str (" : ??? ");
2555 end if;
2557 Write_Str_With_Col_Check (" renames ");
2558 Sprint_Node (Name (Node));
2559 Write_Char (';');
2561 when N_Op_Abs =>
2562 Write_Operator (Node, "abs ");
2563 Sprint_Right_Opnd (Node);
2565 when N_Op_Add =>
2566 Sprint_Left_Opnd (Node);
2567 Write_Operator (Node, " + ");
2568 Sprint_Right_Opnd (Node);
2570 when N_Op_And =>
2571 Sprint_Left_Opnd (Node);
2572 Write_Operator (Node, " and ");
2573 Sprint_Right_Opnd (Node);
2575 when N_Op_Concat =>
2576 Sprint_Left_Opnd (Node);
2577 Write_Operator (Node, " & ");
2578 Sprint_Right_Opnd (Node);
2580 when N_Op_Divide =>
2581 Sprint_Left_Opnd (Node);
2582 Write_Char (' ');
2583 if Rounded_Result (Node) then
2584 Write_Char ('@');
2585 end if;
2586 Write_Operator (Node, "/ ");
2587 Sprint_Right_Opnd (Node);
2589 when N_Op_Eq =>
2590 Sprint_Left_Opnd (Node);
2591 Write_Operator (Node, " = ");
2592 Sprint_Right_Opnd (Node);
2594 when N_Op_Expon =>
2595 Sprint_Left_Opnd (Node);
2596 Write_Operator (Node, " ** ");
2597 Sprint_Right_Opnd (Node);
2599 when N_Op_Ge =>
2600 Sprint_Left_Opnd (Node);
2601 Write_Operator (Node, " >= ");
2602 Sprint_Right_Opnd (Node);
2604 when N_Op_Gt =>
2605 Sprint_Left_Opnd (Node);
2606 Write_Operator (Node, " > ");
2607 Sprint_Right_Opnd (Node);
2609 when N_Op_Le =>
2610 Sprint_Left_Opnd (Node);
2611 Write_Operator (Node, " <= ");
2612 Sprint_Right_Opnd (Node);
2614 when N_Op_Lt =>
2615 Sprint_Left_Opnd (Node);
2616 Write_Operator (Node, " < ");
2617 Sprint_Right_Opnd (Node);
2619 when N_Op_Minus =>
2620 Write_Operator (Node, "-");
2621 Sprint_Right_Opnd (Node);
2623 when N_Op_Mod =>
2624 Sprint_Left_Opnd (Node);
2625 Write_Operator (Node, " mod ");
2626 Sprint_Right_Opnd (Node);
2628 when N_Op_Multiply =>
2629 Sprint_Left_Opnd (Node);
2630 Write_Char (' ');
2631 if Rounded_Result (Node) then
2632 Write_Char ('@');
2633 end if;
2634 Write_Operator (Node, "* ");
2635 Sprint_Right_Opnd (Node);
2637 when N_Op_Ne =>
2638 Sprint_Left_Opnd (Node);
2639 Write_Operator (Node, " /= ");
2640 Sprint_Right_Opnd (Node);
2642 when N_Op_Not =>
2643 Write_Operator (Node, "not ");
2644 Sprint_Right_Opnd (Node);
2646 when N_Op_Or =>
2647 Sprint_Left_Opnd (Node);
2648 Write_Operator (Node, " or ");
2649 Sprint_Right_Opnd (Node);
2651 when N_Op_Plus =>
2652 Write_Operator (Node, "+");
2653 Sprint_Right_Opnd (Node);
2655 when N_Op_Rem =>
2656 Sprint_Left_Opnd (Node);
2657 Write_Operator (Node, " rem ");
2658 Sprint_Right_Opnd (Node);
2660 when N_Op_Shift =>
2661 Set_Debug_Sloc;
2662 Write_Id (Node);
2663 Write_Char ('!');
2664 Write_Str_With_Col_Check ("(");
2665 Sprint_Node (Left_Opnd (Node));
2666 Write_Str (", ");
2667 Sprint_Node (Right_Opnd (Node));
2668 Write_Char (')');
2670 when N_Op_Subtract =>
2671 Sprint_Left_Opnd (Node);
2672 Write_Operator (Node, " - ");
2673 Sprint_Right_Opnd (Node);
2675 when N_Op_Xor =>
2676 Sprint_Left_Opnd (Node);
2677 Write_Operator (Node, " xor ");
2678 Sprint_Right_Opnd (Node);
2680 when N_Operator_Symbol =>
2681 Write_Name_With_Col_Check_Sloc (Chars (Node));
2683 when N_Ordinary_Fixed_Point_Definition =>
2684 Write_Str_With_Col_Check_Sloc ("delta ");
2685 Sprint_Node (Delta_Expression (Node));
2686 Sprint_Opt_Node (Real_Range_Specification (Node));
2688 when N_Or_Else =>
2689 Sprint_Left_Opnd (Node);
2690 Write_Str_Sloc (" or else ");
2691 Sprint_Right_Opnd (Node);
2693 when N_Others_Choice =>
2694 if All_Others (Node) then
2695 Write_Str_With_Col_Check ("all ");
2696 end if;
2698 Write_Str_With_Col_Check_Sloc ("others");
2700 when N_Package_Body =>
2701 Extra_Blank_Line;
2702 Write_Indent_Str_Sloc ("package body ");
2703 Sprint_Node (Defining_Unit_Name (Node));
2704 Write_Str (" is");
2705 Sprint_Indented_List (Declarations (Node));
2707 if Present (Handled_Statement_Sequence (Node)) then
2708 Write_Indent_Str ("begin");
2709 Sprint_Node (Handled_Statement_Sequence (Node));
2710 end if;
2712 Write_Indent_Str ("end ");
2713 Sprint_End_Label
2714 (Handled_Statement_Sequence (Node), Defining_Unit_Name (Node));
2715 Write_Char (';');
2716 Sprint_At_End_Proc (Node);
2718 when N_Package_Body_Stub =>
2719 Write_Indent_Str_Sloc ("package body ");
2720 Sprint_Node (Defining_Identifier (Node));
2721 Write_Str_With_Col_Check (" is separate;");
2723 when N_Package_Declaration =>
2724 Extra_Blank_Line;
2725 Write_Indent;
2726 Sprint_Node_Sloc (Specification (Node));
2727 Write_Char (';');
2729 -- If this is an instantiation, get the aspects from the original
2730 -- instantiation node.
2732 if Is_Generic_Instance (Defining_Entity (Node))
2733 and then Has_Aspects
2734 (Package_Instantiation (Defining_Entity (Node)))
2735 then
2736 Sprint_Aspect_Specifications
2737 (Package_Instantiation (Defining_Entity (Node)),
2738 Semicolon => True);
2739 end if;
2741 when N_Package_Instantiation =>
2742 Extra_Blank_Line;
2743 Write_Indent_Str_Sloc ("package ");
2744 Sprint_Node (Defining_Unit_Name (Node));
2745 Write_Str (" is new ");
2746 Sprint_Node (Name (Node));
2747 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
2748 Write_Char (';');
2750 when N_Package_Renaming_Declaration =>
2751 Write_Indent_Str_Sloc ("package ");
2752 Sprint_Node (Defining_Unit_Name (Node));
2753 Write_Str_With_Col_Check (" renames ");
2754 Sprint_Node (Name (Node));
2755 Write_Char (';');
2757 when N_Package_Specification =>
2758 Write_Str_With_Col_Check_Sloc ("package ");
2759 Sprint_Node (Defining_Unit_Name (Node));
2761 if Nkind (Parent (Node)) = N_Generic_Package_Declaration
2762 and then Has_Aspects (Parent (Node))
2763 then
2764 Sprint_Aspect_Specifications
2765 (Parent (Node), Semicolon => False);
2767 -- An instantiation is rewritten as a package declaration, but
2768 -- the aspects belong to the instantiation node.
2770 elsif Nkind (Parent (Node)) = N_Package_Declaration then
2771 declare
2772 Pack : constant Entity_Id := Defining_Entity (Node);
2774 begin
2775 if not Is_Generic_Instance (Pack) then
2776 if Has_Aspects (Parent (Node)) then
2777 Sprint_Aspect_Specifications
2778 (Parent (Node), Semicolon => False);
2779 end if;
2780 end if;
2781 end;
2782 end if;
2784 Write_Str (" is");
2785 Sprint_Indented_List (Visible_Declarations (Node));
2787 if Present (Private_Declarations (Node)) then
2788 Write_Indent_Str ("private");
2789 Sprint_Indented_List (Private_Declarations (Node));
2790 end if;
2792 Write_Indent_Str ("end ");
2793 Sprint_Node (Defining_Unit_Name (Node));
2795 when N_Parameter_Association =>
2796 Sprint_Node_Sloc (Selector_Name (Node));
2797 Write_Str (" => ");
2798 Sprint_Node (Explicit_Actual_Parameter (Node));
2800 when N_Parameter_Specification =>
2801 Set_Debug_Sloc;
2803 if Write_Identifiers (Node) then
2804 Write_Str (" : ");
2806 if In_Present (Node) then
2807 Write_Str_With_Col_Check ("in ");
2808 end if;
2810 if Out_Present (Node) then
2811 Write_Str_With_Col_Check ("out ");
2812 end if;
2814 -- Ada 2005 (AI-231): Parameter specification may carry null
2815 -- exclusion. Do not print it now if this is an access formal,
2816 -- it is emitted when the access definition is displayed.
2818 if Null_Exclusion_Present (Node)
2819 and then Nkind (Parameter_Type (Node)) /= N_Access_Definition
2820 then
2821 Write_Str ("not null ");
2822 end if;
2824 if Aliased_Present (Node) then
2825 Write_Str ("aliased ");
2826 end if;
2828 Sprint_Node (Parameter_Type (Node));
2830 if Present (Expression (Node)) then
2831 Write_Str (" := ");
2832 Sprint_Node (Expression (Node));
2833 end if;
2834 else
2835 Write_Str (", ");
2836 end if;
2838 when N_Pop_Constraint_Error_Label =>
2839 Write_Indent_Str ("%pop_constraint_error_label");
2841 when N_Pop_Program_Error_Label =>
2842 Write_Indent_Str ("%pop_program_error_label");
2844 when N_Pop_Storage_Error_Label =>
2845 Write_Indent_Str ("%pop_storage_error_label");
2847 when N_Private_Extension_Declaration =>
2848 Write_Indent_Str_Sloc ("type ");
2849 Write_Id (Defining_Identifier (Node));
2851 if Present (Discriminant_Specifications (Node)) then
2852 Write_Discr_Specs (Node);
2853 elsif Unknown_Discriminants_Present (Node) then
2854 Write_Str_With_Col_Check ("(<>)");
2855 end if;
2857 Write_Str_With_Col_Check (" is new ");
2858 Sprint_Node (Subtype_Indication (Node));
2860 if Present (Interface_List (Node)) then
2861 Write_Str_With_Col_Check (" and ");
2862 Sprint_And_List (Interface_List (Node));
2863 end if;
2865 Write_Str_With_Col_Check (" with private;");
2867 when N_Private_Type_Declaration =>
2868 Write_Indent_Str_Sloc ("type ");
2869 Write_Id (Defining_Identifier (Node));
2871 if Present (Discriminant_Specifications (Node)) then
2872 Write_Discr_Specs (Node);
2873 elsif Unknown_Discriminants_Present (Node) then
2874 Write_Str_With_Col_Check ("(<>)");
2875 end if;
2877 Write_Str (" is ");
2879 if Tagged_Present (Node) then
2880 Write_Str_With_Col_Check ("tagged ");
2881 end if;
2883 if Limited_Present (Node) then
2884 Write_Str_With_Col_Check ("limited ");
2885 end if;
2887 Write_Str_With_Col_Check ("private;");
2889 when N_Push_Constraint_Error_Label =>
2890 Write_Indent_Str ("%push_constraint_error_label (");
2892 if Present (Exception_Label (Node)) then
2893 Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2894 end if;
2896 Write_Str (")");
2898 when N_Push_Program_Error_Label =>
2899 Write_Indent_Str ("%push_program_error_label (");
2901 if Present (Exception_Label (Node)) then
2902 Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2903 end if;
2905 Write_Str (")");
2907 when N_Push_Storage_Error_Label =>
2908 Write_Indent_Str ("%push_storage_error_label (");
2910 if Present (Exception_Label (Node)) then
2911 Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2912 end if;
2914 Write_Str (")");
2916 when N_Pragma =>
2917 Write_Indent_Str_Sloc ("pragma ");
2918 Write_Name_With_Col_Check (Pragma_Name_Unmapped (Node));
2920 if Present (Pragma_Argument_Associations (Node)) then
2921 Sprint_Opt_Paren_Comma_List
2922 (Pragma_Argument_Associations (Node));
2923 end if;
2925 Write_Char (';');
2927 when N_Pragma_Argument_Association =>
2928 Set_Debug_Sloc;
2930 if Chars (Node) /= No_Name then
2931 Write_Name_With_Col_Check (Chars (Node));
2932 Write_Str (" => ");
2933 end if;
2935 Sprint_Node (Expression (Node));
2937 when N_Procedure_Call_Statement =>
2938 Write_Indent;
2939 Set_Debug_Sloc;
2940 Write_Subprogram_Name (Name (Node));
2941 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
2942 Write_Char (';');
2944 when N_Procedure_Instantiation =>
2945 Write_Indent_Str_Sloc ("procedure ");
2946 Sprint_Node (Defining_Unit_Name (Node));
2947 Write_Str_With_Col_Check (" is new ");
2948 Sprint_Node (Name (Node));
2949 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
2950 Write_Char (';');
2952 when N_Procedure_Specification =>
2953 Write_Str_With_Col_Check_Sloc ("procedure ");
2954 Sprint_Node (Defining_Unit_Name (Node));
2955 Write_Param_Specs (Node);
2957 when N_Protected_Body =>
2958 Write_Indent_Str_Sloc ("protected body ");
2959 Write_Id (Defining_Identifier (Node));
2960 Write_Str (" is");
2961 Sprint_Indented_List (Declarations (Node));
2962 Write_Indent_Str ("end ");
2963 Write_Id (Defining_Identifier (Node));
2964 Write_Char (';');
2966 when N_Protected_Body_Stub =>
2967 Write_Indent_Str_Sloc ("protected body ");
2968 Write_Id (Defining_Identifier (Node));
2969 Write_Str_With_Col_Check (" is separate;");
2971 when N_Protected_Definition =>
2972 Set_Debug_Sloc;
2973 Sprint_Indented_List (Visible_Declarations (Node));
2975 if Present (Private_Declarations (Node)) then
2976 Write_Indent_Str ("private");
2977 Sprint_Indented_List (Private_Declarations (Node));
2978 end if;
2980 Write_Indent_Str ("end ");
2982 when N_Protected_Type_Declaration =>
2983 Write_Indent_Str_Sloc ("protected type ");
2984 Sprint_Node (Defining_Identifier (Node));
2985 Write_Discr_Specs (Node);
2987 if Present (Interface_List (Node)) then
2988 Write_Str (" is new ");
2989 Sprint_And_List (Interface_List (Node));
2990 Write_Str (" with ");
2991 else
2992 Write_Str (" is");
2993 end if;
2995 Sprint_Node (Protected_Definition (Node));
2996 Write_Id (Defining_Identifier (Node));
2997 Write_Char (';');
2999 when N_Qualified_Expression =>
3000 Sprint_Node (Subtype_Mark (Node));
3001 Write_Char_Sloc (''');
3003 -- Print expression, make sure we have at least one level of
3004 -- parentheses around the expression. For cases of qualified
3005 -- expressions in the source, this is always the case, but
3006 -- for generated qualifications, there may be no explicit
3007 -- parentheses present.
3009 if Paren_Count (Expression (Node)) /= 0 then
3010 Sprint_Node (Expression (Node));
3012 else
3013 Write_Char ('(');
3014 Sprint_Node (Expression (Node));
3016 -- Odd case, for the qualified expressions used in machine
3017 -- code the argument may be a procedure call, resulting in
3018 -- a junk semicolon before the right parent, get rid of it.
3020 Write_Erase_Char (';');
3022 -- Now we can add the terminating right paren
3024 Write_Char (')');
3025 end if;
3027 when N_Quantified_Expression =>
3028 Write_Str (" for");
3030 if All_Present (Node) then
3031 Write_Str (" all ");
3032 else
3033 Write_Str (" some ");
3034 end if;
3036 if Present (Iterator_Specification (Node)) then
3037 Sprint_Node (Iterator_Specification (Node));
3038 else
3039 Sprint_Node (Loop_Parameter_Specification (Node));
3040 end if;
3042 Write_Str (" => ");
3043 Sprint_Node (Condition (Node));
3045 when N_Raise_Expression =>
3046 declare
3047 Has_Parens : constant Boolean := Paren_Count (Node) > 0;
3049 begin
3050 -- The syntax for raise_expression does not include parentheses
3051 -- but sometimes parentheses are required, so unconditionally
3052 -- generate them here unless already present.
3054 if not Has_Parens then
3055 Write_Char ('(');
3056 end if;
3058 Write_Str_With_Col_Check_Sloc ("raise ");
3059 Sprint_Node (Name (Node));
3061 if Present (Expression (Node)) then
3062 Write_Str_With_Col_Check (" with ");
3063 Sprint_Node (Expression (Node));
3064 end if;
3066 if not Has_Parens then
3067 Write_Char (')');
3068 end if;
3069 end;
3071 when N_Raise_Constraint_Error =>
3073 -- This node can be used either as a subexpression or as a
3074 -- statement form. The following test is a reasonably reliable
3075 -- way to distinguish the two cases.
3077 if Is_List_Member (Node)
3078 and then Nkind (Parent (Node)) not in N_Subexpr
3079 then
3080 Write_Indent;
3081 end if;
3083 Write_Str_With_Col_Check_Sloc ("[constraint_error");
3084 Write_Condition_And_Reason (Node);
3086 when N_Raise_Program_Error =>
3088 -- This node can be used either as a subexpression or as a
3089 -- statement form. The following test is a reasonably reliable
3090 -- way to distinguish the two cases.
3092 if Is_List_Member (Node)
3093 and then Nkind (Parent (Node)) not in N_Subexpr
3094 then
3095 Write_Indent;
3096 end if;
3098 Write_Str_With_Col_Check_Sloc ("[program_error");
3099 Write_Condition_And_Reason (Node);
3101 when N_Raise_Storage_Error =>
3103 -- This node can be used either as a subexpression or as a
3104 -- statement form. The following test is a reasonably reliable
3105 -- way to distinguish the two cases.
3107 if Is_List_Member (Node)
3108 and then Nkind (Parent (Node)) not in N_Subexpr
3109 then
3110 Write_Indent;
3111 end if;
3113 Write_Str_With_Col_Check_Sloc ("[storage_error");
3114 Write_Condition_And_Reason (Node);
3116 when N_Raise_Statement =>
3117 Write_Indent_Str_Sloc ("raise ");
3118 Sprint_Node (Name (Node));
3120 if Present (Expression (Node)) then
3121 Write_Str_With_Col_Check_Sloc (" with ");
3122 Sprint_Node (Expression (Node));
3123 end if;
3125 Write_Char (';');
3127 when N_Raise_When_Statement =>
3128 Write_Indent_Str_Sloc ("raise ");
3129 Sprint_Node (Name (Node));
3130 Write_Str (" when ");
3131 Sprint_Node (Condition (Node));
3133 if Present (Expression (Node)) then
3134 Write_Str_With_Col_Check_Sloc (" with ");
3135 Sprint_Node (Expression (Node));
3136 end if;
3138 Write_Char (';');
3140 when N_Range =>
3141 Sprint_Node (Low_Bound (Node));
3142 Write_Str_Sloc (" .. ");
3143 if Present (Etype (Node))
3144 and then Is_Fixed_Lower_Bound_Index_Subtype (Etype (Node))
3145 then
3146 Write_Str ("<>");
3147 else
3148 Sprint_Node (High_Bound (Node));
3149 end if;
3150 Update_Itype (Node);
3152 when N_Range_Constraint =>
3153 Write_Str_With_Col_Check_Sloc ("range ");
3154 Sprint_Node (Range_Expression (Node));
3156 when N_Real_Literal =>
3157 Write_Ureal_With_Col_Check_Sloc (Realval (Node));
3159 when N_Real_Range_Specification
3160 | N_Signed_Integer_Type_Definition
3162 Write_Str_With_Col_Check_Sloc ("range ");
3163 Sprint_Node (Low_Bound (Node));
3164 Write_Str (" .. ");
3165 Sprint_Node (High_Bound (Node));
3167 when N_Record_Definition =>
3168 if Abstract_Present (Node) then
3169 Write_Str_With_Col_Check ("abstract ");
3170 end if;
3172 if Tagged_Present (Node) then
3173 Write_Str_With_Col_Check ("tagged ");
3174 end if;
3176 if Limited_Present (Node) then
3177 Write_Str_With_Col_Check ("limited ");
3178 end if;
3180 if Null_Present (Node) then
3181 Write_Str_With_Col_Check_Sloc ("null record");
3183 else
3184 Write_Str_With_Col_Check_Sloc ("record");
3185 Sprint_Node (Component_List (Node));
3186 Write_Indent_Str ("end record");
3187 end if;
3189 when N_Record_Representation_Clause =>
3190 Write_Indent_Str_Sloc ("for ");
3191 Sprint_Node (Identifier (Node));
3192 Write_Str_With_Col_Check (" use record ");
3194 if Present (Mod_Clause (Node)) then
3195 Sprint_Node (Mod_Clause (Node));
3196 end if;
3198 Sprint_Indented_List (Component_Clauses (Node));
3199 Write_Indent_Str ("end record;");
3201 when N_Reference =>
3202 Sprint_Node (Prefix (Node));
3203 Write_Str_With_Col_Check_Sloc ("'reference");
3205 when N_Requeue_Statement =>
3206 Write_Indent_Str_Sloc ("requeue ");
3207 Sprint_Node (Name (Node));
3209 if Abort_Present (Node) then
3210 Write_Str_With_Col_Check (" with abort");
3211 end if;
3213 Write_Char (';');
3215 when N_Return_When_Statement =>
3216 Write_Indent_Str_Sloc ("return ");
3217 Sprint_Node (Expression (Node));
3218 Write_Str (" when ");
3219 Sprint_Node (Condition (Node));
3220 Write_Char (';');
3222 when N_SCIL_Dispatch_Table_Tag_Init =>
3223 Write_Indent_Str ("[N_SCIL_Dispatch_Table_Tag_Init]");
3225 when N_SCIL_Dispatching_Call =>
3226 Write_Indent_Str ("[N_SCIL_Dispatching_Node]");
3228 when N_SCIL_Membership_Test =>
3229 Write_Indent_Str ("[N_SCIL_Membership_Test]");
3231 when N_Simple_Return_Statement =>
3232 if Present (Expression (Node)) then
3233 Write_Indent_Str_Sloc ("return ");
3234 Sprint_Node (Expression (Node));
3235 else
3236 Write_Indent_Str_Sloc ("return");
3237 end if;
3239 if Present (Storage_Pool (Node)) then
3240 Write_Str_With_Col_Check ("[storage_pool = ");
3241 Sprint_Node (Storage_Pool (Node));
3242 Write_Char (']');
3243 end if;
3245 if Present (Procedure_To_Call (Node)) then
3246 Write_Str_With_Col_Check ("[procedure_to_call = ");
3247 Sprint_Node (Procedure_To_Call (Node));
3248 Write_Char (']');
3249 end if;
3251 Write_Char (';');
3253 when N_Selective_Accept =>
3254 Write_Indent_Str_Sloc ("select");
3256 declare
3257 Alt_Node : Node_Id;
3258 begin
3259 Alt_Node := First (Select_Alternatives (Node));
3260 loop
3261 Indent_Begin;
3262 Sprint_Node (Alt_Node);
3263 Indent_End;
3264 Next (Alt_Node);
3265 exit when No (Alt_Node);
3266 Write_Indent_Str ("or");
3267 end loop;
3268 end;
3270 if Present (Else_Statements (Node)) then
3271 Write_Indent_Str ("else");
3272 Sprint_Indented_List (Else_Statements (Node));
3273 end if;
3275 Write_Indent_Str ("end select;");
3277 when N_Single_Protected_Declaration =>
3278 Write_Indent_Str_Sloc ("protected ");
3279 Write_Id (Defining_Identifier (Node));
3280 Write_Str (" is");
3281 Sprint_Node (Protected_Definition (Node));
3282 Write_Id (Defining_Identifier (Node));
3283 Write_Char (';');
3285 when N_Single_Task_Declaration =>
3286 Write_Indent_Str_Sloc ("task ");
3287 Sprint_Node (Defining_Identifier (Node));
3289 if Present (Task_Definition (Node)) then
3290 Write_Str (" is");
3291 Sprint_Node (Task_Definition (Node));
3292 end if;
3294 Write_Char (';');
3296 when N_Selected_Component =>
3297 Sprint_Node (Prefix (Node));
3298 Write_Char_Sloc ('.');
3299 Sprint_Node (Selector_Name (Node));
3301 when N_Slice =>
3302 Set_Debug_Sloc;
3303 Sprint_Node (Prefix (Node));
3304 Write_Str_With_Col_Check (" (");
3305 Sprint_Node (Discrete_Range (Node));
3306 Write_Char (')');
3308 when N_String_Literal =>
3309 if String_Length (Strval (Node)) + Column > Sprint_Line_Limit then
3310 Write_Indent_Str (" ");
3311 end if;
3313 Set_Debug_Sloc;
3314 Write_String_Table_Entry (Strval (Node));
3316 when N_Interpolated_String_Literal =>
3317 Write_Char ('{');
3319 declare
3320 Str_Elem : Node_Id := First (Expressions (Node));
3321 Is_First : Boolean := True;
3323 begin
3324 while Present (Str_Elem) loop
3325 if not Is_First then
3326 Write_Str (" & ");
3327 end if;
3329 if Nkind (Str_Elem) = N_String_Literal then
3330 Sprint_Node (Str_Elem);
3332 else
3333 Write_Char ('"');
3334 Write_Char ('{');
3335 Sprint_Node (Str_Elem);
3336 Write_Char ('}');
3337 Write_Char ('"');
3338 end if;
3340 Is_First := False;
3342 Next (Str_Elem);
3343 end loop;
3344 end;
3346 Write_Char ('}');
3348 when N_Subprogram_Body =>
3350 -- Output extra blank line unless we are in freeze actions
3352 if Freeze_Indent = 0 then
3353 Extra_Blank_Line;
3354 end if;
3356 Write_Indent;
3358 if Present (Corresponding_Spec (Node)) then
3359 Sprint_Node_Sloc (Parent (Corresponding_Spec (Node)));
3360 else
3361 Sprint_Node_Sloc (Specification (Node));
3362 end if;
3364 Write_Str (" is");
3366 Sprint_Indented_List (Declarations (Node));
3367 Write_Indent_Str ("begin");
3368 Sprint_Node (Handled_Statement_Sequence (Node));
3370 Write_Indent_Str ("end ");
3372 Sprint_End_Label
3373 (Handled_Statement_Sequence (Node),
3374 Defining_Unit_Name (Specification (Node)));
3375 Write_Char (';');
3376 Sprint_At_End_Proc (Node);
3378 if Is_List_Member (Node)
3379 and then Present (Next (Node))
3380 and then Nkind (Next (Node)) /= N_Subprogram_Body
3381 then
3382 Write_Indent;
3383 end if;
3385 when N_Subprogram_Body_Stub =>
3386 Write_Indent;
3387 Sprint_Node_Sloc (Specification (Node));
3388 Write_Str_With_Col_Check (" is separate;");
3390 when N_Subprogram_Declaration =>
3391 Write_Indent;
3392 Sprint_Node_Sloc (Specification (Node));
3394 if Nkind (Specification (Node)) = N_Procedure_Specification
3395 and then Null_Present (Specification (Node))
3396 then
3397 Write_Str_With_Col_Check (" is null");
3398 end if;
3400 Write_Char (';');
3402 when N_Subprogram_Renaming_Declaration =>
3403 Write_Indent;
3404 Sprint_Node (Specification (Node));
3405 Write_Str_With_Col_Check_Sloc (" renames ");
3406 Sprint_Node (Name (Node));
3407 Write_Char (';');
3409 when N_Subtype_Declaration =>
3410 Write_Indent_Str_Sloc ("subtype ");
3411 Sprint_Node (Defining_Identifier (Node));
3412 Write_Str (" is ");
3414 -- Ada 2005 (AI-231)
3416 if Null_Exclusion_Present (Node) then
3417 Write_Str ("not null ");
3418 end if;
3420 Sprint_Node (Subtype_Indication (Node));
3421 Write_Char (';');
3423 when N_Subtype_Indication =>
3424 Sprint_Node_Sloc (Subtype_Mark (Node));
3425 Write_Char (' ');
3426 Sprint_Node (Constraint (Node));
3428 when N_Subunit =>
3429 Write_Indent_Str_Sloc ("separate (");
3430 Sprint_Node (Name (Node));
3431 Write_Char (')');
3432 Extra_Blank_Line;
3433 Sprint_Node (Proper_Body (Node));
3435 when N_Target_Name =>
3436 Write_Char ('@');
3438 when N_Task_Body =>
3439 Write_Indent_Str_Sloc ("task body ");
3440 Write_Id (Defining_Identifier (Node));
3441 Write_Str (" is");
3442 Sprint_Indented_List (Declarations (Node));
3443 Write_Indent_Str ("begin");
3444 Sprint_Node (Handled_Statement_Sequence (Node));
3445 Write_Indent_Str ("end ");
3446 Sprint_End_Label
3447 (Handled_Statement_Sequence (Node), Defining_Identifier (Node));
3448 Write_Char (';');
3449 Sprint_At_End_Proc (Node);
3451 when N_Task_Body_Stub =>
3452 Write_Indent_Str_Sloc ("task body ");
3453 Write_Id (Defining_Identifier (Node));
3454 Write_Str_With_Col_Check (" is separate;");
3456 when N_Task_Definition =>
3457 Set_Debug_Sloc;
3458 Sprint_Indented_List (Visible_Declarations (Node));
3460 if Present (Private_Declarations (Node)) then
3461 Write_Indent_Str ("private");
3462 Sprint_Indented_List (Private_Declarations (Node));
3463 end if;
3465 Write_Indent_Str ("end ");
3466 Sprint_End_Label (Node, Defining_Identifier (Parent (Node)));
3468 when N_Task_Type_Declaration =>
3469 Write_Indent_Str_Sloc ("task type ");
3470 Sprint_Node (Defining_Identifier (Node));
3471 Write_Discr_Specs (Node);
3473 if Present (Interface_List (Node)) then
3474 Write_Str (" is new ");
3475 Sprint_And_List (Interface_List (Node));
3476 end if;
3478 if Present (Task_Definition (Node)) then
3479 if No (Interface_List (Node)) then
3480 Write_Str (" is");
3481 else
3482 Write_Str (" with ");
3483 end if;
3485 Sprint_Node (Task_Definition (Node));
3486 end if;
3488 Write_Char (';');
3490 when N_Terminate_Alternative =>
3491 Sprint_Node_List (Pragmas_Before (Node));
3492 Write_Indent;
3494 if Present (Condition (Node)) then
3495 Write_Str_With_Col_Check ("when ");
3496 Sprint_Node (Condition (Node));
3497 Write_Str (" => ");
3498 end if;
3500 Write_Str_With_Col_Check_Sloc ("terminate;");
3501 Sprint_Node_List (Pragmas_After (Node));
3503 when N_Timed_Entry_Call =>
3504 Write_Indent_Str_Sloc ("select");
3505 Indent_Begin;
3506 Sprint_Node (Entry_Call_Alternative (Node));
3507 Indent_End;
3508 Write_Indent_Str ("or");
3509 Indent_Begin;
3510 Sprint_Node (Delay_Alternative (Node));
3511 Indent_End;
3512 Write_Indent_Str ("end select;");
3514 when N_Triggering_Alternative =>
3515 Sprint_Node_List (Pragmas_Before (Node));
3516 Sprint_Node_Sloc (Triggering_Statement (Node));
3517 Sprint_Node_List (Statements (Node));
3519 when N_Type_Conversion =>
3520 Set_Debug_Sloc;
3521 Sprint_Node (Subtype_Mark (Node));
3522 Col_Check (4);
3524 if Conversion_OK (Node) then
3525 Write_Char ('?');
3526 end if;
3528 if Float_Truncate (Node) then
3529 Write_Char ('^');
3530 end if;
3532 if Rounded_Result (Node) then
3533 Write_Char ('@');
3534 end if;
3536 Write_Char ('(');
3537 Sprint_Node (Expression (Node));
3538 Write_Char (')');
3540 when N_Unchecked_Expression =>
3541 Col_Check (10);
3542 Write_Str ("`(");
3543 Sprint_Node_Sloc (Expression (Node));
3544 Write_Char (')');
3546 when N_Unchecked_Type_Conversion =>
3547 Sprint_Node (Subtype_Mark (Node));
3548 Write_Char ('!');
3549 Write_Str_With_Col_Check ("(");
3550 Sprint_Node_Sloc (Expression (Node));
3551 Write_Char (')');
3553 when N_Unconstrained_Array_Definition =>
3554 Write_Str_With_Col_Check_Sloc ("array (");
3556 declare
3557 Node1 : Node_Id;
3558 begin
3559 Node1 := First (Subtype_Marks (Node));
3560 loop
3561 Sprint_Node (Node1);
3562 Write_Str_With_Col_Check (" range <>");
3563 Next (Node1);
3564 exit when Node1 = Empty;
3565 Write_Str (", ");
3566 end loop;
3567 end;
3569 Write_Str (") of ");
3570 Sprint_Node (Component_Definition (Node));
3572 when N_Unused_At_Start | N_Unused_At_End =>
3573 Write_Indent_Str ("***** Error, unused node encountered *****");
3574 Write_Eol;
3576 when N_Use_Package_Clause =>
3577 Write_Indent_Str_Sloc ("use ");
3578 Sprint_Node_Sloc (Name (Node));
3579 Write_Char (';');
3581 when N_Use_Type_Clause =>
3582 Write_Indent_Str_Sloc ("use type ");
3583 Sprint_Node_Sloc (Subtype_Mark (Node));
3584 Write_Char (';');
3586 when N_Validate_Unchecked_Conversion =>
3587 Write_Indent_Str_Sloc ("validate unchecked_conversion (");
3588 Sprint_Node (Source_Type (Node));
3589 Write_Str (", ");
3590 Sprint_Node (Target_Type (Node));
3591 Write_Str (");");
3593 when N_Variable_Reference_Marker =>
3594 null;
3596 -- Enable the following code for debugging purposes only
3598 -- if Is_Read (Node) and then Is_Write (Node) then
3599 -- Write_Indent_Str ("rw#");
3601 -- elsif Is_Read (Node) then
3602 -- Write_Indent_Str ("r#");
3604 -- else
3605 -- pragma Assert (Is_Write (Node));
3606 -- Write_Indent_Str ("w#");
3607 -- end if;
3609 -- Write_Id (Target (Node));
3610 -- Write_Char ('#');
3612 when N_Variant =>
3613 Write_Indent_Str_Sloc ("when ");
3614 Sprint_Bar_List (Discrete_Choices (Node));
3615 Write_Str (" => ");
3616 Sprint_Node (Component_List (Node));
3618 when N_Variant_Part =>
3619 Indent_Begin;
3620 Write_Indent_Str_Sloc ("case ");
3621 Sprint_Node (Name (Node));
3622 Write_Str (" is ");
3623 Sprint_Indented_List (Variants (Node));
3624 Write_Indent_Str ("end case");
3625 Indent_End;
3627 when N_With_Clause =>
3629 -- Special test, if we are dumping the original tree only,
3630 -- then we want to eliminate the bogus with clauses that
3631 -- correspond to the non-existent children of Text_IO.
3633 if Dump_Original_Only
3634 and then Is_Text_IO_Special_Unit (Name (Node))
3635 then
3636 null;
3638 -- Normal case, output the with clause
3640 else
3641 if First_Name (Node) or else not Dump_Original_Only then
3643 -- Ada 2005 (AI-50217): Print limited with_clauses
3645 if Private_Present (Node) and Limited_Present (Node) then
3646 Write_Indent_Str ("limited private with ");
3648 elsif Private_Present (Node) then
3649 Write_Indent_Str ("private with ");
3651 elsif Limited_Present (Node) then
3652 Write_Indent_Str ("limited with ");
3654 else
3655 Write_Indent_Str ("with ");
3656 end if;
3658 else
3659 Write_Str (", ");
3660 end if;
3662 Sprint_Node_Sloc (Name (Node));
3664 if Last_Name (Node) or else not Dump_Original_Only then
3665 Write_Char (';');
3666 end if;
3667 end if;
3668 end case;
3670 -- Print aspects, except for special case of package declaration,
3671 -- where the aspects are printed inside the package specification.
3673 if Has_Aspects (Node)
3674 and then Nkind (Node) not in
3675 N_Generic_Package_Declaration | N_Package_Declaration
3676 and then not Is_Empty_List (Aspect_Specifications (Node))
3677 then
3678 Sprint_Aspect_Specifications (Node, Semicolon => True);
3679 end if;
3681 if Nkind (Node) in N_Subexpr and then Do_Range_Check (Node) then
3682 Write_Str ("}");
3683 end if;
3685 for J in 1 .. Paren_Count (Node) loop
3686 Write_Char (')');
3687 end loop;
3689 Dump_Node := Save_Dump_Node;
3690 end Sprint_Node_Actual;
3692 ----------------------
3693 -- Sprint_Node_List --
3694 ----------------------
3696 procedure Sprint_Node_List (List : List_Id; New_Lines : Boolean := False) is
3697 Node : Node_Id;
3699 begin
3700 if Is_Non_Empty_List (List) then
3701 Node := First (List);
3703 loop
3704 Sprint_Node (Node);
3705 Next (Node);
3706 exit when Node = Empty;
3707 end loop;
3708 end if;
3710 if New_Lines and then Column /= 1 then
3711 Write_Eol;
3712 end if;
3713 end Sprint_Node_List;
3715 ----------------------
3716 -- Sprint_Node_Sloc --
3717 ----------------------
3719 procedure Sprint_Node_Sloc (Node : Node_Id) is
3720 begin
3721 Sprint_Node (Node);
3723 if Debug_Generated_Code and then Present (Dump_Node) then
3724 Set_Sloc (Dump_Node, Sloc (Node));
3725 Dump_Node := Empty;
3726 end if;
3727 end Sprint_Node_Sloc;
3729 ---------------------
3730 -- Sprint_Opt_Node --
3731 ---------------------
3733 procedure Sprint_Opt_Node (Node : Node_Id) is
3734 begin
3735 if Present (Node) then
3736 Write_Char (' ');
3737 Sprint_Node (Node);
3738 end if;
3739 end Sprint_Opt_Node;
3741 --------------------------
3742 -- Sprint_Opt_Node_List --
3743 --------------------------
3745 procedure Sprint_Opt_Node_List (List : List_Id) is
3746 begin
3747 if Present (List) then
3748 Sprint_Node_List (List);
3749 end if;
3750 end Sprint_Opt_Node_List;
3752 ---------------------------------
3753 -- Sprint_Opt_Paren_Comma_List --
3754 ---------------------------------
3756 procedure Sprint_Opt_Paren_Comma_List (List : List_Id) is
3757 begin
3758 if Is_Non_Empty_List (List) then
3759 Write_Char (' ');
3760 Sprint_Paren_Comma_List (List);
3761 end if;
3762 end Sprint_Opt_Paren_Comma_List;
3764 -----------------------------
3765 -- Sprint_Paren_Comma_List --
3766 -----------------------------
3768 procedure Sprint_Paren_Comma_List (List : List_Id) is
3769 N : Node_Id;
3770 Node_Exists : Boolean := False;
3772 begin
3774 if Is_Non_Empty_List (List) then
3776 if Dump_Original_Only then
3777 N := First (List);
3778 while Present (N) loop
3779 if not Is_Rewrite_Insertion (N) then
3780 Node_Exists := True;
3781 exit;
3782 end if;
3784 Next (N);
3785 end loop;
3787 if not Node_Exists then
3788 return;
3789 end if;
3790 end if;
3792 Write_Str_With_Col_Check ("(");
3793 Sprint_Comma_List (List);
3794 Write_Char (')');
3795 end if;
3796 end Sprint_Paren_Comma_List;
3798 ----------------------
3799 -- Sprint_Right_Opnd --
3800 ----------------------
3802 procedure Sprint_Right_Opnd (N : Node_Id) is
3803 Opnd : constant Node_Id := Right_Opnd (N);
3805 begin
3806 if Paren_Count (Opnd) /= 0
3807 or else Op_Prec (Nkind (Opnd)) > Op_Prec (Nkind (N))
3808 then
3809 Sprint_Node (Opnd);
3811 else
3812 Write_Char ('(');
3813 Sprint_Node (Opnd);
3814 Write_Char (')');
3815 end if;
3816 end Sprint_Right_Opnd;
3818 ------------------
3819 -- Update_Itype --
3820 ------------------
3822 procedure Update_Itype (Node : Node_Id) is
3823 begin
3824 if Present (Etype (Node))
3825 and then Is_Itype (Etype (Node))
3826 and then Debug_Generated_Code
3827 then
3828 Set_Sloc (Etype (Node), Sloc (Node));
3829 end if;
3830 end Update_Itype;
3832 ---------------------
3833 -- Write_Char_Sloc --
3834 ---------------------
3836 procedure Write_Char_Sloc (C : Character) is
3837 begin
3838 if Debug_Generated_Code and then C /= ' ' then
3839 Set_Debug_Sloc;
3840 end if;
3842 Write_Char (C);
3843 end Write_Char_Sloc;
3845 --------------------------------
3846 -- Write_Condition_And_Reason --
3847 --------------------------------
3849 procedure Write_Condition_And_Reason (Node : Node_Id) is
3850 Cond : constant Node_Id := Condition (Node);
3851 Image : constant String := RT_Exception_Code'Image
3852 (RT_Exception_Code'Val
3853 (UI_To_Int (Reason (Node))));
3855 begin
3856 if Present (Cond) then
3858 -- If condition is a single entity, or NOT with a single entity,
3859 -- output all on one line, since it will likely fit just fine.
3861 if Is_Entity_Name (Cond)
3862 or else (Nkind (Cond) = N_Op_Not
3863 and then Is_Entity_Name (Right_Opnd (Cond)))
3864 then
3865 Write_Str_With_Col_Check (" when ");
3866 Sprint_Node (Cond);
3867 Write_Char (' ');
3869 -- Otherwise for more complex condition, multiple lines
3871 else
3872 Write_Str_With_Col_Check (" when");
3873 Indent := Indent + 2;
3874 Write_Indent;
3875 Sprint_Node (Cond);
3876 Write_Indent;
3877 Indent := Indent - 2;
3878 end if;
3880 -- If no condition, just need a space (all on one line)
3882 else
3883 Write_Char (' ');
3884 end if;
3886 -- Write the reason
3888 Write_Char ('"');
3890 for J in 4 .. Image'Last loop
3891 if Image (J) = '_' then
3892 Write_Char (' ');
3893 else
3894 Write_Char (Fold_Lower (Image (J)));
3895 end if;
3896 end loop;
3898 Write_Str ("""]");
3899 end Write_Condition_And_Reason;
3901 --------------------------------
3902 -- Write_Corresponding_Source --
3903 --------------------------------
3905 procedure Write_Corresponding_Source (S : String) is
3906 Loc : Source_Ptr;
3907 Src : Source_Buffer_Ptr;
3909 begin
3910 -- Ignore if there is no current source file, or we're not in dump
3911 -- source text mode, or if in freeze actions.
3913 if Current_Source_File > No_Source_File
3914 and then Dump_Source_Text
3915 and then Freeze_Indent = 0
3916 then
3918 -- Ignore null string
3920 if S = "" then
3921 return;
3922 end if;
3924 -- Ignore space or semicolon at end of given string
3926 if S (S'Last) = ' ' or else S (S'Last) = ';' then
3927 Write_Corresponding_Source (S (S'First .. S'Last - 1));
3928 return;
3929 end if;
3931 -- Loop to look at next lines not yet printed in source file
3933 for L in
3934 Last_Line_Printed + 1 .. Last_Source_Line (Current_Source_File)
3935 loop
3936 Src := Source_Text (Current_Source_File);
3937 Loc := Line_Start (L, Current_Source_File);
3939 -- If comment, keep looking
3941 if Src (Loc .. Loc + 1) = "--" then
3942 null;
3944 -- Search to first non-blank
3946 else
3947 while Src (Loc) not in Line_Terminator loop
3949 -- Non-blank found
3951 if Src (Loc) /= ' ' and then Src (Loc) /= ASCII.HT then
3953 -- Loop through characters in string to see if we match
3955 for J in S'Range loop
3957 -- If mismatch, then not the case we are looking for
3959 if Src (Loc) /= S (J) then
3960 return;
3961 end if;
3963 Loc := Loc + 1;
3964 end loop;
3966 -- If we fall through, string matched, if white space or
3967 -- semicolon after the matched string, this is the case
3968 -- we are looking for.
3970 if Src (Loc) in Line_Terminator
3971 or else Src (Loc) = ' '
3972 or else Src (Loc) = ASCII.HT
3973 or else Src (Loc) = ';'
3974 then
3975 -- So output source lines up to and including this one
3977 Write_Source_Lines (L);
3978 return;
3979 end if;
3980 end if;
3982 Loc := Loc + 1;
3983 end loop;
3984 end if;
3986 -- Line was all blanks, or a comment line, keep looking
3988 end loop;
3989 end if;
3990 end Write_Corresponding_Source;
3992 -----------------------
3993 -- Write_Discr_Specs --
3994 -----------------------
3996 procedure Write_Discr_Specs (N : Node_Id) is
3997 Specs : List_Id;
3998 Spec : Node_Id;
4000 begin
4001 Specs := Discriminant_Specifications (N);
4003 if Present (Specs) then
4004 Write_Str_With_Col_Check (" (");
4005 Spec := First (Specs);
4007 loop
4008 Sprint_Node (Spec);
4009 Next (Spec);
4010 exit when Spec = Empty;
4012 -- Add semicolon, unless we are printing original tree and the
4013 -- next specification is part of a list (but not the first
4014 -- element of that list)
4016 if not Dump_Original_Only or else not Prev_Ids (Spec) then
4017 Write_Str ("; ");
4018 end if;
4019 end loop;
4021 Write_Char (')');
4022 end if;
4023 end Write_Discr_Specs;
4025 -----------------
4026 -- Write_Ekind --
4027 -----------------
4029 procedure Write_Ekind (E : Entity_Id) is
4030 S : constant String := Entity_Kind'Image (Ekind (E));
4032 begin
4033 Name_Len := S'Length;
4034 Name_Buffer (1 .. Name_Len) := S;
4035 Set_Casing (Mixed_Case);
4036 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
4037 end Write_Ekind;
4039 --------------
4040 -- Write_Id --
4041 --------------
4043 procedure Write_Id (N : Node_Id) is
4044 begin
4045 -- Deal with outputting Itype
4047 -- Note: if we are printing the full tree with -gnatds, then we may
4048 -- end up picking up the Associated_Node link from a generic template
4049 -- here which overlaps the Entity field, but as documented, Write_Itype
4050 -- is defended against junk calls.
4052 if Nkind (N) in N_Entity then
4053 Write_Itype (N);
4054 elsif Nkind (N) in N_Has_Entity then
4055 Write_Itype (Entity (N));
4056 end if;
4058 -- Case of a defining identifier
4060 if Nkind (N) = N_Defining_Identifier then
4062 -- If defining identifier has an interface name (and no
4063 -- address clause), then we output the interface name.
4065 if (Is_Imported (N) or else Is_Exported (N))
4066 and then Present (Interface_Name (N))
4067 and then No (Address_Clause (N))
4068 then
4069 String_To_Name_Buffer (Strval (Interface_Name (N)));
4070 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
4072 -- If no interface name (or inactive because there was
4073 -- an address clause), then just output the Chars name.
4075 else
4076 Write_Name_With_Col_Check (Chars (N));
4077 end if;
4079 -- Case of selector of an expanded name where the expanded name
4080 -- has an associated entity, output this entity. Check that the
4081 -- entity or associated node is of the right kind, see above.
4083 elsif Nkind (Parent (N)) = N_Expanded_Name
4084 and then Selector_Name (Parent (N)) = N
4085 and then Present (Entity_Or_Associated_Node (Parent (N)))
4086 and then Nkind (Entity (Parent (N))) in N_Entity
4087 then
4088 Write_Id (Entity (Parent (N)));
4090 -- For any other node with an associated entity, output it
4092 elsif Nkind (N) in N_Has_Entity
4093 and then Present (Entity_Or_Associated_Node (N))
4094 and then Nkind (Entity_Or_Associated_Node (N)) in N_Entity
4095 then
4096 Write_Id (Entity (N));
4098 -- All other cases, we just print the Chars field
4100 else
4101 Write_Name_With_Col_Check (Chars (N));
4102 end if;
4103 end Write_Id;
4105 -----------------------
4106 -- Write_Identifiers --
4107 -----------------------
4109 function Write_Identifiers (Node : Node_Id) return Boolean is
4110 begin
4111 Sprint_Node (Defining_Identifier (Node));
4112 Update_Itype (Defining_Identifier (Node));
4114 -- The remainder of the declaration must be printed unless we are
4115 -- printing the original tree and this is not the last identifier
4117 return
4118 not Dump_Original_Only or else not More_Ids (Node);
4120 end Write_Identifiers;
4122 ------------------------
4123 -- Write_Implicit_Def --
4124 ------------------------
4126 procedure Write_Implicit_Def (E : Entity_Id) is
4127 Ind : Node_Id;
4129 begin
4130 case Ekind (E) is
4131 when E_Array_Subtype =>
4132 Write_Str_With_Col_Check ("subtype ");
4133 Write_Id (E);
4134 Write_Str_With_Col_Check (" is ");
4135 Write_Id (Base_Type (E));
4136 Write_Str_With_Col_Check (" (");
4138 Ind := First_Index (E);
4139 while Present (Ind) loop
4140 Sprint_Node (Ind);
4141 Next_Index (Ind);
4143 if Present (Ind) then
4144 Write_Str (", ");
4145 end if;
4146 end loop;
4148 Write_Str (");");
4150 when E_Enumeration_Subtype
4151 | E_Signed_Integer_Subtype
4153 Write_Str_With_Col_Check ("subtype ");
4154 Write_Id (E);
4155 Write_Str (" is ");
4156 Write_Id (Etype (E));
4157 Write_Str_With_Col_Check (" range ");
4158 Sprint_Node (Scalar_Range (E));
4159 Write_Str (";");
4161 when others =>
4162 Write_Str_With_Col_Check ("type ");
4163 Write_Id (E);
4164 Write_Str_With_Col_Check (" is <");
4165 Write_Ekind (E);
4166 Write_Str (">;");
4167 end case;
4168 end Write_Implicit_Def;
4170 ------------------
4171 -- Write_Indent --
4172 ------------------
4174 procedure Write_Indent is
4175 Loc : constant Source_Ptr := Sloc (Dump_Node);
4177 begin
4178 if Indent_Annull_Flag then
4179 Indent_Annull_Flag := False;
4180 else
4181 -- Deal with Dump_Source_Text output. Note that we ignore implicit
4182 -- label declarations, since they typically have the sloc of the
4183 -- corresponding label, which really messes up the -gnatL output.
4185 if Dump_Source_Text
4186 and then Loc > No_Location
4187 and then Nkind (Dump_Node) /= N_Implicit_Label_Declaration
4188 then
4189 if Get_Source_File_Index (Loc) = Current_Source_File then
4190 Write_Source_Lines
4191 (Get_Physical_Line_Number (Sloc (Dump_Node)));
4192 end if;
4193 end if;
4195 Write_Eol;
4197 for J in 1 .. Indent loop
4198 Write_Char (' ');
4199 end loop;
4200 end if;
4201 end Write_Indent;
4203 ------------------------------
4204 -- Write_Indent_Identifiers --
4205 ------------------------------
4207 function Write_Indent_Identifiers (Node : Node_Id) return Boolean is
4208 begin
4209 -- We need to start a new line for every node, except in the case
4210 -- where we are printing the original tree and this is not the first
4211 -- defining identifier in the list.
4213 if not Dump_Original_Only or else not Prev_Ids (Node) then
4214 Write_Indent;
4216 -- If printing original tree and this is not the first defining
4217 -- identifier in the list, then the previous call to this procedure
4218 -- printed only the name, and we add a comma to separate the names.
4220 else
4221 Write_Str (", ");
4222 end if;
4224 Sprint_Node (Defining_Identifier (Node));
4226 -- The remainder of the declaration must be printed unless we are
4227 -- printing the original tree and this is not the last identifier
4229 return
4230 not Dump_Original_Only or else not More_Ids (Node);
4231 end Write_Indent_Identifiers;
4233 -----------------------------------
4234 -- Write_Indent_Identifiers_Sloc --
4235 -----------------------------------
4237 function Write_Indent_Identifiers_Sloc (Node : Node_Id) return Boolean is
4238 begin
4239 -- We need to start a new line for every node, except in the case
4240 -- where we are printing the original tree and this is not the first
4241 -- defining identifier in the list.
4243 if not Dump_Original_Only or else not Prev_Ids (Node) then
4244 Write_Indent;
4246 -- If printing original tree and this is not the first defining
4247 -- identifier in the list, then the previous call to this procedure
4248 -- printed only the name, and we add a comma to separate the names.
4250 else
4251 Write_Str (", ");
4252 end if;
4254 Set_Debug_Sloc;
4255 Sprint_Node (Defining_Identifier (Node));
4257 -- The remainder of the declaration must be printed unless we are
4258 -- printing the original tree and this is not the last identifier
4260 return not Dump_Original_Only or else not More_Ids (Node);
4261 end Write_Indent_Identifiers_Sloc;
4263 ----------------------
4264 -- Write_Indent_Str --
4265 ----------------------
4267 procedure Write_Indent_Str (S : String) is
4268 begin
4269 Write_Corresponding_Source (S);
4270 Write_Indent;
4271 Write_Str (S);
4272 end Write_Indent_Str;
4274 ---------------------------
4275 -- Write_Indent_Str_Sloc --
4276 ---------------------------
4278 procedure Write_Indent_Str_Sloc (S : String) is
4279 begin
4280 Write_Corresponding_Source (S);
4281 Write_Indent;
4282 Write_Str_Sloc (S);
4283 end Write_Indent_Str_Sloc;
4285 -----------------
4286 -- Write_Itype --
4287 -----------------
4289 procedure Write_Itype (Typ : Entity_Id) is
4291 procedure Write_Header (T : Boolean := True);
4292 -- Write type if T is True, subtype if T is false
4294 ------------------
4295 -- Write_Header --
4296 ------------------
4298 procedure Write_Header (T : Boolean := True) is
4299 begin
4300 if T then
4301 Write_Str ("[type ");
4302 else
4303 Write_Str ("[subtype ");
4304 end if;
4306 Write_Name_With_Col_Check (Chars (Typ));
4307 Write_Str (" is ");
4308 end Write_Header;
4310 -- Start of processing for Write_Itype
4312 begin
4313 if Nkind (Typ) in N_Entity
4314 and then Is_Itype (Typ)
4315 and then not Itype_Printed (Typ)
4316 then
4317 -- Itype to be printed
4319 declare
4320 B : constant Entity_Id := Etype (Typ);
4321 P : constant Node_Id := Parent (Typ);
4322 S : constant Saved_Output_Buffer := Save_Output_Buffer;
4323 -- Save current output buffer
4325 Old_Sloc : Source_Ptr;
4326 -- Save sloc of related node, so it is not modified when
4327 -- printing with -gnatD.
4329 X : Node_Id;
4331 begin
4332 -- Write indentation at start of line
4334 for J in 1 .. Indent loop
4335 Write_Char (' ');
4336 end loop;
4338 -- If we have a constructed declaration for the itype, print it
4340 if Present (P)
4341 and then Nkind (P) in N_Declaration
4342 and then Defining_Entity (P) = Typ
4343 then
4344 -- We must set Itype_Printed true before the recursive call to
4345 -- print the node, otherwise we get an infinite recursion.
4347 Set_Itype_Printed (Typ, True);
4349 -- Write the declaration enclosed in [], avoiding new line
4350 -- at start of declaration, and semicolon at end.
4352 -- Note: The itype may be imported from another unit, in which
4353 -- case we do not want to modify the Sloc of the declaration.
4354 -- Otherwise the itype may appear to be in the current unit,
4355 -- and the back-end will reject a reference out of scope.
4357 Write_Char ('[');
4358 Indent_Annull_Flag := True;
4359 Old_Sloc := Sloc (P);
4360 Sprint_Node (P);
4361 Set_Sloc (P, Old_Sloc);
4362 Write_Erase_Char (';');
4364 -- If no constructed declaration, then we have to concoct the
4365 -- source corresponding to the type entity that we have at hand.
4367 else
4368 case Ekind (Typ) is
4370 -- Access types and subtypes
4372 when Access_Kind =>
4373 Write_Header (Ekind (Typ) = E_Access_Type);
4375 if Can_Never_Be_Null (Typ) then
4376 Write_Str ("not null ");
4377 end if;
4379 Write_Str ("access ");
4381 if Is_Access_Constant (Typ) then
4382 Write_Str ("constant ");
4383 end if;
4385 Write_Id (Directly_Designated_Type (Typ));
4387 -- Array types
4389 when E_Array_Type =>
4390 Write_Header;
4391 Write_Str ("array (");
4393 X := First_Index (Typ);
4394 loop
4395 Sprint_Node (X);
4397 if not Is_Constrained (Typ) then
4398 Write_Str (" range <>");
4399 end if;
4401 Next_Index (X);
4402 exit when No (X);
4403 Write_Str (", ");
4404 end loop;
4406 Write_Str (") of ");
4407 X := Component_Type (Typ);
4409 -- Preserve sloc of component type, which is defined
4410 -- elsewhere than the itype (see comment above).
4412 Old_Sloc := Sloc (X);
4413 Sprint_Node (X);
4414 Set_Sloc (X, Old_Sloc);
4416 -- Array subtypes
4418 -- Preserve Sloc of index subtypes, as above
4420 when E_Array_Subtype =>
4421 Write_Header (False);
4422 Write_Id (Etype (Typ));
4423 Write_Str (" (");
4425 X := First_Index (Typ);
4426 loop
4427 Old_Sloc := Sloc (X);
4428 Sprint_Node (X);
4429 Set_Sloc (X, Old_Sloc);
4430 Next_Index (X);
4431 exit when No (X);
4432 Write_Str (", ");
4433 end loop;
4435 Write_Char (')');
4437 -- Signed integer types, and modular integer subtypes,
4438 -- and also enumeration subtypes.
4440 when E_Enumeration_Subtype
4441 | E_Modular_Integer_Subtype
4442 | E_Signed_Integer_Subtype
4443 | E_Signed_Integer_Type
4445 Write_Header (Ekind (Typ) = E_Signed_Integer_Type);
4447 if Ekind (Typ) = E_Signed_Integer_Type then
4448 Write_Str ("new ");
4449 end if;
4451 Write_Id (B);
4453 -- Print bounds if different from base type
4455 declare
4456 L : constant Node_Id := Type_Low_Bound (Typ);
4457 H : constant Node_Id := Type_High_Bound (Typ);
4458 BL : Node_Id;
4459 BH : Node_Id;
4461 begin
4462 -- B can either be a scalar type, in which case the
4463 -- declaration of Typ may constrain it with different
4464 -- bounds, or a private type, in which case we know
4465 -- that the declaration of Typ cannot have a scalar
4466 -- constraint.
4468 if Is_Scalar_Type (B) then
4469 BL := Type_Low_Bound (B);
4470 BH := Type_High_Bound (B);
4471 else
4472 BL := Empty;
4473 BH := Empty;
4474 end if;
4476 if No (BL)
4477 or else (True
4478 and then Nkind (L) = N_Integer_Literal
4479 and then Nkind (H) = N_Integer_Literal
4480 and then Nkind (BL) = N_Integer_Literal
4481 and then Nkind (BH) = N_Integer_Literal
4482 and then UI_Eq (Intval (L), Intval (BL))
4483 and then UI_Eq (Intval (H), Intval (BH)))
4484 then
4485 null;
4487 else
4488 Write_Str (" range ");
4489 Sprint_Node (L);
4490 Write_Str (" .. ");
4491 Sprint_Node (H);
4492 end if;
4493 end;
4495 -- Modular integer types
4497 when E_Modular_Integer_Type =>
4498 Write_Header;
4499 Write_Str ("mod ");
4501 if No (Modulus (Typ)) then
4502 Write_Uint_With_Col_Check (Uint_0, Auto);
4503 else
4504 Write_Uint_With_Col_Check (Modulus (Typ), Auto);
4505 end if;
4507 -- Floating-point types and subtypes
4509 when E_Floating_Point_Subtype
4510 | E_Floating_Point_Type
4512 Write_Header (Ekind (Typ) = E_Floating_Point_Type);
4514 if Ekind (Typ) = E_Floating_Point_Type then
4515 Write_Str ("new ");
4516 end if;
4518 Write_Id (B);
4520 if Digits_Value (Typ) /= Digits_Value (B) then
4521 Write_Str (" digits ");
4522 Write_Uint_With_Col_Check
4523 (Digits_Value (Typ), Decimal);
4524 end if;
4526 -- Print bounds if not different from base type
4528 declare
4529 L : constant Node_Id := Type_Low_Bound (Typ);
4530 H : constant Node_Id := Type_High_Bound (Typ);
4531 BL : constant Node_Id := Type_Low_Bound (B);
4532 BH : constant Node_Id := Type_High_Bound (B);
4534 begin
4535 if True
4536 and then Nkind (L) = N_Real_Literal
4537 and then Nkind (H) = N_Real_Literal
4538 and then Nkind (BL) = N_Real_Literal
4539 and then Nkind (BH) = N_Real_Literal
4540 and then UR_Eq (Realval (L), Realval (BL))
4541 and then UR_Eq (Realval (H), Realval (BH))
4542 then
4543 null;
4545 else
4546 Write_Str (" range ");
4547 Sprint_Node (L);
4548 Write_Str (" .. ");
4549 Sprint_Node (H);
4550 end if;
4551 end;
4553 -- Ordinary fixed-point types and subtypes
4555 when E_Ordinary_Fixed_Point_Subtype
4556 | E_Ordinary_Fixed_Point_Type
4558 Write_Header (Ekind (Typ) = E_Ordinary_Fixed_Point_Type);
4560 Write_Str ("delta ");
4561 Write_Ureal_With_Col_Check_Sloc (Delta_Value (Typ));
4562 Write_Str (" range ");
4563 Sprint_Node (Type_Low_Bound (Typ));
4564 Write_Str (" .. ");
4565 Sprint_Node (Type_High_Bound (Typ));
4567 -- Decimal fixed-point types and subtypes
4569 when E_Decimal_Fixed_Point_Subtype
4570 | E_Decimal_Fixed_Point_Type
4572 Write_Header (Ekind (Typ) = E_Decimal_Fixed_Point_Type);
4574 Write_Str ("delta ");
4575 Write_Ureal_With_Col_Check_Sloc (Delta_Value (Typ));
4576 Write_Str (" digits ");
4577 Write_Uint_With_Col_Check (Digits_Value (Typ), Decimal);
4579 -- Record subtypes
4581 when E_Record_Subtype
4582 | E_Record_Subtype_With_Private
4584 Write_Header (False);
4585 Write_Str ("record");
4586 Indent_Begin;
4588 declare
4589 C : Entity_Id;
4590 begin
4591 C := First_Entity (Typ);
4592 while Present (C) loop
4593 Write_Indent;
4594 Write_Id (C);
4595 Write_Str (" : ");
4596 Write_Id (Etype (C));
4597 Next_Entity (C);
4598 end loop;
4599 end;
4601 Indent_End;
4602 Write_Indent_Str (" end record");
4604 -- Class-Wide types
4606 when E_Class_Wide_Subtype
4607 | E_Class_Wide_Type
4609 Write_Header (Ekind (Typ) = E_Class_Wide_Type);
4610 Write_Name_With_Col_Check (Chars (Etype (Typ)));
4611 Write_Str ("'Class");
4613 -- Subprogram types
4615 when E_Subprogram_Type =>
4616 Write_Header;
4618 if Etype (Typ) = Standard_Void_Type then
4619 Write_Str ("procedure");
4620 else
4621 Write_Str ("function");
4622 end if;
4624 if Present (First_Entity (Typ)) then
4625 Write_Str (" (");
4627 declare
4628 Param : Entity_Id;
4630 begin
4631 Param := First_Entity (Typ);
4632 loop
4633 Write_Id (Param);
4634 Write_Str (" : ");
4636 if Ekind (Param) = E_In_Out_Parameter then
4637 Write_Str ("in out ");
4638 elsif Ekind (Param) = E_Out_Parameter then
4639 Write_Str ("out ");
4640 end if;
4642 Write_Id (Etype (Param));
4643 Next_Entity (Param);
4644 exit when No (Param);
4645 Write_Str (", ");
4646 end loop;
4648 if Present (Extra_Formals (Typ)) then
4649 Param := Extra_Formals (Typ);
4651 while Present (Param) loop
4652 Write_Str (", ");
4653 Write_Id (Param);
4654 Write_Str (" : ");
4655 Write_Id (Etype (Param));
4657 Param := Extra_Formal (Param);
4658 end loop;
4659 end if;
4661 Write_Char (')');
4662 end;
4664 elsif Present (Extra_Formals (Typ)) then
4665 declare
4666 Param : Entity_Id;
4668 begin
4669 Write_Str (" (");
4671 Param := Extra_Formals (Typ);
4673 while Present (Param) loop
4674 Write_Id (Param);
4675 Write_Str (" : ");
4676 Write_Id (Etype (Param));
4678 if Present (Extra_Formal (Param)) then
4679 Write_Str (", ");
4680 end if;
4682 Param := Extra_Formal (Param);
4683 end loop;
4685 Write_Char (')');
4686 end;
4687 end if;
4689 if Etype (Typ) /= Standard_Void_Type then
4690 Write_Str (" return ");
4691 Write_Id (Etype (Typ));
4692 end if;
4694 when E_String_Literal_Subtype =>
4695 declare
4696 L : constant Uint :=
4697 Expr_Value (String_Literal_Low_Bound (Typ));
4698 Len : constant Uint :=
4699 String_Literal_Length (Typ);
4700 begin
4701 Write_Header (False);
4702 Write_Str ("String (");
4703 Write_Int (UI_To_Int (L));
4704 Write_Str (" .. ");
4705 Write_Int (UI_To_Int (L + Len) - 1);
4706 Write_Str (");");
4707 end;
4709 -- For all other Itypes, print a triple ? (fill in later
4710 -- if needed).
4712 when others =>
4713 Write_Header (True);
4714 Write_Str ("???");
4715 end case;
4716 end if;
4718 -- Add terminating bracket and restore output buffer
4720 Write_Char (']');
4721 Write_Eol;
4722 Restore_Output_Buffer (S);
4723 end;
4725 Set_Itype_Printed (Typ);
4726 end if;
4727 end Write_Itype;
4729 -------------------------------
4730 -- Write_Name_With_Col_Check --
4731 -------------------------------
4733 procedure Write_Name_With_Col_Check (N : Name_Id) is
4734 J : Natural;
4735 K : Natural;
4736 L : Natural;
4738 begin
4739 -- Avoid crashing on invalid Name_Ids
4741 if not Is_Valid_Name (N) then
4742 Write_Str ("<invalid name ");
4743 Write_Int (Int (N));
4744 Write_Str (">");
4745 return;
4746 end if;
4748 Get_Name_String (N);
4750 -- Deal with -gnatdI which replaces any sequence Cnnnb where C is an
4751 -- upper case letter, nnn is one or more digits and b is a lower case
4752 -- letter by C...b, so that listings do not depend on serial numbers.
4754 if Debug_Flag_II then
4755 J := 1;
4756 while J < Name_Len - 1 loop
4757 if Name_Buffer (J) in 'A' .. 'Z'
4758 and then Name_Buffer (J + 1) in '0' .. '9'
4759 then
4760 K := J + 1;
4761 while K < Name_Len loop
4762 exit when Name_Buffer (K) not in '0' .. '9';
4763 K := K + 1;
4764 end loop;
4766 if Name_Buffer (K) in 'a' .. 'z' then
4767 L := Name_Len - K + 1;
4769 Name_Buffer (J + 4 .. J + L + 3) :=
4770 Name_Buffer (K .. Name_Len);
4771 Name_Buffer (J + 1 .. J + 3) := "...";
4772 Name_Len := J + L + 3;
4773 J := J + 5;
4775 else
4776 J := K;
4777 end if;
4779 else
4780 J := J + 1;
4781 end if;
4782 end loop;
4783 end if;
4785 -- Fall through for normal case
4787 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
4788 end Write_Name_With_Col_Check;
4790 ------------------------------------
4791 -- Write_Name_With_Col_Check_Sloc --
4792 ------------------------------------
4794 procedure Write_Name_With_Col_Check_Sloc (N : Name_Id) is
4795 begin
4796 -- Avoid crashing on invalid Name_Ids
4798 if not Is_Valid_Name (N) then
4799 Write_Str ("<invalid name ");
4800 Write_Int (Int (N));
4801 Write_Str (">");
4802 return;
4803 end if;
4805 Get_Name_String (N);
4806 Write_Str_With_Col_Check_Sloc (Name_Buffer (1 .. Name_Len));
4807 end Write_Name_With_Col_Check_Sloc;
4809 --------------------
4810 -- Write_Operator --
4811 --------------------
4813 procedure Write_Operator (N : Node_Id; S : String) is
4814 F : Natural := S'First;
4815 T : Natural := S'Last;
4817 begin
4818 -- If no overflow check, just write string out, and we are done
4820 if not Do_Overflow_Check (N) then
4821 Write_Str_Sloc (S);
4823 -- If overflow check, we want to surround the operator with curly
4824 -- brackets, but not include spaces within the brackets.
4826 else
4827 if S (F) = ' ' then
4828 Write_Char (' ');
4829 F := F + 1;
4830 end if;
4832 if S (T) = ' ' then
4833 T := T - 1;
4834 end if;
4836 Write_Char ('{');
4837 Write_Str_Sloc (S (F .. T));
4838 Write_Char ('}');
4840 if S (S'Last) = ' ' then
4841 Write_Char (' ');
4842 end if;
4843 end if;
4844 end Write_Operator;
4846 -----------------------
4847 -- Write_Param_Specs --
4848 -----------------------
4850 procedure Write_Param_Specs (N : Node_Id) is
4851 Specs : constant List_Id := Parameter_Specifications (N);
4852 Specs_Present : constant Boolean := Is_Non_Empty_List (Specs);
4854 Ent : Entity_Id;
4855 Extras : Node_Id;
4856 Spec : Node_Id;
4857 Formal : Node_Id;
4859 Output : Boolean := False;
4860 -- Set true if we output at least one parameter
4862 begin
4863 -- Write out explicit specs from Parameter_Specifications list
4865 if Specs_Present then
4866 Write_Str_With_Col_Check (" (");
4867 Output := True;
4869 Spec := First (Specs);
4870 loop
4871 Sprint_Node (Spec);
4872 Formal := Defining_Identifier (Spec);
4873 Next (Spec);
4874 exit when Spec = Empty;
4876 -- Add semicolon, unless we are printing original tree and the
4877 -- next specification is part of a list (but not the first element
4878 -- of that list).
4880 if not Dump_Original_Only or else not Prev_Ids (Spec) then
4881 Write_Str ("; ");
4882 end if;
4883 end loop;
4884 end if;
4886 -- See if we have extra formals
4888 if Nkind (N) in N_Function_Specification | N_Procedure_Specification then
4889 Ent := Defining_Entity (N);
4891 -- Loop to write extra formals (if any)
4893 if Present (Ent) and then Is_Subprogram (Ent) then
4894 Extras := Extra_Formals (Ent);
4896 if Present (Extras) then
4897 if not Specs_Present then
4898 Write_Str_With_Col_Check (" (");
4899 Output := True;
4900 end if;
4902 Formal := Extras;
4903 while Present (Formal) loop
4904 if Specs_Present or else Formal /= Extras then
4905 Write_Str ("; ");
4906 end if;
4908 Write_Name_With_Col_Check (Chars (Formal));
4909 Write_Str (" : ");
4910 Write_Name_With_Col_Check (Chars (Etype (Formal)));
4911 Formal := Extra_Formal (Formal);
4912 end loop;
4913 end if;
4914 end if;
4915 end if;
4917 if Output then
4918 Write_Char (')');
4919 end if;
4920 end Write_Param_Specs;
4922 -----------------------
4923 -- Write_Rewrite_Str --
4924 -----------------------
4926 procedure Write_Rewrite_Str (S : String) is
4927 begin
4928 if not Dump_Generated_Only then
4929 if S'Length = 3 and then S = ">>>" then
4930 Write_Str (">>>");
4931 else
4932 Write_Str_With_Col_Check (S);
4933 end if;
4934 end if;
4935 end Write_Rewrite_Str;
4937 -----------------------
4938 -- Write_Source_Line --
4939 -----------------------
4941 procedure Write_Source_Line (L : Physical_Line_Number) is
4942 Loc : Source_Ptr;
4943 Src : Source_Buffer_Ptr;
4944 Scn : Source_Ptr;
4946 begin
4947 if Dump_Source_Text then
4948 Src := Source_Text (Current_Source_File);
4949 Loc := Line_Start (L, Current_Source_File);
4950 Write_Eol;
4952 -- See if line is a comment line, if not, and if not line one,
4953 -- precede with blank line.
4955 Scn := Loc;
4956 while Src (Scn) = ' ' or else Src (Scn) = ASCII.HT loop
4957 Scn := Scn + 1;
4958 end loop;
4960 if (Src (Scn) in Line_Terminator
4961 or else Src (Scn .. Scn + 1) /= "--")
4962 and then L /= 1
4963 then
4964 Write_Eol;
4965 end if;
4967 -- Now write the source text of the line
4969 Write_Str ("-- ");
4970 Write_Int (Int (L));
4971 Write_Str (": ");
4973 -- We need to check for EOF here, in case the last line of the source
4974 -- file does not have a Line_Terminator.
4976 while Src (Loc) not in Line_Terminator | EOF loop
4977 Write_Char (Src (Loc));
4978 Loc := Loc + 1;
4979 end loop;
4980 end if;
4981 end Write_Source_Line;
4983 ------------------------
4984 -- Write_Source_Lines --
4985 ------------------------
4987 procedure Write_Source_Lines (L : Physical_Line_Number) is
4988 begin
4989 while Last_Line_Printed < L loop
4990 Last_Line_Printed := Last_Line_Printed + 1;
4991 Write_Source_Line (Last_Line_Printed);
4992 end loop;
4993 end Write_Source_Lines;
4995 --------------------
4996 -- Write_Str_Sloc --
4997 --------------------
4999 procedure Write_Str_Sloc (S : String) is
5000 begin
5001 for J in S'Range loop
5002 Write_Char_Sloc (S (J));
5003 end loop;
5004 end Write_Str_Sloc;
5006 ------------------------------
5007 -- Write_Str_With_Col_Check --
5008 ------------------------------
5010 procedure Write_Str_With_Col_Check (S : String) is
5011 begin
5012 if Int (S'Last) + Column > Sprint_Line_Limit then
5013 Write_Indent_Str (" ");
5015 if S (S'First) = ' ' then
5016 Write_Str (S (S'First + 1 .. S'Last));
5017 else
5018 Write_Str (S);
5019 end if;
5021 else
5022 Write_Str (S);
5023 end if;
5024 end Write_Str_With_Col_Check;
5026 -----------------------------------
5027 -- Write_Str_With_Col_Check_Sloc --
5028 -----------------------------------
5030 procedure Write_Str_With_Col_Check_Sloc (S : String) is
5031 begin
5032 if Int (S'Last) + Column > Sprint_Line_Limit then
5033 Write_Indent_Str (" ");
5035 if S (S'First) = ' ' then
5036 Write_Str_Sloc (S (S'First + 1 .. S'Last));
5037 else
5038 Write_Str_Sloc (S);
5039 end if;
5041 else
5042 Write_Str_Sloc (S);
5043 end if;
5044 end Write_Str_With_Col_Check_Sloc;
5046 ---------------------------
5047 -- Write_Subprogram_Name --
5048 ---------------------------
5050 procedure Write_Subprogram_Name (N : Node_Id) is
5051 begin
5052 if not Comes_From_Source (N)
5053 and then Is_Entity_Name (N)
5054 then
5055 declare
5056 Ent : constant Entity_Id := Entity (N);
5057 begin
5058 if not In_Extended_Main_Source_Unit (Ent)
5059 and then In_Predefined_Unit (Ent)
5060 then
5061 -- Run-time routine name, output name with a preceding dollar
5062 -- making sure that we do not get a line split between them.
5064 Col_Check (Length_Of_Name (Chars (Ent)) + 1);
5065 Write_Char ('$');
5066 Write_Name (Chars (Ent));
5067 return;
5068 end if;
5069 end;
5070 end if;
5072 -- Normal case, not a run-time routine name
5074 Sprint_Node (N);
5075 end Write_Subprogram_Name;
5077 -------------------------------
5078 -- Write_Uint_With_Col_Check --
5079 -------------------------------
5081 procedure Write_Uint_With_Col_Check (U : Uint; Format : UI_Format) is
5082 begin
5083 Col_Check (UI_Decimal_Digits_Hi (U));
5084 UI_Write (U, Format);
5085 end Write_Uint_With_Col_Check;
5087 ------------------------------------
5088 -- Write_Uint_With_Col_Check_Sloc --
5089 ------------------------------------
5091 procedure Write_Uint_With_Col_Check_Sloc (U : Uint; Format : UI_Format) is
5092 begin
5093 Col_Check (UI_Decimal_Digits_Hi (U));
5094 Set_Debug_Sloc;
5095 UI_Write (U, Format);
5096 end Write_Uint_With_Col_Check_Sloc;
5098 -------------------------------------
5099 -- Write_Ureal_With_Col_Check_Sloc --
5100 -------------------------------------
5102 procedure Write_Ureal_With_Col_Check_Sloc (U : Ureal) is
5103 D : constant Uint := Denominator (U);
5104 N : constant Uint := Numerator (U);
5105 begin
5106 Col_Check (UI_Decimal_Digits_Hi (D) + UI_Decimal_Digits_Hi (N) + 4);
5107 Set_Debug_Sloc;
5108 UR_Write (U, Brackets => True);
5109 end Write_Ureal_With_Col_Check_Sloc;
5111 end Sprint;