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