1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, 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 Aspects; use Aspects;
27 with Atree; use Atree;
28 with Casing; use Casing;
29 with Csets; use Csets;
30 with Debug; use Debug;
31 with Einfo; use Einfo;
32 with Fname; use Fname;
34 with Namet; use Namet;
35 with Nlists; use Nlists;
37 with Output; use Output;
38 with Rtsfind; use Rtsfind;
39 with Sem_Eval; use Sem_Eval;
40 with Sem_Util; use Sem_Util;
41 with Sinfo; use Sinfo;
42 with Sinput; use Sinput;
43 with Sinput.D; use Sinput.D;
44 with Snames; use Snames;
45 with Stand; use Stand;
46 with Stringt; use Stringt;
47 with Uintp; use Uintp;
48 with Uname; use Uname;
49 with Urealp; use Urealp;
51 package body Sprint is
52 Current_Source_File : Source_File_Index;
53 -- Index of source file whose generated code is being dumped
55 Dump_Node : Node_Id := Empty;
56 -- This is set to the current node, used for printing line numbers. In
57 -- Debug_Generated_Code mode, Dump_Node is set to the current node
58 -- requiring Sloc fixup, until Set_Debug_Sloc is called to set the proper
59 -- value. The call clears it back to Empty.
61 Debug_Sloc : Source_Ptr;
62 -- Sloc of first byte of line currently being written if we are
63 -- generating a source debug file.
65 Dump_Original_Only : Boolean;
66 -- Set True if the -gnatdo (dump original tree) flag is set
68 Dump_Generated_Only : Boolean;
69 -- Set True if the -gnatdG (dump generated tree) debug flag is set
70 -- or for Print_Generated_Code (-gnatG) or Dump_Generated_Code (-gnatD).
72 Dump_Freeze_Null : Boolean;
73 -- Set True if empty freeze nodes and non-source null statements output.
74 -- Note that freeze nodes containing freeze actions are always output,
75 -- as are freeze nodes for itypes, which in general have the effect of
76 -- causing elaboration of the itype.
78 Freeze_Indent : Int := 0;
79 -- Keep track of freeze indent level (controls output of blank lines before
80 -- procedures within expression freeze actions). Relevant only if we are
81 -- not in Dump_Source_Text mode, since in Dump_Source_Text mode we don't
82 -- output these blank lines in any case.
85 -- Number of columns for current line output indentation
87 Indent_Annull_Flag : Boolean := False;
88 -- Set True if subsequent Write_Indent call to be ignored, gets reset
89 -- by this call, so it is only active to suppress a single indent call.
91 Last_Line_Printed : Physical_Line_Number;
92 -- This keeps track of the physical line number of the last source line
93 -- that has been output. The value is only valid in Dump_Source_Text mode.
95 -------------------------------
96 -- Operator Precedence Table --
97 -------------------------------
99 -- This table is used to decide whether a subexpression needs to be
100 -- parenthesized. The rule is that if an operand of an operator (which
101 -- for this purpose includes AND THEN and OR ELSE) is itself an operator
102 -- with a lower precedence than the operator (or equal precedence if
103 -- appearing as the right operand), then parentheses are required.
105 Op_Prec : constant array (N_Subexpr) of Short_Short_Integer :=
138 procedure Sprint_Left_Opnd (N : Node_Id);
139 -- Print left operand of operator, parenthesizing if necessary
141 procedure Sprint_Right_Opnd (N : Node_Id);
142 -- Print right operand of operator, parenthesizing if necessary
144 -----------------------
145 -- Local Subprograms --
146 -----------------------
148 procedure Col_Check (N : Nat);
149 -- Check that at least N characters remain on current line, and if not,
150 -- then start an extra line with two characters extra indentation for
151 -- continuing text on the next line.
153 procedure Extra_Blank_Line;
154 -- In some situations we write extra blank lines to separate the generated
155 -- code to make it more readable. However, these extra blank lines are not
156 -- generated in Dump_Source_Text mode, since there the source text lines
157 -- output with preceding blank lines are quite sufficient as separators.
158 -- This procedure writes a blank line if Dump_Source_Text is False.
160 procedure Indent_Annull;
161 -- Causes following call to Write_Indent to be ignored. This is used when
162 -- a higher level node wants to stop a lower level node from starting a
163 -- new line, when it would otherwise be inclined to do so (e.g. the case
164 -- of an accept statement called from an accept alternative with a guard)
166 procedure Indent_Begin;
167 -- Increase indentation level
169 procedure Indent_End;
170 -- Decrease indentation level
172 procedure Print_Debug_Line (S : String);
173 -- Used to print output lines in Debug_Generated_Code mode (this is used
174 -- as the argument for a call to Set_Special_Output in package Output).
176 procedure Process_TFAI_RR_Flags (Nod : Node_Id);
177 -- Given a divide, multiplication or division node, check the flags
178 -- Treat_Fixed_As_Integer and Rounded_Flags, and if set, output the
179 -- appropriate special syntax characters (# and @).
181 procedure Set_Debug_Sloc;
182 -- If Dump_Node is non-empty, this routine sets the appropriate value
183 -- in its Sloc field, from the current location in the debug source file
184 -- that is currently being written.
186 procedure Sprint_And_List (List : List_Id);
187 -- Print the given list with items separated by vertical "and"
189 procedure Sprint_Aspect_Specifications
191 Semicolon : Boolean);
192 -- Node is a declaration node that has aspect specifications (Has_Aspects
193 -- flag set True). It outputs the aspect specifications. For the case
194 -- of Semicolon = True, it is called after outputting the terminating
195 -- semicolon for the related node. The effect is to remove the semicolon
196 -- and print the aspect specifications followed by a terminating semicolon.
197 -- For the case of Semicolon False, no semicolon is removed or output, and
198 -- all the aspects are printed on a single line.
200 procedure Sprint_Bar_List (List : List_Id);
201 -- Print the given list with items separated by vertical bars
203 procedure Sprint_End_Label
206 -- Print the end label for a Handled_Sequence_Of_Statements in a body.
207 -- If there is no end label, use the defining identifier of the enclosing
208 -- construct. If the end label is present, treat it as a reference to the
209 -- defining entity of the construct: this guarantees that it carries the
210 -- proper sloc information for debugging purposes.
212 procedure Sprint_Node_Actual (Node : Node_Id);
213 -- This routine prints its node argument. It is a lower level routine than
214 -- Sprint_Node, in that it does not bother about rewritten trees.
216 procedure Sprint_Node_Sloc (Node : Node_Id);
217 -- Like Sprint_Node, but in addition, in Debug_Generated_Code mode,
218 -- sets the Sloc of the current debug node to be a copy of the Sloc
219 -- of the sprinted node Node. Note that this is done after printing
220 -- Node, so that the Sloc is the proper updated value for the debug file.
222 procedure Update_Itype (Node : Node_Id);
223 -- Update the Sloc of an itype that is not attached to the tree, when
224 -- debugging expanded code. This routine is called from nodes whose
225 -- type can be an Itype, such as defining_identifiers that may be of
226 -- an anonymous access type, or ranges in slices.
228 procedure Write_Char_Sloc (C : Character);
229 -- Like Write_Char, except that if C is non-blank, Set_Debug_Sloc is
230 -- called to ensure that the current node has a proper Sloc set.
232 procedure Write_Condition_And_Reason (Node : Node_Id);
233 -- Write Condition and Reason codes of Raise_xxx_Error node
235 procedure Write_Corresponding_Source (S : String);
236 -- If S is a string with a single keyword (possibly followed by a space),
237 -- and if the next non-comment non-blank source line matches this keyword,
238 -- then output all source lines up to this matching line.
240 procedure Write_Discr_Specs (N : Node_Id);
241 -- Output discriminant specification for node, which is any of the type
242 -- declarations that can have discriminants.
244 procedure Write_Ekind (E : Entity_Id);
245 -- Write the String corresponding to the Ekind without "E_"
247 procedure Write_Id (N : Node_Id);
248 -- N is a node with a Chars field. This procedure writes the name that
249 -- will be used in the generated code associated with the name. For a
250 -- node with no associated entity, this is simply the Chars field. For
251 -- the case where there is an entity associated with the node, we print
252 -- the name associated with the entity (since it may have been encoded).
253 -- One other special case is that an entity has an active external name
254 -- (i.e. an external name present with no address clause), then this
255 -- external name is output. This procedure also deals with outputting
256 -- declarations of referenced itypes, if not output earlier.
258 function Write_Identifiers (Node : Node_Id) return Boolean;
259 -- Handle node where the grammar has a list of defining identifiers, but
260 -- the tree has a separate declaration for each identifier. Handles the
261 -- printing of the defining identifier, and returns True if the type and
262 -- initialization information is to be printed, False if it is to be
263 -- skipped (the latter case happens when printing defining identifiers
264 -- other than the first in the original tree output case).
266 procedure Write_Implicit_Def (E : Entity_Id);
267 pragma Warnings (Off, Write_Implicit_Def);
268 -- Write the definition of the implicit type E according to its Ekind
269 -- For now a debugging procedure, but might be used in the future.
271 procedure Write_Indent;
272 -- Start a new line and write indentation spacing
274 function Write_Indent_Identifiers (Node : Node_Id) return Boolean;
275 -- Like Write_Identifiers except that each new printed declaration
276 -- is at the start of a new line.
278 function Write_Indent_Identifiers_Sloc (Node : Node_Id) return Boolean;
279 -- Like Write_Indent_Identifiers except that in Debug_Generated_Code
280 -- mode, the Sloc of the current debug node is set to point to the
281 -- first output identifier.
283 procedure Write_Indent_Str (S : String);
284 -- Start a new line and write indent spacing followed by given string
286 procedure Write_Indent_Str_Sloc (S : String);
287 -- Like Write_Indent_Str, but in addition, in Debug_Generated_Code mode,
288 -- the Sloc of the current node is set to the first non-blank character
291 procedure Write_Itype (Typ : Entity_Id);
292 -- If Typ is an Itype that has not been written yet, write it. If Typ is
293 -- any other kind of entity or tree node, the call is ignored.
295 procedure Write_Name_With_Col_Check (N : Name_Id);
296 -- Write name (using Write_Name) with initial column check, and possible
297 -- initial Write_Indent (to get new line) if current line is too full.
299 procedure Write_Name_With_Col_Check_Sloc (N : Name_Id);
300 -- Like Write_Name_With_Col_Check but in addition, in Debug_Generated_Code
301 -- mode, sets Sloc of current debug node to first character of name.
303 procedure Write_Operator (N : Node_Id; S : String);
304 -- Like Write_Str_Sloc, used for operators, encloses the string in
305 -- characters {} if the Do_Overflow flag is set on the node N.
307 procedure Write_Param_Specs (N : Node_Id);
308 -- Output parameter specifications for node (which is either a function
309 -- or procedure specification with a Parameter_Specifications field)
311 procedure Write_Rewrite_Str (S : String);
312 -- Writes out a string (typically containing <<< or >>>}) for a node
313 -- created by rewriting the tree. Suppressed if we are outputting the
314 -- generated code only, since in this case we don't specially mark nodes
315 -- created by rewriting).
317 procedure Write_Source_Line (L : Physical_Line_Number);
318 -- If writing of interspersed source lines is enabled, then write the given
319 -- line from the source file, preceded by Eol, then an extra blank line if
320 -- the line has at least one blank, is not a comment and is not line one,
321 -- then "--" and the line number followed by period followed by text of the
322 -- source line (without terminating Eol). If interspersed source line
323 -- output not enabled, then the call has no effect.
325 procedure Write_Source_Lines (L : Physical_Line_Number);
326 -- If writing of interspersed source lines is enabled, then writes source
327 -- lines Last_Line_Printed + 1 .. L, and updates Last_Line_Printed. If
328 -- interspersed source line output not enabled, then call has no effect.
330 procedure Write_Str_Sloc (S : String);
331 -- Like Write_Str, but sets debug Sloc of current debug node to first
332 -- non-blank character if a current debug node is active.
334 procedure Write_Str_With_Col_Check (S : String);
335 -- Write string (using Write_Str) with initial column check, and possible
336 -- initial Write_Indent (to get new line) if current line is too full.
338 procedure Write_Str_With_Col_Check_Sloc (S : String);
339 -- Like Write_Str_With_Col_Check, but sets debug Sloc of current debug
340 -- node to first non-blank character if a current debug node is active.
342 procedure Write_Subprogram_Name (N : Node_Id);
343 -- N is the Name field of a function call or procedure statement call.
344 -- The effect of the call is to output the name, preceded by a $ if the
345 -- call is identified as an implicit call to a run time routine.
347 procedure Write_Uint_With_Col_Check (U : Uint; Format : UI_Format);
348 -- Write Uint (using UI_Write) with initial column check, and possible
349 -- initial Write_Indent (to get new line) if current line is too full.
350 -- The format parameter determines the output format (see UI_Write).
352 procedure Write_Uint_With_Col_Check_Sloc (U : Uint; Format : UI_Format);
353 -- Write Uint (using UI_Write) with initial column check, and possible
354 -- initial Write_Indent (to get new line) if current line is too full.
355 -- The format parameter determines the output format (see UI_Write).
356 -- In addition, in Debug_Generated_Code mode, sets the current node
357 -- Sloc to the first character of the output value.
359 procedure Write_Ureal_With_Col_Check_Sloc (U : Ureal);
360 -- Write Ureal (using same output format as UR_Write) with column checks
361 -- and a possible initial Write_Indent (to get new line) if current line
362 -- is too full. In addition, in Debug_Generated_Code mode, sets the
363 -- current node Sloc to the first character of the output value.
369 procedure Col_Check (N : Nat) is
371 if N + Column > Sprint_Line_Limit then
372 Write_Indent_Str (" ");
376 ----------------------
377 -- Extra_Blank_Line --
378 ----------------------
380 procedure Extra_Blank_Line is
382 if not Dump_Source_Text then
385 end Extra_Blank_Line;
391 procedure Indent_Annull is
393 Indent_Annull_Flag := True;
400 procedure Indent_Begin is
402 Indent := Indent + 3;
409 procedure Indent_End is
411 Indent := Indent - 3;
418 procedure pg (Arg : Union_Id) is
420 Dump_Generated_Only := True;
421 Dump_Original_Only := False;
422 Dump_Freeze_Null := True;
423 Current_Source_File := No_Source_File;
425 if Arg in List_Range then
426 Sprint_Node_List (List_Id (Arg), New_Lines => True);
428 elsif Arg in Node_Range then
429 Sprint_Node (Node_Id (Arg));
442 procedure po (Arg : Union_Id) is
444 Dump_Generated_Only := False;
445 Dump_Original_Only := True;
446 Current_Source_File := No_Source_File;
448 if Arg in List_Range then
449 Sprint_Node_List (List_Id (Arg), New_Lines => True);
451 elsif Arg in Node_Range then
452 Sprint_Node (Node_Id (Arg));
461 ----------------------
462 -- Print_Debug_Line --
463 ----------------------
465 procedure Print_Debug_Line (S : String) is
467 Write_Debug_Line (S, Debug_Sloc);
468 end Print_Debug_Line;
470 ---------------------------
471 -- Process_TFAI_RR_Flags --
472 ---------------------------
474 procedure Process_TFAI_RR_Flags (Nod : Node_Id) is
476 if Treat_Fixed_As_Integer (Nod) then
480 if Rounded_Result (Nod) then
483 end Process_TFAI_RR_Flags;
489 procedure ps (Arg : Union_Id) is
491 Dump_Generated_Only := False;
492 Dump_Original_Only := False;
493 Current_Source_File := No_Source_File;
495 if Arg in List_Range then
496 Sprint_Node_List (List_Id (Arg), New_Lines => True);
498 elsif Arg in Node_Range then
499 Sprint_Node (Node_Id (Arg));
512 procedure Set_Debug_Sloc is
514 if Debug_Generated_Code and then Present (Dump_Node) then
515 Set_Sloc (Dump_Node, Debug_Sloc + Source_Ptr (Column - 1));
524 procedure Source_Dump is
527 -- Put underline under string we just printed
533 procedure Underline is
534 Col : constant Int := Column;
539 while Col > Column loop
546 -- Start of processing for Source_Dump
549 Dump_Generated_Only := Debug_Flag_G or
550 Print_Generated_Code or
551 Debug_Generated_Code;
552 Dump_Original_Only := Debug_Flag_O;
553 Dump_Freeze_Null := Debug_Flag_S or Debug_Flag_G;
555 -- Note that we turn off the tree dump flags immediately, before
556 -- starting the dump. This avoids generating two copies of the dump
557 -- if an abort occurs after printing the dump, and more importantly,
558 -- avoids an infinite loop if an abort occurs during the dump.
561 Current_Source_File := No_Source_File;
562 Debug_Flag_Z := False;
565 Write_Str ("Source recreated from tree of Standard (spec)");
567 Sprint_Node (Standard_Package_Node);
572 if Debug_Flag_S or Dump_Generated_Only or Dump_Original_Only then
573 Debug_Flag_G := False;
574 Debug_Flag_O := False;
575 Debug_Flag_S := False;
577 -- Dump requested units
579 for U in Main_Unit .. Last_Unit loop
580 Current_Source_File := Source_Index (U);
582 -- Dump all units if -gnatdf set, otherwise we dump only
583 -- the source files that are in the extended main source.
586 or else In_Extended_Main_Source_Unit (Cunit_Entity (U))
588 -- If we are generating debug files, setup to write them
590 if Debug_Generated_Code then
591 Set_Special_Output (Print_Debug_Line'Access);
592 Create_Debug_Source (Source_Index (U), Debug_Sloc);
593 Write_Source_Line (1);
594 Last_Line_Printed := 1;
595 Sprint_Node (Cunit (U));
596 Write_Source_Lines (Last_Source_Line (Current_Source_File));
599 Set_Special_Output (null);
601 -- Normal output to standard output file
604 Write_Str ("Source recreated from tree for ");
605 Write_Unit_Name (Unit_Name (U));
607 Write_Source_Line (1);
608 Last_Line_Printed := 1;
609 Sprint_Node (Cunit (U));
610 Write_Source_Lines (Last_Source_Line (Current_Source_File));
619 ---------------------
620 -- Sprint_And_List --
621 ---------------------
623 procedure Sprint_And_List (List : List_Id) is
626 if Is_Non_Empty_List (List) then
627 Node := First (List);
631 exit when Node = Empty;
637 ----------------------------------
638 -- Sprint_Aspect_Specifications --
639 ----------------------------------
641 procedure Sprint_Aspect_Specifications
645 AS : constant List_Id := Aspect_Specifications (Node);
650 Write_Erase_Char (';');
651 Indent := Indent + 2;
654 Indent := Indent + 5;
657 Write_Str (" with ");
662 Sprint_Node (Identifier (A));
664 if Class_Present (A) then
665 Write_Str ("'Class");
668 if Present (Expression (A)) then
670 Sprint_Node (Expression (A));
684 Indent := Indent - 7;
687 end Sprint_Aspect_Specifications;
689 ---------------------
690 -- Sprint_Bar_List --
691 ---------------------
693 procedure Sprint_Bar_List (List : List_Id) is
696 if Is_Non_Empty_List (List) then
697 Node := First (List);
701 exit when Node = Empty;
707 ----------------------
708 -- Sprint_End_Label --
709 ----------------------
711 procedure Sprint_End_Label
717 and then Present (End_Label (Node))
718 and then Is_Entity_Name (End_Label (Node))
720 Set_Entity (End_Label (Node), Default);
722 -- For a function whose name is an operator, use the qualified name
723 -- created for the defining entity.
725 if Nkind (End_Label (Node)) = N_Operator_Symbol then
726 Set_Chars (End_Label (Node), Chars (Default));
729 Sprint_Node (End_Label (Node));
731 Sprint_Node (Default);
733 end Sprint_End_Label;
735 -----------------------
736 -- Sprint_Comma_List --
737 -----------------------
739 procedure Sprint_Comma_List (List : List_Id) is
743 if Is_Non_Empty_List (List) then
744 Node := First (List);
748 exit when Node = Empty;
750 if not Is_Rewrite_Insertion (Node)
751 or else not Dump_Original_Only
757 end Sprint_Comma_List;
759 --------------------------
760 -- Sprint_Indented_List --
761 --------------------------
763 procedure Sprint_Indented_List (List : List_Id) is
766 Sprint_Node_List (List);
768 end Sprint_Indented_List;
770 ---------------------
771 -- Sprint_Left_Opnd --
772 ---------------------
774 procedure Sprint_Left_Opnd (N : Node_Id) is
775 Opnd : constant Node_Id := Left_Opnd (N);
778 if Paren_Count (Opnd) /= 0
779 or else Op_Prec (Nkind (Opnd)) >= Op_Prec (Nkind (N))
788 end Sprint_Left_Opnd;
794 procedure Sprint_Node (Node : Node_Id) is
796 if Is_Rewrite_Insertion (Node) then
797 if not Dump_Original_Only then
799 -- For special cases of nodes that always output <<< >>>
800 -- do not duplicate the output at this point.
802 if Nkind (Node) = N_Freeze_Entity
803 or else Nkind (Node) = N_Freeze_Generic_Entity
804 or else Nkind (Node) = N_Implicit_Label_Declaration
806 Sprint_Node_Actual (Node);
808 -- Normal case where <<< >>> may be required
811 Write_Rewrite_Str ("<<<");
812 Sprint_Node_Actual (Node);
813 Write_Rewrite_Str (">>>");
817 elsif Is_Rewrite_Substitution (Node) then
819 -- Case of dump generated only
821 if Dump_Generated_Only then
822 Sprint_Node_Actual (Node);
824 -- Case of dump original only
826 elsif Dump_Original_Only then
827 Sprint_Node_Actual (Original_Node (Node));
829 -- Case of both being dumped
832 Sprint_Node_Actual (Original_Node (Node));
833 Write_Rewrite_Str ("<<<");
834 Sprint_Node_Actual (Node);
835 Write_Rewrite_Str (">>>");
839 Sprint_Node_Actual (Node);
843 ------------------------
844 -- Sprint_Node_Actual --
845 ------------------------
847 procedure Sprint_Node_Actual (Node : Node_Id) is
848 Save_Dump_Node : constant Node_Id := Dump_Node;
855 for J in 1 .. Paren_Count (Node) loop
856 Write_Str_With_Col_Check ("(");
859 -- Setup current dump node
863 if Nkind (Node) in N_Subexpr
864 and then Do_Range_Check (Node)
866 Write_Str_With_Col_Check ("{");
869 -- Select print circuit based on node kind
872 when N_Abort_Statement =>
873 Write_Indent_Str_Sloc ("abort ");
874 Sprint_Comma_List (Names (Node));
877 when N_Abortable_Part =>
879 Write_Str_Sloc ("abort ");
880 Sprint_Indented_List (Statements (Node));
882 when N_Abstract_Subprogram_Declaration =>
884 Sprint_Node (Specification (Node));
885 Write_Str_With_Col_Check (" is ");
886 Write_Str_Sloc ("abstract;");
888 when N_Accept_Alternative =>
889 Sprint_Node_List (Pragmas_Before (Node));
891 if Present (Condition (Node)) then
892 Write_Indent_Str ("when ");
893 Sprint_Node (Condition (Node));
898 Sprint_Node_Sloc (Accept_Statement (Node));
899 Sprint_Node_List (Statements (Node));
901 when N_Accept_Statement =>
902 Write_Indent_Str_Sloc ("accept ");
903 Write_Id (Entry_Direct_Name (Node));
905 if Present (Entry_Index (Node)) then
906 Write_Str_With_Col_Check (" (");
907 Sprint_Node (Entry_Index (Node));
911 Write_Param_Specs (Node);
913 if Present (Handled_Statement_Sequence (Node)) then
914 Write_Str_With_Col_Check (" do");
915 Sprint_Node (Handled_Statement_Sequence (Node));
916 Write_Indent_Str ("end ");
917 Write_Id (Entry_Direct_Name (Node));
922 when N_Access_Definition =>
926 if Present (Access_To_Subprogram_Definition (Node)) then
927 Sprint_Node (Access_To_Subprogram_Definition (Node));
931 if Null_Exclusion_Present (Node) then
932 Write_Str ("not null ");
935 Write_Str_With_Col_Check_Sloc ("access ");
937 if All_Present (Node) then
939 elsif Constant_Present (Node) then
940 Write_Str ("constant ");
943 Sprint_Node (Subtype_Mark (Node));
946 when N_Access_Function_Definition =>
950 if Null_Exclusion_Present (Node) then
951 Write_Str ("not null ");
954 Write_Str_With_Col_Check_Sloc ("access ");
956 if Protected_Present (Node) then
957 Write_Str_With_Col_Check ("protected ");
960 Write_Str_With_Col_Check ("function");
961 Write_Param_Specs (Node);
962 Write_Str_With_Col_Check (" return ");
963 Sprint_Node (Result_Definition (Node));
965 when N_Access_Procedure_Definition =>
969 if Null_Exclusion_Present (Node) then
970 Write_Str ("not null ");
973 Write_Str_With_Col_Check_Sloc ("access ");
975 if Protected_Present (Node) then
976 Write_Str_With_Col_Check ("protected ");
979 Write_Str_With_Col_Check ("procedure");
980 Write_Param_Specs (Node);
982 when N_Access_To_Object_Definition =>
983 Write_Str_With_Col_Check_Sloc ("access ");
985 if All_Present (Node) then
986 Write_Str_With_Col_Check ("all ");
987 elsif Constant_Present (Node) then
988 Write_Str_With_Col_Check ("constant ");
993 if Null_Exclusion_Present (Node) then
994 Write_Str ("not null ");
997 Sprint_Node (Subtype_Indication (Node));
1000 if Null_Record_Present (Node) then
1001 Write_Str_With_Col_Check_Sloc ("(null record)");
1004 Write_Str_With_Col_Check_Sloc ("(");
1006 if Present (Expressions (Node)) then
1007 Sprint_Comma_List (Expressions (Node));
1009 if Present (Component_Associations (Node))
1010 and then not Is_Empty_List (Component_Associations (Node))
1016 if Present (Component_Associations (Node))
1017 and then not Is_Empty_List (Component_Associations (Node))
1025 Nd := First (Component_Associations (Node));
1033 if not Is_Rewrite_Insertion (Nd)
1034 or else not Dump_Original_Only
1048 Write_Str_With_Col_Check_Sloc ("new ");
1050 -- Ada 2005 (AI-231)
1052 if Null_Exclusion_Present (Node) then
1053 Write_Str ("not null ");
1056 Sprint_Node (Expression (Node));
1058 if Present (Storage_Pool (Node)) then
1059 Write_Str_With_Col_Check ("[storage_pool = ");
1060 Sprint_Node (Storage_Pool (Node));
1065 Sprint_Left_Opnd (Node);
1066 Write_Str_Sloc (" and then ");
1067 Sprint_Right_Opnd (Node);
1069 -- Note: the following code for N_Aspect_Specification is not
1070 -- normally used, since we deal with aspects as part of a
1071 -- declaration, but it is here in case we deliberately try
1072 -- to print an N_Aspect_Speficiation node (e.g. from GDB).
1074 when N_Aspect_Specification =>
1075 Sprint_Node (Identifier (Node));
1077 Sprint_Node (Expression (Node));
1079 when N_Assignment_Statement =>
1081 Sprint_Node (Name (Node));
1082 Write_Str_Sloc (" := ");
1083 Sprint_Node (Expression (Node));
1086 when N_Asynchronous_Select =>
1087 Write_Indent_Str_Sloc ("select");
1089 Sprint_Node (Triggering_Alternative (Node));
1092 -- Note: let the printing of Abortable_Part handle outputting
1093 -- the ABORT keyword, so that the Sloc can be set correctly.
1095 Write_Indent_Str ("then ");
1096 Sprint_Node (Abortable_Part (Node));
1097 Write_Indent_Str ("end select;");
1100 Write_Indent_Str_Sloc ("for ");
1101 Write_Id (Identifier (Node));
1102 Write_Str_With_Col_Check (" use at ");
1103 Sprint_Node (Expression (Node));
1106 when N_Attribute_Definition_Clause =>
1107 Write_Indent_Str_Sloc ("for ");
1108 Sprint_Node (Name (Node));
1110 Write_Name_With_Col_Check (Chars (Node));
1111 Write_Str_With_Col_Check (" use ");
1112 Sprint_Node (Expression (Node));
1115 when N_Attribute_Reference =>
1116 if Is_Procedure_Attribute_Name (Attribute_Name (Node)) then
1120 Sprint_Node (Prefix (Node));
1121 Write_Char_Sloc (''');
1122 Write_Name_With_Col_Check (Attribute_Name (Node));
1123 Sprint_Paren_Comma_List (Expressions (Node));
1125 if Is_Procedure_Attribute_Name (Attribute_Name (Node)) then
1129 when N_Block_Statement =>
1132 if Present (Identifier (Node))
1133 and then (not Has_Created_Identifier (Node)
1134 or else not Dump_Original_Only)
1136 Write_Rewrite_Str ("<<<");
1137 Write_Id (Identifier (Node));
1139 Write_Rewrite_Str (">>>");
1142 if Present (Declarations (Node)) then
1143 Write_Str_With_Col_Check_Sloc ("declare");
1144 Sprint_Indented_List (Declarations (Node));
1148 Write_Str_With_Col_Check_Sloc ("begin");
1149 Sprint_Node (Handled_Statement_Sequence (Node));
1150 Write_Indent_Str ("end");
1152 if Present (Identifier (Node))
1153 and then (not Has_Created_Identifier (Node)
1154 or else not Dump_Original_Only)
1156 Write_Rewrite_Str ("<<<");
1158 Write_Id (Identifier (Node));
1159 Write_Rewrite_Str (">>>");
1164 when N_Case_Expression =>
1166 Has_Parens : constant Boolean := Paren_Count (Node) > 0;
1170 -- The syntax for case_expression does not include parentheses,
1171 -- but sometimes parentheses are required, so unconditionally
1172 -- generate them here unless already present.
1174 if not Has_Parens then
1178 Write_Str_With_Col_Check_Sloc ("case ");
1179 Sprint_Node (Expression (Node));
1180 Write_Str_With_Col_Check (" is");
1182 Alt := First (Alternatives (Node));
1190 if not Has_Parens then
1195 when N_Case_Expression_Alternative =>
1196 Write_Str_With_Col_Check (" when ");
1197 Sprint_Bar_List (Discrete_Choices (Node));
1199 Sprint_Node (Expression (Node));
1201 when N_Case_Statement =>
1202 Write_Indent_Str_Sloc ("case ");
1203 Sprint_Node (Expression (Node));
1205 Sprint_Indented_List (Alternatives (Node));
1206 Write_Indent_Str ("end case;");
1208 when N_Case_Statement_Alternative =>
1209 Write_Indent_Str_Sloc ("when ");
1210 Sprint_Bar_List (Discrete_Choices (Node));
1212 Sprint_Indented_List (Statements (Node));
1214 when N_Character_Literal =>
1215 if Column > Sprint_Line_Limit - 2 then
1216 Write_Indent_Str (" ");
1219 Write_Char_Sloc (''');
1220 Write_Char_Code (UI_To_CC (Char_Literal_Value (Node)));
1223 when N_Code_Statement =>
1226 Sprint_Node (Expression (Node));
1229 when N_Compilation_Unit =>
1230 Sprint_Node_List (Context_Items (Node));
1231 Sprint_Opt_Node_List (Declarations (Aux_Decls_Node (Node)));
1233 if Private_Present (Node) then
1234 Write_Indent_Str ("private ");
1238 Sprint_Node_Sloc (Unit (Node));
1240 if Present (Actions (Aux_Decls_Node (Node)))
1242 Present (Pragmas_After (Aux_Decls_Node (Node)))
1247 Sprint_Opt_Node_List (Actions (Aux_Decls_Node (Node)));
1248 Sprint_Opt_Node_List (Pragmas_After (Aux_Decls_Node (Node)));
1250 when N_Compilation_Unit_Aux =>
1251 null; -- nothing to do, never used, see above
1253 when N_Component_Association =>
1255 Sprint_Bar_List (Choices (Node));
1258 -- Ada 2005 (AI-287): Print the box if present
1260 if Box_Present (Node) then
1261 Write_Str_With_Col_Check ("<>");
1263 Sprint_Node (Expression (Node));
1266 when N_Component_Clause =>
1268 Sprint_Node (Component_Name (Node));
1269 Write_Str_Sloc (" at ");
1270 Sprint_Node (Position (Node));
1272 Write_Str_With_Col_Check ("range ");
1273 Sprint_Node (First_Bit (Node));
1275 Sprint_Node (Last_Bit (Node));
1278 when N_Component_Definition =>
1281 -- Ada 2005 (AI-230): Access definition components
1283 if Present (Access_Definition (Node)) then
1284 Sprint_Node (Access_Definition (Node));
1286 elsif Present (Subtype_Indication (Node)) then
1287 if Aliased_Present (Node) then
1288 Write_Str_With_Col_Check ("aliased ");
1291 -- Ada 2005 (AI-231)
1293 if Null_Exclusion_Present (Node) then
1294 Write_Str (" not null ");
1297 Sprint_Node (Subtype_Indication (Node));
1300 Write_Str (" ??? ");
1303 when N_Component_Declaration =>
1304 if Write_Indent_Identifiers_Sloc (Node) then
1306 Sprint_Node (Component_Definition (Node));
1308 if Present (Expression (Node)) then
1310 Sprint_Node (Expression (Node));
1316 when N_Component_List =>
1317 if Null_Present (Node) then
1319 Write_Indent_Str_Sloc ("null");
1325 Sprint_Indented_List (Component_Items (Node));
1326 Sprint_Node (Variant_Part (Node));
1329 when N_Compound_Statement =>
1330 Write_Indent_Str ("do");
1332 Sprint_Node_List (Actions (Node));
1334 Write_Indent_Str ("end;");
1336 when N_Conditional_Entry_Call =>
1337 Write_Indent_Str_Sloc ("select");
1339 Sprint_Node (Entry_Call_Alternative (Node));
1341 Write_Indent_Str ("else");
1342 Sprint_Indented_List (Else_Statements (Node));
1343 Write_Indent_Str ("end select;");
1345 when N_Constrained_Array_Definition =>
1346 Write_Str_With_Col_Check_Sloc ("array ");
1347 Sprint_Paren_Comma_List (Discrete_Subtype_Definitions (Node));
1350 Sprint_Node (Component_Definition (Node));
1352 -- A contract node should not appear in the tree. It is a semantic
1353 -- node attached to entry and [generic] subprogram entities.
1356 raise Program_Error;
1358 when N_Decimal_Fixed_Point_Definition =>
1359 Write_Str_With_Col_Check_Sloc (" delta ");
1360 Sprint_Node (Delta_Expression (Node));
1361 Write_Str_With_Col_Check ("digits ");
1362 Sprint_Node (Digits_Expression (Node));
1363 Sprint_Opt_Node (Real_Range_Specification (Node));
1365 when N_Defining_Character_Literal =>
1366 Write_Name_With_Col_Check_Sloc (Chars (Node));
1368 when N_Defining_Identifier =>
1372 when N_Defining_Operator_Symbol =>
1373 Write_Name_With_Col_Check_Sloc (Chars (Node));
1375 when N_Defining_Program_Unit_Name =>
1377 Sprint_Node (Name (Node));
1379 Write_Id (Defining_Identifier (Node));
1381 when N_Delay_Alternative =>
1382 Sprint_Node_List (Pragmas_Before (Node));
1384 if Present (Condition (Node)) then
1386 Write_Str_With_Col_Check ("when ");
1387 Sprint_Node (Condition (Node));
1392 Sprint_Node_Sloc (Delay_Statement (Node));
1393 Sprint_Node_List (Statements (Node));
1395 when N_Delay_Relative_Statement =>
1396 Write_Indent_Str_Sloc ("delay ");
1397 Sprint_Node (Expression (Node));
1400 when N_Delay_Until_Statement =>
1401 Write_Indent_Str_Sloc ("delay until ");
1402 Sprint_Node (Expression (Node));
1405 when N_Delta_Constraint =>
1406 Write_Str_With_Col_Check_Sloc ("delta ");
1407 Sprint_Node (Delta_Expression (Node));
1408 Sprint_Opt_Node (Range_Constraint (Node));
1410 when N_Derived_Type_Definition =>
1411 if Abstract_Present (Node) then
1412 Write_Str_With_Col_Check ("abstract ");
1415 Write_Str_With_Col_Check ("new ");
1417 -- Ada 2005 (AI-231)
1419 if Null_Exclusion_Present (Node) then
1420 Write_Str_With_Col_Check ("not null ");
1423 Sprint_Node (Subtype_Indication (Node));
1425 if Present (Interface_List (Node)) then
1426 Write_Str_With_Col_Check (" and ");
1427 Sprint_And_List (Interface_List (Node));
1428 Write_Str_With_Col_Check (" with ");
1431 if Present (Record_Extension_Part (Node)) then
1432 if No (Interface_List (Node)) then
1433 Write_Str_With_Col_Check (" with ");
1436 Sprint_Node (Record_Extension_Part (Node));
1439 when N_Designator =>
1440 Sprint_Node (Name (Node));
1441 Write_Char_Sloc ('.');
1442 Write_Id (Identifier (Node));
1444 when N_Digits_Constraint =>
1445 Write_Str_With_Col_Check_Sloc ("digits ");
1446 Sprint_Node (Digits_Expression (Node));
1447 Sprint_Opt_Node (Range_Constraint (Node));
1449 when N_Discriminant_Association =>
1452 if Present (Selector_Names (Node)) then
1453 Sprint_Bar_List (Selector_Names (Node));
1458 Sprint_Node (Expression (Node));
1460 when N_Discriminant_Specification =>
1463 if Write_Identifiers (Node) then
1466 if Null_Exclusion_Present (Node) then
1467 Write_Str ("not null ");
1470 Sprint_Node (Discriminant_Type (Node));
1472 if Present (Expression (Node)) then
1474 Sprint_Node (Expression (Node));
1480 when N_Elsif_Part =>
1481 Write_Indent_Str_Sloc ("elsif ");
1482 Sprint_Node (Condition (Node));
1483 Write_Str_With_Col_Check (" then");
1484 Sprint_Indented_List (Then_Statements (Node));
1489 when N_Entry_Body =>
1490 Write_Indent_Str_Sloc ("entry ");
1491 Write_Id (Defining_Identifier (Node));
1492 Sprint_Node (Entry_Body_Formal_Part (Node));
1493 Write_Str_With_Col_Check (" is");
1494 Sprint_Indented_List (Declarations (Node));
1495 Write_Indent_Str ("begin");
1496 Sprint_Node (Handled_Statement_Sequence (Node));
1497 Write_Indent_Str ("end ");
1498 Write_Id (Defining_Identifier (Node));
1501 when N_Entry_Body_Formal_Part =>
1502 if Present (Entry_Index_Specification (Node)) then
1503 Write_Str_With_Col_Check_Sloc (" (");
1504 Sprint_Node (Entry_Index_Specification (Node));
1508 Write_Param_Specs (Node);
1509 Write_Str_With_Col_Check_Sloc (" when ");
1510 Sprint_Node (Condition (Node));
1512 when N_Entry_Call_Alternative =>
1513 Sprint_Node_List (Pragmas_Before (Node));
1514 Sprint_Node_Sloc (Entry_Call_Statement (Node));
1515 Sprint_Node_List (Statements (Node));
1517 when N_Entry_Call_Statement =>
1519 Sprint_Node_Sloc (Name (Node));
1520 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
1523 when N_Entry_Declaration =>
1524 Write_Indent_Str_Sloc ("entry ");
1525 Write_Id (Defining_Identifier (Node));
1527 if Present (Discrete_Subtype_Definition (Node)) then
1528 Write_Str_With_Col_Check (" (");
1529 Sprint_Node (Discrete_Subtype_Definition (Node));
1533 Write_Param_Specs (Node);
1536 when N_Entry_Index_Specification =>
1537 Write_Str_With_Col_Check_Sloc ("for ");
1538 Write_Id (Defining_Identifier (Node));
1539 Write_Str_With_Col_Check (" in ");
1540 Sprint_Node (Discrete_Subtype_Definition (Node));
1542 when N_Enumeration_Representation_Clause =>
1543 Write_Indent_Str_Sloc ("for ");
1544 Write_Id (Identifier (Node));
1545 Write_Str_With_Col_Check (" use ");
1546 Sprint_Node (Array_Aggregate (Node));
1549 when N_Enumeration_Type_Definition =>
1552 -- Skip attempt to print Literals field if it's not there and
1553 -- we are in package Standard (case of Character, which is
1554 -- handled specially (without an explicit literals list).
1556 if Sloc (Node) > Standard_Location
1557 or else Present (Literals (Node))
1559 Sprint_Paren_Comma_List (Literals (Node));
1563 Write_Str_With_Col_Check_Sloc ("<error>");
1565 when N_Exception_Declaration =>
1566 if Write_Indent_Identifiers (Node) then
1567 Write_Str_With_Col_Check (" : ");
1569 if Is_Statically_Allocated (Defining_Identifier (Node)) then
1570 Write_Str_With_Col_Check ("static ");
1573 Write_Str_Sloc ("exception");
1575 if Present (Expression (Node)) then
1577 Sprint_Node (Expression (Node));
1583 when N_Exception_Handler =>
1584 Write_Indent_Str_Sloc ("when ");
1586 if Present (Choice_Parameter (Node)) then
1587 Sprint_Node (Choice_Parameter (Node));
1591 Sprint_Bar_List (Exception_Choices (Node));
1593 Sprint_Indented_List (Statements (Node));
1595 when N_Exception_Renaming_Declaration =>
1598 Sprint_Node (Defining_Identifier (Node));
1599 Write_Str_With_Col_Check (" : exception renames ");
1600 Sprint_Node (Name (Node));
1603 when N_Exit_Statement =>
1604 Write_Indent_Str_Sloc ("exit");
1605 Sprint_Opt_Node (Name (Node));
1607 if Present (Condition (Node)) then
1608 Write_Str_With_Col_Check (" when ");
1609 Sprint_Node (Condition (Node));
1614 when N_Expanded_Name =>
1615 Sprint_Node (Prefix (Node));
1616 Write_Char_Sloc ('.');
1617 Sprint_Node (Selector_Name (Node));
1619 when N_Explicit_Dereference =>
1620 Sprint_Node (Prefix (Node));
1621 Write_Char_Sloc ('.');
1622 Write_Str_Sloc ("all");
1624 when N_Expression_With_Actions =>
1626 Write_Indent_Str_Sloc ("do ");
1628 Sprint_Node_List (Actions (Node));
1631 Write_Str_With_Col_Check_Sloc ("in ");
1632 Sprint_Node (Expression (Node));
1633 Write_Str_With_Col_Check (" end");
1637 when N_Expression_Function =>
1639 Sprint_Node_Sloc (Specification (Node));
1643 Sprint_Node (Expression (Node));
1647 when N_Extended_Return_Statement =>
1648 Write_Indent_Str_Sloc ("return ");
1649 Sprint_Node_List (Return_Object_Declarations (Node));
1651 if Present (Handled_Statement_Sequence (Node)) then
1652 Write_Str_With_Col_Check (" do");
1653 Sprint_Node (Handled_Statement_Sequence (Node));
1654 Write_Indent_Str ("end return;");
1656 Write_Indent_Str (";");
1659 when N_Extension_Aggregate =>
1660 Write_Str_With_Col_Check_Sloc ("(");
1661 Sprint_Node (Ancestor_Part (Node));
1662 Write_Str_With_Col_Check (" with ");
1664 if Null_Record_Present (Node) then
1665 Write_Str_With_Col_Check ("null record");
1667 if Present (Expressions (Node)) then
1668 Sprint_Comma_List (Expressions (Node));
1670 if Present (Component_Associations (Node)) then
1675 if Present (Component_Associations (Node)) then
1676 Sprint_Comma_List (Component_Associations (Node));
1682 when N_Floating_Point_Definition =>
1683 Write_Str_With_Col_Check_Sloc ("digits ");
1684 Sprint_Node (Digits_Expression (Node));
1685 Sprint_Opt_Node (Real_Range_Specification (Node));
1687 when N_Formal_Decimal_Fixed_Point_Definition =>
1688 Write_Str_With_Col_Check_Sloc ("delta <> digits <>");
1690 when N_Formal_Derived_Type_Definition =>
1691 Write_Str_With_Col_Check_Sloc ("new ");
1692 Sprint_Node (Subtype_Mark (Node));
1694 if Present (Interface_List (Node)) then
1695 Write_Str_With_Col_Check (" and ");
1696 Sprint_And_List (Interface_List (Node));
1699 if Private_Present (Node) then
1700 Write_Str_With_Col_Check (" with private");
1703 when N_Formal_Abstract_Subprogram_Declaration =>
1704 Write_Indent_Str_Sloc ("with ");
1705 Sprint_Node (Specification (Node));
1707 Write_Str_With_Col_Check (" is abstract");
1709 if Box_Present (Node) then
1710 Write_Str_With_Col_Check (" <>");
1711 elsif Present (Default_Name (Node)) then
1712 Write_Str_With_Col_Check (" ");
1713 Sprint_Node (Default_Name (Node));
1718 when N_Formal_Concrete_Subprogram_Declaration =>
1719 Write_Indent_Str_Sloc ("with ");
1720 Sprint_Node (Specification (Node));
1722 if Box_Present (Node) then
1723 Write_Str_With_Col_Check (" is <>");
1724 elsif Present (Default_Name (Node)) then
1725 Write_Str_With_Col_Check (" is ");
1726 Sprint_Node (Default_Name (Node));
1731 when N_Formal_Discrete_Type_Definition =>
1732 Write_Str_With_Col_Check_Sloc ("<>");
1734 when N_Formal_Floating_Point_Definition =>
1735 Write_Str_With_Col_Check_Sloc ("digits <>");
1737 when N_Formal_Modular_Type_Definition =>
1738 Write_Str_With_Col_Check_Sloc ("mod <>");
1740 when N_Formal_Object_Declaration =>
1743 if Write_Indent_Identifiers (Node) then
1746 if In_Present (Node) then
1747 Write_Str_With_Col_Check ("in ");
1750 if Out_Present (Node) then
1751 Write_Str_With_Col_Check ("out ");
1754 if Present (Subtype_Mark (Node)) then
1756 -- Ada 2005 (AI-423): Formal object with null exclusion
1758 if Null_Exclusion_Present (Node) then
1759 Write_Str ("not null ");
1762 Sprint_Node (Subtype_Mark (Node));
1764 -- Ada 2005 (AI-423): Formal object with access definition
1767 pragma Assert (Present (Access_Definition (Node)));
1769 Sprint_Node (Access_Definition (Node));
1772 if Present (Default_Expression (Node)) then
1774 Sprint_Node (Default_Expression (Node));
1780 when N_Formal_Ordinary_Fixed_Point_Definition =>
1781 Write_Str_With_Col_Check_Sloc ("delta <>");
1783 when N_Formal_Package_Declaration =>
1784 Write_Indent_Str_Sloc ("with package ");
1785 Write_Id (Defining_Identifier (Node));
1786 Write_Str_With_Col_Check (" is new ");
1787 Sprint_Node (Name (Node));
1788 Write_Str_With_Col_Check (" (<>);");
1790 when N_Formal_Private_Type_Definition =>
1791 if Abstract_Present (Node) then
1792 Write_Str_With_Col_Check ("abstract ");
1795 if Tagged_Present (Node) then
1796 Write_Str_With_Col_Check ("tagged ");
1799 if Limited_Present (Node) then
1800 Write_Str_With_Col_Check ("limited ");
1803 Write_Str_With_Col_Check_Sloc ("private");
1805 when N_Formal_Incomplete_Type_Definition =>
1806 if Tagged_Present (Node) then
1807 Write_Str_With_Col_Check ("is tagged ");
1810 when N_Formal_Signed_Integer_Type_Definition =>
1811 Write_Str_With_Col_Check_Sloc ("range <>");
1813 when N_Formal_Type_Declaration =>
1814 Write_Indent_Str_Sloc ("type ");
1815 Write_Id (Defining_Identifier (Node));
1817 if Present (Discriminant_Specifications (Node)) then
1818 Write_Discr_Specs (Node);
1819 elsif Unknown_Discriminants_Present (Node) then
1820 Write_Str_With_Col_Check ("(<>)");
1823 if Nkind (Formal_Type_Definition (Node)) /=
1824 N_Formal_Incomplete_Type_Definition
1826 Write_Str_With_Col_Check (" is ");
1829 Sprint_Node (Formal_Type_Definition (Node));
1832 when N_Free_Statement =>
1833 Write_Indent_Str_Sloc ("free ");
1834 Sprint_Node (Expression (Node));
1837 when N_Freeze_Entity =>
1838 if Dump_Original_Only then
1841 -- A freeze node is output if it has some effect (i.e. non-empty
1842 -- actions, or freeze node for an itype, which causes elaboration
1843 -- of the itype), and is also always output if Dump_Freeze_Null
1846 elsif Present (Actions (Node))
1847 or else Is_Itype (Entity (Node))
1848 or else Dump_Freeze_Null
1851 Write_Rewrite_Str ("<<<");
1852 Write_Str_With_Col_Check_Sloc ("freeze ");
1853 Write_Id (Entity (Node));
1856 if No (Actions (Node)) then
1860 -- Output freeze actions. We increment Freeze_Indent during
1861 -- this output to avoid generating extra blank lines before
1862 -- any procedures included in the freeze actions.
1864 Freeze_Indent := Freeze_Indent + 1;
1865 Sprint_Indented_List (Actions (Node));
1866 Freeze_Indent := Freeze_Indent - 1;
1867 Write_Indent_Str ("]");
1870 Write_Rewrite_Str (">>>");
1873 when N_Freeze_Generic_Entity =>
1874 if Dump_Original_Only then
1879 Write_Str_With_Col_Check_Sloc ("freeze_generic ");
1880 Write_Id (Entity (Node));
1883 when N_Full_Type_Declaration =>
1884 Write_Indent_Str_Sloc ("type ");
1885 Sprint_Node (Defining_Identifier (Node));
1886 Write_Discr_Specs (Node);
1887 Write_Str_With_Col_Check (" is ");
1888 Sprint_Node (Type_Definition (Node));
1891 when N_Function_Call =>
1893 Write_Subprogram_Name (Name (Node));
1894 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
1896 when N_Function_Instantiation =>
1897 Write_Indent_Str_Sloc ("function ");
1898 Sprint_Node (Defining_Unit_Name (Node));
1899 Write_Str_With_Col_Check (" is new ");
1900 Sprint_Node (Name (Node));
1901 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
1904 when N_Function_Specification =>
1905 Write_Str_With_Col_Check_Sloc ("function ");
1906 Sprint_Node (Defining_Unit_Name (Node));
1907 Write_Param_Specs (Node);
1908 Write_Str_With_Col_Check (" return ");
1910 -- Ada 2005 (AI-231)
1912 if Nkind (Result_Definition (Node)) /= N_Access_Definition
1913 and then Null_Exclusion_Present (Node)
1915 Write_Str (" not null ");
1918 Sprint_Node (Result_Definition (Node));
1920 when N_Generic_Association =>
1923 if Present (Selector_Name (Node)) then
1924 Sprint_Node (Selector_Name (Node));
1928 Sprint_Node (Explicit_Generic_Actual_Parameter (Node));
1930 when N_Generic_Function_Renaming_Declaration =>
1931 Write_Indent_Str_Sloc ("generic function ");
1932 Sprint_Node (Defining_Unit_Name (Node));
1933 Write_Str_With_Col_Check (" renames ");
1934 Sprint_Node (Name (Node));
1937 when N_Generic_Package_Declaration =>
1939 Write_Indent_Str_Sloc ("generic ");
1940 Sprint_Indented_List (Generic_Formal_Declarations (Node));
1942 Sprint_Node (Specification (Node));
1945 when N_Generic_Package_Renaming_Declaration =>
1946 Write_Indent_Str_Sloc ("generic package ");
1947 Sprint_Node (Defining_Unit_Name (Node));
1948 Write_Str_With_Col_Check (" renames ");
1949 Sprint_Node (Name (Node));
1952 when N_Generic_Procedure_Renaming_Declaration =>
1953 Write_Indent_Str_Sloc ("generic procedure ");
1954 Sprint_Node (Defining_Unit_Name (Node));
1955 Write_Str_With_Col_Check (" renames ");
1956 Sprint_Node (Name (Node));
1959 when N_Generic_Subprogram_Declaration =>
1961 Write_Indent_Str_Sloc ("generic ");
1962 Sprint_Indented_List (Generic_Formal_Declarations (Node));
1964 Sprint_Node (Specification (Node));
1967 when N_Goto_Statement =>
1968 Write_Indent_Str_Sloc ("goto ");
1969 Sprint_Node (Name (Node));
1972 if Nkind (Next (Node)) = N_Label then
1976 when N_Handled_Sequence_Of_Statements =>
1978 Sprint_Indented_List (Statements (Node));
1980 if Present (Exception_Handlers (Node)) then
1981 Write_Indent_Str ("exception");
1983 Sprint_Node_List (Exception_Handlers (Node));
1987 if Present (At_End_Proc (Node)) then
1988 Write_Indent_Str ("at end");
1991 Sprint_Node (At_End_Proc (Node));
1996 when N_Identifier =>
2000 when N_If_Expression =>
2002 Has_Parens : constant Boolean := Paren_Count (Node) > 0;
2003 Condition : constant Node_Id := First (Expressions (Node));
2004 Then_Expr : constant Node_Id := Next (Condition);
2007 -- The syntax for if_expression does not include parentheses,
2008 -- but sometimes parentheses are required, so unconditionally
2009 -- generate them here unless already present.
2011 if not Has_Parens then
2015 Write_Str_With_Col_Check_Sloc ("if ");
2016 Sprint_Node (Condition);
2017 Write_Str_With_Col_Check (" then ");
2019 -- Defense against junk here
2021 if Present (Then_Expr) then
2022 Sprint_Node (Then_Expr);
2024 if Present (Next (Then_Expr)) then
2025 Write_Str_With_Col_Check (" else ");
2026 Sprint_Node (Next (Then_Expr));
2030 if not Has_Parens then
2035 when N_If_Statement =>
2036 Write_Indent_Str_Sloc ("if ");
2037 Sprint_Node (Condition (Node));
2038 Write_Str_With_Col_Check (" then");
2039 Sprint_Indented_List (Then_Statements (Node));
2040 Sprint_Opt_Node_List (Elsif_Parts (Node));
2042 if Present (Else_Statements (Node)) then
2043 Write_Indent_Str ("else");
2044 Sprint_Indented_List (Else_Statements (Node));
2047 Write_Indent_Str ("end if;");
2049 when N_Implicit_Label_Declaration =>
2050 if not Dump_Original_Only then
2052 Write_Rewrite_Str ("<<<");
2054 Write_Id (Defining_Identifier (Node));
2056 Write_Str_With_Col_Check ("label");
2057 Write_Rewrite_Str (">>>");
2061 Sprint_Left_Opnd (Node);
2062 Write_Str_Sloc (" in ");
2064 if Present (Right_Opnd (Node)) then
2065 Sprint_Right_Opnd (Node);
2067 Sprint_Bar_List (Alternatives (Node));
2070 when N_Incomplete_Type_Declaration =>
2071 Write_Indent_Str_Sloc ("type ");
2072 Write_Id (Defining_Identifier (Node));
2074 if Present (Discriminant_Specifications (Node)) then
2075 Write_Discr_Specs (Node);
2076 elsif Unknown_Discriminants_Present (Node) then
2077 Write_Str_With_Col_Check ("(<>)");
2082 when N_Index_Or_Discriminant_Constraint =>
2084 Sprint_Paren_Comma_List (Constraints (Node));
2086 when N_Indexed_Component =>
2087 Sprint_Node_Sloc (Prefix (Node));
2088 Sprint_Opt_Paren_Comma_List (Expressions (Node));
2090 when N_Integer_Literal =>
2091 if Print_In_Hex (Node) then
2092 Write_Uint_With_Col_Check_Sloc (Intval (Node), Hex);
2094 Write_Uint_With_Col_Check_Sloc (Intval (Node), Auto);
2097 when N_Iteration_Scheme =>
2098 if Present (Condition (Node)) then
2099 Write_Str_With_Col_Check_Sloc ("while ");
2100 Sprint_Node (Condition (Node));
2102 Write_Str_With_Col_Check_Sloc ("for ");
2104 if Present (Iterator_Specification (Node)) then
2105 Sprint_Node (Iterator_Specification (Node));
2107 Sprint_Node (Loop_Parameter_Specification (Node));
2113 when N_Iterator_Specification =>
2115 Write_Id (Defining_Identifier (Node));
2117 if Present (Subtype_Indication (Node)) then
2118 Write_Str_With_Col_Check (" : ");
2119 Sprint_Node (Subtype_Indication (Node));
2122 if Of_Present (Node) then
2123 Write_Str_With_Col_Check (" of ");
2125 Write_Str_With_Col_Check (" in ");
2128 if Reverse_Present (Node) then
2129 Write_Str_With_Col_Check ("reverse ");
2132 Sprint_Node (Name (Node));
2134 when N_Itype_Reference =>
2135 Write_Indent_Str_Sloc ("reference ");
2136 Write_Id (Itype (Node));
2139 Write_Indent_Str_Sloc ("<<");
2140 Write_Id (Identifier (Node));
2143 when N_Loop_Parameter_Specification =>
2145 Write_Id (Defining_Identifier (Node));
2146 Write_Str_With_Col_Check (" in ");
2148 if Reverse_Present (Node) then
2149 Write_Str_With_Col_Check ("reverse ");
2152 Sprint_Node (Discrete_Subtype_Definition (Node));
2154 when N_Loop_Statement =>
2157 if Present (Identifier (Node))
2158 and then (not Has_Created_Identifier (Node)
2159 or else not Dump_Original_Only)
2161 Write_Rewrite_Str ("<<<");
2162 Write_Id (Identifier (Node));
2164 Write_Rewrite_Str (">>>");
2165 Sprint_Node (Iteration_Scheme (Node));
2166 Write_Str_With_Col_Check_Sloc ("loop");
2167 Sprint_Indented_List (Statements (Node));
2168 Write_Indent_Str ("end loop ");
2169 Write_Rewrite_Str ("<<<");
2170 Write_Id (Identifier (Node));
2171 Write_Rewrite_Str (">>>");
2175 Sprint_Node (Iteration_Scheme (Node));
2176 Write_Str_With_Col_Check_Sloc ("loop");
2177 Sprint_Indented_List (Statements (Node));
2178 Write_Indent_Str ("end loop;");
2181 when N_Mod_Clause =>
2182 Sprint_Node_List (Pragmas_Before (Node));
2183 Write_Str_With_Col_Check_Sloc ("at mod ");
2184 Sprint_Node (Expression (Node));
2186 when N_Modular_Type_Definition =>
2187 Write_Str_With_Col_Check_Sloc ("mod ");
2188 Sprint_Node (Expression (Node));
2191 Sprint_Left_Opnd (Node);
2192 Write_Str_Sloc (" not in ");
2194 if Present (Right_Opnd (Node)) then
2195 Sprint_Right_Opnd (Node);
2197 Sprint_Bar_List (Alternatives (Node));
2201 Write_Str_With_Col_Check_Sloc ("null");
2203 when N_Null_Statement =>
2204 if Comes_From_Source (Node)
2205 or else Dump_Freeze_Null
2206 or else not Is_List_Member (Node)
2207 or else (No (Prev (Node)) and then No (Next (Node)))
2209 Write_Indent_Str_Sloc ("null;");
2212 when N_Number_Declaration =>
2215 if Write_Indent_Identifiers (Node) then
2216 Write_Str_With_Col_Check (" : constant ");
2218 Sprint_Node (Expression (Node));
2222 when N_Object_Declaration =>
2225 if Write_Indent_Identifiers (Node) then
2227 Def_Id : constant Entity_Id := Defining_Identifier (Node);
2230 Write_Str_With_Col_Check (" : ");
2232 if Is_Statically_Allocated (Def_Id) then
2233 Write_Str_With_Col_Check ("static ");
2236 if Aliased_Present (Node) then
2237 Write_Str_With_Col_Check ("aliased ");
2240 if Constant_Present (Node) then
2241 Write_Str_With_Col_Check ("constant ");
2244 -- Ada 2005 (AI-231)
2246 if Null_Exclusion_Present (Node) then
2247 Write_Str_With_Col_Check ("not null ");
2250 Sprint_Node (Object_Definition (Node));
2252 if Present (Expression (Node)) then
2254 Sprint_Node (Expression (Node));
2259 -- Handle implicit importation and implicit exportation of
2260 -- object declarations:
2261 -- $pragma import (Convention_Id, Def_Id, "...");
2262 -- $pragma export (Convention_Id, Def_Id, "...");
2264 if Is_Internal (Def_Id)
2265 and then Present (Interface_Name (Def_Id))
2267 Write_Indent_Str_Sloc ("$pragma ");
2269 if Is_Imported (Def_Id) then
2270 Write_Str ("import (");
2272 else pragma Assert (Is_Exported (Def_Id));
2273 Write_Str ("export (");
2277 Prefix : constant String := "Convention_";
2278 S : constant String := Convention (Def_Id)'Img;
2281 Name_Len := S'Last - Prefix'Last;
2282 Name_Buffer (1 .. Name_Len) :=
2283 S (Prefix'Last + 1 .. S'Last);
2284 Set_Casing (All_Lower_Case);
2285 Write_Str (Name_Buffer (1 .. Name_Len));
2291 Write_String_Table_Entry
2292 (Strval (Interface_Name (Def_Id)));
2298 when N_Object_Renaming_Declaration =>
2301 Sprint_Node (Defining_Identifier (Node));
2304 -- Ada 2005 (AI-230): Access renamings
2306 if Present (Access_Definition (Node)) then
2307 Sprint_Node (Access_Definition (Node));
2309 elsif Present (Subtype_Mark (Node)) then
2311 -- Ada 2005 (AI-423): Object renaming with a null exclusion
2313 if Null_Exclusion_Present (Node) then
2314 Write_Str ("not null ");
2317 Sprint_Node (Subtype_Mark (Node));
2320 Write_Str (" ??? ");
2323 Write_Str_With_Col_Check (" renames ");
2324 Sprint_Node (Name (Node));
2328 Write_Operator (Node, "abs ");
2329 Sprint_Right_Opnd (Node);
2332 Sprint_Left_Opnd (Node);
2333 Write_Operator (Node, " + ");
2334 Sprint_Right_Opnd (Node);
2337 Sprint_Left_Opnd (Node);
2338 Write_Operator (Node, " and ");
2339 Sprint_Right_Opnd (Node);
2342 Sprint_Left_Opnd (Node);
2343 Write_Operator (Node, " & ");
2344 Sprint_Right_Opnd (Node);
2347 Sprint_Left_Opnd (Node);
2349 Process_TFAI_RR_Flags (Node);
2350 Write_Operator (Node, "/ ");
2351 Sprint_Right_Opnd (Node);
2354 Sprint_Left_Opnd (Node);
2355 Write_Operator (Node, " = ");
2356 Sprint_Right_Opnd (Node);
2359 Sprint_Left_Opnd (Node);
2360 Write_Operator (Node, " ** ");
2361 Sprint_Right_Opnd (Node);
2364 Sprint_Left_Opnd (Node);
2365 Write_Operator (Node, " >= ");
2366 Sprint_Right_Opnd (Node);
2369 Sprint_Left_Opnd (Node);
2370 Write_Operator (Node, " > ");
2371 Sprint_Right_Opnd (Node);
2374 Sprint_Left_Opnd (Node);
2375 Write_Operator (Node, " <= ");
2376 Sprint_Right_Opnd (Node);
2379 Sprint_Left_Opnd (Node);
2380 Write_Operator (Node, " < ");
2381 Sprint_Right_Opnd (Node);
2384 Write_Operator (Node, "-");
2385 Sprint_Right_Opnd (Node);
2388 Sprint_Left_Opnd (Node);
2390 if Treat_Fixed_As_Integer (Node) then
2394 Write_Operator (Node, " mod ");
2395 Sprint_Right_Opnd (Node);
2397 when N_Op_Multiply =>
2398 Sprint_Left_Opnd (Node);
2400 Process_TFAI_RR_Flags (Node);
2401 Write_Operator (Node, "* ");
2402 Sprint_Right_Opnd (Node);
2405 Sprint_Left_Opnd (Node);
2406 Write_Operator (Node, " /= ");
2407 Sprint_Right_Opnd (Node);
2410 Write_Operator (Node, "not ");
2411 Sprint_Right_Opnd (Node);
2414 Sprint_Left_Opnd (Node);
2415 Write_Operator (Node, " or ");
2416 Sprint_Right_Opnd (Node);
2419 Write_Operator (Node, "+");
2420 Sprint_Right_Opnd (Node);
2423 Sprint_Left_Opnd (Node);
2425 if Treat_Fixed_As_Integer (Node) then
2429 Write_Operator (Node, " rem ");
2430 Sprint_Right_Opnd (Node);
2436 Write_Str_With_Col_Check ("(");
2437 Sprint_Node (Left_Opnd (Node));
2439 Sprint_Node (Right_Opnd (Node));
2442 when N_Op_Subtract =>
2443 Sprint_Left_Opnd (Node);
2444 Write_Operator (Node, " - ");
2445 Sprint_Right_Opnd (Node);
2448 Sprint_Left_Opnd (Node);
2449 Write_Operator (Node, " xor ");
2450 Sprint_Right_Opnd (Node);
2452 when N_Operator_Symbol =>
2453 Write_Name_With_Col_Check_Sloc (Chars (Node));
2455 when N_Ordinary_Fixed_Point_Definition =>
2456 Write_Str_With_Col_Check_Sloc ("delta ");
2457 Sprint_Node (Delta_Expression (Node));
2458 Sprint_Opt_Node (Real_Range_Specification (Node));
2461 Sprint_Left_Opnd (Node);
2462 Write_Str_Sloc (" or else ");
2463 Sprint_Right_Opnd (Node);
2465 when N_Others_Choice =>
2466 if All_Others (Node) then
2467 Write_Str_With_Col_Check ("all ");
2470 Write_Str_With_Col_Check_Sloc ("others");
2472 when N_Package_Body =>
2474 Write_Indent_Str_Sloc ("package body ");
2475 Sprint_Node (Defining_Unit_Name (Node));
2477 Sprint_Indented_List (Declarations (Node));
2479 if Present (Handled_Statement_Sequence (Node)) then
2480 Write_Indent_Str ("begin");
2481 Sprint_Node (Handled_Statement_Sequence (Node));
2484 Write_Indent_Str ("end ");
2486 (Handled_Statement_Sequence (Node), Defining_Unit_Name (Node));
2489 when N_Package_Body_Stub =>
2490 Write_Indent_Str_Sloc ("package body ");
2491 Sprint_Node (Defining_Identifier (Node));
2492 Write_Str_With_Col_Check (" is separate;");
2494 when N_Package_Declaration =>
2497 Sprint_Node_Sloc (Specification (Node));
2500 -- If this is an instantiation, get the aspects from the original
2501 -- instantiation node.
2503 if Is_Generic_Instance (Defining_Entity (Node))
2504 and then Has_Aspects
2505 (Package_Instantiation (Defining_Entity (Node)))
2507 Sprint_Aspect_Specifications
2508 (Package_Instantiation (Defining_Entity (Node)),
2512 when N_Package_Instantiation =>
2514 Write_Indent_Str_Sloc ("package ");
2515 Sprint_Node (Defining_Unit_Name (Node));
2516 Write_Str (" is new ");
2517 Sprint_Node (Name (Node));
2518 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
2521 when N_Package_Renaming_Declaration =>
2522 Write_Indent_Str_Sloc ("package ");
2523 Sprint_Node (Defining_Unit_Name (Node));
2524 Write_Str_With_Col_Check (" renames ");
2525 Sprint_Node (Name (Node));
2528 when N_Package_Specification =>
2529 Write_Str_With_Col_Check_Sloc ("package ");
2530 Sprint_Node (Defining_Unit_Name (Node));
2532 if Nkind (Parent (Node)) = N_Generic_Package_Declaration
2533 and then Has_Aspects (Parent (Node))
2535 Sprint_Aspect_Specifications
2536 (Parent (Node), Semicolon => False);
2538 -- An instantiation is rewritten as a package declaration, but
2539 -- the aspects belong to the instantiation node.
2541 elsif Nkind (Parent (Node)) = N_Package_Declaration then
2543 Pack : constant Entity_Id := Defining_Entity (Node);
2546 if not Is_Generic_Instance (Pack) then
2547 if Has_Aspects (Parent (Node)) then
2548 Sprint_Aspect_Specifications
2549 (Parent (Node), Semicolon => False);
2556 Sprint_Indented_List (Visible_Declarations (Node));
2558 if Present (Private_Declarations (Node)) then
2559 Write_Indent_Str ("private");
2560 Sprint_Indented_List (Private_Declarations (Node));
2563 Write_Indent_Str ("end ");
2564 Sprint_Node (Defining_Unit_Name (Node));
2566 when N_Parameter_Association =>
2567 Sprint_Node_Sloc (Selector_Name (Node));
2569 Sprint_Node (Explicit_Actual_Parameter (Node));
2571 when N_Parameter_Specification =>
2574 if Write_Identifiers (Node) then
2577 if In_Present (Node) then
2578 Write_Str_With_Col_Check ("in ");
2581 if Out_Present (Node) then
2582 Write_Str_With_Col_Check ("out ");
2585 -- Ada 2005 (AI-231): Parameter specification may carry null
2586 -- exclusion. Do not print it now if this is an access formal,
2587 -- it is emitted when the access definition is displayed.
2589 if Null_Exclusion_Present (Node)
2590 and then Nkind (Parameter_Type (Node))
2591 /= N_Access_Definition
2593 Write_Str ("not null ");
2596 Sprint_Node (Parameter_Type (Node));
2598 if Present (Expression (Node)) then
2600 Sprint_Node (Expression (Node));
2606 when N_Pop_Constraint_Error_Label =>
2607 Write_Indent_Str ("%pop_constraint_error_label");
2609 when N_Pop_Program_Error_Label =>
2610 Write_Indent_Str ("%pop_program_error_label");
2612 when N_Pop_Storage_Error_Label =>
2613 Write_Indent_Str ("%pop_storage_error_label");
2615 when N_Private_Extension_Declaration =>
2616 Write_Indent_Str_Sloc ("type ");
2617 Write_Id (Defining_Identifier (Node));
2619 if Present (Discriminant_Specifications (Node)) then
2620 Write_Discr_Specs (Node);
2621 elsif Unknown_Discriminants_Present (Node) then
2622 Write_Str_With_Col_Check ("(<>)");
2625 Write_Str_With_Col_Check (" is new ");
2626 Sprint_Node (Subtype_Indication (Node));
2628 if Present (Interface_List (Node)) then
2629 Write_Str_With_Col_Check (" and ");
2630 Sprint_And_List (Interface_List (Node));
2633 Write_Str_With_Col_Check (" with private;");
2635 when N_Private_Type_Declaration =>
2636 Write_Indent_Str_Sloc ("type ");
2637 Write_Id (Defining_Identifier (Node));
2639 if Present (Discriminant_Specifications (Node)) then
2640 Write_Discr_Specs (Node);
2641 elsif Unknown_Discriminants_Present (Node) then
2642 Write_Str_With_Col_Check ("(<>)");
2647 if Tagged_Present (Node) then
2648 Write_Str_With_Col_Check ("tagged ");
2651 if Limited_Present (Node) then
2652 Write_Str_With_Col_Check ("limited ");
2655 Write_Str_With_Col_Check ("private;");
2657 when N_Push_Constraint_Error_Label =>
2658 Write_Indent_Str ("%push_constraint_error_label (");
2660 if Present (Exception_Label (Node)) then
2661 Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2666 when N_Push_Program_Error_Label =>
2667 Write_Indent_Str ("%push_program_error_label (");
2669 if Present (Exception_Label (Node)) then
2670 Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2675 when N_Push_Storage_Error_Label =>
2676 Write_Indent_Str ("%push_storage_error_label (");
2678 if Present (Exception_Label (Node)) then
2679 Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2685 Write_Indent_Str_Sloc ("pragma ");
2686 Write_Name_With_Col_Check (Pragma_Name (Node));
2688 if Present (Pragma_Argument_Associations (Node)) then
2689 Sprint_Opt_Paren_Comma_List
2690 (Pragma_Argument_Associations (Node));
2695 when N_Pragma_Argument_Association =>
2698 if Chars (Node) /= No_Name then
2699 Write_Name_With_Col_Check (Chars (Node));
2703 Sprint_Node (Expression (Node));
2705 when N_Procedure_Call_Statement =>
2708 Write_Subprogram_Name (Name (Node));
2709 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
2712 when N_Procedure_Instantiation =>
2713 Write_Indent_Str_Sloc ("procedure ");
2714 Sprint_Node (Defining_Unit_Name (Node));
2715 Write_Str_With_Col_Check (" is new ");
2716 Sprint_Node (Name (Node));
2717 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
2720 when N_Procedure_Specification =>
2721 Write_Str_With_Col_Check_Sloc ("procedure ");
2722 Sprint_Node (Defining_Unit_Name (Node));
2723 Write_Param_Specs (Node);
2725 when N_Protected_Body =>
2726 Write_Indent_Str_Sloc ("protected body ");
2727 Write_Id (Defining_Identifier (Node));
2729 Sprint_Indented_List (Declarations (Node));
2730 Write_Indent_Str ("end ");
2731 Write_Id (Defining_Identifier (Node));
2734 when N_Protected_Body_Stub =>
2735 Write_Indent_Str_Sloc ("protected body ");
2736 Write_Id (Defining_Identifier (Node));
2737 Write_Str_With_Col_Check (" is separate;");
2739 when N_Protected_Definition =>
2741 Sprint_Indented_List (Visible_Declarations (Node));
2743 if Present (Private_Declarations (Node)) then
2744 Write_Indent_Str ("private");
2745 Sprint_Indented_List (Private_Declarations (Node));
2748 Write_Indent_Str ("end ");
2750 when N_Protected_Type_Declaration =>
2751 Write_Indent_Str_Sloc ("protected type ");
2752 Sprint_Node (Defining_Identifier (Node));
2753 Write_Discr_Specs (Node);
2755 if Present (Interface_List (Node)) then
2756 Write_Str (" is new ");
2757 Sprint_And_List (Interface_List (Node));
2758 Write_Str (" with ");
2763 Sprint_Node (Protected_Definition (Node));
2764 Write_Id (Defining_Identifier (Node));
2767 when N_Qualified_Expression =>
2768 Sprint_Node (Subtype_Mark (Node));
2769 Write_Char_Sloc (''');
2771 -- Print expression, make sure we have at least one level of
2772 -- parentheses around the expression. For cases of qualified
2773 -- expressions in the source, this is always the case, but
2774 -- for generated qualifications, there may be no explicit
2775 -- parentheses present.
2777 if Paren_Count (Expression (Node)) /= 0 then
2778 Sprint_Node (Expression (Node));
2782 Sprint_Node (Expression (Node));
2784 -- Odd case, for the qualified expressions used in machine
2785 -- code the argument may be a procedure call, resulting in
2786 -- a junk semicolon before the right parent, get rid of it.
2788 Write_Erase_Char (';');
2790 -- Now we can add the terminating right paren
2795 when N_Quantified_Expression =>
2798 if All_Present (Node) then
2799 Write_Str (" all ");
2801 Write_Str (" some ");
2804 if Present (Iterator_Specification (Node)) then
2805 Sprint_Node (Iterator_Specification (Node));
2807 Sprint_Node (Loop_Parameter_Specification (Node));
2811 Sprint_Node (Condition (Node));
2813 when N_Raise_Expression =>
2815 Has_Parens : constant Boolean := Paren_Count (Node) > 0;
2818 -- The syntax for raise_expression does not include parentheses
2819 -- but sometimes parentheses are required, so unconditionally
2820 -- generate them here unless already present.
2822 if not Has_Parens then
2826 Write_Str_With_Col_Check_Sloc ("raise ");
2827 Sprint_Node (Name (Node));
2829 if Present (Expression (Node)) then
2830 Write_Str_With_Col_Check (" with ");
2831 Sprint_Node (Expression (Node));
2834 if not Has_Parens then
2839 when N_Raise_Constraint_Error =>
2841 -- This node can be used either as a subexpression or as a
2842 -- statement form. The following test is a reasonably reliable
2843 -- way to distinguish the two cases.
2845 if Is_List_Member (Node)
2846 and then Nkind (Parent (Node)) not in N_Subexpr
2851 Write_Str_With_Col_Check_Sloc ("[constraint_error");
2852 Write_Condition_And_Reason (Node);
2854 when N_Raise_Program_Error =>
2856 -- This node can be used either as a subexpression or as a
2857 -- statement form. The following test is a reasonably reliable
2858 -- way to distinguish the two cases.
2860 if Is_List_Member (Node)
2861 and then Nkind (Parent (Node)) not in N_Subexpr
2866 Write_Str_With_Col_Check_Sloc ("[program_error");
2867 Write_Condition_And_Reason (Node);
2869 when N_Raise_Storage_Error =>
2871 -- This node can be used either as a subexpression or as a
2872 -- statement form. The following test is a reasonably reliable
2873 -- way to distinguish the two cases.
2875 if Is_List_Member (Node)
2876 and then Nkind (Parent (Node)) not in N_Subexpr
2881 Write_Str_With_Col_Check_Sloc ("[storage_error");
2882 Write_Condition_And_Reason (Node);
2884 when N_Raise_Statement =>
2885 Write_Indent_Str_Sloc ("raise ");
2886 Sprint_Node (Name (Node));
2890 Sprint_Node (Low_Bound (Node));
2891 Write_Str_Sloc (" .. ");
2892 Sprint_Node (High_Bound (Node));
2893 Update_Itype (Node);
2895 when N_Range_Constraint =>
2896 Write_Str_With_Col_Check_Sloc ("range ");
2897 Sprint_Node (Range_Expression (Node));
2899 when N_Real_Literal =>
2900 Write_Ureal_With_Col_Check_Sloc (Realval (Node));
2902 when N_Real_Range_Specification =>
2903 Write_Str_With_Col_Check_Sloc ("range ");
2904 Sprint_Node (Low_Bound (Node));
2906 Sprint_Node (High_Bound (Node));
2908 when N_Record_Definition =>
2909 if Abstract_Present (Node) then
2910 Write_Str_With_Col_Check ("abstract ");
2913 if Tagged_Present (Node) then
2914 Write_Str_With_Col_Check ("tagged ");
2917 if Limited_Present (Node) then
2918 Write_Str_With_Col_Check ("limited ");
2921 if Null_Present (Node) then
2922 Write_Str_With_Col_Check_Sloc ("null record");
2925 Write_Str_With_Col_Check_Sloc ("record");
2926 Sprint_Node (Component_List (Node));
2927 Write_Indent_Str ("end record");
2930 when N_Record_Representation_Clause =>
2931 Write_Indent_Str_Sloc ("for ");
2932 Sprint_Node (Identifier (Node));
2933 Write_Str_With_Col_Check (" use record ");
2935 if Present (Mod_Clause (Node)) then
2936 Sprint_Node (Mod_Clause (Node));
2939 Sprint_Indented_List (Component_Clauses (Node));
2940 Write_Indent_Str ("end record;");
2943 Sprint_Node (Prefix (Node));
2944 Write_Str_With_Col_Check_Sloc ("'reference");
2946 when N_Requeue_Statement =>
2947 Write_Indent_Str_Sloc ("requeue ");
2948 Sprint_Node (Name (Node));
2950 if Abort_Present (Node) then
2951 Write_Str_With_Col_Check (" with abort");
2956 -- Don't we want to print more detail???
2958 -- Doc of this extended syntax belongs in sinfo.ads and/or
2961 when N_SCIL_Dispatch_Table_Tag_Init =>
2962 Write_Indent_Str ("[N_SCIL_Dispatch_Table_Tag_Init]");
2964 when N_SCIL_Dispatching_Call =>
2965 Write_Indent_Str ("[N_SCIL_Dispatching_Node]");
2967 when N_SCIL_Membership_Test =>
2968 Write_Indent_Str ("[N_SCIL_Membership_Test]");
2970 when N_Simple_Return_Statement =>
2971 if Present (Expression (Node)) then
2972 Write_Indent_Str_Sloc ("return ");
2973 Sprint_Node (Expression (Node));
2976 Write_Indent_Str_Sloc ("return;");
2979 when N_Selective_Accept =>
2980 Write_Indent_Str_Sloc ("select");
2985 Alt_Node := First (Select_Alternatives (Node));
2988 Sprint_Node (Alt_Node);
2991 exit when No (Alt_Node);
2992 Write_Indent_Str ("or");
2996 if Present (Else_Statements (Node)) then
2997 Write_Indent_Str ("else");
2998 Sprint_Indented_List (Else_Statements (Node));
3001 Write_Indent_Str ("end select;");
3003 when N_Signed_Integer_Type_Definition =>
3004 Write_Str_With_Col_Check_Sloc ("range ");
3005 Sprint_Node (Low_Bound (Node));
3007 Sprint_Node (High_Bound (Node));
3009 when N_Single_Protected_Declaration =>
3010 Write_Indent_Str_Sloc ("protected ");
3011 Write_Id (Defining_Identifier (Node));
3013 Sprint_Node (Protected_Definition (Node));
3014 Write_Id (Defining_Identifier (Node));
3017 when N_Single_Task_Declaration =>
3018 Write_Indent_Str_Sloc ("task ");
3019 Sprint_Node (Defining_Identifier (Node));
3021 if Present (Task_Definition (Node)) then
3023 Sprint_Node (Task_Definition (Node));
3028 when N_Selected_Component =>
3029 Sprint_Node (Prefix (Node));
3030 Write_Char_Sloc ('.');
3031 Sprint_Node (Selector_Name (Node));
3035 Sprint_Node (Prefix (Node));
3036 Write_Str_With_Col_Check (" (");
3037 Sprint_Node (Discrete_Range (Node));
3040 when N_String_Literal =>
3041 if String_Length (Strval (Node)) + Column > Sprint_Line_Limit then
3042 Write_Indent_Str (" ");
3046 Write_String_Table_Entry (Strval (Node));
3048 when N_Subprogram_Body =>
3050 -- Output extra blank line unless we are in freeze actions
3052 if Freeze_Indent = 0 then
3058 if Present (Corresponding_Spec (Node)) then
3059 Sprint_Node_Sloc (Parent (Corresponding_Spec (Node)));
3061 Sprint_Node_Sloc (Specification (Node));
3066 Sprint_Indented_List (Declarations (Node));
3067 Write_Indent_Str ("begin");
3068 Sprint_Node (Handled_Statement_Sequence (Node));
3070 Write_Indent_Str ("end ");
3073 (Handled_Statement_Sequence (Node),
3074 Defining_Unit_Name (Specification (Node)));
3077 if Is_List_Member (Node)
3078 and then Present (Next (Node))
3079 and then Nkind (Next (Node)) /= N_Subprogram_Body
3084 when N_Subprogram_Body_Stub =>
3086 Sprint_Node_Sloc (Specification (Node));
3087 Write_Str_With_Col_Check (" is separate;");
3089 when N_Subprogram_Declaration =>
3091 Sprint_Node_Sloc (Specification (Node));
3093 if Nkind (Specification (Node)) = N_Procedure_Specification
3094 and then Null_Present (Specification (Node))
3096 Write_Str_With_Col_Check (" is null");
3101 when N_Subprogram_Renaming_Declaration =>
3103 Sprint_Node (Specification (Node));
3104 Write_Str_With_Col_Check_Sloc (" renames ");
3105 Sprint_Node (Name (Node));
3108 when N_Subtype_Declaration =>
3109 Write_Indent_Str_Sloc ("subtype ");
3110 Sprint_Node (Defining_Identifier (Node));
3113 -- Ada 2005 (AI-231)
3115 if Null_Exclusion_Present (Node) then
3116 Write_Str ("not null ");
3119 Sprint_Node (Subtype_Indication (Node));
3122 when N_Subtype_Indication =>
3123 Sprint_Node_Sloc (Subtype_Mark (Node));
3125 Sprint_Node (Constraint (Node));
3128 Write_Indent_Str_Sloc ("separate (");
3129 Sprint_Node (Name (Node));
3132 Sprint_Node (Proper_Body (Node));
3135 Write_Indent_Str_Sloc ("task body ");
3136 Write_Id (Defining_Identifier (Node));
3138 Sprint_Indented_List (Declarations (Node));
3139 Write_Indent_Str ("begin");
3140 Sprint_Node (Handled_Statement_Sequence (Node));
3141 Write_Indent_Str ("end ");
3143 (Handled_Statement_Sequence (Node), Defining_Identifier (Node));
3146 when N_Task_Body_Stub =>
3147 Write_Indent_Str_Sloc ("task body ");
3148 Write_Id (Defining_Identifier (Node));
3149 Write_Str_With_Col_Check (" is separate;");
3151 when N_Task_Definition =>
3153 Sprint_Indented_List (Visible_Declarations (Node));
3155 if Present (Private_Declarations (Node)) then
3156 Write_Indent_Str ("private");
3157 Sprint_Indented_List (Private_Declarations (Node));
3160 Write_Indent_Str ("end ");
3161 Sprint_End_Label (Node, Defining_Identifier (Parent (Node)));
3163 when N_Task_Type_Declaration =>
3164 Write_Indent_Str_Sloc ("task type ");
3165 Sprint_Node (Defining_Identifier (Node));
3166 Write_Discr_Specs (Node);
3168 if Present (Interface_List (Node)) then
3169 Write_Str (" is new ");
3170 Sprint_And_List (Interface_List (Node));
3173 if Present (Task_Definition (Node)) then
3174 if No (Interface_List (Node)) then
3177 Write_Str (" with ");
3180 Sprint_Node (Task_Definition (Node));
3185 when N_Terminate_Alternative =>
3186 Sprint_Node_List (Pragmas_Before (Node));
3189 if Present (Condition (Node)) then
3190 Write_Str_With_Col_Check ("when ");
3191 Sprint_Node (Condition (Node));
3195 Write_Str_With_Col_Check_Sloc ("terminate;");
3196 Sprint_Node_List (Pragmas_After (Node));
3198 when N_Timed_Entry_Call =>
3199 Write_Indent_Str_Sloc ("select");
3201 Sprint_Node (Entry_Call_Alternative (Node));
3203 Write_Indent_Str ("or");
3205 Sprint_Node (Delay_Alternative (Node));
3207 Write_Indent_Str ("end select;");
3209 when N_Triggering_Alternative =>
3210 Sprint_Node_List (Pragmas_Before (Node));
3211 Sprint_Node_Sloc (Triggering_Statement (Node));
3212 Sprint_Node_List (Statements (Node));
3214 when N_Type_Conversion =>
3216 Sprint_Node (Subtype_Mark (Node));
3219 if Conversion_OK (Node) then
3223 if Float_Truncate (Node) then
3227 if Rounded_Result (Node) then
3232 Sprint_Node (Expression (Node));
3235 when N_Unchecked_Expression =>
3238 Sprint_Node_Sloc (Expression (Node));
3241 when N_Unchecked_Type_Conversion =>
3242 Sprint_Node (Subtype_Mark (Node));
3244 Write_Str_With_Col_Check ("(");
3245 Sprint_Node_Sloc (Expression (Node));
3248 when N_Unconstrained_Array_Definition =>
3249 Write_Str_With_Col_Check_Sloc ("array (");
3254 Node1 := First (Subtype_Marks (Node));
3256 Sprint_Node (Node1);
3257 Write_Str_With_Col_Check (" range <>");
3259 exit when Node1 = Empty;
3264 Write_Str (") of ");
3265 Sprint_Node (Component_Definition (Node));
3267 when N_Unused_At_Start | N_Unused_At_End =>
3268 Write_Indent_Str ("***** Error, unused node encountered *****");
3271 when N_Use_Package_Clause =>
3272 Write_Indent_Str_Sloc ("use ");
3273 Sprint_Comma_List (Names (Node));
3276 when N_Use_Type_Clause =>
3277 Write_Indent_Str_Sloc ("use type ");
3278 Sprint_Comma_List (Subtype_Marks (Node));
3281 when N_Validate_Unchecked_Conversion =>
3282 Write_Indent_Str_Sloc ("validate unchecked_conversion (");
3283 Sprint_Node (Source_Type (Node));
3285 Sprint_Node (Target_Type (Node));
3289 Write_Indent_Str_Sloc ("when ");
3290 Sprint_Bar_List (Discrete_Choices (Node));
3292 Sprint_Node (Component_List (Node));
3294 when N_Variant_Part =>
3296 Write_Indent_Str_Sloc ("case ");
3297 Sprint_Node (Name (Node));
3299 Sprint_Indented_List (Variants (Node));
3300 Write_Indent_Str ("end case");
3303 when N_With_Clause =>
3305 -- Special test, if we are dumping the original tree only,
3306 -- then we want to eliminate the bogus with clauses that
3307 -- correspond to the non-existent children of Text_IO.
3309 if Dump_Original_Only
3310 and then Is_Text_IO_Special_Unit (Name (Node))
3314 -- Normal case, output the with clause
3317 if First_Name (Node) or else not Dump_Original_Only then
3319 -- Ada 2005 (AI-50217): Print limited with_clauses
3321 if Private_Present (Node) and Limited_Present (Node) then
3322 Write_Indent_Str ("limited private with ");
3324 elsif Private_Present (Node) then
3325 Write_Indent_Str ("private with ");
3327 elsif Limited_Present (Node) then
3328 Write_Indent_Str ("limited with ");
3331 Write_Indent_Str ("with ");
3338 Sprint_Node_Sloc (Name (Node));
3340 if Last_Name (Node) or else not Dump_Original_Only then
3346 -- Print aspects, except for special case of package declaration,
3347 -- where the aspects are printed inside the package specification.
3349 if Has_Aspects (Node)
3350 and then not Nkind_In (Node, N_Package_Declaration,
3351 N_Generic_Package_Declaration)
3353 Sprint_Aspect_Specifications (Node, Semicolon => True);
3356 if Nkind (Node) in N_Subexpr
3357 and then Do_Range_Check (Node)
3362 for J in 1 .. Paren_Count (Node) loop
3366 Dump_Node := Save_Dump_Node;
3367 end Sprint_Node_Actual;
3369 ----------------------
3370 -- Sprint_Node_List --
3371 ----------------------
3373 procedure Sprint_Node_List (List : List_Id; New_Lines : Boolean := False) is
3377 if Is_Non_Empty_List (List) then
3378 Node := First (List);
3383 exit when Node = Empty;
3387 if New_Lines and then Column /= 1 then
3390 end Sprint_Node_List;
3392 ----------------------
3393 -- Sprint_Node_Sloc --
3394 ----------------------
3396 procedure Sprint_Node_Sloc (Node : Node_Id) is
3400 if Debug_Generated_Code and then Present (Dump_Node) then
3401 Set_Sloc (Dump_Node, Sloc (Node));
3404 end Sprint_Node_Sloc;
3406 ---------------------
3407 -- Sprint_Opt_Node --
3408 ---------------------
3410 procedure Sprint_Opt_Node (Node : Node_Id) is
3412 if Present (Node) then
3416 end Sprint_Opt_Node;
3418 --------------------------
3419 -- Sprint_Opt_Node_List --
3420 --------------------------
3422 procedure Sprint_Opt_Node_List (List : List_Id) is
3424 if Present (List) then
3425 Sprint_Node_List (List);
3427 end Sprint_Opt_Node_List;
3429 ---------------------------------
3430 -- Sprint_Opt_Paren_Comma_List --
3431 ---------------------------------
3433 procedure Sprint_Opt_Paren_Comma_List (List : List_Id) is
3435 if Is_Non_Empty_List (List) then
3437 Sprint_Paren_Comma_List (List);
3439 end Sprint_Opt_Paren_Comma_List;
3441 -----------------------------
3442 -- Sprint_Paren_Comma_List --
3443 -----------------------------
3445 procedure Sprint_Paren_Comma_List (List : List_Id) is
3447 Node_Exists : Boolean := False;
3451 if Is_Non_Empty_List (List) then
3453 if Dump_Original_Only then
3455 while Present (N) loop
3456 if not Is_Rewrite_Insertion (N) then
3457 Node_Exists := True;
3464 if not Node_Exists then
3469 Write_Str_With_Col_Check ("(");
3470 Sprint_Comma_List (List);
3473 end Sprint_Paren_Comma_List;
3475 ----------------------
3476 -- Sprint_Right_Opnd --
3477 ----------------------
3479 procedure Sprint_Right_Opnd (N : Node_Id) is
3480 Opnd : constant Node_Id := Right_Opnd (N);
3483 if Paren_Count (Opnd) /= 0
3484 or else Op_Prec (Nkind (Opnd)) > Op_Prec (Nkind (N))
3493 end Sprint_Right_Opnd;
3499 procedure Update_Itype (Node : Node_Id) is
3501 if Present (Etype (Node))
3502 and then Is_Itype (Etype (Node))
3503 and then Debug_Generated_Code
3505 Set_Sloc (Etype (Node), Sloc (Node));
3509 ---------------------
3510 -- Write_Char_Sloc --
3511 ---------------------
3513 procedure Write_Char_Sloc (C : Character) is
3515 if Debug_Generated_Code and then C /= ' ' then
3520 end Write_Char_Sloc;
3522 --------------------------------
3523 -- Write_Condition_And_Reason --
3524 --------------------------------
3526 procedure Write_Condition_And_Reason (Node : Node_Id) is
3527 Cond : constant Node_Id := Condition (Node);
3528 Image : constant String := RT_Exception_Code'Image
3529 (RT_Exception_Code'Val
3530 (UI_To_Int (Reason (Node))));
3533 if Present (Cond) then
3535 -- If condition is a single entity, or NOT with a single entity,
3536 -- output all on one line, since it will likely fit just fine.
3538 if Is_Entity_Name (Cond)
3539 or else (Nkind (Cond) = N_Op_Not
3540 and then Is_Entity_Name (Right_Opnd (Cond)))
3542 Write_Str_With_Col_Check (" when ");
3546 -- Otherwise for more complex condition, multiple lines
3549 Write_Str_With_Col_Check (" when");
3550 Indent := Indent + 2;
3554 Indent := Indent - 2;
3557 -- If no condition, just need a space (all on one line)
3567 for J in 4 .. Image'Last loop
3568 if Image (J) = '_' then
3571 Write_Char (Fold_Lower (Image (J)));
3576 end Write_Condition_And_Reason;
3578 --------------------------------
3579 -- Write_Corresponding_Source --
3580 --------------------------------
3582 procedure Write_Corresponding_Source (S : String) is
3584 Src : Source_Buffer_Ptr;
3587 -- Ignore if not in dump source text mode, or if in freeze actions
3589 if Dump_Source_Text and then Freeze_Indent = 0 then
3591 -- Ignore null string
3597 -- Ignore space or semicolon at end of given string
3599 if S (S'Last) = ' ' or else S (S'Last) = ';' then
3600 Write_Corresponding_Source (S (S'First .. S'Last - 1));
3604 -- Loop to look at next lines not yet printed in source file
3607 Last_Line_Printed + 1 .. Last_Source_Line (Current_Source_File)
3609 Src := Source_Text (Current_Source_File);
3610 Loc := Line_Start (L, Current_Source_File);
3612 -- If comment, keep looking
3614 if Src (Loc .. Loc + 1) = "--" then
3617 -- Search to first non-blank
3620 while Src (Loc) not in Line_Terminator loop
3624 if Src (Loc) /= ' ' and then Src (Loc) /= ASCII.HT then
3626 -- Loop through characters in string to see if we match
3628 for J in S'Range loop
3630 -- If mismatch, then not the case we are looking for
3632 if Src (Loc) /= S (J) then
3639 -- If we fall through, string matched, if white space or
3640 -- semicolon after the matched string, this is the case
3641 -- we are looking for.
3643 if Src (Loc) in Line_Terminator
3644 or else Src (Loc) = ' '
3645 or else Src (Loc) = ASCII.HT
3646 or else Src (Loc) = ';'
3648 -- So output source lines up to and including this one
3650 Write_Source_Lines (L);
3659 -- Line was all blanks, or a comment line, keep looking
3663 end Write_Corresponding_Source;
3665 -----------------------
3666 -- Write_Discr_Specs --
3667 -----------------------
3669 procedure Write_Discr_Specs (N : Node_Id) is
3674 Specs := Discriminant_Specifications (N);
3676 if Present (Specs) then
3677 Write_Str_With_Col_Check (" (");
3678 Spec := First (Specs);
3683 exit when Spec = Empty;
3685 -- Add semicolon, unless we are printing original tree and the
3686 -- next specification is part of a list (but not the first
3687 -- element of that list)
3689 if not Dump_Original_Only or else not Prev_Ids (Spec) then
3696 end Write_Discr_Specs;
3702 procedure Write_Ekind (E : Entity_Id) is
3703 S : constant String := Entity_Kind'Image (Ekind (E));
3706 Name_Len := S'Length;
3707 Name_Buffer (1 .. Name_Len) := S;
3708 Set_Casing (Mixed_Case);
3709 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
3716 procedure Write_Id (N : Node_Id) is
3718 -- Deal with outputting Itype
3720 -- Note: if we are printing the full tree with -gnatds, then we may
3721 -- end up picking up the Associated_Node link from a generic template
3722 -- here which overlaps the Entity field, but as documented, Write_Itype
3723 -- is defended against junk calls.
3725 if Nkind (N) in N_Entity then
3727 elsif Nkind (N) in N_Has_Entity then
3728 Write_Itype (Entity (N));
3731 -- Case of a defining identifier
3733 if Nkind (N) = N_Defining_Identifier then
3735 -- If defining identifier has an interface name (and no
3736 -- address clause), then we output the interface name.
3738 if (Is_Imported (N) or else Is_Exported (N))
3739 and then Present (Interface_Name (N))
3740 and then No (Address_Clause (N))
3742 String_To_Name_Buffer (Strval (Interface_Name (N)));
3743 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
3745 -- If no interface name (or inactive because there was
3746 -- an address clause), then just output the Chars name.
3749 Write_Name_With_Col_Check (Chars (N));
3752 -- Case of selector of an expanded name where the expanded name
3753 -- has an associated entity, output this entity. Check that the
3754 -- entity or associated node is of the right kind, see above.
3756 elsif Nkind (Parent (N)) = N_Expanded_Name
3757 and then Selector_Name (Parent (N)) = N
3758 and then Present (Entity_Or_Associated_Node (Parent (N)))
3759 and then Nkind (Entity (Parent (N))) in N_Entity
3761 Write_Id (Entity (Parent (N)));
3763 -- For any other node with an associated entity, output it
3765 elsif Nkind (N) in N_Has_Entity
3766 and then Present (Entity_Or_Associated_Node (N))
3767 and then Nkind (Entity_Or_Associated_Node (N)) in N_Entity
3769 Write_Id (Entity (N));
3771 -- All other cases, we just print the Chars field
3774 Write_Name_With_Col_Check (Chars (N));
3778 -----------------------
3779 -- Write_Identifiers --
3780 -----------------------
3782 function Write_Identifiers (Node : Node_Id) return Boolean is
3784 Sprint_Node (Defining_Identifier (Node));
3785 Update_Itype (Defining_Identifier (Node));
3787 -- The remainder of the declaration must be printed unless we are
3788 -- printing the original tree and this is not the last identifier
3791 not Dump_Original_Only or else not More_Ids (Node);
3793 end Write_Identifiers;
3795 ------------------------
3796 -- Write_Implicit_Def --
3797 ------------------------
3799 procedure Write_Implicit_Def (E : Entity_Id) is
3804 when E_Array_Subtype =>
3805 Write_Str_With_Col_Check ("subtype ");
3807 Write_Str_With_Col_Check (" is ");
3808 Write_Id (Base_Type (E));
3809 Write_Str_With_Col_Check (" (");
3811 Ind := First_Index (E);
3812 while Present (Ind) loop
3816 if Present (Ind) then
3823 when E_Signed_Integer_Subtype | E_Enumeration_Subtype =>
3824 Write_Str_With_Col_Check ("subtype ");
3827 Write_Id (Etype (E));
3828 Write_Str_With_Col_Check (" range ");
3829 Sprint_Node (Scalar_Range (E));
3833 Write_Str_With_Col_Check ("type ");
3835 Write_Str_With_Col_Check (" is <");
3840 end Write_Implicit_Def;
3846 procedure Write_Indent is
3847 Loc : constant Source_Ptr := Sloc (Dump_Node);
3850 if Indent_Annull_Flag then
3851 Indent_Annull_Flag := False;
3853 -- Deal with Dump_Source_Text output. Note that we ignore implicit
3854 -- label declarations, since they typically have the sloc of the
3855 -- corresponding label, which really messes up the -gnatL output.
3858 and then Loc > No_Location
3859 and then Nkind (Dump_Node) /= N_Implicit_Label_Declaration
3861 if Get_Source_File_Index (Loc) = Current_Source_File then
3863 (Get_Physical_Line_Number (Sloc (Dump_Node)));
3869 for J in 1 .. Indent loop
3875 ------------------------------
3876 -- Write_Indent_Identifiers --
3877 ------------------------------
3879 function Write_Indent_Identifiers (Node : Node_Id) return Boolean is
3881 -- We need to start a new line for every node, except in the case
3882 -- where we are printing the original tree and this is not the first
3883 -- defining identifier in the list.
3885 if not Dump_Original_Only or else not Prev_Ids (Node) then
3888 -- If printing original tree and this is not the first defining
3889 -- identifier in the list, then the previous call to this procedure
3890 -- printed only the name, and we add a comma to separate the names.
3896 Sprint_Node (Defining_Identifier (Node));
3898 -- The remainder of the declaration must be printed unless we are
3899 -- printing the original tree and this is not the last identifier
3902 not Dump_Original_Only or else not More_Ids (Node);
3903 end Write_Indent_Identifiers;
3905 -----------------------------------
3906 -- Write_Indent_Identifiers_Sloc --
3907 -----------------------------------
3909 function Write_Indent_Identifiers_Sloc (Node : Node_Id) return Boolean is
3911 -- We need to start a new line for every node, except in the case
3912 -- where we are printing the original tree and this is not the first
3913 -- defining identifier in the list.
3915 if not Dump_Original_Only or else not Prev_Ids (Node) then
3918 -- If printing original tree and this is not the first defining
3919 -- identifier in the list, then the previous call to this procedure
3920 -- printed only the name, and we add a comma to separate the names.
3927 Sprint_Node (Defining_Identifier (Node));
3929 -- The remainder of the declaration must be printed unless we are
3930 -- printing the original tree and this is not the last identifier
3932 return not Dump_Original_Only or else not More_Ids (Node);
3933 end Write_Indent_Identifiers_Sloc;
3935 ----------------------
3936 -- Write_Indent_Str --
3937 ----------------------
3939 procedure Write_Indent_Str (S : String) is
3941 Write_Corresponding_Source (S);
3944 end Write_Indent_Str;
3946 ---------------------------
3947 -- Write_Indent_Str_Sloc --
3948 ---------------------------
3950 procedure Write_Indent_Str_Sloc (S : String) is
3952 Write_Corresponding_Source (S);
3955 end Write_Indent_Str_Sloc;
3961 procedure Write_Itype (Typ : Entity_Id) is
3963 procedure Write_Header (T : Boolean := True);
3964 -- Write type if T is True, subtype if T is false
3970 procedure Write_Header (T : Boolean := True) is
3973 Write_Str ("[type ");
3975 Write_Str ("[subtype ");
3978 Write_Name_With_Col_Check (Chars (Typ));
3982 -- Start of processing for Write_Itype
3985 if Nkind (Typ) in N_Entity
3986 and then Is_Itype (Typ)
3987 and then not Itype_Printed (Typ)
3989 -- Itype to be printed
3992 B : constant Node_Id := Etype (Typ);
3994 P : constant Node_Id := Parent (Typ);
3996 S : constant Saved_Output_Buffer := Save_Output_Buffer;
3997 -- Save current output buffer
3999 Old_Sloc : Source_Ptr;
4000 -- Save sloc of related node, so it is not modified when
4001 -- printing with -gnatD.
4004 -- Write indentation at start of line
4006 for J in 1 .. Indent loop
4010 -- If we have a constructed declaration for the itype, print it
4013 and then Nkind (P) in N_Declaration
4014 and then Defining_Entity (P) = Typ
4016 -- We must set Itype_Printed true before the recursive call to
4017 -- print the node, otherwise we get an infinite recursion.
4019 Set_Itype_Printed (Typ, True);
4021 -- Write the declaration enclosed in [], avoiding new line
4022 -- at start of declaration, and semicolon at end.
4024 -- Note: The itype may be imported from another unit, in which
4025 -- case we do not want to modify the Sloc of the declaration.
4026 -- Otherwise the itype may appear to be in the current unit,
4027 -- and the back-end will reject a reference out of scope.
4030 Indent_Annull_Flag := True;
4031 Old_Sloc := Sloc (P);
4033 Set_Sloc (P, Old_Sloc);
4034 Write_Erase_Char (';');
4036 -- If no constructed declaration, then we have to concoct the
4037 -- source corresponding to the type entity that we have at hand.
4042 -- Access types and subtypes
4045 Write_Header (Ekind (Typ) = E_Access_Type);
4047 if Can_Never_Be_Null (Typ) then
4048 Write_Str ("not null ");
4051 Write_Str ("access ");
4053 if Is_Access_Constant (Typ) then
4054 Write_Str ("constant ");
4057 Write_Id (Directly_Designated_Type (Typ));
4059 -- Array types and string types
4061 when E_Array_Type | E_String_Type =>
4063 Write_Str ("array (");
4065 X := First_Index (Typ);
4069 if not Is_Constrained (Typ) then
4070 Write_Str (" range <>");
4078 Write_Str (") of ");
4079 X := Component_Type (Typ);
4081 -- Preserve sloc of component type, which is defined
4082 -- elsewhere than the itype (see comment above).
4084 Old_Sloc := Sloc (X);
4086 Set_Sloc (X, Old_Sloc);
4088 -- Array subtypes and string subtypes.
4089 -- Preserve Sloc of index subtypes, as above.
4091 when E_Array_Subtype | E_String_Subtype =>
4092 Write_Header (False);
4093 Write_Id (Etype (Typ));
4096 X := First_Index (Typ);
4098 Old_Sloc := Sloc (X);
4100 Set_Sloc (X, Old_Sloc);
4108 -- Signed integer types, and modular integer subtypes,
4109 -- and also enumeration subtypes.
4111 when E_Signed_Integer_Type |
4112 E_Signed_Integer_Subtype |
4113 E_Modular_Integer_Subtype |
4114 E_Enumeration_Subtype =>
4116 Write_Header (Ekind (Typ) = E_Signed_Integer_Type);
4118 if Ekind (Typ) = E_Signed_Integer_Type then
4124 -- Print bounds if different from base type
4127 L : constant Node_Id := Type_Low_Bound (Typ);
4128 H : constant Node_Id := Type_High_Bound (Typ);
4133 -- B can either be a scalar type, in which case the
4134 -- declaration of Typ may constrain it with different
4135 -- bounds, or a private type, in which case we know
4136 -- that the declaration of Typ cannot have a scalar
4139 if Is_Scalar_Type (B) then
4140 LE := Type_Low_Bound (B);
4141 HE := Type_High_Bound (B);
4149 and then Nkind (L) = N_Integer_Literal
4150 and then Nkind (H) = N_Integer_Literal
4151 and then Nkind (LE) = N_Integer_Literal
4152 and then Nkind (HE) = N_Integer_Literal
4153 and then UI_Eq (Intval (L), Intval (LE))
4154 and then UI_Eq (Intval (H), Intval (HE)))
4159 Write_Str (" range ");
4160 Sprint_Node (Type_Low_Bound (Typ));
4162 Sprint_Node (Type_High_Bound (Typ));
4166 -- Modular integer types
4168 when E_Modular_Integer_Type =>
4171 Write_Uint_With_Col_Check (Modulus (Typ), Auto);
4173 -- Floating point types and subtypes
4175 when E_Floating_Point_Type |
4176 E_Floating_Point_Subtype =>
4178 Write_Header (Ekind (Typ) = E_Floating_Point_Type);
4180 if Ekind (Typ) = E_Floating_Point_Type then
4184 Write_Id (Etype (Typ));
4186 if Digits_Value (Typ) /= Digits_Value (Etype (Typ)) then
4187 Write_Str (" digits ");
4188 Write_Uint_With_Col_Check
4189 (Digits_Value (Typ), Decimal);
4192 -- Print bounds if not different from base type
4195 L : constant Node_Id := Type_Low_Bound (Typ);
4196 H : constant Node_Id := Type_High_Bound (Typ);
4197 LE : constant Node_Id := Type_Low_Bound (B);
4198 HE : constant Node_Id := Type_High_Bound (B);
4201 if Nkind (L) = N_Real_Literal
4202 and then Nkind (H) = N_Real_Literal
4203 and then Nkind (LE) = N_Real_Literal
4204 and then Nkind (HE) = N_Real_Literal
4205 and then UR_Eq (Realval (L), Realval (LE))
4206 and then UR_Eq (Realval (H), Realval (HE))
4211 Write_Str (" range ");
4212 Sprint_Node (Type_Low_Bound (Typ));
4214 Sprint_Node (Type_High_Bound (Typ));
4220 when E_Record_Subtype | E_Record_Subtype_With_Private =>
4221 Write_Header (False);
4222 Write_Str ("record");
4228 C := First_Entity (Typ);
4229 while Present (C) loop
4233 Write_Id (Etype (C));
4239 Write_Indent_Str (" end record");
4243 when E_Class_Wide_Type |
4244 E_Class_Wide_Subtype =>
4245 Write_Header (Ekind (Typ) = E_Class_Wide_Type);
4246 Write_Name_With_Col_Check (Chars (Etype (Typ)));
4247 Write_Str ("'Class");
4251 when E_Subprogram_Type =>
4254 if Etype (Typ) = Standard_Void_Type then
4255 Write_Str ("procedure");
4257 Write_Str ("function");
4260 if Present (First_Entity (Typ)) then
4267 Param := First_Entity (Typ);
4272 if Ekind (Param) = E_In_Out_Parameter then
4273 Write_Str ("in out ");
4274 elsif Ekind (Param) = E_Out_Parameter then
4278 Write_Id (Etype (Param));
4279 Next_Entity (Param);
4280 exit when No (Param);
4288 if Etype (Typ) /= Standard_Void_Type then
4289 Write_Str (" return ");
4290 Write_Id (Etype (Typ));
4293 when E_String_Literal_Subtype =>
4295 LB : constant Uint :=
4296 Expr_Value (String_Literal_Low_Bound (Typ));
4297 Len : constant Uint :=
4298 String_Literal_Length (Typ);
4300 Write_Str ("String (");
4301 Write_Int (UI_To_Int (LB));
4303 Write_Int (UI_To_Int (LB + Len) - 1);
4307 -- For all other Itypes, print ??? (fill in later)
4310 Write_Header (True);
4316 -- Add terminating bracket and restore output buffer
4320 Restore_Output_Buffer (S);
4323 Set_Itype_Printed (Typ);
4327 -------------------------------
4328 -- Write_Name_With_Col_Check --
4329 -------------------------------
4331 procedure Write_Name_With_Col_Check (N : Name_Id) is
4337 Get_Name_String (N);
4339 -- Deal with -gnatdI which replaces any sequence Cnnnb where C is an
4340 -- upper case letter, nnn is one or more digits and b is a lower case
4341 -- letter by C...b, so that listings do not depend on serial numbers.
4343 if Debug_Flag_II then
4345 while J < Name_Len - 1 loop
4346 if Name_Buffer (J) in 'A' .. 'Z'
4347 and then Name_Buffer (J + 1) in '0' .. '9'
4350 while K < Name_Len loop
4351 exit when Name_Buffer (K) not in '0' .. '9';
4355 if Name_Buffer (K) in 'a' .. 'z' then
4356 L := Name_Len - K + 1;
4358 Name_Buffer (J + 4 .. J + L + 3) :=
4359 Name_Buffer (K .. Name_Len);
4360 Name_Buffer (J + 1 .. J + 3) := "...";
4361 Name_Len := J + L + 3;
4374 -- Fall through for normal case
4376 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
4377 end Write_Name_With_Col_Check;
4379 ------------------------------------
4380 -- Write_Name_With_Col_Check_Sloc --
4381 ------------------------------------
4383 procedure Write_Name_With_Col_Check_Sloc (N : Name_Id) is
4385 Get_Name_String (N);
4386 Write_Str_With_Col_Check_Sloc (Name_Buffer (1 .. Name_Len));
4387 end Write_Name_With_Col_Check_Sloc;
4389 --------------------
4390 -- Write_Operator --
4391 --------------------
4393 procedure Write_Operator (N : Node_Id; S : String) is
4394 F : Natural := S'First;
4395 T : Natural := S'Last;
4398 -- If no overflow check, just write string out, and we are done
4400 if not Do_Overflow_Check (N) then
4403 -- If overflow check, we want to surround the operator with curly
4404 -- brackets, but not include spaces within the brackets.
4417 Write_Str_Sloc (S (F .. T));
4420 if S (S'Last) = ' ' then
4426 -----------------------
4427 -- Write_Param_Specs --
4428 -----------------------
4430 procedure Write_Param_Specs (N : Node_Id) is
4436 Specs := Parameter_Specifications (N);
4438 if Is_Non_Empty_List (Specs) then
4439 Write_Str_With_Col_Check (" (");
4440 Spec := First (Specs);
4444 Formal := Defining_Identifier (Spec);
4446 exit when Spec = Empty;
4448 -- Add semicolon, unless we are printing original tree and the
4449 -- next specification is part of a list (but not the first element
4452 if not Dump_Original_Only or else not Prev_Ids (Spec) then
4457 -- Write out any extra formals
4459 while Present (Extra_Formal (Formal)) loop
4460 Formal := Extra_Formal (Formal);
4462 Write_Name_With_Col_Check (Chars (Formal));
4464 Write_Name_With_Col_Check (Chars (Etype (Formal)));
4469 end Write_Param_Specs;
4471 -----------------------
4472 -- Write_Rewrite_Str --
4473 -----------------------
4475 procedure Write_Rewrite_Str (S : String) is
4477 if not Dump_Generated_Only then
4478 if S'Length = 3 and then S = ">>>" then
4481 Write_Str_With_Col_Check (S);
4484 end Write_Rewrite_Str;
4486 -----------------------
4487 -- Write_Source_Line --
4488 -----------------------
4490 procedure Write_Source_Line (L : Physical_Line_Number) is
4492 Src : Source_Buffer_Ptr;
4496 if Dump_Source_Text then
4497 Src := Source_Text (Current_Source_File);
4498 Loc := Line_Start (L, Current_Source_File);
4501 -- See if line is a comment line, if not, and if not line one,
4502 -- precede with blank line.
4505 while Src (Scn) = ' ' or else Src (Scn) = ASCII.HT loop
4509 if (Src (Scn) in Line_Terminator
4510 or else Src (Scn .. Scn + 1) /= "--")
4516 -- Now write the source text of the line
4519 Write_Int (Int (L));
4522 while Src (Loc) not in Line_Terminator loop
4523 Write_Char (Src (Loc));
4527 end Write_Source_Line;
4529 ------------------------
4530 -- Write_Source_Lines --
4531 ------------------------
4533 procedure Write_Source_Lines (L : Physical_Line_Number) is
4535 while Last_Line_Printed < L loop
4536 Last_Line_Printed := Last_Line_Printed + 1;
4537 Write_Source_Line (Last_Line_Printed);
4539 end Write_Source_Lines;
4541 --------------------
4542 -- Write_Str_Sloc --
4543 --------------------
4545 procedure Write_Str_Sloc (S : String) is
4547 for J in S'Range loop
4548 Write_Char_Sloc (S (J));
4552 ------------------------------
4553 -- Write_Str_With_Col_Check --
4554 ------------------------------
4556 procedure Write_Str_With_Col_Check (S : String) is
4558 if Int (S'Last) + Column > Sprint_Line_Limit then
4559 Write_Indent_Str (" ");
4561 if S (S'First) = ' ' then
4562 Write_Str (S (S'First + 1 .. S'Last));
4570 end Write_Str_With_Col_Check;
4572 -----------------------------------
4573 -- Write_Str_With_Col_Check_Sloc --
4574 -----------------------------------
4576 procedure Write_Str_With_Col_Check_Sloc (S : String) is
4578 if Int (S'Last) + Column > Sprint_Line_Limit then
4579 Write_Indent_Str (" ");
4581 if S (S'First) = ' ' then
4582 Write_Str_Sloc (S (S'First + 1 .. S'Last));
4590 end Write_Str_With_Col_Check_Sloc;
4592 ---------------------------
4593 -- Write_Subprogram_Name --
4594 ---------------------------
4596 procedure Write_Subprogram_Name (N : Node_Id) is
4598 if not Comes_From_Source (N)
4599 and then Is_Entity_Name (N)
4602 Ent : constant Entity_Id := Entity (N);
4604 if not In_Extended_Main_Source_Unit (Ent)
4606 Is_Predefined_File_Name
4607 (Unit_File_Name (Get_Source_Unit (Ent)))
4609 -- Run-time routine name, output name with a preceding dollar
4610 -- making sure that we do not get a line split between them.
4612 Col_Check (Length_Of_Name (Chars (Ent)) + 1);
4614 Write_Name (Chars (Ent));
4620 -- Normal case, not a run-time routine name
4623 end Write_Subprogram_Name;
4625 -------------------------------
4626 -- Write_Uint_With_Col_Check --
4627 -------------------------------
4629 procedure Write_Uint_With_Col_Check (U : Uint; Format : UI_Format) is
4631 Col_Check (UI_Decimal_Digits_Hi (U));
4632 UI_Write (U, Format);
4633 end Write_Uint_With_Col_Check;
4635 ------------------------------------
4636 -- Write_Uint_With_Col_Check_Sloc --
4637 ------------------------------------
4639 procedure Write_Uint_With_Col_Check_Sloc (U : Uint; Format : UI_Format) is
4641 Col_Check (UI_Decimal_Digits_Hi (U));
4643 UI_Write (U, Format);
4644 end Write_Uint_With_Col_Check_Sloc;
4646 -------------------------------------
4647 -- Write_Ureal_With_Col_Check_Sloc --
4648 -------------------------------------
4650 procedure Write_Ureal_With_Col_Check_Sloc (U : Ureal) is
4651 D : constant Uint := Denominator (U);
4652 N : constant Uint := Numerator (U);
4654 Col_Check (UI_Decimal_Digits_Hi (D) + UI_Decimal_Digits_Hi (N) + 4);
4656 UR_Write (U, Brackets => True);
4657 end Write_Ureal_With_Col_Check_Sloc;