PR target/79080
[official-gcc.git] / gcc / ada / sprint.adb
bloba357fb2da84a3af6beca8741587183d34cb538e5
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S P R I N T --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2016, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with Aspects; use Aspects;
27 with Atree; use Atree;
28 with Casing; use Casing;
29 with Csets; use Csets;
30 with Debug; use Debug;
31 with Einfo; use Einfo;
32 with Fname; use Fname;
33 with Lib; use Lib;
34 with Namet; use Namet;
35 with Nlists; use Nlists;
36 with Opt; use Opt;
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 First_Debug_Sloc : Source_Ptr;
62 -- Sloc of first byte of the current output file if we are generating a
63 -- source debug file.
65 Debug_Sloc : Source_Ptr;
66 -- Sloc of first byte of line currently being written if we are
67 -- generating a source debug file.
69 Dump_Original_Only : Boolean;
70 -- Set True if the -gnatdo (dump original tree) flag is set
72 Dump_Generated_Only : Boolean;
73 -- Set True if the -gnatdG (dump generated tree) debug flag is set
74 -- or for Print_Generated_Code (-gnatG) or Dump_Generated_Code (-gnatD).
76 Dump_Freeze_Null : Boolean;
77 -- Set True if empty freeze nodes and non-source null statements output.
78 -- Note that freeze nodes containing freeze actions are always output,
79 -- as are freeze nodes for itypes, which in general have the effect of
80 -- causing elaboration of the itype.
82 Freeze_Indent : Int := 0;
83 -- Keep track of freeze indent level (controls output of blank lines before
84 -- procedures within expression freeze actions). Relevant only if we are
85 -- not in Dump_Source_Text mode, since in Dump_Source_Text mode we don't
86 -- output these blank lines in any case.
88 Indent : Int := 0;
89 -- Number of columns for current line output indentation
91 Indent_Annull_Flag : Boolean := False;
92 -- Set True if subsequent Write_Indent call to be ignored, gets reset
93 -- by this call, so it is only active to suppress a single indent call.
95 Last_Line_Printed : Physical_Line_Number;
96 -- This keeps track of the physical line number of the last source line
97 -- that has been output. The value is only valid in Dump_Source_Text mode.
99 -------------------------------
100 -- Operator Precedence Table --
101 -------------------------------
103 -- This table is used to decide whether a subexpression needs to be
104 -- parenthesized. The rule is that if an operand of an operator (which
105 -- for this purpose includes AND THEN and OR ELSE) is itself an operator
106 -- with a lower precedence than the operator (or equal precedence if
107 -- appearing as the right operand), then parentheses are required.
109 Op_Prec : constant array (N_Subexpr) of Short_Short_Integer :=
110 (N_Op_And => 1,
111 N_Op_Or => 1,
112 N_Op_Xor => 1,
113 N_And_Then => 1,
114 N_Or_Else => 1,
116 N_In => 2,
117 N_Not_In => 2,
118 N_Op_Eq => 2,
119 N_Op_Ge => 2,
120 N_Op_Gt => 2,
121 N_Op_Le => 2,
122 N_Op_Lt => 2,
123 N_Op_Ne => 2,
125 N_Op_Add => 3,
126 N_Op_Concat => 3,
127 N_Op_Subtract => 3,
128 N_Op_Plus => 3,
129 N_Op_Minus => 3,
131 N_Op_Divide => 4,
132 N_Op_Mod => 4,
133 N_Op_Rem => 4,
134 N_Op_Multiply => 4,
136 N_Op_Expon => 5,
137 N_Op_Abs => 5,
138 N_Op_Not => 5,
140 others => 6);
142 procedure Sprint_Left_Opnd (N : Node_Id);
143 -- Print left operand of operator, parenthesizing if necessary
145 procedure Sprint_Right_Opnd (N : Node_Id);
146 -- Print right operand of operator, parenthesizing if necessary
148 -----------------------
149 -- Local Subprograms --
150 -----------------------
152 procedure Col_Check (N : Nat);
153 -- Check that at least N characters remain on current line, and if not,
154 -- then start an extra line with two characters extra indentation for
155 -- continuing text on the next line.
157 procedure Extra_Blank_Line;
158 -- In some situations we write extra blank lines to separate the generated
159 -- code to make it more readable. However, these extra blank lines are not
160 -- generated in Dump_Source_Text mode, since there the source text lines
161 -- output with preceding blank lines are quite sufficient as separators.
162 -- This procedure writes a blank line if Dump_Source_Text is False.
164 procedure Indent_Annull;
165 -- Causes following call to Write_Indent to be ignored. This is used when
166 -- a higher level node wants to stop a lower level node from starting a
167 -- new line, when it would otherwise be inclined to do so (e.g. the case
168 -- of an accept statement called from an accept alternative with a guard)
170 procedure Indent_Begin;
171 -- Increase indentation level
173 procedure Indent_End;
174 -- Decrease indentation level
176 procedure Print_Debug_Line (S : String);
177 -- Used to print output lines in Debug_Generated_Code mode (this is used
178 -- as the argument for a call to Set_Special_Output in package Output).
180 procedure Process_TFAI_RR_Flags (Nod : Node_Id);
181 -- Given a divide, multiplication or division node, check the flags
182 -- Treat_Fixed_As_Integer and Rounded_Flags, and if set, output the
183 -- appropriate special syntax characters (# and @).
185 procedure Set_Debug_Sloc;
186 -- If Dump_Node is non-empty, this routine sets the appropriate value
187 -- in its Sloc field, from the current location in the debug source file
188 -- that is currently being written.
190 procedure Sprint_And_List (List : List_Id);
191 -- Print the given list with items separated by vertical "and"
193 procedure Sprint_Aspect_Specifications
194 (Node : Node_Id;
195 Semicolon : Boolean);
196 -- Node is a declaration node that has aspect specifications (Has_Aspects
197 -- flag set True). It outputs the aspect specifications. For the case
198 -- of Semicolon = True, it is called after outputting the terminating
199 -- semicolon for the related node. The effect is to remove the semicolon
200 -- and print the aspect specifications followed by a terminating semicolon.
201 -- For the case of Semicolon False, no semicolon is removed or output, and
202 -- all the aspects are printed on a single line.
204 procedure Sprint_Bar_List (List : List_Id);
205 -- Print the given list with items separated by vertical bars
207 procedure Sprint_End_Label
208 (Node : Node_Id;
209 Default : Node_Id);
210 -- Print the end label for a Handled_Sequence_Of_Statements in a body.
211 -- If there is no end label, use the defining identifier of the enclosing
212 -- construct. If the end label is present, treat it as a reference to the
213 -- defining entity of the construct: this guarantees that it carries the
214 -- proper sloc information for debugging purposes.
216 procedure Sprint_Node_Actual (Node : Node_Id);
217 -- This routine prints its node argument. It is a lower level routine than
218 -- Sprint_Node, in that it does not bother about rewritten trees.
220 procedure Sprint_Node_Sloc (Node : Node_Id);
221 -- Like Sprint_Node, but in addition, in Debug_Generated_Code mode,
222 -- sets the Sloc of the current debug node to be a copy of the Sloc
223 -- of the sprinted node Node. Note that this is done after printing
224 -- Node, so that the Sloc is the proper updated value for the debug file.
226 procedure Update_Itype (Node : Node_Id);
227 -- Update the Sloc of an itype that is not attached to the tree, when
228 -- debugging expanded code. This routine is called from nodes whose
229 -- type can be an Itype, such as defining_identifiers that may be of
230 -- an anonymous access type, or ranges in slices.
232 procedure Write_Char_Sloc (C : Character);
233 -- Like Write_Char, except that if C is non-blank, Set_Debug_Sloc is
234 -- called to ensure that the current node has a proper Sloc set.
236 procedure Write_Condition_And_Reason (Node : Node_Id);
237 -- Write Condition and Reason codes of Raise_xxx_Error node
239 procedure Write_Corresponding_Source (S : String);
240 -- If S is a string with a single keyword (possibly followed by a space),
241 -- and if the next non-comment non-blank source line matches this keyword,
242 -- then output all source lines up to this matching line.
244 procedure Write_Discr_Specs (N : Node_Id);
245 -- Output discriminant specification for node, which is any of the type
246 -- declarations that can have discriminants.
248 procedure Write_Ekind (E : Entity_Id);
249 -- Write the String corresponding to the Ekind without "E_"
251 procedure Write_Id (N : Node_Id);
252 -- N is a node with a Chars field. This procedure writes the name that
253 -- will be used in the generated code associated with the name. For a
254 -- node with no associated entity, this is simply the Chars field. For
255 -- the case where there is an entity associated with the node, we print
256 -- the name associated with the entity (since it may have been encoded).
257 -- One other special case is that an entity has an active external name
258 -- (i.e. an external name present with no address clause), then this
259 -- external name is output. This procedure also deals with outputting
260 -- declarations of referenced itypes, if not output earlier.
262 function Write_Identifiers (Node : Node_Id) return Boolean;
263 -- Handle node where the grammar has a list of defining identifiers, but
264 -- the tree has a separate declaration for each identifier. Handles the
265 -- printing of the defining identifier, and returns True if the type and
266 -- initialization information is to be printed, False if it is to be
267 -- skipped (the latter case happens when printing defining identifiers
268 -- other than the first in the original tree output case).
270 procedure Write_Implicit_Def (E : Entity_Id);
271 pragma Warnings (Off, Write_Implicit_Def);
272 -- Write the definition of the implicit type E according to its Ekind
273 -- For now a debugging procedure, but might be used in the future.
275 procedure Write_Indent;
276 -- Start a new line and write indentation spacing
278 function Write_Indent_Identifiers (Node : Node_Id) return Boolean;
279 -- Like Write_Identifiers except that each new printed declaration
280 -- is at the start of a new line.
282 function Write_Indent_Identifiers_Sloc (Node : Node_Id) return Boolean;
283 -- Like Write_Indent_Identifiers except that in Debug_Generated_Code
284 -- mode, the Sloc of the current debug node is set to point to the
285 -- first output identifier.
287 procedure Write_Indent_Str (S : String);
288 -- Start a new line and write indent spacing followed by given string
290 procedure Write_Indent_Str_Sloc (S : String);
291 -- Like Write_Indent_Str, but in addition, in Debug_Generated_Code mode,
292 -- the Sloc of the current node is set to the first non-blank character
293 -- in the string S.
295 procedure Write_Itype (Typ : Entity_Id);
296 -- If Typ is an Itype that has not been written yet, write it. If Typ is
297 -- any other kind of entity or tree node, the call is ignored.
299 procedure Write_Name_With_Col_Check (N : Name_Id);
300 -- Write name (using Write_Name) with initial column check, and possible
301 -- initial Write_Indent (to get new line) if current line is too full.
303 procedure Write_Name_With_Col_Check_Sloc (N : Name_Id);
304 -- Like Write_Name_With_Col_Check but in addition, in Debug_Generated_Code
305 -- mode, sets Sloc of current debug node to first character of name.
307 procedure Write_Operator (N : Node_Id; S : String);
308 -- Like Write_Str_Sloc, used for operators, encloses the string in
309 -- characters {} if the Do_Overflow flag is set on the node N.
311 procedure Write_Param_Specs (N : Node_Id);
312 -- Output parameter specifications for node N (which is a subprogram, or
313 -- entry or entry family or access-subprogram-definition, all of which
314 -- have a Parameter_Specificatioons field).
316 procedure Write_Rewrite_Str (S : String);
317 -- Writes out a string (typically containing <<< or >>>}) for a node
318 -- created by rewriting the tree. Suppressed if we are outputting the
319 -- generated code only, since in this case we don't specially mark nodes
320 -- created by rewriting).
322 procedure Write_Source_Line (L : Physical_Line_Number);
323 -- If writing of interspersed source lines is enabled, then write the given
324 -- line from the source file, preceded by Eol, then an extra blank line if
325 -- the line has at least one blank, is not a comment and is not line one,
326 -- then "--" and the line number followed by period followed by text of the
327 -- source line (without terminating Eol). If interspersed source line
328 -- output not enabled, then the call has no effect.
330 procedure Write_Source_Lines (L : Physical_Line_Number);
331 -- If writing of interspersed source lines is enabled, then writes source
332 -- lines Last_Line_Printed + 1 .. L, and updates Last_Line_Printed. If
333 -- interspersed source line output not enabled, then call has no effect.
335 procedure Write_Str_Sloc (S : String);
336 -- Like Write_Str, but sets debug Sloc of current debug node to first
337 -- non-blank character if a current debug node is active.
339 procedure Write_Str_With_Col_Check (S : String);
340 -- Write string (using Write_Str) with initial column check, and possible
341 -- initial Write_Indent (to get new line) if current line is too full.
343 procedure Write_Str_With_Col_Check_Sloc (S : String);
344 -- Like Write_Str_With_Col_Check, but sets debug Sloc of current debug
345 -- node to first non-blank character if a current debug node is active.
347 procedure Write_Subprogram_Name (N : Node_Id);
348 -- N is the Name field of a function call or procedure statement call.
349 -- The effect of the call is to output the name, preceded by a $ if the
350 -- call is identified as an implicit call to a run time routine.
352 procedure Write_Uint_With_Col_Check (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).
357 procedure Write_Uint_With_Col_Check_Sloc (U : Uint; Format : UI_Format);
358 -- Write Uint (using UI_Write) with initial column check, and possible
359 -- initial Write_Indent (to get new line) if current line is too full.
360 -- The format parameter determines the output format (see UI_Write).
361 -- In addition, in Debug_Generated_Code mode, sets the current node
362 -- Sloc to the first character of the output value.
364 procedure Write_Ureal_With_Col_Check_Sloc (U : Ureal);
365 -- Write Ureal (using same output format as UR_Write) with column checks
366 -- and a possible initial Write_Indent (to get new line) if current line
367 -- is too full. In addition, in Debug_Generated_Code mode, sets the
368 -- current node Sloc to the first character of the output value.
370 ---------------
371 -- Col_Check --
372 ---------------
374 procedure Col_Check (N : Nat) is
375 begin
376 if N + Column > Sprint_Line_Limit then
377 Write_Indent_Str (" ");
378 end if;
379 end Col_Check;
381 ----------------------
382 -- Extra_Blank_Line --
383 ----------------------
385 procedure Extra_Blank_Line is
386 begin
387 if not Dump_Source_Text then
388 Write_Indent;
389 end if;
390 end Extra_Blank_Line;
392 -------------------
393 -- Indent_Annull --
394 -------------------
396 procedure Indent_Annull is
397 begin
398 Indent_Annull_Flag := True;
399 end Indent_Annull;
401 ------------------
402 -- Indent_Begin --
403 ------------------
405 procedure Indent_Begin is
406 begin
407 Indent := Indent + 3;
408 end Indent_Begin;
410 ----------------
411 -- Indent_End --
412 ----------------
414 procedure Indent_End is
415 begin
416 Indent := Indent - 3;
417 end Indent_End;
419 --------
420 -- pg --
421 --------
423 procedure pg (Arg : Union_Id) is
424 begin
425 Dump_Generated_Only := True;
426 Dump_Original_Only := False;
427 Dump_Freeze_Null := True;
428 Current_Source_File := No_Source_File;
430 if Arg in List_Range then
431 Sprint_Node_List (List_Id (Arg), New_Lines => True);
433 elsif Arg in Node_Range then
434 Sprint_Node (Node_Id (Arg));
436 else
437 null;
438 end if;
440 Write_Eol;
441 end pg;
443 --------
444 -- po --
445 --------
447 procedure po (Arg : Union_Id) is
448 begin
449 Dump_Generated_Only := False;
450 Dump_Original_Only := True;
451 Current_Source_File := No_Source_File;
453 if Arg in List_Range then
454 Sprint_Node_List (List_Id (Arg), New_Lines => True);
456 elsif Arg in Node_Range then
457 Sprint_Node (Node_Id (Arg));
459 else
460 null;
461 end if;
463 Write_Eol;
464 end po;
466 ----------------------
467 -- Print_Debug_Line --
468 ----------------------
470 procedure Print_Debug_Line (S : String) is
471 begin
472 Write_Debug_Line (S, Debug_Sloc);
473 end Print_Debug_Line;
475 ---------------------------
476 -- Process_TFAI_RR_Flags --
477 ---------------------------
479 procedure Process_TFAI_RR_Flags (Nod : Node_Id) is
480 begin
481 if Treat_Fixed_As_Integer (Nod) then
482 Write_Char ('#');
483 end if;
485 if Rounded_Result (Nod) then
486 Write_Char ('@');
487 end if;
488 end Process_TFAI_RR_Flags;
490 --------
491 -- ps --
492 --------
494 procedure ps (Arg : Union_Id) is
495 begin
496 Dump_Generated_Only := False;
497 Dump_Original_Only := False;
498 Current_Source_File := No_Source_File;
500 if Arg in List_Range then
501 Sprint_Node_List (List_Id (Arg), New_Lines => True);
503 elsif Arg in Node_Range then
504 Sprint_Node (Node_Id (Arg));
506 else
507 null;
508 end if;
510 Write_Eol;
511 end ps;
513 --------------------
514 -- Set_Debug_Sloc --
515 --------------------
517 procedure Set_Debug_Sloc is
518 begin
519 if Debug_Generated_Code and then Present (Dump_Node) then
520 declare
521 Loc : constant Source_Ptr := Sloc (Dump_Node);
523 begin
524 -- Do not change the location of nodes defined in package Standard
525 -- and nodes of pragmas scanned by Targparm.
527 if Loc <= Standard_Location then
528 null;
530 -- Update the location of a node which is part of the current .dg
531 -- output. This situation occurs in comma separated parameter
532 -- declarations since each parameter references the same parameter
533 -- type node (ie. obj1, obj2 : <param-type>).
535 -- Note: This case is needed here since we cannot use the routine
536 -- In_Extended_Main_Code_Unit with nodes whose location is a .dg
537 -- file.
539 elsif Loc >= First_Debug_Sloc then
540 Set_Sloc (Dump_Node, Debug_Sloc + Source_Ptr (Column - 1));
542 -- Do not change the location of nodes which are not part of the
543 -- generated code
545 elsif not In_Extended_Main_Code_Unit (Loc) then
546 null;
548 else
549 Set_Sloc (Dump_Node, Debug_Sloc + Source_Ptr (Column - 1));
550 end if;
551 end;
553 -- We do not know the actual end location in the generated code and
554 -- it could be much closer than in the source code, so play safe.
556 if Nkind_In (Dump_Node, N_Case_Statement, N_If_Statement) then
557 Set_End_Location (Dump_Node, Debug_Sloc + Source_Ptr (Column - 1));
558 end if;
560 Dump_Node := Empty;
561 end if;
562 end Set_Debug_Sloc;
564 -----------------
565 -- Source_Dump --
566 -----------------
568 procedure Source_Dump is
570 procedure Underline;
571 -- Put underline under string we just printed
573 ---------------
574 -- Underline --
575 ---------------
577 procedure Underline is
578 Col : constant Int := Column;
580 begin
581 Write_Eol;
583 while Col > Column loop
584 Write_Char ('-');
585 end loop;
587 Write_Eol;
588 end Underline;
590 -- Start of processing for Source_Dump
592 begin
593 Dump_Generated_Only := Debug_Flag_G or
594 Print_Generated_Code or
595 Debug_Generated_Code;
596 Dump_Original_Only := Debug_Flag_O;
597 Dump_Freeze_Null := Debug_Flag_S or Debug_Flag_G;
599 -- Note that we turn off the tree dump flags immediately, before
600 -- starting the dump. This avoids generating two copies of the dump
601 -- if an abort occurs after printing the dump, and more importantly,
602 -- avoids an infinite loop if an abort occurs during the dump.
604 if Debug_Flag_Z then
605 Current_Source_File := No_Source_File;
606 Debug_Flag_Z := False;
607 Write_Eol;
608 Write_Eol;
609 Write_Str ("Source recreated from tree of Standard (spec)");
610 Underline;
611 Sprint_Node (Standard_Package_Node);
612 Write_Eol;
613 Write_Eol;
614 end if;
616 if Debug_Flag_S or Dump_Generated_Only or Dump_Original_Only then
617 Debug_Flag_G := False;
618 Debug_Flag_O := False;
619 Debug_Flag_S := False;
620 First_Debug_Sloc := No_Location;
622 -- Dump requested units
624 for U in Main_Unit .. Last_Unit loop
625 Current_Source_File := Source_Index (U);
627 -- Dump all units if -gnatdf set, otherwise dump only the source
628 -- files that are in the extended main source. Note that, if we
629 -- are generating debug files, generating that of the main unit
630 -- has an effect on the outcome of In_Extended_Main_Source_Unit
631 -- because slocs are rewritten, so we also test for equality of
632 -- Cunit_Entity to work around this effect.
634 if Debug_Flag_F
635 or else In_Extended_Main_Source_Unit (Cunit_Entity (U))
636 or else Cunit_Entity (U) = Cunit_Entity (Main_Unit)
637 then
638 -- If we are generating debug files, setup to write them
640 if Debug_Generated_Code then
641 Set_Special_Output (Print_Debug_Line'Access);
642 Create_Debug_Source (Source_Index (U), Debug_Sloc);
643 First_Debug_Sloc := Debug_Sloc;
644 Write_Source_Line (1);
645 Last_Line_Printed := 1;
647 -- If this unit has the same entity as the main unit, for
648 -- example is the spec of a stand-alone instantiation of
649 -- a package and the main unit is the body, its debug file
650 -- will also be the same. Therefore, we need to print again
651 -- the main unit to have both units in the debug file.
653 if U /= Main_Unit
654 and then Cunit_Entity (U) = Cunit_Entity (Main_Unit)
655 then
656 Sprint_Node (Cunit (Main_Unit));
657 Write_Eol;
658 end if;
660 Sprint_Node (Cunit (U));
661 Write_Source_Lines (Last_Source_Line (Current_Source_File));
662 Write_Eol;
663 Close_Debug_Source;
664 Set_Special_Output (null);
666 -- Normal output to standard output file
668 else
669 Write_Str ("Source recreated from tree for ");
670 Write_Unit_Name (Unit_Name (U));
671 Underline;
672 Write_Source_Line (1);
673 Last_Line_Printed := 1;
674 Sprint_Node (Cunit (U));
675 Write_Source_Lines (Last_Source_Line (Current_Source_File));
676 Write_Eol;
677 Write_Eol;
678 end if;
679 end if;
680 end loop;
681 end if;
682 end Source_Dump;
684 ---------------------
685 -- Sprint_And_List --
686 ---------------------
688 procedure Sprint_And_List (List : List_Id) is
689 Node : Node_Id;
690 begin
691 if Is_Non_Empty_List (List) then
692 Node := First (List);
693 loop
694 Sprint_Node (Node);
695 Next (Node);
696 exit when Node = Empty;
697 Write_Str (" and ");
698 end loop;
699 end if;
700 end Sprint_And_List;
702 ----------------------------------
703 -- Sprint_Aspect_Specifications --
704 ----------------------------------
706 procedure Sprint_Aspect_Specifications
707 (Node : Node_Id;
708 Semicolon : Boolean)
710 AS : constant List_Id := Aspect_Specifications (Node);
711 A : Node_Id;
713 begin
714 if Semicolon then
715 Write_Erase_Char (';');
716 Indent := Indent + 2;
717 Write_Indent;
718 Write_Str ("with ");
719 Indent := Indent + 5;
721 else
722 Write_Str (" with ");
723 end if;
725 A := First (AS);
726 loop
727 Sprint_Node (Identifier (A));
729 if Class_Present (A) then
730 Write_Str ("'Class");
731 end if;
733 if Present (Expression (A)) then
734 Write_Str (" => ");
735 Sprint_Node (Expression (A));
736 end if;
738 Next (A);
740 exit when No (A);
741 Write_Char (',');
743 if Semicolon then
744 Write_Indent;
745 end if;
746 end loop;
748 if Semicolon then
749 Indent := Indent - 7;
750 Write_Char (';');
751 end if;
752 end Sprint_Aspect_Specifications;
754 ---------------------
755 -- Sprint_Bar_List --
756 ---------------------
758 procedure Sprint_Bar_List (List : List_Id) is
759 Node : Node_Id;
760 begin
761 if Is_Non_Empty_List (List) then
762 Node := First (List);
763 loop
764 Sprint_Node (Node);
765 Next (Node);
766 exit when Node = Empty;
767 Write_Str (" | ");
768 end loop;
769 end if;
770 end Sprint_Bar_List;
772 ----------------------
773 -- Sprint_End_Label --
774 ----------------------
776 procedure Sprint_End_Label
777 (Node : Node_Id;
778 Default : Node_Id)
780 begin
781 if Present (Node)
782 and then Present (End_Label (Node))
783 and then Is_Entity_Name (End_Label (Node))
784 then
785 Set_Entity (End_Label (Node), Default);
787 -- For a function whose name is an operator, use the qualified name
788 -- created for the defining entity.
790 if Nkind (End_Label (Node)) = N_Operator_Symbol then
791 Set_Chars (End_Label (Node), Chars (Default));
792 end if;
794 Sprint_Node (End_Label (Node));
795 else
796 Sprint_Node (Default);
797 end if;
798 end Sprint_End_Label;
800 -----------------------
801 -- Sprint_Comma_List --
802 -----------------------
804 procedure Sprint_Comma_List (List : List_Id) is
805 Node : Node_Id;
807 begin
808 if Is_Non_Empty_List (List) then
809 Node := First (List);
810 loop
811 Sprint_Node (Node);
812 Next (Node);
813 exit when Node = Empty;
815 if not Is_Rewrite_Insertion (Node)
816 or else not Dump_Original_Only
817 then
818 Write_Str (", ");
819 end if;
820 end loop;
821 end if;
822 end Sprint_Comma_List;
824 --------------------------
825 -- Sprint_Indented_List --
826 --------------------------
828 procedure Sprint_Indented_List (List : List_Id) is
829 begin
830 Indent_Begin;
831 Sprint_Node_List (List);
832 Indent_End;
833 end Sprint_Indented_List;
835 ---------------------
836 -- Sprint_Left_Opnd --
837 ---------------------
839 procedure Sprint_Left_Opnd (N : Node_Id) is
840 Opnd : constant Node_Id := Left_Opnd (N);
842 begin
843 if Paren_Count (Opnd) /= 0
844 or else Op_Prec (Nkind (Opnd)) >= Op_Prec (Nkind (N))
845 then
846 Sprint_Node (Opnd);
848 else
849 Write_Char ('(');
850 Sprint_Node (Opnd);
851 Write_Char (')');
852 end if;
853 end Sprint_Left_Opnd;
855 -----------------
856 -- Sprint_Node --
857 -----------------
859 procedure Sprint_Node (Node : Node_Id) is
860 begin
861 if Is_Rewrite_Insertion (Node) then
862 if not Dump_Original_Only then
864 -- For special cases of nodes that always output <<< >>>
865 -- do not duplicate the output at this point.
867 if Nkind (Node) = N_Freeze_Entity
868 or else Nkind (Node) = N_Freeze_Generic_Entity
869 or else Nkind (Node) = N_Implicit_Label_Declaration
870 then
871 Sprint_Node_Actual (Node);
873 -- Normal case where <<< >>> may be required
875 else
876 Write_Rewrite_Str ("<<<");
877 Sprint_Node_Actual (Node);
878 Write_Rewrite_Str (">>>");
879 end if;
880 end if;
882 elsif Is_Rewrite_Substitution (Node) then
884 -- Case of dump generated only
886 if Dump_Generated_Only then
887 Sprint_Node_Actual (Node);
889 -- Case of dump original only
891 elsif Dump_Original_Only then
892 Sprint_Node_Actual (Original_Node (Node));
894 -- Case of both being dumped
896 else
897 Sprint_Node_Actual (Original_Node (Node));
898 Write_Rewrite_Str ("<<<");
899 Sprint_Node_Actual (Node);
900 Write_Rewrite_Str (">>>");
901 end if;
903 else
904 Sprint_Node_Actual (Node);
905 end if;
906 end Sprint_Node;
908 ------------------------
909 -- Sprint_Node_Actual --
910 ------------------------
912 procedure Sprint_Node_Actual (Node : Node_Id) is
913 Save_Dump_Node : constant Node_Id := Dump_Node;
915 begin
916 if Node = Empty then
917 return;
918 end if;
920 for J in 1 .. Paren_Count (Node) loop
921 Write_Str_With_Col_Check ("(");
922 end loop;
924 -- Setup current dump node
926 Dump_Node := Node;
928 if Nkind (Node) in N_Subexpr
929 and then Do_Range_Check (Node)
930 then
931 Write_Str_With_Col_Check ("{");
932 end if;
934 -- Select print circuit based on node kind
936 case Nkind (Node) is
937 when N_Abort_Statement =>
938 Write_Indent_Str_Sloc ("abort ");
939 Sprint_Comma_List (Names (Node));
940 Write_Char (';');
942 when N_Abortable_Part =>
943 Set_Debug_Sloc;
944 Write_Str_Sloc ("abort ");
945 Sprint_Indented_List (Statements (Node));
947 when N_Abstract_Subprogram_Declaration =>
948 Write_Indent;
949 Sprint_Node (Specification (Node));
950 Write_Str_With_Col_Check (" is ");
951 Write_Str_Sloc ("abstract;");
953 when N_Accept_Alternative =>
954 Sprint_Node_List (Pragmas_Before (Node));
956 if Present (Condition (Node)) then
957 Write_Indent_Str ("when ");
958 Sprint_Node (Condition (Node));
959 Write_Str (" => ");
960 Indent_Annull;
961 end if;
963 Sprint_Node_Sloc (Accept_Statement (Node));
964 Sprint_Node_List (Statements (Node));
966 when N_Accept_Statement =>
967 Write_Indent_Str_Sloc ("accept ");
968 Write_Id (Entry_Direct_Name (Node));
970 if Present (Entry_Index (Node)) then
971 Write_Str_With_Col_Check (" (");
972 Sprint_Node (Entry_Index (Node));
973 Write_Char (')');
974 end if;
976 Write_Param_Specs (Node);
978 if Present (Handled_Statement_Sequence (Node)) then
979 Write_Str_With_Col_Check (" do");
980 Sprint_Node (Handled_Statement_Sequence (Node));
981 Write_Indent_Str ("end ");
982 Write_Id (Entry_Direct_Name (Node));
983 end if;
985 Write_Char (';');
987 when N_Access_Definition =>
989 -- Ada 2005 (AI-254)
991 if Present (Access_To_Subprogram_Definition (Node)) then
992 Sprint_Node (Access_To_Subprogram_Definition (Node));
993 else
994 -- Ada 2005 (AI-231)
996 if Null_Exclusion_Present (Node) then
997 Write_Str ("not null ");
998 end if;
1000 Write_Str_With_Col_Check_Sloc ("access ");
1002 if All_Present (Node) then
1003 Write_Str ("all ");
1004 elsif Constant_Present (Node) then
1005 Write_Str ("constant ");
1006 end if;
1008 Sprint_Node (Subtype_Mark (Node));
1009 end if;
1011 when N_Access_Function_Definition =>
1013 -- Ada 2005 (AI-231)
1015 if Null_Exclusion_Present (Node) then
1016 Write_Str ("not null ");
1017 end if;
1019 Write_Str_With_Col_Check_Sloc ("access ");
1021 if Protected_Present (Node) then
1022 Write_Str_With_Col_Check ("protected ");
1023 end if;
1025 Write_Str_With_Col_Check ("function");
1026 Write_Param_Specs (Node);
1027 Write_Str_With_Col_Check (" return ");
1028 Sprint_Node (Result_Definition (Node));
1030 when N_Access_Procedure_Definition =>
1032 -- Ada 2005 (AI-231)
1034 if Null_Exclusion_Present (Node) then
1035 Write_Str ("not null ");
1036 end if;
1038 Write_Str_With_Col_Check_Sloc ("access ");
1040 if Protected_Present (Node) then
1041 Write_Str_With_Col_Check ("protected ");
1042 end if;
1044 Write_Str_With_Col_Check ("procedure");
1045 Write_Param_Specs (Node);
1047 when N_Access_To_Object_Definition =>
1048 Write_Str_With_Col_Check_Sloc ("access ");
1050 if All_Present (Node) then
1051 Write_Str_With_Col_Check ("all ");
1052 elsif Constant_Present (Node) then
1053 Write_Str_With_Col_Check ("constant ");
1054 end if;
1056 -- Ada 2005 (AI-231)
1058 if Null_Exclusion_Present (Node) then
1059 Write_Str ("not null ");
1060 end if;
1062 Sprint_Node (Subtype_Indication (Node));
1064 when N_Aggregate =>
1065 if Null_Record_Present (Node) then
1066 Write_Str_With_Col_Check_Sloc ("(null record)");
1068 else
1069 Write_Str_With_Col_Check_Sloc ("(");
1071 if Present (Expressions (Node)) then
1072 Sprint_Comma_List (Expressions (Node));
1074 if Present (Component_Associations (Node))
1075 and then not Is_Empty_List (Component_Associations (Node))
1076 then
1077 Write_Str (", ");
1078 end if;
1079 end if;
1081 if Present (Component_Associations (Node))
1082 and then not Is_Empty_List (Component_Associations (Node))
1083 then
1084 Indent_Begin;
1086 declare
1087 Nd : Node_Id;
1089 begin
1090 Nd := First (Component_Associations (Node));
1092 loop
1093 Write_Indent;
1094 Sprint_Node (Nd);
1095 Next (Nd);
1096 exit when No (Nd);
1098 if not Is_Rewrite_Insertion (Nd)
1099 or else not Dump_Original_Only
1100 then
1101 Write_Str (", ");
1102 end if;
1103 end loop;
1104 end;
1106 Indent_End;
1107 end if;
1109 Write_Char (')');
1110 end if;
1112 when N_Allocator =>
1113 Write_Str_With_Col_Check_Sloc ("new ");
1115 -- Ada 2005 (AI-231)
1117 if Null_Exclusion_Present (Node) then
1118 Write_Str ("not null ");
1119 end if;
1121 Sprint_Node (Expression (Node));
1123 if Present (Storage_Pool (Node)) then
1124 Write_Str_With_Col_Check ("[storage_pool = ");
1125 Sprint_Node (Storage_Pool (Node));
1126 Write_Char (']');
1127 end if;
1129 when N_And_Then =>
1130 Sprint_Left_Opnd (Node);
1131 Write_Str_Sloc (" and then ");
1132 Sprint_Right_Opnd (Node);
1134 -- Note: the following code for N_Aspect_Specification is not
1135 -- normally used, since we deal with aspects as part of a
1136 -- declaration, but it is here in case we deliberately try
1137 -- to print an N_Aspect_Speficiation node (e.g. from GDB).
1139 when N_Aspect_Specification =>
1140 Sprint_Node (Identifier (Node));
1141 Write_Str (" => ");
1142 Sprint_Node (Expression (Node));
1144 when N_Assignment_Statement =>
1145 Write_Indent;
1146 Sprint_Node (Name (Node));
1147 Write_Str_Sloc (" := ");
1148 Sprint_Node (Expression (Node));
1149 Write_Char (';');
1151 when N_Asynchronous_Select =>
1152 Write_Indent_Str_Sloc ("select");
1153 Indent_Begin;
1154 Sprint_Node (Triggering_Alternative (Node));
1155 Indent_End;
1157 -- Note: let the printing of Abortable_Part handle outputting
1158 -- the ABORT keyword, so that the Sloc can be set correctly.
1160 Write_Indent_Str ("then ");
1161 Sprint_Node (Abortable_Part (Node));
1162 Write_Indent_Str ("end select;");
1164 when N_At_Clause =>
1165 Write_Indent_Str_Sloc ("for ");
1166 Write_Id (Identifier (Node));
1167 Write_Str_With_Col_Check (" use at ");
1168 Sprint_Node (Expression (Node));
1169 Write_Char (';');
1171 when N_Attribute_Definition_Clause =>
1172 Write_Indent_Str_Sloc ("for ");
1173 Sprint_Node (Name (Node));
1174 Write_Char (''');
1175 Write_Name_With_Col_Check (Chars (Node));
1176 Write_Str_With_Col_Check (" use ");
1177 Sprint_Node (Expression (Node));
1178 Write_Char (';');
1180 when N_Attribute_Reference =>
1181 if Is_Procedure_Attribute_Name (Attribute_Name (Node)) then
1182 Write_Indent;
1183 end if;
1185 Sprint_Node (Prefix (Node));
1186 Write_Char_Sloc (''');
1187 Write_Name_With_Col_Check (Attribute_Name (Node));
1188 Sprint_Paren_Comma_List (Expressions (Node));
1190 if Is_Procedure_Attribute_Name (Attribute_Name (Node)) then
1191 Write_Char (';');
1192 end if;
1194 when N_Block_Statement =>
1195 Write_Indent;
1197 if Present (Identifier (Node))
1198 and then (not Has_Created_Identifier (Node)
1199 or else not Dump_Original_Only)
1200 then
1201 Write_Rewrite_Str ("<<<");
1202 Write_Id (Identifier (Node));
1203 Write_Str (" : ");
1204 Write_Rewrite_Str (">>>");
1205 end if;
1207 if Present (Declarations (Node)) then
1208 Write_Str_With_Col_Check_Sloc ("declare");
1209 Sprint_Indented_List (Declarations (Node));
1210 Write_Indent;
1211 end if;
1213 Write_Str_With_Col_Check_Sloc ("begin");
1214 Sprint_Node (Handled_Statement_Sequence (Node));
1215 Write_Indent_Str ("end");
1217 if Present (Identifier (Node))
1218 and then (not Has_Created_Identifier (Node)
1219 or else not Dump_Original_Only)
1220 then
1221 Write_Rewrite_Str ("<<<");
1222 Write_Char (' ');
1223 Write_Id (Identifier (Node));
1224 Write_Rewrite_Str (">>>");
1225 end if;
1227 Write_Char (';');
1229 when N_Case_Expression =>
1230 declare
1231 Has_Parens : constant Boolean := Paren_Count (Node) > 0;
1232 Alt : Node_Id;
1234 begin
1235 -- The syntax for case_expression does not include parentheses,
1236 -- but sometimes parentheses are required, so unconditionally
1237 -- generate them here unless already present.
1239 if not Has_Parens then
1240 Write_Char ('(');
1241 end if;
1243 Write_Str_With_Col_Check_Sloc ("case ");
1244 Sprint_Node (Expression (Node));
1245 Write_Str_With_Col_Check (" is");
1247 Alt := First (Alternatives (Node));
1248 loop
1249 Sprint_Node (Alt);
1250 Next (Alt);
1251 exit when No (Alt);
1252 Write_Char (',');
1253 end loop;
1255 if not Has_Parens then
1256 Write_Char (')');
1257 end if;
1258 end;
1260 when N_Case_Expression_Alternative =>
1261 Write_Str_With_Col_Check (" when ");
1262 Sprint_Bar_List (Discrete_Choices (Node));
1263 Write_Str (" => ");
1264 Sprint_Node (Expression (Node));
1266 when N_Case_Statement =>
1267 Write_Indent_Str_Sloc ("case ");
1268 Sprint_Node (Expression (Node));
1269 Write_Str (" is");
1270 Sprint_Indented_List (Alternatives (Node));
1271 Write_Indent_Str ("end case;");
1273 when N_Case_Statement_Alternative =>
1274 Write_Indent_Str_Sloc ("when ");
1275 Sprint_Bar_List (Discrete_Choices (Node));
1276 Write_Str (" => ");
1277 Sprint_Indented_List (Statements (Node));
1279 when N_Character_Literal =>
1280 if Column > Sprint_Line_Limit - 2 then
1281 Write_Indent_Str (" ");
1282 end if;
1284 Write_Char_Sloc (''');
1285 Write_Char_Code (UI_To_CC (Char_Literal_Value (Node)));
1286 Write_Char (''');
1288 when N_Code_Statement =>
1289 Write_Indent;
1290 Set_Debug_Sloc;
1291 Sprint_Node (Expression (Node));
1292 Write_Char (';');
1294 when N_Compilation_Unit =>
1295 Sprint_Node_List (Context_Items (Node));
1296 Sprint_Opt_Node_List (Declarations (Aux_Decls_Node (Node)));
1298 if Private_Present (Node) then
1299 Write_Indent_Str ("private ");
1300 Indent_Annull;
1301 end if;
1303 Sprint_Node_Sloc (Unit (Node));
1305 if Present (Actions (Aux_Decls_Node (Node)))
1306 or else
1307 Present (Pragmas_After (Aux_Decls_Node (Node)))
1308 then
1309 Write_Indent;
1310 end if;
1312 Sprint_Opt_Node_List (Actions (Aux_Decls_Node (Node)));
1313 Sprint_Opt_Node_List (Pragmas_After (Aux_Decls_Node (Node)));
1315 when N_Compilation_Unit_Aux =>
1316 null; -- nothing to do, never used, see above
1318 when N_Component_Association =>
1319 Set_Debug_Sloc;
1320 Sprint_Bar_List (Choices (Node));
1321 Write_Str (" => ");
1323 -- Ada 2005 (AI-287): Print the box if present
1325 if Box_Present (Node) then
1326 Write_Str_With_Col_Check ("<>");
1327 else
1328 Sprint_Node (Expression (Node));
1329 end if;
1331 when N_Iterated_Component_Association =>
1332 Set_Debug_Sloc;
1333 Write_Str (" for ");
1334 Write_Id (Defining_Identifier (Node));
1335 Write_Str (" in ");
1336 Sprint_Bar_List (Discrete_Choices (Node));
1337 Write_Str (" => ");
1338 Sprint_Node (Expression (Node));
1340 when N_Component_Clause =>
1341 Write_Indent;
1342 Sprint_Node (Component_Name (Node));
1343 Write_Str_Sloc (" at ");
1344 Sprint_Node (Position (Node));
1345 Write_Char (' ');
1346 Write_Str_With_Col_Check ("range ");
1347 Sprint_Node (First_Bit (Node));
1348 Write_Str (" .. ");
1349 Sprint_Node (Last_Bit (Node));
1350 Write_Char (';');
1352 when N_Component_Definition =>
1353 Set_Debug_Sloc;
1355 -- Ada 2005 (AI-230): Access definition components
1357 if Present (Access_Definition (Node)) then
1358 Sprint_Node (Access_Definition (Node));
1360 elsif Present (Subtype_Indication (Node)) then
1361 if Aliased_Present (Node) then
1362 Write_Str_With_Col_Check ("aliased ");
1363 end if;
1365 -- Ada 2005 (AI-231)
1367 if Null_Exclusion_Present (Node) then
1368 Write_Str (" not null ");
1369 end if;
1371 Sprint_Node (Subtype_Indication (Node));
1373 else
1374 Write_Str (" ??? ");
1375 end if;
1377 when N_Component_Declaration =>
1378 if Write_Indent_Identifiers_Sloc (Node) then
1379 Write_Str (" : ");
1380 Sprint_Node (Component_Definition (Node));
1382 if Present (Expression (Node)) then
1383 Write_Str (" := ");
1384 Sprint_Node (Expression (Node));
1385 end if;
1387 Write_Char (';');
1388 end if;
1390 when N_Component_List =>
1391 if Null_Present (Node) then
1392 Indent_Begin;
1393 Write_Indent_Str_Sloc ("null");
1394 Write_Char (';');
1395 Indent_End;
1397 else
1398 Set_Debug_Sloc;
1399 Sprint_Indented_List (Component_Items (Node));
1400 Sprint_Node (Variant_Part (Node));
1401 end if;
1403 when N_Compound_Statement =>
1404 Write_Indent_Str ("do");
1405 Indent_Begin;
1406 Sprint_Node_List (Actions (Node));
1407 Indent_End;
1408 Write_Indent_Str ("end;");
1410 when N_Conditional_Entry_Call =>
1411 Write_Indent_Str_Sloc ("select");
1412 Indent_Begin;
1413 Sprint_Node (Entry_Call_Alternative (Node));
1414 Indent_End;
1415 Write_Indent_Str ("else");
1416 Sprint_Indented_List (Else_Statements (Node));
1417 Write_Indent_Str ("end select;");
1419 when N_Constrained_Array_Definition =>
1420 Write_Str_With_Col_Check_Sloc ("array ");
1421 Sprint_Paren_Comma_List (Discrete_Subtype_Definitions (Node));
1422 Write_Str (" of ");
1424 Sprint_Node (Component_Definition (Node));
1426 -- A contract node should not appear in the tree. It is a semantic
1427 -- node attached to entry and [generic] subprogram entities. But we
1428 -- still provide meaningful output, in case called from the debugger.
1430 when N_Contract =>
1431 declare
1432 P : Node_Id;
1434 begin
1435 Indent_Begin;
1436 Write_Str ("N_Contract node");
1437 Write_Eol;
1439 Write_Indent_Str ("Pre_Post_Conditions");
1440 Indent_Begin;
1442 P := Pre_Post_Conditions (Node);
1443 while Present (P) loop
1444 Sprint_Node (P);
1445 P := Next_Pragma (P);
1446 end loop;
1448 Write_Eol;
1449 Indent_End;
1451 Write_Indent_Str ("Contract_Test_Cases");
1452 Indent_Begin;
1454 P := Contract_Test_Cases (Node);
1455 while Present (P) loop
1456 Sprint_Node (P);
1457 P := Next_Pragma (P);
1458 end loop;
1460 Write_Eol;
1461 Indent_End;
1463 Write_Indent_Str ("Classifications");
1464 Indent_Begin;
1466 P := Classifications (Node);
1467 while Present (P) loop
1468 Sprint_Node (P);
1469 P := Next_Pragma (P);
1470 end loop;
1472 Write_Eol;
1473 Indent_End;
1474 Indent_End;
1475 end;
1477 when N_Decimal_Fixed_Point_Definition =>
1478 Write_Str_With_Col_Check_Sloc (" delta ");
1479 Sprint_Node (Delta_Expression (Node));
1480 Write_Str_With_Col_Check ("digits ");
1481 Sprint_Node (Digits_Expression (Node));
1482 Sprint_Opt_Node (Real_Range_Specification (Node));
1484 when N_Defining_Character_Literal =>
1485 Write_Name_With_Col_Check_Sloc (Chars (Node));
1487 when N_Defining_Identifier =>
1488 Set_Debug_Sloc;
1489 Write_Id (Node);
1491 when N_Defining_Operator_Symbol =>
1492 Write_Name_With_Col_Check_Sloc (Chars (Node));
1494 when N_Defining_Program_Unit_Name =>
1495 Set_Debug_Sloc;
1496 Sprint_Node (Name (Node));
1497 Write_Char ('.');
1498 Write_Id (Defining_Identifier (Node));
1500 when N_Delay_Alternative =>
1501 Sprint_Node_List (Pragmas_Before (Node));
1503 if Present (Condition (Node)) then
1504 Write_Indent;
1505 Write_Str_With_Col_Check ("when ");
1506 Sprint_Node (Condition (Node));
1507 Write_Str (" => ");
1508 Indent_Annull;
1509 end if;
1511 Sprint_Node_Sloc (Delay_Statement (Node));
1512 Sprint_Node_List (Statements (Node));
1514 when N_Delay_Relative_Statement =>
1515 Write_Indent_Str_Sloc ("delay ");
1516 Sprint_Node (Expression (Node));
1517 Write_Char (';');
1519 when N_Delay_Until_Statement =>
1520 Write_Indent_Str_Sloc ("delay until ");
1521 Sprint_Node (Expression (Node));
1522 Write_Char (';');
1524 when N_Delta_Constraint =>
1525 Write_Str_With_Col_Check_Sloc ("delta ");
1526 Sprint_Node (Delta_Expression (Node));
1527 Sprint_Opt_Node (Range_Constraint (Node));
1529 when N_Derived_Type_Definition =>
1530 if Abstract_Present (Node) then
1531 Write_Str_With_Col_Check ("abstract ");
1532 end if;
1534 Write_Str_With_Col_Check ("new ");
1536 -- Ada 2005 (AI-231)
1538 if Null_Exclusion_Present (Node) then
1539 Write_Str_With_Col_Check ("not null ");
1540 end if;
1542 Sprint_Node (Subtype_Indication (Node));
1544 if Present (Interface_List (Node)) then
1545 Write_Str_With_Col_Check (" and ");
1546 Sprint_And_List (Interface_List (Node));
1547 Write_Str_With_Col_Check (" with ");
1548 end if;
1550 if Present (Record_Extension_Part (Node)) then
1551 if No (Interface_List (Node)) then
1552 Write_Str_With_Col_Check (" with ");
1553 end if;
1555 Sprint_Node (Record_Extension_Part (Node));
1556 end if;
1558 when N_Designator =>
1559 Sprint_Node (Name (Node));
1560 Write_Char_Sloc ('.');
1561 Write_Id (Identifier (Node));
1563 when N_Digits_Constraint =>
1564 Write_Str_With_Col_Check_Sloc ("digits ");
1565 Sprint_Node (Digits_Expression (Node));
1566 Sprint_Opt_Node (Range_Constraint (Node));
1568 when N_Discriminant_Association =>
1569 Set_Debug_Sloc;
1571 if Present (Selector_Names (Node)) then
1572 Sprint_Bar_List (Selector_Names (Node));
1573 Write_Str (" => ");
1574 end if;
1576 Set_Debug_Sloc;
1577 Sprint_Node (Expression (Node));
1579 when N_Discriminant_Specification =>
1580 Set_Debug_Sloc;
1582 if Write_Identifiers (Node) then
1583 Write_Str (" : ");
1585 if Null_Exclusion_Present (Node) then
1586 Write_Str ("not null ");
1587 end if;
1589 Sprint_Node (Discriminant_Type (Node));
1591 if Present (Expression (Node)) then
1592 Write_Str (" := ");
1593 Sprint_Node (Expression (Node));
1594 end if;
1595 else
1596 Write_Str (", ");
1597 end if;
1599 when N_Elsif_Part =>
1600 Write_Indent_Str_Sloc ("elsif ");
1601 Sprint_Node (Condition (Node));
1602 Write_Str_With_Col_Check (" then");
1603 Sprint_Indented_List (Then_Statements (Node));
1605 when N_Empty =>
1606 null;
1608 when N_Entry_Body =>
1609 Write_Indent_Str_Sloc ("entry ");
1610 Write_Id (Defining_Identifier (Node));
1611 Sprint_Node (Entry_Body_Formal_Part (Node));
1612 Write_Str_With_Col_Check (" is");
1613 Sprint_Indented_List (Declarations (Node));
1614 Write_Indent_Str ("begin");
1615 Sprint_Node (Handled_Statement_Sequence (Node));
1616 Write_Indent_Str ("end ");
1617 Write_Id (Defining_Identifier (Node));
1618 Write_Char (';');
1620 when N_Entry_Body_Formal_Part =>
1621 if Present (Entry_Index_Specification (Node)) then
1622 Write_Str_With_Col_Check_Sloc (" (");
1623 Sprint_Node (Entry_Index_Specification (Node));
1624 Write_Char (')');
1625 end if;
1627 Write_Param_Specs (Node);
1628 Write_Str_With_Col_Check_Sloc (" when ");
1629 Sprint_Node (Condition (Node));
1631 when N_Entry_Call_Alternative =>
1632 Sprint_Node_List (Pragmas_Before (Node));
1633 Sprint_Node_Sloc (Entry_Call_Statement (Node));
1634 Sprint_Node_List (Statements (Node));
1636 when N_Entry_Call_Statement =>
1637 Write_Indent;
1638 Sprint_Node_Sloc (Name (Node));
1639 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
1640 Write_Char (';');
1642 when N_Entry_Declaration =>
1643 Write_Indent_Str_Sloc ("entry ");
1644 Write_Id (Defining_Identifier (Node));
1646 if Present (Discrete_Subtype_Definition (Node)) then
1647 Write_Str_With_Col_Check (" (");
1648 Sprint_Node (Discrete_Subtype_Definition (Node));
1649 Write_Char (')');
1650 end if;
1652 Write_Param_Specs (Node);
1653 Write_Char (';');
1655 when N_Entry_Index_Specification =>
1656 Write_Str_With_Col_Check_Sloc ("for ");
1657 Write_Id (Defining_Identifier (Node));
1658 Write_Str_With_Col_Check (" in ");
1659 Sprint_Node (Discrete_Subtype_Definition (Node));
1661 when N_Enumeration_Representation_Clause =>
1662 Write_Indent_Str_Sloc ("for ");
1663 Write_Id (Identifier (Node));
1664 Write_Str_With_Col_Check (" use ");
1665 Sprint_Node (Array_Aggregate (Node));
1666 Write_Char (';');
1668 when N_Enumeration_Type_Definition =>
1669 Set_Debug_Sloc;
1671 -- Skip attempt to print Literals field if it's not there and
1672 -- we are in package Standard (case of Character, which is
1673 -- handled specially (without an explicit literals list).
1675 if Sloc (Node) > Standard_Location
1676 or else Present (Literals (Node))
1677 then
1678 Sprint_Paren_Comma_List (Literals (Node));
1679 end if;
1681 when N_Error =>
1682 Write_Str_With_Col_Check_Sloc ("<error>");
1684 when N_Exception_Declaration =>
1685 if Write_Indent_Identifiers (Node) then
1686 Write_Str_With_Col_Check (" : ");
1688 if Is_Statically_Allocated (Defining_Identifier (Node)) then
1689 Write_Str_With_Col_Check ("static ");
1690 end if;
1692 Write_Str_Sloc ("exception");
1694 if Present (Expression (Node)) then
1695 Write_Str (" := ");
1696 Sprint_Node (Expression (Node));
1697 end if;
1699 Write_Char (';');
1700 end if;
1702 when N_Exception_Handler =>
1703 Write_Indent_Str_Sloc ("when ");
1705 if Present (Choice_Parameter (Node)) then
1706 Sprint_Node (Choice_Parameter (Node));
1707 Write_Str (" : ");
1708 end if;
1710 Sprint_Bar_List (Exception_Choices (Node));
1711 Write_Str (" => ");
1712 Sprint_Indented_List (Statements (Node));
1714 when N_Exception_Renaming_Declaration =>
1715 Write_Indent;
1716 Set_Debug_Sloc;
1717 Sprint_Node (Defining_Identifier (Node));
1718 Write_Str_With_Col_Check (" : exception renames ");
1719 Sprint_Node (Name (Node));
1720 Write_Char (';');
1722 when N_Exit_Statement =>
1723 Write_Indent_Str_Sloc ("exit");
1724 Sprint_Opt_Node (Name (Node));
1726 if Present (Condition (Node)) then
1727 Write_Str_With_Col_Check (" when ");
1728 Sprint_Node (Condition (Node));
1729 end if;
1731 Write_Char (';');
1733 when N_Expanded_Name =>
1734 Sprint_Node (Prefix (Node));
1735 Write_Char_Sloc ('.');
1736 Sprint_Node (Selector_Name (Node));
1738 when N_Explicit_Dereference =>
1739 Sprint_Node (Prefix (Node));
1740 Write_Char_Sloc ('.');
1741 Write_Str_Sloc ("all");
1743 when N_Expression_With_Actions =>
1744 Indent_Begin;
1745 Write_Indent_Str_Sloc ("do ");
1746 Indent_Begin;
1747 Sprint_Node_List (Actions (Node));
1748 Indent_End;
1749 Write_Indent;
1750 Write_Str_With_Col_Check_Sloc ("in ");
1751 Sprint_Node (Expression (Node));
1752 Write_Str_With_Col_Check (" end");
1753 Indent_End;
1754 Write_Indent;
1756 when N_Expression_Function =>
1757 Write_Indent;
1758 Sprint_Node_Sloc (Specification (Node));
1759 Write_Str (" is");
1760 Indent_Begin;
1761 Write_Indent;
1762 Sprint_Node (Expression (Node));
1763 Write_Char (';');
1764 Indent_End;
1766 when N_Extended_Return_Statement =>
1767 Write_Indent_Str_Sloc ("return ");
1768 Sprint_Node_List (Return_Object_Declarations (Node));
1770 if Present (Handled_Statement_Sequence (Node)) then
1771 Write_Str_With_Col_Check (" do");
1772 Sprint_Node (Handled_Statement_Sequence (Node));
1773 Write_Indent_Str ("end return;");
1774 else
1775 Write_Indent_Str (";");
1776 end if;
1778 when N_Extension_Aggregate =>
1779 Write_Str_With_Col_Check_Sloc ("(");
1780 Sprint_Node (Ancestor_Part (Node));
1781 Write_Str_With_Col_Check (" with ");
1783 if Null_Record_Present (Node) then
1784 Write_Str_With_Col_Check ("null record");
1785 else
1786 if Present (Expressions (Node)) then
1787 Sprint_Comma_List (Expressions (Node));
1789 if Present (Component_Associations (Node)) then
1790 Write_Str (", ");
1791 end if;
1792 end if;
1794 if Present (Component_Associations (Node)) then
1795 Sprint_Comma_List (Component_Associations (Node));
1796 end if;
1797 end if;
1799 Write_Char (')');
1801 when N_Floating_Point_Definition =>
1802 Write_Str_With_Col_Check_Sloc ("digits ");
1803 Sprint_Node (Digits_Expression (Node));
1804 Sprint_Opt_Node (Real_Range_Specification (Node));
1806 when N_Formal_Decimal_Fixed_Point_Definition =>
1807 Write_Str_With_Col_Check_Sloc ("delta <> digits <>");
1809 when N_Formal_Derived_Type_Definition =>
1810 Write_Str_With_Col_Check_Sloc ("new ");
1811 Sprint_Node (Subtype_Mark (Node));
1813 if Present (Interface_List (Node)) then
1814 Write_Str_With_Col_Check (" and ");
1815 Sprint_And_List (Interface_List (Node));
1816 end if;
1818 if Private_Present (Node) then
1819 Write_Str_With_Col_Check (" with private");
1820 end if;
1822 when N_Formal_Abstract_Subprogram_Declaration =>
1823 Write_Indent_Str_Sloc ("with ");
1824 Sprint_Node (Specification (Node));
1826 Write_Str_With_Col_Check (" is abstract");
1828 if Box_Present (Node) then
1829 Write_Str_With_Col_Check (" <>");
1830 elsif Present (Default_Name (Node)) then
1831 Write_Str_With_Col_Check (" ");
1832 Sprint_Node (Default_Name (Node));
1833 end if;
1835 Write_Char (';');
1837 when N_Formal_Concrete_Subprogram_Declaration =>
1838 Write_Indent_Str_Sloc ("with ");
1839 Sprint_Node (Specification (Node));
1841 if Box_Present (Node) then
1842 Write_Str_With_Col_Check (" is <>");
1843 elsif Present (Default_Name (Node)) then
1844 Write_Str_With_Col_Check (" is ");
1845 Sprint_Node (Default_Name (Node));
1846 end if;
1848 Write_Char (';');
1850 when N_Formal_Discrete_Type_Definition =>
1851 Write_Str_With_Col_Check_Sloc ("<>");
1853 when N_Formal_Floating_Point_Definition =>
1854 Write_Str_With_Col_Check_Sloc ("digits <>");
1856 when N_Formal_Modular_Type_Definition =>
1857 Write_Str_With_Col_Check_Sloc ("mod <>");
1859 when N_Formal_Object_Declaration =>
1860 Set_Debug_Sloc;
1862 if Write_Indent_Identifiers (Node) then
1863 Write_Str (" : ");
1865 if In_Present (Node) then
1866 Write_Str_With_Col_Check ("in ");
1867 end if;
1869 if Out_Present (Node) then
1870 Write_Str_With_Col_Check ("out ");
1871 end if;
1873 if Present (Subtype_Mark (Node)) then
1875 -- Ada 2005 (AI-423): Formal object with null exclusion
1877 if Null_Exclusion_Present (Node) then
1878 Write_Str ("not null ");
1879 end if;
1881 Sprint_Node (Subtype_Mark (Node));
1883 -- Ada 2005 (AI-423): Formal object with access definition
1885 else
1886 pragma Assert (Present (Access_Definition (Node)));
1888 Sprint_Node (Access_Definition (Node));
1889 end if;
1891 if Present (Default_Expression (Node)) then
1892 Write_Str (" := ");
1893 Sprint_Node (Default_Expression (Node));
1894 end if;
1896 Write_Char (';');
1897 end if;
1899 when N_Formal_Ordinary_Fixed_Point_Definition =>
1900 Write_Str_With_Col_Check_Sloc ("delta <>");
1902 when N_Formal_Package_Declaration =>
1903 Write_Indent_Str_Sloc ("with package ");
1904 Write_Id (Defining_Identifier (Node));
1905 Write_Str_With_Col_Check (" is new ");
1906 Sprint_Node (Name (Node));
1907 Write_Str_With_Col_Check (" (<>);");
1909 when N_Formal_Private_Type_Definition =>
1910 if Abstract_Present (Node) then
1911 Write_Str_With_Col_Check ("abstract ");
1912 end if;
1914 if Tagged_Present (Node) then
1915 Write_Str_With_Col_Check ("tagged ");
1916 end if;
1918 if Limited_Present (Node) then
1919 Write_Str_With_Col_Check ("limited ");
1920 end if;
1922 Write_Str_With_Col_Check_Sloc ("private");
1924 when N_Formal_Incomplete_Type_Definition =>
1925 if Tagged_Present (Node) then
1926 Write_Str_With_Col_Check ("is tagged ");
1927 end if;
1929 when N_Formal_Signed_Integer_Type_Definition =>
1930 Write_Str_With_Col_Check_Sloc ("range <>");
1932 when N_Formal_Type_Declaration =>
1933 Write_Indent_Str_Sloc ("type ");
1934 Write_Id (Defining_Identifier (Node));
1936 if Present (Discriminant_Specifications (Node)) then
1937 Write_Discr_Specs (Node);
1938 elsif Unknown_Discriminants_Present (Node) then
1939 Write_Str_With_Col_Check ("(<>)");
1940 end if;
1942 if Nkind (Formal_Type_Definition (Node)) /=
1943 N_Formal_Incomplete_Type_Definition
1944 then
1945 Write_Str_With_Col_Check (" is ");
1946 end if;
1948 Sprint_Node (Formal_Type_Definition (Node));
1949 Write_Char (';');
1951 when N_Free_Statement =>
1952 Write_Indent_Str_Sloc ("free ");
1953 Sprint_Node (Expression (Node));
1954 Write_Char (';');
1956 when N_Freeze_Entity =>
1957 if Dump_Original_Only then
1958 null;
1960 -- A freeze node is output if it has some effect (i.e. non-empty
1961 -- actions, or freeze node for an itype, which causes elaboration
1962 -- of the itype), and is also always output if Dump_Freeze_Null
1963 -- is set True.
1965 elsif Present (Actions (Node))
1966 or else Is_Itype (Entity (Node))
1967 or else Dump_Freeze_Null
1968 then
1969 Write_Indent;
1970 Write_Rewrite_Str ("<<<");
1971 Write_Str_With_Col_Check_Sloc ("freeze ");
1972 Write_Id (Entity (Node));
1973 Write_Str (" [");
1975 if No (Actions (Node)) then
1976 Write_Char (']');
1978 else
1979 -- Output freeze actions. We increment Freeze_Indent during
1980 -- this output to avoid generating extra blank lines before
1981 -- any procedures included in the freeze actions.
1983 Freeze_Indent := Freeze_Indent + 1;
1984 Sprint_Indented_List (Actions (Node));
1985 Freeze_Indent := Freeze_Indent - 1;
1986 Write_Indent_Str ("]");
1987 end if;
1989 Write_Rewrite_Str (">>>");
1990 end if;
1992 when N_Freeze_Generic_Entity =>
1993 if Dump_Original_Only then
1994 null;
1996 else
1997 Write_Indent;
1998 Write_Str_With_Col_Check_Sloc ("freeze_generic ");
1999 Write_Id (Entity (Node));
2000 end if;
2002 when N_Full_Type_Declaration =>
2003 Write_Indent_Str_Sloc ("type ");
2004 Sprint_Node (Defining_Identifier (Node));
2005 Write_Discr_Specs (Node);
2006 Write_Str_With_Col_Check (" is ");
2007 Sprint_Node (Type_Definition (Node));
2008 Write_Char (';');
2010 when N_Function_Call =>
2011 Set_Debug_Sloc;
2012 Write_Subprogram_Name (Name (Node));
2013 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
2015 when N_Function_Instantiation =>
2016 Write_Indent_Str_Sloc ("function ");
2017 Sprint_Node (Defining_Unit_Name (Node));
2018 Write_Str_With_Col_Check (" is new ");
2019 Sprint_Node (Name (Node));
2020 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
2021 Write_Char (';');
2023 when N_Function_Specification =>
2024 Write_Str_With_Col_Check_Sloc ("function ");
2025 Sprint_Node (Defining_Unit_Name (Node));
2026 Write_Param_Specs (Node);
2027 Write_Str_With_Col_Check (" return ");
2029 -- Ada 2005 (AI-231)
2031 if Nkind (Result_Definition (Node)) /= N_Access_Definition
2032 and then Null_Exclusion_Present (Node)
2033 then
2034 Write_Str (" not null ");
2035 end if;
2037 Sprint_Node (Result_Definition (Node));
2039 when N_Generic_Association =>
2040 Set_Debug_Sloc;
2042 if Present (Selector_Name (Node)) then
2043 Sprint_Node (Selector_Name (Node));
2044 Write_Str (" => ");
2045 end if;
2047 Sprint_Node (Explicit_Generic_Actual_Parameter (Node));
2049 when N_Generic_Function_Renaming_Declaration =>
2050 Write_Indent_Str_Sloc ("generic function ");
2051 Sprint_Node (Defining_Unit_Name (Node));
2052 Write_Str_With_Col_Check (" renames ");
2053 Sprint_Node (Name (Node));
2054 Write_Char (';');
2056 when N_Generic_Package_Declaration =>
2057 Extra_Blank_Line;
2058 Write_Indent_Str_Sloc ("generic ");
2059 Sprint_Indented_List (Generic_Formal_Declarations (Node));
2060 Write_Indent;
2061 Sprint_Node (Specification (Node));
2062 Write_Char (';');
2064 when N_Generic_Package_Renaming_Declaration =>
2065 Write_Indent_Str_Sloc ("generic package ");
2066 Sprint_Node (Defining_Unit_Name (Node));
2067 Write_Str_With_Col_Check (" renames ");
2068 Sprint_Node (Name (Node));
2069 Write_Char (';');
2071 when N_Generic_Procedure_Renaming_Declaration =>
2072 Write_Indent_Str_Sloc ("generic procedure ");
2073 Sprint_Node (Defining_Unit_Name (Node));
2074 Write_Str_With_Col_Check (" renames ");
2075 Sprint_Node (Name (Node));
2076 Write_Char (';');
2078 when N_Generic_Subprogram_Declaration =>
2079 Extra_Blank_Line;
2080 Write_Indent_Str_Sloc ("generic ");
2081 Sprint_Indented_List (Generic_Formal_Declarations (Node));
2082 Write_Indent;
2083 Sprint_Node (Specification (Node));
2084 Write_Char (';');
2086 when N_Goto_Statement =>
2087 Write_Indent_Str_Sloc ("goto ");
2088 Sprint_Node (Name (Node));
2089 Write_Char (';');
2091 if Nkind (Next (Node)) = N_Label then
2092 Write_Indent;
2093 end if;
2095 when N_Handled_Sequence_Of_Statements =>
2096 Set_Debug_Sloc;
2097 Sprint_Indented_List (Statements (Node));
2099 if Present (Exception_Handlers (Node)) then
2100 Write_Indent_Str ("exception");
2101 Indent_Begin;
2102 Sprint_Node_List (Exception_Handlers (Node));
2103 Indent_End;
2104 end if;
2106 if Present (At_End_Proc (Node)) then
2107 Write_Indent_Str ("at end");
2108 Indent_Begin;
2109 Write_Indent;
2110 Sprint_Node (At_End_Proc (Node));
2111 Write_Char (';');
2112 Indent_End;
2113 end if;
2115 when N_Identifier =>
2116 Set_Debug_Sloc;
2117 Write_Id (Node);
2119 when N_If_Expression =>
2120 declare
2121 Has_Parens : constant Boolean := Paren_Count (Node) > 0;
2122 Condition : constant Node_Id := First (Expressions (Node));
2123 Then_Expr : constant Node_Id := Next (Condition);
2125 begin
2126 -- The syntax for if_expression does not include parentheses,
2127 -- but sometimes parentheses are required, so unconditionally
2128 -- generate them here unless already present.
2130 if not Has_Parens then
2131 Write_Char ('(');
2132 end if;
2134 Write_Str_With_Col_Check_Sloc ("if ");
2135 Sprint_Node (Condition);
2136 Write_Str_With_Col_Check (" then ");
2138 -- Defense against junk here
2140 if Present (Then_Expr) then
2141 Sprint_Node (Then_Expr);
2143 if Present (Next (Then_Expr)) then
2144 Write_Str_With_Col_Check (" else ");
2145 Sprint_Node (Next (Then_Expr));
2146 end if;
2147 end if;
2149 if not Has_Parens then
2150 Write_Char (')');
2151 end if;
2152 end;
2154 when N_If_Statement =>
2155 Write_Indent_Str_Sloc ("if ");
2156 Sprint_Node (Condition (Node));
2157 Write_Str_With_Col_Check (" then");
2158 Sprint_Indented_List (Then_Statements (Node));
2159 Sprint_Opt_Node_List (Elsif_Parts (Node));
2161 if Present (Else_Statements (Node)) then
2162 Write_Indent_Str ("else");
2163 Sprint_Indented_List (Else_Statements (Node));
2164 end if;
2166 Write_Indent_Str ("end if;");
2168 when N_Implicit_Label_Declaration =>
2169 if not Dump_Original_Only then
2170 Write_Indent;
2171 Write_Rewrite_Str ("<<<");
2172 Set_Debug_Sloc;
2173 Write_Id (Defining_Identifier (Node));
2174 Write_Str (" : ");
2175 Write_Str_With_Col_Check ("label");
2176 Write_Rewrite_Str (">>>");
2177 end if;
2179 when N_In =>
2180 Sprint_Left_Opnd (Node);
2181 Write_Str_Sloc (" in ");
2183 if Present (Right_Opnd (Node)) then
2184 Sprint_Right_Opnd (Node);
2185 else
2186 Sprint_Bar_List (Alternatives (Node));
2187 end if;
2189 when N_Incomplete_Type_Declaration =>
2190 Write_Indent_Str_Sloc ("type ");
2191 Write_Id (Defining_Identifier (Node));
2193 if Present (Discriminant_Specifications (Node)) then
2194 Write_Discr_Specs (Node);
2195 elsif Unknown_Discriminants_Present (Node) then
2196 Write_Str_With_Col_Check ("(<>)");
2197 end if;
2199 Write_Char (';');
2201 when N_Index_Or_Discriminant_Constraint =>
2202 Set_Debug_Sloc;
2203 Sprint_Paren_Comma_List (Constraints (Node));
2205 when N_Indexed_Component =>
2206 Sprint_Node_Sloc (Prefix (Node));
2207 Sprint_Opt_Paren_Comma_List (Expressions (Node));
2209 when N_Integer_Literal =>
2210 if Print_In_Hex (Node) then
2211 Write_Uint_With_Col_Check_Sloc (Intval (Node), Hex);
2212 else
2213 Write_Uint_With_Col_Check_Sloc (Intval (Node), Auto);
2214 end if;
2216 when N_Iteration_Scheme =>
2217 if Present (Condition (Node)) then
2218 Write_Str_With_Col_Check_Sloc ("while ");
2219 Sprint_Node (Condition (Node));
2220 else
2221 Write_Str_With_Col_Check_Sloc ("for ");
2223 if Present (Iterator_Specification (Node)) then
2224 Sprint_Node (Iterator_Specification (Node));
2225 else
2226 Sprint_Node (Loop_Parameter_Specification (Node));
2227 end if;
2228 end if;
2230 Write_Char (' ');
2232 when N_Iterator_Specification =>
2233 Set_Debug_Sloc;
2234 Write_Id (Defining_Identifier (Node));
2236 if Present (Subtype_Indication (Node)) then
2237 Write_Str_With_Col_Check (" : ");
2238 Sprint_Node (Subtype_Indication (Node));
2239 end if;
2241 if Of_Present (Node) then
2242 Write_Str_With_Col_Check (" of ");
2243 else
2244 Write_Str_With_Col_Check (" in ");
2245 end if;
2247 if Reverse_Present (Node) then
2248 Write_Str_With_Col_Check ("reverse ");
2249 end if;
2251 Sprint_Node (Name (Node));
2253 when N_Itype_Reference =>
2254 Write_Indent_Str_Sloc ("reference ");
2255 Write_Id (Itype (Node));
2257 when N_Label =>
2258 Write_Indent_Str_Sloc ("<<");
2259 Write_Id (Identifier (Node));
2260 Write_Str (">>");
2262 when N_Loop_Parameter_Specification =>
2263 Set_Debug_Sloc;
2264 Write_Id (Defining_Identifier (Node));
2265 Write_Str_With_Col_Check (" in ");
2267 if Reverse_Present (Node) then
2268 Write_Str_With_Col_Check ("reverse ");
2269 end if;
2271 Sprint_Node (Discrete_Subtype_Definition (Node));
2273 when N_Loop_Statement =>
2274 Write_Indent;
2276 if Present (Identifier (Node))
2277 and then (not Has_Created_Identifier (Node)
2278 or else not Dump_Original_Only)
2279 then
2280 Write_Rewrite_Str ("<<<");
2281 Write_Id (Identifier (Node));
2282 Write_Str (" : ");
2283 Write_Rewrite_Str (">>>");
2284 Sprint_Node (Iteration_Scheme (Node));
2285 Write_Str_With_Col_Check_Sloc ("loop");
2286 Sprint_Indented_List (Statements (Node));
2287 Write_Indent_Str ("end loop ");
2288 Write_Rewrite_Str ("<<<");
2289 Write_Id (Identifier (Node));
2290 Write_Rewrite_Str (">>>");
2291 Write_Char (';');
2293 else
2294 Sprint_Node (Iteration_Scheme (Node));
2295 Write_Str_With_Col_Check_Sloc ("loop");
2296 Sprint_Indented_List (Statements (Node));
2297 Write_Indent_Str ("end loop;");
2298 end if;
2300 when N_Mod_Clause =>
2301 Sprint_Node_List (Pragmas_Before (Node));
2302 Write_Str_With_Col_Check_Sloc ("at mod ");
2303 Sprint_Node (Expression (Node));
2305 when N_Modular_Type_Definition =>
2306 Write_Str_With_Col_Check_Sloc ("mod ");
2307 Sprint_Node (Expression (Node));
2309 when N_Not_In =>
2310 Sprint_Left_Opnd (Node);
2311 Write_Str_Sloc (" not in ");
2313 if Present (Right_Opnd (Node)) then
2314 Sprint_Right_Opnd (Node);
2315 else
2316 Sprint_Bar_List (Alternatives (Node));
2317 end if;
2319 when N_Null =>
2320 Write_Str_With_Col_Check_Sloc ("null");
2322 when N_Null_Statement =>
2323 if Comes_From_Source (Node)
2324 or else Dump_Freeze_Null
2325 or else not Is_List_Member (Node)
2326 or else (No (Prev (Node)) and then No (Next (Node)))
2327 then
2328 Write_Indent_Str_Sloc ("null;");
2329 end if;
2331 when N_Number_Declaration =>
2332 Set_Debug_Sloc;
2334 if Write_Indent_Identifiers (Node) then
2335 Write_Str_With_Col_Check (" : constant ");
2336 Write_Str (" := ");
2337 Sprint_Node (Expression (Node));
2338 Write_Char (';');
2339 end if;
2341 when N_Object_Declaration =>
2342 Set_Debug_Sloc;
2344 if Write_Indent_Identifiers (Node) then
2345 declare
2346 Def_Id : constant Entity_Id := Defining_Identifier (Node);
2348 begin
2349 Write_Str_With_Col_Check (" : ");
2351 if Is_Statically_Allocated (Def_Id) then
2352 Write_Str_With_Col_Check ("static ");
2353 end if;
2355 if Aliased_Present (Node) then
2356 Write_Str_With_Col_Check ("aliased ");
2357 end if;
2359 if Constant_Present (Node) then
2360 Write_Str_With_Col_Check ("constant ");
2361 end if;
2363 -- Ada 2005 (AI-231)
2365 if Null_Exclusion_Present (Node) then
2366 Write_Str_With_Col_Check ("not null ");
2367 end if;
2369 -- Print type. We used to print the Object_Definition from
2370 -- the node, but it is much more useful to print the Etype
2371 -- of the defining identifier for the case where the nominal
2372 -- type is an unconstrained array type. For example, this
2373 -- will be a clear reference to the Itype with the bounds
2374 -- in the case of a type like String. The object after
2375 -- all is constrained, even if its nominal subtype is
2376 -- unconstrained.
2378 declare
2379 Odef : constant Node_Id := Object_Definition (Node);
2381 begin
2382 if Nkind (Odef) = N_Identifier
2383 and then Present (Etype (Odef))
2384 and then Is_Array_Type (Etype (Odef))
2385 and then not Is_Constrained (Etype (Odef))
2386 and then Present (Etype (Def_Id))
2387 then
2388 Sprint_Node (Etype (Def_Id));
2390 -- In other cases, the nominal type is fine to print
2392 else
2393 Sprint_Node (Odef);
2394 end if;
2395 end;
2397 if Present (Expression (Node))
2398 and then Expression (Node) /= Error
2399 then
2400 Write_Str (" := ");
2401 Sprint_Node (Expression (Node));
2402 end if;
2404 Write_Char (';');
2406 -- Handle implicit importation and implicit exportation of
2407 -- object declarations:
2408 -- $pragma import (Convention_Id, Def_Id, "...");
2409 -- $pragma export (Convention_Id, Def_Id, "...");
2411 if Is_Internal (Def_Id)
2412 and then Present (Interface_Name (Def_Id))
2413 then
2414 Write_Indent_Str_Sloc ("$pragma ");
2416 if Is_Imported (Def_Id) then
2417 Write_Str ("import (");
2419 else pragma Assert (Is_Exported (Def_Id));
2420 Write_Str ("export (");
2421 end if;
2423 declare
2424 Prefix : constant String := "Convention_";
2425 S : constant String := Convention (Def_Id)'Img;
2427 begin
2428 Name_Len := S'Last - Prefix'Last;
2429 Name_Buffer (1 .. Name_Len) :=
2430 S (Prefix'Last + 1 .. S'Last);
2431 Set_Casing (All_Lower_Case);
2432 Write_Str (Name_Buffer (1 .. Name_Len));
2433 end;
2435 Write_Str (", ");
2436 Write_Id (Def_Id);
2437 Write_Str (", ");
2438 Write_String_Table_Entry
2439 (Strval (Interface_Name (Def_Id)));
2440 Write_Str (");");
2441 end if;
2442 end;
2443 end if;
2445 when N_Object_Renaming_Declaration =>
2446 Write_Indent;
2447 Set_Debug_Sloc;
2448 Sprint_Node (Defining_Identifier (Node));
2449 Write_Str (" : ");
2451 -- Ada 2005 (AI-230): Access renamings
2453 if Present (Access_Definition (Node)) then
2454 Sprint_Node (Access_Definition (Node));
2456 elsif Present (Subtype_Mark (Node)) then
2458 -- Ada 2005 (AI-423): Object renaming with a null exclusion
2460 if Null_Exclusion_Present (Node) then
2461 Write_Str ("not null ");
2462 end if;
2464 Sprint_Node (Subtype_Mark (Node));
2466 else
2467 Write_Str (" ??? ");
2468 end if;
2470 Write_Str_With_Col_Check (" renames ");
2471 Sprint_Node (Name (Node));
2472 Write_Char (';');
2474 when N_Op_Abs =>
2475 Write_Operator (Node, "abs ");
2476 Sprint_Right_Opnd (Node);
2478 when N_Op_Add =>
2479 Sprint_Left_Opnd (Node);
2480 Write_Operator (Node, " + ");
2481 Sprint_Right_Opnd (Node);
2483 when N_Op_And =>
2484 Sprint_Left_Opnd (Node);
2485 Write_Operator (Node, " and ");
2486 Sprint_Right_Opnd (Node);
2488 when N_Op_Concat =>
2489 Sprint_Left_Opnd (Node);
2490 Write_Operator (Node, " & ");
2491 Sprint_Right_Opnd (Node);
2493 when N_Op_Divide =>
2494 Sprint_Left_Opnd (Node);
2495 Write_Char (' ');
2496 Process_TFAI_RR_Flags (Node);
2497 Write_Operator (Node, "/ ");
2498 Sprint_Right_Opnd (Node);
2500 when N_Op_Eq =>
2501 Sprint_Left_Opnd (Node);
2502 Write_Operator (Node, " = ");
2503 Sprint_Right_Opnd (Node);
2505 when N_Op_Expon =>
2506 Sprint_Left_Opnd (Node);
2507 Write_Operator (Node, " ** ");
2508 Sprint_Right_Opnd (Node);
2510 when N_Op_Ge =>
2511 Sprint_Left_Opnd (Node);
2512 Write_Operator (Node, " >= ");
2513 Sprint_Right_Opnd (Node);
2515 when N_Op_Gt =>
2516 Sprint_Left_Opnd (Node);
2517 Write_Operator (Node, " > ");
2518 Sprint_Right_Opnd (Node);
2520 when N_Op_Le =>
2521 Sprint_Left_Opnd (Node);
2522 Write_Operator (Node, " <= ");
2523 Sprint_Right_Opnd (Node);
2525 when N_Op_Lt =>
2526 Sprint_Left_Opnd (Node);
2527 Write_Operator (Node, " < ");
2528 Sprint_Right_Opnd (Node);
2530 when N_Op_Minus =>
2531 Write_Operator (Node, "-");
2532 Sprint_Right_Opnd (Node);
2534 when N_Op_Mod =>
2535 Sprint_Left_Opnd (Node);
2537 if Treat_Fixed_As_Integer (Node) then
2538 Write_Str (" #");
2539 end if;
2541 Write_Operator (Node, " mod ");
2542 Sprint_Right_Opnd (Node);
2544 when N_Op_Multiply =>
2545 Sprint_Left_Opnd (Node);
2546 Write_Char (' ');
2547 Process_TFAI_RR_Flags (Node);
2548 Write_Operator (Node, "* ");
2549 Sprint_Right_Opnd (Node);
2551 when N_Op_Ne =>
2552 Sprint_Left_Opnd (Node);
2553 Write_Operator (Node, " /= ");
2554 Sprint_Right_Opnd (Node);
2556 when N_Op_Not =>
2557 Write_Operator (Node, "not ");
2558 Sprint_Right_Opnd (Node);
2560 when N_Op_Or =>
2561 Sprint_Left_Opnd (Node);
2562 Write_Operator (Node, " or ");
2563 Sprint_Right_Opnd (Node);
2565 when N_Op_Plus =>
2566 Write_Operator (Node, "+");
2567 Sprint_Right_Opnd (Node);
2569 when N_Op_Rem =>
2570 Sprint_Left_Opnd (Node);
2572 if Treat_Fixed_As_Integer (Node) then
2573 Write_Str (" #");
2574 end if;
2576 Write_Operator (Node, " rem ");
2577 Sprint_Right_Opnd (Node);
2579 when N_Op_Shift =>
2580 Set_Debug_Sloc;
2581 Write_Id (Node);
2582 Write_Char ('!');
2583 Write_Str_With_Col_Check ("(");
2584 Sprint_Node (Left_Opnd (Node));
2585 Write_Str (", ");
2586 Sprint_Node (Right_Opnd (Node));
2587 Write_Char (')');
2589 when N_Op_Subtract =>
2590 Sprint_Left_Opnd (Node);
2591 Write_Operator (Node, " - ");
2592 Sprint_Right_Opnd (Node);
2594 when N_Op_Xor =>
2595 Sprint_Left_Opnd (Node);
2596 Write_Operator (Node, " xor ");
2597 Sprint_Right_Opnd (Node);
2599 when N_Operator_Symbol =>
2600 Write_Name_With_Col_Check_Sloc (Chars (Node));
2602 when N_Ordinary_Fixed_Point_Definition =>
2603 Write_Str_With_Col_Check_Sloc ("delta ");
2604 Sprint_Node (Delta_Expression (Node));
2605 Sprint_Opt_Node (Real_Range_Specification (Node));
2607 when N_Or_Else =>
2608 Sprint_Left_Opnd (Node);
2609 Write_Str_Sloc (" or else ");
2610 Sprint_Right_Opnd (Node);
2612 when N_Others_Choice =>
2613 if All_Others (Node) then
2614 Write_Str_With_Col_Check ("all ");
2615 end if;
2617 Write_Str_With_Col_Check_Sloc ("others");
2619 when N_Package_Body =>
2620 Extra_Blank_Line;
2621 Write_Indent_Str_Sloc ("package body ");
2622 Sprint_Node (Defining_Unit_Name (Node));
2623 Write_Str (" is");
2624 Sprint_Indented_List (Declarations (Node));
2626 if Present (Handled_Statement_Sequence (Node)) then
2627 Write_Indent_Str ("begin");
2628 Sprint_Node (Handled_Statement_Sequence (Node));
2629 end if;
2631 Write_Indent_Str ("end ");
2632 Sprint_End_Label
2633 (Handled_Statement_Sequence (Node), Defining_Unit_Name (Node));
2634 Write_Char (';');
2636 when N_Package_Body_Stub =>
2637 Write_Indent_Str_Sloc ("package body ");
2638 Sprint_Node (Defining_Identifier (Node));
2639 Write_Str_With_Col_Check (" is separate;");
2641 when N_Package_Declaration =>
2642 Extra_Blank_Line;
2643 Write_Indent;
2644 Sprint_Node_Sloc (Specification (Node));
2645 Write_Char (';');
2647 -- If this is an instantiation, get the aspects from the original
2648 -- instantiation node.
2650 if Is_Generic_Instance (Defining_Entity (Node))
2651 and then Has_Aspects
2652 (Package_Instantiation (Defining_Entity (Node)))
2653 then
2654 Sprint_Aspect_Specifications
2655 (Package_Instantiation (Defining_Entity (Node)),
2656 Semicolon => True);
2657 end if;
2659 when N_Package_Instantiation =>
2660 Extra_Blank_Line;
2661 Write_Indent_Str_Sloc ("package ");
2662 Sprint_Node (Defining_Unit_Name (Node));
2663 Write_Str (" is new ");
2664 Sprint_Node (Name (Node));
2665 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
2666 Write_Char (';');
2668 when N_Package_Renaming_Declaration =>
2669 Write_Indent_Str_Sloc ("package ");
2670 Sprint_Node (Defining_Unit_Name (Node));
2671 Write_Str_With_Col_Check (" renames ");
2672 Sprint_Node (Name (Node));
2673 Write_Char (';');
2675 when N_Package_Specification =>
2676 Write_Str_With_Col_Check_Sloc ("package ");
2677 Sprint_Node (Defining_Unit_Name (Node));
2679 if Nkind (Parent (Node)) = N_Generic_Package_Declaration
2680 and then Has_Aspects (Parent (Node))
2681 then
2682 Sprint_Aspect_Specifications
2683 (Parent (Node), Semicolon => False);
2685 -- An instantiation is rewritten as a package declaration, but
2686 -- the aspects belong to the instantiation node.
2688 elsif Nkind (Parent (Node)) = N_Package_Declaration then
2689 declare
2690 Pack : constant Entity_Id := Defining_Entity (Node);
2692 begin
2693 if not Is_Generic_Instance (Pack) then
2694 if Has_Aspects (Parent (Node)) then
2695 Sprint_Aspect_Specifications
2696 (Parent (Node), Semicolon => False);
2697 end if;
2698 end if;
2699 end;
2700 end if;
2702 Write_Str (" is");
2703 Sprint_Indented_List (Visible_Declarations (Node));
2705 if Present (Private_Declarations (Node)) then
2706 Write_Indent_Str ("private");
2707 Sprint_Indented_List (Private_Declarations (Node));
2708 end if;
2710 Write_Indent_Str ("end ");
2711 Sprint_Node (Defining_Unit_Name (Node));
2713 when N_Parameter_Association =>
2714 Sprint_Node_Sloc (Selector_Name (Node));
2715 Write_Str (" => ");
2716 Sprint_Node (Explicit_Actual_Parameter (Node));
2718 when N_Parameter_Specification =>
2719 Set_Debug_Sloc;
2721 if Write_Identifiers (Node) then
2722 Write_Str (" : ");
2724 if In_Present (Node) then
2725 Write_Str_With_Col_Check ("in ");
2726 end if;
2728 if Out_Present (Node) then
2729 Write_Str_With_Col_Check ("out ");
2730 end if;
2732 -- Ada 2005 (AI-231): Parameter specification may carry null
2733 -- exclusion. Do not print it now if this is an access formal,
2734 -- it is emitted when the access definition is displayed.
2736 if Null_Exclusion_Present (Node)
2737 and then Nkind (Parameter_Type (Node)) /= N_Access_Definition
2738 then
2739 Write_Str ("not null ");
2740 end if;
2742 if Aliased_Present (Node) then
2743 Write_Str ("aliased ");
2744 end if;
2746 Sprint_Node (Parameter_Type (Node));
2748 if Present (Expression (Node)) then
2749 Write_Str (" := ");
2750 Sprint_Node (Expression (Node));
2751 end if;
2752 else
2753 Write_Str (", ");
2754 end if;
2756 when N_Pop_Constraint_Error_Label =>
2757 Write_Indent_Str ("%pop_constraint_error_label");
2759 when N_Pop_Program_Error_Label =>
2760 Write_Indent_Str ("%pop_program_error_label");
2762 when N_Pop_Storage_Error_Label =>
2763 Write_Indent_Str ("%pop_storage_error_label");
2765 when N_Private_Extension_Declaration =>
2766 Write_Indent_Str_Sloc ("type ");
2767 Write_Id (Defining_Identifier (Node));
2769 if Present (Discriminant_Specifications (Node)) then
2770 Write_Discr_Specs (Node);
2771 elsif Unknown_Discriminants_Present (Node) then
2772 Write_Str_With_Col_Check ("(<>)");
2773 end if;
2775 Write_Str_With_Col_Check (" is new ");
2776 Sprint_Node (Subtype_Indication (Node));
2778 if Present (Interface_List (Node)) then
2779 Write_Str_With_Col_Check (" and ");
2780 Sprint_And_List (Interface_List (Node));
2781 end if;
2783 Write_Str_With_Col_Check (" with private;");
2785 when N_Private_Type_Declaration =>
2786 Write_Indent_Str_Sloc ("type ");
2787 Write_Id (Defining_Identifier (Node));
2789 if Present (Discriminant_Specifications (Node)) then
2790 Write_Discr_Specs (Node);
2791 elsif Unknown_Discriminants_Present (Node) then
2792 Write_Str_With_Col_Check ("(<>)");
2793 end if;
2795 Write_Str (" is ");
2797 if Tagged_Present (Node) then
2798 Write_Str_With_Col_Check ("tagged ");
2799 end if;
2801 if Limited_Present (Node) then
2802 Write_Str_With_Col_Check ("limited ");
2803 end if;
2805 Write_Str_With_Col_Check ("private;");
2807 when N_Push_Constraint_Error_Label =>
2808 Write_Indent_Str ("%push_constraint_error_label (");
2810 if Present (Exception_Label (Node)) then
2811 Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2812 end if;
2814 Write_Str (")");
2816 when N_Push_Program_Error_Label =>
2817 Write_Indent_Str ("%push_program_error_label (");
2819 if Present (Exception_Label (Node)) then
2820 Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2821 end if;
2823 Write_Str (")");
2825 when N_Push_Storage_Error_Label =>
2826 Write_Indent_Str ("%push_storage_error_label (");
2828 if Present (Exception_Label (Node)) then
2829 Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2830 end if;
2832 Write_Str (")");
2834 when N_Pragma =>
2835 Write_Indent_Str_Sloc ("pragma ");
2836 Write_Name_With_Col_Check (Pragma_Name_Unmapped (Node));
2838 if Present (Pragma_Argument_Associations (Node)) then
2839 Sprint_Opt_Paren_Comma_List
2840 (Pragma_Argument_Associations (Node));
2841 end if;
2843 Write_Char (';');
2845 when N_Pragma_Argument_Association =>
2846 Set_Debug_Sloc;
2848 if Chars (Node) /= No_Name then
2849 Write_Name_With_Col_Check (Chars (Node));
2850 Write_Str (" => ");
2851 end if;
2853 Sprint_Node (Expression (Node));
2855 when N_Procedure_Call_Statement =>
2856 Write_Indent;
2857 Set_Debug_Sloc;
2858 Write_Subprogram_Name (Name (Node));
2859 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
2860 Write_Char (';');
2862 when N_Procedure_Instantiation =>
2863 Write_Indent_Str_Sloc ("procedure ");
2864 Sprint_Node (Defining_Unit_Name (Node));
2865 Write_Str_With_Col_Check (" is new ");
2866 Sprint_Node (Name (Node));
2867 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
2868 Write_Char (';');
2870 when N_Procedure_Specification =>
2871 Write_Str_With_Col_Check_Sloc ("procedure ");
2872 Sprint_Node (Defining_Unit_Name (Node));
2873 Write_Param_Specs (Node);
2875 when N_Protected_Body =>
2876 Write_Indent_Str_Sloc ("protected body ");
2877 Write_Id (Defining_Identifier (Node));
2878 Write_Str (" is");
2879 Sprint_Indented_List (Declarations (Node));
2880 Write_Indent_Str ("end ");
2881 Write_Id (Defining_Identifier (Node));
2882 Write_Char (';');
2884 when N_Protected_Body_Stub =>
2885 Write_Indent_Str_Sloc ("protected body ");
2886 Write_Id (Defining_Identifier (Node));
2887 Write_Str_With_Col_Check (" is separate;");
2889 when N_Protected_Definition =>
2890 Set_Debug_Sloc;
2891 Sprint_Indented_List (Visible_Declarations (Node));
2893 if Present (Private_Declarations (Node)) then
2894 Write_Indent_Str ("private");
2895 Sprint_Indented_List (Private_Declarations (Node));
2896 end if;
2898 Write_Indent_Str ("end ");
2900 when N_Protected_Type_Declaration =>
2901 Write_Indent_Str_Sloc ("protected type ");
2902 Sprint_Node (Defining_Identifier (Node));
2903 Write_Discr_Specs (Node);
2905 if Present (Interface_List (Node)) then
2906 Write_Str (" is new ");
2907 Sprint_And_List (Interface_List (Node));
2908 Write_Str (" with ");
2909 else
2910 Write_Str (" is");
2911 end if;
2913 Sprint_Node (Protected_Definition (Node));
2914 Write_Id (Defining_Identifier (Node));
2915 Write_Char (';');
2917 when N_Qualified_Expression =>
2918 Sprint_Node (Subtype_Mark (Node));
2919 Write_Char_Sloc (''');
2921 -- Print expression, make sure we have at least one level of
2922 -- parentheses around the expression. For cases of qualified
2923 -- expressions in the source, this is always the case, but
2924 -- for generated qualifications, there may be no explicit
2925 -- parentheses present.
2927 if Paren_Count (Expression (Node)) /= 0 then
2928 Sprint_Node (Expression (Node));
2930 else
2931 Write_Char ('(');
2932 Sprint_Node (Expression (Node));
2934 -- Odd case, for the qualified expressions used in machine
2935 -- code the argument may be a procedure call, resulting in
2936 -- a junk semicolon before the right parent, get rid of it.
2938 Write_Erase_Char (';');
2940 -- Now we can add the terminating right paren
2942 Write_Char (')');
2943 end if;
2945 when N_Quantified_Expression =>
2946 Write_Str (" for");
2948 if All_Present (Node) then
2949 Write_Str (" all ");
2950 else
2951 Write_Str (" some ");
2952 end if;
2954 if Present (Iterator_Specification (Node)) then
2955 Sprint_Node (Iterator_Specification (Node));
2956 else
2957 Sprint_Node (Loop_Parameter_Specification (Node));
2958 end if;
2960 Write_Str (" => ");
2961 Sprint_Node (Condition (Node));
2963 when N_Raise_Expression =>
2964 declare
2965 Has_Parens : constant Boolean := Paren_Count (Node) > 0;
2967 begin
2968 -- The syntax for raise_expression does not include parentheses
2969 -- but sometimes parentheses are required, so unconditionally
2970 -- generate them here unless already present.
2972 if not Has_Parens then
2973 Write_Char ('(');
2974 end if;
2976 Write_Str_With_Col_Check_Sloc ("raise ");
2977 Sprint_Node (Name (Node));
2979 if Present (Expression (Node)) then
2980 Write_Str_With_Col_Check (" with ");
2981 Sprint_Node (Expression (Node));
2982 end if;
2984 if not Has_Parens then
2985 Write_Char (')');
2986 end if;
2987 end;
2989 when N_Raise_Constraint_Error =>
2991 -- This node can be used either as a subexpression or as a
2992 -- statement form. The following test is a reasonably reliable
2993 -- way to distinguish the two cases.
2995 if Is_List_Member (Node)
2996 and then Nkind (Parent (Node)) not in N_Subexpr
2997 then
2998 Write_Indent;
2999 end if;
3001 Write_Str_With_Col_Check_Sloc ("[constraint_error");
3002 Write_Condition_And_Reason (Node);
3004 when N_Raise_Program_Error =>
3006 -- This node can be used either as a subexpression or as a
3007 -- statement form. The following test is a reasonably reliable
3008 -- way to distinguish the two cases.
3010 if Is_List_Member (Node)
3011 and then Nkind (Parent (Node)) not in N_Subexpr
3012 then
3013 Write_Indent;
3014 end if;
3016 Write_Str_With_Col_Check_Sloc ("[program_error");
3017 Write_Condition_And_Reason (Node);
3019 when N_Raise_Storage_Error =>
3021 -- This node can be used either as a subexpression or as a
3022 -- statement form. The following test is a reasonably reliable
3023 -- way to distinguish the two cases.
3025 if Is_List_Member (Node)
3026 and then Nkind (Parent (Node)) not in N_Subexpr
3027 then
3028 Write_Indent;
3029 end if;
3031 Write_Str_With_Col_Check_Sloc ("[storage_error");
3032 Write_Condition_And_Reason (Node);
3034 when N_Raise_Statement =>
3035 Write_Indent_Str_Sloc ("raise ");
3036 Sprint_Node (Name (Node));
3038 if Present (Expression (Node)) then
3039 Write_Str_With_Col_Check_Sloc (" with ");
3040 Sprint_Node (Expression (Node));
3041 end if;
3043 Write_Char (';');
3045 when N_Range =>
3046 Sprint_Node (Low_Bound (Node));
3047 Write_Str_Sloc (" .. ");
3048 Sprint_Node (High_Bound (Node));
3049 Update_Itype (Node);
3051 when N_Range_Constraint =>
3052 Write_Str_With_Col_Check_Sloc ("range ");
3053 Sprint_Node (Range_Expression (Node));
3055 when N_Real_Literal =>
3056 Write_Ureal_With_Col_Check_Sloc (Realval (Node));
3058 when N_Real_Range_Specification =>
3059 Write_Str_With_Col_Check_Sloc ("range ");
3060 Sprint_Node (Low_Bound (Node));
3061 Write_Str (" .. ");
3062 Sprint_Node (High_Bound (Node));
3064 when N_Record_Definition =>
3065 if Abstract_Present (Node) then
3066 Write_Str_With_Col_Check ("abstract ");
3067 end if;
3069 if Tagged_Present (Node) then
3070 Write_Str_With_Col_Check ("tagged ");
3071 end if;
3073 if Limited_Present (Node) then
3074 Write_Str_With_Col_Check ("limited ");
3075 end if;
3077 if Null_Present (Node) then
3078 Write_Str_With_Col_Check_Sloc ("null record");
3080 else
3081 Write_Str_With_Col_Check_Sloc ("record");
3082 Sprint_Node (Component_List (Node));
3083 Write_Indent_Str ("end record");
3084 end if;
3086 when N_Record_Representation_Clause =>
3087 Write_Indent_Str_Sloc ("for ");
3088 Sprint_Node (Identifier (Node));
3089 Write_Str_With_Col_Check (" use record ");
3091 if Present (Mod_Clause (Node)) then
3092 Sprint_Node (Mod_Clause (Node));
3093 end if;
3095 Sprint_Indented_List (Component_Clauses (Node));
3096 Write_Indent_Str ("end record;");
3098 when N_Reference =>
3099 Sprint_Node (Prefix (Node));
3100 Write_Str_With_Col_Check_Sloc ("'reference");
3102 when N_Requeue_Statement =>
3103 Write_Indent_Str_Sloc ("requeue ");
3104 Sprint_Node (Name (Node));
3106 if Abort_Present (Node) then
3107 Write_Str_With_Col_Check (" with abort");
3108 end if;
3110 Write_Char (';');
3112 -- Don't we want to print more detail???
3114 -- Doc of this extended syntax belongs in sinfo.ads and/or
3115 -- sprint.ads ???
3117 when N_SCIL_Dispatch_Table_Tag_Init =>
3118 Write_Indent_Str ("[N_SCIL_Dispatch_Table_Tag_Init]");
3120 when N_SCIL_Dispatching_Call =>
3121 Write_Indent_Str ("[N_SCIL_Dispatching_Node]");
3123 when N_SCIL_Membership_Test =>
3124 Write_Indent_Str ("[N_SCIL_Membership_Test]");
3126 when N_Simple_Return_Statement =>
3127 if Present (Expression (Node)) then
3128 Write_Indent_Str_Sloc ("return ");
3129 Sprint_Node (Expression (Node));
3130 Write_Char (';');
3131 else
3132 Write_Indent_Str_Sloc ("return;");
3133 end if;
3135 when N_Selective_Accept =>
3136 Write_Indent_Str_Sloc ("select");
3138 declare
3139 Alt_Node : Node_Id;
3140 begin
3141 Alt_Node := First (Select_Alternatives (Node));
3142 loop
3143 Indent_Begin;
3144 Sprint_Node (Alt_Node);
3145 Indent_End;
3146 Next (Alt_Node);
3147 exit when No (Alt_Node);
3148 Write_Indent_Str ("or");
3149 end loop;
3150 end;
3152 if Present (Else_Statements (Node)) then
3153 Write_Indent_Str ("else");
3154 Sprint_Indented_List (Else_Statements (Node));
3155 end if;
3157 Write_Indent_Str ("end select;");
3159 when N_Signed_Integer_Type_Definition =>
3160 Write_Str_With_Col_Check_Sloc ("range ");
3161 Sprint_Node (Low_Bound (Node));
3162 Write_Str (" .. ");
3163 Sprint_Node (High_Bound (Node));
3165 when N_Single_Protected_Declaration =>
3166 Write_Indent_Str_Sloc ("protected ");
3167 Write_Id (Defining_Identifier (Node));
3168 Write_Str (" is");
3169 Sprint_Node (Protected_Definition (Node));
3170 Write_Id (Defining_Identifier (Node));
3171 Write_Char (';');
3173 when N_Single_Task_Declaration =>
3174 Write_Indent_Str_Sloc ("task ");
3175 Sprint_Node (Defining_Identifier (Node));
3177 if Present (Task_Definition (Node)) then
3178 Write_Str (" is");
3179 Sprint_Node (Task_Definition (Node));
3180 end if;
3182 Write_Char (';');
3184 when N_Selected_Component =>
3185 Sprint_Node (Prefix (Node));
3186 Write_Char_Sloc ('.');
3187 Sprint_Node (Selector_Name (Node));
3189 when N_Slice =>
3190 Set_Debug_Sloc;
3191 Sprint_Node (Prefix (Node));
3192 Write_Str_With_Col_Check (" (");
3193 Sprint_Node (Discrete_Range (Node));
3194 Write_Char (')');
3196 when N_String_Literal =>
3197 if String_Length (Strval (Node)) + Column > Sprint_Line_Limit then
3198 Write_Indent_Str (" ");
3199 end if;
3201 Set_Debug_Sloc;
3202 Write_String_Table_Entry (Strval (Node));
3204 when N_Subprogram_Body =>
3206 -- Output extra blank line unless we are in freeze actions
3208 if Freeze_Indent = 0 then
3209 Extra_Blank_Line;
3210 end if;
3212 Write_Indent;
3214 if Present (Corresponding_Spec (Node)) then
3215 Sprint_Node_Sloc (Parent (Corresponding_Spec (Node)));
3216 else
3217 Sprint_Node_Sloc (Specification (Node));
3218 end if;
3220 Write_Str (" is");
3222 Sprint_Indented_List (Declarations (Node));
3223 Write_Indent_Str ("begin");
3224 Sprint_Node (Handled_Statement_Sequence (Node));
3226 Write_Indent_Str ("end ");
3228 Sprint_End_Label
3229 (Handled_Statement_Sequence (Node),
3230 Defining_Unit_Name (Specification (Node)));
3231 Write_Char (';');
3233 if Is_List_Member (Node)
3234 and then Present (Next (Node))
3235 and then Nkind (Next (Node)) /= N_Subprogram_Body
3236 then
3237 Write_Indent;
3238 end if;
3240 when N_Subprogram_Body_Stub =>
3241 Write_Indent;
3242 Sprint_Node_Sloc (Specification (Node));
3243 Write_Str_With_Col_Check (" is separate;");
3245 when N_Subprogram_Declaration =>
3246 Write_Indent;
3247 Sprint_Node_Sloc (Specification (Node));
3249 if Nkind (Specification (Node)) = N_Procedure_Specification
3250 and then Null_Present (Specification (Node))
3251 then
3252 Write_Str_With_Col_Check (" is null");
3253 end if;
3255 Write_Char (';');
3257 when N_Subprogram_Renaming_Declaration =>
3258 Write_Indent;
3259 Sprint_Node (Specification (Node));
3260 Write_Str_With_Col_Check_Sloc (" renames ");
3261 Sprint_Node (Name (Node));
3262 Write_Char (';');
3264 when N_Subtype_Declaration =>
3265 Write_Indent_Str_Sloc ("subtype ");
3266 Sprint_Node (Defining_Identifier (Node));
3267 Write_Str (" is ");
3269 -- Ada 2005 (AI-231)
3271 if Null_Exclusion_Present (Node) then
3272 Write_Str ("not null ");
3273 end if;
3275 Sprint_Node (Subtype_Indication (Node));
3276 Write_Char (';');
3278 when N_Subtype_Indication =>
3279 Sprint_Node_Sloc (Subtype_Mark (Node));
3280 Write_Char (' ');
3281 Sprint_Node (Constraint (Node));
3283 when N_Subunit =>
3284 Write_Indent_Str_Sloc ("separate (");
3285 Sprint_Node (Name (Node));
3286 Write_Char (')');
3287 Extra_Blank_Line;
3288 Sprint_Node (Proper_Body (Node));
3290 when N_Task_Body =>
3291 Write_Indent_Str_Sloc ("task body ");
3292 Write_Id (Defining_Identifier (Node));
3293 Write_Str (" is");
3294 Sprint_Indented_List (Declarations (Node));
3295 Write_Indent_Str ("begin");
3296 Sprint_Node (Handled_Statement_Sequence (Node));
3297 Write_Indent_Str ("end ");
3298 Sprint_End_Label
3299 (Handled_Statement_Sequence (Node), Defining_Identifier (Node));
3300 Write_Char (';');
3302 when N_Task_Body_Stub =>
3303 Write_Indent_Str_Sloc ("task body ");
3304 Write_Id (Defining_Identifier (Node));
3305 Write_Str_With_Col_Check (" is separate;");
3307 when N_Task_Definition =>
3308 Set_Debug_Sloc;
3309 Sprint_Indented_List (Visible_Declarations (Node));
3311 if Present (Private_Declarations (Node)) then
3312 Write_Indent_Str ("private");
3313 Sprint_Indented_List (Private_Declarations (Node));
3314 end if;
3316 Write_Indent_Str ("end ");
3317 Sprint_End_Label (Node, Defining_Identifier (Parent (Node)));
3319 when N_Task_Type_Declaration =>
3320 Write_Indent_Str_Sloc ("task type ");
3321 Sprint_Node (Defining_Identifier (Node));
3322 Write_Discr_Specs (Node);
3324 if Present (Interface_List (Node)) then
3325 Write_Str (" is new ");
3326 Sprint_And_List (Interface_List (Node));
3327 end if;
3329 if Present (Task_Definition (Node)) then
3330 if No (Interface_List (Node)) then
3331 Write_Str (" is");
3332 else
3333 Write_Str (" with ");
3334 end if;
3336 Sprint_Node (Task_Definition (Node));
3337 end if;
3339 Write_Char (';');
3341 when N_Terminate_Alternative =>
3342 Sprint_Node_List (Pragmas_Before (Node));
3343 Write_Indent;
3345 if Present (Condition (Node)) then
3346 Write_Str_With_Col_Check ("when ");
3347 Sprint_Node (Condition (Node));
3348 Write_Str (" => ");
3349 end if;
3351 Write_Str_With_Col_Check_Sloc ("terminate;");
3352 Sprint_Node_List (Pragmas_After (Node));
3354 when N_Timed_Entry_Call =>
3355 Write_Indent_Str_Sloc ("select");
3356 Indent_Begin;
3357 Sprint_Node (Entry_Call_Alternative (Node));
3358 Indent_End;
3359 Write_Indent_Str ("or");
3360 Indent_Begin;
3361 Sprint_Node (Delay_Alternative (Node));
3362 Indent_End;
3363 Write_Indent_Str ("end select;");
3365 when N_Triggering_Alternative =>
3366 Sprint_Node_List (Pragmas_Before (Node));
3367 Sprint_Node_Sloc (Triggering_Statement (Node));
3368 Sprint_Node_List (Statements (Node));
3370 when N_Type_Conversion =>
3371 Set_Debug_Sloc;
3372 Sprint_Node (Subtype_Mark (Node));
3373 Col_Check (4);
3375 if Conversion_OK (Node) then
3376 Write_Char ('?');
3377 end if;
3379 if Float_Truncate (Node) then
3380 Write_Char ('^');
3381 end if;
3383 if Rounded_Result (Node) then
3384 Write_Char ('@');
3385 end if;
3387 Write_Char ('(');
3388 Sprint_Node (Expression (Node));
3389 Write_Char (')');
3391 when N_Unchecked_Expression =>
3392 Col_Check (10);
3393 Write_Str ("`(");
3394 Sprint_Node_Sloc (Expression (Node));
3395 Write_Char (')');
3397 when N_Unchecked_Type_Conversion =>
3398 Sprint_Node (Subtype_Mark (Node));
3399 Write_Char ('!');
3400 Write_Str_With_Col_Check ("(");
3401 Sprint_Node_Sloc (Expression (Node));
3402 Write_Char (')');
3404 when N_Unconstrained_Array_Definition =>
3405 Write_Str_With_Col_Check_Sloc ("array (");
3407 declare
3408 Node1 : Node_Id;
3409 begin
3410 Node1 := First (Subtype_Marks (Node));
3411 loop
3412 Sprint_Node (Node1);
3413 Write_Str_With_Col_Check (" range <>");
3414 Next (Node1);
3415 exit when Node1 = Empty;
3416 Write_Str (", ");
3417 end loop;
3418 end;
3420 Write_Str (") of ");
3421 Sprint_Node (Component_Definition (Node));
3423 when N_Unused_At_Start | N_Unused_At_End =>
3424 Write_Indent_Str ("***** Error, unused node encountered *****");
3425 Write_Eol;
3427 when N_Use_Package_Clause =>
3428 Write_Indent_Str_Sloc ("use ");
3429 Sprint_Comma_List (Names (Node));
3430 Write_Char (';');
3432 when N_Use_Type_Clause =>
3433 Write_Indent_Str_Sloc ("use type ");
3434 Sprint_Comma_List (Subtype_Marks (Node));
3435 Write_Char (';');
3437 when N_Validate_Unchecked_Conversion =>
3438 Write_Indent_Str_Sloc ("validate unchecked_conversion (");
3439 Sprint_Node (Source_Type (Node));
3440 Write_Str (", ");
3441 Sprint_Node (Target_Type (Node));
3442 Write_Str (");");
3444 when N_Variant =>
3445 Write_Indent_Str_Sloc ("when ");
3446 Sprint_Bar_List (Discrete_Choices (Node));
3447 Write_Str (" => ");
3448 Sprint_Node (Component_List (Node));
3450 when N_Variant_Part =>
3451 Indent_Begin;
3452 Write_Indent_Str_Sloc ("case ");
3453 Sprint_Node (Name (Node));
3454 Write_Str (" is ");
3455 Sprint_Indented_List (Variants (Node));
3456 Write_Indent_Str ("end case");
3457 Indent_End;
3459 when N_With_Clause =>
3461 -- Special test, if we are dumping the original tree only,
3462 -- then we want to eliminate the bogus with clauses that
3463 -- correspond to the non-existent children of Text_IO.
3465 if Dump_Original_Only
3466 and then Is_Text_IO_Special_Unit (Name (Node))
3467 then
3468 null;
3470 -- Normal case, output the with clause
3472 else
3473 if First_Name (Node) or else not Dump_Original_Only then
3475 -- Ada 2005 (AI-50217): Print limited with_clauses
3477 if Private_Present (Node) and Limited_Present (Node) then
3478 Write_Indent_Str ("limited private with ");
3480 elsif Private_Present (Node) then
3481 Write_Indent_Str ("private with ");
3483 elsif Limited_Present (Node) then
3484 Write_Indent_Str ("limited with ");
3486 else
3487 Write_Indent_Str ("with ");
3488 end if;
3490 else
3491 Write_Str (", ");
3492 end if;
3494 Sprint_Node_Sloc (Name (Node));
3496 if Last_Name (Node) or else not Dump_Original_Only then
3497 Write_Char (';');
3498 end if;
3499 end if;
3500 end case;
3502 -- Print aspects, except for special case of package declaration,
3503 -- where the aspects are printed inside the package specification.
3505 if Has_Aspects (Node)
3506 and then not Nkind_In (Node, N_Package_Declaration,
3507 N_Generic_Package_Declaration)
3508 then
3509 Sprint_Aspect_Specifications (Node, Semicolon => True);
3510 end if;
3512 if Nkind (Node) in N_Subexpr
3513 and then Do_Range_Check (Node)
3514 then
3515 Write_Str ("}");
3516 end if;
3518 for J in 1 .. Paren_Count (Node) loop
3519 Write_Char (')');
3520 end loop;
3522 Dump_Node := Save_Dump_Node;
3523 end Sprint_Node_Actual;
3525 ----------------------
3526 -- Sprint_Node_List --
3527 ----------------------
3529 procedure Sprint_Node_List (List : List_Id; New_Lines : Boolean := False) is
3530 Node : Node_Id;
3532 begin
3533 if Is_Non_Empty_List (List) then
3534 Node := First (List);
3536 loop
3537 Sprint_Node (Node);
3538 Next (Node);
3539 exit when Node = Empty;
3540 end loop;
3541 end if;
3543 if New_Lines and then Column /= 1 then
3544 Write_Eol;
3545 end if;
3546 end Sprint_Node_List;
3548 ----------------------
3549 -- Sprint_Node_Sloc --
3550 ----------------------
3552 procedure Sprint_Node_Sloc (Node : Node_Id) is
3553 begin
3554 Sprint_Node (Node);
3556 if Debug_Generated_Code and then Present (Dump_Node) then
3557 Set_Sloc (Dump_Node, Sloc (Node));
3558 Dump_Node := Empty;
3559 end if;
3560 end Sprint_Node_Sloc;
3562 ---------------------
3563 -- Sprint_Opt_Node --
3564 ---------------------
3566 procedure Sprint_Opt_Node (Node : Node_Id) is
3567 begin
3568 if Present (Node) then
3569 Write_Char (' ');
3570 Sprint_Node (Node);
3571 end if;
3572 end Sprint_Opt_Node;
3574 --------------------------
3575 -- Sprint_Opt_Node_List --
3576 --------------------------
3578 procedure Sprint_Opt_Node_List (List : List_Id) is
3579 begin
3580 if Present (List) then
3581 Sprint_Node_List (List);
3582 end if;
3583 end Sprint_Opt_Node_List;
3585 ---------------------------------
3586 -- Sprint_Opt_Paren_Comma_List --
3587 ---------------------------------
3589 procedure Sprint_Opt_Paren_Comma_List (List : List_Id) is
3590 begin
3591 if Is_Non_Empty_List (List) then
3592 Write_Char (' ');
3593 Sprint_Paren_Comma_List (List);
3594 end if;
3595 end Sprint_Opt_Paren_Comma_List;
3597 -----------------------------
3598 -- Sprint_Paren_Comma_List --
3599 -----------------------------
3601 procedure Sprint_Paren_Comma_List (List : List_Id) is
3602 N : Node_Id;
3603 Node_Exists : Boolean := False;
3605 begin
3607 if Is_Non_Empty_List (List) then
3609 if Dump_Original_Only then
3610 N := First (List);
3611 while Present (N) loop
3612 if not Is_Rewrite_Insertion (N) then
3613 Node_Exists := True;
3614 exit;
3615 end if;
3617 Next (N);
3618 end loop;
3620 if not Node_Exists then
3621 return;
3622 end if;
3623 end if;
3625 Write_Str_With_Col_Check ("(");
3626 Sprint_Comma_List (List);
3627 Write_Char (')');
3628 end if;
3629 end Sprint_Paren_Comma_List;
3631 ----------------------
3632 -- Sprint_Right_Opnd --
3633 ----------------------
3635 procedure Sprint_Right_Opnd (N : Node_Id) is
3636 Opnd : constant Node_Id := Right_Opnd (N);
3638 begin
3639 if Paren_Count (Opnd) /= 0
3640 or else Op_Prec (Nkind (Opnd)) > Op_Prec (Nkind (N))
3641 then
3642 Sprint_Node (Opnd);
3644 else
3645 Write_Char ('(');
3646 Sprint_Node (Opnd);
3647 Write_Char (')');
3648 end if;
3649 end Sprint_Right_Opnd;
3651 ------------------
3652 -- Update_Itype --
3653 ------------------
3655 procedure Update_Itype (Node : Node_Id) is
3656 begin
3657 if Present (Etype (Node))
3658 and then Is_Itype (Etype (Node))
3659 and then Debug_Generated_Code
3660 then
3661 Set_Sloc (Etype (Node), Sloc (Node));
3662 end if;
3663 end Update_Itype;
3665 ---------------------
3666 -- Write_Char_Sloc --
3667 ---------------------
3669 procedure Write_Char_Sloc (C : Character) is
3670 begin
3671 if Debug_Generated_Code and then C /= ' ' then
3672 Set_Debug_Sloc;
3673 end if;
3675 Write_Char (C);
3676 end Write_Char_Sloc;
3678 --------------------------------
3679 -- Write_Condition_And_Reason --
3680 --------------------------------
3682 procedure Write_Condition_And_Reason (Node : Node_Id) is
3683 Cond : constant Node_Id := Condition (Node);
3684 Image : constant String := RT_Exception_Code'Image
3685 (RT_Exception_Code'Val
3686 (UI_To_Int (Reason (Node))));
3688 begin
3689 if Present (Cond) then
3691 -- If condition is a single entity, or NOT with a single entity,
3692 -- output all on one line, since it will likely fit just fine.
3694 if Is_Entity_Name (Cond)
3695 or else (Nkind (Cond) = N_Op_Not
3696 and then Is_Entity_Name (Right_Opnd (Cond)))
3697 then
3698 Write_Str_With_Col_Check (" when ");
3699 Sprint_Node (Cond);
3700 Write_Char (' ');
3702 -- Otherwise for more complex condition, multiple lines
3704 else
3705 Write_Str_With_Col_Check (" when");
3706 Indent := Indent + 2;
3707 Write_Indent;
3708 Sprint_Node (Cond);
3709 Write_Indent;
3710 Indent := Indent - 2;
3711 end if;
3713 -- If no condition, just need a space (all on one line)
3715 else
3716 Write_Char (' ');
3717 end if;
3719 -- Write the reason
3721 Write_Char ('"');
3723 for J in 4 .. Image'Last loop
3724 if Image (J) = '_' then
3725 Write_Char (' ');
3726 else
3727 Write_Char (Fold_Lower (Image (J)));
3728 end if;
3729 end loop;
3731 Write_Str ("""]");
3732 end Write_Condition_And_Reason;
3734 --------------------------------
3735 -- Write_Corresponding_Source --
3736 --------------------------------
3738 procedure Write_Corresponding_Source (S : String) is
3739 Loc : Source_Ptr;
3740 Src : Source_Buffer_Ptr;
3742 begin
3743 -- Ignore if not in dump source text mode, or if in freeze actions
3745 if Dump_Source_Text and then Freeze_Indent = 0 then
3747 -- Ignore null string
3749 if S = "" then
3750 return;
3751 end if;
3753 -- Ignore space or semicolon at end of given string
3755 if S (S'Last) = ' ' or else S (S'Last) = ';' then
3756 Write_Corresponding_Source (S (S'First .. S'Last - 1));
3757 return;
3758 end if;
3760 -- Loop to look at next lines not yet printed in source file
3762 for L in
3763 Last_Line_Printed + 1 .. Last_Source_Line (Current_Source_File)
3764 loop
3765 Src := Source_Text (Current_Source_File);
3766 Loc := Line_Start (L, Current_Source_File);
3768 -- If comment, keep looking
3770 if Src (Loc .. Loc + 1) = "--" then
3771 null;
3773 -- Search to first non-blank
3775 else
3776 while Src (Loc) not in Line_Terminator loop
3778 -- Non-blank found
3780 if Src (Loc) /= ' ' and then Src (Loc) /= ASCII.HT then
3782 -- Loop through characters in string to see if we match
3784 for J in S'Range loop
3786 -- If mismatch, then not the case we are looking for
3788 if Src (Loc) /= S (J) then
3789 return;
3790 end if;
3792 Loc := Loc + 1;
3793 end loop;
3795 -- If we fall through, string matched, if white space or
3796 -- semicolon after the matched string, this is the case
3797 -- we are looking for.
3799 if Src (Loc) in Line_Terminator
3800 or else Src (Loc) = ' '
3801 or else Src (Loc) = ASCII.HT
3802 or else Src (Loc) = ';'
3803 then
3804 -- So output source lines up to and including this one
3806 Write_Source_Lines (L);
3807 return;
3808 end if;
3809 end if;
3811 Loc := Loc + 1;
3812 end loop;
3813 end if;
3815 -- Line was all blanks, or a comment line, keep looking
3817 end loop;
3818 end if;
3819 end Write_Corresponding_Source;
3821 -----------------------
3822 -- Write_Discr_Specs --
3823 -----------------------
3825 procedure Write_Discr_Specs (N : Node_Id) is
3826 Specs : List_Id;
3827 Spec : Node_Id;
3829 begin
3830 Specs := Discriminant_Specifications (N);
3832 if Present (Specs) then
3833 Write_Str_With_Col_Check (" (");
3834 Spec := First (Specs);
3836 loop
3837 Sprint_Node (Spec);
3838 Next (Spec);
3839 exit when Spec = Empty;
3841 -- Add semicolon, unless we are printing original tree and the
3842 -- next specification is part of a list (but not the first
3843 -- element of that list)
3845 if not Dump_Original_Only or else not Prev_Ids (Spec) then
3846 Write_Str ("; ");
3847 end if;
3848 end loop;
3850 Write_Char (')');
3851 end if;
3852 end Write_Discr_Specs;
3854 -----------------
3855 -- Write_Ekind --
3856 -----------------
3858 procedure Write_Ekind (E : Entity_Id) is
3859 S : constant String := Entity_Kind'Image (Ekind (E));
3861 begin
3862 Name_Len := S'Length;
3863 Name_Buffer (1 .. Name_Len) := S;
3864 Set_Casing (Mixed_Case);
3865 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
3866 end Write_Ekind;
3868 --------------
3869 -- Write_Id --
3870 --------------
3872 procedure Write_Id (N : Node_Id) is
3873 begin
3874 -- Deal with outputting Itype
3876 -- Note: if we are printing the full tree with -gnatds, then we may
3877 -- end up picking up the Associated_Node link from a generic template
3878 -- here which overlaps the Entity field, but as documented, Write_Itype
3879 -- is defended against junk calls.
3881 if Nkind (N) in N_Entity then
3882 Write_Itype (N);
3883 elsif Nkind (N) in N_Has_Entity then
3884 Write_Itype (Entity (N));
3885 end if;
3887 -- Case of a defining identifier
3889 if Nkind (N) = N_Defining_Identifier then
3891 -- If defining identifier has an interface name (and no
3892 -- address clause), then we output the interface name.
3894 if (Is_Imported (N) or else Is_Exported (N))
3895 and then Present (Interface_Name (N))
3896 and then No (Address_Clause (N))
3897 then
3898 String_To_Name_Buffer (Strval (Interface_Name (N)));
3899 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
3901 -- If no interface name (or inactive because there was
3902 -- an address clause), then just output the Chars name.
3904 else
3905 Write_Name_With_Col_Check (Chars (N));
3906 end if;
3908 -- Case of selector of an expanded name where the expanded name
3909 -- has an associated entity, output this entity. Check that the
3910 -- entity or associated node is of the right kind, see above.
3912 elsif Nkind (Parent (N)) = N_Expanded_Name
3913 and then Selector_Name (Parent (N)) = N
3914 and then Present (Entity_Or_Associated_Node (Parent (N)))
3915 and then Nkind (Entity (Parent (N))) in N_Entity
3916 then
3917 Write_Id (Entity (Parent (N)));
3919 -- For any other node with an associated entity, output it
3921 elsif Nkind (N) in N_Has_Entity
3922 and then Present (Entity_Or_Associated_Node (N))
3923 and then Nkind (Entity_Or_Associated_Node (N)) in N_Entity
3924 then
3925 Write_Id (Entity (N));
3927 -- All other cases, we just print the Chars field
3929 else
3930 Write_Name_With_Col_Check (Chars (N));
3931 end if;
3932 end Write_Id;
3934 -----------------------
3935 -- Write_Identifiers --
3936 -----------------------
3938 function Write_Identifiers (Node : Node_Id) return Boolean is
3939 begin
3940 Sprint_Node (Defining_Identifier (Node));
3941 Update_Itype (Defining_Identifier (Node));
3943 -- The remainder of the declaration must be printed unless we are
3944 -- printing the original tree and this is not the last identifier
3946 return
3947 not Dump_Original_Only or else not More_Ids (Node);
3949 end Write_Identifiers;
3951 ------------------------
3952 -- Write_Implicit_Def --
3953 ------------------------
3955 procedure Write_Implicit_Def (E : Entity_Id) is
3956 Ind : Node_Id;
3958 begin
3959 case Ekind (E) is
3960 when E_Array_Subtype =>
3961 Write_Str_With_Col_Check ("subtype ");
3962 Write_Id (E);
3963 Write_Str_With_Col_Check (" is ");
3964 Write_Id (Base_Type (E));
3965 Write_Str_With_Col_Check (" (");
3967 Ind := First_Index (E);
3968 while Present (Ind) loop
3969 Sprint_Node (Ind);
3970 Next_Index (Ind);
3972 if Present (Ind) then
3973 Write_Str (", ");
3974 end if;
3975 end loop;
3977 Write_Str (");");
3979 when E_Enumeration_Subtype
3980 | E_Signed_Integer_Subtype
3982 Write_Str_With_Col_Check ("subtype ");
3983 Write_Id (E);
3984 Write_Str (" is ");
3985 Write_Id (Etype (E));
3986 Write_Str_With_Col_Check (" range ");
3987 Sprint_Node (Scalar_Range (E));
3988 Write_Str (";");
3990 when others =>
3991 Write_Str_With_Col_Check ("type ");
3992 Write_Id (E);
3993 Write_Str_With_Col_Check (" is <");
3994 Write_Ekind (E);
3995 Write_Str (">;");
3996 end case;
3997 end Write_Implicit_Def;
3999 ------------------
4000 -- Write_Indent --
4001 ------------------
4003 procedure Write_Indent is
4004 Loc : constant Source_Ptr := Sloc (Dump_Node);
4006 begin
4007 if Indent_Annull_Flag then
4008 Indent_Annull_Flag := False;
4009 else
4010 -- Deal with Dump_Source_Text output. Note that we ignore implicit
4011 -- label declarations, since they typically have the sloc of the
4012 -- corresponding label, which really messes up the -gnatL output.
4014 if Dump_Source_Text
4015 and then Loc > No_Location
4016 and then Nkind (Dump_Node) /= N_Implicit_Label_Declaration
4017 then
4018 if Get_Source_File_Index (Loc) = Current_Source_File then
4019 Write_Source_Lines
4020 (Get_Physical_Line_Number (Sloc (Dump_Node)));
4021 end if;
4022 end if;
4024 Write_Eol;
4026 for J in 1 .. Indent loop
4027 Write_Char (' ');
4028 end loop;
4029 end if;
4030 end Write_Indent;
4032 ------------------------------
4033 -- Write_Indent_Identifiers --
4034 ------------------------------
4036 function Write_Indent_Identifiers (Node : Node_Id) return Boolean is
4037 begin
4038 -- We need to start a new line for every node, except in the case
4039 -- where we are printing the original tree and this is not the first
4040 -- defining identifier in the list.
4042 if not Dump_Original_Only or else not Prev_Ids (Node) then
4043 Write_Indent;
4045 -- If printing original tree and this is not the first defining
4046 -- identifier in the list, then the previous call to this procedure
4047 -- printed only the name, and we add a comma to separate the names.
4049 else
4050 Write_Str (", ");
4051 end if;
4053 Sprint_Node (Defining_Identifier (Node));
4055 -- The remainder of the declaration must be printed unless we are
4056 -- printing the original tree and this is not the last identifier
4058 return
4059 not Dump_Original_Only or else not More_Ids (Node);
4060 end Write_Indent_Identifiers;
4062 -----------------------------------
4063 -- Write_Indent_Identifiers_Sloc --
4064 -----------------------------------
4066 function Write_Indent_Identifiers_Sloc (Node : Node_Id) return Boolean is
4067 begin
4068 -- We need to start a new line for every node, except in the case
4069 -- where we are printing the original tree and this is not the first
4070 -- defining identifier in the list.
4072 if not Dump_Original_Only or else not Prev_Ids (Node) then
4073 Write_Indent;
4075 -- If printing original tree and this is not the first defining
4076 -- identifier in the list, then the previous call to this procedure
4077 -- printed only the name, and we add a comma to separate the names.
4079 else
4080 Write_Str (", ");
4081 end if;
4083 Set_Debug_Sloc;
4084 Sprint_Node (Defining_Identifier (Node));
4086 -- The remainder of the declaration must be printed unless we are
4087 -- printing the original tree and this is not the last identifier
4089 return not Dump_Original_Only or else not More_Ids (Node);
4090 end Write_Indent_Identifiers_Sloc;
4092 ----------------------
4093 -- Write_Indent_Str --
4094 ----------------------
4096 procedure Write_Indent_Str (S : String) is
4097 begin
4098 Write_Corresponding_Source (S);
4099 Write_Indent;
4100 Write_Str (S);
4101 end Write_Indent_Str;
4103 ---------------------------
4104 -- Write_Indent_Str_Sloc --
4105 ---------------------------
4107 procedure Write_Indent_Str_Sloc (S : String) is
4108 begin
4109 Write_Corresponding_Source (S);
4110 Write_Indent;
4111 Write_Str_Sloc (S);
4112 end Write_Indent_Str_Sloc;
4114 -----------------
4115 -- Write_Itype --
4116 -----------------
4118 procedure Write_Itype (Typ : Entity_Id) is
4120 procedure Write_Header (T : Boolean := True);
4121 -- Write type if T is True, subtype if T is false
4123 ------------------
4124 -- Write_Header --
4125 ------------------
4127 procedure Write_Header (T : Boolean := True) is
4128 begin
4129 if T then
4130 Write_Str ("[type ");
4131 else
4132 Write_Str ("[subtype ");
4133 end if;
4135 Write_Name_With_Col_Check (Chars (Typ));
4136 Write_Str (" is ");
4137 end Write_Header;
4139 -- Start of processing for Write_Itype
4141 begin
4142 if Nkind (Typ) in N_Entity
4143 and then Is_Itype (Typ)
4144 and then not Itype_Printed (Typ)
4145 then
4146 -- Itype to be printed
4148 declare
4149 B : constant Node_Id := Etype (Typ);
4150 X : Node_Id;
4151 P : constant Node_Id := Parent (Typ);
4153 S : constant Saved_Output_Buffer := Save_Output_Buffer;
4154 -- Save current output buffer
4156 Old_Sloc : Source_Ptr;
4157 -- Save sloc of related node, so it is not modified when
4158 -- printing with -gnatD.
4160 begin
4161 -- Write indentation at start of line
4163 for J in 1 .. Indent loop
4164 Write_Char (' ');
4165 end loop;
4167 -- If we have a constructed declaration for the itype, print it
4169 if Present (P)
4170 and then Nkind (P) in N_Declaration
4171 and then Defining_Entity (P) = Typ
4172 then
4173 -- We must set Itype_Printed true before the recursive call to
4174 -- print the node, otherwise we get an infinite recursion.
4176 Set_Itype_Printed (Typ, True);
4178 -- Write the declaration enclosed in [], avoiding new line
4179 -- at start of declaration, and semicolon at end.
4181 -- Note: The itype may be imported from another unit, in which
4182 -- case we do not want to modify the Sloc of the declaration.
4183 -- Otherwise the itype may appear to be in the current unit,
4184 -- and the back-end will reject a reference out of scope.
4186 Write_Char ('[');
4187 Indent_Annull_Flag := True;
4188 Old_Sloc := Sloc (P);
4189 Sprint_Node (P);
4190 Set_Sloc (P, Old_Sloc);
4191 Write_Erase_Char (';');
4193 -- If no constructed declaration, then we have to concoct the
4194 -- source corresponding to the type entity that we have at hand.
4196 else
4197 case Ekind (Typ) is
4199 -- Access types and subtypes
4201 when Access_Kind =>
4202 Write_Header (Ekind (Typ) = E_Access_Type);
4204 if Can_Never_Be_Null (Typ) then
4205 Write_Str ("not null ");
4206 end if;
4208 Write_Str ("access ");
4210 if Is_Access_Constant (Typ) then
4211 Write_Str ("constant ");
4212 end if;
4214 Write_Id (Directly_Designated_Type (Typ));
4216 -- Array types
4218 when E_Array_Type =>
4219 Write_Header;
4220 Write_Str ("array (");
4222 X := First_Index (Typ);
4223 loop
4224 Sprint_Node (X);
4226 if not Is_Constrained (Typ) then
4227 Write_Str (" range <>");
4228 end if;
4230 Next_Index (X);
4231 exit when No (X);
4232 Write_Str (", ");
4233 end loop;
4235 Write_Str (") of ");
4236 X := Component_Type (Typ);
4238 -- Preserve sloc of component type, which is defined
4239 -- elsewhere than the itype (see comment above).
4241 Old_Sloc := Sloc (X);
4242 Sprint_Node (X);
4243 Set_Sloc (X, Old_Sloc);
4245 -- Array subtypes
4247 -- Preserve Sloc of index subtypes, as above
4249 when E_Array_Subtype =>
4250 Write_Header (False);
4251 Write_Id (Etype (Typ));
4252 Write_Str (" (");
4254 X := First_Index (Typ);
4255 loop
4256 Old_Sloc := Sloc (X);
4257 Sprint_Node (X);
4258 Set_Sloc (X, Old_Sloc);
4259 Next_Index (X);
4260 exit when No (X);
4261 Write_Str (", ");
4262 end loop;
4264 Write_Char (')');
4266 -- Signed integer types, and modular integer subtypes,
4267 -- and also enumeration subtypes.
4269 when E_Enumeration_Subtype
4270 | E_Modular_Integer_Subtype
4271 | E_Signed_Integer_Subtype
4272 | E_Signed_Integer_Type
4274 Write_Header (Ekind (Typ) = E_Signed_Integer_Type);
4276 if Ekind (Typ) = E_Signed_Integer_Type then
4277 Write_Str ("new ");
4278 end if;
4280 Write_Id (B);
4282 -- Print bounds if different from base type
4284 declare
4285 L : constant Node_Id := Type_Low_Bound (Typ);
4286 H : constant Node_Id := Type_High_Bound (Typ);
4287 LE : Node_Id;
4288 HE : Node_Id;
4290 begin
4291 -- B can either be a scalar type, in which case the
4292 -- declaration of Typ may constrain it with different
4293 -- bounds, or a private type, in which case we know
4294 -- that the declaration of Typ cannot have a scalar
4295 -- constraint.
4297 if Is_Scalar_Type (B) then
4298 LE := Type_Low_Bound (B);
4299 HE := Type_High_Bound (B);
4300 else
4301 LE := Empty;
4302 HE := Empty;
4303 end if;
4305 if No (LE)
4306 or else (True
4307 and then Nkind (L) = N_Integer_Literal
4308 and then Nkind (H) = N_Integer_Literal
4309 and then Nkind (LE) = N_Integer_Literal
4310 and then Nkind (HE) = N_Integer_Literal
4311 and then UI_Eq (Intval (L), Intval (LE))
4312 and then UI_Eq (Intval (H), Intval (HE)))
4313 then
4314 null;
4316 else
4317 Write_Str (" range ");
4318 Sprint_Node (Type_Low_Bound (Typ));
4319 Write_Str (" .. ");
4320 Sprint_Node (Type_High_Bound (Typ));
4321 end if;
4322 end;
4324 -- Modular integer types
4326 when E_Modular_Integer_Type =>
4327 Write_Header;
4328 Write_Str ("mod ");
4329 Write_Uint_With_Col_Check (Modulus (Typ), Auto);
4331 -- Floating point types and subtypes
4333 when E_Floating_Point_Subtype
4334 | E_Floating_Point_Type
4336 Write_Header (Ekind (Typ) = E_Floating_Point_Type);
4338 if Ekind (Typ) = E_Floating_Point_Type then
4339 Write_Str ("new ");
4340 end if;
4342 Write_Id (Etype (Typ));
4344 if Digits_Value (Typ) /= Digits_Value (Etype (Typ)) then
4345 Write_Str (" digits ");
4346 Write_Uint_With_Col_Check
4347 (Digits_Value (Typ), Decimal);
4348 end if;
4350 -- Print bounds if not different from base type
4352 declare
4353 L : constant Node_Id := Type_Low_Bound (Typ);
4354 H : constant Node_Id := Type_High_Bound (Typ);
4355 LE : constant Node_Id := Type_Low_Bound (B);
4356 HE : constant Node_Id := Type_High_Bound (B);
4358 begin
4359 if Nkind (L) = N_Real_Literal
4360 and then Nkind (H) = N_Real_Literal
4361 and then Nkind (LE) = N_Real_Literal
4362 and then Nkind (HE) = N_Real_Literal
4363 and then UR_Eq (Realval (L), Realval (LE))
4364 and then UR_Eq (Realval (H), Realval (HE))
4365 then
4366 null;
4368 else
4369 Write_Str (" range ");
4370 Sprint_Node (Type_Low_Bound (Typ));
4371 Write_Str (" .. ");
4372 Sprint_Node (Type_High_Bound (Typ));
4373 end if;
4374 end;
4376 -- Record subtypes
4378 when E_Record_Subtype
4379 | E_Record_Subtype_With_Private
4381 Write_Header (False);
4382 Write_Str ("record");
4383 Indent_Begin;
4385 declare
4386 C : Entity_Id;
4387 begin
4388 C := First_Entity (Typ);
4389 while Present (C) loop
4390 Write_Indent;
4391 Write_Id (C);
4392 Write_Str (" : ");
4393 Write_Id (Etype (C));
4394 Next_Entity (C);
4395 end loop;
4396 end;
4398 Indent_End;
4399 Write_Indent_Str (" end record");
4401 -- Class-Wide types
4403 when E_Class_Wide_Subtype
4404 | E_Class_Wide_Type
4406 Write_Header (Ekind (Typ) = E_Class_Wide_Type);
4407 Write_Name_With_Col_Check (Chars (Etype (Typ)));
4408 Write_Str ("'Class");
4410 -- Subprogram types
4412 when E_Subprogram_Type =>
4413 Write_Header;
4415 if Etype (Typ) = Standard_Void_Type then
4416 Write_Str ("procedure");
4417 else
4418 Write_Str ("function");
4419 end if;
4421 if Present (First_Entity (Typ)) then
4422 Write_Str (" (");
4424 declare
4425 Param : Entity_Id;
4427 begin
4428 Param := First_Entity (Typ);
4429 loop
4430 Write_Id (Param);
4431 Write_Str (" : ");
4433 if Ekind (Param) = E_In_Out_Parameter then
4434 Write_Str ("in out ");
4435 elsif Ekind (Param) = E_Out_Parameter then
4436 Write_Str ("out ");
4437 end if;
4439 Write_Id (Etype (Param));
4440 Next_Entity (Param);
4441 exit when No (Param);
4442 Write_Str (", ");
4443 end loop;
4445 Write_Char (')');
4446 end;
4447 end if;
4449 if Etype (Typ) /= Standard_Void_Type then
4450 Write_Str (" return ");
4451 Write_Id (Etype (Typ));
4452 end if;
4454 when E_String_Literal_Subtype =>
4455 declare
4456 LB : constant Uint :=
4457 Expr_Value (String_Literal_Low_Bound (Typ));
4458 Len : constant Uint :=
4459 String_Literal_Length (Typ);
4460 begin
4461 Write_Header (False);
4462 Write_Str ("String (");
4463 Write_Int (UI_To_Int (LB));
4464 Write_Str (" .. ");
4465 Write_Int (UI_To_Int (LB + Len) - 1);
4466 Write_Str (");");
4467 end;
4469 -- For all other Itypes, print ??? (fill in later)
4471 when others =>
4472 Write_Header (True);
4473 Write_Str ("???");
4474 end case;
4475 end if;
4477 -- Add terminating bracket and restore output buffer
4479 Write_Char (']');
4480 Write_Eol;
4481 Restore_Output_Buffer (S);
4482 end;
4484 Set_Itype_Printed (Typ);
4485 end if;
4486 end Write_Itype;
4488 -------------------------------
4489 -- Write_Name_With_Col_Check --
4490 -------------------------------
4492 procedure Write_Name_With_Col_Check (N : Name_Id) is
4493 J : Natural;
4494 K : Natural;
4495 L : Natural;
4497 begin
4498 Get_Name_String (N);
4500 -- Deal with -gnatdI which replaces any sequence Cnnnb where C is an
4501 -- upper case letter, nnn is one or more digits and b is a lower case
4502 -- letter by C...b, so that listings do not depend on serial numbers.
4504 if Debug_Flag_II then
4505 J := 1;
4506 while J < Name_Len - 1 loop
4507 if Name_Buffer (J) in 'A' .. 'Z'
4508 and then Name_Buffer (J + 1) in '0' .. '9'
4509 then
4510 K := J + 1;
4511 while K < Name_Len loop
4512 exit when Name_Buffer (K) not in '0' .. '9';
4513 K := K + 1;
4514 end loop;
4516 if Name_Buffer (K) in 'a' .. 'z' then
4517 L := Name_Len - K + 1;
4519 Name_Buffer (J + 4 .. J + L + 3) :=
4520 Name_Buffer (K .. Name_Len);
4521 Name_Buffer (J + 1 .. J + 3) := "...";
4522 Name_Len := J + L + 3;
4523 J := J + 5;
4525 else
4526 J := K;
4527 end if;
4529 else
4530 J := J + 1;
4531 end if;
4532 end loop;
4533 end if;
4535 -- Fall through for normal case
4537 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
4538 end Write_Name_With_Col_Check;
4540 ------------------------------------
4541 -- Write_Name_With_Col_Check_Sloc --
4542 ------------------------------------
4544 procedure Write_Name_With_Col_Check_Sloc (N : Name_Id) is
4545 begin
4546 Get_Name_String (N);
4547 Write_Str_With_Col_Check_Sloc (Name_Buffer (1 .. Name_Len));
4548 end Write_Name_With_Col_Check_Sloc;
4550 --------------------
4551 -- Write_Operator --
4552 --------------------
4554 procedure Write_Operator (N : Node_Id; S : String) is
4555 F : Natural := S'First;
4556 T : Natural := S'Last;
4558 begin
4559 -- If no overflow check, just write string out, and we are done
4561 if not Do_Overflow_Check (N) then
4562 Write_Str_Sloc (S);
4564 -- If overflow check, we want to surround the operator with curly
4565 -- brackets, but not include spaces within the brackets.
4567 else
4568 if S (F) = ' ' then
4569 Write_Char (' ');
4570 F := F + 1;
4571 end if;
4573 if S (T) = ' ' then
4574 T := T - 1;
4575 end if;
4577 Write_Char ('{');
4578 Write_Str_Sloc (S (F .. T));
4579 Write_Char ('}');
4581 if S (S'Last) = ' ' then
4582 Write_Char (' ');
4583 end if;
4584 end if;
4585 end Write_Operator;
4587 -----------------------
4588 -- Write_Param_Specs --
4589 -----------------------
4591 procedure Write_Param_Specs (N : Node_Id) is
4592 Specs : constant List_Id := Parameter_Specifications (N);
4593 Specs_Present : constant Boolean := Is_Non_Empty_List (Specs);
4595 Ent : Entity_Id;
4596 Extras : Node_Id;
4597 Spec : Node_Id;
4598 Formal : Node_Id;
4600 Output : Boolean := False;
4601 -- Set true if we output at least one parameter
4603 begin
4604 -- Write out explicit specs from Parameter_Speficiations list
4606 if Specs_Present then
4607 Write_Str_With_Col_Check (" (");
4608 Output := True;
4610 Spec := First (Specs);
4611 loop
4612 Sprint_Node (Spec);
4613 Formal := Defining_Identifier (Spec);
4614 Next (Spec);
4615 exit when Spec = Empty;
4617 -- Add semicolon, unless we are printing original tree and the
4618 -- next specification is part of a list (but not the first element
4619 -- of that list).
4621 if not Dump_Original_Only or else not Prev_Ids (Spec) then
4622 Write_Str ("; ");
4623 end if;
4624 end loop;
4625 end if;
4627 -- See if we have extra formals
4629 if Nkind_In (N, N_Function_Specification,
4630 N_Procedure_Specification)
4631 then
4632 Ent := Defining_Entity (N);
4634 -- Loop to write extra formals (if any)
4636 if Present (Ent) and then Is_Subprogram (Ent) then
4637 Extras := Extra_Formals (Ent);
4639 if Present (Extras) then
4640 if not Specs_Present then
4641 Write_Str_With_Col_Check (" (");
4642 Output := True;
4643 end if;
4645 Formal := Extras;
4646 while Present (Formal) loop
4647 if Specs_Present or else Formal /= Extras then
4648 Write_Str ("; ");
4649 end if;
4651 Write_Name_With_Col_Check (Chars (Formal));
4652 Write_Str (" : ");
4653 Write_Name_With_Col_Check (Chars (Etype (Formal)));
4654 Formal := Extra_Formal (Formal);
4655 end loop;
4656 end if;
4657 end if;
4658 end if;
4660 if Output then
4661 Write_Char (')');
4662 end if;
4663 end Write_Param_Specs;
4665 -----------------------
4666 -- Write_Rewrite_Str --
4667 -----------------------
4669 procedure Write_Rewrite_Str (S : String) is
4670 begin
4671 if not Dump_Generated_Only then
4672 if S'Length = 3 and then S = ">>>" then
4673 Write_Str (">>>");
4674 else
4675 Write_Str_With_Col_Check (S);
4676 end if;
4677 end if;
4678 end Write_Rewrite_Str;
4680 -----------------------
4681 -- Write_Source_Line --
4682 -----------------------
4684 procedure Write_Source_Line (L : Physical_Line_Number) is
4685 Loc : Source_Ptr;
4686 Src : Source_Buffer_Ptr;
4687 Scn : Source_Ptr;
4689 begin
4690 if Dump_Source_Text then
4691 Src := Source_Text (Current_Source_File);
4692 Loc := Line_Start (L, Current_Source_File);
4693 Write_Eol;
4695 -- See if line is a comment line, if not, and if not line one,
4696 -- precede with blank line.
4698 Scn := Loc;
4699 while Src (Scn) = ' ' or else Src (Scn) = ASCII.HT loop
4700 Scn := Scn + 1;
4701 end loop;
4703 if (Src (Scn) in Line_Terminator
4704 or else Src (Scn .. Scn + 1) /= "--")
4705 and then L /= 1
4706 then
4707 Write_Eol;
4708 end if;
4710 -- Now write the source text of the line
4712 Write_Str ("-- ");
4713 Write_Int (Int (L));
4714 Write_Str (": ");
4716 while Src (Loc) not in Line_Terminator loop
4717 Write_Char (Src (Loc));
4718 Loc := Loc + 1;
4719 end loop;
4720 end if;
4721 end Write_Source_Line;
4723 ------------------------
4724 -- Write_Source_Lines --
4725 ------------------------
4727 procedure Write_Source_Lines (L : Physical_Line_Number) is
4728 begin
4729 while Last_Line_Printed < L loop
4730 Last_Line_Printed := Last_Line_Printed + 1;
4731 Write_Source_Line (Last_Line_Printed);
4732 end loop;
4733 end Write_Source_Lines;
4735 --------------------
4736 -- Write_Str_Sloc --
4737 --------------------
4739 procedure Write_Str_Sloc (S : String) is
4740 begin
4741 for J in S'Range loop
4742 Write_Char_Sloc (S (J));
4743 end loop;
4744 end Write_Str_Sloc;
4746 ------------------------------
4747 -- Write_Str_With_Col_Check --
4748 ------------------------------
4750 procedure Write_Str_With_Col_Check (S : String) is
4751 begin
4752 if Int (S'Last) + Column > Sprint_Line_Limit then
4753 Write_Indent_Str (" ");
4755 if S (S'First) = ' ' then
4756 Write_Str (S (S'First + 1 .. S'Last));
4757 else
4758 Write_Str (S);
4759 end if;
4761 else
4762 Write_Str (S);
4763 end if;
4764 end Write_Str_With_Col_Check;
4766 -----------------------------------
4767 -- Write_Str_With_Col_Check_Sloc --
4768 -----------------------------------
4770 procedure Write_Str_With_Col_Check_Sloc (S : String) is
4771 begin
4772 if Int (S'Last) + Column > Sprint_Line_Limit then
4773 Write_Indent_Str (" ");
4775 if S (S'First) = ' ' then
4776 Write_Str_Sloc (S (S'First + 1 .. S'Last));
4777 else
4778 Write_Str_Sloc (S);
4779 end if;
4781 else
4782 Write_Str_Sloc (S);
4783 end if;
4784 end Write_Str_With_Col_Check_Sloc;
4786 ---------------------------
4787 -- Write_Subprogram_Name --
4788 ---------------------------
4790 procedure Write_Subprogram_Name (N : Node_Id) is
4791 begin
4792 if not Comes_From_Source (N)
4793 and then Is_Entity_Name (N)
4794 then
4795 declare
4796 Ent : constant Entity_Id := Entity (N);
4797 begin
4798 if not In_Extended_Main_Source_Unit (Ent)
4799 and then
4800 Is_Predefined_File_Name
4801 (Unit_File_Name (Get_Source_Unit (Ent)))
4802 then
4803 -- Run-time routine name, output name with a preceding dollar
4804 -- making sure that we do not get a line split between them.
4806 Col_Check (Length_Of_Name (Chars (Ent)) + 1);
4807 Write_Char ('$');
4808 Write_Name (Chars (Ent));
4809 return;
4810 end if;
4811 end;
4812 end if;
4814 -- Normal case, not a run-time routine name
4816 Sprint_Node (N);
4817 end Write_Subprogram_Name;
4819 -------------------------------
4820 -- Write_Uint_With_Col_Check --
4821 -------------------------------
4823 procedure Write_Uint_With_Col_Check (U : Uint; Format : UI_Format) is
4824 begin
4825 Col_Check (UI_Decimal_Digits_Hi (U));
4826 UI_Write (U, Format);
4827 end Write_Uint_With_Col_Check;
4829 ------------------------------------
4830 -- Write_Uint_With_Col_Check_Sloc --
4831 ------------------------------------
4833 procedure Write_Uint_With_Col_Check_Sloc (U : Uint; Format : UI_Format) is
4834 begin
4835 Col_Check (UI_Decimal_Digits_Hi (U));
4836 Set_Debug_Sloc;
4837 UI_Write (U, Format);
4838 end Write_Uint_With_Col_Check_Sloc;
4840 -------------------------------------
4841 -- Write_Ureal_With_Col_Check_Sloc --
4842 -------------------------------------
4844 procedure Write_Ureal_With_Col_Check_Sloc (U : Ureal) is
4845 D : constant Uint := Denominator (U);
4846 N : constant Uint := Numerator (U);
4847 begin
4848 Col_Check (UI_Decimal_Digits_Hi (D) + UI_Decimal_Digits_Hi (N) + 4);
4849 Set_Debug_Sloc;
4850 UR_Write (U, Brackets => True);
4851 end Write_Ureal_With_Col_Check_Sloc;
4853 end Sprint;