2008-05-30 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / ada / sprint.adb
blob4306ce41450a38b6c369949cf215cd3efd03f82c
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S P R I N T --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2008, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Casing; use Casing;
28 with Csets; use Csets;
29 with Debug; use Debug;
30 with Einfo; use Einfo;
31 with Fname; use Fname;
32 with Lib; use Lib;
33 with Namet; use Namet;
34 with Nlists; use Nlists;
35 with Opt; use Opt;
36 with Output; use Output;
37 with Rtsfind; use Rtsfind;
38 with Sem_Util; use Sem_Util;
39 with Sinfo; use Sinfo;
40 with Sinput; use Sinput;
41 with Sinput.D; use Sinput.D;
42 with Snames; use Snames;
43 with Stand; use Stand;
44 with Stringt; use Stringt;
45 with Uintp; use Uintp;
46 with Uname; use Uname;
47 with Urealp; use Urealp;
49 package body Sprint is
50 Current_Source_File : Source_File_Index;
51 -- Index of source file whose generated code is being dumped
53 Dump_Node : Node_Id := Empty;
54 -- This is set to the current node, used for printing line numbers. In
55 -- Debug_Generated_Code mode, Dump_Node is set to the current node
56 -- requiring Sloc fixup, until Set_Debug_Sloc is called to set the proper
57 -- value. The call clears it back to Empty.
59 Debug_Sloc : Source_Ptr;
60 -- Sloc of first byte of line currently being written if we are
61 -- generating a source debug file.
63 Dump_Original_Only : Boolean;
64 -- Set True if the -gnatdo (dump original tree) flag is set
66 Dump_Generated_Only : Boolean;
67 -- Set True if the -gnatG (dump generated tree) debug flag is set
68 -- or for Print_Generated_Code (-gnatG) or Dump_Generated_Code (-gnatD).
70 Dump_Freeze_Null : Boolean;
71 -- Set True if freeze nodes and non-source null statements output
73 Freeze_Indent : Int := 0;
74 -- Keep track of freeze indent level (controls output of blank lines before
75 -- procedures within expression freeze actions). Relevant only if we are
76 -- not in Dump_Source_Text mode, since in Dump_Source_Text mode we don't
77 -- output these blank lines in any case.
79 Indent : Int := 0;
80 -- Number of columns for current line output indentation
82 Indent_Annull_Flag : Boolean := False;
83 -- Set True if subsequent Write_Indent call to be ignored, gets reset
84 -- by this call, so it is only active to suppress a single indent call.
86 Last_Line_Printed : Physical_Line_Number;
87 -- This keeps track of the physical line number of the last source line
88 -- that has been output. The value is only valid in Dump_Source_Text mode.
90 Line_Limit : constant := 72;
91 -- Limit value for chopping long lines
93 -------------------------------
94 -- Operator Precedence Table --
95 -------------------------------
97 -- This table is used to decide whether a subexpression needs to be
98 -- parenthesized. The rule is that if an operand of an operator (which
99 -- for this purpose includes AND THEN and OR ELSE) is itself an operator
100 -- with a lower precedence than the operator (or equal precedence if
101 -- appearing as the right operand), then parentheses are required.
103 Op_Prec : constant array (N_Subexpr) of Short_Short_Integer :=
104 (N_Op_And => 1,
105 N_Op_Or => 1,
106 N_Op_Xor => 1,
107 N_And_Then => 1,
108 N_Or_Else => 1,
110 N_In => 2,
111 N_Not_In => 2,
112 N_Op_Eq => 2,
113 N_Op_Ge => 2,
114 N_Op_Gt => 2,
115 N_Op_Le => 2,
116 N_Op_Lt => 2,
117 N_Op_Ne => 2,
119 N_Op_Add => 3,
120 N_Op_Concat => 3,
121 N_Op_Subtract => 3,
122 N_Op_Plus => 3,
123 N_Op_Minus => 3,
125 N_Op_Divide => 4,
126 N_Op_Mod => 4,
127 N_Op_Rem => 4,
128 N_Op_Multiply => 4,
130 N_Op_Expon => 5,
131 N_Op_Abs => 5,
132 N_Op_Not => 5,
134 others => 6);
136 procedure Sprint_Left_Opnd (N : Node_Id);
137 -- Print left operand of operator, parenthesizing if necessary
139 procedure Sprint_Right_Opnd (N : Node_Id);
140 -- Print right operand of operator, parenthesizing if necessary
142 -----------------------
143 -- Local Subprograms --
144 -----------------------
146 procedure Col_Check (N : Nat);
147 -- Check that at least N characters remain on current line, and if not,
148 -- then start an extra line with two characters extra indentation for
149 -- continuing text on the next line.
151 procedure Extra_Blank_Line;
152 -- In some situations we write extra blank lines to separate the generated
153 -- code to make it more readable. However, these extra blank lines are not
154 -- generated in Dump_Source_Text mode, since there the source text lines
155 -- output with preceding blank lines are quite sufficient as separators.
156 -- This procedure writes a blank line if Dump_Source_Text is False.
158 procedure Indent_Annull;
159 -- Causes following call to Write_Indent to be ignored. This is used when
160 -- a higher level node wants to stop a lower level node from starting a
161 -- new line, when it would otherwise be inclined to do so (e.g. the case
162 -- of an accept statement called from an accept alternative with a guard)
164 procedure Indent_Begin;
165 -- Increase indentation level
167 procedure Indent_End;
168 -- Decrease indentation level
170 procedure Note_Implicit_Run_Time_Call (N : Node_Id);
171 -- N is the Name field of a function call or procedure statement call.
172 -- The effect of the call is to output a $ if the call is identified as
173 -- an implicit call to a run time routine.
175 procedure Print_Debug_Line (S : String);
176 -- Used to print output lines in Debug_Generated_Code mode (this is used
177 -- as the argument for a call to Set_Special_Output in package Output).
179 procedure Process_TFAI_RR_Flags (Nod : Node_Id);
180 -- Given a divide, multiplication or division node, check the flags
181 -- Treat_Fixed_As_Integer and Rounded_Flags, and if set, output the
182 -- appropriate special syntax characters (# and @).
184 procedure Set_Debug_Sloc;
185 -- If Dump_Node is non-empty, this routine sets the appropriate value
186 -- in its Sloc field, from the current location in the debug source file
187 -- that is currently being written.
189 procedure Sprint_And_List (List : List_Id);
190 -- Print the given list with items separated by vertical "and"
192 procedure Sprint_Bar_List (List : List_Id);
193 -- Print the given list with items separated by vertical bars
195 procedure Sprint_End_Label
196 (Node : Node_Id;
197 Default : Node_Id);
198 -- Print the end label for a Handled_Sequence_Of_Statements in a body.
199 -- If there is not end label, use the defining identifier of the enclosing
200 -- construct. If the end label is present, treat it as a reference to the
201 -- defining entity of the construct: this guarantees that it carries the
202 -- proper sloc information for debugging purposes.
204 procedure Sprint_Node_Actual (Node : Node_Id);
205 -- This routine prints its node argument. It is a lower level routine than
206 -- Sprint_Node, in that it does not bother about rewritten trees.
208 procedure Sprint_Node_Sloc (Node : Node_Id);
209 -- Like Sprint_Node, but in addition, in Debug_Generated_Code mode,
210 -- sets the Sloc of the current debug node to be a copy of the Sloc
211 -- of the sprinted node Node. Note that this is done after printing
212 -- Node, so that the Sloc is the proper updated value for the debug file.
214 procedure Update_Itype (Node : Node_Id);
215 -- Update the Sloc of an itype that is not attached to the tree, when
216 -- debugging expanded code. This routine is called from nodes whose
217 -- type can be an Itype, such as defining_identifiers that may be of
218 -- an anonymous access type, or ranges in slices.
220 procedure Write_Char_Sloc (C : Character);
221 -- Like Write_Char, except that if C is non-blank, Set_Debug_Sloc is
222 -- called to ensure that the current node has a proper Sloc set.
224 procedure Write_Condition_And_Reason (Node : Node_Id);
225 -- Write Condition and Reason codes of Raise_xxx_Error node
227 procedure Write_Corresponding_Source (S : String);
228 -- If S is a string with a single keyword (possibly followed by a space),
229 -- and if the next non-comment non-blank source line matches this keyword,
230 -- then output all source lines up to this matching line.
232 procedure Write_Discr_Specs (N : Node_Id);
233 -- Output discriminant specification for node, which is any of the type
234 -- declarations that can have discriminants.
236 procedure Write_Ekind (E : Entity_Id);
237 -- Write the String corresponding to the Ekind without "E_"
239 procedure Write_Id (N : Node_Id);
240 -- N is a node with a Chars field. This procedure writes the name that
241 -- will be used in the generated code associated with the name. For a
242 -- node with no associated entity, this is simply the Chars field. For
243 -- the case where there is an entity associated with the node, we print
244 -- the name associated with the entity (since it may have been encoded).
245 -- One other special case is that an entity has an active external name
246 -- (i.e. an external name present with no address clause), then this
247 -- external name is output. This procedure also deals with outputting
248 -- declarations of referenced itypes, if not output earlier.
250 function Write_Identifiers (Node : Node_Id) return Boolean;
251 -- Handle node where the grammar has a list of defining identifiers, but
252 -- the tree has a separate declaration for each identifier. Handles the
253 -- printing of the defining identifier, and returns True if the type and
254 -- initialization information is to be printed, False if it is to be
255 -- skipped (the latter case happens when printing defining identifiers
256 -- other than the first in the original tree output case).
258 procedure Write_Implicit_Def (E : Entity_Id);
259 pragma Warnings (Off, Write_Implicit_Def);
260 -- Write the definition of the implicit type E according to its Ekind
261 -- For now a debugging procedure, but might be used in the future.
263 procedure Write_Indent;
264 -- Start a new line and write indentation spacing
266 function Write_Indent_Identifiers (Node : Node_Id) return Boolean;
267 -- Like Write_Identifiers except that each new printed declaration
268 -- is at the start of a new line.
270 function Write_Indent_Identifiers_Sloc (Node : Node_Id) return Boolean;
271 -- Like Write_Indent_Identifiers except that in Debug_Generated_Code
272 -- mode, the Sloc of the current debug node is set to point to the
273 -- first output identifier.
275 procedure Write_Indent_Str (S : String);
276 -- Start a new line and write indent spacing followed by given string
278 procedure Write_Indent_Str_Sloc (S : String);
279 -- Like Write_Indent_Str, but in addition, in Debug_Generated_Code mode,
280 -- the Sloc of the current node is set to the first non-blank character
281 -- in the string S.
283 procedure Write_Itype (Typ : Entity_Id);
284 -- If Typ is an Itype that has not been written yet, write it. If Typ is
285 -- any other kind of entity or tree node, the call is ignored.
287 procedure Write_Name_With_Col_Check (N : Name_Id);
288 -- Write name (using Write_Name) with initial column check, and possible
289 -- initial Write_Indent (to get new line) if current line is too full.
291 procedure Write_Name_With_Col_Check_Sloc (N : Name_Id);
292 -- Like Write_Name_With_Col_Check but in addition, in Debug_Generated_Code
293 -- mode, sets Sloc of current debug node to first character of name.
295 procedure Write_Operator (N : Node_Id; S : String);
296 -- Like Write_Str_Sloc, used for operators, encloses the string in
297 -- characters {} if the Do_Overflow flag is set on the node N.
299 procedure Write_Param_Specs (N : Node_Id);
300 -- Output parameter specifications for node (which is either a function
301 -- or procedure specification with a Parameter_Specifications field)
303 procedure Write_Rewrite_Str (S : String);
304 -- Writes out a string (typically containing <<< or >>>}) for a node
305 -- created by rewriting the tree. Suppressed if we are outputting the
306 -- generated code only, since in this case we don't specially mark nodes
307 -- created by rewriting).
309 procedure Write_Source_Line (L : Physical_Line_Number);
310 -- If writing of interspersed source lines is enabled, then write the given
311 -- line from the source file, preceded by Eol, then an extra blank line if
312 -- the line has at least one blank, is not a comment and is not line one,
313 -- then "--" and the line number followed by period followed by text of the
314 -- source line (without terminating Eol). If interspersed source line
315 -- output not enabled, then the call has no effect.
317 procedure Write_Source_Lines (L : Physical_Line_Number);
318 -- If writing of interspersed source lines is enabled, then writes source
319 -- lines Last_Line_Printed + 1 .. L, and updates Last_Line_Printed. If
320 -- interspersed source line output not enabled, then call has no effect.
322 procedure Write_Str_Sloc (S : String);
323 -- Like Write_Str, but sets debug Sloc of current debug node to first
324 -- non-blank character if a current debug node is active.
326 procedure Write_Str_With_Col_Check (S : String);
327 -- Write string (using Write_Str) with initial column check, and possible
328 -- initial Write_Indent (to get new line) if current line is too full.
330 procedure Write_Str_With_Col_Check_Sloc (S : String);
331 -- Like Write_Str_With_Col_Check, but sets debug Sloc of current debug
332 -- node to first non-blank character if a current debug node is active.
334 procedure Write_Uint_With_Col_Check (U : Uint; Format : UI_Format);
335 -- Write Uint (using UI_Write) with initial column check, and possible
336 -- initial Write_Indent (to get new line) if current line is too full.
337 -- The format parameter determines the output format (see UI_Write).
339 procedure Write_Uint_With_Col_Check_Sloc (U : Uint; Format : UI_Format);
340 -- Write Uint (using UI_Write) with initial column check, and possible
341 -- initial Write_Indent (to get new line) if current line is too full.
342 -- The format parameter determines the output format (see UI_Write).
343 -- In addition, in Debug_Generated_Code mode, sets the current node
344 -- Sloc to the first character of the output value.
346 procedure Write_Ureal_With_Col_Check_Sloc (U : Ureal);
347 -- Write Ureal (using same output format as UR_Write) with column checks
348 -- and a possible initial Write_Indent (to get new line) if current line
349 -- is too full. In addition, in Debug_Generated_Code mode, sets the
350 -- current node Sloc to the first character of the output value.
352 ---------------
353 -- Col_Check --
354 ---------------
356 procedure Col_Check (N : Nat) is
357 begin
358 if N + Column > Line_Limit then
359 Write_Indent_Str (" ");
360 end if;
361 end Col_Check;
363 ----------------------
364 -- Extra_Blank_Line --
365 ----------------------
367 procedure Extra_Blank_Line is
368 begin
369 if not Dump_Source_Text then
370 Write_Indent;
371 end if;
372 end Extra_Blank_Line;
374 -------------------
375 -- Indent_Annull --
376 -------------------
378 procedure Indent_Annull is
379 begin
380 Indent_Annull_Flag := True;
381 end Indent_Annull;
383 ------------------
384 -- Indent_Begin --
385 ------------------
387 procedure Indent_Begin is
388 begin
389 Indent := Indent + 3;
390 end Indent_Begin;
392 ----------------
393 -- Indent_End --
394 ----------------
396 procedure Indent_End is
397 begin
398 Indent := Indent - 3;
399 end Indent_End;
401 ---------------------------------
402 -- Note_Implicit_Run_Time_Call --
403 ---------------------------------
405 procedure Note_Implicit_Run_Time_Call (N : Node_Id) is
406 begin
407 if not Comes_From_Source (N)
408 and then Is_Entity_Name (N)
409 then
410 declare
411 Ent : constant Entity_Id := Entity (N);
412 begin
413 if not In_Extended_Main_Source_Unit (Ent)
414 and then
415 Is_Predefined_File_Name
416 (Unit_File_Name (Get_Source_Unit (Ent)))
417 then
418 Col_Check (Length_Of_Name (Chars (Ent)));
419 Write_Char ('$');
420 end if;
421 end;
422 end if;
423 end Note_Implicit_Run_Time_Call;
425 --------
426 -- pg --
427 --------
429 procedure pg (Arg : Union_Id) is
430 begin
431 Dump_Generated_Only := True;
432 Dump_Original_Only := False;
433 Current_Source_File := No_Source_File;
435 if Arg in List_Range then
436 Sprint_Node_List (List_Id (Arg));
438 elsif Arg in Node_Range then
439 Sprint_Node (Node_Id (Arg));
441 else
442 null;
443 end if;
445 Write_Eol;
446 end pg;
448 --------
449 -- po --
450 --------
452 procedure po (Arg : Union_Id) is
453 begin
454 Dump_Generated_Only := False;
455 Dump_Original_Only := True;
456 Current_Source_File := No_Source_File;
458 if Arg in List_Range then
459 Sprint_Node_List (List_Id (Arg));
461 elsif Arg in Node_Range then
462 Sprint_Node (Node_Id (Arg));
464 else
465 null;
466 end if;
468 Write_Eol;
469 end po;
471 ----------------------
472 -- Print_Debug_Line --
473 ----------------------
475 procedure Print_Debug_Line (S : String) is
476 begin
477 Write_Debug_Line (S, Debug_Sloc);
478 end Print_Debug_Line;
480 ---------------------------
481 -- Process_TFAI_RR_Flags --
482 ---------------------------
484 procedure Process_TFAI_RR_Flags (Nod : Node_Id) is
485 begin
486 if Treat_Fixed_As_Integer (Nod) then
487 Write_Char ('#');
488 end if;
490 if Rounded_Result (Nod) then
491 Write_Char ('@');
492 end if;
493 end Process_TFAI_RR_Flags;
495 --------
496 -- ps --
497 --------
499 procedure ps (Arg : Union_Id) is
500 begin
501 Dump_Generated_Only := False;
502 Dump_Original_Only := False;
503 Current_Source_File := No_Source_File;
505 if Arg in List_Range then
506 Sprint_Node_List (List_Id (Arg));
508 elsif Arg in Node_Range then
509 Sprint_Node (Node_Id (Arg));
511 else
512 null;
513 end if;
515 Write_Eol;
516 end ps;
518 --------------------
519 -- Set_Debug_Sloc --
520 --------------------
522 procedure Set_Debug_Sloc is
523 begin
524 if Debug_Generated_Code and then Present (Dump_Node) then
525 Set_Sloc (Dump_Node, Debug_Sloc + Source_Ptr (Column - 1));
526 Dump_Node := Empty;
527 end if;
528 end Set_Debug_Sloc;
530 -----------------
531 -- Source_Dump --
532 -----------------
534 procedure Source_Dump is
536 procedure Underline;
537 -- Put underline under string we just printed
539 ---------------
540 -- Underline --
541 ---------------
543 procedure Underline is
544 Col : constant Int := Column;
546 begin
547 Write_Eol;
549 while Col > Column loop
550 Write_Char ('-');
551 end loop;
553 Write_Eol;
554 end Underline;
556 -- Start of processing for Tree_Dump
558 begin
559 Dump_Generated_Only := Debug_Flag_G or
560 Print_Generated_Code or
561 Debug_Generated_Code;
562 Dump_Original_Only := Debug_Flag_O;
563 Dump_Freeze_Null := Debug_Flag_S or Debug_Flag_G;
565 -- Note that we turn off the tree dump flags immediately, before
566 -- starting the dump. This avoids generating two copies of the dump
567 -- if an abort occurs after printing the dump, and more importantly,
568 -- avoids an infinite loop if an abort occurs during the dump.
570 if Debug_Flag_Z then
571 Current_Source_File := No_Source_File;
572 Debug_Flag_Z := False;
573 Write_Eol;
574 Write_Eol;
575 Write_Str ("Source recreated from tree of Standard (spec)");
576 Underline;
577 Sprint_Node (Standard_Package_Node);
578 Write_Eol;
579 Write_Eol;
580 end if;
582 if Debug_Flag_S or Dump_Generated_Only or Dump_Original_Only then
583 Debug_Flag_G := False;
584 Debug_Flag_O := False;
585 Debug_Flag_S := False;
587 -- Dump requested units
589 for U in Main_Unit .. Last_Unit loop
590 Current_Source_File := Source_Index (U);
592 -- Dump all units if -gnatdf set, otherwise we dump only
593 -- the source files that are in the extended main source.
595 if Debug_Flag_F
596 or else In_Extended_Main_Source_Unit (Cunit_Entity (U))
597 then
598 -- If we are generating debug files, setup to write them
600 if Debug_Generated_Code then
601 Set_Special_Output (Print_Debug_Line'Access);
602 Create_Debug_Source (Source_Index (U), Debug_Sloc);
603 Write_Source_Line (1);
604 Last_Line_Printed := 1;
605 Sprint_Node (Cunit (U));
606 Write_Source_Lines (Last_Source_Line (Current_Source_File));
607 Write_Eol;
608 Close_Debug_Source;
609 Set_Special_Output (null);
611 -- Normal output to standard output file
613 else
614 Write_Str ("Source recreated from tree for ");
615 Write_Unit_Name (Unit_Name (U));
616 Underline;
617 Write_Source_Line (1);
618 Last_Line_Printed := 1;
619 Sprint_Node (Cunit (U));
620 Write_Source_Lines (Last_Source_Line (Current_Source_File));
621 Write_Eol;
622 Write_Eol;
623 end if;
624 end if;
625 end loop;
626 end if;
627 end Source_Dump;
629 ---------------------
630 -- Sprint_And_List --
631 ---------------------
633 procedure Sprint_And_List (List : List_Id) is
634 Node : Node_Id;
635 begin
636 if Is_Non_Empty_List (List) then
637 Node := First (List);
638 loop
639 Sprint_Node (Node);
640 Next (Node);
641 exit when Node = Empty;
642 Write_Str (" and ");
643 end loop;
644 end if;
645 end Sprint_And_List;
647 ---------------------
648 -- Sprint_Bar_List --
649 ---------------------
651 procedure Sprint_Bar_List (List : List_Id) is
652 Node : Node_Id;
653 begin
654 if Is_Non_Empty_List (List) then
655 Node := First (List);
656 loop
657 Sprint_Node (Node);
658 Next (Node);
659 exit when Node = Empty;
660 Write_Str (" | ");
661 end loop;
662 end if;
663 end Sprint_Bar_List;
665 ----------------------
666 -- Sprint_End_Label --
667 ----------------------
669 procedure Sprint_End_Label
670 (Node : Node_Id;
671 Default : Node_Id)
673 begin
674 if Present (Node)
675 and then Present (End_Label (Node))
676 and then Is_Entity_Name (End_Label (Node))
677 then
678 Set_Entity (End_Label (Node), Default);
680 -- For a function whose name is an operator, use the qualified name
681 -- created for the defining entity.
683 if Nkind (End_Label (Node)) = N_Operator_Symbol then
684 Set_Chars (End_Label (Node), Chars (Default));
685 end if;
687 Sprint_Node (End_Label (Node));
688 else
689 Sprint_Node (Default);
690 end if;
691 end Sprint_End_Label;
693 -----------------------
694 -- Sprint_Comma_List --
695 -----------------------
697 procedure Sprint_Comma_List (List : List_Id) is
698 Node : Node_Id;
700 begin
701 if Is_Non_Empty_List (List) then
702 Node := First (List);
703 loop
704 Sprint_Node (Node);
705 Next (Node);
706 exit when Node = Empty;
708 if not Is_Rewrite_Insertion (Node)
709 or else not Dump_Original_Only
710 then
711 Write_Str (", ");
712 end if;
713 end loop;
714 end if;
715 end Sprint_Comma_List;
717 --------------------------
718 -- Sprint_Indented_List --
719 --------------------------
721 procedure Sprint_Indented_List (List : List_Id) is
722 begin
723 Indent_Begin;
724 Sprint_Node_List (List);
725 Indent_End;
726 end Sprint_Indented_List;
728 ---------------------
729 -- Sprint_Left_Opnd --
730 ---------------------
732 procedure Sprint_Left_Opnd (N : Node_Id) is
733 Opnd : constant Node_Id := Left_Opnd (N);
735 begin
736 if Paren_Count (Opnd) /= 0
737 or else Op_Prec (Nkind (Opnd)) >= Op_Prec (Nkind (N))
738 then
739 Sprint_Node (Opnd);
741 else
742 Write_Char ('(');
743 Sprint_Node (Opnd);
744 Write_Char (')');
745 end if;
746 end Sprint_Left_Opnd;
748 -----------------
749 -- Sprint_Node --
750 -----------------
752 procedure Sprint_Node (Node : Node_Id) is
753 begin
754 if Is_Rewrite_Insertion (Node) then
755 if not Dump_Original_Only then
757 -- For special cases of nodes that always output <<< >>>
758 -- do not duplicate the output at this point.
760 if Nkind (Node) = N_Freeze_Entity
761 or else Nkind (Node) = N_Implicit_Label_Declaration
762 then
763 Sprint_Node_Actual (Node);
765 -- Normal case where <<< >>> may be required
767 else
768 Write_Rewrite_Str ("<<<");
769 Sprint_Node_Actual (Node);
770 Write_Rewrite_Str (">>>");
771 end if;
772 end if;
774 elsif Is_Rewrite_Substitution (Node) then
776 -- Case of dump generated only
778 if Dump_Generated_Only then
779 Sprint_Node_Actual (Node);
781 -- Case of dump original only
783 elsif Dump_Original_Only then
784 Sprint_Node_Actual (Original_Node (Node));
786 -- Case of both being dumped
788 else
789 Sprint_Node_Actual (Original_Node (Node));
790 Write_Rewrite_Str ("<<<");
791 Sprint_Node_Actual (Node);
792 Write_Rewrite_Str (">>>");
793 end if;
795 else
796 Sprint_Node_Actual (Node);
797 end if;
798 end Sprint_Node;
800 ------------------------
801 -- Sprint_Node_Actual --
802 ------------------------
804 procedure Sprint_Node_Actual (Node : Node_Id) is
805 Save_Dump_Node : constant Node_Id := Dump_Node;
807 begin
808 if Node = Empty then
809 return;
810 end if;
812 for J in 1 .. Paren_Count (Node) loop
813 Write_Str_With_Col_Check ("(");
814 end loop;
816 -- Setup current dump node
818 Dump_Node := Node;
820 if Nkind (Node) in N_Subexpr
821 and then Do_Range_Check (Node)
822 then
823 Write_Str_With_Col_Check ("{");
824 end if;
826 -- Select print circuit based on node kind
828 case Nkind (Node) is
830 when N_Abort_Statement =>
831 Write_Indent_Str_Sloc ("abort ");
832 Sprint_Comma_List (Names (Node));
833 Write_Char (';');
835 when N_Abortable_Part =>
836 Set_Debug_Sloc;
837 Write_Str_Sloc ("abort ");
838 Sprint_Indented_List (Statements (Node));
840 when N_Abstract_Subprogram_Declaration =>
841 Write_Indent;
842 Sprint_Node (Specification (Node));
843 Write_Str_With_Col_Check (" is ");
844 Write_Str_Sloc ("abstract;");
846 when N_Accept_Alternative =>
847 Sprint_Node_List (Pragmas_Before (Node));
849 if Present (Condition (Node)) then
850 Write_Indent_Str ("when ");
851 Sprint_Node (Condition (Node));
852 Write_Str (" => ");
853 Indent_Annull;
854 end if;
856 Sprint_Node_Sloc (Accept_Statement (Node));
857 Sprint_Node_List (Statements (Node));
859 when N_Accept_Statement =>
860 Write_Indent_Str_Sloc ("accept ");
861 Write_Id (Entry_Direct_Name (Node));
863 if Present (Entry_Index (Node)) then
864 Write_Str_With_Col_Check (" (");
865 Sprint_Node (Entry_Index (Node));
866 Write_Char (')');
867 end if;
869 Write_Param_Specs (Node);
871 if Present (Handled_Statement_Sequence (Node)) then
872 Write_Str_With_Col_Check (" do");
873 Sprint_Node (Handled_Statement_Sequence (Node));
874 Write_Indent_Str ("end ");
875 Write_Id (Entry_Direct_Name (Node));
876 end if;
878 Write_Char (';');
880 when N_Access_Definition =>
882 -- Ada 2005 (AI-254)
884 if Present (Access_To_Subprogram_Definition (Node)) then
885 Sprint_Node (Access_To_Subprogram_Definition (Node));
886 else
887 -- Ada 2005 (AI-231)
889 if Null_Exclusion_Present (Node) then
890 Write_Str ("not null ");
891 end if;
893 Write_Str_With_Col_Check_Sloc ("access ");
895 if All_Present (Node) then
896 Write_Str ("all ");
897 elsif Constant_Present (Node) then
898 Write_Str ("constant ");
899 end if;
901 Sprint_Node (Subtype_Mark (Node));
902 end if;
904 when N_Access_Function_Definition =>
906 -- Ada 2005 (AI-231)
908 if Null_Exclusion_Present (Node) then
909 Write_Str ("not null ");
910 end if;
912 Write_Str_With_Col_Check_Sloc ("access ");
914 if Protected_Present (Node) then
915 Write_Str_With_Col_Check ("protected ");
916 end if;
918 Write_Str_With_Col_Check ("function");
919 Write_Param_Specs (Node);
920 Write_Str_With_Col_Check (" return ");
921 Sprint_Node (Result_Definition (Node));
923 when N_Access_Procedure_Definition =>
925 -- Ada 2005 (AI-231)
927 if Null_Exclusion_Present (Node) then
928 Write_Str ("not null ");
929 end if;
931 Write_Str_With_Col_Check_Sloc ("access ");
933 if Protected_Present (Node) then
934 Write_Str_With_Col_Check ("protected ");
935 end if;
937 Write_Str_With_Col_Check ("procedure");
938 Write_Param_Specs (Node);
940 when N_Access_To_Object_Definition =>
941 Write_Str_With_Col_Check_Sloc ("access ");
943 if All_Present (Node) then
944 Write_Str_With_Col_Check ("all ");
945 elsif Constant_Present (Node) then
946 Write_Str_With_Col_Check ("constant ");
947 end if;
949 -- Ada 2005 (AI-231)
951 if Null_Exclusion_Present (Node) then
952 Write_Str ("not null ");
953 end if;
955 Sprint_Node (Subtype_Indication (Node));
957 when N_Aggregate =>
958 if Null_Record_Present (Node) then
959 Write_Str_With_Col_Check_Sloc ("(null record)");
961 else
962 Write_Str_With_Col_Check_Sloc ("(");
964 if Present (Expressions (Node)) then
965 Sprint_Comma_List (Expressions (Node));
967 if Present (Component_Associations (Node)) then
968 Write_Str (", ");
969 end if;
970 end if;
972 if Present (Component_Associations (Node)) then
973 Indent_Begin;
975 declare
976 Nd : Node_Id;
978 begin
979 Nd := First (Component_Associations (Node));
981 loop
982 Write_Indent;
983 Sprint_Node (Nd);
984 Next (Nd);
985 exit when No (Nd);
987 if not Is_Rewrite_Insertion (Nd)
988 or else not Dump_Original_Only
989 then
990 Write_Str (", ");
991 end if;
992 end loop;
993 end;
995 Indent_End;
996 end if;
998 Write_Char (')');
999 end if;
1001 when N_Allocator =>
1002 Write_Str_With_Col_Check_Sloc ("new ");
1004 -- Ada 2005 (AI-231)
1006 if Null_Exclusion_Present (Node) then
1007 Write_Str ("not null ");
1008 end if;
1010 Sprint_Node (Expression (Node));
1012 if Present (Storage_Pool (Node)) then
1013 Write_Str_With_Col_Check ("[storage_pool = ");
1014 Sprint_Node (Storage_Pool (Node));
1015 Write_Char (']');
1016 end if;
1018 when N_And_Then =>
1019 Sprint_Left_Opnd (Node);
1020 Write_Str_Sloc (" and then ");
1021 Sprint_Right_Opnd (Node);
1023 when N_At_Clause =>
1024 Write_Indent_Str_Sloc ("for ");
1025 Write_Id (Identifier (Node));
1026 Write_Str_With_Col_Check (" use at ");
1027 Sprint_Node (Expression (Node));
1028 Write_Char (';');
1030 when N_Assignment_Statement =>
1031 Write_Indent;
1032 Sprint_Node (Name (Node));
1033 Write_Str_Sloc (" := ");
1034 Sprint_Node (Expression (Node));
1035 Write_Char (';');
1037 when N_Asynchronous_Select =>
1038 Write_Indent_Str_Sloc ("select");
1039 Indent_Begin;
1040 Sprint_Node (Triggering_Alternative (Node));
1041 Indent_End;
1043 -- Note: let the printing of Abortable_Part handle outputting
1044 -- the ABORT keyword, so that the Sloc can be set correctly.
1046 Write_Indent_Str ("then ");
1047 Sprint_Node (Abortable_Part (Node));
1048 Write_Indent_Str ("end select;");
1050 when N_Attribute_Definition_Clause =>
1051 Write_Indent_Str_Sloc ("for ");
1052 Sprint_Node (Name (Node));
1053 Write_Char (''');
1054 Write_Name_With_Col_Check (Chars (Node));
1055 Write_Str_With_Col_Check (" use ");
1056 Sprint_Node (Expression (Node));
1057 Write_Char (';');
1059 when N_Attribute_Reference =>
1060 if Is_Procedure_Attribute_Name (Attribute_Name (Node)) then
1061 Write_Indent;
1062 end if;
1064 Sprint_Node (Prefix (Node));
1065 Write_Char_Sloc (''');
1066 Write_Name_With_Col_Check (Attribute_Name (Node));
1067 Sprint_Paren_Comma_List (Expressions (Node));
1069 if Is_Procedure_Attribute_Name (Attribute_Name (Node)) then
1070 Write_Char (';');
1071 end if;
1073 when N_Block_Statement =>
1074 Write_Indent;
1076 if Present (Identifier (Node))
1077 and then (not Has_Created_Identifier (Node)
1078 or else not Dump_Original_Only)
1079 then
1080 Write_Rewrite_Str ("<<<");
1081 Write_Id (Identifier (Node));
1082 Write_Str (" : ");
1083 Write_Rewrite_Str (">>>");
1084 end if;
1086 if Present (Declarations (Node)) then
1087 Write_Str_With_Col_Check_Sloc ("declare");
1088 Sprint_Indented_List (Declarations (Node));
1089 Write_Indent;
1090 end if;
1092 Write_Str_With_Col_Check_Sloc ("begin");
1093 Sprint_Node (Handled_Statement_Sequence (Node));
1094 Write_Indent_Str ("end");
1096 if Present (Identifier (Node))
1097 and then (not Has_Created_Identifier (Node)
1098 or else not Dump_Original_Only)
1099 then
1100 Write_Rewrite_Str ("<<<");
1101 Write_Char (' ');
1102 Write_Id (Identifier (Node));
1103 Write_Rewrite_Str (">>>");
1104 end if;
1106 Write_Char (';');
1108 when N_Case_Statement =>
1109 Write_Indent_Str_Sloc ("case ");
1110 Sprint_Node (Expression (Node));
1111 Write_Str (" is");
1112 Sprint_Indented_List (Alternatives (Node));
1113 Write_Indent_Str ("end case;");
1115 when N_Case_Statement_Alternative =>
1116 Write_Indent_Str_Sloc ("when ");
1117 Sprint_Bar_List (Discrete_Choices (Node));
1118 Write_Str (" => ");
1119 Sprint_Indented_List (Statements (Node));
1121 when N_Character_Literal =>
1122 if Column > 70 then
1123 Write_Indent_Str (" ");
1124 end if;
1126 Write_Char_Sloc (''');
1127 Write_Char_Code (UI_To_CC (Char_Literal_Value (Node)));
1128 Write_Char (''');
1130 when N_Code_Statement =>
1131 Write_Indent;
1132 Set_Debug_Sloc;
1133 Sprint_Node (Expression (Node));
1134 Write_Char (';');
1136 when N_Compilation_Unit =>
1137 Sprint_Node_List (Context_Items (Node));
1138 Sprint_Opt_Node_List (Declarations (Aux_Decls_Node (Node)));
1140 if Private_Present (Node) then
1141 Write_Indent_Str ("private ");
1142 Indent_Annull;
1143 end if;
1145 Sprint_Node_Sloc (Unit (Node));
1147 if Present (Actions (Aux_Decls_Node (Node)))
1148 or else
1149 Present (Pragmas_After (Aux_Decls_Node (Node)))
1150 then
1151 Write_Indent;
1152 end if;
1154 Sprint_Opt_Node_List (Actions (Aux_Decls_Node (Node)));
1155 Sprint_Opt_Node_List (Pragmas_After (Aux_Decls_Node (Node)));
1157 when N_Compilation_Unit_Aux =>
1158 null; -- nothing to do, never used, see above
1160 when N_Component_Association =>
1161 Set_Debug_Sloc;
1162 Sprint_Bar_List (Choices (Node));
1163 Write_Str (" => ");
1165 -- Ada 2005 (AI-287): Print the box if present
1167 if Box_Present (Node) then
1168 Write_Str_With_Col_Check ("<>");
1169 else
1170 Sprint_Node (Expression (Node));
1171 end if;
1173 when N_Component_Clause =>
1174 Write_Indent;
1175 Sprint_Node (Component_Name (Node));
1176 Write_Str_Sloc (" at ");
1177 Sprint_Node (Position (Node));
1178 Write_Char (' ');
1179 Write_Str_With_Col_Check ("range ");
1180 Sprint_Node (First_Bit (Node));
1181 Write_Str (" .. ");
1182 Sprint_Node (Last_Bit (Node));
1183 Write_Char (';');
1185 when N_Component_Definition =>
1186 Set_Debug_Sloc;
1188 -- Ada 2005 (AI-230): Access definition components
1190 if Present (Access_Definition (Node)) then
1191 Sprint_Node (Access_Definition (Node));
1193 elsif Present (Subtype_Indication (Node)) then
1194 if Aliased_Present (Node) then
1195 Write_Str_With_Col_Check ("aliased ");
1196 end if;
1198 -- Ada 2005 (AI-231)
1200 if Null_Exclusion_Present (Node) then
1201 Write_Str (" not null ");
1202 end if;
1204 Sprint_Node (Subtype_Indication (Node));
1206 else
1207 Write_Str (" ??? ");
1208 end if;
1210 when N_Component_Declaration =>
1211 if Write_Indent_Identifiers_Sloc (Node) then
1212 Write_Str (" : ");
1213 Sprint_Node (Component_Definition (Node));
1215 if Present (Expression (Node)) then
1216 Write_Str (" := ");
1217 Sprint_Node (Expression (Node));
1218 end if;
1220 Write_Char (';');
1221 end if;
1223 when N_Component_List =>
1224 if Null_Present (Node) then
1225 Indent_Begin;
1226 Write_Indent_Str_Sloc ("null");
1227 Write_Char (';');
1228 Indent_End;
1230 else
1231 Set_Debug_Sloc;
1232 Sprint_Indented_List (Component_Items (Node));
1233 Sprint_Node (Variant_Part (Node));
1234 end if;
1236 when N_Conditional_Entry_Call =>
1237 Write_Indent_Str_Sloc ("select");
1238 Indent_Begin;
1239 Sprint_Node (Entry_Call_Alternative (Node));
1240 Indent_End;
1241 Write_Indent_Str ("else");
1242 Sprint_Indented_List (Else_Statements (Node));
1243 Write_Indent_Str ("end select;");
1245 when N_Conditional_Expression =>
1246 declare
1247 Condition : constant Node_Id := First (Expressions (Node));
1248 Then_Expr : constant Node_Id := Next (Condition);
1249 Else_Expr : constant Node_Id := Next (Then_Expr);
1250 begin
1251 Write_Str_With_Col_Check_Sloc ("(if ");
1252 Sprint_Node (Condition);
1253 Write_Str_With_Col_Check (" then ");
1254 Sprint_Node (Then_Expr);
1255 Write_Str_With_Col_Check (" else ");
1256 Sprint_Node (Else_Expr);
1257 Write_Char (')');
1258 end;
1260 when N_Constrained_Array_Definition =>
1261 Write_Str_With_Col_Check_Sloc ("array ");
1262 Sprint_Paren_Comma_List (Discrete_Subtype_Definitions (Node));
1263 Write_Str (" of ");
1265 Sprint_Node (Component_Definition (Node));
1267 when N_Decimal_Fixed_Point_Definition =>
1268 Write_Str_With_Col_Check_Sloc (" delta ");
1269 Sprint_Node (Delta_Expression (Node));
1270 Write_Str_With_Col_Check ("digits ");
1271 Sprint_Node (Digits_Expression (Node));
1272 Sprint_Opt_Node (Real_Range_Specification (Node));
1274 when N_Defining_Character_Literal =>
1275 Write_Name_With_Col_Check_Sloc (Chars (Node));
1277 when N_Defining_Identifier =>
1278 Set_Debug_Sloc;
1279 Write_Id (Node);
1281 when N_Defining_Operator_Symbol =>
1282 Write_Name_With_Col_Check_Sloc (Chars (Node));
1284 when N_Defining_Program_Unit_Name =>
1285 Set_Debug_Sloc;
1286 Sprint_Node (Name (Node));
1287 Write_Char ('.');
1288 Write_Id (Defining_Identifier (Node));
1290 when N_Delay_Alternative =>
1291 Sprint_Node_List (Pragmas_Before (Node));
1293 if Present (Condition (Node)) then
1294 Write_Indent;
1295 Write_Str_With_Col_Check ("when ");
1296 Sprint_Node (Condition (Node));
1297 Write_Str (" => ");
1298 Indent_Annull;
1299 end if;
1301 Sprint_Node_Sloc (Delay_Statement (Node));
1302 Sprint_Node_List (Statements (Node));
1304 when N_Delay_Relative_Statement =>
1305 Write_Indent_Str_Sloc ("delay ");
1306 Sprint_Node (Expression (Node));
1307 Write_Char (';');
1309 when N_Delay_Until_Statement =>
1310 Write_Indent_Str_Sloc ("delay until ");
1311 Sprint_Node (Expression (Node));
1312 Write_Char (';');
1314 when N_Delta_Constraint =>
1315 Write_Str_With_Col_Check_Sloc ("delta ");
1316 Sprint_Node (Delta_Expression (Node));
1317 Sprint_Opt_Node (Range_Constraint (Node));
1319 when N_Derived_Type_Definition =>
1320 if Abstract_Present (Node) then
1321 Write_Str_With_Col_Check ("abstract ");
1322 end if;
1324 Write_Str_With_Col_Check_Sloc ("new ");
1326 -- Ada 2005 (AI-231)
1328 if Null_Exclusion_Present (Node) then
1329 Write_Str_With_Col_Check ("not null ");
1330 end if;
1332 Sprint_Node (Subtype_Indication (Node));
1334 if Present (Interface_List (Node)) then
1335 Write_Str_With_Col_Check (" and ");
1336 Sprint_And_List (Interface_List (Node));
1337 Write_Str_With_Col_Check (" with ");
1338 end if;
1340 if Present (Record_Extension_Part (Node)) then
1341 if No (Interface_List (Node)) then
1342 Write_Str_With_Col_Check (" with ");
1343 end if;
1345 Sprint_Node (Record_Extension_Part (Node));
1346 end if;
1348 when N_Designator =>
1349 Sprint_Node (Name (Node));
1350 Write_Char_Sloc ('.');
1351 Write_Id (Identifier (Node));
1353 when N_Digits_Constraint =>
1354 Write_Str_With_Col_Check_Sloc ("digits ");
1355 Sprint_Node (Digits_Expression (Node));
1356 Sprint_Opt_Node (Range_Constraint (Node));
1358 when N_Discriminant_Association =>
1359 Set_Debug_Sloc;
1361 if Present (Selector_Names (Node)) then
1362 Sprint_Bar_List (Selector_Names (Node));
1363 Write_Str (" => ");
1364 end if;
1366 Set_Debug_Sloc;
1367 Sprint_Node (Expression (Node));
1369 when N_Discriminant_Specification =>
1370 Set_Debug_Sloc;
1372 if Write_Identifiers (Node) then
1373 Write_Str (" : ");
1375 if Null_Exclusion_Present (Node) then
1376 Write_Str ("not null ");
1377 end if;
1379 Sprint_Node (Discriminant_Type (Node));
1381 if Present (Expression (Node)) then
1382 Write_Str (" := ");
1383 Sprint_Node (Expression (Node));
1384 end if;
1385 else
1386 Write_Str (", ");
1387 end if;
1389 when N_Elsif_Part =>
1390 Write_Indent_Str_Sloc ("elsif ");
1391 Sprint_Node (Condition (Node));
1392 Write_Str_With_Col_Check (" then");
1393 Sprint_Indented_List (Then_Statements (Node));
1395 when N_Empty =>
1396 null;
1398 when N_Entry_Body =>
1399 Write_Indent_Str_Sloc ("entry ");
1400 Write_Id (Defining_Identifier (Node));
1401 Sprint_Node (Entry_Body_Formal_Part (Node));
1402 Write_Str_With_Col_Check (" is");
1403 Sprint_Indented_List (Declarations (Node));
1404 Write_Indent_Str ("begin");
1405 Sprint_Node (Handled_Statement_Sequence (Node));
1406 Write_Indent_Str ("end ");
1407 Write_Id (Defining_Identifier (Node));
1408 Write_Char (';');
1410 when N_Entry_Body_Formal_Part =>
1411 if Present (Entry_Index_Specification (Node)) then
1412 Write_Str_With_Col_Check_Sloc (" (");
1413 Sprint_Node (Entry_Index_Specification (Node));
1414 Write_Char (')');
1415 end if;
1417 Write_Param_Specs (Node);
1418 Write_Str_With_Col_Check_Sloc (" when ");
1419 Sprint_Node (Condition (Node));
1421 when N_Entry_Call_Alternative =>
1422 Sprint_Node_List (Pragmas_Before (Node));
1423 Sprint_Node_Sloc (Entry_Call_Statement (Node));
1424 Sprint_Node_List (Statements (Node));
1426 when N_Entry_Call_Statement =>
1427 Write_Indent;
1428 Sprint_Node_Sloc (Name (Node));
1429 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
1430 Write_Char (';');
1432 when N_Entry_Declaration =>
1433 Write_Indent_Str_Sloc ("entry ");
1434 Write_Id (Defining_Identifier (Node));
1436 if Present (Discrete_Subtype_Definition (Node)) then
1437 Write_Str_With_Col_Check (" (");
1438 Sprint_Node (Discrete_Subtype_Definition (Node));
1439 Write_Char (')');
1440 end if;
1442 Write_Param_Specs (Node);
1443 Write_Char (';');
1445 when N_Entry_Index_Specification =>
1446 Write_Str_With_Col_Check_Sloc ("for ");
1447 Write_Id (Defining_Identifier (Node));
1448 Write_Str_With_Col_Check (" in ");
1449 Sprint_Node (Discrete_Subtype_Definition (Node));
1451 when N_Enumeration_Representation_Clause =>
1452 Write_Indent_Str_Sloc ("for ");
1453 Write_Id (Identifier (Node));
1454 Write_Str_With_Col_Check (" use ");
1455 Sprint_Node (Array_Aggregate (Node));
1456 Write_Char (';');
1458 when N_Enumeration_Type_Definition =>
1459 Set_Debug_Sloc;
1461 -- Skip attempt to print Literals field if it's not there and
1462 -- we are in package Standard (case of Character, which is
1463 -- handled specially (without an explicit literals list).
1465 if Sloc (Node) > Standard_Location
1466 or else Present (Literals (Node))
1467 then
1468 Sprint_Paren_Comma_List (Literals (Node));
1469 end if;
1471 when N_Error =>
1472 Write_Str_With_Col_Check_Sloc ("<error>");
1474 when N_Exception_Declaration =>
1475 if Write_Indent_Identifiers (Node) then
1476 Write_Str_With_Col_Check (" : ");
1478 if Is_Statically_Allocated (Defining_Identifier (Node)) then
1479 Write_Str_With_Col_Check ("static ");
1480 end if;
1482 Write_Str_Sloc ("exception");
1484 if Present (Expression (Node)) then
1485 Write_Str (" := ");
1486 Sprint_Node (Expression (Node));
1487 end if;
1489 Write_Char (';');
1490 end if;
1492 when N_Exception_Handler =>
1493 Write_Indent_Str_Sloc ("when ");
1495 if Present (Choice_Parameter (Node)) then
1496 Sprint_Node (Choice_Parameter (Node));
1497 Write_Str (" : ");
1498 end if;
1500 Sprint_Bar_List (Exception_Choices (Node));
1501 Write_Str (" => ");
1502 Sprint_Indented_List (Statements (Node));
1504 when N_Exception_Renaming_Declaration =>
1505 Write_Indent;
1506 Set_Debug_Sloc;
1507 Sprint_Node (Defining_Identifier (Node));
1508 Write_Str_With_Col_Check (" : exception renames ");
1509 Sprint_Node (Name (Node));
1510 Write_Char (';');
1512 when N_Exit_Statement =>
1513 Write_Indent_Str_Sloc ("exit");
1514 Sprint_Opt_Node (Name (Node));
1516 if Present (Condition (Node)) then
1517 Write_Str_With_Col_Check (" when ");
1518 Sprint_Node (Condition (Node));
1519 end if;
1521 Write_Char (';');
1523 when N_Expanded_Name =>
1524 Sprint_Node (Prefix (Node));
1525 Write_Char_Sloc ('.');
1526 Sprint_Node (Selector_Name (Node));
1528 when N_Explicit_Dereference =>
1529 Sprint_Node (Prefix (Node));
1530 Write_Char_Sloc ('.');
1531 Write_Str_Sloc ("all");
1533 when N_Extended_Return_Statement =>
1534 Write_Indent_Str_Sloc ("return ");
1535 Sprint_Node_List (Return_Object_Declarations (Node));
1537 if Present (Handled_Statement_Sequence (Node)) then
1538 Write_Str_With_Col_Check (" do");
1539 Sprint_Node (Handled_Statement_Sequence (Node));
1540 Write_Indent_Str ("end return;");
1541 else
1542 Write_Indent_Str (";");
1543 end if;
1545 when N_Extension_Aggregate =>
1546 Write_Str_With_Col_Check_Sloc ("(");
1547 Sprint_Node (Ancestor_Part (Node));
1548 Write_Str_With_Col_Check (" with ");
1550 if Null_Record_Present (Node) then
1551 Write_Str_With_Col_Check ("null record");
1552 else
1553 if Present (Expressions (Node)) then
1554 Sprint_Comma_List (Expressions (Node));
1556 if Present (Component_Associations (Node)) then
1557 Write_Str (", ");
1558 end if;
1559 end if;
1561 if Present (Component_Associations (Node)) then
1562 Sprint_Comma_List (Component_Associations (Node));
1563 end if;
1564 end if;
1566 Write_Char (')');
1568 when N_Floating_Point_Definition =>
1569 Write_Str_With_Col_Check_Sloc ("digits ");
1570 Sprint_Node (Digits_Expression (Node));
1571 Sprint_Opt_Node (Real_Range_Specification (Node));
1573 when N_Formal_Decimal_Fixed_Point_Definition =>
1574 Write_Str_With_Col_Check_Sloc ("delta <> digits <>");
1576 when N_Formal_Derived_Type_Definition =>
1577 Write_Str_With_Col_Check_Sloc ("new ");
1578 Sprint_Node (Subtype_Mark (Node));
1580 if Present (Interface_List (Node)) then
1581 Write_Str_With_Col_Check (" and ");
1582 Sprint_And_List (Interface_List (Node));
1583 end if;
1585 if Private_Present (Node) then
1586 Write_Str_With_Col_Check (" with private");
1587 end if;
1589 when N_Formal_Abstract_Subprogram_Declaration =>
1590 Write_Indent_Str_Sloc ("with ");
1591 Sprint_Node (Specification (Node));
1593 Write_Str_With_Col_Check (" is abstract");
1595 if Box_Present (Node) then
1596 Write_Str_With_Col_Check (" <>");
1597 elsif Present (Default_Name (Node)) then
1598 Write_Str_With_Col_Check (" ");
1599 Sprint_Node (Default_Name (Node));
1600 end if;
1602 Write_Char (';');
1604 when N_Formal_Concrete_Subprogram_Declaration =>
1605 Write_Indent_Str_Sloc ("with ");
1606 Sprint_Node (Specification (Node));
1608 if Box_Present (Node) then
1609 Write_Str_With_Col_Check (" is <>");
1610 elsif Present (Default_Name (Node)) then
1611 Write_Str_With_Col_Check (" is ");
1612 Sprint_Node (Default_Name (Node));
1613 end if;
1615 Write_Char (';');
1617 when N_Formal_Discrete_Type_Definition =>
1618 Write_Str_With_Col_Check_Sloc ("<>");
1620 when N_Formal_Floating_Point_Definition =>
1621 Write_Str_With_Col_Check_Sloc ("digits <>");
1623 when N_Formal_Modular_Type_Definition =>
1624 Write_Str_With_Col_Check_Sloc ("mod <>");
1626 when N_Formal_Object_Declaration =>
1627 Set_Debug_Sloc;
1629 if Write_Indent_Identifiers (Node) then
1630 Write_Str (" : ");
1632 if In_Present (Node) then
1633 Write_Str_With_Col_Check ("in ");
1634 end if;
1636 if Out_Present (Node) then
1637 Write_Str_With_Col_Check ("out ");
1638 end if;
1640 if Present (Subtype_Mark (Node)) then
1642 -- Ada 2005 (AI-423): Formal object with null exclusion
1644 if Null_Exclusion_Present (Node) then
1645 Write_Str ("not null ");
1646 end if;
1648 Sprint_Node (Subtype_Mark (Node));
1650 -- Ada 2005 (AI-423): Formal object with access definition
1652 else
1653 pragma Assert (Present (Access_Definition (Node)));
1655 Sprint_Node (Access_Definition (Node));
1656 end if;
1658 if Present (Default_Expression (Node)) then
1659 Write_Str (" := ");
1660 Sprint_Node (Default_Expression (Node));
1661 end if;
1663 Write_Char (';');
1664 end if;
1666 when N_Formal_Ordinary_Fixed_Point_Definition =>
1667 Write_Str_With_Col_Check_Sloc ("delta <>");
1669 when N_Formal_Package_Declaration =>
1670 Write_Indent_Str_Sloc ("with package ");
1671 Write_Id (Defining_Identifier (Node));
1672 Write_Str_With_Col_Check (" is new ");
1673 Sprint_Node (Name (Node));
1674 Write_Str_With_Col_Check (" (<>);");
1676 when N_Formal_Private_Type_Definition =>
1677 if Abstract_Present (Node) then
1678 Write_Str_With_Col_Check ("abstract ");
1679 end if;
1681 if Tagged_Present (Node) then
1682 Write_Str_With_Col_Check ("tagged ");
1683 end if;
1685 if Limited_Present (Node) then
1686 Write_Str_With_Col_Check ("limited ");
1687 end if;
1689 Write_Str_With_Col_Check_Sloc ("private");
1691 when N_Formal_Signed_Integer_Type_Definition =>
1692 Write_Str_With_Col_Check_Sloc ("range <>");
1694 when N_Formal_Type_Declaration =>
1695 Write_Indent_Str_Sloc ("type ");
1696 Write_Id (Defining_Identifier (Node));
1698 if Present (Discriminant_Specifications (Node)) then
1699 Write_Discr_Specs (Node);
1700 elsif Unknown_Discriminants_Present (Node) then
1701 Write_Str_With_Col_Check ("(<>)");
1702 end if;
1704 Write_Str_With_Col_Check (" is ");
1705 Sprint_Node (Formal_Type_Definition (Node));
1706 Write_Char (';');
1708 when N_Free_Statement =>
1709 Write_Indent_Str_Sloc ("free ");
1710 Sprint_Node (Expression (Node));
1711 Write_Char (';');
1713 when N_Freeze_Entity =>
1714 if Dump_Original_Only then
1715 null;
1717 elsif Present (Actions (Node)) or else Dump_Freeze_Null then
1718 Write_Indent;
1719 Write_Rewrite_Str ("<<<");
1720 Write_Str_With_Col_Check_Sloc ("freeze ");
1721 Write_Id (Entity (Node));
1722 Write_Str (" [");
1724 if No (Actions (Node)) then
1725 Write_Char (']');
1727 else
1728 -- Output freeze actions. We increment Freeze_Indent during
1729 -- this output to avoid generating extra blank lines before
1730 -- any procedures included in the freeze actions.
1732 Freeze_Indent := Freeze_Indent + 1;
1733 Sprint_Indented_List (Actions (Node));
1734 Freeze_Indent := Freeze_Indent - 1;
1735 Write_Indent_Str ("]");
1736 end if;
1738 Write_Rewrite_Str (">>>");
1739 end if;
1741 when N_Full_Type_Declaration =>
1742 Write_Indent_Str_Sloc ("type ");
1743 Sprint_Node (Defining_Identifier (Node));
1744 Write_Discr_Specs (Node);
1745 Write_Str_With_Col_Check (" is ");
1746 Sprint_Node (Type_Definition (Node));
1747 Write_Char (';');
1749 when N_Function_Call =>
1750 Set_Debug_Sloc;
1751 Note_Implicit_Run_Time_Call (Name (Node));
1752 Sprint_Node (Name (Node));
1753 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
1755 when N_Function_Instantiation =>
1756 Write_Indent_Str_Sloc ("function ");
1757 Sprint_Node (Defining_Unit_Name (Node));
1758 Write_Str_With_Col_Check (" is new ");
1759 Sprint_Node (Name (Node));
1760 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
1761 Write_Char (';');
1763 when N_Function_Specification =>
1764 Write_Str_With_Col_Check_Sloc ("function ");
1765 Sprint_Node (Defining_Unit_Name (Node));
1766 Write_Param_Specs (Node);
1767 Write_Str_With_Col_Check (" return ");
1769 -- Ada 2005 (AI-231)
1771 if Nkind (Result_Definition (Node)) /= N_Access_Definition
1772 and then Null_Exclusion_Present (Node)
1773 then
1774 Write_Str (" not null ");
1775 end if;
1777 Sprint_Node (Result_Definition (Node));
1779 when N_Generic_Association =>
1780 Set_Debug_Sloc;
1782 if Present (Selector_Name (Node)) then
1783 Sprint_Node (Selector_Name (Node));
1784 Write_Str (" => ");
1785 end if;
1787 Sprint_Node (Explicit_Generic_Actual_Parameter (Node));
1789 when N_Generic_Function_Renaming_Declaration =>
1790 Write_Indent_Str_Sloc ("generic function ");
1791 Sprint_Node (Defining_Unit_Name (Node));
1792 Write_Str_With_Col_Check (" renames ");
1793 Sprint_Node (Name (Node));
1794 Write_Char (';');
1796 when N_Generic_Package_Declaration =>
1797 Extra_Blank_Line;
1798 Write_Indent_Str_Sloc ("generic ");
1799 Sprint_Indented_List (Generic_Formal_Declarations (Node));
1800 Write_Indent;
1801 Sprint_Node (Specification (Node));
1802 Write_Char (';');
1804 when N_Generic_Package_Renaming_Declaration =>
1805 Write_Indent_Str_Sloc ("generic package ");
1806 Sprint_Node (Defining_Unit_Name (Node));
1807 Write_Str_With_Col_Check (" renames ");
1808 Sprint_Node (Name (Node));
1809 Write_Char (';');
1811 when N_Generic_Procedure_Renaming_Declaration =>
1812 Write_Indent_Str_Sloc ("generic procedure ");
1813 Sprint_Node (Defining_Unit_Name (Node));
1814 Write_Str_With_Col_Check (" renames ");
1815 Sprint_Node (Name (Node));
1816 Write_Char (';');
1818 when N_Generic_Subprogram_Declaration =>
1819 Extra_Blank_Line;
1820 Write_Indent_Str_Sloc ("generic ");
1821 Sprint_Indented_List (Generic_Formal_Declarations (Node));
1822 Write_Indent;
1823 Sprint_Node (Specification (Node));
1824 Write_Char (';');
1826 when N_Goto_Statement =>
1827 Write_Indent_Str_Sloc ("goto ");
1828 Sprint_Node (Name (Node));
1829 Write_Char (';');
1831 if Nkind (Next (Node)) = N_Label then
1832 Write_Indent;
1833 end if;
1835 when N_Handled_Sequence_Of_Statements =>
1836 Set_Debug_Sloc;
1837 Sprint_Indented_List (Statements (Node));
1839 if Present (Exception_Handlers (Node)) then
1840 Write_Indent_Str ("exception");
1841 Indent_Begin;
1842 Sprint_Node_List (Exception_Handlers (Node));
1843 Indent_End;
1844 end if;
1846 if Present (At_End_Proc (Node)) then
1847 Write_Indent_Str ("at end");
1848 Indent_Begin;
1849 Write_Indent;
1850 Sprint_Node (At_End_Proc (Node));
1851 Write_Char (';');
1852 Indent_End;
1853 end if;
1855 when N_Identifier =>
1856 Set_Debug_Sloc;
1857 Write_Id (Node);
1859 when N_If_Statement =>
1860 Write_Indent_Str_Sloc ("if ");
1861 Sprint_Node (Condition (Node));
1862 Write_Str_With_Col_Check (" then");
1863 Sprint_Indented_List (Then_Statements (Node));
1864 Sprint_Opt_Node_List (Elsif_Parts (Node));
1866 if Present (Else_Statements (Node)) then
1867 Write_Indent_Str ("else");
1868 Sprint_Indented_List (Else_Statements (Node));
1869 end if;
1871 Write_Indent_Str ("end if;");
1873 when N_Implicit_Label_Declaration =>
1874 if not Dump_Original_Only then
1875 Write_Indent;
1876 Write_Rewrite_Str ("<<<");
1877 Set_Debug_Sloc;
1878 Write_Id (Defining_Identifier (Node));
1879 Write_Str (" : ");
1880 Write_Str_With_Col_Check ("label");
1881 Write_Rewrite_Str (">>>");
1882 end if;
1884 when N_In =>
1885 Sprint_Left_Opnd (Node);
1886 Write_Str_Sloc (" in ");
1887 Sprint_Right_Opnd (Node);
1889 when N_Incomplete_Type_Declaration =>
1890 Write_Indent_Str_Sloc ("type ");
1891 Write_Id (Defining_Identifier (Node));
1893 if Present (Discriminant_Specifications (Node)) then
1894 Write_Discr_Specs (Node);
1895 elsif Unknown_Discriminants_Present (Node) then
1896 Write_Str_With_Col_Check ("(<>)");
1897 end if;
1899 Write_Char (';');
1901 when N_Index_Or_Discriminant_Constraint =>
1902 Set_Debug_Sloc;
1903 Sprint_Paren_Comma_List (Constraints (Node));
1905 when N_Indexed_Component =>
1906 Sprint_Node_Sloc (Prefix (Node));
1907 Sprint_Opt_Paren_Comma_List (Expressions (Node));
1909 when N_Integer_Literal =>
1910 if Print_In_Hex (Node) then
1911 Write_Uint_With_Col_Check_Sloc (Intval (Node), Hex);
1912 else
1913 Write_Uint_With_Col_Check_Sloc (Intval (Node), Auto);
1914 end if;
1916 when N_Iteration_Scheme =>
1917 if Present (Condition (Node)) then
1918 Write_Str_With_Col_Check_Sloc ("while ");
1919 Sprint_Node (Condition (Node));
1920 else
1921 Write_Str_With_Col_Check_Sloc ("for ");
1922 Sprint_Node (Loop_Parameter_Specification (Node));
1923 end if;
1925 Write_Char (' ');
1927 when N_Itype_Reference =>
1928 Write_Indent_Str_Sloc ("reference ");
1929 Write_Id (Itype (Node));
1931 when N_Label =>
1932 Write_Indent_Str_Sloc ("<<");
1933 Write_Id (Identifier (Node));
1934 Write_Str (">>");
1936 when N_Loop_Parameter_Specification =>
1937 Set_Debug_Sloc;
1938 Write_Id (Defining_Identifier (Node));
1939 Write_Str_With_Col_Check (" in ");
1941 if Reverse_Present (Node) then
1942 Write_Str_With_Col_Check ("reverse ");
1943 end if;
1945 Sprint_Node (Discrete_Subtype_Definition (Node));
1947 when N_Loop_Statement =>
1948 Write_Indent;
1950 if Present (Identifier (Node))
1951 and then (not Has_Created_Identifier (Node)
1952 or else not Dump_Original_Only)
1953 then
1954 Write_Rewrite_Str ("<<<");
1955 Write_Id (Identifier (Node));
1956 Write_Str (" : ");
1957 Write_Rewrite_Str (">>>");
1958 Sprint_Node (Iteration_Scheme (Node));
1959 Write_Str_With_Col_Check_Sloc ("loop");
1960 Sprint_Indented_List (Statements (Node));
1961 Write_Indent_Str ("end loop ");
1962 Write_Rewrite_Str ("<<<");
1963 Write_Id (Identifier (Node));
1964 Write_Rewrite_Str (">>>");
1965 Write_Char (';');
1967 else
1968 Sprint_Node (Iteration_Scheme (Node));
1969 Write_Str_With_Col_Check_Sloc ("loop");
1970 Sprint_Indented_List (Statements (Node));
1971 Write_Indent_Str ("end loop;");
1972 end if;
1974 when N_Mod_Clause =>
1975 Sprint_Node_List (Pragmas_Before (Node));
1976 Write_Str_With_Col_Check_Sloc ("at mod ");
1977 Sprint_Node (Expression (Node));
1979 when N_Modular_Type_Definition =>
1980 Write_Str_With_Col_Check_Sloc ("mod ");
1981 Sprint_Node (Expression (Node));
1983 when N_Not_In =>
1984 Sprint_Left_Opnd (Node);
1985 Write_Str_Sloc (" not in ");
1986 Sprint_Right_Opnd (Node);
1988 when N_Null =>
1989 Write_Str_With_Col_Check_Sloc ("null");
1991 when N_Null_Statement =>
1992 if Comes_From_Source (Node)
1993 or else Dump_Freeze_Null
1994 or else not Is_List_Member (Node)
1995 or else (No (Prev (Node)) and then No (Next (Node)))
1996 then
1997 Write_Indent_Str_Sloc ("null;");
1998 end if;
2000 when N_Number_Declaration =>
2001 Set_Debug_Sloc;
2003 if Write_Indent_Identifiers (Node) then
2004 Write_Str_With_Col_Check (" : constant ");
2005 Write_Str (" := ");
2006 Sprint_Node (Expression (Node));
2007 Write_Char (';');
2008 end if;
2010 when N_Object_Declaration =>
2011 Set_Debug_Sloc;
2013 if Write_Indent_Identifiers (Node) then
2014 declare
2015 Def_Id : constant Entity_Id := Defining_Identifier (Node);
2017 begin
2018 Write_Str_With_Col_Check (" : ");
2020 if Is_Statically_Allocated (Def_Id) then
2021 Write_Str_With_Col_Check ("static ");
2022 end if;
2024 if Aliased_Present (Node) then
2025 Write_Str_With_Col_Check ("aliased ");
2026 end if;
2028 if Constant_Present (Node) then
2029 Write_Str_With_Col_Check ("constant ");
2030 end if;
2032 -- Ada 2005 (AI-231)
2034 if Null_Exclusion_Present (Node) then
2035 Write_Str_With_Col_Check ("not null ");
2036 end if;
2038 Sprint_Node (Object_Definition (Node));
2040 if Present (Expression (Node)) then
2041 Write_Str (" := ");
2042 Sprint_Node (Expression (Node));
2043 end if;
2045 Write_Char (';');
2047 -- Handle implicit importation and implicit exportation of
2048 -- object declarations:
2049 -- $pragma import (Convention_Id, Def_Id, "...");
2050 -- $pragma export (Convention_Id, Def_Id, "...");
2052 if Is_Internal (Def_Id)
2053 and then Present (Interface_Name (Def_Id))
2054 then
2055 Write_Indent_Str_Sloc ("$pragma ");
2057 if Is_Imported (Def_Id) then
2058 Write_Str ("import (");
2060 else pragma Assert (Is_Exported (Def_Id));
2061 Write_Str ("export (");
2062 end if;
2064 declare
2065 Prefix : constant String := "Convention_";
2066 S : constant String := Convention (Def_Id)'Img;
2068 begin
2069 Name_Len := S'Last - Prefix'Last;
2070 Name_Buffer (1 .. Name_Len) :=
2071 S (Prefix'Last + 1 .. S'Last);
2072 Set_Casing (All_Lower_Case);
2073 Write_Str (Name_Buffer (1 .. Name_Len));
2074 end;
2076 Write_Str (", ");
2077 Write_Id (Def_Id);
2078 Write_Str (", ");
2079 Write_String_Table_Entry
2080 (Strval (Interface_Name (Def_Id)));
2081 Write_Str (");");
2082 end if;
2083 end;
2084 end if;
2086 when N_Object_Renaming_Declaration =>
2087 Write_Indent;
2088 Set_Debug_Sloc;
2089 Sprint_Node (Defining_Identifier (Node));
2090 Write_Str (" : ");
2092 -- Ada 2005 (AI-230): Access renamings
2094 if Present (Access_Definition (Node)) then
2095 Sprint_Node (Access_Definition (Node));
2097 elsif Present (Subtype_Mark (Node)) then
2099 -- Ada 2005 (AI-423): Object renaming with a null exclusion
2101 if Null_Exclusion_Present (Node) then
2102 Write_Str ("not null ");
2103 end if;
2105 Sprint_Node (Subtype_Mark (Node));
2107 else
2108 Write_Str (" ??? ");
2109 end if;
2111 Write_Str_With_Col_Check (" renames ");
2112 Sprint_Node (Name (Node));
2113 Write_Char (';');
2115 when N_Op_Abs =>
2116 Write_Operator (Node, "abs ");
2117 Sprint_Right_Opnd (Node);
2119 when N_Op_Add =>
2120 Sprint_Left_Opnd (Node);
2121 Write_Operator (Node, " + ");
2122 Sprint_Right_Opnd (Node);
2124 when N_Op_And =>
2125 Sprint_Left_Opnd (Node);
2126 Write_Operator (Node, " and ");
2127 Sprint_Right_Opnd (Node);
2129 when N_Op_Concat =>
2130 Sprint_Left_Opnd (Node);
2131 Write_Operator (Node, " & ");
2132 Sprint_Right_Opnd (Node);
2134 when N_Op_Divide =>
2135 Sprint_Left_Opnd (Node);
2136 Write_Char (' ');
2137 Process_TFAI_RR_Flags (Node);
2138 Write_Operator (Node, "/ ");
2139 Sprint_Right_Opnd (Node);
2141 when N_Op_Eq =>
2142 Sprint_Left_Opnd (Node);
2143 Write_Operator (Node, " = ");
2144 Sprint_Right_Opnd (Node);
2146 when N_Op_Expon =>
2147 Sprint_Left_Opnd (Node);
2148 Write_Operator (Node, " ** ");
2149 Sprint_Right_Opnd (Node);
2151 when N_Op_Ge =>
2152 Sprint_Left_Opnd (Node);
2153 Write_Operator (Node, " >= ");
2154 Sprint_Right_Opnd (Node);
2156 when N_Op_Gt =>
2157 Sprint_Left_Opnd (Node);
2158 Write_Operator (Node, " > ");
2159 Sprint_Right_Opnd (Node);
2161 when N_Op_Le =>
2162 Sprint_Left_Opnd (Node);
2163 Write_Operator (Node, " <= ");
2164 Sprint_Right_Opnd (Node);
2166 when N_Op_Lt =>
2167 Sprint_Left_Opnd (Node);
2168 Write_Operator (Node, " < ");
2169 Sprint_Right_Opnd (Node);
2171 when N_Op_Minus =>
2172 Write_Operator (Node, "-");
2173 Sprint_Right_Opnd (Node);
2175 when N_Op_Mod =>
2176 Sprint_Left_Opnd (Node);
2178 if Treat_Fixed_As_Integer (Node) then
2179 Write_Str (" #");
2180 end if;
2182 Write_Operator (Node, " mod ");
2183 Sprint_Right_Opnd (Node);
2185 when N_Op_Multiply =>
2186 Sprint_Left_Opnd (Node);
2187 Write_Char (' ');
2188 Process_TFAI_RR_Flags (Node);
2189 Write_Operator (Node, "* ");
2190 Sprint_Right_Opnd (Node);
2192 when N_Op_Ne =>
2193 Sprint_Left_Opnd (Node);
2194 Write_Operator (Node, " /= ");
2195 Sprint_Right_Opnd (Node);
2197 when N_Op_Not =>
2198 Write_Operator (Node, "not ");
2199 Sprint_Right_Opnd (Node);
2201 when N_Op_Or =>
2202 Sprint_Left_Opnd (Node);
2203 Write_Operator (Node, " or ");
2204 Sprint_Right_Opnd (Node);
2206 when N_Op_Plus =>
2207 Write_Operator (Node, "+");
2208 Sprint_Right_Opnd (Node);
2210 when N_Op_Rem =>
2211 Sprint_Left_Opnd (Node);
2213 if Treat_Fixed_As_Integer (Node) then
2214 Write_Str (" #");
2215 end if;
2217 Write_Operator (Node, " rem ");
2218 Sprint_Right_Opnd (Node);
2220 when N_Op_Shift =>
2221 Set_Debug_Sloc;
2222 Write_Id (Node);
2223 Write_Char ('!');
2224 Write_Str_With_Col_Check ("(");
2225 Sprint_Node (Left_Opnd (Node));
2226 Write_Str (", ");
2227 Sprint_Node (Right_Opnd (Node));
2228 Write_Char (')');
2230 when N_Op_Subtract =>
2231 Sprint_Left_Opnd (Node);
2232 Write_Operator (Node, " - ");
2233 Sprint_Right_Opnd (Node);
2235 when N_Op_Xor =>
2236 Sprint_Left_Opnd (Node);
2237 Write_Operator (Node, " xor ");
2238 Sprint_Right_Opnd (Node);
2240 when N_Operator_Symbol =>
2241 Write_Name_With_Col_Check_Sloc (Chars (Node));
2243 when N_Ordinary_Fixed_Point_Definition =>
2244 Write_Str_With_Col_Check_Sloc ("delta ");
2245 Sprint_Node (Delta_Expression (Node));
2246 Sprint_Opt_Node (Real_Range_Specification (Node));
2248 when N_Or_Else =>
2249 Sprint_Left_Opnd (Node);
2250 Write_Str_Sloc (" or else ");
2251 Sprint_Right_Opnd (Node);
2253 when N_Others_Choice =>
2254 if All_Others (Node) then
2255 Write_Str_With_Col_Check ("all ");
2256 end if;
2258 Write_Str_With_Col_Check_Sloc ("others");
2260 when N_Package_Body =>
2261 Extra_Blank_Line;
2262 Write_Indent_Str_Sloc ("package body ");
2263 Sprint_Node (Defining_Unit_Name (Node));
2264 Write_Str (" is");
2265 Sprint_Indented_List (Declarations (Node));
2267 if Present (Handled_Statement_Sequence (Node)) then
2268 Write_Indent_Str ("begin");
2269 Sprint_Node (Handled_Statement_Sequence (Node));
2270 end if;
2272 Write_Indent_Str ("end ");
2273 Sprint_End_Label
2274 (Handled_Statement_Sequence (Node), Defining_Unit_Name (Node));
2275 Write_Char (';');
2277 when N_Package_Body_Stub =>
2278 Write_Indent_Str_Sloc ("package body ");
2279 Sprint_Node (Defining_Identifier (Node));
2280 Write_Str_With_Col_Check (" is separate;");
2282 when N_Package_Declaration =>
2283 Extra_Blank_Line;
2284 Write_Indent;
2285 Sprint_Node_Sloc (Specification (Node));
2286 Write_Char (';');
2288 when N_Package_Instantiation =>
2289 Extra_Blank_Line;
2290 Write_Indent_Str_Sloc ("package ");
2291 Sprint_Node (Defining_Unit_Name (Node));
2292 Write_Str (" is new ");
2293 Sprint_Node (Name (Node));
2294 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
2295 Write_Char (';');
2297 when N_Package_Renaming_Declaration =>
2298 Write_Indent_Str_Sloc ("package ");
2299 Sprint_Node (Defining_Unit_Name (Node));
2300 Write_Str_With_Col_Check (" renames ");
2301 Sprint_Node (Name (Node));
2302 Write_Char (';');
2304 when N_Package_Specification =>
2305 Write_Str_With_Col_Check_Sloc ("package ");
2306 Sprint_Node (Defining_Unit_Name (Node));
2307 Write_Str (" is");
2308 Sprint_Indented_List (Visible_Declarations (Node));
2310 if Present (Private_Declarations (Node)) then
2311 Write_Indent_Str ("private");
2312 Sprint_Indented_List (Private_Declarations (Node));
2313 end if;
2315 Write_Indent_Str ("end ");
2316 Sprint_Node (Defining_Unit_Name (Node));
2318 when N_Parameter_Association =>
2319 Sprint_Node_Sloc (Selector_Name (Node));
2320 Write_Str (" => ");
2321 Sprint_Node (Explicit_Actual_Parameter (Node));
2323 when N_Parameter_Specification =>
2324 Set_Debug_Sloc;
2326 if Write_Identifiers (Node) then
2327 Write_Str (" : ");
2329 if In_Present (Node) then
2330 Write_Str_With_Col_Check ("in ");
2331 end if;
2333 if Out_Present (Node) then
2334 Write_Str_With_Col_Check ("out ");
2335 end if;
2337 -- Ada 2005 (AI-231) parameter specification may carry
2338 -- null exclusion. Do not print it now if this is an
2339 -- access parameter, it is emitted when the access
2340 -- definition is displayed.
2342 if Null_Exclusion_Present (Node)
2343 and then Nkind (Parameter_Type (Node))
2344 /= N_Access_Definition
2345 then
2346 Write_Str ("not null ");
2347 end if;
2349 Sprint_Node (Parameter_Type (Node));
2351 if Present (Expression (Node)) then
2352 Write_Str (" := ");
2353 Sprint_Node (Expression (Node));
2354 end if;
2355 else
2356 Write_Str (", ");
2357 end if;
2359 when N_Pop_Constraint_Error_Label =>
2360 Write_Indent_Str ("%pop_constraint_error_label");
2362 when N_Pop_Program_Error_Label =>
2363 Write_Indent_Str ("%pop_program_error_label");
2365 when N_Pop_Storage_Error_Label =>
2366 Write_Indent_Str ("%pop_storage_error_label");
2368 when N_Push_Constraint_Error_Label =>
2369 Write_Indent_Str ("%push_constraint_error_label (");
2371 if Present (Exception_Label (Node)) then
2372 Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2373 end if;
2375 Write_Str (")");
2377 when N_Push_Program_Error_Label =>
2378 Write_Indent_Str ("%push_program_error_label (");
2380 if Present (Exception_Label (Node)) then
2381 Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2382 end if;
2384 Write_Str (")");
2386 when N_Push_Storage_Error_Label =>
2387 Write_Indent_Str ("%push_storage_error_label (");
2389 if Present (Exception_Label (Node)) then
2390 Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2391 end if;
2393 Write_Str (")");
2395 when N_Pragma =>
2396 Write_Indent_Str_Sloc ("pragma ");
2397 Write_Name_With_Col_Check (Pragma_Name (Node));
2399 if Present (Pragma_Argument_Associations (Node)) then
2400 Sprint_Opt_Paren_Comma_List
2401 (Pragma_Argument_Associations (Node));
2402 end if;
2404 Write_Char (';');
2406 when N_Pragma_Argument_Association =>
2407 Set_Debug_Sloc;
2409 if Chars (Node) /= No_Name then
2410 Write_Name_With_Col_Check (Chars (Node));
2411 Write_Str (" => ");
2412 end if;
2414 Sprint_Node (Expression (Node));
2416 when N_Private_Type_Declaration =>
2417 Write_Indent_Str_Sloc ("type ");
2418 Write_Id (Defining_Identifier (Node));
2420 if Present (Discriminant_Specifications (Node)) then
2421 Write_Discr_Specs (Node);
2422 elsif Unknown_Discriminants_Present (Node) then
2423 Write_Str_With_Col_Check ("(<>)");
2424 end if;
2426 Write_Str (" is ");
2428 if Tagged_Present (Node) then
2429 Write_Str_With_Col_Check ("tagged ");
2430 end if;
2432 if Limited_Present (Node) then
2433 Write_Str_With_Col_Check ("limited ");
2434 end if;
2436 Write_Str_With_Col_Check ("private;");
2438 when N_Private_Extension_Declaration =>
2439 Write_Indent_Str_Sloc ("type ");
2440 Write_Id (Defining_Identifier (Node));
2442 if Present (Discriminant_Specifications (Node)) then
2443 Write_Discr_Specs (Node);
2444 elsif Unknown_Discriminants_Present (Node) then
2445 Write_Str_With_Col_Check ("(<>)");
2446 end if;
2448 Write_Str_With_Col_Check (" is new ");
2449 Sprint_Node (Subtype_Indication (Node));
2451 if Present (Interface_List (Node)) then
2452 Write_Str_With_Col_Check (" and ");
2453 Sprint_And_List (Interface_List (Node));
2454 end if;
2456 Write_Str_With_Col_Check (" with private;");
2458 when N_Procedure_Call_Statement =>
2459 Write_Indent;
2460 Set_Debug_Sloc;
2461 Note_Implicit_Run_Time_Call (Name (Node));
2462 Sprint_Node (Name (Node));
2463 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
2464 Write_Char (';');
2466 when N_Procedure_Instantiation =>
2467 Write_Indent_Str_Sloc ("procedure ");
2468 Sprint_Node (Defining_Unit_Name (Node));
2469 Write_Str_With_Col_Check (" is new ");
2470 Sprint_Node (Name (Node));
2471 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
2472 Write_Char (';');
2474 when N_Procedure_Specification =>
2475 Write_Str_With_Col_Check_Sloc ("procedure ");
2476 Sprint_Node (Defining_Unit_Name (Node));
2477 Write_Param_Specs (Node);
2479 when N_Protected_Body =>
2480 Write_Indent_Str_Sloc ("protected body ");
2481 Write_Id (Defining_Identifier (Node));
2482 Write_Str (" is");
2483 Sprint_Indented_List (Declarations (Node));
2484 Write_Indent_Str ("end ");
2485 Write_Id (Defining_Identifier (Node));
2486 Write_Char (';');
2488 when N_Protected_Body_Stub =>
2489 Write_Indent_Str_Sloc ("protected body ");
2490 Write_Id (Defining_Identifier (Node));
2491 Write_Str_With_Col_Check (" is separate;");
2493 when N_Protected_Definition =>
2494 Set_Debug_Sloc;
2495 Sprint_Indented_List (Visible_Declarations (Node));
2497 if Present (Private_Declarations (Node)) then
2498 Write_Indent_Str ("private");
2499 Sprint_Indented_List (Private_Declarations (Node));
2500 end if;
2502 Write_Indent_Str ("end ");
2504 when N_Protected_Type_Declaration =>
2505 Write_Indent_Str_Sloc ("protected type ");
2506 Sprint_Node (Defining_Identifier (Node));
2507 Write_Discr_Specs (Node);
2509 if Present (Interface_List (Node)) then
2510 Write_Str (" is new ");
2511 Sprint_And_List (Interface_List (Node));
2512 Write_Str (" with ");
2513 else
2514 Write_Str (" is");
2515 end if;
2517 Sprint_Node (Protected_Definition (Node));
2518 Write_Id (Defining_Identifier (Node));
2519 Write_Char (';');
2521 when N_Qualified_Expression =>
2522 Sprint_Node (Subtype_Mark (Node));
2523 Write_Char_Sloc (''');
2525 -- Print expression, make sure we have at least one level of
2526 -- parentheses around the expression. For cases of qualified
2527 -- expressions in the source, this is always the case, but
2528 -- for generated qualifications, there may be no explicit
2529 -- parentheses present.
2531 if Paren_Count (Expression (Node)) /= 0 then
2532 Sprint_Node (Expression (Node));
2533 else
2534 Write_Char ('(');
2535 Sprint_Node (Expression (Node));
2536 Write_Char (')');
2537 end if;
2539 when N_Raise_Constraint_Error =>
2541 -- This node can be used either as a subexpression or as a
2542 -- statement form. The following test is a reasonably reliable
2543 -- way to distinguish the two cases.
2545 if Is_List_Member (Node)
2546 and then Nkind (Parent (Node)) not in N_Subexpr
2547 then
2548 Write_Indent;
2549 end if;
2551 Write_Str_With_Col_Check_Sloc ("[constraint_error");
2552 Write_Condition_And_Reason (Node);
2554 when N_Raise_Program_Error =>
2556 -- This node can be used either as a subexpression or as a
2557 -- statement form. The following test is a reasonably reliable
2558 -- way to distinguish the two cases.
2560 if Is_List_Member (Node)
2561 and then Nkind (Parent (Node)) not in N_Subexpr
2562 then
2563 Write_Indent;
2564 end if;
2566 Write_Str_With_Col_Check_Sloc ("[program_error");
2567 Write_Condition_And_Reason (Node);
2569 when N_Raise_Storage_Error =>
2571 -- This node can be used either as a subexpression or as a
2572 -- statement form. The following test is a reasonably reliable
2573 -- way to distinguish the two cases.
2575 if Is_List_Member (Node)
2576 and then Nkind (Parent (Node)) not in N_Subexpr
2577 then
2578 Write_Indent;
2579 end if;
2581 Write_Str_With_Col_Check_Sloc ("[storage_error");
2582 Write_Condition_And_Reason (Node);
2584 when N_Raise_Statement =>
2585 Write_Indent_Str_Sloc ("raise ");
2586 Sprint_Node (Name (Node));
2587 Write_Char (';');
2589 when N_Range =>
2590 Sprint_Node (Low_Bound (Node));
2591 Write_Str_Sloc (" .. ");
2592 Sprint_Node (High_Bound (Node));
2593 Update_Itype (Node);
2595 when N_Range_Constraint =>
2596 Write_Str_With_Col_Check_Sloc ("range ");
2597 Sprint_Node (Range_Expression (Node));
2599 when N_Real_Literal =>
2600 Write_Ureal_With_Col_Check_Sloc (Realval (Node));
2602 when N_Real_Range_Specification =>
2603 Write_Str_With_Col_Check_Sloc ("range ");
2604 Sprint_Node (Low_Bound (Node));
2605 Write_Str (" .. ");
2606 Sprint_Node (High_Bound (Node));
2608 when N_Record_Definition =>
2609 if Abstract_Present (Node) then
2610 Write_Str_With_Col_Check ("abstract ");
2611 end if;
2613 if Tagged_Present (Node) then
2614 Write_Str_With_Col_Check ("tagged ");
2615 end if;
2617 if Limited_Present (Node) then
2618 Write_Str_With_Col_Check ("limited ");
2619 end if;
2621 if Null_Present (Node) then
2622 Write_Str_With_Col_Check_Sloc ("null record");
2624 else
2625 Write_Str_With_Col_Check_Sloc ("record");
2626 Sprint_Node (Component_List (Node));
2627 Write_Indent_Str ("end record");
2628 end if;
2630 when N_Record_Representation_Clause =>
2631 Write_Indent_Str_Sloc ("for ");
2632 Sprint_Node (Identifier (Node));
2633 Write_Str_With_Col_Check (" use record ");
2635 if Present (Mod_Clause (Node)) then
2636 Sprint_Node (Mod_Clause (Node));
2637 end if;
2639 Sprint_Indented_List (Component_Clauses (Node));
2640 Write_Indent_Str ("end record;");
2642 when N_Reference =>
2643 Sprint_Node (Prefix (Node));
2644 Write_Str_With_Col_Check_Sloc ("'reference");
2646 when N_Requeue_Statement =>
2647 Write_Indent_Str_Sloc ("requeue ");
2648 Sprint_Node (Name (Node));
2650 if Abort_Present (Node) then
2651 Write_Str_With_Col_Check (" with abort");
2652 end if;
2654 Write_Char (';');
2656 when N_Simple_Return_Statement =>
2657 if Present (Expression (Node)) then
2658 Write_Indent_Str_Sloc ("return ");
2659 Sprint_Node (Expression (Node));
2660 Write_Char (';');
2661 else
2662 Write_Indent_Str_Sloc ("return;");
2663 end if;
2665 when N_Selective_Accept =>
2666 Write_Indent_Str_Sloc ("select");
2668 declare
2669 Alt_Node : Node_Id;
2670 begin
2671 Alt_Node := First (Select_Alternatives (Node));
2672 loop
2673 Indent_Begin;
2674 Sprint_Node (Alt_Node);
2675 Indent_End;
2676 Next (Alt_Node);
2677 exit when No (Alt_Node);
2678 Write_Indent_Str ("or");
2679 end loop;
2680 end;
2682 if Present (Else_Statements (Node)) then
2683 Write_Indent_Str ("else");
2684 Sprint_Indented_List (Else_Statements (Node));
2685 end if;
2687 Write_Indent_Str ("end select;");
2689 when N_Signed_Integer_Type_Definition =>
2690 Write_Str_With_Col_Check_Sloc ("range ");
2691 Sprint_Node (Low_Bound (Node));
2692 Write_Str (" .. ");
2693 Sprint_Node (High_Bound (Node));
2695 when N_Single_Protected_Declaration =>
2696 Write_Indent_Str_Sloc ("protected ");
2697 Write_Id (Defining_Identifier (Node));
2698 Write_Str (" is");
2699 Sprint_Node (Protected_Definition (Node));
2700 Write_Id (Defining_Identifier (Node));
2701 Write_Char (';');
2703 when N_Single_Task_Declaration =>
2704 Write_Indent_Str_Sloc ("task ");
2705 Sprint_Node (Defining_Identifier (Node));
2707 if Present (Task_Definition (Node)) then
2708 Write_Str (" is");
2709 Sprint_Node (Task_Definition (Node));
2710 end if;
2712 Write_Char (';');
2714 when N_Selected_Component =>
2715 Sprint_Node (Prefix (Node));
2716 Write_Char_Sloc ('.');
2717 Sprint_Node (Selector_Name (Node));
2719 when N_Slice =>
2720 Set_Debug_Sloc;
2721 Sprint_Node (Prefix (Node));
2722 Write_Str_With_Col_Check (" (");
2723 Sprint_Node (Discrete_Range (Node));
2724 Write_Char (')');
2726 when N_String_Literal =>
2727 if String_Length (Strval (Node)) + Column > 75 then
2728 Write_Indent_Str (" ");
2729 end if;
2731 Set_Debug_Sloc;
2732 Write_String_Table_Entry (Strval (Node));
2734 when N_Subprogram_Body =>
2736 -- Output extra blank line unless we are in freeze actions
2738 if Freeze_Indent = 0 then
2739 Extra_Blank_Line;
2740 end if;
2742 Write_Indent;
2743 Sprint_Node_Sloc (Specification (Node));
2744 Write_Str (" is");
2746 Sprint_Indented_List (Declarations (Node));
2747 Write_Indent_Str ("begin");
2748 Sprint_Node (Handled_Statement_Sequence (Node));
2750 Write_Indent_Str ("end ");
2752 Sprint_End_Label
2753 (Handled_Statement_Sequence (Node),
2754 Defining_Unit_Name (Specification (Node)));
2755 Write_Char (';');
2757 if Is_List_Member (Node)
2758 and then Present (Next (Node))
2759 and then Nkind (Next (Node)) /= N_Subprogram_Body
2760 then
2761 Write_Indent;
2762 end if;
2764 when N_Subprogram_Body_Stub =>
2765 Write_Indent;
2766 Sprint_Node_Sloc (Specification (Node));
2767 Write_Str_With_Col_Check (" is separate;");
2769 when N_Subprogram_Declaration =>
2770 Write_Indent;
2771 Sprint_Node_Sloc (Specification (Node));
2773 if Nkind (Specification (Node)) = N_Procedure_Specification
2774 and then Null_Present (Specification (Node))
2775 then
2776 Write_Str_With_Col_Check (" is null");
2777 end if;
2779 Write_Char (';');
2781 when N_Subprogram_Info =>
2782 Sprint_Node (Identifier (Node));
2783 Write_Str_With_Col_Check_Sloc ("'subprogram_info");
2785 when N_Subprogram_Renaming_Declaration =>
2786 Write_Indent;
2787 Sprint_Node (Specification (Node));
2788 Write_Str_With_Col_Check_Sloc (" renames ");
2789 Sprint_Node (Name (Node));
2790 Write_Char (';');
2792 when N_Subtype_Declaration =>
2793 Write_Indent_Str_Sloc ("subtype ");
2794 Sprint_Node (Defining_Identifier (Node));
2795 Write_Str (" is ");
2797 -- Ada 2005 (AI-231)
2799 if Null_Exclusion_Present (Node) then
2800 Write_Str ("not null ");
2801 end if;
2803 Sprint_Node (Subtype_Indication (Node));
2804 Write_Char (';');
2806 when N_Subtype_Indication =>
2807 Sprint_Node_Sloc (Subtype_Mark (Node));
2808 Write_Char (' ');
2809 Sprint_Node (Constraint (Node));
2811 when N_Subunit =>
2812 Write_Indent_Str_Sloc ("separate (");
2813 Sprint_Node (Name (Node));
2814 Write_Char (')');
2815 Extra_Blank_Line;
2816 Sprint_Node (Proper_Body (Node));
2818 when N_Task_Body =>
2819 Write_Indent_Str_Sloc ("task body ");
2820 Write_Id (Defining_Identifier (Node));
2821 Write_Str (" is");
2822 Sprint_Indented_List (Declarations (Node));
2823 Write_Indent_Str ("begin");
2824 Sprint_Node (Handled_Statement_Sequence (Node));
2825 Write_Indent_Str ("end ");
2826 Sprint_End_Label
2827 (Handled_Statement_Sequence (Node), Defining_Identifier (Node));
2828 Write_Char (';');
2830 when N_Task_Body_Stub =>
2831 Write_Indent_Str_Sloc ("task body ");
2832 Write_Id (Defining_Identifier (Node));
2833 Write_Str_With_Col_Check (" is separate;");
2835 when N_Task_Definition =>
2836 Set_Debug_Sloc;
2837 Sprint_Indented_List (Visible_Declarations (Node));
2839 if Present (Private_Declarations (Node)) then
2840 Write_Indent_Str ("private");
2841 Sprint_Indented_List (Private_Declarations (Node));
2842 end if;
2844 Write_Indent_Str ("end ");
2845 Sprint_End_Label (Node, Defining_Identifier (Parent (Node)));
2847 when N_Task_Type_Declaration =>
2848 Write_Indent_Str_Sloc ("task type ");
2849 Sprint_Node (Defining_Identifier (Node));
2850 Write_Discr_Specs (Node);
2852 if Present (Interface_List (Node)) then
2853 Write_Str (" is new ");
2854 Sprint_And_List (Interface_List (Node));
2855 end if;
2857 if Present (Task_Definition (Node)) then
2858 if No (Interface_List (Node)) then
2859 Write_Str (" is");
2860 else
2861 Write_Str (" with ");
2862 end if;
2864 Sprint_Node (Task_Definition (Node));
2865 end if;
2867 Write_Char (';');
2869 when N_Terminate_Alternative =>
2870 Sprint_Node_List (Pragmas_Before (Node));
2872 Write_Indent;
2874 if Present (Condition (Node)) then
2875 Write_Str_With_Col_Check ("when ");
2876 Sprint_Node (Condition (Node));
2877 Write_Str (" => ");
2878 end if;
2880 Write_Str_With_Col_Check_Sloc ("terminate;");
2881 Sprint_Node_List (Pragmas_After (Node));
2883 when N_Timed_Entry_Call =>
2884 Write_Indent_Str_Sloc ("select");
2885 Indent_Begin;
2886 Sprint_Node (Entry_Call_Alternative (Node));
2887 Indent_End;
2888 Write_Indent_Str ("or");
2889 Indent_Begin;
2890 Sprint_Node (Delay_Alternative (Node));
2891 Indent_End;
2892 Write_Indent_Str ("end select;");
2894 when N_Triggering_Alternative =>
2895 Sprint_Node_List (Pragmas_Before (Node));
2896 Sprint_Node_Sloc (Triggering_Statement (Node));
2897 Sprint_Node_List (Statements (Node));
2899 when N_Type_Conversion =>
2900 Set_Debug_Sloc;
2901 Sprint_Node (Subtype_Mark (Node));
2902 Col_Check (4);
2904 if Conversion_OK (Node) then
2905 Write_Char ('?');
2906 end if;
2908 if Float_Truncate (Node) then
2909 Write_Char ('^');
2910 end if;
2912 if Rounded_Result (Node) then
2913 Write_Char ('@');
2914 end if;
2916 Write_Char ('(');
2917 Sprint_Node (Expression (Node));
2918 Write_Char (')');
2920 when N_Unchecked_Expression =>
2921 Col_Check (10);
2922 Write_Str ("`(");
2923 Sprint_Node_Sloc (Expression (Node));
2924 Write_Char (')');
2926 when N_Unchecked_Type_Conversion =>
2927 Sprint_Node (Subtype_Mark (Node));
2928 Write_Char ('!');
2929 Write_Str_With_Col_Check ("(");
2930 Sprint_Node_Sloc (Expression (Node));
2931 Write_Char (')');
2933 when N_Unconstrained_Array_Definition =>
2934 Write_Str_With_Col_Check_Sloc ("array (");
2936 declare
2937 Node1 : Node_Id;
2938 begin
2939 Node1 := First (Subtype_Marks (Node));
2940 loop
2941 Sprint_Node (Node1);
2942 Write_Str_With_Col_Check (" range <>");
2943 Next (Node1);
2944 exit when Node1 = Empty;
2945 Write_Str (", ");
2946 end loop;
2947 end;
2949 Write_Str (") of ");
2950 Sprint_Node (Component_Definition (Node));
2952 when N_Unused_At_Start | N_Unused_At_End =>
2953 Write_Indent_Str ("***** Error, unused node encountered *****");
2954 Write_Eol;
2956 when N_Use_Package_Clause =>
2957 Write_Indent_Str_Sloc ("use ");
2958 Sprint_Comma_List (Names (Node));
2959 Write_Char (';');
2961 when N_Use_Type_Clause =>
2962 Write_Indent_Str_Sloc ("use type ");
2963 Sprint_Comma_List (Subtype_Marks (Node));
2964 Write_Char (';');
2966 when N_Validate_Unchecked_Conversion =>
2967 Write_Indent_Str_Sloc ("validate unchecked_conversion (");
2968 Sprint_Node (Source_Type (Node));
2969 Write_Str (", ");
2970 Sprint_Node (Target_Type (Node));
2971 Write_Str (");");
2973 when N_Variant =>
2974 Write_Indent_Str_Sloc ("when ");
2975 Sprint_Bar_List (Discrete_Choices (Node));
2976 Write_Str (" => ");
2977 Sprint_Node (Component_List (Node));
2979 when N_Variant_Part =>
2980 Indent_Begin;
2981 Write_Indent_Str_Sloc ("case ");
2982 Sprint_Node (Name (Node));
2983 Write_Str (" is ");
2984 Sprint_Indented_List (Variants (Node));
2985 Write_Indent_Str ("end case");
2986 Indent_End;
2988 when N_With_Clause =>
2990 -- Special test, if we are dumping the original tree only,
2991 -- then we want to eliminate the bogus with clauses that
2992 -- correspond to the non-existent children of Text_IO.
2994 if Dump_Original_Only
2995 and then Is_Text_IO_Kludge_Unit (Name (Node))
2996 then
2997 null;
2999 -- Normal case, output the with clause
3001 else
3002 if First_Name (Node) or else not Dump_Original_Only then
3004 -- Ada 2005 (AI-50217): Print limited with_clauses
3006 if Private_Present (Node) and Limited_Present (Node) then
3007 Write_Indent_Str ("limited private with ");
3009 elsif Private_Present (Node) then
3010 Write_Indent_Str ("private with ");
3012 elsif Limited_Present (Node) then
3013 Write_Indent_Str ("limited with ");
3015 else
3016 Write_Indent_Str ("with ");
3017 end if;
3019 else
3020 Write_Str (", ");
3021 end if;
3023 Sprint_Node_Sloc (Name (Node));
3025 if Last_Name (Node) or else not Dump_Original_Only then
3026 Write_Char (';');
3027 end if;
3028 end if;
3030 end case;
3032 if Nkind (Node) in N_Subexpr
3033 and then Do_Range_Check (Node)
3034 then
3035 Write_Str ("}");
3036 end if;
3038 for J in 1 .. Paren_Count (Node) loop
3039 Write_Char (')');
3040 end loop;
3042 Dump_Node := Save_Dump_Node;
3043 end Sprint_Node_Actual;
3045 ----------------------
3046 -- Sprint_Node_List --
3047 ----------------------
3049 procedure Sprint_Node_List (List : List_Id) is
3050 Node : Node_Id;
3052 begin
3053 if Is_Non_Empty_List (List) then
3054 Node := First (List);
3056 loop
3057 Sprint_Node (Node);
3058 Next (Node);
3059 exit when Node = Empty;
3060 end loop;
3061 end if;
3062 end Sprint_Node_List;
3064 ----------------------
3065 -- Sprint_Node_Sloc --
3066 ----------------------
3068 procedure Sprint_Node_Sloc (Node : Node_Id) is
3069 begin
3070 Sprint_Node (Node);
3072 if Debug_Generated_Code and then Present (Dump_Node) then
3073 Set_Sloc (Dump_Node, Sloc (Node));
3074 Dump_Node := Empty;
3075 end if;
3076 end Sprint_Node_Sloc;
3078 ---------------------
3079 -- Sprint_Opt_Node --
3080 ---------------------
3082 procedure Sprint_Opt_Node (Node : Node_Id) is
3083 begin
3084 if Present (Node) then
3085 Write_Char (' ');
3086 Sprint_Node (Node);
3087 end if;
3088 end Sprint_Opt_Node;
3090 --------------------------
3091 -- Sprint_Opt_Node_List --
3092 --------------------------
3094 procedure Sprint_Opt_Node_List (List : List_Id) is
3095 begin
3096 if Present (List) then
3097 Sprint_Node_List (List);
3098 end if;
3099 end Sprint_Opt_Node_List;
3101 ---------------------------------
3102 -- Sprint_Opt_Paren_Comma_List --
3103 ---------------------------------
3105 procedure Sprint_Opt_Paren_Comma_List (List : List_Id) is
3106 begin
3107 if Is_Non_Empty_List (List) then
3108 Write_Char (' ');
3109 Sprint_Paren_Comma_List (List);
3110 end if;
3111 end Sprint_Opt_Paren_Comma_List;
3113 -----------------------------
3114 -- Sprint_Paren_Comma_List --
3115 -----------------------------
3117 procedure Sprint_Paren_Comma_List (List : List_Id) is
3118 N : Node_Id;
3119 Node_Exists : Boolean := False;
3121 begin
3123 if Is_Non_Empty_List (List) then
3125 if Dump_Original_Only then
3126 N := First (List);
3127 while Present (N) loop
3128 if not Is_Rewrite_Insertion (N) then
3129 Node_Exists := True;
3130 exit;
3131 end if;
3133 Next (N);
3134 end loop;
3136 if not Node_Exists then
3137 return;
3138 end if;
3139 end if;
3141 Write_Str_With_Col_Check ("(");
3142 Sprint_Comma_List (List);
3143 Write_Char (')');
3144 end if;
3145 end Sprint_Paren_Comma_List;
3147 ----------------------
3148 -- Sprint_Right_Opnd --
3149 ----------------------
3151 procedure Sprint_Right_Opnd (N : Node_Id) is
3152 Opnd : constant Node_Id := Right_Opnd (N);
3154 begin
3155 if Paren_Count (Opnd) /= 0
3156 or else Op_Prec (Nkind (Opnd)) > Op_Prec (Nkind (N))
3157 then
3158 Sprint_Node (Opnd);
3160 else
3161 Write_Char ('(');
3162 Sprint_Node (Opnd);
3163 Write_Char (')');
3164 end if;
3165 end Sprint_Right_Opnd;
3167 ------------------
3168 -- Update_Itype --
3169 ------------------
3171 procedure Update_Itype (Node : Node_Id) is
3172 begin
3173 if Present (Etype (Node))
3174 and then Is_Itype (Etype (Node))
3175 and then Debug_Generated_Code
3176 then
3177 Set_Sloc (Etype (Node), Sloc (Node));
3178 end if;
3179 end Update_Itype;
3181 ---------------------
3182 -- Write_Char_Sloc --
3183 ---------------------
3185 procedure Write_Char_Sloc (C : Character) is
3186 begin
3187 if Debug_Generated_Code and then C /= ' ' then
3188 Set_Debug_Sloc;
3189 end if;
3191 Write_Char (C);
3192 end Write_Char_Sloc;
3194 --------------------------------
3195 -- Write_Condition_And_Reason --
3196 --------------------------------
3198 procedure Write_Condition_And_Reason (Node : Node_Id) is
3199 Cond : constant Node_Id := Condition (Node);
3200 Image : constant String := RT_Exception_Code'Image
3201 (RT_Exception_Code'Val
3202 (UI_To_Int (Reason (Node))));
3204 begin
3205 if Present (Cond) then
3207 -- If condition is a single entity, or NOT with a single entity,
3208 -- output all on one line, since it will likely fit just fine.
3210 if Is_Entity_Name (Cond)
3211 or else (Nkind (Cond) = N_Op_Not
3212 and then Is_Entity_Name (Right_Opnd (Cond)))
3213 then
3214 Write_Str_With_Col_Check (" when ");
3215 Sprint_Node (Cond);
3216 Write_Char (' ');
3218 -- Otherwise for more complex condition, multiple lines
3220 else
3221 Write_Str_With_Col_Check (" when");
3222 Indent := Indent + 2;
3223 Write_Indent;
3224 Sprint_Node (Cond);
3225 Write_Indent;
3226 Indent := Indent - 2;
3227 end if;
3229 -- If no condition, just need a space (all on one line)
3231 else
3232 Write_Char (' ');
3233 end if;
3235 -- Write the reason
3237 Write_Char ('"');
3239 for J in 4 .. Image'Last loop
3240 if Image (J) = '_' then
3241 Write_Char (' ');
3242 else
3243 Write_Char (Fold_Lower (Image (J)));
3244 end if;
3245 end loop;
3247 Write_Str ("""]");
3248 end Write_Condition_And_Reason;
3250 --------------------------------
3251 -- Write_Corresponding_Source --
3252 --------------------------------
3254 procedure Write_Corresponding_Source (S : String) is
3255 Loc : Source_Ptr;
3256 Src : Source_Buffer_Ptr;
3258 begin
3259 -- Ignore if not in dump source text mode, or if in freeze actions
3261 if Dump_Source_Text and then Freeze_Indent = 0 then
3263 -- Ignore null string
3265 if S = "" then
3266 return;
3267 end if;
3269 -- Ignore space or semicolon at end of given string
3271 if S (S'Last) = ' ' or else S (S'Last) = ';' then
3272 Write_Corresponding_Source (S (S'First .. S'Last - 1));
3273 return;
3274 end if;
3276 -- Loop to look at next lines not yet printed in source file
3278 for L in
3279 Last_Line_Printed + 1 .. Last_Source_Line (Current_Source_File)
3280 loop
3281 Src := Source_Text (Current_Source_File);
3282 Loc := Line_Start (L, Current_Source_File);
3284 -- If comment, keep looking
3286 if Src (Loc .. Loc + 1) = "--" then
3287 null;
3289 -- Search to first non-blank
3291 else
3292 while Src (Loc) not in Line_Terminator loop
3294 -- Non-blank found
3296 if Src (Loc) /= ' ' and then Src (Loc) /= ASCII.HT then
3298 -- Loop through characters in string to see if we match
3300 for J in S'Range loop
3302 -- If mismatch, then not the case we are looking for
3304 if Src (Loc) /= S (J) then
3305 return;
3306 end if;
3308 Loc := Loc + 1;
3309 end loop;
3311 -- If we fall through, string matched, if white space or
3312 -- semicolon after the matched string, this is the case
3313 -- we are looking for.
3315 if Src (Loc) in Line_Terminator
3316 or else Src (Loc) = ' '
3317 or else Src (Loc) = ASCII.HT
3318 or else Src (Loc) = ';'
3319 then
3320 -- So output source lines up to and including this one
3322 Write_Source_Lines (L);
3323 return;
3324 end if;
3325 end if;
3327 Loc := Loc + 1;
3328 end loop;
3329 end if;
3331 -- Line was all blanks, or a comment line, keep looking
3333 end loop;
3334 end if;
3335 end Write_Corresponding_Source;
3337 -----------------------
3338 -- Write_Discr_Specs --
3339 -----------------------
3341 procedure Write_Discr_Specs (N : Node_Id) is
3342 Specs : List_Id;
3343 Spec : Node_Id;
3345 begin
3346 Specs := Discriminant_Specifications (N);
3348 if Present (Specs) then
3349 Write_Str_With_Col_Check (" (");
3350 Spec := First (Specs);
3352 loop
3353 Sprint_Node (Spec);
3354 Next (Spec);
3355 exit when Spec = Empty;
3357 -- Add semicolon, unless we are printing original tree and the
3358 -- next specification is part of a list (but not the first
3359 -- element of that list)
3361 if not Dump_Original_Only or else not Prev_Ids (Spec) then
3362 Write_Str ("; ");
3363 end if;
3364 end loop;
3366 Write_Char (')');
3367 end if;
3368 end Write_Discr_Specs;
3370 -----------------
3371 -- Write_Ekind --
3372 -----------------
3374 procedure Write_Ekind (E : Entity_Id) is
3375 S : constant String := Entity_Kind'Image (Ekind (E));
3377 begin
3378 Name_Len := S'Length;
3379 Name_Buffer (1 .. Name_Len) := S;
3380 Set_Casing (Mixed_Case);
3381 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
3382 end Write_Ekind;
3384 --------------
3385 -- Write_Id --
3386 --------------
3388 procedure Write_Id (N : Node_Id) is
3389 begin
3390 -- Deal with outputting Itype
3392 -- Note: if we are printing the full tree with -gnatds, then we may
3393 -- end up picking up the Associated_Node link from a generic template
3394 -- here which overlaps the Entity field, but as documented, Write_Itype
3395 -- is defended against junk calls.
3397 if Nkind (N) in N_Entity then
3398 Write_Itype (N);
3399 elsif Nkind (N) in N_Has_Entity then
3400 Write_Itype (Entity (N));
3401 end if;
3403 -- Case of a defining identifier
3405 if Nkind (N) = N_Defining_Identifier then
3407 -- If defining identifier has an interface name (and no
3408 -- address clause), then we output the interface name.
3410 if (Is_Imported (N) or else Is_Exported (N))
3411 and then Present (Interface_Name (N))
3412 and then No (Address_Clause (N))
3413 then
3414 String_To_Name_Buffer (Strval (Interface_Name (N)));
3415 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
3417 -- If no interface name (or inactive because there was
3418 -- an address clause), then just output the Chars name.
3420 else
3421 Write_Name_With_Col_Check (Chars (N));
3422 end if;
3424 -- Case of selector of an expanded name where the expanded name
3425 -- has an associated entity, output this entity.
3427 elsif Nkind (Parent (N)) = N_Expanded_Name
3428 and then Selector_Name (Parent (N)) = N
3429 and then Present (Entity (Parent (N)))
3430 then
3431 Write_Id (Entity (Parent (N)));
3433 -- For any other node with an associated entity, output it
3435 elsif Nkind (N) in N_Has_Entity
3436 and then Present (Entity_Or_Associated_Node (N))
3437 and then Nkind (Entity_Or_Associated_Node (N)) in N_Entity
3438 then
3439 Write_Id (Entity (N));
3441 -- All other cases, we just print the Chars field
3443 else
3444 Write_Name_With_Col_Check (Chars (N));
3445 end if;
3446 end Write_Id;
3448 -----------------------
3449 -- Write_Identifiers --
3450 -----------------------
3452 function Write_Identifiers (Node : Node_Id) return Boolean is
3453 begin
3454 Sprint_Node (Defining_Identifier (Node));
3455 Update_Itype (Defining_Identifier (Node));
3457 -- The remainder of the declaration must be printed unless we are
3458 -- printing the original tree and this is not the last identifier
3460 return
3461 not Dump_Original_Only or else not More_Ids (Node);
3463 end Write_Identifiers;
3465 ------------------------
3466 -- Write_Implicit_Def --
3467 ------------------------
3469 procedure Write_Implicit_Def (E : Entity_Id) is
3470 Ind : Node_Id;
3472 begin
3473 case Ekind (E) is
3474 when E_Array_Subtype =>
3475 Write_Str_With_Col_Check ("subtype ");
3476 Write_Id (E);
3477 Write_Str_With_Col_Check (" is ");
3478 Write_Id (Base_Type (E));
3479 Write_Str_With_Col_Check (" (");
3481 Ind := First_Index (E);
3482 while Present (Ind) loop
3483 Sprint_Node (Ind);
3484 Next_Index (Ind);
3486 if Present (Ind) then
3487 Write_Str (", ");
3488 end if;
3489 end loop;
3491 Write_Str (");");
3493 when E_Signed_Integer_Subtype | E_Enumeration_Subtype =>
3494 Write_Str_With_Col_Check ("subtype ");
3495 Write_Id (E);
3496 Write_Str (" is ");
3497 Write_Id (Etype (E));
3498 Write_Str_With_Col_Check (" range ");
3499 Sprint_Node (Scalar_Range (E));
3500 Write_Str (";");
3502 when others =>
3503 Write_Str_With_Col_Check ("type ");
3504 Write_Id (E);
3505 Write_Str_With_Col_Check (" is <");
3506 Write_Ekind (E);
3507 Write_Str (">;");
3508 end case;
3510 end Write_Implicit_Def;
3512 ------------------
3513 -- Write_Indent --
3514 ------------------
3516 procedure Write_Indent is
3517 Loc : constant Source_Ptr := Sloc (Dump_Node);
3519 begin
3520 if Indent_Annull_Flag then
3521 Indent_Annull_Flag := False;
3522 else
3523 -- Deal with Dump_Source_Text output. Note that we ignore implicit
3524 -- label declarations, since they typically have the sloc of the
3525 -- corresponding label, which really messes up the -gnatL output.
3527 if Dump_Source_Text
3528 and then Loc > No_Location
3529 and then Nkind (Dump_Node) /= N_Implicit_Label_Declaration
3530 then
3531 if Get_Source_File_Index (Loc) = Current_Source_File then
3532 Write_Source_Lines
3533 (Get_Physical_Line_Number (Sloc (Dump_Node)));
3534 end if;
3535 end if;
3537 Write_Eol;
3539 for J in 1 .. Indent loop
3540 Write_Char (' ');
3541 end loop;
3542 end if;
3543 end Write_Indent;
3545 ------------------------------
3546 -- Write_Indent_Identifiers --
3547 ------------------------------
3549 function Write_Indent_Identifiers (Node : Node_Id) return Boolean is
3550 begin
3551 -- We need to start a new line for every node, except in the case
3552 -- where we are printing the original tree and this is not the first
3553 -- defining identifier in the list.
3555 if not Dump_Original_Only or else not Prev_Ids (Node) then
3556 Write_Indent;
3558 -- If printing original tree and this is not the first defining
3559 -- identifier in the list, then the previous call to this procedure
3560 -- printed only the name, and we add a comma to separate the names.
3562 else
3563 Write_Str (", ");
3564 end if;
3566 Sprint_Node (Defining_Identifier (Node));
3568 -- The remainder of the declaration must be printed unless we are
3569 -- printing the original tree and this is not the last identifier
3571 return
3572 not Dump_Original_Only or else not More_Ids (Node);
3573 end Write_Indent_Identifiers;
3575 -----------------------------------
3576 -- Write_Indent_Identifiers_Sloc --
3577 -----------------------------------
3579 function Write_Indent_Identifiers_Sloc (Node : Node_Id) return Boolean is
3580 begin
3581 -- We need to start a new line for every node, except in the case
3582 -- where we are printing the original tree and this is not the first
3583 -- defining identifier in the list.
3585 if not Dump_Original_Only or else not Prev_Ids (Node) then
3586 Write_Indent;
3588 -- If printing original tree and this is not the first defining
3589 -- identifier in the list, then the previous call to this procedure
3590 -- printed only the name, and we add a comma to separate the names.
3592 else
3593 Write_Str (", ");
3594 end if;
3596 Set_Debug_Sloc;
3597 Sprint_Node (Defining_Identifier (Node));
3599 -- The remainder of the declaration must be printed unless we are
3600 -- printing the original tree and this is not the last identifier
3602 return not Dump_Original_Only or else not More_Ids (Node);
3603 end Write_Indent_Identifiers_Sloc;
3605 ----------------------
3606 -- Write_Indent_Str --
3607 ----------------------
3609 procedure Write_Indent_Str (S : String) is
3610 begin
3611 Write_Corresponding_Source (S);
3612 Write_Indent;
3613 Write_Str (S);
3614 end Write_Indent_Str;
3616 ---------------------------
3617 -- Write_Indent_Str_Sloc --
3618 ---------------------------
3620 procedure Write_Indent_Str_Sloc (S : String) is
3621 begin
3622 Write_Corresponding_Source (S);
3623 Write_Indent;
3624 Write_Str_Sloc (S);
3625 end Write_Indent_Str_Sloc;
3627 -----------------
3628 -- Write_Itype --
3629 -----------------
3631 procedure Write_Itype (Typ : Entity_Id) is
3633 procedure Write_Header (T : Boolean := True);
3634 -- Write type if T is True, subtype if T is false
3636 ------------------
3637 -- Write_Header --
3638 ------------------
3640 procedure Write_Header (T : Boolean := True) is
3641 begin
3642 if T then
3643 Write_Str ("[type ");
3644 else
3645 Write_Str ("[subtype ");
3646 end if;
3648 Write_Name_With_Col_Check (Chars (Typ));
3649 Write_Str (" is ");
3650 end Write_Header;
3652 -- Start of processing for Write_Itype
3654 begin
3655 if Nkind (Typ) in N_Entity
3656 and then Is_Itype (Typ)
3657 and then not Itype_Printed (Typ)
3658 then
3659 -- Itype to be printed
3661 declare
3662 B : constant Node_Id := Etype (Typ);
3663 X : Node_Id;
3664 P : constant Node_Id := Parent (Typ);
3666 S : constant Saved_Output_Buffer := Save_Output_Buffer;
3667 -- Save current output buffer
3669 Old_Sloc : Source_Ptr;
3670 -- Save sloc of related node, so it is not modified when
3671 -- printing with -gnatD.
3673 begin
3674 -- Write indentation at start of line
3676 for J in 1 .. Indent loop
3677 Write_Char (' ');
3678 end loop;
3680 -- If we have a constructed declaration for the itype, print it
3682 if Present (P)
3683 and then Nkind (P) in N_Declaration
3684 and then Defining_Entity (P) = Typ
3685 then
3686 -- We must set Itype_Printed true before the recursive call to
3687 -- print the node, otherwise we get an infinite recursion!
3689 Set_Itype_Printed (Typ, True);
3691 -- Write the declaration enclosed in [], avoiding new line
3692 -- at start of declaration, and semicolon at end.
3694 -- Note: The itype may be imported from another unit, in which
3695 -- case we do not want to modify the Sloc of the declaration.
3696 -- Otherwise the itype may appear to be in the current unit,
3697 -- and the back-end will reject a reference out of scope.
3699 Write_Char ('[');
3700 Indent_Annull_Flag := True;
3701 Old_Sloc := Sloc (P);
3702 Sprint_Node (P);
3703 Set_Sloc (P, Old_Sloc);
3704 Write_Erase_Char (';');
3706 -- If no constructed declaration, then we have to concoct the
3707 -- source corresponding to the type entity that we have at hand.
3709 else
3710 case Ekind (Typ) is
3712 -- Access types and subtypes
3714 when Access_Kind =>
3715 Write_Header (Ekind (Typ) = E_Access_Type);
3716 Write_Str ("access ");
3718 if Is_Access_Constant (Typ) then
3719 Write_Str ("constant ");
3720 elsif Can_Never_Be_Null (Typ) then
3721 Write_Str ("not null ");
3722 end if;
3724 Write_Id (Directly_Designated_Type (Typ));
3726 -- Array types and string types
3728 when E_Array_Type | E_String_Type =>
3729 Write_Header;
3730 Write_Str ("array (");
3732 X := First_Index (Typ);
3733 loop
3734 Sprint_Node (X);
3736 if not Is_Constrained (Typ) then
3737 Write_Str (" range <>");
3738 end if;
3740 Next_Index (X);
3741 exit when No (X);
3742 Write_Str (", ");
3743 end loop;
3745 Write_Str (") of ");
3746 X := Component_Type (Typ);
3748 -- Preserve sloc of component type, which is defined
3749 -- elsewhere than the itype (see comment above).
3751 Old_Sloc := Sloc (X);
3752 Sprint_Node (X);
3753 Set_Sloc (X, Old_Sloc);
3755 -- Array subtypes and string subtypes
3757 when E_Array_Subtype | E_String_Subtype =>
3758 Write_Header (False);
3759 Write_Id (Etype (Typ));
3760 Write_Str (" (");
3762 X := First_Index (Typ);
3763 loop
3764 Sprint_Node (X);
3765 Next_Index (X);
3766 exit when No (X);
3767 Write_Str (", ");
3768 end loop;
3770 Write_Char (')');
3772 -- Signed integer types, and modular integer subtypes
3774 when E_Signed_Integer_Type |
3775 E_Signed_Integer_Subtype |
3776 E_Modular_Integer_Subtype =>
3778 Write_Header (Ekind (Typ) = E_Signed_Integer_Type);
3780 if Ekind (Typ) = E_Signed_Integer_Type then
3781 Write_Str ("new ");
3782 end if;
3784 Write_Id (B);
3786 -- Print bounds if different from base type
3788 declare
3789 L : constant Node_Id := Type_Low_Bound (Typ);
3790 H : constant Node_Id := Type_High_Bound (Typ);
3791 LE : Node_Id;
3792 HE : Node_Id;
3794 begin
3795 -- B can either be a scalar type, in which case the
3796 -- declaration of Typ may constrain it with different
3797 -- bounds, or a private type, in which case we know
3798 -- that the declaration of Typ cannot have a scalar
3799 -- constraint.
3801 if Is_Scalar_Type (B) then
3802 LE := Type_Low_Bound (B);
3803 HE := Type_High_Bound (B);
3804 else
3805 LE := Empty;
3806 HE := Empty;
3807 end if;
3809 if No (LE)
3810 or else (True
3811 and then Nkind (L) = N_Integer_Literal
3812 and then Nkind (H) = N_Integer_Literal
3813 and then Nkind (LE) = N_Integer_Literal
3814 and then Nkind (HE) = N_Integer_Literal
3815 and then UI_Eq (Intval (L), Intval (LE))
3816 and then UI_Eq (Intval (H), Intval (HE)))
3817 then
3818 null;
3820 else
3821 Write_Str (" range ");
3822 Sprint_Node (Type_Low_Bound (Typ));
3823 Write_Str (" .. ");
3824 Sprint_Node (Type_High_Bound (Typ));
3825 end if;
3826 end;
3828 -- Modular integer types
3830 when E_Modular_Integer_Type =>
3831 Write_Header;
3832 Write_Str (" mod ");
3833 Write_Uint_With_Col_Check (Modulus (Typ), Auto);
3835 -- Floating point types and subtypes
3837 when E_Floating_Point_Type |
3838 E_Floating_Point_Subtype =>
3840 Write_Header (Ekind (Typ) = E_Floating_Point_Type);
3842 if Ekind (Typ) = E_Floating_Point_Type then
3843 Write_Str ("new ");
3844 end if;
3846 Write_Id (Etype (Typ));
3848 if Digits_Value (Typ) /= Digits_Value (Etype (Typ)) then
3849 Write_Str (" digits ");
3850 Write_Uint_With_Col_Check
3851 (Digits_Value (Typ), Decimal);
3852 end if;
3854 -- Print bounds if not different from base type
3856 declare
3857 L : constant Node_Id := Type_Low_Bound (Typ);
3858 H : constant Node_Id := Type_High_Bound (Typ);
3859 LE : constant Node_Id := Type_Low_Bound (B);
3860 HE : constant Node_Id := Type_High_Bound (B);
3862 begin
3863 if Nkind (L) = N_Real_Literal
3864 and then Nkind (H) = N_Real_Literal
3865 and then Nkind (LE) = N_Real_Literal
3866 and then Nkind (HE) = N_Real_Literal
3867 and then UR_Eq (Realval (L), Realval (LE))
3868 and then UR_Eq (Realval (H), Realval (HE))
3869 then
3870 null;
3872 else
3873 Write_Str (" range ");
3874 Sprint_Node (Type_Low_Bound (Typ));
3875 Write_Str (" .. ");
3876 Sprint_Node (Type_High_Bound (Typ));
3877 end if;
3878 end;
3880 -- Record subtypes
3882 when E_Record_Subtype =>
3883 Write_Header (False);
3884 Write_Str ("record");
3885 Indent_Begin;
3887 declare
3888 C : Entity_Id;
3889 begin
3890 C := First_Entity (Typ);
3891 while Present (C) loop
3892 Write_Indent;
3893 Write_Id (C);
3894 Write_Str (" : ");
3895 Write_Id (Etype (C));
3896 Next_Entity (C);
3897 end loop;
3898 end;
3900 Indent_End;
3901 Write_Indent_Str (" end record");
3903 -- Class-Wide types
3905 when E_Class_Wide_Type |
3906 E_Class_Wide_Subtype =>
3907 Write_Header;
3908 Write_Name_With_Col_Check (Chars (Etype (Typ)));
3909 Write_Str ("'Class");
3911 -- Subprogram types
3913 when E_Subprogram_Type =>
3914 Write_Header;
3916 if Etype (Typ) = Standard_Void_Type then
3917 Write_Str ("procedure");
3918 else
3919 Write_Str ("function");
3920 end if;
3922 if Present (First_Entity (Typ)) then
3923 Write_Str (" (");
3925 declare
3926 Param : Entity_Id;
3928 begin
3929 Param := First_Entity (Typ);
3930 loop
3931 Write_Id (Param);
3932 Write_Str (" : ");
3934 if Ekind (Param) = E_In_Out_Parameter then
3935 Write_Str ("in out ");
3936 elsif Ekind (Param) = E_Out_Parameter then
3937 Write_Str ("out ");
3938 end if;
3940 Write_Id (Etype (Param));
3941 Next_Entity (Param);
3942 exit when No (Param);
3943 Write_Str (", ");
3944 end loop;
3946 Write_Char (')');
3947 end;
3948 end if;
3950 if Etype (Typ) /= Standard_Void_Type then
3951 Write_Str (" return ");
3952 Write_Id (Etype (Typ));
3953 end if;
3955 when E_String_Literal_Subtype =>
3956 declare
3957 LB : constant Uint :=
3958 Intval (String_Literal_Low_Bound (Typ));
3959 Len : constant Uint :=
3960 String_Literal_Length (Typ);
3961 begin
3962 Write_Str ("String (");
3963 Write_Int (UI_To_Int (LB));
3964 Write_Str (" .. ");
3965 Write_Int (UI_To_Int (LB + Len) - 1);
3966 Write_Str (");");
3967 end;
3969 -- For all other Itypes, print ??? (fill in later)
3971 when others =>
3972 Write_Header (True);
3973 Write_Str ("???");
3975 end case;
3976 end if;
3978 -- Add terminating bracket and restore output buffer
3980 Write_Char (']');
3981 Write_Eol;
3982 Restore_Output_Buffer (S);
3983 end;
3985 Set_Itype_Printed (Typ);
3986 end if;
3987 end Write_Itype;
3989 -------------------------------
3990 -- Write_Name_With_Col_Check --
3991 -------------------------------
3993 procedure Write_Name_With_Col_Check (N : Name_Id) is
3994 J : Natural;
3995 K : Natural;
3996 L : Natural;
3998 begin
3999 Get_Name_String (N);
4001 -- Deal with -gnatdI which replaces any sequence Cnnnb where C is an
4002 -- upper case letter, nnn is one or more digits and b is a lower case
4003 -- letter by C...b, so that listings do not depend on serial numbers.
4005 if Debug_Flag_II then
4006 J := 1;
4007 while J < Name_Len - 1 loop
4008 if Name_Buffer (J) in 'A' .. 'Z'
4009 and then Name_Buffer (J + 1) in '0' .. '9'
4010 then
4011 K := J + 1;
4012 while K < Name_Len loop
4013 exit when Name_Buffer (K) not in '0' .. '9';
4014 K := K + 1;
4015 end loop;
4017 if Name_Buffer (K) in 'a' .. 'z' then
4018 L := Name_Len - K + 1;
4020 Name_Buffer (J + 4 .. J + L + 3) :=
4021 Name_Buffer (K .. Name_Len);
4022 Name_Buffer (J + 1 .. J + 3) := "...";
4023 Name_Len := J + L + 3;
4024 J := J + 5;
4026 else
4027 J := K;
4028 end if;
4030 else
4031 J := J + 1;
4032 end if;
4033 end loop;
4034 end if;
4036 -- Fall through for normal case
4038 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
4039 end Write_Name_With_Col_Check;
4041 ------------------------------------
4042 -- Write_Name_With_Col_Check_Sloc --
4043 ------------------------------------
4045 procedure Write_Name_With_Col_Check_Sloc (N : Name_Id) is
4046 begin
4047 Get_Name_String (N);
4048 Write_Str_With_Col_Check_Sloc (Name_Buffer (1 .. Name_Len));
4049 end Write_Name_With_Col_Check_Sloc;
4051 --------------------
4052 -- Write_Operator --
4053 --------------------
4055 procedure Write_Operator (N : Node_Id; S : String) is
4056 F : Natural := S'First;
4057 T : Natural := S'Last;
4059 begin
4060 -- If no overflow check, just write string out, and we are done
4062 if not Do_Overflow_Check (N) then
4063 Write_Str_Sloc (S);
4065 -- If overflow check, we want to surround the operator with curly
4066 -- brackets, but not include spaces within the brackets.
4068 else
4069 if S (F) = ' ' then
4070 Write_Char (' ');
4071 F := F + 1;
4072 end if;
4074 if S (T) = ' ' then
4075 T := T - 1;
4076 end if;
4078 Write_Char ('{');
4079 Write_Str_Sloc (S (F .. T));
4080 Write_Char ('}');
4082 if S (S'Last) = ' ' then
4083 Write_Char (' ');
4084 end if;
4085 end if;
4086 end Write_Operator;
4088 -----------------------
4089 -- Write_Param_Specs --
4090 -----------------------
4092 procedure Write_Param_Specs (N : Node_Id) is
4093 Specs : List_Id;
4094 Spec : Node_Id;
4095 Formal : Node_Id;
4097 begin
4098 Specs := Parameter_Specifications (N);
4100 if Is_Non_Empty_List (Specs) then
4101 Write_Str_With_Col_Check (" (");
4102 Spec := First (Specs);
4104 loop
4105 Sprint_Node (Spec);
4106 Formal := Defining_Identifier (Spec);
4107 Next (Spec);
4108 exit when Spec = Empty;
4110 -- Add semicolon, unless we are printing original tree and the
4111 -- next specification is part of a list (but not the first
4112 -- element of that list)
4114 if not Dump_Original_Only or else not Prev_Ids (Spec) then
4115 Write_Str ("; ");
4116 end if;
4117 end loop;
4119 -- Write out any extra formals
4121 while Present (Extra_Formal (Formal)) loop
4122 Formal := Extra_Formal (Formal);
4123 Write_Str ("; ");
4124 Write_Name_With_Col_Check (Chars (Formal));
4125 Write_Str (" : ");
4126 Write_Name_With_Col_Check (Chars (Etype (Formal)));
4127 end loop;
4129 Write_Char (')');
4130 end if;
4131 end Write_Param_Specs;
4133 -----------------------
4134 -- Write_Rewrite_Str --
4135 -----------------------
4137 procedure Write_Rewrite_Str (S : String) is
4138 begin
4139 if not Dump_Generated_Only then
4140 if S'Length = 3 and then S = ">>>" then
4141 Write_Str (">>>");
4142 else
4143 Write_Str_With_Col_Check (S);
4144 end if;
4145 end if;
4146 end Write_Rewrite_Str;
4148 -----------------------
4149 -- Write_Source_Line --
4150 -----------------------
4152 procedure Write_Source_Line (L : Physical_Line_Number) is
4153 Loc : Source_Ptr;
4154 Src : Source_Buffer_Ptr;
4155 Scn : Source_Ptr;
4157 begin
4158 if Dump_Source_Text then
4159 Src := Source_Text (Current_Source_File);
4160 Loc := Line_Start (L, Current_Source_File);
4161 Write_Eol;
4163 -- See if line is a comment line, if not, and if not line one,
4164 -- precede with blank line.
4166 Scn := Loc;
4167 while Src (Scn) = ' ' or else Src (Scn) = ASCII.HT loop
4168 Scn := Scn + 1;
4169 end loop;
4171 if (Src (Scn) in Line_Terminator
4172 or else Src (Scn .. Scn + 1) /= "--")
4173 and then L /= 1
4174 then
4175 Write_Eol;
4176 end if;
4178 -- Now write the source text of the line
4180 Write_Str ("-- ");
4181 Write_Int (Int (L));
4182 Write_Str (": ");
4184 while Src (Loc) not in Line_Terminator loop
4185 Write_Char (Src (Loc));
4186 Loc := Loc + 1;
4187 end loop;
4188 end if;
4189 end Write_Source_Line;
4191 ------------------------
4192 -- Write_Source_Lines --
4193 ------------------------
4195 procedure Write_Source_Lines (L : Physical_Line_Number) is
4196 begin
4197 while Last_Line_Printed < L loop
4198 Last_Line_Printed := Last_Line_Printed + 1;
4199 Write_Source_Line (Last_Line_Printed);
4200 end loop;
4201 end Write_Source_Lines;
4203 --------------------
4204 -- Write_Str_Sloc --
4205 --------------------
4207 procedure Write_Str_Sloc (S : String) is
4208 begin
4209 for J in S'Range loop
4210 Write_Char_Sloc (S (J));
4211 end loop;
4212 end Write_Str_Sloc;
4214 ------------------------------
4215 -- Write_Str_With_Col_Check --
4216 ------------------------------
4218 procedure Write_Str_With_Col_Check (S : String) is
4219 begin
4220 if Int (S'Last) + Column > Line_Limit then
4221 Write_Indent_Str (" ");
4223 if S (S'First) = ' ' then
4224 Write_Str (S (S'First + 1 .. S'Last));
4225 else
4226 Write_Str (S);
4227 end if;
4229 else
4230 Write_Str (S);
4231 end if;
4232 end Write_Str_With_Col_Check;
4234 -----------------------------------
4235 -- Write_Str_With_Col_Check_Sloc --
4236 -----------------------------------
4238 procedure Write_Str_With_Col_Check_Sloc (S : String) is
4239 begin
4240 if Int (S'Last) + Column > Line_Limit then
4241 Write_Indent_Str (" ");
4243 if S (S'First) = ' ' then
4244 Write_Str_Sloc (S (S'First + 1 .. S'Last));
4245 else
4246 Write_Str_Sloc (S);
4247 end if;
4249 else
4250 Write_Str_Sloc (S);
4251 end if;
4252 end Write_Str_With_Col_Check_Sloc;
4254 -------------------------------
4255 -- Write_Uint_With_Col_Check --
4256 -------------------------------
4258 procedure Write_Uint_With_Col_Check (U : Uint; Format : UI_Format) is
4259 begin
4260 Col_Check (UI_Decimal_Digits_Hi (U));
4261 UI_Write (U, Format);
4262 end Write_Uint_With_Col_Check;
4264 ------------------------------------
4265 -- Write_Uint_With_Col_Check_Sloc --
4266 ------------------------------------
4268 procedure Write_Uint_With_Col_Check_Sloc (U : Uint; Format : UI_Format) is
4269 begin
4270 Col_Check (UI_Decimal_Digits_Hi (U));
4271 Set_Debug_Sloc;
4272 UI_Write (U, Format);
4273 end Write_Uint_With_Col_Check_Sloc;
4275 -------------------------------------
4276 -- Write_Ureal_With_Col_Check_Sloc --
4277 -------------------------------------
4279 procedure Write_Ureal_With_Col_Check_Sloc (U : Ureal) is
4280 D : constant Uint := Denominator (U);
4281 N : constant Uint := Numerator (U);
4283 begin
4284 Col_Check
4285 (UI_Decimal_Digits_Hi (D) + UI_Decimal_Digits_Hi (N) + 4);
4286 Set_Debug_Sloc;
4287 UR_Write (U);
4288 end Write_Ureal_With_Col_Check_Sloc;
4290 end Sprint;