1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, 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_Eval; use Sem_Eval;
39 with Sem_Util; use Sem_Util;
40 with Sinfo; use Sinfo;
41 with Sinput; use Sinput;
42 with Sinput.D; use Sinput.D;
43 with Snames; use Snames;
44 with Stand; use Stand;
45 with Stringt; use Stringt;
46 with Uintp; use Uintp;
47 with Uname; use Uname;
48 with Urealp; use Urealp;
50 package body Sprint is
51 Current_Source_File : Source_File_Index;
52 -- Index of source file whose generated code is being dumped
54 Dump_Node : Node_Id := Empty;
55 -- This is set to the current node, used for printing line numbers. In
56 -- Debug_Generated_Code mode, Dump_Node is set to the current node
57 -- requiring Sloc fixup, until Set_Debug_Sloc is called to set the proper
58 -- value. The call clears it back to Empty.
60 Debug_Sloc : Source_Ptr;
61 -- Sloc of first byte of line currently being written if we are
62 -- generating a source debug file.
64 Dump_Original_Only : Boolean;
65 -- Set True if the -gnatdo (dump original tree) flag is set
67 Dump_Generated_Only : Boolean;
68 -- Set True if the -gnatG (dump generated tree) debug flag is set
69 -- or for Print_Generated_Code (-gnatG) or Dump_Generated_Code (-gnatD).
71 Dump_Freeze_Null : Boolean;
72 -- Set True if freeze nodes and non-source null statements output
74 Freeze_Indent : Int := 0;
75 -- Keep track of freeze indent level (controls output of blank lines before
76 -- procedures within expression freeze actions). Relevant only if we are
77 -- not in Dump_Source_Text mode, since in Dump_Source_Text mode we don't
78 -- output these blank lines in any case.
81 -- Number of columns for current line output indentation
83 Indent_Annull_Flag : Boolean := False;
84 -- Set True if subsequent Write_Indent call to be ignored, gets reset
85 -- by this call, so it is only active to suppress a single indent call.
87 Last_Line_Printed : Physical_Line_Number;
88 -- This keeps track of the physical line number of the last source line
89 -- that has been output. The value is only valid in Dump_Source_Text mode.
91 -------------------------------
92 -- Operator Precedence Table --
93 -------------------------------
95 -- This table is used to decide whether a subexpression needs to be
96 -- parenthesized. The rule is that if an operand of an operator (which
97 -- for this purpose includes AND THEN and OR ELSE) is itself an operator
98 -- with a lower precedence than the operator (or equal precedence if
99 -- appearing as the right operand), then parentheses are required.
101 Op_Prec : constant array (N_Subexpr) of Short_Short_Integer :=
134 procedure Sprint_Left_Opnd (N : Node_Id);
135 -- Print left operand of operator, parenthesizing if necessary
137 procedure Sprint_Right_Opnd (N : Node_Id);
138 -- Print right operand of operator, parenthesizing if necessary
140 -----------------------
141 -- Local Subprograms --
142 -----------------------
144 procedure Col_Check (N : Nat);
145 -- Check that at least N characters remain on current line, and if not,
146 -- then start an extra line with two characters extra indentation for
147 -- continuing text on the next line.
149 procedure Extra_Blank_Line;
150 -- In some situations we write extra blank lines to separate the generated
151 -- code to make it more readable. However, these extra blank lines are not
152 -- generated in Dump_Source_Text mode, since there the source text lines
153 -- output with preceding blank lines are quite sufficient as separators.
154 -- This procedure writes a blank line if Dump_Source_Text is False.
156 procedure Indent_Annull;
157 -- Causes following call to Write_Indent to be ignored. This is used when
158 -- a higher level node wants to stop a lower level node from starting a
159 -- new line, when it would otherwise be inclined to do so (e.g. the case
160 -- of an accept statement called from an accept alternative with a guard)
162 procedure Indent_Begin;
163 -- Increase indentation level
165 procedure Indent_End;
166 -- Decrease indentation level
168 procedure Print_Debug_Line (S : String);
169 -- Used to print output lines in Debug_Generated_Code mode (this is used
170 -- as the argument for a call to Set_Special_Output in package Output).
172 procedure Process_TFAI_RR_Flags (Nod : Node_Id);
173 -- Given a divide, multiplication or division node, check the flags
174 -- Treat_Fixed_As_Integer and Rounded_Flags, and if set, output the
175 -- appropriate special syntax characters (# and @).
177 procedure Set_Debug_Sloc;
178 -- If Dump_Node is non-empty, this routine sets the appropriate value
179 -- in its Sloc field, from the current location in the debug source file
180 -- that is currently being written.
182 procedure Sprint_And_List (List : List_Id);
183 -- Print the given list with items separated by vertical "and"
185 procedure Sprint_Bar_List (List : List_Id);
186 -- Print the given list with items separated by vertical bars
188 procedure Sprint_End_Label
191 -- Print the end label for a Handled_Sequence_Of_Statements in a body.
192 -- If there is not end label, use the defining identifier of the enclosing
193 -- construct. If the end label is present, treat it as a reference to the
194 -- defining entity of the construct: this guarantees that it carries the
195 -- proper sloc information for debugging purposes.
197 procedure Sprint_Node_Actual (Node : Node_Id);
198 -- This routine prints its node argument. It is a lower level routine than
199 -- Sprint_Node, in that it does not bother about rewritten trees.
201 procedure Sprint_Node_Sloc (Node : Node_Id);
202 -- Like Sprint_Node, but in addition, in Debug_Generated_Code mode,
203 -- sets the Sloc of the current debug node to be a copy of the Sloc
204 -- of the sprinted node Node. Note that this is done after printing
205 -- Node, so that the Sloc is the proper updated value for the debug file.
207 procedure Update_Itype (Node : Node_Id);
208 -- Update the Sloc of an itype that is not attached to the tree, when
209 -- debugging expanded code. This routine is called from nodes whose
210 -- type can be an Itype, such as defining_identifiers that may be of
211 -- an anonymous access type, or ranges in slices.
213 procedure Write_Char_Sloc (C : Character);
214 -- Like Write_Char, except that if C is non-blank, Set_Debug_Sloc is
215 -- called to ensure that the current node has a proper Sloc set.
217 procedure Write_Condition_And_Reason (Node : Node_Id);
218 -- Write Condition and Reason codes of Raise_xxx_Error node
220 procedure Write_Corresponding_Source (S : String);
221 -- If S is a string with a single keyword (possibly followed by a space),
222 -- and if the next non-comment non-blank source line matches this keyword,
223 -- then output all source lines up to this matching line.
225 procedure Write_Discr_Specs (N : Node_Id);
226 -- Output discriminant specification for node, which is any of the type
227 -- declarations that can have discriminants.
229 procedure Write_Ekind (E : Entity_Id);
230 -- Write the String corresponding to the Ekind without "E_"
232 procedure Write_Id (N : Node_Id);
233 -- N is a node with a Chars field. This procedure writes the name that
234 -- will be used in the generated code associated with the name. For a
235 -- node with no associated entity, this is simply the Chars field. For
236 -- the case where there is an entity associated with the node, we print
237 -- the name associated with the entity (since it may have been encoded).
238 -- One other special case is that an entity has an active external name
239 -- (i.e. an external name present with no address clause), then this
240 -- external name is output. This procedure also deals with outputting
241 -- declarations of referenced itypes, if not output earlier.
243 function Write_Identifiers (Node : Node_Id) return Boolean;
244 -- Handle node where the grammar has a list of defining identifiers, but
245 -- the tree has a separate declaration for each identifier. Handles the
246 -- printing of the defining identifier, and returns True if the type and
247 -- initialization information is to be printed, False if it is to be
248 -- skipped (the latter case happens when printing defining identifiers
249 -- other than the first in the original tree output case).
251 procedure Write_Implicit_Def (E : Entity_Id);
252 pragma Warnings (Off, Write_Implicit_Def);
253 -- Write the definition of the implicit type E according to its Ekind
254 -- For now a debugging procedure, but might be used in the future.
256 procedure Write_Indent;
257 -- Start a new line and write indentation spacing
259 function Write_Indent_Identifiers (Node : Node_Id) return Boolean;
260 -- Like Write_Identifiers except that each new printed declaration
261 -- is at the start of a new line.
263 function Write_Indent_Identifiers_Sloc (Node : Node_Id) return Boolean;
264 -- Like Write_Indent_Identifiers except that in Debug_Generated_Code
265 -- mode, the Sloc of the current debug node is set to point to the
266 -- first output identifier.
268 procedure Write_Indent_Str (S : String);
269 -- Start a new line and write indent spacing followed by given string
271 procedure Write_Indent_Str_Sloc (S : String);
272 -- Like Write_Indent_Str, but in addition, in Debug_Generated_Code mode,
273 -- the Sloc of the current node is set to the first non-blank character
276 procedure Write_Itype (Typ : Entity_Id);
277 -- If Typ is an Itype that has not been written yet, write it. If Typ is
278 -- any other kind of entity or tree node, the call is ignored.
280 procedure Write_Name_With_Col_Check (N : Name_Id);
281 -- Write name (using Write_Name) with initial column check, and possible
282 -- initial Write_Indent (to get new line) if current line is too full.
284 procedure Write_Name_With_Col_Check_Sloc (N : Name_Id);
285 -- Like Write_Name_With_Col_Check but in addition, in Debug_Generated_Code
286 -- mode, sets Sloc of current debug node to first character of name.
288 procedure Write_Operator (N : Node_Id; S : String);
289 -- Like Write_Str_Sloc, used for operators, encloses the string in
290 -- characters {} if the Do_Overflow flag is set on the node N.
292 procedure Write_Param_Specs (N : Node_Id);
293 -- Output parameter specifications for node (which is either a function
294 -- or procedure specification with a Parameter_Specifications field)
296 procedure Write_Rewrite_Str (S : String);
297 -- Writes out a string (typically containing <<< or >>>}) for a node
298 -- created by rewriting the tree. Suppressed if we are outputting the
299 -- generated code only, since in this case we don't specially mark nodes
300 -- created by rewriting).
302 procedure Write_Source_Line (L : Physical_Line_Number);
303 -- If writing of interspersed source lines is enabled, then write the given
304 -- line from the source file, preceded by Eol, then an extra blank line if
305 -- the line has at least one blank, is not a comment and is not line one,
306 -- then "--" and the line number followed by period followed by text of the
307 -- source line (without terminating Eol). If interspersed source line
308 -- output not enabled, then the call has no effect.
310 procedure Write_Source_Lines (L : Physical_Line_Number);
311 -- If writing of interspersed source lines is enabled, then writes source
312 -- lines Last_Line_Printed + 1 .. L, and updates Last_Line_Printed. If
313 -- interspersed source line output not enabled, then call has no effect.
315 procedure Write_Str_Sloc (S : String);
316 -- Like Write_Str, but sets debug Sloc of current debug node to first
317 -- non-blank character if a current debug node is active.
319 procedure Write_Str_With_Col_Check (S : String);
320 -- Write string (using Write_Str) with initial column check, and possible
321 -- initial Write_Indent (to get new line) if current line is too full.
323 procedure Write_Str_With_Col_Check_Sloc (S : String);
324 -- Like Write_Str_With_Col_Check, but sets debug Sloc of current debug
325 -- node to first non-blank character if a current debug node is active.
327 procedure Write_Subprogram_Name (N : Node_Id);
328 -- N is the Name field of a function call or procedure statement call.
329 -- The effect of the call is to output the name, preceded by a $ if the
330 -- call is identified as an implicit call to a run time routine.
332 procedure Write_Uint_With_Col_Check (U : Uint; Format : UI_Format);
333 -- Write Uint (using UI_Write) with initial column check, and possible
334 -- initial Write_Indent (to get new line) if current line is too full.
335 -- The format parameter determines the output format (see UI_Write).
337 procedure Write_Uint_With_Col_Check_Sloc (U : Uint; Format : UI_Format);
338 -- Write Uint (using UI_Write) with initial column check, and possible
339 -- initial Write_Indent (to get new line) if current line is too full.
340 -- The format parameter determines the output format (see UI_Write).
341 -- In addition, in Debug_Generated_Code mode, sets the current node
342 -- Sloc to the first character of the output value.
344 procedure Write_Ureal_With_Col_Check_Sloc (U : Ureal);
345 -- Write Ureal (using same output format as UR_Write) with column checks
346 -- and a possible initial Write_Indent (to get new line) if current line
347 -- is too full. In addition, in Debug_Generated_Code mode, sets the
348 -- current node Sloc to the first character of the output value.
354 procedure Col_Check (N : Nat) is
356 if N + Column > Sprint_Line_Limit then
357 Write_Indent_Str (" ");
361 ----------------------
362 -- Extra_Blank_Line --
363 ----------------------
365 procedure Extra_Blank_Line is
367 if not Dump_Source_Text then
370 end Extra_Blank_Line;
376 procedure Indent_Annull is
378 Indent_Annull_Flag := True;
385 procedure Indent_Begin is
387 Indent := Indent + 3;
394 procedure Indent_End is
396 Indent := Indent - 3;
403 procedure pg (Arg : Union_Id) is
405 Dump_Generated_Only := True;
406 Dump_Original_Only := False;
407 Dump_Freeze_Null := True;
408 Current_Source_File := No_Source_File;
410 if Arg in List_Range then
411 Sprint_Node_List (List_Id (Arg));
413 elsif Arg in Node_Range then
414 Sprint_Node (Node_Id (Arg));
427 procedure po (Arg : Union_Id) is
429 Dump_Generated_Only := False;
430 Dump_Original_Only := True;
431 Current_Source_File := No_Source_File;
433 if Arg in List_Range then
434 Sprint_Node_List (List_Id (Arg));
436 elsif Arg in Node_Range then
437 Sprint_Node (Node_Id (Arg));
446 ----------------------
447 -- Print_Debug_Line --
448 ----------------------
450 procedure Print_Debug_Line (S : String) is
452 Write_Debug_Line (S, Debug_Sloc);
453 end Print_Debug_Line;
455 ---------------------------
456 -- Process_TFAI_RR_Flags --
457 ---------------------------
459 procedure Process_TFAI_RR_Flags (Nod : Node_Id) is
461 if Treat_Fixed_As_Integer (Nod) then
465 if Rounded_Result (Nod) then
468 end Process_TFAI_RR_Flags;
474 procedure ps (Arg : Union_Id) is
476 Dump_Generated_Only := False;
477 Dump_Original_Only := False;
478 Current_Source_File := No_Source_File;
480 if Arg in List_Range then
481 Sprint_Node_List (List_Id (Arg));
483 elsif Arg in Node_Range then
484 Sprint_Node (Node_Id (Arg));
497 procedure Set_Debug_Sloc is
499 if Debug_Generated_Code and then Present (Dump_Node) then
500 Set_Sloc (Dump_Node, Debug_Sloc + Source_Ptr (Column - 1));
509 procedure Source_Dump is
512 -- Put underline under string we just printed
518 procedure Underline is
519 Col : constant Int := Column;
524 while Col > Column loop
531 -- Start of processing for Source_Dump
534 Dump_Generated_Only := Debug_Flag_G or
535 Print_Generated_Code or
536 Debug_Generated_Code;
537 Dump_Original_Only := Debug_Flag_O;
538 Dump_Freeze_Null := Debug_Flag_S or Debug_Flag_G;
540 -- Note that we turn off the tree dump flags immediately, before
541 -- starting the dump. This avoids generating two copies of the dump
542 -- if an abort occurs after printing the dump, and more importantly,
543 -- avoids an infinite loop if an abort occurs during the dump.
546 Current_Source_File := No_Source_File;
547 Debug_Flag_Z := False;
550 Write_Str ("Source recreated from tree of Standard (spec)");
552 Sprint_Node (Standard_Package_Node);
557 if Debug_Flag_S or Dump_Generated_Only or Dump_Original_Only then
558 Debug_Flag_G := False;
559 Debug_Flag_O := False;
560 Debug_Flag_S := False;
562 -- Dump requested units
564 for U in Main_Unit .. Last_Unit loop
565 Current_Source_File := Source_Index (U);
567 -- Dump all units if -gnatdf set, otherwise we dump only
568 -- the source files that are in the extended main source.
571 or else In_Extended_Main_Source_Unit (Cunit_Entity (U))
573 -- If we are generating debug files, setup to write them
575 if Debug_Generated_Code then
576 Set_Special_Output (Print_Debug_Line'Access);
577 Create_Debug_Source (Source_Index (U), Debug_Sloc);
578 Write_Source_Line (1);
579 Last_Line_Printed := 1;
580 Sprint_Node (Cunit (U));
581 Write_Source_Lines (Last_Source_Line (Current_Source_File));
584 Set_Special_Output (null);
586 -- Normal output to standard output file
589 Write_Str ("Source recreated from tree for ");
590 Write_Unit_Name (Unit_Name (U));
592 Write_Source_Line (1);
593 Last_Line_Printed := 1;
594 Sprint_Node (Cunit (U));
595 Write_Source_Lines (Last_Source_Line (Current_Source_File));
604 ---------------------
605 -- Sprint_And_List --
606 ---------------------
608 procedure Sprint_And_List (List : List_Id) is
611 if Is_Non_Empty_List (List) then
612 Node := First (List);
616 exit when Node = Empty;
622 ---------------------
623 -- Sprint_Bar_List --
624 ---------------------
626 procedure Sprint_Bar_List (List : List_Id) is
629 if Is_Non_Empty_List (List) then
630 Node := First (List);
634 exit when Node = Empty;
640 ----------------------
641 -- Sprint_End_Label --
642 ----------------------
644 procedure Sprint_End_Label
650 and then Present (End_Label (Node))
651 and then Is_Entity_Name (End_Label (Node))
653 Set_Entity (End_Label (Node), Default);
655 -- For a function whose name is an operator, use the qualified name
656 -- created for the defining entity.
658 if Nkind (End_Label (Node)) = N_Operator_Symbol then
659 Set_Chars (End_Label (Node), Chars (Default));
662 Sprint_Node (End_Label (Node));
664 Sprint_Node (Default);
666 end Sprint_End_Label;
668 -----------------------
669 -- Sprint_Comma_List --
670 -----------------------
672 procedure Sprint_Comma_List (List : List_Id) is
676 if Is_Non_Empty_List (List) then
677 Node := First (List);
681 exit when Node = Empty;
683 if not Is_Rewrite_Insertion (Node)
684 or else not Dump_Original_Only
690 end Sprint_Comma_List;
692 --------------------------
693 -- Sprint_Indented_List --
694 --------------------------
696 procedure Sprint_Indented_List (List : List_Id) is
699 Sprint_Node_List (List);
701 end Sprint_Indented_List;
703 ---------------------
704 -- Sprint_Left_Opnd --
705 ---------------------
707 procedure Sprint_Left_Opnd (N : Node_Id) is
708 Opnd : constant Node_Id := Left_Opnd (N);
711 if Paren_Count (Opnd) /= 0
712 or else Op_Prec (Nkind (Opnd)) >= Op_Prec (Nkind (N))
721 end Sprint_Left_Opnd;
727 procedure Sprint_Node (Node : Node_Id) is
729 if Is_Rewrite_Insertion (Node) then
730 if not Dump_Original_Only then
732 -- For special cases of nodes that always output <<< >>>
733 -- do not duplicate the output at this point.
735 if Nkind (Node) = N_Freeze_Entity
736 or else Nkind (Node) = N_Implicit_Label_Declaration
738 Sprint_Node_Actual (Node);
740 -- Normal case where <<< >>> may be required
743 Write_Rewrite_Str ("<<<");
744 Sprint_Node_Actual (Node);
745 Write_Rewrite_Str (">>>");
749 elsif Is_Rewrite_Substitution (Node) then
751 -- Case of dump generated only
753 if Dump_Generated_Only then
754 Sprint_Node_Actual (Node);
756 -- Case of dump original only
758 elsif Dump_Original_Only then
759 Sprint_Node_Actual (Original_Node (Node));
761 -- Case of both being dumped
764 Sprint_Node_Actual (Original_Node (Node));
765 Write_Rewrite_Str ("<<<");
766 Sprint_Node_Actual (Node);
767 Write_Rewrite_Str (">>>");
771 Sprint_Node_Actual (Node);
775 ------------------------
776 -- Sprint_Node_Actual --
777 ------------------------
779 procedure Sprint_Node_Actual (Node : Node_Id) is
780 Save_Dump_Node : constant Node_Id := Dump_Node;
787 for J in 1 .. Paren_Count (Node) loop
788 Write_Str_With_Col_Check ("(");
791 -- Setup current dump node
795 if Nkind (Node) in N_Subexpr
796 and then Do_Range_Check (Node)
798 Write_Str_With_Col_Check ("{");
801 -- Select print circuit based on node kind
805 when N_Abort_Statement =>
806 Write_Indent_Str_Sloc ("abort ");
807 Sprint_Comma_List (Names (Node));
810 when N_Abortable_Part =>
812 Write_Str_Sloc ("abort ");
813 Sprint_Indented_List (Statements (Node));
815 when N_Abstract_Subprogram_Declaration =>
817 Sprint_Node (Specification (Node));
818 Write_Str_With_Col_Check (" is ");
819 Write_Str_Sloc ("abstract;");
821 when N_Accept_Alternative =>
822 Sprint_Node_List (Pragmas_Before (Node));
824 if Present (Condition (Node)) then
825 Write_Indent_Str ("when ");
826 Sprint_Node (Condition (Node));
831 Sprint_Node_Sloc (Accept_Statement (Node));
832 Sprint_Node_List (Statements (Node));
834 when N_Accept_Statement =>
835 Write_Indent_Str_Sloc ("accept ");
836 Write_Id (Entry_Direct_Name (Node));
838 if Present (Entry_Index (Node)) then
839 Write_Str_With_Col_Check (" (");
840 Sprint_Node (Entry_Index (Node));
844 Write_Param_Specs (Node);
846 if Present (Handled_Statement_Sequence (Node)) then
847 Write_Str_With_Col_Check (" do");
848 Sprint_Node (Handled_Statement_Sequence (Node));
849 Write_Indent_Str ("end ");
850 Write_Id (Entry_Direct_Name (Node));
855 when N_Access_Definition =>
859 if Present (Access_To_Subprogram_Definition (Node)) then
860 Sprint_Node (Access_To_Subprogram_Definition (Node));
864 if Null_Exclusion_Present (Node) then
865 Write_Str ("not null ");
868 Write_Str_With_Col_Check_Sloc ("access ");
870 if All_Present (Node) then
872 elsif Constant_Present (Node) then
873 Write_Str ("constant ");
876 Sprint_Node (Subtype_Mark (Node));
879 when N_Access_Function_Definition =>
883 if Null_Exclusion_Present (Node) then
884 Write_Str ("not null ");
887 Write_Str_With_Col_Check_Sloc ("access ");
889 if Protected_Present (Node) then
890 Write_Str_With_Col_Check ("protected ");
893 Write_Str_With_Col_Check ("function");
894 Write_Param_Specs (Node);
895 Write_Str_With_Col_Check (" return ");
896 Sprint_Node (Result_Definition (Node));
898 when N_Access_Procedure_Definition =>
902 if Null_Exclusion_Present (Node) then
903 Write_Str ("not null ");
906 Write_Str_With_Col_Check_Sloc ("access ");
908 if Protected_Present (Node) then
909 Write_Str_With_Col_Check ("protected ");
912 Write_Str_With_Col_Check ("procedure");
913 Write_Param_Specs (Node);
915 when N_Access_To_Object_Definition =>
916 Write_Str_With_Col_Check_Sloc ("access ");
918 if All_Present (Node) then
919 Write_Str_With_Col_Check ("all ");
920 elsif Constant_Present (Node) then
921 Write_Str_With_Col_Check ("constant ");
926 if Null_Exclusion_Present (Node) then
927 Write_Str ("not null ");
930 Sprint_Node (Subtype_Indication (Node));
933 if Null_Record_Present (Node) then
934 Write_Str_With_Col_Check_Sloc ("(null record)");
937 Write_Str_With_Col_Check_Sloc ("(");
939 if Present (Expressions (Node)) then
940 Sprint_Comma_List (Expressions (Node));
942 if Present (Component_Associations (Node))
943 and then not Is_Empty_List (Component_Associations (Node))
949 if Present (Component_Associations (Node))
950 and then not Is_Empty_List (Component_Associations (Node))
958 Nd := First (Component_Associations (Node));
966 if not Is_Rewrite_Insertion (Nd)
967 or else not Dump_Original_Only
981 Write_Str_With_Col_Check_Sloc ("new ");
985 if Null_Exclusion_Present (Node) then
986 Write_Str ("not null ");
989 Sprint_Node (Expression (Node));
991 if Present (Storage_Pool (Node)) then
992 Write_Str_With_Col_Check ("[storage_pool = ");
993 Sprint_Node (Storage_Pool (Node));
998 Sprint_Left_Opnd (Node);
999 Write_Str_Sloc (" and then ");
1000 Sprint_Right_Opnd (Node);
1003 Write_Indent_Str_Sloc ("for ");
1004 Write_Id (Identifier (Node));
1005 Write_Str_With_Col_Check (" use at ");
1006 Sprint_Node (Expression (Node));
1009 when N_Assignment_Statement =>
1011 Sprint_Node (Name (Node));
1012 Write_Str_Sloc (" := ");
1013 Sprint_Node (Expression (Node));
1016 when N_Asynchronous_Select =>
1017 Write_Indent_Str_Sloc ("select");
1019 Sprint_Node (Triggering_Alternative (Node));
1022 -- Note: let the printing of Abortable_Part handle outputting
1023 -- the ABORT keyword, so that the Sloc can be set correctly.
1025 Write_Indent_Str ("then ");
1026 Sprint_Node (Abortable_Part (Node));
1027 Write_Indent_Str ("end select;");
1029 when N_Attribute_Definition_Clause =>
1030 Write_Indent_Str_Sloc ("for ");
1031 Sprint_Node (Name (Node));
1033 Write_Name_With_Col_Check (Chars (Node));
1034 Write_Str_With_Col_Check (" use ");
1035 Sprint_Node (Expression (Node));
1038 when N_Attribute_Reference =>
1039 if Is_Procedure_Attribute_Name (Attribute_Name (Node)) then
1043 Sprint_Node (Prefix (Node));
1044 Write_Char_Sloc (''');
1045 Write_Name_With_Col_Check (Attribute_Name (Node));
1046 Sprint_Paren_Comma_List (Expressions (Node));
1048 if Is_Procedure_Attribute_Name (Attribute_Name (Node)) then
1052 when N_Block_Statement =>
1055 if Present (Identifier (Node))
1056 and then (not Has_Created_Identifier (Node)
1057 or else not Dump_Original_Only)
1059 Write_Rewrite_Str ("<<<");
1060 Write_Id (Identifier (Node));
1062 Write_Rewrite_Str (">>>");
1065 if Present (Declarations (Node)) then
1066 Write_Str_With_Col_Check_Sloc ("declare");
1067 Sprint_Indented_List (Declarations (Node));
1071 Write_Str_With_Col_Check_Sloc ("begin");
1072 Sprint_Node (Handled_Statement_Sequence (Node));
1073 Write_Indent_Str ("end");
1075 if Present (Identifier (Node))
1076 and then (not Has_Created_Identifier (Node)
1077 or else not Dump_Original_Only)
1079 Write_Rewrite_Str ("<<<");
1081 Write_Id (Identifier (Node));
1082 Write_Rewrite_Str (">>>");
1087 when N_Case_Expression =>
1092 Write_Str_With_Col_Check_Sloc ("(case ");
1093 Sprint_Node (Expression (Node));
1094 Write_Str_With_Col_Check (" is");
1096 Alt := First (Alternatives (Node));
1107 when N_Case_Expression_Alternative =>
1108 Write_Str_With_Col_Check (" when ");
1109 Sprint_Bar_List (Discrete_Choices (Node));
1111 Sprint_Node (Expression (Node));
1113 when N_Case_Statement =>
1114 Write_Indent_Str_Sloc ("case ");
1115 Sprint_Node (Expression (Node));
1117 Sprint_Indented_List (Alternatives (Node));
1118 Write_Indent_Str ("end case;");
1120 when N_Case_Statement_Alternative =>
1121 Write_Indent_Str_Sloc ("when ");
1122 Sprint_Bar_List (Discrete_Choices (Node));
1124 Sprint_Indented_List (Statements (Node));
1126 when N_Character_Literal =>
1127 if Column > Sprint_Line_Limit - 2 then
1128 Write_Indent_Str (" ");
1131 Write_Char_Sloc (''');
1132 Write_Char_Code (UI_To_CC (Char_Literal_Value (Node)));
1135 when N_Code_Statement =>
1138 Sprint_Node (Expression (Node));
1141 when N_Compilation_Unit =>
1142 Sprint_Node_List (Context_Items (Node));
1143 Sprint_Opt_Node_List (Declarations (Aux_Decls_Node (Node)));
1145 if Private_Present (Node) then
1146 Write_Indent_Str ("private ");
1150 Sprint_Node_Sloc (Unit (Node));
1152 if Present (Actions (Aux_Decls_Node (Node)))
1154 Present (Pragmas_After (Aux_Decls_Node (Node)))
1159 Sprint_Opt_Node_List (Actions (Aux_Decls_Node (Node)));
1160 Sprint_Opt_Node_List (Pragmas_After (Aux_Decls_Node (Node)));
1162 when N_Compilation_Unit_Aux =>
1163 null; -- nothing to do, never used, see above
1165 when N_Component_Association =>
1167 Sprint_Bar_List (Choices (Node));
1170 -- Ada 2005 (AI-287): Print the box if present
1172 if Box_Present (Node) then
1173 Write_Str_With_Col_Check ("<>");
1175 Sprint_Node (Expression (Node));
1178 when N_Component_Clause =>
1180 Sprint_Node (Component_Name (Node));
1181 Write_Str_Sloc (" at ");
1182 Sprint_Node (Position (Node));
1184 Write_Str_With_Col_Check ("range ");
1185 Sprint_Node (First_Bit (Node));
1187 Sprint_Node (Last_Bit (Node));
1190 when N_Component_Definition =>
1193 -- Ada 2005 (AI-230): Access definition components
1195 if Present (Access_Definition (Node)) then
1196 Sprint_Node (Access_Definition (Node));
1198 elsif Present (Subtype_Indication (Node)) then
1199 if Aliased_Present (Node) then
1200 Write_Str_With_Col_Check ("aliased ");
1203 -- Ada 2005 (AI-231)
1205 if Null_Exclusion_Present (Node) then
1206 Write_Str (" not null ");
1209 Sprint_Node (Subtype_Indication (Node));
1212 Write_Str (" ??? ");
1215 when N_Component_Declaration =>
1216 if Write_Indent_Identifiers_Sloc (Node) then
1218 Sprint_Node (Component_Definition (Node));
1220 if Present (Expression (Node)) then
1222 Sprint_Node (Expression (Node));
1228 when N_Component_List =>
1229 if Null_Present (Node) then
1231 Write_Indent_Str_Sloc ("null");
1237 Sprint_Indented_List (Component_Items (Node));
1238 Sprint_Node (Variant_Part (Node));
1241 when N_Conditional_Entry_Call =>
1242 Write_Indent_Str_Sloc ("select");
1244 Sprint_Node (Entry_Call_Alternative (Node));
1246 Write_Indent_Str ("else");
1247 Sprint_Indented_List (Else_Statements (Node));
1248 Write_Indent_Str ("end select;");
1250 when N_Conditional_Expression =>
1252 Condition : constant Node_Id := First (Expressions (Node));
1253 Then_Expr : constant Node_Id := Next (Condition);
1256 Write_Str_With_Col_Check_Sloc ("(if ");
1257 Sprint_Node (Condition);
1258 Write_Str_With_Col_Check (" then ");
1260 -- Defense against junk here!
1262 if Present (Then_Expr) then
1263 Sprint_Node (Then_Expr);
1264 Write_Str_With_Col_Check (" else ");
1265 Sprint_Node (Next (Then_Expr));
1271 when N_Constrained_Array_Definition =>
1272 Write_Str_With_Col_Check_Sloc ("array ");
1273 Sprint_Paren_Comma_List (Discrete_Subtype_Definitions (Node));
1276 Sprint_Node (Component_Definition (Node));
1278 when N_Decimal_Fixed_Point_Definition =>
1279 Write_Str_With_Col_Check_Sloc (" delta ");
1280 Sprint_Node (Delta_Expression (Node));
1281 Write_Str_With_Col_Check ("digits ");
1282 Sprint_Node (Digits_Expression (Node));
1283 Sprint_Opt_Node (Real_Range_Specification (Node));
1285 when N_Defining_Character_Literal =>
1286 Write_Name_With_Col_Check_Sloc (Chars (Node));
1288 when N_Defining_Identifier =>
1292 when N_Defining_Operator_Symbol =>
1293 Write_Name_With_Col_Check_Sloc (Chars (Node));
1295 when N_Defining_Program_Unit_Name =>
1297 Sprint_Node (Name (Node));
1299 Write_Id (Defining_Identifier (Node));
1301 when N_Delay_Alternative =>
1302 Sprint_Node_List (Pragmas_Before (Node));
1304 if Present (Condition (Node)) then
1306 Write_Str_With_Col_Check ("when ");
1307 Sprint_Node (Condition (Node));
1312 Sprint_Node_Sloc (Delay_Statement (Node));
1313 Sprint_Node_List (Statements (Node));
1315 when N_Delay_Relative_Statement =>
1316 Write_Indent_Str_Sloc ("delay ");
1317 Sprint_Node (Expression (Node));
1320 when N_Delay_Until_Statement =>
1321 Write_Indent_Str_Sloc ("delay until ");
1322 Sprint_Node (Expression (Node));
1325 when N_Delta_Constraint =>
1326 Write_Str_With_Col_Check_Sloc ("delta ");
1327 Sprint_Node (Delta_Expression (Node));
1328 Sprint_Opt_Node (Range_Constraint (Node));
1330 when N_Derived_Type_Definition =>
1331 if Abstract_Present (Node) then
1332 Write_Str_With_Col_Check ("abstract ");
1335 Write_Str_With_Col_Check_Sloc ("new ");
1337 -- Ada 2005 (AI-231)
1339 if Null_Exclusion_Present (Node) then
1340 Write_Str_With_Col_Check ("not null ");
1343 Sprint_Node (Subtype_Indication (Node));
1345 if Present (Interface_List (Node)) then
1346 Write_Str_With_Col_Check (" and ");
1347 Sprint_And_List (Interface_List (Node));
1348 Write_Str_With_Col_Check (" with ");
1351 if Present (Record_Extension_Part (Node)) then
1352 if No (Interface_List (Node)) then
1353 Write_Str_With_Col_Check (" with ");
1356 Sprint_Node (Record_Extension_Part (Node));
1359 when N_Designator =>
1360 Sprint_Node (Name (Node));
1361 Write_Char_Sloc ('.');
1362 Write_Id (Identifier (Node));
1364 when N_Digits_Constraint =>
1365 Write_Str_With_Col_Check_Sloc ("digits ");
1366 Sprint_Node (Digits_Expression (Node));
1367 Sprint_Opt_Node (Range_Constraint (Node));
1369 when N_Discriminant_Association =>
1372 if Present (Selector_Names (Node)) then
1373 Sprint_Bar_List (Selector_Names (Node));
1378 Sprint_Node (Expression (Node));
1380 when N_Discriminant_Specification =>
1383 if Write_Identifiers (Node) then
1386 if Null_Exclusion_Present (Node) then
1387 Write_Str ("not null ");
1390 Sprint_Node (Discriminant_Type (Node));
1392 if Present (Expression (Node)) then
1394 Sprint_Node (Expression (Node));
1400 when N_Elsif_Part =>
1401 Write_Indent_Str_Sloc ("elsif ");
1402 Sprint_Node (Condition (Node));
1403 Write_Str_With_Col_Check (" then");
1404 Sprint_Indented_List (Then_Statements (Node));
1409 when N_Entry_Body =>
1410 Write_Indent_Str_Sloc ("entry ");
1411 Write_Id (Defining_Identifier (Node));
1412 Sprint_Node (Entry_Body_Formal_Part (Node));
1413 Write_Str_With_Col_Check (" is");
1414 Sprint_Indented_List (Declarations (Node));
1415 Write_Indent_Str ("begin");
1416 Sprint_Node (Handled_Statement_Sequence (Node));
1417 Write_Indent_Str ("end ");
1418 Write_Id (Defining_Identifier (Node));
1421 when N_Entry_Body_Formal_Part =>
1422 if Present (Entry_Index_Specification (Node)) then
1423 Write_Str_With_Col_Check_Sloc (" (");
1424 Sprint_Node (Entry_Index_Specification (Node));
1428 Write_Param_Specs (Node);
1429 Write_Str_With_Col_Check_Sloc (" when ");
1430 Sprint_Node (Condition (Node));
1432 when N_Entry_Call_Alternative =>
1433 Sprint_Node_List (Pragmas_Before (Node));
1434 Sprint_Node_Sloc (Entry_Call_Statement (Node));
1435 Sprint_Node_List (Statements (Node));
1437 when N_Entry_Call_Statement =>
1439 Sprint_Node_Sloc (Name (Node));
1440 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
1443 when N_Entry_Declaration =>
1444 Write_Indent_Str_Sloc ("entry ");
1445 Write_Id (Defining_Identifier (Node));
1447 if Present (Discrete_Subtype_Definition (Node)) then
1448 Write_Str_With_Col_Check (" (");
1449 Sprint_Node (Discrete_Subtype_Definition (Node));
1453 Write_Param_Specs (Node);
1456 when N_Entry_Index_Specification =>
1457 Write_Str_With_Col_Check_Sloc ("for ");
1458 Write_Id (Defining_Identifier (Node));
1459 Write_Str_With_Col_Check (" in ");
1460 Sprint_Node (Discrete_Subtype_Definition (Node));
1462 when N_Enumeration_Representation_Clause =>
1463 Write_Indent_Str_Sloc ("for ");
1464 Write_Id (Identifier (Node));
1465 Write_Str_With_Col_Check (" use ");
1466 Sprint_Node (Array_Aggregate (Node));
1469 when N_Enumeration_Type_Definition =>
1472 -- Skip attempt to print Literals field if it's not there and
1473 -- we are in package Standard (case of Character, which is
1474 -- handled specially (without an explicit literals list).
1476 if Sloc (Node) > Standard_Location
1477 or else Present (Literals (Node))
1479 Sprint_Paren_Comma_List (Literals (Node));
1483 Write_Str_With_Col_Check_Sloc ("<error>");
1485 when N_Exception_Declaration =>
1486 if Write_Indent_Identifiers (Node) then
1487 Write_Str_With_Col_Check (" : ");
1489 if Is_Statically_Allocated (Defining_Identifier (Node)) then
1490 Write_Str_With_Col_Check ("static ");
1493 Write_Str_Sloc ("exception");
1495 if Present (Expression (Node)) then
1497 Sprint_Node (Expression (Node));
1503 when N_Exception_Handler =>
1504 Write_Indent_Str_Sloc ("when ");
1506 if Present (Choice_Parameter (Node)) then
1507 Sprint_Node (Choice_Parameter (Node));
1511 Sprint_Bar_List (Exception_Choices (Node));
1513 Sprint_Indented_List (Statements (Node));
1515 when N_Exception_Renaming_Declaration =>
1518 Sprint_Node (Defining_Identifier (Node));
1519 Write_Str_With_Col_Check (" : exception renames ");
1520 Sprint_Node (Name (Node));
1523 when N_Exit_Statement =>
1524 Write_Indent_Str_Sloc ("exit");
1525 Sprint_Opt_Node (Name (Node));
1527 if Present (Condition (Node)) then
1528 Write_Str_With_Col_Check (" when ");
1529 Sprint_Node (Condition (Node));
1534 when N_Expanded_Name =>
1535 Sprint_Node (Prefix (Node));
1536 Write_Char_Sloc ('.');
1537 Sprint_Node (Selector_Name (Node));
1539 when N_Explicit_Dereference =>
1540 Sprint_Node (Prefix (Node));
1541 Write_Char_Sloc ('.');
1542 Write_Str_Sloc ("all");
1544 when N_Expression_With_Actions =>
1546 Write_Indent_Str_Sloc ("do ");
1548 Sprint_Node_List (Actions (Node));
1551 Write_Str_With_Col_Check_Sloc ("in ");
1552 Sprint_Node (Expression (Node));
1553 Write_Str_With_Col_Check (" end");
1557 when N_Extended_Return_Statement =>
1558 Write_Indent_Str_Sloc ("return ");
1559 Sprint_Node_List (Return_Object_Declarations (Node));
1561 if Present (Handled_Statement_Sequence (Node)) then
1562 Write_Str_With_Col_Check (" do");
1563 Sprint_Node (Handled_Statement_Sequence (Node));
1564 Write_Indent_Str ("end return;");
1566 Write_Indent_Str (";");
1569 when N_Extension_Aggregate =>
1570 Write_Str_With_Col_Check_Sloc ("(");
1571 Sprint_Node (Ancestor_Part (Node));
1572 Write_Str_With_Col_Check (" with ");
1574 if Null_Record_Present (Node) then
1575 Write_Str_With_Col_Check ("null record");
1577 if Present (Expressions (Node)) then
1578 Sprint_Comma_List (Expressions (Node));
1580 if Present (Component_Associations (Node)) then
1585 if Present (Component_Associations (Node)) then
1586 Sprint_Comma_List (Component_Associations (Node));
1592 when N_Floating_Point_Definition =>
1593 Write_Str_With_Col_Check_Sloc ("digits ");
1594 Sprint_Node (Digits_Expression (Node));
1595 Sprint_Opt_Node (Real_Range_Specification (Node));
1597 when N_Formal_Decimal_Fixed_Point_Definition =>
1598 Write_Str_With_Col_Check_Sloc ("delta <> digits <>");
1600 when N_Formal_Derived_Type_Definition =>
1601 Write_Str_With_Col_Check_Sloc ("new ");
1602 Sprint_Node (Subtype_Mark (Node));
1604 if Present (Interface_List (Node)) then
1605 Write_Str_With_Col_Check (" and ");
1606 Sprint_And_List (Interface_List (Node));
1609 if Private_Present (Node) then
1610 Write_Str_With_Col_Check (" with private");
1613 when N_Formal_Abstract_Subprogram_Declaration =>
1614 Write_Indent_Str_Sloc ("with ");
1615 Sprint_Node (Specification (Node));
1617 Write_Str_With_Col_Check (" is abstract");
1619 if Box_Present (Node) then
1620 Write_Str_With_Col_Check (" <>");
1621 elsif Present (Default_Name (Node)) then
1622 Write_Str_With_Col_Check (" ");
1623 Sprint_Node (Default_Name (Node));
1628 when N_Formal_Concrete_Subprogram_Declaration =>
1629 Write_Indent_Str_Sloc ("with ");
1630 Sprint_Node (Specification (Node));
1632 if Box_Present (Node) then
1633 Write_Str_With_Col_Check (" is <>");
1634 elsif Present (Default_Name (Node)) then
1635 Write_Str_With_Col_Check (" is ");
1636 Sprint_Node (Default_Name (Node));
1641 when N_Formal_Discrete_Type_Definition =>
1642 Write_Str_With_Col_Check_Sloc ("<>");
1644 when N_Formal_Floating_Point_Definition =>
1645 Write_Str_With_Col_Check_Sloc ("digits <>");
1647 when N_Formal_Modular_Type_Definition =>
1648 Write_Str_With_Col_Check_Sloc ("mod <>");
1650 when N_Formal_Object_Declaration =>
1653 if Write_Indent_Identifiers (Node) then
1656 if In_Present (Node) then
1657 Write_Str_With_Col_Check ("in ");
1660 if Out_Present (Node) then
1661 Write_Str_With_Col_Check ("out ");
1664 if Present (Subtype_Mark (Node)) then
1666 -- Ada 2005 (AI-423): Formal object with null exclusion
1668 if Null_Exclusion_Present (Node) then
1669 Write_Str ("not null ");
1672 Sprint_Node (Subtype_Mark (Node));
1674 -- Ada 2005 (AI-423): Formal object with access definition
1677 pragma Assert (Present (Access_Definition (Node)));
1679 Sprint_Node (Access_Definition (Node));
1682 if Present (Default_Expression (Node)) then
1684 Sprint_Node (Default_Expression (Node));
1690 when N_Formal_Ordinary_Fixed_Point_Definition =>
1691 Write_Str_With_Col_Check_Sloc ("delta <>");
1693 when N_Formal_Package_Declaration =>
1694 Write_Indent_Str_Sloc ("with package ");
1695 Write_Id (Defining_Identifier (Node));
1696 Write_Str_With_Col_Check (" is new ");
1697 Sprint_Node (Name (Node));
1698 Write_Str_With_Col_Check (" (<>);");
1700 when N_Formal_Private_Type_Definition =>
1701 if Abstract_Present (Node) then
1702 Write_Str_With_Col_Check ("abstract ");
1705 if Tagged_Present (Node) then
1706 Write_Str_With_Col_Check ("tagged ");
1709 if Limited_Present (Node) then
1710 Write_Str_With_Col_Check ("limited ");
1713 Write_Str_With_Col_Check_Sloc ("private");
1715 when N_Formal_Signed_Integer_Type_Definition =>
1716 Write_Str_With_Col_Check_Sloc ("range <>");
1718 when N_Formal_Type_Declaration =>
1719 Write_Indent_Str_Sloc ("type ");
1720 Write_Id (Defining_Identifier (Node));
1722 if Present (Discriminant_Specifications (Node)) then
1723 Write_Discr_Specs (Node);
1724 elsif Unknown_Discriminants_Present (Node) then
1725 Write_Str_With_Col_Check ("(<>)");
1728 Write_Str_With_Col_Check (" is ");
1729 Sprint_Node (Formal_Type_Definition (Node));
1732 when N_Free_Statement =>
1733 Write_Indent_Str_Sloc ("free ");
1734 Sprint_Node (Expression (Node));
1737 when N_Freeze_Entity =>
1738 if Dump_Original_Only then
1741 elsif Present (Actions (Node)) or else Dump_Freeze_Null then
1743 Write_Rewrite_Str ("<<<");
1744 Write_Str_With_Col_Check_Sloc ("freeze ");
1745 Write_Id (Entity (Node));
1748 if No (Actions (Node)) then
1752 -- Output freeze actions. We increment Freeze_Indent during
1753 -- this output to avoid generating extra blank lines before
1754 -- any procedures included in the freeze actions.
1756 Freeze_Indent := Freeze_Indent + 1;
1757 Sprint_Indented_List (Actions (Node));
1758 Freeze_Indent := Freeze_Indent - 1;
1759 Write_Indent_Str ("]");
1762 Write_Rewrite_Str (">>>");
1765 when N_Full_Type_Declaration =>
1766 Write_Indent_Str_Sloc ("type ");
1767 Sprint_Node (Defining_Identifier (Node));
1768 Write_Discr_Specs (Node);
1769 Write_Str_With_Col_Check (" is ");
1770 Sprint_Node (Type_Definition (Node));
1773 when N_Function_Call =>
1775 Write_Subprogram_Name (Name (Node));
1776 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
1778 when N_Function_Instantiation =>
1779 Write_Indent_Str_Sloc ("function ");
1780 Sprint_Node (Defining_Unit_Name (Node));
1781 Write_Str_With_Col_Check (" is new ");
1782 Sprint_Node (Name (Node));
1783 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
1786 when N_Function_Specification =>
1787 Write_Str_With_Col_Check_Sloc ("function ");
1788 Sprint_Node (Defining_Unit_Name (Node));
1789 Write_Param_Specs (Node);
1790 Write_Str_With_Col_Check (" return ");
1792 -- Ada 2005 (AI-231)
1794 if Nkind (Result_Definition (Node)) /= N_Access_Definition
1795 and then Null_Exclusion_Present (Node)
1797 Write_Str (" not null ");
1800 Sprint_Node (Result_Definition (Node));
1802 when N_Generic_Association =>
1805 if Present (Selector_Name (Node)) then
1806 Sprint_Node (Selector_Name (Node));
1810 Sprint_Node (Explicit_Generic_Actual_Parameter (Node));
1812 when N_Generic_Function_Renaming_Declaration =>
1813 Write_Indent_Str_Sloc ("generic function ");
1814 Sprint_Node (Defining_Unit_Name (Node));
1815 Write_Str_With_Col_Check (" renames ");
1816 Sprint_Node (Name (Node));
1819 when N_Generic_Package_Declaration =>
1821 Write_Indent_Str_Sloc ("generic ");
1822 Sprint_Indented_List (Generic_Formal_Declarations (Node));
1824 Sprint_Node (Specification (Node));
1827 when N_Generic_Package_Renaming_Declaration =>
1828 Write_Indent_Str_Sloc ("generic package ");
1829 Sprint_Node (Defining_Unit_Name (Node));
1830 Write_Str_With_Col_Check (" renames ");
1831 Sprint_Node (Name (Node));
1834 when N_Generic_Procedure_Renaming_Declaration =>
1835 Write_Indent_Str_Sloc ("generic procedure ");
1836 Sprint_Node (Defining_Unit_Name (Node));
1837 Write_Str_With_Col_Check (" renames ");
1838 Sprint_Node (Name (Node));
1841 when N_Generic_Subprogram_Declaration =>
1843 Write_Indent_Str_Sloc ("generic ");
1844 Sprint_Indented_List (Generic_Formal_Declarations (Node));
1846 Sprint_Node (Specification (Node));
1849 when N_Goto_Statement =>
1850 Write_Indent_Str_Sloc ("goto ");
1851 Sprint_Node (Name (Node));
1854 if Nkind (Next (Node)) = N_Label then
1858 when N_Handled_Sequence_Of_Statements =>
1860 Sprint_Indented_List (Statements (Node));
1862 if Present (Exception_Handlers (Node)) then
1863 Write_Indent_Str ("exception");
1865 Sprint_Node_List (Exception_Handlers (Node));
1869 if Present (At_End_Proc (Node)) then
1870 Write_Indent_Str ("at end");
1873 Sprint_Node (At_End_Proc (Node));
1878 when N_Identifier =>
1882 when N_If_Statement =>
1883 Write_Indent_Str_Sloc ("if ");
1884 Sprint_Node (Condition (Node));
1885 Write_Str_With_Col_Check (" then");
1886 Sprint_Indented_List (Then_Statements (Node));
1887 Sprint_Opt_Node_List (Elsif_Parts (Node));
1889 if Present (Else_Statements (Node)) then
1890 Write_Indent_Str ("else");
1891 Sprint_Indented_List (Else_Statements (Node));
1894 Write_Indent_Str ("end if;");
1896 when N_Implicit_Label_Declaration =>
1897 if not Dump_Original_Only then
1899 Write_Rewrite_Str ("<<<");
1901 Write_Id (Defining_Identifier (Node));
1903 Write_Str_With_Col_Check ("label");
1904 Write_Rewrite_Str (">>>");
1908 Sprint_Left_Opnd (Node);
1909 Write_Str_Sloc (" in ");
1911 if Present (Right_Opnd (Node)) then
1912 Sprint_Right_Opnd (Node);
1914 Sprint_Bar_List (Alternatives (Node));
1917 when N_Incomplete_Type_Declaration =>
1918 Write_Indent_Str_Sloc ("type ");
1919 Write_Id (Defining_Identifier (Node));
1921 if Present (Discriminant_Specifications (Node)) then
1922 Write_Discr_Specs (Node);
1923 elsif Unknown_Discriminants_Present (Node) then
1924 Write_Str_With_Col_Check ("(<>)");
1929 when N_Index_Or_Discriminant_Constraint =>
1931 Sprint_Paren_Comma_List (Constraints (Node));
1933 when N_Indexed_Component =>
1934 Sprint_Node_Sloc (Prefix (Node));
1935 Sprint_Opt_Paren_Comma_List (Expressions (Node));
1937 when N_Integer_Literal =>
1938 if Print_In_Hex (Node) then
1939 Write_Uint_With_Col_Check_Sloc (Intval (Node), Hex);
1941 Write_Uint_With_Col_Check_Sloc (Intval (Node), Auto);
1944 when N_Iteration_Scheme =>
1945 if Present (Condition (Node)) then
1946 Write_Str_With_Col_Check_Sloc ("while ");
1947 Sprint_Node (Condition (Node));
1949 Write_Str_With_Col_Check_Sloc ("for ");
1950 Sprint_Node (Loop_Parameter_Specification (Node));
1955 when N_Itype_Reference =>
1956 Write_Indent_Str_Sloc ("reference ");
1957 Write_Id (Itype (Node));
1960 Write_Indent_Str_Sloc ("<<");
1961 Write_Id (Identifier (Node));
1964 when N_Loop_Parameter_Specification =>
1966 Write_Id (Defining_Identifier (Node));
1967 Write_Str_With_Col_Check (" in ");
1969 if Reverse_Present (Node) then
1970 Write_Str_With_Col_Check ("reverse ");
1973 Sprint_Node (Discrete_Subtype_Definition (Node));
1975 when N_Loop_Statement =>
1978 if Present (Identifier (Node))
1979 and then (not Has_Created_Identifier (Node)
1980 or else not Dump_Original_Only)
1982 Write_Rewrite_Str ("<<<");
1983 Write_Id (Identifier (Node));
1985 Write_Rewrite_Str (">>>");
1986 Sprint_Node (Iteration_Scheme (Node));
1987 Write_Str_With_Col_Check_Sloc ("loop");
1988 Sprint_Indented_List (Statements (Node));
1989 Write_Indent_Str ("end loop ");
1990 Write_Rewrite_Str ("<<<");
1991 Write_Id (Identifier (Node));
1992 Write_Rewrite_Str (">>>");
1996 Sprint_Node (Iteration_Scheme (Node));
1997 Write_Str_With_Col_Check_Sloc ("loop");
1998 Sprint_Indented_List (Statements (Node));
1999 Write_Indent_Str ("end loop;");
2002 when N_Mod_Clause =>
2003 Sprint_Node_List (Pragmas_Before (Node));
2004 Write_Str_With_Col_Check_Sloc ("at mod ");
2005 Sprint_Node (Expression (Node));
2007 when N_Modular_Type_Definition =>
2008 Write_Str_With_Col_Check_Sloc ("mod ");
2009 Sprint_Node (Expression (Node));
2012 Sprint_Left_Opnd (Node);
2013 Write_Str_Sloc (" not in ");
2015 if Present (Right_Opnd (Node)) then
2016 Sprint_Right_Opnd (Node);
2018 Sprint_Bar_List (Alternatives (Node));
2022 Write_Str_With_Col_Check_Sloc ("null");
2024 when N_Null_Statement =>
2025 if Comes_From_Source (Node)
2026 or else Dump_Freeze_Null
2027 or else not Is_List_Member (Node)
2028 or else (No (Prev (Node)) and then No (Next (Node)))
2030 Write_Indent_Str_Sloc ("null;");
2033 when N_Number_Declaration =>
2036 if Write_Indent_Identifiers (Node) then
2037 Write_Str_With_Col_Check (" : constant ");
2039 Sprint_Node (Expression (Node));
2043 when N_Object_Declaration =>
2046 if Write_Indent_Identifiers (Node) then
2048 Def_Id : constant Entity_Id := Defining_Identifier (Node);
2051 Write_Str_With_Col_Check (" : ");
2053 if Is_Statically_Allocated (Def_Id) then
2054 Write_Str_With_Col_Check ("static ");
2057 if Aliased_Present (Node) then
2058 Write_Str_With_Col_Check ("aliased ");
2061 if Constant_Present (Node) then
2062 Write_Str_With_Col_Check ("constant ");
2065 -- Ada 2005 (AI-231)
2067 if Null_Exclusion_Present (Node) then
2068 Write_Str_With_Col_Check ("not null ");
2071 Sprint_Node (Object_Definition (Node));
2073 if Present (Expression (Node)) then
2075 Sprint_Node (Expression (Node));
2080 -- Handle implicit importation and implicit exportation of
2081 -- object declarations:
2082 -- $pragma import (Convention_Id, Def_Id, "...");
2083 -- $pragma export (Convention_Id, Def_Id, "...");
2085 if Is_Internal (Def_Id)
2086 and then Present (Interface_Name (Def_Id))
2088 Write_Indent_Str_Sloc ("$pragma ");
2090 if Is_Imported (Def_Id) then
2091 Write_Str ("import (");
2093 else pragma Assert (Is_Exported (Def_Id));
2094 Write_Str ("export (");
2098 Prefix : constant String := "Convention_";
2099 S : constant String := Convention (Def_Id)'Img;
2102 Name_Len := S'Last - Prefix'Last;
2103 Name_Buffer (1 .. Name_Len) :=
2104 S (Prefix'Last + 1 .. S'Last);
2105 Set_Casing (All_Lower_Case);
2106 Write_Str (Name_Buffer (1 .. Name_Len));
2112 Write_String_Table_Entry
2113 (Strval (Interface_Name (Def_Id)));
2119 when N_Object_Renaming_Declaration =>
2122 Sprint_Node (Defining_Identifier (Node));
2125 -- Ada 2005 (AI-230): Access renamings
2127 if Present (Access_Definition (Node)) then
2128 Sprint_Node (Access_Definition (Node));
2130 elsif Present (Subtype_Mark (Node)) then
2132 -- Ada 2005 (AI-423): Object renaming with a null exclusion
2134 if Null_Exclusion_Present (Node) then
2135 Write_Str ("not null ");
2138 Sprint_Node (Subtype_Mark (Node));
2141 Write_Str (" ??? ");
2144 Write_Str_With_Col_Check (" renames ");
2145 Sprint_Node (Name (Node));
2149 Write_Operator (Node, "abs ");
2150 Sprint_Right_Opnd (Node);
2153 Sprint_Left_Opnd (Node);
2154 Write_Operator (Node, " + ");
2155 Sprint_Right_Opnd (Node);
2158 Sprint_Left_Opnd (Node);
2159 Write_Operator (Node, " and ");
2160 Sprint_Right_Opnd (Node);
2163 Sprint_Left_Opnd (Node);
2164 Write_Operator (Node, " & ");
2165 Sprint_Right_Opnd (Node);
2168 Sprint_Left_Opnd (Node);
2170 Process_TFAI_RR_Flags (Node);
2171 Write_Operator (Node, "/ ");
2172 Sprint_Right_Opnd (Node);
2175 Sprint_Left_Opnd (Node);
2176 Write_Operator (Node, " = ");
2177 Sprint_Right_Opnd (Node);
2180 Sprint_Left_Opnd (Node);
2181 Write_Operator (Node, " ** ");
2182 Sprint_Right_Opnd (Node);
2185 Sprint_Left_Opnd (Node);
2186 Write_Operator (Node, " >= ");
2187 Sprint_Right_Opnd (Node);
2190 Sprint_Left_Opnd (Node);
2191 Write_Operator (Node, " > ");
2192 Sprint_Right_Opnd (Node);
2195 Sprint_Left_Opnd (Node);
2196 Write_Operator (Node, " <= ");
2197 Sprint_Right_Opnd (Node);
2200 Sprint_Left_Opnd (Node);
2201 Write_Operator (Node, " < ");
2202 Sprint_Right_Opnd (Node);
2205 Write_Operator (Node, "-");
2206 Sprint_Right_Opnd (Node);
2209 Sprint_Left_Opnd (Node);
2211 if Treat_Fixed_As_Integer (Node) then
2215 Write_Operator (Node, " mod ");
2216 Sprint_Right_Opnd (Node);
2218 when N_Op_Multiply =>
2219 Sprint_Left_Opnd (Node);
2221 Process_TFAI_RR_Flags (Node);
2222 Write_Operator (Node, "* ");
2223 Sprint_Right_Opnd (Node);
2226 Sprint_Left_Opnd (Node);
2227 Write_Operator (Node, " /= ");
2228 Sprint_Right_Opnd (Node);
2231 Write_Operator (Node, "not ");
2232 Sprint_Right_Opnd (Node);
2235 Sprint_Left_Opnd (Node);
2236 Write_Operator (Node, " or ");
2237 Sprint_Right_Opnd (Node);
2240 Write_Operator (Node, "+");
2241 Sprint_Right_Opnd (Node);
2244 Sprint_Left_Opnd (Node);
2246 if Treat_Fixed_As_Integer (Node) then
2250 Write_Operator (Node, " rem ");
2251 Sprint_Right_Opnd (Node);
2257 Write_Str_With_Col_Check ("(");
2258 Sprint_Node (Left_Opnd (Node));
2260 Sprint_Node (Right_Opnd (Node));
2263 when N_Op_Subtract =>
2264 Sprint_Left_Opnd (Node);
2265 Write_Operator (Node, " - ");
2266 Sprint_Right_Opnd (Node);
2269 Sprint_Left_Opnd (Node);
2270 Write_Operator (Node, " xor ");
2271 Sprint_Right_Opnd (Node);
2273 when N_Operator_Symbol =>
2274 Write_Name_With_Col_Check_Sloc (Chars (Node));
2276 when N_Ordinary_Fixed_Point_Definition =>
2277 Write_Str_With_Col_Check_Sloc ("delta ");
2278 Sprint_Node (Delta_Expression (Node));
2279 Sprint_Opt_Node (Real_Range_Specification (Node));
2282 Sprint_Left_Opnd (Node);
2283 Write_Str_Sloc (" or else ");
2284 Sprint_Right_Opnd (Node);
2286 when N_Others_Choice =>
2287 if All_Others (Node) then
2288 Write_Str_With_Col_Check ("all ");
2291 Write_Str_With_Col_Check_Sloc ("others");
2293 when N_Package_Body =>
2295 Write_Indent_Str_Sloc ("package body ");
2296 Sprint_Node (Defining_Unit_Name (Node));
2298 Sprint_Indented_List (Declarations (Node));
2300 if Present (Handled_Statement_Sequence (Node)) then
2301 Write_Indent_Str ("begin");
2302 Sprint_Node (Handled_Statement_Sequence (Node));
2305 Write_Indent_Str ("end ");
2307 (Handled_Statement_Sequence (Node), Defining_Unit_Name (Node));
2310 when N_Package_Body_Stub =>
2311 Write_Indent_Str_Sloc ("package body ");
2312 Sprint_Node (Defining_Identifier (Node));
2313 Write_Str_With_Col_Check (" is separate;");
2315 when N_Package_Declaration =>
2318 Sprint_Node_Sloc (Specification (Node));
2321 when N_Package_Instantiation =>
2323 Write_Indent_Str_Sloc ("package ");
2324 Sprint_Node (Defining_Unit_Name (Node));
2325 Write_Str (" is new ");
2326 Sprint_Node (Name (Node));
2327 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
2330 when N_Package_Renaming_Declaration =>
2331 Write_Indent_Str_Sloc ("package ");
2332 Sprint_Node (Defining_Unit_Name (Node));
2333 Write_Str_With_Col_Check (" renames ");
2334 Sprint_Node (Name (Node));
2337 when N_Package_Specification =>
2338 Write_Str_With_Col_Check_Sloc ("package ");
2339 Sprint_Node (Defining_Unit_Name (Node));
2341 Sprint_Indented_List (Visible_Declarations (Node));
2343 if Present (Private_Declarations (Node)) then
2344 Write_Indent_Str ("private");
2345 Sprint_Indented_List (Private_Declarations (Node));
2348 Write_Indent_Str ("end ");
2349 Sprint_Node (Defining_Unit_Name (Node));
2351 when N_Parameter_Association =>
2352 Sprint_Node_Sloc (Selector_Name (Node));
2354 Sprint_Node (Explicit_Actual_Parameter (Node));
2356 when N_Parameter_Specification =>
2359 if Write_Identifiers (Node) then
2362 if In_Present (Node) then
2363 Write_Str_With_Col_Check ("in ");
2366 if Out_Present (Node) then
2367 Write_Str_With_Col_Check ("out ");
2370 -- Ada 2005 (AI-231): Parameter specification may carry null
2371 -- exclusion. Do not print it now if this is an access formal,
2372 -- it is emitted when the access definition is displayed.
2374 if Null_Exclusion_Present (Node)
2375 and then Nkind (Parameter_Type (Node))
2376 /= N_Access_Definition
2378 Write_Str ("not null ");
2381 Sprint_Node (Parameter_Type (Node));
2383 if Present (Expression (Node)) then
2385 Sprint_Node (Expression (Node));
2391 when N_Pop_Constraint_Error_Label =>
2392 Write_Indent_Str ("%pop_constraint_error_label");
2394 when N_Pop_Program_Error_Label =>
2395 Write_Indent_Str ("%pop_program_error_label");
2397 when N_Pop_Storage_Error_Label =>
2398 Write_Indent_Str ("%pop_storage_error_label");
2400 when N_Push_Constraint_Error_Label =>
2401 Write_Indent_Str ("%push_constraint_error_label (");
2403 if Present (Exception_Label (Node)) then
2404 Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2409 when N_Push_Program_Error_Label =>
2410 Write_Indent_Str ("%push_program_error_label (");
2412 if Present (Exception_Label (Node)) then
2413 Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2418 when N_Push_Storage_Error_Label =>
2419 Write_Indent_Str ("%push_storage_error_label (");
2421 if Present (Exception_Label (Node)) then
2422 Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2428 Write_Indent_Str_Sloc ("pragma ");
2429 Write_Name_With_Col_Check (Pragma_Name (Node));
2431 if Present (Pragma_Argument_Associations (Node)) then
2432 Sprint_Opt_Paren_Comma_List
2433 (Pragma_Argument_Associations (Node));
2438 when N_Pragma_Argument_Association =>
2441 if Chars (Node) /= No_Name then
2442 Write_Name_With_Col_Check (Chars (Node));
2446 Sprint_Node (Expression (Node));
2448 when N_Private_Type_Declaration =>
2449 Write_Indent_Str_Sloc ("type ");
2450 Write_Id (Defining_Identifier (Node));
2452 if Present (Discriminant_Specifications (Node)) then
2453 Write_Discr_Specs (Node);
2454 elsif Unknown_Discriminants_Present (Node) then
2455 Write_Str_With_Col_Check ("(<>)");
2460 if Tagged_Present (Node) then
2461 Write_Str_With_Col_Check ("tagged ");
2464 if Limited_Present (Node) then
2465 Write_Str_With_Col_Check ("limited ");
2468 Write_Str_With_Col_Check ("private;");
2470 when N_Private_Extension_Declaration =>
2471 Write_Indent_Str_Sloc ("type ");
2472 Write_Id (Defining_Identifier (Node));
2474 if Present (Discriminant_Specifications (Node)) then
2475 Write_Discr_Specs (Node);
2476 elsif Unknown_Discriminants_Present (Node) then
2477 Write_Str_With_Col_Check ("(<>)");
2480 Write_Str_With_Col_Check (" is new ");
2481 Sprint_Node (Subtype_Indication (Node));
2483 if Present (Interface_List (Node)) then
2484 Write_Str_With_Col_Check (" and ");
2485 Sprint_And_List (Interface_List (Node));
2488 Write_Str_With_Col_Check (" with private;");
2490 when N_Procedure_Call_Statement =>
2493 Write_Subprogram_Name (Name (Node));
2494 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
2497 when N_Procedure_Instantiation =>
2498 Write_Indent_Str_Sloc ("procedure ");
2499 Sprint_Node (Defining_Unit_Name (Node));
2500 Write_Str_With_Col_Check (" is new ");
2501 Sprint_Node (Name (Node));
2502 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
2505 when N_Procedure_Specification =>
2506 Write_Str_With_Col_Check_Sloc ("procedure ");
2507 Sprint_Node (Defining_Unit_Name (Node));
2508 Write_Param_Specs (Node);
2510 when N_Protected_Body =>
2511 Write_Indent_Str_Sloc ("protected body ");
2512 Write_Id (Defining_Identifier (Node));
2514 Sprint_Indented_List (Declarations (Node));
2515 Write_Indent_Str ("end ");
2516 Write_Id (Defining_Identifier (Node));
2519 when N_Protected_Body_Stub =>
2520 Write_Indent_Str_Sloc ("protected body ");
2521 Write_Id (Defining_Identifier (Node));
2522 Write_Str_With_Col_Check (" is separate;");
2524 when N_Protected_Definition =>
2526 Sprint_Indented_List (Visible_Declarations (Node));
2528 if Present (Private_Declarations (Node)) then
2529 Write_Indent_Str ("private");
2530 Sprint_Indented_List (Private_Declarations (Node));
2533 Write_Indent_Str ("end ");
2535 when N_Protected_Type_Declaration =>
2536 Write_Indent_Str_Sloc ("protected type ");
2537 Sprint_Node (Defining_Identifier (Node));
2538 Write_Discr_Specs (Node);
2540 if Present (Interface_List (Node)) then
2541 Write_Str (" is new ");
2542 Sprint_And_List (Interface_List (Node));
2543 Write_Str (" with ");
2548 Sprint_Node (Protected_Definition (Node));
2549 Write_Id (Defining_Identifier (Node));
2552 when N_Qualified_Expression =>
2553 Sprint_Node (Subtype_Mark (Node));
2554 Write_Char_Sloc (''');
2556 -- Print expression, make sure we have at least one level of
2557 -- parentheses around the expression. For cases of qualified
2558 -- expressions in the source, this is always the case, but
2559 -- for generated qualifications, there may be no explicit
2560 -- parentheses present.
2562 if Paren_Count (Expression (Node)) /= 0 then
2563 Sprint_Node (Expression (Node));
2566 Sprint_Node (Expression (Node));
2570 when N_Raise_Constraint_Error =>
2572 -- This node can be used either as a subexpression or as a
2573 -- statement form. The following test is a reasonably reliable
2574 -- way to distinguish the two cases.
2576 if Is_List_Member (Node)
2577 and then Nkind (Parent (Node)) not in N_Subexpr
2582 Write_Str_With_Col_Check_Sloc ("[constraint_error");
2583 Write_Condition_And_Reason (Node);
2585 when N_Raise_Program_Error =>
2587 -- This node can be used either as a subexpression or as a
2588 -- statement form. The following test is a reasonably reliable
2589 -- way to distinguish the two cases.
2591 if Is_List_Member (Node)
2592 and then Nkind (Parent (Node)) not in N_Subexpr
2597 Write_Str_With_Col_Check_Sloc ("[program_error");
2598 Write_Condition_And_Reason (Node);
2600 when N_Raise_Storage_Error =>
2602 -- This node can be used either as a subexpression or as a
2603 -- statement form. The following test is a reasonably reliable
2604 -- way to distinguish the two cases.
2606 if Is_List_Member (Node)
2607 and then Nkind (Parent (Node)) not in N_Subexpr
2612 Write_Str_With_Col_Check_Sloc ("[storage_error");
2613 Write_Condition_And_Reason (Node);
2615 when N_Raise_Statement =>
2616 Write_Indent_Str_Sloc ("raise ");
2617 Sprint_Node (Name (Node));
2621 Sprint_Node (Low_Bound (Node));
2622 Write_Str_Sloc (" .. ");
2623 Sprint_Node (High_Bound (Node));
2624 Update_Itype (Node);
2626 when N_Range_Constraint =>
2627 Write_Str_With_Col_Check_Sloc ("range ");
2628 Sprint_Node (Range_Expression (Node));
2630 when N_Real_Literal =>
2631 Write_Ureal_With_Col_Check_Sloc (Realval (Node));
2633 when N_Real_Range_Specification =>
2634 Write_Str_With_Col_Check_Sloc ("range ");
2635 Sprint_Node (Low_Bound (Node));
2637 Sprint_Node (High_Bound (Node));
2639 when N_Record_Definition =>
2640 if Abstract_Present (Node) then
2641 Write_Str_With_Col_Check ("abstract ");
2644 if Tagged_Present (Node) then
2645 Write_Str_With_Col_Check ("tagged ");
2648 if Limited_Present (Node) then
2649 Write_Str_With_Col_Check ("limited ");
2652 if Null_Present (Node) then
2653 Write_Str_With_Col_Check_Sloc ("null record");
2656 Write_Str_With_Col_Check_Sloc ("record");
2657 Sprint_Node (Component_List (Node));
2658 Write_Indent_Str ("end record");
2661 when N_Record_Representation_Clause =>
2662 Write_Indent_Str_Sloc ("for ");
2663 Sprint_Node (Identifier (Node));
2664 Write_Str_With_Col_Check (" use record ");
2666 if Present (Mod_Clause (Node)) then
2667 Sprint_Node (Mod_Clause (Node));
2670 Sprint_Indented_List (Component_Clauses (Node));
2671 Write_Indent_Str ("end record;");
2674 Sprint_Node (Prefix (Node));
2675 Write_Str_With_Col_Check_Sloc ("'reference");
2677 when N_Requeue_Statement =>
2678 Write_Indent_Str_Sloc ("requeue ");
2679 Sprint_Node (Name (Node));
2681 if Abort_Present (Node) then
2682 Write_Str_With_Col_Check (" with abort");
2687 -- Don't we want to print more detail???
2689 -- Doc of this extended syntax belongs in sinfo.ads and/or
2692 when N_SCIL_Dispatch_Table_Object_Init =>
2693 Write_Indent_Str ("[N_SCIL_Dispatch_Table_Object_Init]");
2695 when N_SCIL_Dispatch_Table_Tag_Init =>
2696 Write_Indent_Str ("[N_SCIL_Dispatch_Table_Tag_Init]");
2698 when N_SCIL_Dispatching_Call =>
2699 Write_Indent_Str ("[N_SCIL_Dispatching_Node]");
2701 when N_SCIL_Membership_Test =>
2702 Write_Indent_Str ("[N_SCIL_Membership_Test]");
2704 when N_SCIL_Tag_Init =>
2705 Write_Indent_Str ("[N_SCIL_Dispatch_Table_Tag_Init]");
2707 when N_Simple_Return_Statement =>
2708 if Present (Expression (Node)) then
2709 Write_Indent_Str_Sloc ("return ");
2710 Sprint_Node (Expression (Node));
2713 Write_Indent_Str_Sloc ("return;");
2716 when N_Selective_Accept =>
2717 Write_Indent_Str_Sloc ("select");
2722 Alt_Node := First (Select_Alternatives (Node));
2725 Sprint_Node (Alt_Node);
2728 exit when No (Alt_Node);
2729 Write_Indent_Str ("or");
2733 if Present (Else_Statements (Node)) then
2734 Write_Indent_Str ("else");
2735 Sprint_Indented_List (Else_Statements (Node));
2738 Write_Indent_Str ("end select;");
2740 when N_Signed_Integer_Type_Definition =>
2741 Write_Str_With_Col_Check_Sloc ("range ");
2742 Sprint_Node (Low_Bound (Node));
2744 Sprint_Node (High_Bound (Node));
2746 when N_Single_Protected_Declaration =>
2747 Write_Indent_Str_Sloc ("protected ");
2748 Write_Id (Defining_Identifier (Node));
2750 Sprint_Node (Protected_Definition (Node));
2751 Write_Id (Defining_Identifier (Node));
2754 when N_Single_Task_Declaration =>
2755 Write_Indent_Str_Sloc ("task ");
2756 Sprint_Node (Defining_Identifier (Node));
2758 if Present (Task_Definition (Node)) then
2760 Sprint_Node (Task_Definition (Node));
2765 when N_Selected_Component =>
2766 Sprint_Node (Prefix (Node));
2767 Write_Char_Sloc ('.');
2768 Sprint_Node (Selector_Name (Node));
2772 Sprint_Node (Prefix (Node));
2773 Write_Str_With_Col_Check (" (");
2774 Sprint_Node (Discrete_Range (Node));
2777 when N_String_Literal =>
2778 if String_Length (Strval (Node)) + Column > Sprint_Line_Limit then
2779 Write_Indent_Str (" ");
2783 Write_String_Table_Entry (Strval (Node));
2785 when N_Subprogram_Body =>
2787 -- Output extra blank line unless we are in freeze actions
2789 if Freeze_Indent = 0 then
2794 Sprint_Node_Sloc (Specification (Node));
2797 Sprint_Indented_List (Declarations (Node));
2798 Write_Indent_Str ("begin");
2799 Sprint_Node (Handled_Statement_Sequence (Node));
2801 Write_Indent_Str ("end ");
2804 (Handled_Statement_Sequence (Node),
2805 Defining_Unit_Name (Specification (Node)));
2808 if Is_List_Member (Node)
2809 and then Present (Next (Node))
2810 and then Nkind (Next (Node)) /= N_Subprogram_Body
2815 when N_Subprogram_Body_Stub =>
2817 Sprint_Node_Sloc (Specification (Node));
2818 Write_Str_With_Col_Check (" is separate;");
2820 when N_Subprogram_Declaration =>
2822 Sprint_Node_Sloc (Specification (Node));
2824 if Nkind (Specification (Node)) = N_Procedure_Specification
2825 and then Null_Present (Specification (Node))
2827 Write_Str_With_Col_Check (" is null");
2832 when N_Subprogram_Info =>
2833 Sprint_Node (Identifier (Node));
2834 Write_Str_With_Col_Check_Sloc ("'subprogram_info");
2836 when N_Subprogram_Renaming_Declaration =>
2838 Sprint_Node (Specification (Node));
2839 Write_Str_With_Col_Check_Sloc (" renames ");
2840 Sprint_Node (Name (Node));
2843 when N_Subtype_Declaration =>
2844 Write_Indent_Str_Sloc ("subtype ");
2845 Sprint_Node (Defining_Identifier (Node));
2848 -- Ada 2005 (AI-231)
2850 if Null_Exclusion_Present (Node) then
2851 Write_Str ("not null ");
2854 Sprint_Node (Subtype_Indication (Node));
2857 when N_Subtype_Indication =>
2858 Sprint_Node_Sloc (Subtype_Mark (Node));
2860 Sprint_Node (Constraint (Node));
2863 Write_Indent_Str_Sloc ("separate (");
2864 Sprint_Node (Name (Node));
2867 Sprint_Node (Proper_Body (Node));
2870 Write_Indent_Str_Sloc ("task body ");
2871 Write_Id (Defining_Identifier (Node));
2873 Sprint_Indented_List (Declarations (Node));
2874 Write_Indent_Str ("begin");
2875 Sprint_Node (Handled_Statement_Sequence (Node));
2876 Write_Indent_Str ("end ");
2878 (Handled_Statement_Sequence (Node), Defining_Identifier (Node));
2881 when N_Task_Body_Stub =>
2882 Write_Indent_Str_Sloc ("task body ");
2883 Write_Id (Defining_Identifier (Node));
2884 Write_Str_With_Col_Check (" is separate;");
2886 when N_Task_Definition =>
2888 Sprint_Indented_List (Visible_Declarations (Node));
2890 if Present (Private_Declarations (Node)) then
2891 Write_Indent_Str ("private");
2892 Sprint_Indented_List (Private_Declarations (Node));
2895 Write_Indent_Str ("end ");
2896 Sprint_End_Label (Node, Defining_Identifier (Parent (Node)));
2898 when N_Task_Type_Declaration =>
2899 Write_Indent_Str_Sloc ("task type ");
2900 Sprint_Node (Defining_Identifier (Node));
2901 Write_Discr_Specs (Node);
2903 if Present (Interface_List (Node)) then
2904 Write_Str (" is new ");
2905 Sprint_And_List (Interface_List (Node));
2908 if Present (Task_Definition (Node)) then
2909 if No (Interface_List (Node)) then
2912 Write_Str (" with ");
2915 Sprint_Node (Task_Definition (Node));
2920 when N_Terminate_Alternative =>
2921 Sprint_Node_List (Pragmas_Before (Node));
2925 if Present (Condition (Node)) then
2926 Write_Str_With_Col_Check ("when ");
2927 Sprint_Node (Condition (Node));
2931 Write_Str_With_Col_Check_Sloc ("terminate;");
2932 Sprint_Node_List (Pragmas_After (Node));
2934 when N_Timed_Entry_Call =>
2935 Write_Indent_Str_Sloc ("select");
2937 Sprint_Node (Entry_Call_Alternative (Node));
2939 Write_Indent_Str ("or");
2941 Sprint_Node (Delay_Alternative (Node));
2943 Write_Indent_Str ("end select;");
2945 when N_Triggering_Alternative =>
2946 Sprint_Node_List (Pragmas_Before (Node));
2947 Sprint_Node_Sloc (Triggering_Statement (Node));
2948 Sprint_Node_List (Statements (Node));
2950 when N_Type_Conversion =>
2952 Sprint_Node (Subtype_Mark (Node));
2955 if Conversion_OK (Node) then
2959 if Float_Truncate (Node) then
2963 if Rounded_Result (Node) then
2968 Sprint_Node (Expression (Node));
2971 when N_Unchecked_Expression =>
2974 Sprint_Node_Sloc (Expression (Node));
2977 when N_Unchecked_Type_Conversion =>
2978 Sprint_Node (Subtype_Mark (Node));
2980 Write_Str_With_Col_Check ("(");
2981 Sprint_Node_Sloc (Expression (Node));
2984 when N_Unconstrained_Array_Definition =>
2985 Write_Str_With_Col_Check_Sloc ("array (");
2990 Node1 := First (Subtype_Marks (Node));
2992 Sprint_Node (Node1);
2993 Write_Str_With_Col_Check (" range <>");
2995 exit when Node1 = Empty;
3000 Write_Str (") of ");
3001 Sprint_Node (Component_Definition (Node));
3003 when N_Unused_At_Start | N_Unused_At_End =>
3004 Write_Indent_Str ("***** Error, unused node encountered *****");
3007 when N_Use_Package_Clause =>
3008 Write_Indent_Str_Sloc ("use ");
3009 Sprint_Comma_List (Names (Node));
3012 when N_Use_Type_Clause =>
3013 Write_Indent_Str_Sloc ("use type ");
3014 Sprint_Comma_List (Subtype_Marks (Node));
3017 when N_Validate_Unchecked_Conversion =>
3018 Write_Indent_Str_Sloc ("validate unchecked_conversion (");
3019 Sprint_Node (Source_Type (Node));
3021 Sprint_Node (Target_Type (Node));
3025 Write_Indent_Str_Sloc ("when ");
3026 Sprint_Bar_List (Discrete_Choices (Node));
3028 Sprint_Node (Component_List (Node));
3030 when N_Variant_Part =>
3032 Write_Indent_Str_Sloc ("case ");
3033 Sprint_Node (Name (Node));
3035 Sprint_Indented_List (Variants (Node));
3036 Write_Indent_Str ("end case");
3039 when N_With_Clause =>
3041 -- Special test, if we are dumping the original tree only,
3042 -- then we want to eliminate the bogus with clauses that
3043 -- correspond to the non-existent children of Text_IO.
3045 if Dump_Original_Only
3046 and then Is_Text_IO_Kludge_Unit (Name (Node))
3050 -- Normal case, output the with clause
3053 if First_Name (Node) or else not Dump_Original_Only then
3055 -- Ada 2005 (AI-50217): Print limited with_clauses
3057 if Private_Present (Node) and Limited_Present (Node) then
3058 Write_Indent_Str ("limited private with ");
3060 elsif Private_Present (Node) then
3061 Write_Indent_Str ("private with ");
3063 elsif Limited_Present (Node) then
3064 Write_Indent_Str ("limited with ");
3067 Write_Indent_Str ("with ");
3074 Sprint_Node_Sloc (Name (Node));
3076 if Last_Name (Node) or else not Dump_Original_Only then
3083 if Nkind (Node) in N_Subexpr
3084 and then Do_Range_Check (Node)
3089 for J in 1 .. Paren_Count (Node) loop
3093 Dump_Node := Save_Dump_Node;
3094 end Sprint_Node_Actual;
3096 ----------------------
3097 -- Sprint_Node_List --
3098 ----------------------
3100 procedure Sprint_Node_List (List : List_Id) is
3104 if Is_Non_Empty_List (List) then
3105 Node := First (List);
3110 exit when Node = Empty;
3113 end Sprint_Node_List;
3115 ----------------------
3116 -- Sprint_Node_Sloc --
3117 ----------------------
3119 procedure Sprint_Node_Sloc (Node : Node_Id) is
3123 if Debug_Generated_Code and then Present (Dump_Node) then
3124 Set_Sloc (Dump_Node, Sloc (Node));
3127 end Sprint_Node_Sloc;
3129 ---------------------
3130 -- Sprint_Opt_Node --
3131 ---------------------
3133 procedure Sprint_Opt_Node (Node : Node_Id) is
3135 if Present (Node) then
3139 end Sprint_Opt_Node;
3141 --------------------------
3142 -- Sprint_Opt_Node_List --
3143 --------------------------
3145 procedure Sprint_Opt_Node_List (List : List_Id) is
3147 if Present (List) then
3148 Sprint_Node_List (List);
3150 end Sprint_Opt_Node_List;
3152 ---------------------------------
3153 -- Sprint_Opt_Paren_Comma_List --
3154 ---------------------------------
3156 procedure Sprint_Opt_Paren_Comma_List (List : List_Id) is
3158 if Is_Non_Empty_List (List) then
3160 Sprint_Paren_Comma_List (List);
3162 end Sprint_Opt_Paren_Comma_List;
3164 -----------------------------
3165 -- Sprint_Paren_Comma_List --
3166 -----------------------------
3168 procedure Sprint_Paren_Comma_List (List : List_Id) is
3170 Node_Exists : Boolean := False;
3174 if Is_Non_Empty_List (List) then
3176 if Dump_Original_Only then
3178 while Present (N) loop
3179 if not Is_Rewrite_Insertion (N) then
3180 Node_Exists := True;
3187 if not Node_Exists then
3192 Write_Str_With_Col_Check ("(");
3193 Sprint_Comma_List (List);
3196 end Sprint_Paren_Comma_List;
3198 ----------------------
3199 -- Sprint_Right_Opnd --
3200 ----------------------
3202 procedure Sprint_Right_Opnd (N : Node_Id) is
3203 Opnd : constant Node_Id := Right_Opnd (N);
3206 if Paren_Count (Opnd) /= 0
3207 or else Op_Prec (Nkind (Opnd)) > Op_Prec (Nkind (N))
3216 end Sprint_Right_Opnd;
3222 procedure Update_Itype (Node : Node_Id) is
3224 if Present (Etype (Node))
3225 and then Is_Itype (Etype (Node))
3226 and then Debug_Generated_Code
3228 Set_Sloc (Etype (Node), Sloc (Node));
3232 ---------------------
3233 -- Write_Char_Sloc --
3234 ---------------------
3236 procedure Write_Char_Sloc (C : Character) is
3238 if Debug_Generated_Code and then C /= ' ' then
3243 end Write_Char_Sloc;
3245 --------------------------------
3246 -- Write_Condition_And_Reason --
3247 --------------------------------
3249 procedure Write_Condition_And_Reason (Node : Node_Id) is
3250 Cond : constant Node_Id := Condition (Node);
3251 Image : constant String := RT_Exception_Code'Image
3252 (RT_Exception_Code'Val
3253 (UI_To_Int (Reason (Node))));
3256 if Present (Cond) then
3258 -- If condition is a single entity, or NOT with a single entity,
3259 -- output all on one line, since it will likely fit just fine.
3261 if Is_Entity_Name (Cond)
3262 or else (Nkind (Cond) = N_Op_Not
3263 and then Is_Entity_Name (Right_Opnd (Cond)))
3265 Write_Str_With_Col_Check (" when ");
3269 -- Otherwise for more complex condition, multiple lines
3272 Write_Str_With_Col_Check (" when");
3273 Indent := Indent + 2;
3277 Indent := Indent - 2;
3280 -- If no condition, just need a space (all on one line)
3290 for J in 4 .. Image'Last loop
3291 if Image (J) = '_' then
3294 Write_Char (Fold_Lower (Image (J)));
3299 end Write_Condition_And_Reason;
3301 --------------------------------
3302 -- Write_Corresponding_Source --
3303 --------------------------------
3305 procedure Write_Corresponding_Source (S : String) is
3307 Src : Source_Buffer_Ptr;
3310 -- Ignore if not in dump source text mode, or if in freeze actions
3312 if Dump_Source_Text and then Freeze_Indent = 0 then
3314 -- Ignore null string
3320 -- Ignore space or semicolon at end of given string
3322 if S (S'Last) = ' ' or else S (S'Last) = ';' then
3323 Write_Corresponding_Source (S (S'First .. S'Last - 1));
3327 -- Loop to look at next lines not yet printed in source file
3330 Last_Line_Printed + 1 .. Last_Source_Line (Current_Source_File)
3332 Src := Source_Text (Current_Source_File);
3333 Loc := Line_Start (L, Current_Source_File);
3335 -- If comment, keep looking
3337 if Src (Loc .. Loc + 1) = "--" then
3340 -- Search to first non-blank
3343 while Src (Loc) not in Line_Terminator loop
3347 if Src (Loc) /= ' ' and then Src (Loc) /= ASCII.HT then
3349 -- Loop through characters in string to see if we match
3351 for J in S'Range loop
3353 -- If mismatch, then not the case we are looking for
3355 if Src (Loc) /= S (J) then
3362 -- If we fall through, string matched, if white space or
3363 -- semicolon after the matched string, this is the case
3364 -- we are looking for.
3366 if Src (Loc) in Line_Terminator
3367 or else Src (Loc) = ' '
3368 or else Src (Loc) = ASCII.HT
3369 or else Src (Loc) = ';'
3371 -- So output source lines up to and including this one
3373 Write_Source_Lines (L);
3382 -- Line was all blanks, or a comment line, keep looking
3386 end Write_Corresponding_Source;
3388 -----------------------
3389 -- Write_Discr_Specs --
3390 -----------------------
3392 procedure Write_Discr_Specs (N : Node_Id) is
3397 Specs := Discriminant_Specifications (N);
3399 if Present (Specs) then
3400 Write_Str_With_Col_Check (" (");
3401 Spec := First (Specs);
3406 exit when Spec = Empty;
3408 -- Add semicolon, unless we are printing original tree and the
3409 -- next specification is part of a list (but not the first
3410 -- element of that list)
3412 if not Dump_Original_Only or else not Prev_Ids (Spec) then
3419 end Write_Discr_Specs;
3425 procedure Write_Ekind (E : Entity_Id) is
3426 S : constant String := Entity_Kind'Image (Ekind (E));
3429 Name_Len := S'Length;
3430 Name_Buffer (1 .. Name_Len) := S;
3431 Set_Casing (Mixed_Case);
3432 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
3439 procedure Write_Id (N : Node_Id) is
3441 -- Deal with outputting Itype
3443 -- Note: if we are printing the full tree with -gnatds, then we may
3444 -- end up picking up the Associated_Node link from a generic template
3445 -- here which overlaps the Entity field, but as documented, Write_Itype
3446 -- is defended against junk calls.
3448 if Nkind (N) in N_Entity then
3450 elsif Nkind (N) in N_Has_Entity then
3451 Write_Itype (Entity (N));
3454 -- Case of a defining identifier
3456 if Nkind (N) = N_Defining_Identifier then
3458 -- If defining identifier has an interface name (and no
3459 -- address clause), then we output the interface name.
3461 if (Is_Imported (N) or else Is_Exported (N))
3462 and then Present (Interface_Name (N))
3463 and then No (Address_Clause (N))
3465 String_To_Name_Buffer (Strval (Interface_Name (N)));
3466 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
3468 -- If no interface name (or inactive because there was
3469 -- an address clause), then just output the Chars name.
3472 Write_Name_With_Col_Check (Chars (N));
3475 -- Case of selector of an expanded name where the expanded name
3476 -- has an associated entity, output this entity.
3478 elsif Nkind (Parent (N)) = N_Expanded_Name
3479 and then Selector_Name (Parent (N)) = N
3480 and then Present (Entity (Parent (N)))
3482 Write_Id (Entity (Parent (N)));
3484 -- For any other node with an associated entity, output it
3486 elsif Nkind (N) in N_Has_Entity
3487 and then Present (Entity_Or_Associated_Node (N))
3488 and then Nkind (Entity_Or_Associated_Node (N)) in N_Entity
3490 Write_Id (Entity (N));
3492 -- All other cases, we just print the Chars field
3495 Write_Name_With_Col_Check (Chars (N));
3499 -----------------------
3500 -- Write_Identifiers --
3501 -----------------------
3503 function Write_Identifiers (Node : Node_Id) return Boolean is
3505 Sprint_Node (Defining_Identifier (Node));
3506 Update_Itype (Defining_Identifier (Node));
3508 -- The remainder of the declaration must be printed unless we are
3509 -- printing the original tree and this is not the last identifier
3512 not Dump_Original_Only or else not More_Ids (Node);
3514 end Write_Identifiers;
3516 ------------------------
3517 -- Write_Implicit_Def --
3518 ------------------------
3520 procedure Write_Implicit_Def (E : Entity_Id) is
3525 when E_Array_Subtype =>
3526 Write_Str_With_Col_Check ("subtype ");
3528 Write_Str_With_Col_Check (" is ");
3529 Write_Id (Base_Type (E));
3530 Write_Str_With_Col_Check (" (");
3532 Ind := First_Index (E);
3533 while Present (Ind) loop
3537 if Present (Ind) then
3544 when E_Signed_Integer_Subtype | E_Enumeration_Subtype =>
3545 Write_Str_With_Col_Check ("subtype ");
3548 Write_Id (Etype (E));
3549 Write_Str_With_Col_Check (" range ");
3550 Sprint_Node (Scalar_Range (E));
3554 Write_Str_With_Col_Check ("type ");
3556 Write_Str_With_Col_Check (" is <");
3561 end Write_Implicit_Def;
3567 procedure Write_Indent is
3568 Loc : constant Source_Ptr := Sloc (Dump_Node);
3571 if Indent_Annull_Flag then
3572 Indent_Annull_Flag := False;
3574 -- Deal with Dump_Source_Text output. Note that we ignore implicit
3575 -- label declarations, since they typically have the sloc of the
3576 -- corresponding label, which really messes up the -gnatL output.
3579 and then Loc > No_Location
3580 and then Nkind (Dump_Node) /= N_Implicit_Label_Declaration
3582 if Get_Source_File_Index (Loc) = Current_Source_File then
3584 (Get_Physical_Line_Number (Sloc (Dump_Node)));
3590 for J in 1 .. Indent loop
3596 ------------------------------
3597 -- Write_Indent_Identifiers --
3598 ------------------------------
3600 function Write_Indent_Identifiers (Node : Node_Id) return Boolean is
3602 -- We need to start a new line for every node, except in the case
3603 -- where we are printing the original tree and this is not the first
3604 -- defining identifier in the list.
3606 if not Dump_Original_Only or else not Prev_Ids (Node) then
3609 -- If printing original tree and this is not the first defining
3610 -- identifier in the list, then the previous call to this procedure
3611 -- printed only the name, and we add a comma to separate the names.
3617 Sprint_Node (Defining_Identifier (Node));
3619 -- The remainder of the declaration must be printed unless we are
3620 -- printing the original tree and this is not the last identifier
3623 not Dump_Original_Only or else not More_Ids (Node);
3624 end Write_Indent_Identifiers;
3626 -----------------------------------
3627 -- Write_Indent_Identifiers_Sloc --
3628 -----------------------------------
3630 function Write_Indent_Identifiers_Sloc (Node : Node_Id) return Boolean is
3632 -- We need to start a new line for every node, except in the case
3633 -- where we are printing the original tree and this is not the first
3634 -- defining identifier in the list.
3636 if not Dump_Original_Only or else not Prev_Ids (Node) then
3639 -- If printing original tree and this is not the first defining
3640 -- identifier in the list, then the previous call to this procedure
3641 -- printed only the name, and we add a comma to separate the names.
3648 Sprint_Node (Defining_Identifier (Node));
3650 -- The remainder of the declaration must be printed unless we are
3651 -- printing the original tree and this is not the last identifier
3653 return not Dump_Original_Only or else not More_Ids (Node);
3654 end Write_Indent_Identifiers_Sloc;
3656 ----------------------
3657 -- Write_Indent_Str --
3658 ----------------------
3660 procedure Write_Indent_Str (S : String) is
3662 Write_Corresponding_Source (S);
3665 end Write_Indent_Str;
3667 ---------------------------
3668 -- Write_Indent_Str_Sloc --
3669 ---------------------------
3671 procedure Write_Indent_Str_Sloc (S : String) is
3673 Write_Corresponding_Source (S);
3676 end Write_Indent_Str_Sloc;
3682 procedure Write_Itype (Typ : Entity_Id) is
3684 procedure Write_Header (T : Boolean := True);
3685 -- Write type if T is True, subtype if T is false
3691 procedure Write_Header (T : Boolean := True) is
3694 Write_Str ("[type ");
3696 Write_Str ("[subtype ");
3699 Write_Name_With_Col_Check (Chars (Typ));
3703 -- Start of processing for Write_Itype
3706 if Nkind (Typ) in N_Entity
3707 and then Is_Itype (Typ)
3708 and then not Itype_Printed (Typ)
3710 -- Itype to be printed
3713 B : constant Node_Id := Etype (Typ);
3715 P : constant Node_Id := Parent (Typ);
3717 S : constant Saved_Output_Buffer := Save_Output_Buffer;
3718 -- Save current output buffer
3720 Old_Sloc : Source_Ptr;
3721 -- Save sloc of related node, so it is not modified when
3722 -- printing with -gnatD.
3725 -- Write indentation at start of line
3727 for J in 1 .. Indent loop
3731 -- If we have a constructed declaration for the itype, print it
3734 and then Nkind (P) in N_Declaration
3735 and then Defining_Entity (P) = Typ
3737 -- We must set Itype_Printed true before the recursive call to
3738 -- print the node, otherwise we get an infinite recursion!
3740 Set_Itype_Printed (Typ, True);
3742 -- Write the declaration enclosed in [], avoiding new line
3743 -- at start of declaration, and semicolon at end.
3745 -- Note: The itype may be imported from another unit, in which
3746 -- case we do not want to modify the Sloc of the declaration.
3747 -- Otherwise the itype may appear to be in the current unit,
3748 -- and the back-end will reject a reference out of scope.
3751 Indent_Annull_Flag := True;
3752 Old_Sloc := Sloc (P);
3754 Set_Sloc (P, Old_Sloc);
3755 Write_Erase_Char (';');
3757 -- If no constructed declaration, then we have to concoct the
3758 -- source corresponding to the type entity that we have at hand.
3763 -- Access types and subtypes
3766 Write_Header (Ekind (Typ) = E_Access_Type);
3767 Write_Str ("access ");
3769 if Is_Access_Constant (Typ) then
3770 Write_Str ("constant ");
3771 elsif Can_Never_Be_Null (Typ) then
3772 Write_Str ("not null ");
3775 Write_Id (Directly_Designated_Type (Typ));
3777 -- Array types and string types
3779 when E_Array_Type | E_String_Type =>
3781 Write_Str ("array (");
3783 X := First_Index (Typ);
3787 if not Is_Constrained (Typ) then
3788 Write_Str (" range <>");
3796 Write_Str (") of ");
3797 X := Component_Type (Typ);
3799 -- Preserve sloc of component type, which is defined
3800 -- elsewhere than the itype (see comment above).
3802 Old_Sloc := Sloc (X);
3804 Set_Sloc (X, Old_Sloc);
3806 -- Array subtypes and string subtypes.
3807 -- Preserve Sloc of index subtypes, as above.
3809 when E_Array_Subtype | E_String_Subtype =>
3810 Write_Header (False);
3811 Write_Id (Etype (Typ));
3814 X := First_Index (Typ);
3816 Old_Sloc := Sloc (X);
3818 Set_Sloc (X, Old_Sloc);
3826 -- Signed integer types, and modular integer subtypes,
3827 -- and also enumeration subtypes.
3829 when E_Signed_Integer_Type |
3830 E_Signed_Integer_Subtype |
3831 E_Modular_Integer_Subtype |
3832 E_Enumeration_Subtype =>
3834 Write_Header (Ekind (Typ) = E_Signed_Integer_Type);
3836 if Ekind (Typ) = E_Signed_Integer_Type then
3842 -- Print bounds if different from base type
3845 L : constant Node_Id := Type_Low_Bound (Typ);
3846 H : constant Node_Id := Type_High_Bound (Typ);
3851 -- B can either be a scalar type, in which case the
3852 -- declaration of Typ may constrain it with different
3853 -- bounds, or a private type, in which case we know
3854 -- that the declaration of Typ cannot have a scalar
3857 if Is_Scalar_Type (B) then
3858 LE := Type_Low_Bound (B);
3859 HE := Type_High_Bound (B);
3867 and then Nkind (L) = N_Integer_Literal
3868 and then Nkind (H) = N_Integer_Literal
3869 and then Nkind (LE) = N_Integer_Literal
3870 and then Nkind (HE) = N_Integer_Literal
3871 and then UI_Eq (Intval (L), Intval (LE))
3872 and then UI_Eq (Intval (H), Intval (HE)))
3877 Write_Str (" range ");
3878 Sprint_Node (Type_Low_Bound (Typ));
3880 Sprint_Node (Type_High_Bound (Typ));
3884 -- Modular integer types
3886 when E_Modular_Integer_Type =>
3888 Write_Str (" mod ");
3889 Write_Uint_With_Col_Check (Modulus (Typ), Auto);
3891 -- Floating point types and subtypes
3893 when E_Floating_Point_Type |
3894 E_Floating_Point_Subtype =>
3896 Write_Header (Ekind (Typ) = E_Floating_Point_Type);
3898 if Ekind (Typ) = E_Floating_Point_Type then
3902 Write_Id (Etype (Typ));
3904 if Digits_Value (Typ) /= Digits_Value (Etype (Typ)) then
3905 Write_Str (" digits ");
3906 Write_Uint_With_Col_Check
3907 (Digits_Value (Typ), Decimal);
3910 -- Print bounds if not different from base type
3913 L : constant Node_Id := Type_Low_Bound (Typ);
3914 H : constant Node_Id := Type_High_Bound (Typ);
3915 LE : constant Node_Id := Type_Low_Bound (B);
3916 HE : constant Node_Id := Type_High_Bound (B);
3919 if Nkind (L) = N_Real_Literal
3920 and then Nkind (H) = N_Real_Literal
3921 and then Nkind (LE) = N_Real_Literal
3922 and then Nkind (HE) = N_Real_Literal
3923 and then UR_Eq (Realval (L), Realval (LE))
3924 and then UR_Eq (Realval (H), Realval (HE))
3929 Write_Str (" range ");
3930 Sprint_Node (Type_Low_Bound (Typ));
3932 Sprint_Node (Type_High_Bound (Typ));
3938 when E_Record_Subtype =>
3939 Write_Header (False);
3940 Write_Str ("record");
3946 C := First_Entity (Typ);
3947 while Present (C) loop
3951 Write_Id (Etype (C));
3957 Write_Indent_Str (" end record");
3961 when E_Class_Wide_Type |
3962 E_Class_Wide_Subtype =>
3964 Write_Name_With_Col_Check (Chars (Etype (Typ)));
3965 Write_Str ("'Class");
3969 when E_Subprogram_Type =>
3972 if Etype (Typ) = Standard_Void_Type then
3973 Write_Str ("procedure");
3975 Write_Str ("function");
3978 if Present (First_Entity (Typ)) then
3985 Param := First_Entity (Typ);
3990 if Ekind (Param) = E_In_Out_Parameter then
3991 Write_Str ("in out ");
3992 elsif Ekind (Param) = E_Out_Parameter then
3996 Write_Id (Etype (Param));
3997 Next_Entity (Param);
3998 exit when No (Param);
4006 if Etype (Typ) /= Standard_Void_Type then
4007 Write_Str (" return ");
4008 Write_Id (Etype (Typ));
4011 when E_String_Literal_Subtype =>
4013 LB : constant Uint :=
4014 Expr_Value (String_Literal_Low_Bound (Typ));
4015 Len : constant Uint :=
4016 String_Literal_Length (Typ);
4018 Write_Str ("String (");
4019 Write_Int (UI_To_Int (LB));
4021 Write_Int (UI_To_Int (LB + Len) - 1);
4025 -- For all other Itypes, print ??? (fill in later)
4028 Write_Header (True);
4034 -- Add terminating bracket and restore output buffer
4038 Restore_Output_Buffer (S);
4041 Set_Itype_Printed (Typ);
4045 -------------------------------
4046 -- Write_Name_With_Col_Check --
4047 -------------------------------
4049 procedure Write_Name_With_Col_Check (N : Name_Id) is
4055 Get_Name_String (N);
4057 -- Deal with -gnatdI which replaces any sequence Cnnnb where C is an
4058 -- upper case letter, nnn is one or more digits and b is a lower case
4059 -- letter by C...b, so that listings do not depend on serial numbers.
4061 if Debug_Flag_II then
4063 while J < Name_Len - 1 loop
4064 if Name_Buffer (J) in 'A' .. 'Z'
4065 and then Name_Buffer (J + 1) in '0' .. '9'
4068 while K < Name_Len loop
4069 exit when Name_Buffer (K) not in '0' .. '9';
4073 if Name_Buffer (K) in 'a' .. 'z' then
4074 L := Name_Len - K + 1;
4076 Name_Buffer (J + 4 .. J + L + 3) :=
4077 Name_Buffer (K .. Name_Len);
4078 Name_Buffer (J + 1 .. J + 3) := "...";
4079 Name_Len := J + L + 3;
4092 -- Fall through for normal case
4094 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
4095 end Write_Name_With_Col_Check;
4097 ------------------------------------
4098 -- Write_Name_With_Col_Check_Sloc --
4099 ------------------------------------
4101 procedure Write_Name_With_Col_Check_Sloc (N : Name_Id) is
4103 Get_Name_String (N);
4104 Write_Str_With_Col_Check_Sloc (Name_Buffer (1 .. Name_Len));
4105 end Write_Name_With_Col_Check_Sloc;
4107 --------------------
4108 -- Write_Operator --
4109 --------------------
4111 procedure Write_Operator (N : Node_Id; S : String) is
4112 F : Natural := S'First;
4113 T : Natural := S'Last;
4116 -- If no overflow check, just write string out, and we are done
4118 if not Do_Overflow_Check (N) then
4121 -- If overflow check, we want to surround the operator with curly
4122 -- brackets, but not include spaces within the brackets.
4135 Write_Str_Sloc (S (F .. T));
4138 if S (S'Last) = ' ' then
4144 -----------------------
4145 -- Write_Param_Specs --
4146 -----------------------
4148 procedure Write_Param_Specs (N : Node_Id) is
4154 Specs := Parameter_Specifications (N);
4156 if Is_Non_Empty_List (Specs) then
4157 Write_Str_With_Col_Check (" (");
4158 Spec := First (Specs);
4162 Formal := Defining_Identifier (Spec);
4164 exit when Spec = Empty;
4166 -- Add semicolon, unless we are printing original tree and the
4167 -- next specification is part of a list (but not the first element
4170 if not Dump_Original_Only or else not Prev_Ids (Spec) then
4175 -- Write out any extra formals
4177 while Present (Extra_Formal (Formal)) loop
4178 Formal := Extra_Formal (Formal);
4180 Write_Name_With_Col_Check (Chars (Formal));
4182 Write_Name_With_Col_Check (Chars (Etype (Formal)));
4187 end Write_Param_Specs;
4189 -----------------------
4190 -- Write_Rewrite_Str --
4191 -----------------------
4193 procedure Write_Rewrite_Str (S : String) is
4195 if not Dump_Generated_Only then
4196 if S'Length = 3 and then S = ">>>" then
4199 Write_Str_With_Col_Check (S);
4202 end Write_Rewrite_Str;
4204 -----------------------
4205 -- Write_Source_Line --
4206 -----------------------
4208 procedure Write_Source_Line (L : Physical_Line_Number) is
4210 Src : Source_Buffer_Ptr;
4214 if Dump_Source_Text then
4215 Src := Source_Text (Current_Source_File);
4216 Loc := Line_Start (L, Current_Source_File);
4219 -- See if line is a comment line, if not, and if not line one,
4220 -- precede with blank line.
4223 while Src (Scn) = ' ' or else Src (Scn) = ASCII.HT loop
4227 if (Src (Scn) in Line_Terminator
4228 or else Src (Scn .. Scn + 1) /= "--")
4234 -- Now write the source text of the line
4237 Write_Int (Int (L));
4240 while Src (Loc) not in Line_Terminator loop
4241 Write_Char (Src (Loc));
4245 end Write_Source_Line;
4247 ------------------------
4248 -- Write_Source_Lines --
4249 ------------------------
4251 procedure Write_Source_Lines (L : Physical_Line_Number) is
4253 while Last_Line_Printed < L loop
4254 Last_Line_Printed := Last_Line_Printed + 1;
4255 Write_Source_Line (Last_Line_Printed);
4257 end Write_Source_Lines;
4259 --------------------
4260 -- Write_Str_Sloc --
4261 --------------------
4263 procedure Write_Str_Sloc (S : String) is
4265 for J in S'Range loop
4266 Write_Char_Sloc (S (J));
4270 ------------------------------
4271 -- Write_Str_With_Col_Check --
4272 ------------------------------
4274 procedure Write_Str_With_Col_Check (S : String) is
4276 if Int (S'Last) + Column > Sprint_Line_Limit then
4277 Write_Indent_Str (" ");
4279 if S (S'First) = ' ' then
4280 Write_Str (S (S'First + 1 .. S'Last));
4288 end Write_Str_With_Col_Check;
4290 -----------------------------------
4291 -- Write_Str_With_Col_Check_Sloc --
4292 -----------------------------------
4294 procedure Write_Str_With_Col_Check_Sloc (S : String) is
4296 if Int (S'Last) + Column > Sprint_Line_Limit then
4297 Write_Indent_Str (" ");
4299 if S (S'First) = ' ' then
4300 Write_Str_Sloc (S (S'First + 1 .. S'Last));
4308 end Write_Str_With_Col_Check_Sloc;
4310 ---------------------------
4311 -- Write_Subprogram_Name --
4312 ---------------------------
4314 procedure Write_Subprogram_Name (N : Node_Id) is
4316 if not Comes_From_Source (N)
4317 and then Is_Entity_Name (N)
4320 Ent : constant Entity_Id := Entity (N);
4322 if not In_Extended_Main_Source_Unit (Ent)
4324 Is_Predefined_File_Name
4325 (Unit_File_Name (Get_Source_Unit (Ent)))
4327 -- Run-time routine name, output name with a preceding dollar
4328 -- making sure that we do not get a line split between them.
4330 Col_Check (Length_Of_Name (Chars (Ent)) + 1);
4332 Write_Name (Chars (Ent));
4338 -- Normal case, not a run-time routine name
4341 end Write_Subprogram_Name;
4343 -------------------------------
4344 -- Write_Uint_With_Col_Check --
4345 -------------------------------
4347 procedure Write_Uint_With_Col_Check (U : Uint; Format : UI_Format) is
4349 Col_Check (UI_Decimal_Digits_Hi (U));
4350 UI_Write (U, Format);
4351 end Write_Uint_With_Col_Check;
4353 ------------------------------------
4354 -- Write_Uint_With_Col_Check_Sloc --
4355 ------------------------------------
4357 procedure Write_Uint_With_Col_Check_Sloc (U : Uint; Format : UI_Format) is
4359 Col_Check (UI_Decimal_Digits_Hi (U));
4361 UI_Write (U, Format);
4362 end Write_Uint_With_Col_Check_Sloc;
4364 -------------------------------------
4365 -- Write_Ureal_With_Col_Check_Sloc --
4366 -------------------------------------
4368 procedure Write_Ureal_With_Col_Check_Sloc (U : Ureal) is
4369 D : constant Uint := Denominator (U);
4370 N : constant Uint := Numerator (U);
4374 (UI_Decimal_Digits_Hi (D) + UI_Decimal_Digits_Hi (N) + 4);
4377 end Write_Ureal_With_Col_Check_Sloc;