1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
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;
33 with Namet; use Namet;
34 with Nlists; use Nlists;
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.
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 -------------------------------
91 -- Operator Precedence Table --
92 -------------------------------
94 -- This table is used to decide whether a subexpression needs to be
95 -- parenthesized. The rule is that if an operand of an operator (which
96 -- for this purpose includes AND THEN and OR ELSE) is itself an operator
97 -- with a lower precedence than the operator (or equal precedence if
98 -- appearing as the right operand), then parentheses are required.
100 Op_Prec : constant array (N_Subexpr) of Short_Short_Integer :=
133 procedure Sprint_Left_Opnd (N : Node_Id);
134 -- Print left operand of operator, parenthesizing if necessary
136 procedure Sprint_Right_Opnd (N : Node_Id);
137 -- Print right operand of operator, parenthesizing if necessary
139 -----------------------
140 -- Local Subprograms --
141 -----------------------
143 procedure Col_Check (N : Nat);
144 -- Check that at least N characters remain on current line, and if not,
145 -- then start an extra line with two characters extra indentation for
146 -- continuing text on the next line.
148 procedure Extra_Blank_Line;
149 -- In some situations we write extra blank lines to separate the generated
150 -- code to make it more readable. However, these extra blank lines are not
151 -- generated in Dump_Source_Text mode, since there the source text lines
152 -- output with preceding blank lines are quite sufficient as separators.
153 -- This procedure writes a blank line if Dump_Source_Text is False.
155 procedure Indent_Annull;
156 -- Causes following call to Write_Indent to be ignored. This is used when
157 -- a higher level node wants to stop a lower level node from starting a
158 -- new line, when it would otherwise be inclined to do so (e.g. the case
159 -- of an accept statement called from an accept alternative with a guard)
161 procedure Indent_Begin;
162 -- Increase indentation level
164 procedure Indent_End;
165 -- Decrease indentation level
167 procedure Print_Debug_Line (S : String);
168 -- Used to print output lines in Debug_Generated_Code mode (this is used
169 -- as the argument for a call to Set_Special_Output in package Output).
171 procedure Process_TFAI_RR_Flags (Nod : Node_Id);
172 -- Given a divide, multiplication or division node, check the flags
173 -- Treat_Fixed_As_Integer and Rounded_Flags, and if set, output the
174 -- appropriate special syntax characters (# and @).
176 procedure Set_Debug_Sloc;
177 -- If Dump_Node is non-empty, this routine sets the appropriate value
178 -- in its Sloc field, from the current location in the debug source file
179 -- that is currently being written.
181 procedure Sprint_And_List (List : List_Id);
182 -- Print the given list with items separated by vertical "and"
184 procedure Sprint_Bar_List (List : List_Id);
185 -- Print the given list with items separated by vertical bars
187 procedure Sprint_End_Label
190 -- Print the end label for a Handled_Sequence_Of_Statements in a body.
191 -- If there is not end label, use the defining identifier of the enclosing
192 -- construct. If the end label is present, treat it as a reference to the
193 -- defining entity of the construct: this guarantees that it carries the
194 -- proper sloc information for debugging purposes.
196 procedure Sprint_Node_Actual (Node : Node_Id);
197 -- This routine prints its node argument. It is a lower level routine than
198 -- Sprint_Node, in that it does not bother about rewritten trees.
200 procedure Sprint_Node_Sloc (Node : Node_Id);
201 -- Like Sprint_Node, but in addition, in Debug_Generated_Code mode,
202 -- sets the Sloc of the current debug node to be a copy of the Sloc
203 -- of the sprinted node Node. Note that this is done after printing
204 -- Node, so that the Sloc is the proper updated value for the debug file.
206 procedure Update_Itype (Node : Node_Id);
207 -- Update the Sloc of an itype that is not attached to the tree, when
208 -- debugging expanded code. This routine is called from nodes whose
209 -- type can be an Itype, such as defining_identifiers that may be of
210 -- an anonymous access type, or ranges in slices.
212 procedure Write_Char_Sloc (C : Character);
213 -- Like Write_Char, except that if C is non-blank, Set_Debug_Sloc is
214 -- called to ensure that the current node has a proper Sloc set.
216 procedure Write_Condition_And_Reason (Node : Node_Id);
217 -- Write Condition and Reason codes of Raise_xxx_Error node
219 procedure Write_Corresponding_Source (S : String);
220 -- If S is a string with a single keyword (possibly followed by a space),
221 -- and if the next non-comment non-blank source line matches this keyword,
222 -- then output all source lines up to this matching line.
224 procedure Write_Discr_Specs (N : Node_Id);
225 -- Output discriminant specification for node, which is any of the type
226 -- declarations that can have discriminants.
228 procedure Write_Ekind (E : Entity_Id);
229 -- Write the String corresponding to the Ekind without "E_"
231 procedure Write_Id (N : Node_Id);
232 -- N is a node with a Chars field. This procedure writes the name that
233 -- will be used in the generated code associated with the name. For a
234 -- node with no associated entity, this is simply the Chars field. For
235 -- the case where there is an entity associated with the node, we print
236 -- the name associated with the entity (since it may have been encoded).
237 -- One other special case is that an entity has an active external name
238 -- (i.e. an external name present with no address clause), then this
239 -- external name is output. This procedure also deals with outputting
240 -- declarations of referenced itypes, if not output earlier.
242 function Write_Identifiers (Node : Node_Id) return Boolean;
243 -- Handle node where the grammar has a list of defining identifiers, but
244 -- the tree has a separate declaration for each identifier. Handles the
245 -- printing of the defining identifier, and returns True if the type and
246 -- initialization information is to be printed, False if it is to be
247 -- skipped (the latter case happens when printing defining identifiers
248 -- other than the first in the original tree output case).
250 procedure Write_Implicit_Def (E : Entity_Id);
251 pragma Warnings (Off, Write_Implicit_Def);
252 -- Write the definition of the implicit type E according to its Ekind
253 -- For now a debugging procedure, but might be used in the future.
255 procedure Write_Indent;
256 -- Start a new line and write indentation spacing
258 function Write_Indent_Identifiers (Node : Node_Id) return Boolean;
259 -- Like Write_Identifiers except that each new printed declaration
260 -- is at the start of a new line.
262 function Write_Indent_Identifiers_Sloc (Node : Node_Id) return Boolean;
263 -- Like Write_Indent_Identifiers except that in Debug_Generated_Code
264 -- mode, the Sloc of the current debug node is set to point to the
265 -- first output identifier.
267 procedure Write_Indent_Str (S : String);
268 -- Start a new line and write indent spacing followed by given string
270 procedure Write_Indent_Str_Sloc (S : String);
271 -- Like Write_Indent_Str, but in addition, in Debug_Generated_Code mode,
272 -- the Sloc of the current node is set to the first non-blank character
275 procedure Write_Itype (Typ : Entity_Id);
276 -- If Typ is an Itype that has not been written yet, write it. If Typ is
277 -- any other kind of entity or tree node, the call is ignored.
279 procedure Write_Name_With_Col_Check (N : Name_Id);
280 -- Write name (using Write_Name) with initial column check, and possible
281 -- initial Write_Indent (to get new line) if current line is too full.
283 procedure Write_Name_With_Col_Check_Sloc (N : Name_Id);
284 -- Like Write_Name_With_Col_Check but in addition, in Debug_Generated_Code
285 -- mode, sets Sloc of current debug node to first character of name.
287 procedure Write_Operator (N : Node_Id; S : String);
288 -- Like Write_Str_Sloc, used for operators, encloses the string in
289 -- characters {} if the Do_Overflow flag is set on the node N.
291 procedure Write_Param_Specs (N : Node_Id);
292 -- Output parameter specifications for node (which is either a function
293 -- or procedure specification with a Parameter_Specifications field)
295 procedure Write_Rewrite_Str (S : String);
296 -- Writes out a string (typically containing <<< or >>>}) for a node
297 -- created by rewriting the tree. Suppressed if we are outputting the
298 -- generated code only, since in this case we don't specially mark nodes
299 -- created by rewriting).
301 procedure Write_Source_Line (L : Physical_Line_Number);
302 -- If writing of interspersed source lines is enabled, then write the given
303 -- line from the source file, preceded by Eol, then an extra blank line if
304 -- the line has at least one blank, is not a comment and is not line one,
305 -- then "--" and the line number followed by period followed by text of the
306 -- source line (without terminating Eol). If interspersed source line
307 -- output not enabled, then the call has no effect.
309 procedure Write_Source_Lines (L : Physical_Line_Number);
310 -- If writing of interspersed source lines is enabled, then writes source
311 -- lines Last_Line_Printed + 1 .. L, and updates Last_Line_Printed. If
312 -- interspersed source line output not enabled, then call has no effect.
314 procedure Write_Str_Sloc (S : String);
315 -- Like Write_Str, but sets debug Sloc of current debug node to first
316 -- non-blank character if a current debug node is active.
318 procedure Write_Str_With_Col_Check (S : String);
319 -- Write string (using Write_Str) with initial column check, and possible
320 -- initial Write_Indent (to get new line) if current line is too full.
322 procedure Write_Str_With_Col_Check_Sloc (S : String);
323 -- Like Write_Str_With_Col_Check, but sets debug Sloc of current debug
324 -- node to first non-blank character if a current debug node is active.
326 procedure Write_Subprogram_Name (N : Node_Id);
327 -- N is the Name field of a function call or procedure statement call.
328 -- The effect of the call is to output the name, preceded by a $ if the
329 -- call is identified as an implicit call to a run time routine.
331 procedure Write_Uint_With_Col_Check (U : Uint; Format : UI_Format);
332 -- Write Uint (using UI_Write) with initial column check, and possible
333 -- initial Write_Indent (to get new line) if current line is too full.
334 -- The format parameter determines the output format (see UI_Write).
336 procedure Write_Uint_With_Col_Check_Sloc (U : Uint; Format : UI_Format);
337 -- Write Uint (using UI_Write) with initial column check, and possible
338 -- initial Write_Indent (to get new line) if current line is too full.
339 -- The format parameter determines the output format (see UI_Write).
340 -- In addition, in Debug_Generated_Code mode, sets the current node
341 -- Sloc to the first character of the output value.
343 procedure Write_Ureal_With_Col_Check_Sloc (U : Ureal);
344 -- Write Ureal (using same output format as UR_Write) with column checks
345 -- and a possible initial Write_Indent (to get new line) if current line
346 -- is too full. In addition, in Debug_Generated_Code mode, sets the
347 -- current node Sloc to the first character of the output value.
353 procedure Col_Check (N : Nat) is
355 if N + Column > Sprint_Line_Limit then
356 Write_Indent_Str (" ");
360 ----------------------
361 -- Extra_Blank_Line --
362 ----------------------
364 procedure Extra_Blank_Line is
366 if not Dump_Source_Text then
369 end Extra_Blank_Line;
375 procedure Indent_Annull is
377 Indent_Annull_Flag := True;
384 procedure Indent_Begin is
386 Indent := Indent + 3;
393 procedure Indent_End is
395 Indent := Indent - 3;
402 procedure pg (Arg : Union_Id) is
404 Dump_Generated_Only := True;
405 Dump_Original_Only := False;
406 Current_Source_File := No_Source_File;
408 if Arg in List_Range then
409 Sprint_Node_List (List_Id (Arg));
411 elsif Arg in Node_Range then
412 Sprint_Node (Node_Id (Arg));
425 procedure po (Arg : Union_Id) is
427 Dump_Generated_Only := False;
428 Dump_Original_Only := True;
429 Current_Source_File := No_Source_File;
431 if Arg in List_Range then
432 Sprint_Node_List (List_Id (Arg));
434 elsif Arg in Node_Range then
435 Sprint_Node (Node_Id (Arg));
444 ----------------------
445 -- Print_Debug_Line --
446 ----------------------
448 procedure Print_Debug_Line (S : String) is
450 Write_Debug_Line (S, Debug_Sloc);
451 end Print_Debug_Line;
453 ---------------------------
454 -- Process_TFAI_RR_Flags --
455 ---------------------------
457 procedure Process_TFAI_RR_Flags (Nod : Node_Id) is
459 if Treat_Fixed_As_Integer (Nod) then
463 if Rounded_Result (Nod) then
466 end Process_TFAI_RR_Flags;
472 procedure ps (Arg : Union_Id) is
474 Dump_Generated_Only := False;
475 Dump_Original_Only := False;
476 Current_Source_File := No_Source_File;
478 if Arg in List_Range then
479 Sprint_Node_List (List_Id (Arg));
481 elsif Arg in Node_Range then
482 Sprint_Node (Node_Id (Arg));
495 procedure Set_Debug_Sloc is
497 if Debug_Generated_Code and then Present (Dump_Node) then
498 Set_Sloc (Dump_Node, Debug_Sloc + Source_Ptr (Column - 1));
507 procedure Source_Dump is
510 -- Put underline under string we just printed
516 procedure Underline is
517 Col : constant Int := Column;
522 while Col > Column loop
529 -- Start of processing for Tree_Dump
532 Dump_Generated_Only := Debug_Flag_G or
533 Print_Generated_Code or
534 Debug_Generated_Code;
535 Dump_Original_Only := Debug_Flag_O;
536 Dump_Freeze_Null := Debug_Flag_S or Debug_Flag_G;
538 -- Note that we turn off the tree dump flags immediately, before
539 -- starting the dump. This avoids generating two copies of the dump
540 -- if an abort occurs after printing the dump, and more importantly,
541 -- avoids an infinite loop if an abort occurs during the dump.
544 Current_Source_File := No_Source_File;
545 Debug_Flag_Z := False;
548 Write_Str ("Source recreated from tree of Standard (spec)");
550 Sprint_Node (Standard_Package_Node);
555 if Debug_Flag_S or Dump_Generated_Only or Dump_Original_Only then
556 Debug_Flag_G := False;
557 Debug_Flag_O := False;
558 Debug_Flag_S := False;
560 -- Dump requested units
562 for U in Main_Unit .. Last_Unit loop
563 Current_Source_File := Source_Index (U);
565 -- Dump all units if -gnatdf set, otherwise we dump only
566 -- the source files that are in the extended main source.
569 or else In_Extended_Main_Source_Unit (Cunit_Entity (U))
571 -- If we are generating debug files, setup to write them
573 if Debug_Generated_Code then
574 Set_Special_Output (Print_Debug_Line'Access);
575 Create_Debug_Source (Source_Index (U), Debug_Sloc);
576 Write_Source_Line (1);
577 Last_Line_Printed := 1;
578 Sprint_Node (Cunit (U));
579 Write_Source_Lines (Last_Source_Line (Current_Source_File));
582 Set_Special_Output (null);
584 -- Normal output to standard output file
587 Write_Str ("Source recreated from tree for ");
588 Write_Unit_Name (Unit_Name (U));
590 Write_Source_Line (1);
591 Last_Line_Printed := 1;
592 Sprint_Node (Cunit (U));
593 Write_Source_Lines (Last_Source_Line (Current_Source_File));
602 ---------------------
603 -- Sprint_And_List --
604 ---------------------
606 procedure Sprint_And_List (List : List_Id) is
609 if Is_Non_Empty_List (List) then
610 Node := First (List);
614 exit when Node = Empty;
620 ---------------------
621 -- Sprint_Bar_List --
622 ---------------------
624 procedure Sprint_Bar_List (List : List_Id) is
627 if Is_Non_Empty_List (List) then
628 Node := First (List);
632 exit when Node = Empty;
638 ----------------------
639 -- Sprint_End_Label --
640 ----------------------
642 procedure Sprint_End_Label
648 and then Present (End_Label (Node))
649 and then Is_Entity_Name (End_Label (Node))
651 Set_Entity (End_Label (Node), Default);
653 -- For a function whose name is an operator, use the qualified name
654 -- created for the defining entity.
656 if Nkind (End_Label (Node)) = N_Operator_Symbol then
657 Set_Chars (End_Label (Node), Chars (Default));
660 Sprint_Node (End_Label (Node));
662 Sprint_Node (Default);
664 end Sprint_End_Label;
666 -----------------------
667 -- Sprint_Comma_List --
668 -----------------------
670 procedure Sprint_Comma_List (List : List_Id) is
674 if Is_Non_Empty_List (List) then
675 Node := First (List);
679 exit when Node = Empty;
681 if not Is_Rewrite_Insertion (Node)
682 or else not Dump_Original_Only
688 end Sprint_Comma_List;
690 --------------------------
691 -- Sprint_Indented_List --
692 --------------------------
694 procedure Sprint_Indented_List (List : List_Id) is
697 Sprint_Node_List (List);
699 end Sprint_Indented_List;
701 ---------------------
702 -- Sprint_Left_Opnd --
703 ---------------------
705 procedure Sprint_Left_Opnd (N : Node_Id) is
706 Opnd : constant Node_Id := Left_Opnd (N);
709 if Paren_Count (Opnd) /= 0
710 or else Op_Prec (Nkind (Opnd)) >= Op_Prec (Nkind (N))
719 end Sprint_Left_Opnd;
725 procedure Sprint_Node (Node : Node_Id) is
727 if Is_Rewrite_Insertion (Node) then
728 if not Dump_Original_Only then
730 -- For special cases of nodes that always output <<< >>>
731 -- do not duplicate the output at this point.
733 if Nkind (Node) = N_Freeze_Entity
734 or else Nkind (Node) = N_Implicit_Label_Declaration
736 Sprint_Node_Actual (Node);
738 -- Normal case where <<< >>> may be required
741 Write_Rewrite_Str ("<<<");
742 Sprint_Node_Actual (Node);
743 Write_Rewrite_Str (">>>");
747 elsif Is_Rewrite_Substitution (Node) then
749 -- Case of dump generated only
751 if Dump_Generated_Only then
752 Sprint_Node_Actual (Node);
754 -- Case of dump original only
756 elsif Dump_Original_Only then
757 Sprint_Node_Actual (Original_Node (Node));
759 -- Case of both being dumped
762 Sprint_Node_Actual (Original_Node (Node));
763 Write_Rewrite_Str ("<<<");
764 Sprint_Node_Actual (Node);
765 Write_Rewrite_Str (">>>");
769 Sprint_Node_Actual (Node);
773 ------------------------
774 -- Sprint_Node_Actual --
775 ------------------------
777 procedure Sprint_Node_Actual (Node : Node_Id) is
778 Save_Dump_Node : constant Node_Id := Dump_Node;
785 for J in 1 .. Paren_Count (Node) loop
786 Write_Str_With_Col_Check ("(");
789 -- Setup current dump node
793 if Nkind (Node) in N_Subexpr
794 and then Do_Range_Check (Node)
796 Write_Str_With_Col_Check ("{");
799 -- Select print circuit based on node kind
803 when N_Abort_Statement =>
804 Write_Indent_Str_Sloc ("abort ");
805 Sprint_Comma_List (Names (Node));
808 when N_Abortable_Part =>
810 Write_Str_Sloc ("abort ");
811 Sprint_Indented_List (Statements (Node));
813 when N_Abstract_Subprogram_Declaration =>
815 Sprint_Node (Specification (Node));
816 Write_Str_With_Col_Check (" is ");
817 Write_Str_Sloc ("abstract;");
819 when N_Accept_Alternative =>
820 Sprint_Node_List (Pragmas_Before (Node));
822 if Present (Condition (Node)) then
823 Write_Indent_Str ("when ");
824 Sprint_Node (Condition (Node));
829 Sprint_Node_Sloc (Accept_Statement (Node));
830 Sprint_Node_List (Statements (Node));
832 when N_Accept_Statement =>
833 Write_Indent_Str_Sloc ("accept ");
834 Write_Id (Entry_Direct_Name (Node));
836 if Present (Entry_Index (Node)) then
837 Write_Str_With_Col_Check (" (");
838 Sprint_Node (Entry_Index (Node));
842 Write_Param_Specs (Node);
844 if Present (Handled_Statement_Sequence (Node)) then
845 Write_Str_With_Col_Check (" do");
846 Sprint_Node (Handled_Statement_Sequence (Node));
847 Write_Indent_Str ("end ");
848 Write_Id (Entry_Direct_Name (Node));
853 when N_Access_Definition =>
857 if Present (Access_To_Subprogram_Definition (Node)) then
858 Sprint_Node (Access_To_Subprogram_Definition (Node));
862 if Null_Exclusion_Present (Node) then
863 Write_Str ("not null ");
866 Write_Str_With_Col_Check_Sloc ("access ");
868 if All_Present (Node) then
870 elsif Constant_Present (Node) then
871 Write_Str ("constant ");
874 Sprint_Node (Subtype_Mark (Node));
877 when N_Access_Function_Definition =>
881 if Null_Exclusion_Present (Node) then
882 Write_Str ("not null ");
885 Write_Str_With_Col_Check_Sloc ("access ");
887 if Protected_Present (Node) then
888 Write_Str_With_Col_Check ("protected ");
891 Write_Str_With_Col_Check ("function");
892 Write_Param_Specs (Node);
893 Write_Str_With_Col_Check (" return ");
894 Sprint_Node (Result_Definition (Node));
896 when N_Access_Procedure_Definition =>
900 if Null_Exclusion_Present (Node) then
901 Write_Str ("not null ");
904 Write_Str_With_Col_Check_Sloc ("access ");
906 if Protected_Present (Node) then
907 Write_Str_With_Col_Check ("protected ");
910 Write_Str_With_Col_Check ("procedure");
911 Write_Param_Specs (Node);
913 when N_Access_To_Object_Definition =>
914 Write_Str_With_Col_Check_Sloc ("access ");
916 if All_Present (Node) then
917 Write_Str_With_Col_Check ("all ");
918 elsif Constant_Present (Node) then
919 Write_Str_With_Col_Check ("constant ");
924 if Null_Exclusion_Present (Node) then
925 Write_Str ("not null ");
928 Sprint_Node (Subtype_Indication (Node));
931 if Null_Record_Present (Node) then
932 Write_Str_With_Col_Check_Sloc ("(null record)");
935 Write_Str_With_Col_Check_Sloc ("(");
937 if Present (Expressions (Node)) then
938 Sprint_Comma_List (Expressions (Node));
940 if Present (Component_Associations (Node))
941 and then not Is_Empty_List (Component_Associations (Node))
947 if Present (Component_Associations (Node))
948 and then not Is_Empty_List (Component_Associations (Node))
956 Nd := First (Component_Associations (Node));
964 if not Is_Rewrite_Insertion (Nd)
965 or else not Dump_Original_Only
979 Write_Str_With_Col_Check_Sloc ("new ");
983 if Null_Exclusion_Present (Node) then
984 Write_Str ("not null ");
987 Sprint_Node (Expression (Node));
989 if Present (Storage_Pool (Node)) then
990 Write_Str_With_Col_Check ("[storage_pool = ");
991 Sprint_Node (Storage_Pool (Node));
996 Sprint_Left_Opnd (Node);
997 Write_Str_Sloc (" and then ");
998 Sprint_Right_Opnd (Node);
1001 Write_Indent_Str_Sloc ("for ");
1002 Write_Id (Identifier (Node));
1003 Write_Str_With_Col_Check (" use at ");
1004 Sprint_Node (Expression (Node));
1007 when N_Assignment_Statement =>
1009 Sprint_Node (Name (Node));
1010 Write_Str_Sloc (" := ");
1011 Sprint_Node (Expression (Node));
1014 when N_Asynchronous_Select =>
1015 Write_Indent_Str_Sloc ("select");
1017 Sprint_Node (Triggering_Alternative (Node));
1020 -- Note: let the printing of Abortable_Part handle outputting
1021 -- the ABORT keyword, so that the Sloc can be set correctly.
1023 Write_Indent_Str ("then ");
1024 Sprint_Node (Abortable_Part (Node));
1025 Write_Indent_Str ("end select;");
1027 when N_Attribute_Definition_Clause =>
1028 Write_Indent_Str_Sloc ("for ");
1029 Sprint_Node (Name (Node));
1031 Write_Name_With_Col_Check (Chars (Node));
1032 Write_Str_With_Col_Check (" use ");
1033 Sprint_Node (Expression (Node));
1036 when N_Attribute_Reference =>
1037 if Is_Procedure_Attribute_Name (Attribute_Name (Node)) then
1041 Sprint_Node (Prefix (Node));
1042 Write_Char_Sloc (''');
1043 Write_Name_With_Col_Check (Attribute_Name (Node));
1044 Sprint_Paren_Comma_List (Expressions (Node));
1046 if Is_Procedure_Attribute_Name (Attribute_Name (Node)) then
1050 when N_Block_Statement =>
1053 if Present (Identifier (Node))
1054 and then (not Has_Created_Identifier (Node)
1055 or else not Dump_Original_Only)
1057 Write_Rewrite_Str ("<<<");
1058 Write_Id (Identifier (Node));
1060 Write_Rewrite_Str (">>>");
1063 if Present (Declarations (Node)) then
1064 Write_Str_With_Col_Check_Sloc ("declare");
1065 Sprint_Indented_List (Declarations (Node));
1069 Write_Str_With_Col_Check_Sloc ("begin");
1070 Sprint_Node (Handled_Statement_Sequence (Node));
1071 Write_Indent_Str ("end");
1073 if Present (Identifier (Node))
1074 and then (not Has_Created_Identifier (Node)
1075 or else not Dump_Original_Only)
1077 Write_Rewrite_Str ("<<<");
1079 Write_Id (Identifier (Node));
1080 Write_Rewrite_Str (">>>");
1085 when N_Case_Statement =>
1086 Write_Indent_Str_Sloc ("case ");
1087 Sprint_Node (Expression (Node));
1089 Sprint_Indented_List (Alternatives (Node));
1090 Write_Indent_Str ("end case;");
1092 when N_Case_Statement_Alternative =>
1093 Write_Indent_Str_Sloc ("when ");
1094 Sprint_Bar_List (Discrete_Choices (Node));
1096 Sprint_Indented_List (Statements (Node));
1098 when N_Character_Literal =>
1099 if Column > Sprint_Line_Limit - 2 then
1100 Write_Indent_Str (" ");
1103 Write_Char_Sloc (''');
1104 Write_Char_Code (UI_To_CC (Char_Literal_Value (Node)));
1107 when N_Code_Statement =>
1110 Sprint_Node (Expression (Node));
1113 when N_Compilation_Unit =>
1114 Sprint_Node_List (Context_Items (Node));
1115 Sprint_Opt_Node_List (Declarations (Aux_Decls_Node (Node)));
1117 if Private_Present (Node) then
1118 Write_Indent_Str ("private ");
1122 Sprint_Node_Sloc (Unit (Node));
1124 if Present (Actions (Aux_Decls_Node (Node)))
1126 Present (Pragmas_After (Aux_Decls_Node (Node)))
1131 Sprint_Opt_Node_List (Actions (Aux_Decls_Node (Node)));
1132 Sprint_Opt_Node_List (Pragmas_After (Aux_Decls_Node (Node)));
1134 when N_Compilation_Unit_Aux =>
1135 null; -- nothing to do, never used, see above
1137 when N_Component_Association =>
1139 Sprint_Bar_List (Choices (Node));
1142 -- Ada 2005 (AI-287): Print the box if present
1144 if Box_Present (Node) then
1145 Write_Str_With_Col_Check ("<>");
1147 Sprint_Node (Expression (Node));
1150 when N_Component_Clause =>
1152 Sprint_Node (Component_Name (Node));
1153 Write_Str_Sloc (" at ");
1154 Sprint_Node (Position (Node));
1156 Write_Str_With_Col_Check ("range ");
1157 Sprint_Node (First_Bit (Node));
1159 Sprint_Node (Last_Bit (Node));
1162 when N_Component_Definition =>
1165 -- Ada 2005 (AI-230): Access definition components
1167 if Present (Access_Definition (Node)) then
1168 Sprint_Node (Access_Definition (Node));
1170 elsif Present (Subtype_Indication (Node)) then
1171 if Aliased_Present (Node) then
1172 Write_Str_With_Col_Check ("aliased ");
1175 -- Ada 2005 (AI-231)
1177 if Null_Exclusion_Present (Node) then
1178 Write_Str (" not null ");
1181 Sprint_Node (Subtype_Indication (Node));
1184 Write_Str (" ??? ");
1187 when N_Component_Declaration =>
1188 if Write_Indent_Identifiers_Sloc (Node) then
1190 Sprint_Node (Component_Definition (Node));
1192 if Present (Expression (Node)) then
1194 Sprint_Node (Expression (Node));
1200 when N_Component_List =>
1201 if Null_Present (Node) then
1203 Write_Indent_Str_Sloc ("null");
1209 Sprint_Indented_List (Component_Items (Node));
1210 Sprint_Node (Variant_Part (Node));
1213 when N_Conditional_Entry_Call =>
1214 Write_Indent_Str_Sloc ("select");
1216 Sprint_Node (Entry_Call_Alternative (Node));
1218 Write_Indent_Str ("else");
1219 Sprint_Indented_List (Else_Statements (Node));
1220 Write_Indent_Str ("end select;");
1222 when N_Conditional_Expression =>
1224 Condition : constant Node_Id := First (Expressions (Node));
1225 Then_Expr : constant Node_Id := Next (Condition);
1226 Else_Expr : constant Node_Id := Next (Then_Expr);
1228 Write_Str_With_Col_Check_Sloc ("(if ");
1229 Sprint_Node (Condition);
1230 Write_Str_With_Col_Check (" then ");
1231 Sprint_Node (Then_Expr);
1232 Write_Str_With_Col_Check (" else ");
1233 Sprint_Node (Else_Expr);
1237 when N_Constrained_Array_Definition =>
1238 Write_Str_With_Col_Check_Sloc ("array ");
1239 Sprint_Paren_Comma_List (Discrete_Subtype_Definitions (Node));
1242 Sprint_Node (Component_Definition (Node));
1244 when N_Decimal_Fixed_Point_Definition =>
1245 Write_Str_With_Col_Check_Sloc (" delta ");
1246 Sprint_Node (Delta_Expression (Node));
1247 Write_Str_With_Col_Check ("digits ");
1248 Sprint_Node (Digits_Expression (Node));
1249 Sprint_Opt_Node (Real_Range_Specification (Node));
1251 when N_Defining_Character_Literal =>
1252 Write_Name_With_Col_Check_Sloc (Chars (Node));
1254 when N_Defining_Identifier =>
1258 when N_Defining_Operator_Symbol =>
1259 Write_Name_With_Col_Check_Sloc (Chars (Node));
1261 when N_Defining_Program_Unit_Name =>
1263 Sprint_Node (Name (Node));
1265 Write_Id (Defining_Identifier (Node));
1267 when N_Delay_Alternative =>
1268 Sprint_Node_List (Pragmas_Before (Node));
1270 if Present (Condition (Node)) then
1272 Write_Str_With_Col_Check ("when ");
1273 Sprint_Node (Condition (Node));
1278 Sprint_Node_Sloc (Delay_Statement (Node));
1279 Sprint_Node_List (Statements (Node));
1281 when N_Delay_Relative_Statement =>
1282 Write_Indent_Str_Sloc ("delay ");
1283 Sprint_Node (Expression (Node));
1286 when N_Delay_Until_Statement =>
1287 Write_Indent_Str_Sloc ("delay until ");
1288 Sprint_Node (Expression (Node));
1291 when N_Delta_Constraint =>
1292 Write_Str_With_Col_Check_Sloc ("delta ");
1293 Sprint_Node (Delta_Expression (Node));
1294 Sprint_Opt_Node (Range_Constraint (Node));
1296 when N_Derived_Type_Definition =>
1297 if Abstract_Present (Node) then
1298 Write_Str_With_Col_Check ("abstract ");
1301 Write_Str_With_Col_Check_Sloc ("new ");
1303 -- Ada 2005 (AI-231)
1305 if Null_Exclusion_Present (Node) then
1306 Write_Str_With_Col_Check ("not null ");
1309 Sprint_Node (Subtype_Indication (Node));
1311 if Present (Interface_List (Node)) then
1312 Write_Str_With_Col_Check (" and ");
1313 Sprint_And_List (Interface_List (Node));
1314 Write_Str_With_Col_Check (" with ");
1317 if Present (Record_Extension_Part (Node)) then
1318 if No (Interface_List (Node)) then
1319 Write_Str_With_Col_Check (" with ");
1322 Sprint_Node (Record_Extension_Part (Node));
1325 when N_Designator =>
1326 Sprint_Node (Name (Node));
1327 Write_Char_Sloc ('.');
1328 Write_Id (Identifier (Node));
1330 when N_Digits_Constraint =>
1331 Write_Str_With_Col_Check_Sloc ("digits ");
1332 Sprint_Node (Digits_Expression (Node));
1333 Sprint_Opt_Node (Range_Constraint (Node));
1335 when N_Discriminant_Association =>
1338 if Present (Selector_Names (Node)) then
1339 Sprint_Bar_List (Selector_Names (Node));
1344 Sprint_Node (Expression (Node));
1346 when N_Discriminant_Specification =>
1349 if Write_Identifiers (Node) then
1352 if Null_Exclusion_Present (Node) then
1353 Write_Str ("not null ");
1356 Sprint_Node (Discriminant_Type (Node));
1358 if Present (Expression (Node)) then
1360 Sprint_Node (Expression (Node));
1366 when N_Elsif_Part =>
1367 Write_Indent_Str_Sloc ("elsif ");
1368 Sprint_Node (Condition (Node));
1369 Write_Str_With_Col_Check (" then");
1370 Sprint_Indented_List (Then_Statements (Node));
1375 when N_Entry_Body =>
1376 Write_Indent_Str_Sloc ("entry ");
1377 Write_Id (Defining_Identifier (Node));
1378 Sprint_Node (Entry_Body_Formal_Part (Node));
1379 Write_Str_With_Col_Check (" is");
1380 Sprint_Indented_List (Declarations (Node));
1381 Write_Indent_Str ("begin");
1382 Sprint_Node (Handled_Statement_Sequence (Node));
1383 Write_Indent_Str ("end ");
1384 Write_Id (Defining_Identifier (Node));
1387 when N_Entry_Body_Formal_Part =>
1388 if Present (Entry_Index_Specification (Node)) then
1389 Write_Str_With_Col_Check_Sloc (" (");
1390 Sprint_Node (Entry_Index_Specification (Node));
1394 Write_Param_Specs (Node);
1395 Write_Str_With_Col_Check_Sloc (" when ");
1396 Sprint_Node (Condition (Node));
1398 when N_Entry_Call_Alternative =>
1399 Sprint_Node_List (Pragmas_Before (Node));
1400 Sprint_Node_Sloc (Entry_Call_Statement (Node));
1401 Sprint_Node_List (Statements (Node));
1403 when N_Entry_Call_Statement =>
1405 Sprint_Node_Sloc (Name (Node));
1406 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
1409 when N_Entry_Declaration =>
1410 Write_Indent_Str_Sloc ("entry ");
1411 Write_Id (Defining_Identifier (Node));
1413 if Present (Discrete_Subtype_Definition (Node)) then
1414 Write_Str_With_Col_Check (" (");
1415 Sprint_Node (Discrete_Subtype_Definition (Node));
1419 Write_Param_Specs (Node);
1422 when N_Entry_Index_Specification =>
1423 Write_Str_With_Col_Check_Sloc ("for ");
1424 Write_Id (Defining_Identifier (Node));
1425 Write_Str_With_Col_Check (" in ");
1426 Sprint_Node (Discrete_Subtype_Definition (Node));
1428 when N_Enumeration_Representation_Clause =>
1429 Write_Indent_Str_Sloc ("for ");
1430 Write_Id (Identifier (Node));
1431 Write_Str_With_Col_Check (" use ");
1432 Sprint_Node (Array_Aggregate (Node));
1435 when N_Enumeration_Type_Definition =>
1438 -- Skip attempt to print Literals field if it's not there and
1439 -- we are in package Standard (case of Character, which is
1440 -- handled specially (without an explicit literals list).
1442 if Sloc (Node) > Standard_Location
1443 or else Present (Literals (Node))
1445 Sprint_Paren_Comma_List (Literals (Node));
1449 Write_Str_With_Col_Check_Sloc ("<error>");
1451 when N_Exception_Declaration =>
1452 if Write_Indent_Identifiers (Node) then
1453 Write_Str_With_Col_Check (" : ");
1455 if Is_Statically_Allocated (Defining_Identifier (Node)) then
1456 Write_Str_With_Col_Check ("static ");
1459 Write_Str_Sloc ("exception");
1461 if Present (Expression (Node)) then
1463 Sprint_Node (Expression (Node));
1469 when N_Exception_Handler =>
1470 Write_Indent_Str_Sloc ("when ");
1472 if Present (Choice_Parameter (Node)) then
1473 Sprint_Node (Choice_Parameter (Node));
1477 Sprint_Bar_List (Exception_Choices (Node));
1479 Sprint_Indented_List (Statements (Node));
1481 when N_Exception_Renaming_Declaration =>
1484 Sprint_Node (Defining_Identifier (Node));
1485 Write_Str_With_Col_Check (" : exception renames ");
1486 Sprint_Node (Name (Node));
1489 when N_Exit_Statement =>
1490 Write_Indent_Str_Sloc ("exit");
1491 Sprint_Opt_Node (Name (Node));
1493 if Present (Condition (Node)) then
1494 Write_Str_With_Col_Check (" when ");
1495 Sprint_Node (Condition (Node));
1500 when N_Expanded_Name =>
1501 Sprint_Node (Prefix (Node));
1502 Write_Char_Sloc ('.');
1503 Sprint_Node (Selector_Name (Node));
1505 when N_Explicit_Dereference =>
1506 Sprint_Node (Prefix (Node));
1507 Write_Char_Sloc ('.');
1508 Write_Str_Sloc ("all");
1510 when N_Extended_Return_Statement =>
1511 Write_Indent_Str_Sloc ("return ");
1512 Sprint_Node_List (Return_Object_Declarations (Node));
1514 if Present (Handled_Statement_Sequence (Node)) then
1515 Write_Str_With_Col_Check (" do");
1516 Sprint_Node (Handled_Statement_Sequence (Node));
1517 Write_Indent_Str ("end return;");
1519 Write_Indent_Str (";");
1522 when N_Extension_Aggregate =>
1523 Write_Str_With_Col_Check_Sloc ("(");
1524 Sprint_Node (Ancestor_Part (Node));
1525 Write_Str_With_Col_Check (" with ");
1527 if Null_Record_Present (Node) then
1528 Write_Str_With_Col_Check ("null record");
1530 if Present (Expressions (Node)) then
1531 Sprint_Comma_List (Expressions (Node));
1533 if Present (Component_Associations (Node)) then
1538 if Present (Component_Associations (Node)) then
1539 Sprint_Comma_List (Component_Associations (Node));
1545 when N_Floating_Point_Definition =>
1546 Write_Str_With_Col_Check_Sloc ("digits ");
1547 Sprint_Node (Digits_Expression (Node));
1548 Sprint_Opt_Node (Real_Range_Specification (Node));
1550 when N_Formal_Decimal_Fixed_Point_Definition =>
1551 Write_Str_With_Col_Check_Sloc ("delta <> digits <>");
1553 when N_Formal_Derived_Type_Definition =>
1554 Write_Str_With_Col_Check_Sloc ("new ");
1555 Sprint_Node (Subtype_Mark (Node));
1557 if Present (Interface_List (Node)) then
1558 Write_Str_With_Col_Check (" and ");
1559 Sprint_And_List (Interface_List (Node));
1562 if Private_Present (Node) then
1563 Write_Str_With_Col_Check (" with private");
1566 when N_Formal_Abstract_Subprogram_Declaration =>
1567 Write_Indent_Str_Sloc ("with ");
1568 Sprint_Node (Specification (Node));
1570 Write_Str_With_Col_Check (" is abstract");
1572 if Box_Present (Node) then
1573 Write_Str_With_Col_Check (" <>");
1574 elsif Present (Default_Name (Node)) then
1575 Write_Str_With_Col_Check (" ");
1576 Sprint_Node (Default_Name (Node));
1581 when N_Formal_Concrete_Subprogram_Declaration =>
1582 Write_Indent_Str_Sloc ("with ");
1583 Sprint_Node (Specification (Node));
1585 if Box_Present (Node) then
1586 Write_Str_With_Col_Check (" is <>");
1587 elsif Present (Default_Name (Node)) then
1588 Write_Str_With_Col_Check (" is ");
1589 Sprint_Node (Default_Name (Node));
1594 when N_Formal_Discrete_Type_Definition =>
1595 Write_Str_With_Col_Check_Sloc ("<>");
1597 when N_Formal_Floating_Point_Definition =>
1598 Write_Str_With_Col_Check_Sloc ("digits <>");
1600 when N_Formal_Modular_Type_Definition =>
1601 Write_Str_With_Col_Check_Sloc ("mod <>");
1603 when N_Formal_Object_Declaration =>
1606 if Write_Indent_Identifiers (Node) then
1609 if In_Present (Node) then
1610 Write_Str_With_Col_Check ("in ");
1613 if Out_Present (Node) then
1614 Write_Str_With_Col_Check ("out ");
1617 if Present (Subtype_Mark (Node)) then
1619 -- Ada 2005 (AI-423): Formal object with null exclusion
1621 if Null_Exclusion_Present (Node) then
1622 Write_Str ("not null ");
1625 Sprint_Node (Subtype_Mark (Node));
1627 -- Ada 2005 (AI-423): Formal object with access definition
1630 pragma Assert (Present (Access_Definition (Node)));
1632 Sprint_Node (Access_Definition (Node));
1635 if Present (Default_Expression (Node)) then
1637 Sprint_Node (Default_Expression (Node));
1643 when N_Formal_Ordinary_Fixed_Point_Definition =>
1644 Write_Str_With_Col_Check_Sloc ("delta <>");
1646 when N_Formal_Package_Declaration =>
1647 Write_Indent_Str_Sloc ("with package ");
1648 Write_Id (Defining_Identifier (Node));
1649 Write_Str_With_Col_Check (" is new ");
1650 Sprint_Node (Name (Node));
1651 Write_Str_With_Col_Check (" (<>);");
1653 when N_Formal_Private_Type_Definition =>
1654 if Abstract_Present (Node) then
1655 Write_Str_With_Col_Check ("abstract ");
1658 if Tagged_Present (Node) then
1659 Write_Str_With_Col_Check ("tagged ");
1662 if Limited_Present (Node) then
1663 Write_Str_With_Col_Check ("limited ");
1666 Write_Str_With_Col_Check_Sloc ("private");
1668 when N_Formal_Signed_Integer_Type_Definition =>
1669 Write_Str_With_Col_Check_Sloc ("range <>");
1671 when N_Formal_Type_Declaration =>
1672 Write_Indent_Str_Sloc ("type ");
1673 Write_Id (Defining_Identifier (Node));
1675 if Present (Discriminant_Specifications (Node)) then
1676 Write_Discr_Specs (Node);
1677 elsif Unknown_Discriminants_Present (Node) then
1678 Write_Str_With_Col_Check ("(<>)");
1681 Write_Str_With_Col_Check (" is ");
1682 Sprint_Node (Formal_Type_Definition (Node));
1685 when N_Free_Statement =>
1686 Write_Indent_Str_Sloc ("free ");
1687 Sprint_Node (Expression (Node));
1690 when N_Freeze_Entity =>
1691 if Dump_Original_Only then
1694 elsif Present (Actions (Node)) or else Dump_Freeze_Null then
1696 Write_Rewrite_Str ("<<<");
1697 Write_Str_With_Col_Check_Sloc ("freeze ");
1698 Write_Id (Entity (Node));
1701 if No (Actions (Node)) then
1705 -- Output freeze actions. We increment Freeze_Indent during
1706 -- this output to avoid generating extra blank lines before
1707 -- any procedures included in the freeze actions.
1709 Freeze_Indent := Freeze_Indent + 1;
1710 Sprint_Indented_List (Actions (Node));
1711 Freeze_Indent := Freeze_Indent - 1;
1712 Write_Indent_Str ("]");
1715 Write_Rewrite_Str (">>>");
1718 when N_Full_Type_Declaration =>
1719 Write_Indent_Str_Sloc ("type ");
1720 Sprint_Node (Defining_Identifier (Node));
1721 Write_Discr_Specs (Node);
1722 Write_Str_With_Col_Check (" is ");
1723 Sprint_Node (Type_Definition (Node));
1726 when N_Function_Call =>
1728 Write_Subprogram_Name (Name (Node));
1729 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
1731 when N_Function_Instantiation =>
1732 Write_Indent_Str_Sloc ("function ");
1733 Sprint_Node (Defining_Unit_Name (Node));
1734 Write_Str_With_Col_Check (" is new ");
1735 Sprint_Node (Name (Node));
1736 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
1739 when N_Function_Specification =>
1740 Write_Str_With_Col_Check_Sloc ("function ");
1741 Sprint_Node (Defining_Unit_Name (Node));
1742 Write_Param_Specs (Node);
1743 Write_Str_With_Col_Check (" return ");
1745 -- Ada 2005 (AI-231)
1747 if Nkind (Result_Definition (Node)) /= N_Access_Definition
1748 and then Null_Exclusion_Present (Node)
1750 Write_Str (" not null ");
1753 Sprint_Node (Result_Definition (Node));
1755 when N_Generic_Association =>
1758 if Present (Selector_Name (Node)) then
1759 Sprint_Node (Selector_Name (Node));
1763 Sprint_Node (Explicit_Generic_Actual_Parameter (Node));
1765 when N_Generic_Function_Renaming_Declaration =>
1766 Write_Indent_Str_Sloc ("generic function ");
1767 Sprint_Node (Defining_Unit_Name (Node));
1768 Write_Str_With_Col_Check (" renames ");
1769 Sprint_Node (Name (Node));
1772 when N_Generic_Package_Declaration =>
1774 Write_Indent_Str_Sloc ("generic ");
1775 Sprint_Indented_List (Generic_Formal_Declarations (Node));
1777 Sprint_Node (Specification (Node));
1780 when N_Generic_Package_Renaming_Declaration =>
1781 Write_Indent_Str_Sloc ("generic package ");
1782 Sprint_Node (Defining_Unit_Name (Node));
1783 Write_Str_With_Col_Check (" renames ");
1784 Sprint_Node (Name (Node));
1787 when N_Generic_Procedure_Renaming_Declaration =>
1788 Write_Indent_Str_Sloc ("generic procedure ");
1789 Sprint_Node (Defining_Unit_Name (Node));
1790 Write_Str_With_Col_Check (" renames ");
1791 Sprint_Node (Name (Node));
1794 when N_Generic_Subprogram_Declaration =>
1796 Write_Indent_Str_Sloc ("generic ");
1797 Sprint_Indented_List (Generic_Formal_Declarations (Node));
1799 Sprint_Node (Specification (Node));
1802 when N_Goto_Statement =>
1803 Write_Indent_Str_Sloc ("goto ");
1804 Sprint_Node (Name (Node));
1807 if Nkind (Next (Node)) = N_Label then
1811 when N_Handled_Sequence_Of_Statements =>
1813 Sprint_Indented_List (Statements (Node));
1815 if Present (Exception_Handlers (Node)) then
1816 Write_Indent_Str ("exception");
1818 Sprint_Node_List (Exception_Handlers (Node));
1822 if Present (At_End_Proc (Node)) then
1823 Write_Indent_Str ("at end");
1826 Sprint_Node (At_End_Proc (Node));
1831 when N_Identifier =>
1835 when N_If_Statement =>
1836 Write_Indent_Str_Sloc ("if ");
1837 Sprint_Node (Condition (Node));
1838 Write_Str_With_Col_Check (" then");
1839 Sprint_Indented_List (Then_Statements (Node));
1840 Sprint_Opt_Node_List (Elsif_Parts (Node));
1842 if Present (Else_Statements (Node)) then
1843 Write_Indent_Str ("else");
1844 Sprint_Indented_List (Else_Statements (Node));
1847 Write_Indent_Str ("end if;");
1849 when N_Implicit_Label_Declaration =>
1850 if not Dump_Original_Only then
1852 Write_Rewrite_Str ("<<<");
1854 Write_Id (Defining_Identifier (Node));
1856 Write_Str_With_Col_Check ("label");
1857 Write_Rewrite_Str (">>>");
1861 Sprint_Left_Opnd (Node);
1862 Write_Str_Sloc (" in ");
1864 if Present (Right_Opnd (Node)) then
1865 Sprint_Right_Opnd (Node);
1867 Sprint_Bar_List (Alternatives (Node));
1870 when N_Incomplete_Type_Declaration =>
1871 Write_Indent_Str_Sloc ("type ");
1872 Write_Id (Defining_Identifier (Node));
1874 if Present (Discriminant_Specifications (Node)) then
1875 Write_Discr_Specs (Node);
1876 elsif Unknown_Discriminants_Present (Node) then
1877 Write_Str_With_Col_Check ("(<>)");
1882 when N_Index_Or_Discriminant_Constraint =>
1884 Sprint_Paren_Comma_List (Constraints (Node));
1886 when N_Indexed_Component =>
1887 Sprint_Node_Sloc (Prefix (Node));
1888 Sprint_Opt_Paren_Comma_List (Expressions (Node));
1890 when N_Integer_Literal =>
1891 if Print_In_Hex (Node) then
1892 Write_Uint_With_Col_Check_Sloc (Intval (Node), Hex);
1894 Write_Uint_With_Col_Check_Sloc (Intval (Node), Auto);
1897 when N_Iteration_Scheme =>
1898 if Present (Condition (Node)) then
1899 Write_Str_With_Col_Check_Sloc ("while ");
1900 Sprint_Node (Condition (Node));
1902 Write_Str_With_Col_Check_Sloc ("for ");
1903 Sprint_Node (Loop_Parameter_Specification (Node));
1908 when N_Itype_Reference =>
1909 Write_Indent_Str_Sloc ("reference ");
1910 Write_Id (Itype (Node));
1913 Write_Indent_Str_Sloc ("<<");
1914 Write_Id (Identifier (Node));
1917 when N_Loop_Parameter_Specification =>
1919 Write_Id (Defining_Identifier (Node));
1920 Write_Str_With_Col_Check (" in ");
1922 if Reverse_Present (Node) then
1923 Write_Str_With_Col_Check ("reverse ");
1926 Sprint_Node (Discrete_Subtype_Definition (Node));
1928 when N_Loop_Statement =>
1931 if Present (Identifier (Node))
1932 and then (not Has_Created_Identifier (Node)
1933 or else not Dump_Original_Only)
1935 Write_Rewrite_Str ("<<<");
1936 Write_Id (Identifier (Node));
1938 Write_Rewrite_Str (">>>");
1939 Sprint_Node (Iteration_Scheme (Node));
1940 Write_Str_With_Col_Check_Sloc ("loop");
1941 Sprint_Indented_List (Statements (Node));
1942 Write_Indent_Str ("end loop ");
1943 Write_Rewrite_Str ("<<<");
1944 Write_Id (Identifier (Node));
1945 Write_Rewrite_Str (">>>");
1949 Sprint_Node (Iteration_Scheme (Node));
1950 Write_Str_With_Col_Check_Sloc ("loop");
1951 Sprint_Indented_List (Statements (Node));
1952 Write_Indent_Str ("end loop;");
1955 when N_Mod_Clause =>
1956 Sprint_Node_List (Pragmas_Before (Node));
1957 Write_Str_With_Col_Check_Sloc ("at mod ");
1958 Sprint_Node (Expression (Node));
1960 when N_Modular_Type_Definition =>
1961 Write_Str_With_Col_Check_Sloc ("mod ");
1962 Sprint_Node (Expression (Node));
1965 Sprint_Left_Opnd (Node);
1966 Write_Str_Sloc (" not in ");
1968 if Present (Right_Opnd (Node)) then
1969 Sprint_Right_Opnd (Node);
1971 Sprint_Bar_List (Alternatives (Node));
1975 Write_Str_With_Col_Check_Sloc ("null");
1977 when N_Null_Statement =>
1978 if Comes_From_Source (Node)
1979 or else Dump_Freeze_Null
1980 or else not Is_List_Member (Node)
1981 or else (No (Prev (Node)) and then No (Next (Node)))
1983 Write_Indent_Str_Sloc ("null;");
1986 when N_Number_Declaration =>
1989 if Write_Indent_Identifiers (Node) then
1990 Write_Str_With_Col_Check (" : constant ");
1992 Sprint_Node (Expression (Node));
1996 when N_Object_Declaration =>
1999 if Write_Indent_Identifiers (Node) then
2001 Def_Id : constant Entity_Id := Defining_Identifier (Node);
2004 Write_Str_With_Col_Check (" : ");
2006 if Is_Statically_Allocated (Def_Id) then
2007 Write_Str_With_Col_Check ("static ");
2010 if Aliased_Present (Node) then
2011 Write_Str_With_Col_Check ("aliased ");
2014 if Constant_Present (Node) then
2015 Write_Str_With_Col_Check ("constant ");
2018 -- Ada 2005 (AI-231)
2020 if Null_Exclusion_Present (Node) then
2021 Write_Str_With_Col_Check ("not null ");
2024 Sprint_Node (Object_Definition (Node));
2026 if Present (Expression (Node)) then
2028 Sprint_Node (Expression (Node));
2033 -- Handle implicit importation and implicit exportation of
2034 -- object declarations:
2035 -- $pragma import (Convention_Id, Def_Id, "...");
2036 -- $pragma export (Convention_Id, Def_Id, "...");
2038 if Is_Internal (Def_Id)
2039 and then Present (Interface_Name (Def_Id))
2041 Write_Indent_Str_Sloc ("$pragma ");
2043 if Is_Imported (Def_Id) then
2044 Write_Str ("import (");
2046 else pragma Assert (Is_Exported (Def_Id));
2047 Write_Str ("export (");
2051 Prefix : constant String := "Convention_";
2052 S : constant String := Convention (Def_Id)'Img;
2055 Name_Len := S'Last - Prefix'Last;
2056 Name_Buffer (1 .. Name_Len) :=
2057 S (Prefix'Last + 1 .. S'Last);
2058 Set_Casing (All_Lower_Case);
2059 Write_Str (Name_Buffer (1 .. Name_Len));
2065 Write_String_Table_Entry
2066 (Strval (Interface_Name (Def_Id)));
2072 when N_Object_Renaming_Declaration =>
2075 Sprint_Node (Defining_Identifier (Node));
2078 -- Ada 2005 (AI-230): Access renamings
2080 if Present (Access_Definition (Node)) then
2081 Sprint_Node (Access_Definition (Node));
2083 elsif Present (Subtype_Mark (Node)) then
2085 -- Ada 2005 (AI-423): Object renaming with a null exclusion
2087 if Null_Exclusion_Present (Node) then
2088 Write_Str ("not null ");
2091 Sprint_Node (Subtype_Mark (Node));
2094 Write_Str (" ??? ");
2097 Write_Str_With_Col_Check (" renames ");
2098 Sprint_Node (Name (Node));
2102 Write_Operator (Node, "abs ");
2103 Sprint_Right_Opnd (Node);
2106 Sprint_Left_Opnd (Node);
2107 Write_Operator (Node, " + ");
2108 Sprint_Right_Opnd (Node);
2111 Sprint_Left_Opnd (Node);
2112 Write_Operator (Node, " and ");
2113 Sprint_Right_Opnd (Node);
2116 Sprint_Left_Opnd (Node);
2117 Write_Operator (Node, " & ");
2118 Sprint_Right_Opnd (Node);
2121 Sprint_Left_Opnd (Node);
2123 Process_TFAI_RR_Flags (Node);
2124 Write_Operator (Node, "/ ");
2125 Sprint_Right_Opnd (Node);
2128 Sprint_Left_Opnd (Node);
2129 Write_Operator (Node, " = ");
2130 Sprint_Right_Opnd (Node);
2133 Sprint_Left_Opnd (Node);
2134 Write_Operator (Node, " ** ");
2135 Sprint_Right_Opnd (Node);
2138 Sprint_Left_Opnd (Node);
2139 Write_Operator (Node, " >= ");
2140 Sprint_Right_Opnd (Node);
2143 Sprint_Left_Opnd (Node);
2144 Write_Operator (Node, " > ");
2145 Sprint_Right_Opnd (Node);
2148 Sprint_Left_Opnd (Node);
2149 Write_Operator (Node, " <= ");
2150 Sprint_Right_Opnd (Node);
2153 Sprint_Left_Opnd (Node);
2154 Write_Operator (Node, " < ");
2155 Sprint_Right_Opnd (Node);
2158 Write_Operator (Node, "-");
2159 Sprint_Right_Opnd (Node);
2162 Sprint_Left_Opnd (Node);
2164 if Treat_Fixed_As_Integer (Node) then
2168 Write_Operator (Node, " mod ");
2169 Sprint_Right_Opnd (Node);
2171 when N_Op_Multiply =>
2172 Sprint_Left_Opnd (Node);
2174 Process_TFAI_RR_Flags (Node);
2175 Write_Operator (Node, "* ");
2176 Sprint_Right_Opnd (Node);
2179 Sprint_Left_Opnd (Node);
2180 Write_Operator (Node, " /= ");
2181 Sprint_Right_Opnd (Node);
2184 Write_Operator (Node, "not ");
2185 Sprint_Right_Opnd (Node);
2188 Sprint_Left_Opnd (Node);
2189 Write_Operator (Node, " or ");
2190 Sprint_Right_Opnd (Node);
2193 Write_Operator (Node, "+");
2194 Sprint_Right_Opnd (Node);
2197 Sprint_Left_Opnd (Node);
2199 if Treat_Fixed_As_Integer (Node) then
2203 Write_Operator (Node, " rem ");
2204 Sprint_Right_Opnd (Node);
2210 Write_Str_With_Col_Check ("(");
2211 Sprint_Node (Left_Opnd (Node));
2213 Sprint_Node (Right_Opnd (Node));
2216 when N_Op_Subtract =>
2217 Sprint_Left_Opnd (Node);
2218 Write_Operator (Node, " - ");
2219 Sprint_Right_Opnd (Node);
2222 Sprint_Left_Opnd (Node);
2223 Write_Operator (Node, " xor ");
2224 Sprint_Right_Opnd (Node);
2226 when N_Operator_Symbol =>
2227 Write_Name_With_Col_Check_Sloc (Chars (Node));
2229 when N_Ordinary_Fixed_Point_Definition =>
2230 Write_Str_With_Col_Check_Sloc ("delta ");
2231 Sprint_Node (Delta_Expression (Node));
2232 Sprint_Opt_Node (Real_Range_Specification (Node));
2235 Sprint_Left_Opnd (Node);
2236 Write_Str_Sloc (" or else ");
2237 Sprint_Right_Opnd (Node);
2239 when N_Others_Choice =>
2240 if All_Others (Node) then
2241 Write_Str_With_Col_Check ("all ");
2244 Write_Str_With_Col_Check_Sloc ("others");
2246 when N_Package_Body =>
2248 Write_Indent_Str_Sloc ("package body ");
2249 Sprint_Node (Defining_Unit_Name (Node));
2251 Sprint_Indented_List (Declarations (Node));
2253 if Present (Handled_Statement_Sequence (Node)) then
2254 Write_Indent_Str ("begin");
2255 Sprint_Node (Handled_Statement_Sequence (Node));
2258 Write_Indent_Str ("end ");
2260 (Handled_Statement_Sequence (Node), Defining_Unit_Name (Node));
2263 when N_Package_Body_Stub =>
2264 Write_Indent_Str_Sloc ("package body ");
2265 Sprint_Node (Defining_Identifier (Node));
2266 Write_Str_With_Col_Check (" is separate;");
2268 when N_Package_Declaration =>
2271 Sprint_Node_Sloc (Specification (Node));
2274 when N_Package_Instantiation =>
2276 Write_Indent_Str_Sloc ("package ");
2277 Sprint_Node (Defining_Unit_Name (Node));
2278 Write_Str (" is new ");
2279 Sprint_Node (Name (Node));
2280 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
2283 when N_Package_Renaming_Declaration =>
2284 Write_Indent_Str_Sloc ("package ");
2285 Sprint_Node (Defining_Unit_Name (Node));
2286 Write_Str_With_Col_Check (" renames ");
2287 Sprint_Node (Name (Node));
2290 when N_Package_Specification =>
2291 Write_Str_With_Col_Check_Sloc ("package ");
2292 Sprint_Node (Defining_Unit_Name (Node));
2294 Sprint_Indented_List (Visible_Declarations (Node));
2296 if Present (Private_Declarations (Node)) then
2297 Write_Indent_Str ("private");
2298 Sprint_Indented_List (Private_Declarations (Node));
2301 Write_Indent_Str ("end ");
2302 Sprint_Node (Defining_Unit_Name (Node));
2304 when N_Parameter_Association =>
2305 Sprint_Node_Sloc (Selector_Name (Node));
2307 Sprint_Node (Explicit_Actual_Parameter (Node));
2309 when N_Parameter_Specification =>
2312 if Write_Identifiers (Node) then
2315 if In_Present (Node) then
2316 Write_Str_With_Col_Check ("in ");
2319 if Out_Present (Node) then
2320 Write_Str_With_Col_Check ("out ");
2323 -- Ada 2005 (AI-231): Parameter specification may carry null
2324 -- exclusion. Do not print it now if this is an access formal,
2325 -- it is emitted when the access definition is displayed.
2327 if Null_Exclusion_Present (Node)
2328 and then Nkind (Parameter_Type (Node))
2329 /= N_Access_Definition
2331 Write_Str ("not null ");
2334 Sprint_Node (Parameter_Type (Node));
2336 if Present (Expression (Node)) then
2338 Sprint_Node (Expression (Node));
2344 when N_Pop_Constraint_Error_Label =>
2345 Write_Indent_Str ("%pop_constraint_error_label");
2347 when N_Pop_Program_Error_Label =>
2348 Write_Indent_Str ("%pop_program_error_label");
2350 when N_Pop_Storage_Error_Label =>
2351 Write_Indent_Str ("%pop_storage_error_label");
2353 when N_Push_Constraint_Error_Label =>
2354 Write_Indent_Str ("%push_constraint_error_label (");
2356 if Present (Exception_Label (Node)) then
2357 Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2362 when N_Push_Program_Error_Label =>
2363 Write_Indent_Str ("%push_program_error_label (");
2365 if Present (Exception_Label (Node)) then
2366 Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2371 when N_Push_Storage_Error_Label =>
2372 Write_Indent_Str ("%push_storage_error_label (");
2374 if Present (Exception_Label (Node)) then
2375 Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2381 Write_Indent_Str_Sloc ("pragma ");
2382 Write_Name_With_Col_Check (Pragma_Name (Node));
2384 if Present (Pragma_Argument_Associations (Node)) then
2385 Sprint_Opt_Paren_Comma_List
2386 (Pragma_Argument_Associations (Node));
2391 when N_Pragma_Argument_Association =>
2394 if Chars (Node) /= No_Name then
2395 Write_Name_With_Col_Check (Chars (Node));
2399 Sprint_Node (Expression (Node));
2401 when N_Private_Type_Declaration =>
2402 Write_Indent_Str_Sloc ("type ");
2403 Write_Id (Defining_Identifier (Node));
2405 if Present (Discriminant_Specifications (Node)) then
2406 Write_Discr_Specs (Node);
2407 elsif Unknown_Discriminants_Present (Node) then
2408 Write_Str_With_Col_Check ("(<>)");
2413 if Tagged_Present (Node) then
2414 Write_Str_With_Col_Check ("tagged ");
2417 if Limited_Present (Node) then
2418 Write_Str_With_Col_Check ("limited ");
2421 Write_Str_With_Col_Check ("private;");
2423 when N_Private_Extension_Declaration =>
2424 Write_Indent_Str_Sloc ("type ");
2425 Write_Id (Defining_Identifier (Node));
2427 if Present (Discriminant_Specifications (Node)) then
2428 Write_Discr_Specs (Node);
2429 elsif Unknown_Discriminants_Present (Node) then
2430 Write_Str_With_Col_Check ("(<>)");
2433 Write_Str_With_Col_Check (" is new ");
2434 Sprint_Node (Subtype_Indication (Node));
2436 if Present (Interface_List (Node)) then
2437 Write_Str_With_Col_Check (" and ");
2438 Sprint_And_List (Interface_List (Node));
2441 Write_Str_With_Col_Check (" with private;");
2443 when N_Procedure_Call_Statement =>
2446 Write_Subprogram_Name (Name (Node));
2447 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
2450 when N_Procedure_Instantiation =>
2451 Write_Indent_Str_Sloc ("procedure ");
2452 Sprint_Node (Defining_Unit_Name (Node));
2453 Write_Str_With_Col_Check (" is new ");
2454 Sprint_Node (Name (Node));
2455 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
2458 when N_Procedure_Specification =>
2459 Write_Str_With_Col_Check_Sloc ("procedure ");
2460 Sprint_Node (Defining_Unit_Name (Node));
2461 Write_Param_Specs (Node);
2463 when N_Protected_Body =>
2464 Write_Indent_Str_Sloc ("protected body ");
2465 Write_Id (Defining_Identifier (Node));
2467 Sprint_Indented_List (Declarations (Node));
2468 Write_Indent_Str ("end ");
2469 Write_Id (Defining_Identifier (Node));
2472 when N_Protected_Body_Stub =>
2473 Write_Indent_Str_Sloc ("protected body ");
2474 Write_Id (Defining_Identifier (Node));
2475 Write_Str_With_Col_Check (" is separate;");
2477 when N_Protected_Definition =>
2479 Sprint_Indented_List (Visible_Declarations (Node));
2481 if Present (Private_Declarations (Node)) then
2482 Write_Indent_Str ("private");
2483 Sprint_Indented_List (Private_Declarations (Node));
2486 Write_Indent_Str ("end ");
2488 when N_Protected_Type_Declaration =>
2489 Write_Indent_Str_Sloc ("protected type ");
2490 Sprint_Node (Defining_Identifier (Node));
2491 Write_Discr_Specs (Node);
2493 if Present (Interface_List (Node)) then
2494 Write_Str (" is new ");
2495 Sprint_And_List (Interface_List (Node));
2496 Write_Str (" with ");
2501 Sprint_Node (Protected_Definition (Node));
2502 Write_Id (Defining_Identifier (Node));
2505 when N_Qualified_Expression =>
2506 Sprint_Node (Subtype_Mark (Node));
2507 Write_Char_Sloc (''');
2509 -- Print expression, make sure we have at least one level of
2510 -- parentheses around the expression. For cases of qualified
2511 -- expressions in the source, this is always the case, but
2512 -- for generated qualifications, there may be no explicit
2513 -- parentheses present.
2515 if Paren_Count (Expression (Node)) /= 0 then
2516 Sprint_Node (Expression (Node));
2519 Sprint_Node (Expression (Node));
2523 when N_Raise_Constraint_Error =>
2525 -- This node can be used either as a subexpression or as a
2526 -- statement form. The following test is a reasonably reliable
2527 -- way to distinguish the two cases.
2529 if Is_List_Member (Node)
2530 and then Nkind (Parent (Node)) not in N_Subexpr
2535 Write_Str_With_Col_Check_Sloc ("[constraint_error");
2536 Write_Condition_And_Reason (Node);
2538 when N_Raise_Program_Error =>
2540 -- This node can be used either as a subexpression or as a
2541 -- statement form. The following test is a reasonably reliable
2542 -- way to distinguish the two cases.
2544 if Is_List_Member (Node)
2545 and then Nkind (Parent (Node)) not in N_Subexpr
2550 Write_Str_With_Col_Check_Sloc ("[program_error");
2551 Write_Condition_And_Reason (Node);
2553 when N_Raise_Storage_Error =>
2555 -- This node can be used either as a subexpression or as a
2556 -- statement form. The following test is a reasonably reliable
2557 -- way to distinguish the two cases.
2559 if Is_List_Member (Node)
2560 and then Nkind (Parent (Node)) not in N_Subexpr
2565 Write_Str_With_Col_Check_Sloc ("[storage_error");
2566 Write_Condition_And_Reason (Node);
2568 when N_Raise_Statement =>
2569 Write_Indent_Str_Sloc ("raise ");
2570 Sprint_Node (Name (Node));
2574 Sprint_Node (Low_Bound (Node));
2575 Write_Str_Sloc (" .. ");
2576 Sprint_Node (High_Bound (Node));
2577 Update_Itype (Node);
2579 when N_Range_Constraint =>
2580 Write_Str_With_Col_Check_Sloc ("range ");
2581 Sprint_Node (Range_Expression (Node));
2583 when N_Real_Literal =>
2584 Write_Ureal_With_Col_Check_Sloc (Realval (Node));
2586 when N_Real_Range_Specification =>
2587 Write_Str_With_Col_Check_Sloc ("range ");
2588 Sprint_Node (Low_Bound (Node));
2590 Sprint_Node (High_Bound (Node));
2592 when N_Record_Definition =>
2593 if Abstract_Present (Node) then
2594 Write_Str_With_Col_Check ("abstract ");
2597 if Tagged_Present (Node) then
2598 Write_Str_With_Col_Check ("tagged ");
2601 if Limited_Present (Node) then
2602 Write_Str_With_Col_Check ("limited ");
2605 if Null_Present (Node) then
2606 Write_Str_With_Col_Check_Sloc ("null record");
2609 Write_Str_With_Col_Check_Sloc ("record");
2610 Sprint_Node (Component_List (Node));
2611 Write_Indent_Str ("end record");
2614 when N_Record_Representation_Clause =>
2615 Write_Indent_Str_Sloc ("for ");
2616 Sprint_Node (Identifier (Node));
2617 Write_Str_With_Col_Check (" use record ");
2619 if Present (Mod_Clause (Node)) then
2620 Sprint_Node (Mod_Clause (Node));
2623 Sprint_Indented_List (Component_Clauses (Node));
2624 Write_Indent_Str ("end record;");
2627 Sprint_Node (Prefix (Node));
2628 Write_Str_With_Col_Check_Sloc ("'reference");
2630 when N_Requeue_Statement =>
2631 Write_Indent_Str_Sloc ("requeue ");
2632 Sprint_Node (Name (Node));
2634 if Abort_Present (Node) then
2635 Write_Str_With_Col_Check (" with abort");
2640 when N_Simple_Return_Statement =>
2641 if Present (Expression (Node)) then
2642 Write_Indent_Str_Sloc ("return ");
2643 Sprint_Node (Expression (Node));
2646 Write_Indent_Str_Sloc ("return;");
2649 when N_Selective_Accept =>
2650 Write_Indent_Str_Sloc ("select");
2655 Alt_Node := First (Select_Alternatives (Node));
2658 Sprint_Node (Alt_Node);
2661 exit when No (Alt_Node);
2662 Write_Indent_Str ("or");
2666 if Present (Else_Statements (Node)) then
2667 Write_Indent_Str ("else");
2668 Sprint_Indented_List (Else_Statements (Node));
2671 Write_Indent_Str ("end select;");
2673 when N_Signed_Integer_Type_Definition =>
2674 Write_Str_With_Col_Check_Sloc ("range ");
2675 Sprint_Node (Low_Bound (Node));
2677 Sprint_Node (High_Bound (Node));
2679 when N_Single_Protected_Declaration =>
2680 Write_Indent_Str_Sloc ("protected ");
2681 Write_Id (Defining_Identifier (Node));
2683 Sprint_Node (Protected_Definition (Node));
2684 Write_Id (Defining_Identifier (Node));
2687 when N_Single_Task_Declaration =>
2688 Write_Indent_Str_Sloc ("task ");
2689 Sprint_Node (Defining_Identifier (Node));
2691 if Present (Task_Definition (Node)) then
2693 Sprint_Node (Task_Definition (Node));
2698 when N_Selected_Component =>
2699 Sprint_Node (Prefix (Node));
2700 Write_Char_Sloc ('.');
2701 Sprint_Node (Selector_Name (Node));
2705 Sprint_Node (Prefix (Node));
2706 Write_Str_With_Col_Check (" (");
2707 Sprint_Node (Discrete_Range (Node));
2710 when N_String_Literal =>
2711 if String_Length (Strval (Node)) + Column > Sprint_Line_Limit then
2712 Write_Indent_Str (" ");
2716 Write_String_Table_Entry (Strval (Node));
2718 when N_Subprogram_Body =>
2720 -- Output extra blank line unless we are in freeze actions
2722 if Freeze_Indent = 0 then
2727 Sprint_Node_Sloc (Specification (Node));
2730 Sprint_Indented_List (Declarations (Node));
2731 Write_Indent_Str ("begin");
2732 Sprint_Node (Handled_Statement_Sequence (Node));
2734 Write_Indent_Str ("end ");
2737 (Handled_Statement_Sequence (Node),
2738 Defining_Unit_Name (Specification (Node)));
2741 if Is_List_Member (Node)
2742 and then Present (Next (Node))
2743 and then Nkind (Next (Node)) /= N_Subprogram_Body
2748 when N_Subprogram_Body_Stub =>
2750 Sprint_Node_Sloc (Specification (Node));
2751 Write_Str_With_Col_Check (" is separate;");
2753 when N_Subprogram_Declaration =>
2755 Sprint_Node_Sloc (Specification (Node));
2757 if Nkind (Specification (Node)) = N_Procedure_Specification
2758 and then Null_Present (Specification (Node))
2760 Write_Str_With_Col_Check (" is null");
2765 when N_Subprogram_Info =>
2766 Sprint_Node (Identifier (Node));
2767 Write_Str_With_Col_Check_Sloc ("'subprogram_info");
2769 when N_Subprogram_Renaming_Declaration =>
2771 Sprint_Node (Specification (Node));
2772 Write_Str_With_Col_Check_Sloc (" renames ");
2773 Sprint_Node (Name (Node));
2776 when N_Subtype_Declaration =>
2777 Write_Indent_Str_Sloc ("subtype ");
2778 Sprint_Node (Defining_Identifier (Node));
2781 -- Ada 2005 (AI-231)
2783 if Null_Exclusion_Present (Node) then
2784 Write_Str ("not null ");
2787 Sprint_Node (Subtype_Indication (Node));
2790 when N_Subtype_Indication =>
2791 Sprint_Node_Sloc (Subtype_Mark (Node));
2793 Sprint_Node (Constraint (Node));
2796 Write_Indent_Str_Sloc ("separate (");
2797 Sprint_Node (Name (Node));
2800 Sprint_Node (Proper_Body (Node));
2803 Write_Indent_Str_Sloc ("task body ");
2804 Write_Id (Defining_Identifier (Node));
2806 Sprint_Indented_List (Declarations (Node));
2807 Write_Indent_Str ("begin");
2808 Sprint_Node (Handled_Statement_Sequence (Node));
2809 Write_Indent_Str ("end ");
2811 (Handled_Statement_Sequence (Node), Defining_Identifier (Node));
2814 when N_Task_Body_Stub =>
2815 Write_Indent_Str_Sloc ("task body ");
2816 Write_Id (Defining_Identifier (Node));
2817 Write_Str_With_Col_Check (" is separate;");
2819 when N_Task_Definition =>
2821 Sprint_Indented_List (Visible_Declarations (Node));
2823 if Present (Private_Declarations (Node)) then
2824 Write_Indent_Str ("private");
2825 Sprint_Indented_List (Private_Declarations (Node));
2828 Write_Indent_Str ("end ");
2829 Sprint_End_Label (Node, Defining_Identifier (Parent (Node)));
2831 when N_Task_Type_Declaration =>
2832 Write_Indent_Str_Sloc ("task type ");
2833 Sprint_Node (Defining_Identifier (Node));
2834 Write_Discr_Specs (Node);
2836 if Present (Interface_List (Node)) then
2837 Write_Str (" is new ");
2838 Sprint_And_List (Interface_List (Node));
2841 if Present (Task_Definition (Node)) then
2842 if No (Interface_List (Node)) then
2845 Write_Str (" with ");
2848 Sprint_Node (Task_Definition (Node));
2853 when N_Terminate_Alternative =>
2854 Sprint_Node_List (Pragmas_Before (Node));
2858 if Present (Condition (Node)) then
2859 Write_Str_With_Col_Check ("when ");
2860 Sprint_Node (Condition (Node));
2864 Write_Str_With_Col_Check_Sloc ("terminate;");
2865 Sprint_Node_List (Pragmas_After (Node));
2867 when N_Timed_Entry_Call =>
2868 Write_Indent_Str_Sloc ("select");
2870 Sprint_Node (Entry_Call_Alternative (Node));
2872 Write_Indent_Str ("or");
2874 Sprint_Node (Delay_Alternative (Node));
2876 Write_Indent_Str ("end select;");
2878 when N_Triggering_Alternative =>
2879 Sprint_Node_List (Pragmas_Before (Node));
2880 Sprint_Node_Sloc (Triggering_Statement (Node));
2881 Sprint_Node_List (Statements (Node));
2883 when N_Type_Conversion =>
2885 Sprint_Node (Subtype_Mark (Node));
2888 if Conversion_OK (Node) then
2892 if Float_Truncate (Node) then
2896 if Rounded_Result (Node) then
2901 Sprint_Node (Expression (Node));
2904 when N_Unchecked_Expression =>
2907 Sprint_Node_Sloc (Expression (Node));
2910 when N_Unchecked_Type_Conversion =>
2911 Sprint_Node (Subtype_Mark (Node));
2913 Write_Str_With_Col_Check ("(");
2914 Sprint_Node_Sloc (Expression (Node));
2917 when N_Unconstrained_Array_Definition =>
2918 Write_Str_With_Col_Check_Sloc ("array (");
2923 Node1 := First (Subtype_Marks (Node));
2925 Sprint_Node (Node1);
2926 Write_Str_With_Col_Check (" range <>");
2928 exit when Node1 = Empty;
2933 Write_Str (") of ");
2934 Sprint_Node (Component_Definition (Node));
2936 when N_Unused_At_Start | N_Unused_At_End =>
2937 Write_Indent_Str ("***** Error, unused node encountered *****");
2940 when N_Use_Package_Clause =>
2941 Write_Indent_Str_Sloc ("use ");
2942 Sprint_Comma_List (Names (Node));
2945 when N_Use_Type_Clause =>
2946 Write_Indent_Str_Sloc ("use type ");
2947 Sprint_Comma_List (Subtype_Marks (Node));
2950 when N_Validate_Unchecked_Conversion =>
2951 Write_Indent_Str_Sloc ("validate unchecked_conversion (");
2952 Sprint_Node (Source_Type (Node));
2954 Sprint_Node (Target_Type (Node));
2958 Write_Indent_Str_Sloc ("when ");
2959 Sprint_Bar_List (Discrete_Choices (Node));
2961 Sprint_Node (Component_List (Node));
2963 when N_Variant_Part =>
2965 Write_Indent_Str_Sloc ("case ");
2966 Sprint_Node (Name (Node));
2968 Sprint_Indented_List (Variants (Node));
2969 Write_Indent_Str ("end case");
2972 when N_With_Clause =>
2974 -- Special test, if we are dumping the original tree only,
2975 -- then we want to eliminate the bogus with clauses that
2976 -- correspond to the non-existent children of Text_IO.
2978 if Dump_Original_Only
2979 and then Is_Text_IO_Kludge_Unit (Name (Node))
2983 -- Normal case, output the with clause
2986 if First_Name (Node) or else not Dump_Original_Only then
2988 -- Ada 2005 (AI-50217): Print limited with_clauses
2990 if Private_Present (Node) and Limited_Present (Node) then
2991 Write_Indent_Str ("limited private with ");
2993 elsif Private_Present (Node) then
2994 Write_Indent_Str ("private with ");
2996 elsif Limited_Present (Node) then
2997 Write_Indent_Str ("limited with ");
3000 Write_Indent_Str ("with ");
3007 Sprint_Node_Sloc (Name (Node));
3009 if Last_Name (Node) or else not Dump_Original_Only then
3016 if Nkind (Node) in N_Subexpr
3017 and then Do_Range_Check (Node)
3022 for J in 1 .. Paren_Count (Node) loop
3026 Dump_Node := Save_Dump_Node;
3027 end Sprint_Node_Actual;
3029 ----------------------
3030 -- Sprint_Node_List --
3031 ----------------------
3033 procedure Sprint_Node_List (List : List_Id) is
3037 if Is_Non_Empty_List (List) then
3038 Node := First (List);
3043 exit when Node = Empty;
3046 end Sprint_Node_List;
3048 ----------------------
3049 -- Sprint_Node_Sloc --
3050 ----------------------
3052 procedure Sprint_Node_Sloc (Node : Node_Id) is
3056 if Debug_Generated_Code and then Present (Dump_Node) then
3057 Set_Sloc (Dump_Node, Sloc (Node));
3060 end Sprint_Node_Sloc;
3062 ---------------------
3063 -- Sprint_Opt_Node --
3064 ---------------------
3066 procedure Sprint_Opt_Node (Node : Node_Id) is
3068 if Present (Node) then
3072 end Sprint_Opt_Node;
3074 --------------------------
3075 -- Sprint_Opt_Node_List --
3076 --------------------------
3078 procedure Sprint_Opt_Node_List (List : List_Id) is
3080 if Present (List) then
3081 Sprint_Node_List (List);
3083 end Sprint_Opt_Node_List;
3085 ---------------------------------
3086 -- Sprint_Opt_Paren_Comma_List --
3087 ---------------------------------
3089 procedure Sprint_Opt_Paren_Comma_List (List : List_Id) is
3091 if Is_Non_Empty_List (List) then
3093 Sprint_Paren_Comma_List (List);
3095 end Sprint_Opt_Paren_Comma_List;
3097 -----------------------------
3098 -- Sprint_Paren_Comma_List --
3099 -----------------------------
3101 procedure Sprint_Paren_Comma_List (List : List_Id) is
3103 Node_Exists : Boolean := False;
3107 if Is_Non_Empty_List (List) then
3109 if Dump_Original_Only then
3111 while Present (N) loop
3112 if not Is_Rewrite_Insertion (N) then
3113 Node_Exists := True;
3120 if not Node_Exists then
3125 Write_Str_With_Col_Check ("(");
3126 Sprint_Comma_List (List);
3129 end Sprint_Paren_Comma_List;
3131 ----------------------
3132 -- Sprint_Right_Opnd --
3133 ----------------------
3135 procedure Sprint_Right_Opnd (N : Node_Id) is
3136 Opnd : constant Node_Id := Right_Opnd (N);
3139 if Paren_Count (Opnd) /= 0
3140 or else Op_Prec (Nkind (Opnd)) > Op_Prec (Nkind (N))
3149 end Sprint_Right_Opnd;
3155 procedure Update_Itype (Node : Node_Id) is
3157 if Present (Etype (Node))
3158 and then Is_Itype (Etype (Node))
3159 and then Debug_Generated_Code
3161 Set_Sloc (Etype (Node), Sloc (Node));
3165 ---------------------
3166 -- Write_Char_Sloc --
3167 ---------------------
3169 procedure Write_Char_Sloc (C : Character) is
3171 if Debug_Generated_Code and then C /= ' ' then
3176 end Write_Char_Sloc;
3178 --------------------------------
3179 -- Write_Condition_And_Reason --
3180 --------------------------------
3182 procedure Write_Condition_And_Reason (Node : Node_Id) is
3183 Cond : constant Node_Id := Condition (Node);
3184 Image : constant String := RT_Exception_Code'Image
3185 (RT_Exception_Code'Val
3186 (UI_To_Int (Reason (Node))));
3189 if Present (Cond) then
3191 -- If condition is a single entity, or NOT with a single entity,
3192 -- output all on one line, since it will likely fit just fine.
3194 if Is_Entity_Name (Cond)
3195 or else (Nkind (Cond) = N_Op_Not
3196 and then Is_Entity_Name (Right_Opnd (Cond)))
3198 Write_Str_With_Col_Check (" when ");
3202 -- Otherwise for more complex condition, multiple lines
3205 Write_Str_With_Col_Check (" when");
3206 Indent := Indent + 2;
3210 Indent := Indent - 2;
3213 -- If no condition, just need a space (all on one line)
3223 for J in 4 .. Image'Last loop
3224 if Image (J) = '_' then
3227 Write_Char (Fold_Lower (Image (J)));
3232 end Write_Condition_And_Reason;
3234 --------------------------------
3235 -- Write_Corresponding_Source --
3236 --------------------------------
3238 procedure Write_Corresponding_Source (S : String) is
3240 Src : Source_Buffer_Ptr;
3243 -- Ignore if not in dump source text mode, or if in freeze actions
3245 if Dump_Source_Text and then Freeze_Indent = 0 then
3247 -- Ignore null string
3253 -- Ignore space or semicolon at end of given string
3255 if S (S'Last) = ' ' or else S (S'Last) = ';' then
3256 Write_Corresponding_Source (S (S'First .. S'Last - 1));
3260 -- Loop to look at next lines not yet printed in source file
3263 Last_Line_Printed + 1 .. Last_Source_Line (Current_Source_File)
3265 Src := Source_Text (Current_Source_File);
3266 Loc := Line_Start (L, Current_Source_File);
3268 -- If comment, keep looking
3270 if Src (Loc .. Loc + 1) = "--" then
3273 -- Search to first non-blank
3276 while Src (Loc) not in Line_Terminator loop
3280 if Src (Loc) /= ' ' and then Src (Loc) /= ASCII.HT then
3282 -- Loop through characters in string to see if we match
3284 for J in S'Range loop
3286 -- If mismatch, then not the case we are looking for
3288 if Src (Loc) /= S (J) then
3295 -- If we fall through, string matched, if white space or
3296 -- semicolon after the matched string, this is the case
3297 -- we are looking for.
3299 if Src (Loc) in Line_Terminator
3300 or else Src (Loc) = ' '
3301 or else Src (Loc) = ASCII.HT
3302 or else Src (Loc) = ';'
3304 -- So output source lines up to and including this one
3306 Write_Source_Lines (L);
3315 -- Line was all blanks, or a comment line, keep looking
3319 end Write_Corresponding_Source;
3321 -----------------------
3322 -- Write_Discr_Specs --
3323 -----------------------
3325 procedure Write_Discr_Specs (N : Node_Id) is
3330 Specs := Discriminant_Specifications (N);
3332 if Present (Specs) then
3333 Write_Str_With_Col_Check (" (");
3334 Spec := First (Specs);
3339 exit when Spec = Empty;
3341 -- Add semicolon, unless we are printing original tree and the
3342 -- next specification is part of a list (but not the first
3343 -- element of that list)
3345 if not Dump_Original_Only or else not Prev_Ids (Spec) then
3352 end Write_Discr_Specs;
3358 procedure Write_Ekind (E : Entity_Id) is
3359 S : constant String := Entity_Kind'Image (Ekind (E));
3362 Name_Len := S'Length;
3363 Name_Buffer (1 .. Name_Len) := S;
3364 Set_Casing (Mixed_Case);
3365 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
3372 procedure Write_Id (N : Node_Id) is
3374 -- Deal with outputting Itype
3376 -- Note: if we are printing the full tree with -gnatds, then we may
3377 -- end up picking up the Associated_Node link from a generic template
3378 -- here which overlaps the Entity field, but as documented, Write_Itype
3379 -- is defended against junk calls.
3381 if Nkind (N) in N_Entity then
3383 elsif Nkind (N) in N_Has_Entity then
3384 Write_Itype (Entity (N));
3387 -- Case of a defining identifier
3389 if Nkind (N) = N_Defining_Identifier then
3391 -- If defining identifier has an interface name (and no
3392 -- address clause), then we output the interface name.
3394 if (Is_Imported (N) or else Is_Exported (N))
3395 and then Present (Interface_Name (N))
3396 and then No (Address_Clause (N))
3398 String_To_Name_Buffer (Strval (Interface_Name (N)));
3399 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
3401 -- If no interface name (or inactive because there was
3402 -- an address clause), then just output the Chars name.
3405 Write_Name_With_Col_Check (Chars (N));
3408 -- Case of selector of an expanded name where the expanded name
3409 -- has an associated entity, output this entity.
3411 elsif Nkind (Parent (N)) = N_Expanded_Name
3412 and then Selector_Name (Parent (N)) = N
3413 and then Present (Entity (Parent (N)))
3415 Write_Id (Entity (Parent (N)));
3417 -- For any other node with an associated entity, output it
3419 elsif Nkind (N) in N_Has_Entity
3420 and then Present (Entity_Or_Associated_Node (N))
3421 and then Nkind (Entity_Or_Associated_Node (N)) in N_Entity
3423 Write_Id (Entity (N));
3425 -- All other cases, we just print the Chars field
3428 Write_Name_With_Col_Check (Chars (N));
3432 -----------------------
3433 -- Write_Identifiers --
3434 -----------------------
3436 function Write_Identifiers (Node : Node_Id) return Boolean is
3438 Sprint_Node (Defining_Identifier (Node));
3439 Update_Itype (Defining_Identifier (Node));
3441 -- The remainder of the declaration must be printed unless we are
3442 -- printing the original tree and this is not the last identifier
3445 not Dump_Original_Only or else not More_Ids (Node);
3447 end Write_Identifiers;
3449 ------------------------
3450 -- Write_Implicit_Def --
3451 ------------------------
3453 procedure Write_Implicit_Def (E : Entity_Id) is
3458 when E_Array_Subtype =>
3459 Write_Str_With_Col_Check ("subtype ");
3461 Write_Str_With_Col_Check (" is ");
3462 Write_Id (Base_Type (E));
3463 Write_Str_With_Col_Check (" (");
3465 Ind := First_Index (E);
3466 while Present (Ind) loop
3470 if Present (Ind) then
3477 when E_Signed_Integer_Subtype | E_Enumeration_Subtype =>
3478 Write_Str_With_Col_Check ("subtype ");
3481 Write_Id (Etype (E));
3482 Write_Str_With_Col_Check (" range ");
3483 Sprint_Node (Scalar_Range (E));
3487 Write_Str_With_Col_Check ("type ");
3489 Write_Str_With_Col_Check (" is <");
3494 end Write_Implicit_Def;
3500 procedure Write_Indent is
3501 Loc : constant Source_Ptr := Sloc (Dump_Node);
3504 if Indent_Annull_Flag then
3505 Indent_Annull_Flag := False;
3507 -- Deal with Dump_Source_Text output. Note that we ignore implicit
3508 -- label declarations, since they typically have the sloc of the
3509 -- corresponding label, which really messes up the -gnatL output.
3512 and then Loc > No_Location
3513 and then Nkind (Dump_Node) /= N_Implicit_Label_Declaration
3515 if Get_Source_File_Index (Loc) = Current_Source_File then
3517 (Get_Physical_Line_Number (Sloc (Dump_Node)));
3523 for J in 1 .. Indent loop
3529 ------------------------------
3530 -- Write_Indent_Identifiers --
3531 ------------------------------
3533 function Write_Indent_Identifiers (Node : Node_Id) return Boolean is
3535 -- We need to start a new line for every node, except in the case
3536 -- where we are printing the original tree and this is not the first
3537 -- defining identifier in the list.
3539 if not Dump_Original_Only or else not Prev_Ids (Node) then
3542 -- If printing original tree and this is not the first defining
3543 -- identifier in the list, then the previous call to this procedure
3544 -- printed only the name, and we add a comma to separate the names.
3550 Sprint_Node (Defining_Identifier (Node));
3552 -- The remainder of the declaration must be printed unless we are
3553 -- printing the original tree and this is not the last identifier
3556 not Dump_Original_Only or else not More_Ids (Node);
3557 end Write_Indent_Identifiers;
3559 -----------------------------------
3560 -- Write_Indent_Identifiers_Sloc --
3561 -----------------------------------
3563 function Write_Indent_Identifiers_Sloc (Node : Node_Id) return Boolean is
3565 -- We need to start a new line for every node, except in the case
3566 -- where we are printing the original tree and this is not the first
3567 -- defining identifier in the list.
3569 if not Dump_Original_Only or else not Prev_Ids (Node) then
3572 -- If printing original tree and this is not the first defining
3573 -- identifier in the list, then the previous call to this procedure
3574 -- printed only the name, and we add a comma to separate the names.
3581 Sprint_Node (Defining_Identifier (Node));
3583 -- The remainder of the declaration must be printed unless we are
3584 -- printing the original tree and this is not the last identifier
3586 return not Dump_Original_Only or else not More_Ids (Node);
3587 end Write_Indent_Identifiers_Sloc;
3589 ----------------------
3590 -- Write_Indent_Str --
3591 ----------------------
3593 procedure Write_Indent_Str (S : String) is
3595 Write_Corresponding_Source (S);
3598 end Write_Indent_Str;
3600 ---------------------------
3601 -- Write_Indent_Str_Sloc --
3602 ---------------------------
3604 procedure Write_Indent_Str_Sloc (S : String) is
3606 Write_Corresponding_Source (S);
3609 end Write_Indent_Str_Sloc;
3615 procedure Write_Itype (Typ : Entity_Id) is
3617 procedure Write_Header (T : Boolean := True);
3618 -- Write type if T is True, subtype if T is false
3624 procedure Write_Header (T : Boolean := True) is
3627 Write_Str ("[type ");
3629 Write_Str ("[subtype ");
3632 Write_Name_With_Col_Check (Chars (Typ));
3636 -- Start of processing for Write_Itype
3639 if Nkind (Typ) in N_Entity
3640 and then Is_Itype (Typ)
3641 and then not Itype_Printed (Typ)
3643 -- Itype to be printed
3646 B : constant Node_Id := Etype (Typ);
3648 P : constant Node_Id := Parent (Typ);
3650 S : constant Saved_Output_Buffer := Save_Output_Buffer;
3651 -- Save current output buffer
3653 Old_Sloc : Source_Ptr;
3654 -- Save sloc of related node, so it is not modified when
3655 -- printing with -gnatD.
3658 -- Write indentation at start of line
3660 for J in 1 .. Indent loop
3664 -- If we have a constructed declaration for the itype, print it
3667 and then Nkind (P) in N_Declaration
3668 and then Defining_Entity (P) = Typ
3670 -- We must set Itype_Printed true before the recursive call to
3671 -- print the node, otherwise we get an infinite recursion!
3673 Set_Itype_Printed (Typ, True);
3675 -- Write the declaration enclosed in [], avoiding new line
3676 -- at start of declaration, and semicolon at end.
3678 -- Note: The itype may be imported from another unit, in which
3679 -- case we do not want to modify the Sloc of the declaration.
3680 -- Otherwise the itype may appear to be in the current unit,
3681 -- and the back-end will reject a reference out of scope.
3684 Indent_Annull_Flag := True;
3685 Old_Sloc := Sloc (P);
3687 Set_Sloc (P, Old_Sloc);
3688 Write_Erase_Char (';');
3690 -- If no constructed declaration, then we have to concoct the
3691 -- source corresponding to the type entity that we have at hand.
3696 -- Access types and subtypes
3699 Write_Header (Ekind (Typ) = E_Access_Type);
3700 Write_Str ("access ");
3702 if Is_Access_Constant (Typ) then
3703 Write_Str ("constant ");
3704 elsif Can_Never_Be_Null (Typ) then
3705 Write_Str ("not null ");
3708 Write_Id (Directly_Designated_Type (Typ));
3710 -- Array types and string types
3712 when E_Array_Type | E_String_Type =>
3714 Write_Str ("array (");
3716 X := First_Index (Typ);
3720 if not Is_Constrained (Typ) then
3721 Write_Str (" range <>");
3729 Write_Str (") of ");
3730 X := Component_Type (Typ);
3732 -- Preserve sloc of component type, which is defined
3733 -- elsewhere than the itype (see comment above).
3735 Old_Sloc := Sloc (X);
3737 Set_Sloc (X, Old_Sloc);
3739 -- Array subtypes and string subtypes.
3740 -- Preserve Sloc of index subtypes, as above.
3742 when E_Array_Subtype | E_String_Subtype =>
3743 Write_Header (False);
3744 Write_Id (Etype (Typ));
3747 X := First_Index (Typ);
3749 Old_Sloc := Sloc (X);
3751 Set_Sloc (X, Old_Sloc);
3759 -- Signed integer types, and modular integer subtypes,
3760 -- and also enumeration subtypes.
3762 when E_Signed_Integer_Type |
3763 E_Signed_Integer_Subtype |
3764 E_Modular_Integer_Subtype |
3765 E_Enumeration_Subtype =>
3767 Write_Header (Ekind (Typ) = E_Signed_Integer_Type);
3769 if Ekind (Typ) = E_Signed_Integer_Type then
3775 -- Print bounds if different from base type
3778 L : constant Node_Id := Type_Low_Bound (Typ);
3779 H : constant Node_Id := Type_High_Bound (Typ);
3784 -- B can either be a scalar type, in which case the
3785 -- declaration of Typ may constrain it with different
3786 -- bounds, or a private type, in which case we know
3787 -- that the declaration of Typ cannot have a scalar
3790 if Is_Scalar_Type (B) then
3791 LE := Type_Low_Bound (B);
3792 HE := Type_High_Bound (B);
3800 and then Nkind (L) = N_Integer_Literal
3801 and then Nkind (H) = N_Integer_Literal
3802 and then Nkind (LE) = N_Integer_Literal
3803 and then Nkind (HE) = N_Integer_Literal
3804 and then UI_Eq (Intval (L), Intval (LE))
3805 and then UI_Eq (Intval (H), Intval (HE)))
3810 Write_Str (" range ");
3811 Sprint_Node (Type_Low_Bound (Typ));
3813 Sprint_Node (Type_High_Bound (Typ));
3817 -- Modular integer types
3819 when E_Modular_Integer_Type =>
3821 Write_Str (" mod ");
3822 Write_Uint_With_Col_Check (Modulus (Typ), Auto);
3824 -- Floating point types and subtypes
3826 when E_Floating_Point_Type |
3827 E_Floating_Point_Subtype =>
3829 Write_Header (Ekind (Typ) = E_Floating_Point_Type);
3831 if Ekind (Typ) = E_Floating_Point_Type then
3835 Write_Id (Etype (Typ));
3837 if Digits_Value (Typ) /= Digits_Value (Etype (Typ)) then
3838 Write_Str (" digits ");
3839 Write_Uint_With_Col_Check
3840 (Digits_Value (Typ), Decimal);
3843 -- Print bounds if not different from base type
3846 L : constant Node_Id := Type_Low_Bound (Typ);
3847 H : constant Node_Id := Type_High_Bound (Typ);
3848 LE : constant Node_Id := Type_Low_Bound (B);
3849 HE : constant Node_Id := Type_High_Bound (B);
3852 if Nkind (L) = N_Real_Literal
3853 and then Nkind (H) = N_Real_Literal
3854 and then Nkind (LE) = N_Real_Literal
3855 and then Nkind (HE) = N_Real_Literal
3856 and then UR_Eq (Realval (L), Realval (LE))
3857 and then UR_Eq (Realval (H), Realval (HE))
3862 Write_Str (" range ");
3863 Sprint_Node (Type_Low_Bound (Typ));
3865 Sprint_Node (Type_High_Bound (Typ));
3871 when E_Record_Subtype =>
3872 Write_Header (False);
3873 Write_Str ("record");
3879 C := First_Entity (Typ);
3880 while Present (C) loop
3884 Write_Id (Etype (C));
3890 Write_Indent_Str (" end record");
3894 when E_Class_Wide_Type |
3895 E_Class_Wide_Subtype =>
3897 Write_Name_With_Col_Check (Chars (Etype (Typ)));
3898 Write_Str ("'Class");
3902 when E_Subprogram_Type =>
3905 if Etype (Typ) = Standard_Void_Type then
3906 Write_Str ("procedure");
3908 Write_Str ("function");
3911 if Present (First_Entity (Typ)) then
3918 Param := First_Entity (Typ);
3923 if Ekind (Param) = E_In_Out_Parameter then
3924 Write_Str ("in out ");
3925 elsif Ekind (Param) = E_Out_Parameter then
3929 Write_Id (Etype (Param));
3930 Next_Entity (Param);
3931 exit when No (Param);
3939 if Etype (Typ) /= Standard_Void_Type then
3940 Write_Str (" return ");
3941 Write_Id (Etype (Typ));
3944 when E_String_Literal_Subtype =>
3946 LB : constant Uint :=
3947 Intval (String_Literal_Low_Bound (Typ));
3948 Len : constant Uint :=
3949 String_Literal_Length (Typ);
3951 Write_Str ("String (");
3952 Write_Int (UI_To_Int (LB));
3954 Write_Int (UI_To_Int (LB + Len) - 1);
3958 -- For all other Itypes, print ??? (fill in later)
3961 Write_Header (True);
3967 -- Add terminating bracket and restore output buffer
3971 Restore_Output_Buffer (S);
3974 Set_Itype_Printed (Typ);
3978 -------------------------------
3979 -- Write_Name_With_Col_Check --
3980 -------------------------------
3982 procedure Write_Name_With_Col_Check (N : Name_Id) is
3988 Get_Name_String (N);
3990 -- Deal with -gnatdI which replaces any sequence Cnnnb where C is an
3991 -- upper case letter, nnn is one or more digits and b is a lower case
3992 -- letter by C...b, so that listings do not depend on serial numbers.
3994 if Debug_Flag_II then
3996 while J < Name_Len - 1 loop
3997 if Name_Buffer (J) in 'A' .. 'Z'
3998 and then Name_Buffer (J + 1) in '0' .. '9'
4001 while K < Name_Len loop
4002 exit when Name_Buffer (K) not in '0' .. '9';
4006 if Name_Buffer (K) in 'a' .. 'z' then
4007 L := Name_Len - K + 1;
4009 Name_Buffer (J + 4 .. J + L + 3) :=
4010 Name_Buffer (K .. Name_Len);
4011 Name_Buffer (J + 1 .. J + 3) := "...";
4012 Name_Len := J + L + 3;
4025 -- Fall through for normal case
4027 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
4028 end Write_Name_With_Col_Check;
4030 ------------------------------------
4031 -- Write_Name_With_Col_Check_Sloc --
4032 ------------------------------------
4034 procedure Write_Name_With_Col_Check_Sloc (N : Name_Id) is
4036 Get_Name_String (N);
4037 Write_Str_With_Col_Check_Sloc (Name_Buffer (1 .. Name_Len));
4038 end Write_Name_With_Col_Check_Sloc;
4040 --------------------
4041 -- Write_Operator --
4042 --------------------
4044 procedure Write_Operator (N : Node_Id; S : String) is
4045 F : Natural := S'First;
4046 T : Natural := S'Last;
4049 -- If no overflow check, just write string out, and we are done
4051 if not Do_Overflow_Check (N) then
4054 -- If overflow check, we want to surround the operator with curly
4055 -- brackets, but not include spaces within the brackets.
4068 Write_Str_Sloc (S (F .. T));
4071 if S (S'Last) = ' ' then
4077 -----------------------
4078 -- Write_Param_Specs --
4079 -----------------------
4081 procedure Write_Param_Specs (N : Node_Id) is
4087 Specs := Parameter_Specifications (N);
4089 if Is_Non_Empty_List (Specs) then
4090 Write_Str_With_Col_Check (" (");
4091 Spec := First (Specs);
4095 Formal := Defining_Identifier (Spec);
4097 exit when Spec = Empty;
4099 -- Add semicolon, unless we are printing original tree and the
4100 -- next specification is part of a list (but not the first element
4103 if not Dump_Original_Only or else not Prev_Ids (Spec) then
4108 -- Write out any extra formals
4110 while Present (Extra_Formal (Formal)) loop
4111 Formal := Extra_Formal (Formal);
4113 Write_Name_With_Col_Check (Chars (Formal));
4115 Write_Name_With_Col_Check (Chars (Etype (Formal)));
4120 end Write_Param_Specs;
4122 -----------------------
4123 -- Write_Rewrite_Str --
4124 -----------------------
4126 procedure Write_Rewrite_Str (S : String) is
4128 if not Dump_Generated_Only then
4129 if S'Length = 3 and then S = ">>>" then
4132 Write_Str_With_Col_Check (S);
4135 end Write_Rewrite_Str;
4137 -----------------------
4138 -- Write_Source_Line --
4139 -----------------------
4141 procedure Write_Source_Line (L : Physical_Line_Number) is
4143 Src : Source_Buffer_Ptr;
4147 if Dump_Source_Text then
4148 Src := Source_Text (Current_Source_File);
4149 Loc := Line_Start (L, Current_Source_File);
4152 -- See if line is a comment line, if not, and if not line one,
4153 -- precede with blank line.
4156 while Src (Scn) = ' ' or else Src (Scn) = ASCII.HT loop
4160 if (Src (Scn) in Line_Terminator
4161 or else Src (Scn .. Scn + 1) /= "--")
4167 -- Now write the source text of the line
4170 Write_Int (Int (L));
4173 while Src (Loc) not in Line_Terminator loop
4174 Write_Char (Src (Loc));
4178 end Write_Source_Line;
4180 ------------------------
4181 -- Write_Source_Lines --
4182 ------------------------
4184 procedure Write_Source_Lines (L : Physical_Line_Number) is
4186 while Last_Line_Printed < L loop
4187 Last_Line_Printed := Last_Line_Printed + 1;
4188 Write_Source_Line (Last_Line_Printed);
4190 end Write_Source_Lines;
4192 --------------------
4193 -- Write_Str_Sloc --
4194 --------------------
4196 procedure Write_Str_Sloc (S : String) is
4198 for J in S'Range loop
4199 Write_Char_Sloc (S (J));
4203 ------------------------------
4204 -- Write_Str_With_Col_Check --
4205 ------------------------------
4207 procedure Write_Str_With_Col_Check (S : String) is
4209 if Int (S'Last) + Column > Sprint_Line_Limit then
4210 Write_Indent_Str (" ");
4212 if S (S'First) = ' ' then
4213 Write_Str (S (S'First + 1 .. S'Last));
4221 end Write_Str_With_Col_Check;
4223 -----------------------------------
4224 -- Write_Str_With_Col_Check_Sloc --
4225 -----------------------------------
4227 procedure Write_Str_With_Col_Check_Sloc (S : String) is
4229 if Int (S'Last) + Column > Sprint_Line_Limit then
4230 Write_Indent_Str (" ");
4232 if S (S'First) = ' ' then
4233 Write_Str_Sloc (S (S'First + 1 .. S'Last));
4241 end Write_Str_With_Col_Check_Sloc;
4243 ---------------------------
4244 -- Write_Subprogram_Name --
4245 ---------------------------
4247 procedure Write_Subprogram_Name (N : Node_Id) is
4249 if not Comes_From_Source (N)
4250 and then Is_Entity_Name (N)
4253 Ent : constant Entity_Id := Entity (N);
4255 if not In_Extended_Main_Source_Unit (Ent)
4257 Is_Predefined_File_Name
4258 (Unit_File_Name (Get_Source_Unit (Ent)))
4260 -- Run-time routine name, output name with a preceding dollar
4261 -- making sure that we do not get a line split between them.
4263 Col_Check (Length_Of_Name (Chars (Ent)) + 1);
4265 Write_Name (Chars (Ent));
4271 -- Normal case, not a run-time routine name
4274 end Write_Subprogram_Name;
4276 -------------------------------
4277 -- Write_Uint_With_Col_Check --
4278 -------------------------------
4280 procedure Write_Uint_With_Col_Check (U : Uint; Format : UI_Format) is
4282 Col_Check (UI_Decimal_Digits_Hi (U));
4283 UI_Write (U, Format);
4284 end Write_Uint_With_Col_Check;
4286 ------------------------------------
4287 -- Write_Uint_With_Col_Check_Sloc --
4288 ------------------------------------
4290 procedure Write_Uint_With_Col_Check_Sloc (U : Uint; Format : UI_Format) is
4292 Col_Check (UI_Decimal_Digits_Hi (U));
4294 UI_Write (U, Format);
4295 end Write_Uint_With_Col_Check_Sloc;
4297 -------------------------------------
4298 -- Write_Ureal_With_Col_Check_Sloc --
4299 -------------------------------------
4301 procedure Write_Ureal_With_Col_Check_Sloc (U : Ureal) is
4302 D : constant Uint := Denominator (U);
4303 N : constant Uint := Numerator (U);
4307 (UI_Decimal_Digits_Hi (D) + UI_Decimal_Digits_Hi (N) + 4);
4310 end Write_Ureal_With_Col_Check_Sloc;