PR middle-end/77674
[official-gcc.git] / gcc / ada / sprint.adb
blob0185719b795991c64e641f9a59db2825a13e535e
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_Component_Clause =>
1332 Write_Indent;
1333 Sprint_Node (Component_Name (Node));
1334 Write_Str_Sloc (" at ");
1335 Sprint_Node (Position (Node));
1336 Write_Char (' ');
1337 Write_Str_With_Col_Check ("range ");
1338 Sprint_Node (First_Bit (Node));
1339 Write_Str (" .. ");
1340 Sprint_Node (Last_Bit (Node));
1341 Write_Char (';');
1343 when N_Component_Definition =>
1344 Set_Debug_Sloc;
1346 -- Ada 2005 (AI-230): Access definition components
1348 if Present (Access_Definition (Node)) then
1349 Sprint_Node (Access_Definition (Node));
1351 elsif Present (Subtype_Indication (Node)) then
1352 if Aliased_Present (Node) then
1353 Write_Str_With_Col_Check ("aliased ");
1354 end if;
1356 -- Ada 2005 (AI-231)
1358 if Null_Exclusion_Present (Node) then
1359 Write_Str (" not null ");
1360 end if;
1362 Sprint_Node (Subtype_Indication (Node));
1364 else
1365 Write_Str (" ??? ");
1366 end if;
1368 when N_Component_Declaration =>
1369 if Write_Indent_Identifiers_Sloc (Node) then
1370 Write_Str (" : ");
1371 Sprint_Node (Component_Definition (Node));
1373 if Present (Expression (Node)) then
1374 Write_Str (" := ");
1375 Sprint_Node (Expression (Node));
1376 end if;
1378 Write_Char (';');
1379 end if;
1381 when N_Component_List =>
1382 if Null_Present (Node) then
1383 Indent_Begin;
1384 Write_Indent_Str_Sloc ("null");
1385 Write_Char (';');
1386 Indent_End;
1388 else
1389 Set_Debug_Sloc;
1390 Sprint_Indented_List (Component_Items (Node));
1391 Sprint_Node (Variant_Part (Node));
1392 end if;
1394 when N_Compound_Statement =>
1395 Write_Indent_Str ("do");
1396 Indent_Begin;
1397 Sprint_Node_List (Actions (Node));
1398 Indent_End;
1399 Write_Indent_Str ("end;");
1401 when N_Conditional_Entry_Call =>
1402 Write_Indent_Str_Sloc ("select");
1403 Indent_Begin;
1404 Sprint_Node (Entry_Call_Alternative (Node));
1405 Indent_End;
1406 Write_Indent_Str ("else");
1407 Sprint_Indented_List (Else_Statements (Node));
1408 Write_Indent_Str ("end select;");
1410 when N_Constrained_Array_Definition =>
1411 Write_Str_With_Col_Check_Sloc ("array ");
1412 Sprint_Paren_Comma_List (Discrete_Subtype_Definitions (Node));
1413 Write_Str (" of ");
1415 Sprint_Node (Component_Definition (Node));
1417 -- A contract node should not appear in the tree. It is a semantic
1418 -- node attached to entry and [generic] subprogram entities. But we
1419 -- still provide meaningful output, in case called from the debugger.
1421 when N_Contract =>
1422 declare
1423 P : Node_Id;
1425 begin
1426 Indent_Begin;
1427 Write_Str ("N_Contract node");
1428 Write_Eol;
1430 Write_Indent_Str ("Pre_Post_Conditions");
1431 Indent_Begin;
1433 P := Pre_Post_Conditions (Node);
1434 while Present (P) loop
1435 Sprint_Node (P);
1436 P := Next_Pragma (P);
1437 end loop;
1439 Write_Eol;
1440 Indent_End;
1442 Write_Indent_Str ("Contract_Test_Cases");
1443 Indent_Begin;
1445 P := Contract_Test_Cases (Node);
1446 while Present (P) loop
1447 Sprint_Node (P);
1448 P := Next_Pragma (P);
1449 end loop;
1451 Write_Eol;
1452 Indent_End;
1454 Write_Indent_Str ("Classifications");
1455 Indent_Begin;
1457 P := Classifications (Node);
1458 while Present (P) loop
1459 Sprint_Node (P);
1460 P := Next_Pragma (P);
1461 end loop;
1463 Write_Eol;
1464 Indent_End;
1465 Indent_End;
1466 end;
1468 when N_Decimal_Fixed_Point_Definition =>
1469 Write_Str_With_Col_Check_Sloc (" delta ");
1470 Sprint_Node (Delta_Expression (Node));
1471 Write_Str_With_Col_Check ("digits ");
1472 Sprint_Node (Digits_Expression (Node));
1473 Sprint_Opt_Node (Real_Range_Specification (Node));
1475 when N_Defining_Character_Literal =>
1476 Write_Name_With_Col_Check_Sloc (Chars (Node));
1478 when N_Defining_Identifier =>
1479 Set_Debug_Sloc;
1480 Write_Id (Node);
1482 when N_Defining_Operator_Symbol =>
1483 Write_Name_With_Col_Check_Sloc (Chars (Node));
1485 when N_Defining_Program_Unit_Name =>
1486 Set_Debug_Sloc;
1487 Sprint_Node (Name (Node));
1488 Write_Char ('.');
1489 Write_Id (Defining_Identifier (Node));
1491 when N_Delay_Alternative =>
1492 Sprint_Node_List (Pragmas_Before (Node));
1494 if Present (Condition (Node)) then
1495 Write_Indent;
1496 Write_Str_With_Col_Check ("when ");
1497 Sprint_Node (Condition (Node));
1498 Write_Str (" => ");
1499 Indent_Annull;
1500 end if;
1502 Sprint_Node_Sloc (Delay_Statement (Node));
1503 Sprint_Node_List (Statements (Node));
1505 when N_Delay_Relative_Statement =>
1506 Write_Indent_Str_Sloc ("delay ");
1507 Sprint_Node (Expression (Node));
1508 Write_Char (';');
1510 when N_Delay_Until_Statement =>
1511 Write_Indent_Str_Sloc ("delay until ");
1512 Sprint_Node (Expression (Node));
1513 Write_Char (';');
1515 when N_Delta_Constraint =>
1516 Write_Str_With_Col_Check_Sloc ("delta ");
1517 Sprint_Node (Delta_Expression (Node));
1518 Sprint_Opt_Node (Range_Constraint (Node));
1520 when N_Derived_Type_Definition =>
1521 if Abstract_Present (Node) then
1522 Write_Str_With_Col_Check ("abstract ");
1523 end if;
1525 Write_Str_With_Col_Check ("new ");
1527 -- Ada 2005 (AI-231)
1529 if Null_Exclusion_Present (Node) then
1530 Write_Str_With_Col_Check ("not null ");
1531 end if;
1533 Sprint_Node (Subtype_Indication (Node));
1535 if Present (Interface_List (Node)) then
1536 Write_Str_With_Col_Check (" and ");
1537 Sprint_And_List (Interface_List (Node));
1538 Write_Str_With_Col_Check (" with ");
1539 end if;
1541 if Present (Record_Extension_Part (Node)) then
1542 if No (Interface_List (Node)) then
1543 Write_Str_With_Col_Check (" with ");
1544 end if;
1546 Sprint_Node (Record_Extension_Part (Node));
1547 end if;
1549 when N_Designator =>
1550 Sprint_Node (Name (Node));
1551 Write_Char_Sloc ('.');
1552 Write_Id (Identifier (Node));
1554 when N_Digits_Constraint =>
1555 Write_Str_With_Col_Check_Sloc ("digits ");
1556 Sprint_Node (Digits_Expression (Node));
1557 Sprint_Opt_Node (Range_Constraint (Node));
1559 when N_Discriminant_Association =>
1560 Set_Debug_Sloc;
1562 if Present (Selector_Names (Node)) then
1563 Sprint_Bar_List (Selector_Names (Node));
1564 Write_Str (" => ");
1565 end if;
1567 Set_Debug_Sloc;
1568 Sprint_Node (Expression (Node));
1570 when N_Discriminant_Specification =>
1571 Set_Debug_Sloc;
1573 if Write_Identifiers (Node) then
1574 Write_Str (" : ");
1576 if Null_Exclusion_Present (Node) then
1577 Write_Str ("not null ");
1578 end if;
1580 Sprint_Node (Discriminant_Type (Node));
1582 if Present (Expression (Node)) then
1583 Write_Str (" := ");
1584 Sprint_Node (Expression (Node));
1585 end if;
1586 else
1587 Write_Str (", ");
1588 end if;
1590 when N_Elsif_Part =>
1591 Write_Indent_Str_Sloc ("elsif ");
1592 Sprint_Node (Condition (Node));
1593 Write_Str_With_Col_Check (" then");
1594 Sprint_Indented_List (Then_Statements (Node));
1596 when N_Empty =>
1597 null;
1599 when N_Entry_Body =>
1600 Write_Indent_Str_Sloc ("entry ");
1601 Write_Id (Defining_Identifier (Node));
1602 Sprint_Node (Entry_Body_Formal_Part (Node));
1603 Write_Str_With_Col_Check (" is");
1604 Sprint_Indented_List (Declarations (Node));
1605 Write_Indent_Str ("begin");
1606 Sprint_Node (Handled_Statement_Sequence (Node));
1607 Write_Indent_Str ("end ");
1608 Write_Id (Defining_Identifier (Node));
1609 Write_Char (';');
1611 when N_Entry_Body_Formal_Part =>
1612 if Present (Entry_Index_Specification (Node)) then
1613 Write_Str_With_Col_Check_Sloc (" (");
1614 Sprint_Node (Entry_Index_Specification (Node));
1615 Write_Char (')');
1616 end if;
1618 Write_Param_Specs (Node);
1619 Write_Str_With_Col_Check_Sloc (" when ");
1620 Sprint_Node (Condition (Node));
1622 when N_Entry_Call_Alternative =>
1623 Sprint_Node_List (Pragmas_Before (Node));
1624 Sprint_Node_Sloc (Entry_Call_Statement (Node));
1625 Sprint_Node_List (Statements (Node));
1627 when N_Entry_Call_Statement =>
1628 Write_Indent;
1629 Sprint_Node_Sloc (Name (Node));
1630 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
1631 Write_Char (';');
1633 when N_Entry_Declaration =>
1634 Write_Indent_Str_Sloc ("entry ");
1635 Write_Id (Defining_Identifier (Node));
1637 if Present (Discrete_Subtype_Definition (Node)) then
1638 Write_Str_With_Col_Check (" (");
1639 Sprint_Node (Discrete_Subtype_Definition (Node));
1640 Write_Char (')');
1641 end if;
1643 Write_Param_Specs (Node);
1644 Write_Char (';');
1646 when N_Entry_Index_Specification =>
1647 Write_Str_With_Col_Check_Sloc ("for ");
1648 Write_Id (Defining_Identifier (Node));
1649 Write_Str_With_Col_Check (" in ");
1650 Sprint_Node (Discrete_Subtype_Definition (Node));
1652 when N_Enumeration_Representation_Clause =>
1653 Write_Indent_Str_Sloc ("for ");
1654 Write_Id (Identifier (Node));
1655 Write_Str_With_Col_Check (" use ");
1656 Sprint_Node (Array_Aggregate (Node));
1657 Write_Char (';');
1659 when N_Enumeration_Type_Definition =>
1660 Set_Debug_Sloc;
1662 -- Skip attempt to print Literals field if it's not there and
1663 -- we are in package Standard (case of Character, which is
1664 -- handled specially (without an explicit literals list).
1666 if Sloc (Node) > Standard_Location
1667 or else Present (Literals (Node))
1668 then
1669 Sprint_Paren_Comma_List (Literals (Node));
1670 end if;
1672 when N_Error =>
1673 Write_Str_With_Col_Check_Sloc ("<error>");
1675 when N_Exception_Declaration =>
1676 if Write_Indent_Identifiers (Node) then
1677 Write_Str_With_Col_Check (" : ");
1679 if Is_Statically_Allocated (Defining_Identifier (Node)) then
1680 Write_Str_With_Col_Check ("static ");
1681 end if;
1683 Write_Str_Sloc ("exception");
1685 if Present (Expression (Node)) then
1686 Write_Str (" := ");
1687 Sprint_Node (Expression (Node));
1688 end if;
1690 Write_Char (';');
1691 end if;
1693 when N_Exception_Handler =>
1694 Write_Indent_Str_Sloc ("when ");
1696 if Present (Choice_Parameter (Node)) then
1697 Sprint_Node (Choice_Parameter (Node));
1698 Write_Str (" : ");
1699 end if;
1701 Sprint_Bar_List (Exception_Choices (Node));
1702 Write_Str (" => ");
1703 Sprint_Indented_List (Statements (Node));
1705 when N_Exception_Renaming_Declaration =>
1706 Write_Indent;
1707 Set_Debug_Sloc;
1708 Sprint_Node (Defining_Identifier (Node));
1709 Write_Str_With_Col_Check (" : exception renames ");
1710 Sprint_Node (Name (Node));
1711 Write_Char (';');
1713 when N_Exit_Statement =>
1714 Write_Indent_Str_Sloc ("exit");
1715 Sprint_Opt_Node (Name (Node));
1717 if Present (Condition (Node)) then
1718 Write_Str_With_Col_Check (" when ");
1719 Sprint_Node (Condition (Node));
1720 end if;
1722 Write_Char (';');
1724 when N_Expanded_Name =>
1725 Sprint_Node (Prefix (Node));
1726 Write_Char_Sloc ('.');
1727 Sprint_Node (Selector_Name (Node));
1729 when N_Explicit_Dereference =>
1730 Sprint_Node (Prefix (Node));
1731 Write_Char_Sloc ('.');
1732 Write_Str_Sloc ("all");
1734 when N_Expression_With_Actions =>
1735 Indent_Begin;
1736 Write_Indent_Str_Sloc ("do ");
1737 Indent_Begin;
1738 Sprint_Node_List (Actions (Node));
1739 Indent_End;
1740 Write_Indent;
1741 Write_Str_With_Col_Check_Sloc ("in ");
1742 Sprint_Node (Expression (Node));
1743 Write_Str_With_Col_Check (" end");
1744 Indent_End;
1745 Write_Indent;
1747 when N_Expression_Function =>
1748 Write_Indent;
1749 Sprint_Node_Sloc (Specification (Node));
1750 Write_Str (" is");
1751 Indent_Begin;
1752 Write_Indent;
1753 Sprint_Node (Expression (Node));
1754 Write_Char (';');
1755 Indent_End;
1757 when N_Extended_Return_Statement =>
1758 Write_Indent_Str_Sloc ("return ");
1759 Sprint_Node_List (Return_Object_Declarations (Node));
1761 if Present (Handled_Statement_Sequence (Node)) then
1762 Write_Str_With_Col_Check (" do");
1763 Sprint_Node (Handled_Statement_Sequence (Node));
1764 Write_Indent_Str ("end return;");
1765 else
1766 Write_Indent_Str (";");
1767 end if;
1769 when N_Extension_Aggregate =>
1770 Write_Str_With_Col_Check_Sloc ("(");
1771 Sprint_Node (Ancestor_Part (Node));
1772 Write_Str_With_Col_Check (" with ");
1774 if Null_Record_Present (Node) then
1775 Write_Str_With_Col_Check ("null record");
1776 else
1777 if Present (Expressions (Node)) then
1778 Sprint_Comma_List (Expressions (Node));
1780 if Present (Component_Associations (Node)) then
1781 Write_Str (", ");
1782 end if;
1783 end if;
1785 if Present (Component_Associations (Node)) then
1786 Sprint_Comma_List (Component_Associations (Node));
1787 end if;
1788 end if;
1790 Write_Char (')');
1792 when N_Floating_Point_Definition =>
1793 Write_Str_With_Col_Check_Sloc ("digits ");
1794 Sprint_Node (Digits_Expression (Node));
1795 Sprint_Opt_Node (Real_Range_Specification (Node));
1797 when N_Formal_Decimal_Fixed_Point_Definition =>
1798 Write_Str_With_Col_Check_Sloc ("delta <> digits <>");
1800 when N_Formal_Derived_Type_Definition =>
1801 Write_Str_With_Col_Check_Sloc ("new ");
1802 Sprint_Node (Subtype_Mark (Node));
1804 if Present (Interface_List (Node)) then
1805 Write_Str_With_Col_Check (" and ");
1806 Sprint_And_List (Interface_List (Node));
1807 end if;
1809 if Private_Present (Node) then
1810 Write_Str_With_Col_Check (" with private");
1811 end if;
1813 when N_Formal_Abstract_Subprogram_Declaration =>
1814 Write_Indent_Str_Sloc ("with ");
1815 Sprint_Node (Specification (Node));
1817 Write_Str_With_Col_Check (" is abstract");
1819 if Box_Present (Node) then
1820 Write_Str_With_Col_Check (" <>");
1821 elsif Present (Default_Name (Node)) then
1822 Write_Str_With_Col_Check (" ");
1823 Sprint_Node (Default_Name (Node));
1824 end if;
1826 Write_Char (';');
1828 when N_Formal_Concrete_Subprogram_Declaration =>
1829 Write_Indent_Str_Sloc ("with ");
1830 Sprint_Node (Specification (Node));
1832 if Box_Present (Node) then
1833 Write_Str_With_Col_Check (" is <>");
1834 elsif Present (Default_Name (Node)) then
1835 Write_Str_With_Col_Check (" is ");
1836 Sprint_Node (Default_Name (Node));
1837 end if;
1839 Write_Char (';');
1841 when N_Formal_Discrete_Type_Definition =>
1842 Write_Str_With_Col_Check_Sloc ("<>");
1844 when N_Formal_Floating_Point_Definition =>
1845 Write_Str_With_Col_Check_Sloc ("digits <>");
1847 when N_Formal_Modular_Type_Definition =>
1848 Write_Str_With_Col_Check_Sloc ("mod <>");
1850 when N_Formal_Object_Declaration =>
1851 Set_Debug_Sloc;
1853 if Write_Indent_Identifiers (Node) then
1854 Write_Str (" : ");
1856 if In_Present (Node) then
1857 Write_Str_With_Col_Check ("in ");
1858 end if;
1860 if Out_Present (Node) then
1861 Write_Str_With_Col_Check ("out ");
1862 end if;
1864 if Present (Subtype_Mark (Node)) then
1866 -- Ada 2005 (AI-423): Formal object with null exclusion
1868 if Null_Exclusion_Present (Node) then
1869 Write_Str ("not null ");
1870 end if;
1872 Sprint_Node (Subtype_Mark (Node));
1874 -- Ada 2005 (AI-423): Formal object with access definition
1876 else
1877 pragma Assert (Present (Access_Definition (Node)));
1879 Sprint_Node (Access_Definition (Node));
1880 end if;
1882 if Present (Default_Expression (Node)) then
1883 Write_Str (" := ");
1884 Sprint_Node (Default_Expression (Node));
1885 end if;
1887 Write_Char (';');
1888 end if;
1890 when N_Formal_Ordinary_Fixed_Point_Definition =>
1891 Write_Str_With_Col_Check_Sloc ("delta <>");
1893 when N_Formal_Package_Declaration =>
1894 Write_Indent_Str_Sloc ("with package ");
1895 Write_Id (Defining_Identifier (Node));
1896 Write_Str_With_Col_Check (" is new ");
1897 Sprint_Node (Name (Node));
1898 Write_Str_With_Col_Check (" (<>);");
1900 when N_Formal_Private_Type_Definition =>
1901 if Abstract_Present (Node) then
1902 Write_Str_With_Col_Check ("abstract ");
1903 end if;
1905 if Tagged_Present (Node) then
1906 Write_Str_With_Col_Check ("tagged ");
1907 end if;
1909 if Limited_Present (Node) then
1910 Write_Str_With_Col_Check ("limited ");
1911 end if;
1913 Write_Str_With_Col_Check_Sloc ("private");
1915 when N_Formal_Incomplete_Type_Definition =>
1916 if Tagged_Present (Node) then
1917 Write_Str_With_Col_Check ("is tagged ");
1918 end if;
1920 when N_Formal_Signed_Integer_Type_Definition =>
1921 Write_Str_With_Col_Check_Sloc ("range <>");
1923 when N_Formal_Type_Declaration =>
1924 Write_Indent_Str_Sloc ("type ");
1925 Write_Id (Defining_Identifier (Node));
1927 if Present (Discriminant_Specifications (Node)) then
1928 Write_Discr_Specs (Node);
1929 elsif Unknown_Discriminants_Present (Node) then
1930 Write_Str_With_Col_Check ("(<>)");
1931 end if;
1933 if Nkind (Formal_Type_Definition (Node)) /=
1934 N_Formal_Incomplete_Type_Definition
1935 then
1936 Write_Str_With_Col_Check (" is ");
1937 end if;
1939 Sprint_Node (Formal_Type_Definition (Node));
1940 Write_Char (';');
1942 when N_Free_Statement =>
1943 Write_Indent_Str_Sloc ("free ");
1944 Sprint_Node (Expression (Node));
1945 Write_Char (';');
1947 when N_Freeze_Entity =>
1948 if Dump_Original_Only then
1949 null;
1951 -- A freeze node is output if it has some effect (i.e. non-empty
1952 -- actions, or freeze node for an itype, which causes elaboration
1953 -- of the itype), and is also always output if Dump_Freeze_Null
1954 -- is set True.
1956 elsif Present (Actions (Node))
1957 or else Is_Itype (Entity (Node))
1958 or else Dump_Freeze_Null
1959 then
1960 Write_Indent;
1961 Write_Rewrite_Str ("<<<");
1962 Write_Str_With_Col_Check_Sloc ("freeze ");
1963 Write_Id (Entity (Node));
1964 Write_Str (" [");
1966 if No (Actions (Node)) then
1967 Write_Char (']');
1969 else
1970 -- Output freeze actions. We increment Freeze_Indent during
1971 -- this output to avoid generating extra blank lines before
1972 -- any procedures included in the freeze actions.
1974 Freeze_Indent := Freeze_Indent + 1;
1975 Sprint_Indented_List (Actions (Node));
1976 Freeze_Indent := Freeze_Indent - 1;
1977 Write_Indent_Str ("]");
1978 end if;
1980 Write_Rewrite_Str (">>>");
1981 end if;
1983 when N_Freeze_Generic_Entity =>
1984 if Dump_Original_Only then
1985 null;
1987 else
1988 Write_Indent;
1989 Write_Str_With_Col_Check_Sloc ("freeze_generic ");
1990 Write_Id (Entity (Node));
1991 end if;
1993 when N_Full_Type_Declaration =>
1994 Write_Indent_Str_Sloc ("type ");
1995 Sprint_Node (Defining_Identifier (Node));
1996 Write_Discr_Specs (Node);
1997 Write_Str_With_Col_Check (" is ");
1998 Sprint_Node (Type_Definition (Node));
1999 Write_Char (';');
2001 when N_Function_Call =>
2002 Set_Debug_Sloc;
2003 Write_Subprogram_Name (Name (Node));
2004 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
2006 when N_Function_Instantiation =>
2007 Write_Indent_Str_Sloc ("function ");
2008 Sprint_Node (Defining_Unit_Name (Node));
2009 Write_Str_With_Col_Check (" is new ");
2010 Sprint_Node (Name (Node));
2011 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
2012 Write_Char (';');
2014 when N_Function_Specification =>
2015 Write_Str_With_Col_Check_Sloc ("function ");
2016 Sprint_Node (Defining_Unit_Name (Node));
2017 Write_Param_Specs (Node);
2018 Write_Str_With_Col_Check (" return ");
2020 -- Ada 2005 (AI-231)
2022 if Nkind (Result_Definition (Node)) /= N_Access_Definition
2023 and then Null_Exclusion_Present (Node)
2024 then
2025 Write_Str (" not null ");
2026 end if;
2028 Sprint_Node (Result_Definition (Node));
2030 when N_Generic_Association =>
2031 Set_Debug_Sloc;
2033 if Present (Selector_Name (Node)) then
2034 Sprint_Node (Selector_Name (Node));
2035 Write_Str (" => ");
2036 end if;
2038 Sprint_Node (Explicit_Generic_Actual_Parameter (Node));
2040 when N_Generic_Function_Renaming_Declaration =>
2041 Write_Indent_Str_Sloc ("generic function ");
2042 Sprint_Node (Defining_Unit_Name (Node));
2043 Write_Str_With_Col_Check (" renames ");
2044 Sprint_Node (Name (Node));
2045 Write_Char (';');
2047 when N_Generic_Package_Declaration =>
2048 Extra_Blank_Line;
2049 Write_Indent_Str_Sloc ("generic ");
2050 Sprint_Indented_List (Generic_Formal_Declarations (Node));
2051 Write_Indent;
2052 Sprint_Node (Specification (Node));
2053 Write_Char (';');
2055 when N_Generic_Package_Renaming_Declaration =>
2056 Write_Indent_Str_Sloc ("generic package ");
2057 Sprint_Node (Defining_Unit_Name (Node));
2058 Write_Str_With_Col_Check (" renames ");
2059 Sprint_Node (Name (Node));
2060 Write_Char (';');
2062 when N_Generic_Procedure_Renaming_Declaration =>
2063 Write_Indent_Str_Sloc ("generic procedure ");
2064 Sprint_Node (Defining_Unit_Name (Node));
2065 Write_Str_With_Col_Check (" renames ");
2066 Sprint_Node (Name (Node));
2067 Write_Char (';');
2069 when N_Generic_Subprogram_Declaration =>
2070 Extra_Blank_Line;
2071 Write_Indent_Str_Sloc ("generic ");
2072 Sprint_Indented_List (Generic_Formal_Declarations (Node));
2073 Write_Indent;
2074 Sprint_Node (Specification (Node));
2075 Write_Char (';');
2077 when N_Goto_Statement =>
2078 Write_Indent_Str_Sloc ("goto ");
2079 Sprint_Node (Name (Node));
2080 Write_Char (';');
2082 if Nkind (Next (Node)) = N_Label then
2083 Write_Indent;
2084 end if;
2086 when N_Handled_Sequence_Of_Statements =>
2087 Set_Debug_Sloc;
2088 Sprint_Indented_List (Statements (Node));
2090 if Present (Exception_Handlers (Node)) then
2091 Write_Indent_Str ("exception");
2092 Indent_Begin;
2093 Sprint_Node_List (Exception_Handlers (Node));
2094 Indent_End;
2095 end if;
2097 if Present (At_End_Proc (Node)) then
2098 Write_Indent_Str ("at end");
2099 Indent_Begin;
2100 Write_Indent;
2101 Sprint_Node (At_End_Proc (Node));
2102 Write_Char (';');
2103 Indent_End;
2104 end if;
2106 when N_Identifier =>
2107 Set_Debug_Sloc;
2108 Write_Id (Node);
2110 when N_If_Expression =>
2111 declare
2112 Has_Parens : constant Boolean := Paren_Count (Node) > 0;
2113 Condition : constant Node_Id := First (Expressions (Node));
2114 Then_Expr : constant Node_Id := Next (Condition);
2116 begin
2117 -- The syntax for if_expression does not include parentheses,
2118 -- but sometimes parentheses are required, so unconditionally
2119 -- generate them here unless already present.
2121 if not Has_Parens then
2122 Write_Char ('(');
2123 end if;
2125 Write_Str_With_Col_Check_Sloc ("if ");
2126 Sprint_Node (Condition);
2127 Write_Str_With_Col_Check (" then ");
2129 -- Defense against junk here
2131 if Present (Then_Expr) then
2132 Sprint_Node (Then_Expr);
2134 if Present (Next (Then_Expr)) then
2135 Write_Str_With_Col_Check (" else ");
2136 Sprint_Node (Next (Then_Expr));
2137 end if;
2138 end if;
2140 if not Has_Parens then
2141 Write_Char (')');
2142 end if;
2143 end;
2145 when N_If_Statement =>
2146 Write_Indent_Str_Sloc ("if ");
2147 Sprint_Node (Condition (Node));
2148 Write_Str_With_Col_Check (" then");
2149 Sprint_Indented_List (Then_Statements (Node));
2150 Sprint_Opt_Node_List (Elsif_Parts (Node));
2152 if Present (Else_Statements (Node)) then
2153 Write_Indent_Str ("else");
2154 Sprint_Indented_List (Else_Statements (Node));
2155 end if;
2157 Write_Indent_Str ("end if;");
2159 when N_Implicit_Label_Declaration =>
2160 if not Dump_Original_Only then
2161 Write_Indent;
2162 Write_Rewrite_Str ("<<<");
2163 Set_Debug_Sloc;
2164 Write_Id (Defining_Identifier (Node));
2165 Write_Str (" : ");
2166 Write_Str_With_Col_Check ("label");
2167 Write_Rewrite_Str (">>>");
2168 end if;
2170 when N_In =>
2171 Sprint_Left_Opnd (Node);
2172 Write_Str_Sloc (" in ");
2174 if Present (Right_Opnd (Node)) then
2175 Sprint_Right_Opnd (Node);
2176 else
2177 Sprint_Bar_List (Alternatives (Node));
2178 end if;
2180 when N_Incomplete_Type_Declaration =>
2181 Write_Indent_Str_Sloc ("type ");
2182 Write_Id (Defining_Identifier (Node));
2184 if Present (Discriminant_Specifications (Node)) then
2185 Write_Discr_Specs (Node);
2186 elsif Unknown_Discriminants_Present (Node) then
2187 Write_Str_With_Col_Check ("(<>)");
2188 end if;
2190 Write_Char (';');
2192 when N_Index_Or_Discriminant_Constraint =>
2193 Set_Debug_Sloc;
2194 Sprint_Paren_Comma_List (Constraints (Node));
2196 when N_Indexed_Component =>
2197 Sprint_Node_Sloc (Prefix (Node));
2198 Sprint_Opt_Paren_Comma_List (Expressions (Node));
2200 when N_Integer_Literal =>
2201 if Print_In_Hex (Node) then
2202 Write_Uint_With_Col_Check_Sloc (Intval (Node), Hex);
2203 else
2204 Write_Uint_With_Col_Check_Sloc (Intval (Node), Auto);
2205 end if;
2207 when N_Iteration_Scheme =>
2208 if Present (Condition (Node)) then
2209 Write_Str_With_Col_Check_Sloc ("while ");
2210 Sprint_Node (Condition (Node));
2211 else
2212 Write_Str_With_Col_Check_Sloc ("for ");
2214 if Present (Iterator_Specification (Node)) then
2215 Sprint_Node (Iterator_Specification (Node));
2216 else
2217 Sprint_Node (Loop_Parameter_Specification (Node));
2218 end if;
2219 end if;
2221 Write_Char (' ');
2223 when N_Iterator_Specification =>
2224 Set_Debug_Sloc;
2225 Write_Id (Defining_Identifier (Node));
2227 if Present (Subtype_Indication (Node)) then
2228 Write_Str_With_Col_Check (" : ");
2229 Sprint_Node (Subtype_Indication (Node));
2230 end if;
2232 if Of_Present (Node) then
2233 Write_Str_With_Col_Check (" of ");
2234 else
2235 Write_Str_With_Col_Check (" in ");
2236 end if;
2238 if Reverse_Present (Node) then
2239 Write_Str_With_Col_Check ("reverse ");
2240 end if;
2242 Sprint_Node (Name (Node));
2244 when N_Itype_Reference =>
2245 Write_Indent_Str_Sloc ("reference ");
2246 Write_Id (Itype (Node));
2248 when N_Label =>
2249 Write_Indent_Str_Sloc ("<<");
2250 Write_Id (Identifier (Node));
2251 Write_Str (">>");
2253 when N_Loop_Parameter_Specification =>
2254 Set_Debug_Sloc;
2255 Write_Id (Defining_Identifier (Node));
2256 Write_Str_With_Col_Check (" in ");
2258 if Reverse_Present (Node) then
2259 Write_Str_With_Col_Check ("reverse ");
2260 end if;
2262 Sprint_Node (Discrete_Subtype_Definition (Node));
2264 when N_Loop_Statement =>
2265 Write_Indent;
2267 if Present (Identifier (Node))
2268 and then (not Has_Created_Identifier (Node)
2269 or else not Dump_Original_Only)
2270 then
2271 Write_Rewrite_Str ("<<<");
2272 Write_Id (Identifier (Node));
2273 Write_Str (" : ");
2274 Write_Rewrite_Str (">>>");
2275 Sprint_Node (Iteration_Scheme (Node));
2276 Write_Str_With_Col_Check_Sloc ("loop");
2277 Sprint_Indented_List (Statements (Node));
2278 Write_Indent_Str ("end loop ");
2279 Write_Rewrite_Str ("<<<");
2280 Write_Id (Identifier (Node));
2281 Write_Rewrite_Str (">>>");
2282 Write_Char (';');
2284 else
2285 Sprint_Node (Iteration_Scheme (Node));
2286 Write_Str_With_Col_Check_Sloc ("loop");
2287 Sprint_Indented_List (Statements (Node));
2288 Write_Indent_Str ("end loop;");
2289 end if;
2291 when N_Mod_Clause =>
2292 Sprint_Node_List (Pragmas_Before (Node));
2293 Write_Str_With_Col_Check_Sloc ("at mod ");
2294 Sprint_Node (Expression (Node));
2296 when N_Modular_Type_Definition =>
2297 Write_Str_With_Col_Check_Sloc ("mod ");
2298 Sprint_Node (Expression (Node));
2300 when N_Not_In =>
2301 Sprint_Left_Opnd (Node);
2302 Write_Str_Sloc (" not in ");
2304 if Present (Right_Opnd (Node)) then
2305 Sprint_Right_Opnd (Node);
2306 else
2307 Sprint_Bar_List (Alternatives (Node));
2308 end if;
2310 when N_Null =>
2311 Write_Str_With_Col_Check_Sloc ("null");
2313 when N_Null_Statement =>
2314 if Comes_From_Source (Node)
2315 or else Dump_Freeze_Null
2316 or else not Is_List_Member (Node)
2317 or else (No (Prev (Node)) and then No (Next (Node)))
2318 then
2319 Write_Indent_Str_Sloc ("null;");
2320 end if;
2322 when N_Number_Declaration =>
2323 Set_Debug_Sloc;
2325 if Write_Indent_Identifiers (Node) then
2326 Write_Str_With_Col_Check (" : constant ");
2327 Write_Str (" := ");
2328 Sprint_Node (Expression (Node));
2329 Write_Char (';');
2330 end if;
2332 when N_Object_Declaration =>
2333 Set_Debug_Sloc;
2335 if Write_Indent_Identifiers (Node) then
2336 declare
2337 Def_Id : constant Entity_Id := Defining_Identifier (Node);
2339 begin
2340 Write_Str_With_Col_Check (" : ");
2342 if Is_Statically_Allocated (Def_Id) then
2343 Write_Str_With_Col_Check ("static ");
2344 end if;
2346 if Aliased_Present (Node) then
2347 Write_Str_With_Col_Check ("aliased ");
2348 end if;
2350 if Constant_Present (Node) then
2351 Write_Str_With_Col_Check ("constant ");
2352 end if;
2354 -- Ada 2005 (AI-231)
2356 if Null_Exclusion_Present (Node) then
2357 Write_Str_With_Col_Check ("not null ");
2358 end if;
2360 -- Print type. We used to print the Object_Definition from
2361 -- the node, but it is much more useful to print the Etype
2362 -- of the defining identifier for the case where the nominal
2363 -- type is an unconstrained array type. For example, this
2364 -- will be a clear reference to the Itype with the bounds
2365 -- in the case of a type like String. The object after
2366 -- all is constrained, even if its nominal subtype is
2367 -- unconstrained.
2369 declare
2370 Odef : constant Node_Id := Object_Definition (Node);
2372 begin
2373 if Nkind (Odef) = N_Identifier
2374 and then Present (Etype (Odef))
2375 and then Is_Array_Type (Etype (Odef))
2376 and then not Is_Constrained (Etype (Odef))
2377 and then Present (Etype (Def_Id))
2378 then
2379 Sprint_Node (Etype (Def_Id));
2381 -- In other cases, the nominal type is fine to print
2383 else
2384 Sprint_Node (Odef);
2385 end if;
2386 end;
2388 if Present (Expression (Node))
2389 and then Expression (Node) /= Error
2390 then
2391 Write_Str (" := ");
2392 Sprint_Node (Expression (Node));
2393 end if;
2395 Write_Char (';');
2397 -- Handle implicit importation and implicit exportation of
2398 -- object declarations:
2399 -- $pragma import (Convention_Id, Def_Id, "...");
2400 -- $pragma export (Convention_Id, Def_Id, "...");
2402 if Is_Internal (Def_Id)
2403 and then Present (Interface_Name (Def_Id))
2404 then
2405 Write_Indent_Str_Sloc ("$pragma ");
2407 if Is_Imported (Def_Id) then
2408 Write_Str ("import (");
2410 else pragma Assert (Is_Exported (Def_Id));
2411 Write_Str ("export (");
2412 end if;
2414 declare
2415 Prefix : constant String := "Convention_";
2416 S : constant String := Convention (Def_Id)'Img;
2418 begin
2419 Name_Len := S'Last - Prefix'Last;
2420 Name_Buffer (1 .. Name_Len) :=
2421 S (Prefix'Last + 1 .. S'Last);
2422 Set_Casing (All_Lower_Case);
2423 Write_Str (Name_Buffer (1 .. Name_Len));
2424 end;
2426 Write_Str (", ");
2427 Write_Id (Def_Id);
2428 Write_Str (", ");
2429 Write_String_Table_Entry
2430 (Strval (Interface_Name (Def_Id)));
2431 Write_Str (");");
2432 end if;
2433 end;
2434 end if;
2436 when N_Object_Renaming_Declaration =>
2437 Write_Indent;
2438 Set_Debug_Sloc;
2439 Sprint_Node (Defining_Identifier (Node));
2440 Write_Str (" : ");
2442 -- Ada 2005 (AI-230): Access renamings
2444 if Present (Access_Definition (Node)) then
2445 Sprint_Node (Access_Definition (Node));
2447 elsif Present (Subtype_Mark (Node)) then
2449 -- Ada 2005 (AI-423): Object renaming with a null exclusion
2451 if Null_Exclusion_Present (Node) then
2452 Write_Str ("not null ");
2453 end if;
2455 Sprint_Node (Subtype_Mark (Node));
2457 else
2458 Write_Str (" ??? ");
2459 end if;
2461 Write_Str_With_Col_Check (" renames ");
2462 Sprint_Node (Name (Node));
2463 Write_Char (';');
2465 when N_Op_Abs =>
2466 Write_Operator (Node, "abs ");
2467 Sprint_Right_Opnd (Node);
2469 when N_Op_Add =>
2470 Sprint_Left_Opnd (Node);
2471 Write_Operator (Node, " + ");
2472 Sprint_Right_Opnd (Node);
2474 when N_Op_And =>
2475 Sprint_Left_Opnd (Node);
2476 Write_Operator (Node, " and ");
2477 Sprint_Right_Opnd (Node);
2479 when N_Op_Concat =>
2480 Sprint_Left_Opnd (Node);
2481 Write_Operator (Node, " & ");
2482 Sprint_Right_Opnd (Node);
2484 when N_Op_Divide =>
2485 Sprint_Left_Opnd (Node);
2486 Write_Char (' ');
2487 Process_TFAI_RR_Flags (Node);
2488 Write_Operator (Node, "/ ");
2489 Sprint_Right_Opnd (Node);
2491 when N_Op_Eq =>
2492 Sprint_Left_Opnd (Node);
2493 Write_Operator (Node, " = ");
2494 Sprint_Right_Opnd (Node);
2496 when N_Op_Expon =>
2497 Sprint_Left_Opnd (Node);
2498 Write_Operator (Node, " ** ");
2499 Sprint_Right_Opnd (Node);
2501 when N_Op_Ge =>
2502 Sprint_Left_Opnd (Node);
2503 Write_Operator (Node, " >= ");
2504 Sprint_Right_Opnd (Node);
2506 when N_Op_Gt =>
2507 Sprint_Left_Opnd (Node);
2508 Write_Operator (Node, " > ");
2509 Sprint_Right_Opnd (Node);
2511 when N_Op_Le =>
2512 Sprint_Left_Opnd (Node);
2513 Write_Operator (Node, " <= ");
2514 Sprint_Right_Opnd (Node);
2516 when N_Op_Lt =>
2517 Sprint_Left_Opnd (Node);
2518 Write_Operator (Node, " < ");
2519 Sprint_Right_Opnd (Node);
2521 when N_Op_Minus =>
2522 Write_Operator (Node, "-");
2523 Sprint_Right_Opnd (Node);
2525 when N_Op_Mod =>
2526 Sprint_Left_Opnd (Node);
2528 if Treat_Fixed_As_Integer (Node) then
2529 Write_Str (" #");
2530 end if;
2532 Write_Operator (Node, " mod ");
2533 Sprint_Right_Opnd (Node);
2535 when N_Op_Multiply =>
2536 Sprint_Left_Opnd (Node);
2537 Write_Char (' ');
2538 Process_TFAI_RR_Flags (Node);
2539 Write_Operator (Node, "* ");
2540 Sprint_Right_Opnd (Node);
2542 when N_Op_Ne =>
2543 Sprint_Left_Opnd (Node);
2544 Write_Operator (Node, " /= ");
2545 Sprint_Right_Opnd (Node);
2547 when N_Op_Not =>
2548 Write_Operator (Node, "not ");
2549 Sprint_Right_Opnd (Node);
2551 when N_Op_Or =>
2552 Sprint_Left_Opnd (Node);
2553 Write_Operator (Node, " or ");
2554 Sprint_Right_Opnd (Node);
2556 when N_Op_Plus =>
2557 Write_Operator (Node, "+");
2558 Sprint_Right_Opnd (Node);
2560 when N_Op_Rem =>
2561 Sprint_Left_Opnd (Node);
2563 if Treat_Fixed_As_Integer (Node) then
2564 Write_Str (" #");
2565 end if;
2567 Write_Operator (Node, " rem ");
2568 Sprint_Right_Opnd (Node);
2570 when N_Op_Shift =>
2571 Set_Debug_Sloc;
2572 Write_Id (Node);
2573 Write_Char ('!');
2574 Write_Str_With_Col_Check ("(");
2575 Sprint_Node (Left_Opnd (Node));
2576 Write_Str (", ");
2577 Sprint_Node (Right_Opnd (Node));
2578 Write_Char (')');
2580 when N_Op_Subtract =>
2581 Sprint_Left_Opnd (Node);
2582 Write_Operator (Node, " - ");
2583 Sprint_Right_Opnd (Node);
2585 when N_Op_Xor =>
2586 Sprint_Left_Opnd (Node);
2587 Write_Operator (Node, " xor ");
2588 Sprint_Right_Opnd (Node);
2590 when N_Operator_Symbol =>
2591 Write_Name_With_Col_Check_Sloc (Chars (Node));
2593 when N_Ordinary_Fixed_Point_Definition =>
2594 Write_Str_With_Col_Check_Sloc ("delta ");
2595 Sprint_Node (Delta_Expression (Node));
2596 Sprint_Opt_Node (Real_Range_Specification (Node));
2598 when N_Or_Else =>
2599 Sprint_Left_Opnd (Node);
2600 Write_Str_Sloc (" or else ");
2601 Sprint_Right_Opnd (Node);
2603 when N_Others_Choice =>
2604 if All_Others (Node) then
2605 Write_Str_With_Col_Check ("all ");
2606 end if;
2608 Write_Str_With_Col_Check_Sloc ("others");
2610 when N_Package_Body =>
2611 Extra_Blank_Line;
2612 Write_Indent_Str_Sloc ("package body ");
2613 Sprint_Node (Defining_Unit_Name (Node));
2614 Write_Str (" is");
2615 Sprint_Indented_List (Declarations (Node));
2617 if Present (Handled_Statement_Sequence (Node)) then
2618 Write_Indent_Str ("begin");
2619 Sprint_Node (Handled_Statement_Sequence (Node));
2620 end if;
2622 Write_Indent_Str ("end ");
2623 Sprint_End_Label
2624 (Handled_Statement_Sequence (Node), Defining_Unit_Name (Node));
2625 Write_Char (';');
2627 when N_Package_Body_Stub =>
2628 Write_Indent_Str_Sloc ("package body ");
2629 Sprint_Node (Defining_Identifier (Node));
2630 Write_Str_With_Col_Check (" is separate;");
2632 when N_Package_Declaration =>
2633 Extra_Blank_Line;
2634 Write_Indent;
2635 Sprint_Node_Sloc (Specification (Node));
2636 Write_Char (';');
2638 -- If this is an instantiation, get the aspects from the original
2639 -- instantiation node.
2641 if Is_Generic_Instance (Defining_Entity (Node))
2642 and then Has_Aspects
2643 (Package_Instantiation (Defining_Entity (Node)))
2644 then
2645 Sprint_Aspect_Specifications
2646 (Package_Instantiation (Defining_Entity (Node)),
2647 Semicolon => True);
2648 end if;
2650 when N_Package_Instantiation =>
2651 Extra_Blank_Line;
2652 Write_Indent_Str_Sloc ("package ");
2653 Sprint_Node (Defining_Unit_Name (Node));
2654 Write_Str (" is new ");
2655 Sprint_Node (Name (Node));
2656 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
2657 Write_Char (';');
2659 when N_Package_Renaming_Declaration =>
2660 Write_Indent_Str_Sloc ("package ");
2661 Sprint_Node (Defining_Unit_Name (Node));
2662 Write_Str_With_Col_Check (" renames ");
2663 Sprint_Node (Name (Node));
2664 Write_Char (';');
2666 when N_Package_Specification =>
2667 Write_Str_With_Col_Check_Sloc ("package ");
2668 Sprint_Node (Defining_Unit_Name (Node));
2670 if Nkind (Parent (Node)) = N_Generic_Package_Declaration
2671 and then Has_Aspects (Parent (Node))
2672 then
2673 Sprint_Aspect_Specifications
2674 (Parent (Node), Semicolon => False);
2676 -- An instantiation is rewritten as a package declaration, but
2677 -- the aspects belong to the instantiation node.
2679 elsif Nkind (Parent (Node)) = N_Package_Declaration then
2680 declare
2681 Pack : constant Entity_Id := Defining_Entity (Node);
2683 begin
2684 if not Is_Generic_Instance (Pack) then
2685 if Has_Aspects (Parent (Node)) then
2686 Sprint_Aspect_Specifications
2687 (Parent (Node), Semicolon => False);
2688 end if;
2689 end if;
2690 end;
2691 end if;
2693 Write_Str (" is");
2694 Sprint_Indented_List (Visible_Declarations (Node));
2696 if Present (Private_Declarations (Node)) then
2697 Write_Indent_Str ("private");
2698 Sprint_Indented_List (Private_Declarations (Node));
2699 end if;
2701 Write_Indent_Str ("end ");
2702 Sprint_Node (Defining_Unit_Name (Node));
2704 when N_Parameter_Association =>
2705 Sprint_Node_Sloc (Selector_Name (Node));
2706 Write_Str (" => ");
2707 Sprint_Node (Explicit_Actual_Parameter (Node));
2709 when N_Parameter_Specification =>
2710 Set_Debug_Sloc;
2712 if Write_Identifiers (Node) then
2713 Write_Str (" : ");
2715 if In_Present (Node) then
2716 Write_Str_With_Col_Check ("in ");
2717 end if;
2719 if Out_Present (Node) then
2720 Write_Str_With_Col_Check ("out ");
2721 end if;
2723 -- Ada 2005 (AI-231): Parameter specification may carry null
2724 -- exclusion. Do not print it now if this is an access formal,
2725 -- it is emitted when the access definition is displayed.
2727 if Null_Exclusion_Present (Node)
2728 and then Nkind (Parameter_Type (Node)) /= N_Access_Definition
2729 then
2730 Write_Str ("not null ");
2731 end if;
2733 if Aliased_Present (Node) then
2734 Write_Str ("aliased ");
2735 end if;
2737 Sprint_Node (Parameter_Type (Node));
2739 if Present (Expression (Node)) then
2740 Write_Str (" := ");
2741 Sprint_Node (Expression (Node));
2742 end if;
2743 else
2744 Write_Str (", ");
2745 end if;
2747 when N_Pop_Constraint_Error_Label =>
2748 Write_Indent_Str ("%pop_constraint_error_label");
2750 when N_Pop_Program_Error_Label =>
2751 Write_Indent_Str ("%pop_program_error_label");
2753 when N_Pop_Storage_Error_Label =>
2754 Write_Indent_Str ("%pop_storage_error_label");
2756 when N_Private_Extension_Declaration =>
2757 Write_Indent_Str_Sloc ("type ");
2758 Write_Id (Defining_Identifier (Node));
2760 if Present (Discriminant_Specifications (Node)) then
2761 Write_Discr_Specs (Node);
2762 elsif Unknown_Discriminants_Present (Node) then
2763 Write_Str_With_Col_Check ("(<>)");
2764 end if;
2766 Write_Str_With_Col_Check (" is new ");
2767 Sprint_Node (Subtype_Indication (Node));
2769 if Present (Interface_List (Node)) then
2770 Write_Str_With_Col_Check (" and ");
2771 Sprint_And_List (Interface_List (Node));
2772 end if;
2774 Write_Str_With_Col_Check (" with private;");
2776 when N_Private_Type_Declaration =>
2777 Write_Indent_Str_Sloc ("type ");
2778 Write_Id (Defining_Identifier (Node));
2780 if Present (Discriminant_Specifications (Node)) then
2781 Write_Discr_Specs (Node);
2782 elsif Unknown_Discriminants_Present (Node) then
2783 Write_Str_With_Col_Check ("(<>)");
2784 end if;
2786 Write_Str (" is ");
2788 if Tagged_Present (Node) then
2789 Write_Str_With_Col_Check ("tagged ");
2790 end if;
2792 if Limited_Present (Node) then
2793 Write_Str_With_Col_Check ("limited ");
2794 end if;
2796 Write_Str_With_Col_Check ("private;");
2798 when N_Push_Constraint_Error_Label =>
2799 Write_Indent_Str ("%push_constraint_error_label (");
2801 if Present (Exception_Label (Node)) then
2802 Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2803 end if;
2805 Write_Str (")");
2807 when N_Push_Program_Error_Label =>
2808 Write_Indent_Str ("%push_program_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_Storage_Error_Label =>
2817 Write_Indent_Str ("%push_storage_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_Pragma =>
2826 Write_Indent_Str_Sloc ("pragma ");
2827 Write_Name_With_Col_Check (Pragma_Name (Node));
2829 if Present (Pragma_Argument_Associations (Node)) then
2830 Sprint_Opt_Paren_Comma_List
2831 (Pragma_Argument_Associations (Node));
2832 end if;
2834 Write_Char (';');
2836 when N_Pragma_Argument_Association =>
2837 Set_Debug_Sloc;
2839 if Chars (Node) /= No_Name then
2840 Write_Name_With_Col_Check (Chars (Node));
2841 Write_Str (" => ");
2842 end if;
2844 Sprint_Node (Expression (Node));
2846 when N_Procedure_Call_Statement =>
2847 Write_Indent;
2848 Set_Debug_Sloc;
2849 Write_Subprogram_Name (Name (Node));
2850 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
2851 Write_Char (';');
2853 when N_Procedure_Instantiation =>
2854 Write_Indent_Str_Sloc ("procedure ");
2855 Sprint_Node (Defining_Unit_Name (Node));
2856 Write_Str_With_Col_Check (" is new ");
2857 Sprint_Node (Name (Node));
2858 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
2859 Write_Char (';');
2861 when N_Procedure_Specification =>
2862 Write_Str_With_Col_Check_Sloc ("procedure ");
2863 Sprint_Node (Defining_Unit_Name (Node));
2864 Write_Param_Specs (Node);
2866 when N_Protected_Body =>
2867 Write_Indent_Str_Sloc ("protected body ");
2868 Write_Id (Defining_Identifier (Node));
2869 Write_Str (" is");
2870 Sprint_Indented_List (Declarations (Node));
2871 Write_Indent_Str ("end ");
2872 Write_Id (Defining_Identifier (Node));
2873 Write_Char (';');
2875 when N_Protected_Body_Stub =>
2876 Write_Indent_Str_Sloc ("protected body ");
2877 Write_Id (Defining_Identifier (Node));
2878 Write_Str_With_Col_Check (" is separate;");
2880 when N_Protected_Definition =>
2881 Set_Debug_Sloc;
2882 Sprint_Indented_List (Visible_Declarations (Node));
2884 if Present (Private_Declarations (Node)) then
2885 Write_Indent_Str ("private");
2886 Sprint_Indented_List (Private_Declarations (Node));
2887 end if;
2889 Write_Indent_Str ("end ");
2891 when N_Protected_Type_Declaration =>
2892 Write_Indent_Str_Sloc ("protected type ");
2893 Sprint_Node (Defining_Identifier (Node));
2894 Write_Discr_Specs (Node);
2896 if Present (Interface_List (Node)) then
2897 Write_Str (" is new ");
2898 Sprint_And_List (Interface_List (Node));
2899 Write_Str (" with ");
2900 else
2901 Write_Str (" is");
2902 end if;
2904 Sprint_Node (Protected_Definition (Node));
2905 Write_Id (Defining_Identifier (Node));
2906 Write_Char (';');
2908 when N_Qualified_Expression =>
2909 Sprint_Node (Subtype_Mark (Node));
2910 Write_Char_Sloc (''');
2912 -- Print expression, make sure we have at least one level of
2913 -- parentheses around the expression. For cases of qualified
2914 -- expressions in the source, this is always the case, but
2915 -- for generated qualifications, there may be no explicit
2916 -- parentheses present.
2918 if Paren_Count (Expression (Node)) /= 0 then
2919 Sprint_Node (Expression (Node));
2921 else
2922 Write_Char ('(');
2923 Sprint_Node (Expression (Node));
2925 -- Odd case, for the qualified expressions used in machine
2926 -- code the argument may be a procedure call, resulting in
2927 -- a junk semicolon before the right parent, get rid of it.
2929 Write_Erase_Char (';');
2931 -- Now we can add the terminating right paren
2933 Write_Char (')');
2934 end if;
2936 when N_Quantified_Expression =>
2937 Write_Str (" for");
2939 if All_Present (Node) then
2940 Write_Str (" all ");
2941 else
2942 Write_Str (" some ");
2943 end if;
2945 if Present (Iterator_Specification (Node)) then
2946 Sprint_Node (Iterator_Specification (Node));
2947 else
2948 Sprint_Node (Loop_Parameter_Specification (Node));
2949 end if;
2951 Write_Str (" => ");
2952 Sprint_Node (Condition (Node));
2954 when N_Raise_Expression =>
2955 declare
2956 Has_Parens : constant Boolean := Paren_Count (Node) > 0;
2958 begin
2959 -- The syntax for raise_expression does not include parentheses
2960 -- but sometimes parentheses are required, so unconditionally
2961 -- generate them here unless already present.
2963 if not Has_Parens then
2964 Write_Char ('(');
2965 end if;
2967 Write_Str_With_Col_Check_Sloc ("raise ");
2968 Sprint_Node (Name (Node));
2970 if Present (Expression (Node)) then
2971 Write_Str_With_Col_Check (" with ");
2972 Sprint_Node (Expression (Node));
2973 end if;
2975 if not Has_Parens then
2976 Write_Char (')');
2977 end if;
2978 end;
2980 when N_Raise_Constraint_Error =>
2982 -- This node can be used either as a subexpression or as a
2983 -- statement form. The following test is a reasonably reliable
2984 -- way to distinguish the two cases.
2986 if Is_List_Member (Node)
2987 and then Nkind (Parent (Node)) not in N_Subexpr
2988 then
2989 Write_Indent;
2990 end if;
2992 Write_Str_With_Col_Check_Sloc ("[constraint_error");
2993 Write_Condition_And_Reason (Node);
2995 when N_Raise_Program_Error =>
2997 -- This node can be used either as a subexpression or as a
2998 -- statement form. The following test is a reasonably reliable
2999 -- way to distinguish the two cases.
3001 if Is_List_Member (Node)
3002 and then Nkind (Parent (Node)) not in N_Subexpr
3003 then
3004 Write_Indent;
3005 end if;
3007 Write_Str_With_Col_Check_Sloc ("[program_error");
3008 Write_Condition_And_Reason (Node);
3010 when N_Raise_Storage_Error =>
3012 -- This node can be used either as a subexpression or as a
3013 -- statement form. The following test is a reasonably reliable
3014 -- way to distinguish the two cases.
3016 if Is_List_Member (Node)
3017 and then Nkind (Parent (Node)) not in N_Subexpr
3018 then
3019 Write_Indent;
3020 end if;
3022 Write_Str_With_Col_Check_Sloc ("[storage_error");
3023 Write_Condition_And_Reason (Node);
3025 when N_Raise_Statement =>
3026 Write_Indent_Str_Sloc ("raise ");
3027 Sprint_Node (Name (Node));
3029 if Present (Expression (Node)) then
3030 Write_Str_With_Col_Check_Sloc (" with ");
3031 Sprint_Node (Expression (Node));
3032 end if;
3034 Write_Char (';');
3036 when N_Range =>
3037 Sprint_Node (Low_Bound (Node));
3038 Write_Str_Sloc (" .. ");
3039 Sprint_Node (High_Bound (Node));
3040 Update_Itype (Node);
3042 when N_Range_Constraint =>
3043 Write_Str_With_Col_Check_Sloc ("range ");
3044 Sprint_Node (Range_Expression (Node));
3046 when N_Real_Literal =>
3047 Write_Ureal_With_Col_Check_Sloc (Realval (Node));
3049 when N_Real_Range_Specification =>
3050 Write_Str_With_Col_Check_Sloc ("range ");
3051 Sprint_Node (Low_Bound (Node));
3052 Write_Str (" .. ");
3053 Sprint_Node (High_Bound (Node));
3055 when N_Record_Definition =>
3056 if Abstract_Present (Node) then
3057 Write_Str_With_Col_Check ("abstract ");
3058 end if;
3060 if Tagged_Present (Node) then
3061 Write_Str_With_Col_Check ("tagged ");
3062 end if;
3064 if Limited_Present (Node) then
3065 Write_Str_With_Col_Check ("limited ");
3066 end if;
3068 if Null_Present (Node) then
3069 Write_Str_With_Col_Check_Sloc ("null record");
3071 else
3072 Write_Str_With_Col_Check_Sloc ("record");
3073 Sprint_Node (Component_List (Node));
3074 Write_Indent_Str ("end record");
3075 end if;
3077 when N_Record_Representation_Clause =>
3078 Write_Indent_Str_Sloc ("for ");
3079 Sprint_Node (Identifier (Node));
3080 Write_Str_With_Col_Check (" use record ");
3082 if Present (Mod_Clause (Node)) then
3083 Sprint_Node (Mod_Clause (Node));
3084 end if;
3086 Sprint_Indented_List (Component_Clauses (Node));
3087 Write_Indent_Str ("end record;");
3089 when N_Reference =>
3090 Sprint_Node (Prefix (Node));
3091 Write_Str_With_Col_Check_Sloc ("'reference");
3093 when N_Requeue_Statement =>
3094 Write_Indent_Str_Sloc ("requeue ");
3095 Sprint_Node (Name (Node));
3097 if Abort_Present (Node) then
3098 Write_Str_With_Col_Check (" with abort");
3099 end if;
3101 Write_Char (';');
3103 -- Don't we want to print more detail???
3105 -- Doc of this extended syntax belongs in sinfo.ads and/or
3106 -- sprint.ads ???
3108 when N_SCIL_Dispatch_Table_Tag_Init =>
3109 Write_Indent_Str ("[N_SCIL_Dispatch_Table_Tag_Init]");
3111 when N_SCIL_Dispatching_Call =>
3112 Write_Indent_Str ("[N_SCIL_Dispatching_Node]");
3114 when N_SCIL_Membership_Test =>
3115 Write_Indent_Str ("[N_SCIL_Membership_Test]");
3117 when N_Simple_Return_Statement =>
3118 if Present (Expression (Node)) then
3119 Write_Indent_Str_Sloc ("return ");
3120 Sprint_Node (Expression (Node));
3121 Write_Char (';');
3122 else
3123 Write_Indent_Str_Sloc ("return;");
3124 end if;
3126 when N_Selective_Accept =>
3127 Write_Indent_Str_Sloc ("select");
3129 declare
3130 Alt_Node : Node_Id;
3131 begin
3132 Alt_Node := First (Select_Alternatives (Node));
3133 loop
3134 Indent_Begin;
3135 Sprint_Node (Alt_Node);
3136 Indent_End;
3137 Next (Alt_Node);
3138 exit when No (Alt_Node);
3139 Write_Indent_Str ("or");
3140 end loop;
3141 end;
3143 if Present (Else_Statements (Node)) then
3144 Write_Indent_Str ("else");
3145 Sprint_Indented_List (Else_Statements (Node));
3146 end if;
3148 Write_Indent_Str ("end select;");
3150 when N_Signed_Integer_Type_Definition =>
3151 Write_Str_With_Col_Check_Sloc ("range ");
3152 Sprint_Node (Low_Bound (Node));
3153 Write_Str (" .. ");
3154 Sprint_Node (High_Bound (Node));
3156 when N_Single_Protected_Declaration =>
3157 Write_Indent_Str_Sloc ("protected ");
3158 Write_Id (Defining_Identifier (Node));
3159 Write_Str (" is");
3160 Sprint_Node (Protected_Definition (Node));
3161 Write_Id (Defining_Identifier (Node));
3162 Write_Char (';');
3164 when N_Single_Task_Declaration =>
3165 Write_Indent_Str_Sloc ("task ");
3166 Sprint_Node (Defining_Identifier (Node));
3168 if Present (Task_Definition (Node)) then
3169 Write_Str (" is");
3170 Sprint_Node (Task_Definition (Node));
3171 end if;
3173 Write_Char (';');
3175 when N_Selected_Component =>
3176 Sprint_Node (Prefix (Node));
3177 Write_Char_Sloc ('.');
3178 Sprint_Node (Selector_Name (Node));
3180 when N_Slice =>
3181 Set_Debug_Sloc;
3182 Sprint_Node (Prefix (Node));
3183 Write_Str_With_Col_Check (" (");
3184 Sprint_Node (Discrete_Range (Node));
3185 Write_Char (')');
3187 when N_String_Literal =>
3188 if String_Length (Strval (Node)) + Column > Sprint_Line_Limit then
3189 Write_Indent_Str (" ");
3190 end if;
3192 Set_Debug_Sloc;
3193 Write_String_Table_Entry (Strval (Node));
3195 when N_Subprogram_Body =>
3197 -- Output extra blank line unless we are in freeze actions
3199 if Freeze_Indent = 0 then
3200 Extra_Blank_Line;
3201 end if;
3203 Write_Indent;
3205 if Present (Corresponding_Spec (Node)) then
3206 Sprint_Node_Sloc (Parent (Corresponding_Spec (Node)));
3207 else
3208 Sprint_Node_Sloc (Specification (Node));
3209 end if;
3211 Write_Str (" is");
3213 Sprint_Indented_List (Declarations (Node));
3214 Write_Indent_Str ("begin");
3215 Sprint_Node (Handled_Statement_Sequence (Node));
3217 Write_Indent_Str ("end ");
3219 Sprint_End_Label
3220 (Handled_Statement_Sequence (Node),
3221 Defining_Unit_Name (Specification (Node)));
3222 Write_Char (';');
3224 if Is_List_Member (Node)
3225 and then Present (Next (Node))
3226 and then Nkind (Next (Node)) /= N_Subprogram_Body
3227 then
3228 Write_Indent;
3229 end if;
3231 when N_Subprogram_Body_Stub =>
3232 Write_Indent;
3233 Sprint_Node_Sloc (Specification (Node));
3234 Write_Str_With_Col_Check (" is separate;");
3236 when N_Subprogram_Declaration =>
3237 Write_Indent;
3238 Sprint_Node_Sloc (Specification (Node));
3240 if Nkind (Specification (Node)) = N_Procedure_Specification
3241 and then Null_Present (Specification (Node))
3242 then
3243 Write_Str_With_Col_Check (" is null");
3244 end if;
3246 Write_Char (';');
3248 when N_Subprogram_Renaming_Declaration =>
3249 Write_Indent;
3250 Sprint_Node (Specification (Node));
3251 Write_Str_With_Col_Check_Sloc (" renames ");
3252 Sprint_Node (Name (Node));
3253 Write_Char (';');
3255 when N_Subtype_Declaration =>
3256 Write_Indent_Str_Sloc ("subtype ");
3257 Sprint_Node (Defining_Identifier (Node));
3258 Write_Str (" is ");
3260 -- Ada 2005 (AI-231)
3262 if Null_Exclusion_Present (Node) then
3263 Write_Str ("not null ");
3264 end if;
3266 Sprint_Node (Subtype_Indication (Node));
3267 Write_Char (';');
3269 when N_Subtype_Indication =>
3270 Sprint_Node_Sloc (Subtype_Mark (Node));
3271 Write_Char (' ');
3272 Sprint_Node (Constraint (Node));
3274 when N_Subunit =>
3275 Write_Indent_Str_Sloc ("separate (");
3276 Sprint_Node (Name (Node));
3277 Write_Char (')');
3278 Extra_Blank_Line;
3279 Sprint_Node (Proper_Body (Node));
3281 when N_Task_Body =>
3282 Write_Indent_Str_Sloc ("task body ");
3283 Write_Id (Defining_Identifier (Node));
3284 Write_Str (" is");
3285 Sprint_Indented_List (Declarations (Node));
3286 Write_Indent_Str ("begin");
3287 Sprint_Node (Handled_Statement_Sequence (Node));
3288 Write_Indent_Str ("end ");
3289 Sprint_End_Label
3290 (Handled_Statement_Sequence (Node), Defining_Identifier (Node));
3291 Write_Char (';');
3293 when N_Task_Body_Stub =>
3294 Write_Indent_Str_Sloc ("task body ");
3295 Write_Id (Defining_Identifier (Node));
3296 Write_Str_With_Col_Check (" is separate;");
3298 when N_Task_Definition =>
3299 Set_Debug_Sloc;
3300 Sprint_Indented_List (Visible_Declarations (Node));
3302 if Present (Private_Declarations (Node)) then
3303 Write_Indent_Str ("private");
3304 Sprint_Indented_List (Private_Declarations (Node));
3305 end if;
3307 Write_Indent_Str ("end ");
3308 Sprint_End_Label (Node, Defining_Identifier (Parent (Node)));
3310 when N_Task_Type_Declaration =>
3311 Write_Indent_Str_Sloc ("task type ");
3312 Sprint_Node (Defining_Identifier (Node));
3313 Write_Discr_Specs (Node);
3315 if Present (Interface_List (Node)) then
3316 Write_Str (" is new ");
3317 Sprint_And_List (Interface_List (Node));
3318 end if;
3320 if Present (Task_Definition (Node)) then
3321 if No (Interface_List (Node)) then
3322 Write_Str (" is");
3323 else
3324 Write_Str (" with ");
3325 end if;
3327 Sprint_Node (Task_Definition (Node));
3328 end if;
3330 Write_Char (';');
3332 when N_Terminate_Alternative =>
3333 Sprint_Node_List (Pragmas_Before (Node));
3334 Write_Indent;
3336 if Present (Condition (Node)) then
3337 Write_Str_With_Col_Check ("when ");
3338 Sprint_Node (Condition (Node));
3339 Write_Str (" => ");
3340 end if;
3342 Write_Str_With_Col_Check_Sloc ("terminate;");
3343 Sprint_Node_List (Pragmas_After (Node));
3345 when N_Timed_Entry_Call =>
3346 Write_Indent_Str_Sloc ("select");
3347 Indent_Begin;
3348 Sprint_Node (Entry_Call_Alternative (Node));
3349 Indent_End;
3350 Write_Indent_Str ("or");
3351 Indent_Begin;
3352 Sprint_Node (Delay_Alternative (Node));
3353 Indent_End;
3354 Write_Indent_Str ("end select;");
3356 when N_Triggering_Alternative =>
3357 Sprint_Node_List (Pragmas_Before (Node));
3358 Sprint_Node_Sloc (Triggering_Statement (Node));
3359 Sprint_Node_List (Statements (Node));
3361 when N_Type_Conversion =>
3362 Set_Debug_Sloc;
3363 Sprint_Node (Subtype_Mark (Node));
3364 Col_Check (4);
3366 if Conversion_OK (Node) then
3367 Write_Char ('?');
3368 end if;
3370 if Float_Truncate (Node) then
3371 Write_Char ('^');
3372 end if;
3374 if Rounded_Result (Node) then
3375 Write_Char ('@');
3376 end if;
3378 Write_Char ('(');
3379 Sprint_Node (Expression (Node));
3380 Write_Char (')');
3382 when N_Unchecked_Expression =>
3383 Col_Check (10);
3384 Write_Str ("`(");
3385 Sprint_Node_Sloc (Expression (Node));
3386 Write_Char (')');
3388 when N_Unchecked_Type_Conversion =>
3389 Sprint_Node (Subtype_Mark (Node));
3390 Write_Char ('!');
3391 Write_Str_With_Col_Check ("(");
3392 Sprint_Node_Sloc (Expression (Node));
3393 Write_Char (')');
3395 when N_Unconstrained_Array_Definition =>
3396 Write_Str_With_Col_Check_Sloc ("array (");
3398 declare
3399 Node1 : Node_Id;
3400 begin
3401 Node1 := First (Subtype_Marks (Node));
3402 loop
3403 Sprint_Node (Node1);
3404 Write_Str_With_Col_Check (" range <>");
3405 Next (Node1);
3406 exit when Node1 = Empty;
3407 Write_Str (", ");
3408 end loop;
3409 end;
3411 Write_Str (") of ");
3412 Sprint_Node (Component_Definition (Node));
3414 when N_Unused_At_Start | N_Unused_At_End =>
3415 Write_Indent_Str ("***** Error, unused node encountered *****");
3416 Write_Eol;
3418 when N_Use_Package_Clause =>
3419 Write_Indent_Str_Sloc ("use ");
3420 Sprint_Comma_List (Names (Node));
3421 Write_Char (';');
3423 when N_Use_Type_Clause =>
3424 Write_Indent_Str_Sloc ("use type ");
3425 Sprint_Comma_List (Subtype_Marks (Node));
3426 Write_Char (';');
3428 when N_Validate_Unchecked_Conversion =>
3429 Write_Indent_Str_Sloc ("validate unchecked_conversion (");
3430 Sprint_Node (Source_Type (Node));
3431 Write_Str (", ");
3432 Sprint_Node (Target_Type (Node));
3433 Write_Str (");");
3435 when N_Variant =>
3436 Write_Indent_Str_Sloc ("when ");
3437 Sprint_Bar_List (Discrete_Choices (Node));
3438 Write_Str (" => ");
3439 Sprint_Node (Component_List (Node));
3441 when N_Variant_Part =>
3442 Indent_Begin;
3443 Write_Indent_Str_Sloc ("case ");
3444 Sprint_Node (Name (Node));
3445 Write_Str (" is ");
3446 Sprint_Indented_List (Variants (Node));
3447 Write_Indent_Str ("end case");
3448 Indent_End;
3450 when N_With_Clause =>
3452 -- Special test, if we are dumping the original tree only,
3453 -- then we want to eliminate the bogus with clauses that
3454 -- correspond to the non-existent children of Text_IO.
3456 if Dump_Original_Only
3457 and then Is_Text_IO_Special_Unit (Name (Node))
3458 then
3459 null;
3461 -- Normal case, output the with clause
3463 else
3464 if First_Name (Node) or else not Dump_Original_Only then
3466 -- Ada 2005 (AI-50217): Print limited with_clauses
3468 if Private_Present (Node) and Limited_Present (Node) then
3469 Write_Indent_Str ("limited private with ");
3471 elsif Private_Present (Node) then
3472 Write_Indent_Str ("private with ");
3474 elsif Limited_Present (Node) then
3475 Write_Indent_Str ("limited with ");
3477 else
3478 Write_Indent_Str ("with ");
3479 end if;
3481 else
3482 Write_Str (", ");
3483 end if;
3485 Sprint_Node_Sloc (Name (Node));
3487 if Last_Name (Node) or else not Dump_Original_Only then
3488 Write_Char (';');
3489 end if;
3490 end if;
3491 end case;
3493 -- Print aspects, except for special case of package declaration,
3494 -- where the aspects are printed inside the package specification.
3496 if Has_Aspects (Node)
3497 and then not Nkind_In (Node, N_Package_Declaration,
3498 N_Generic_Package_Declaration)
3499 then
3500 Sprint_Aspect_Specifications (Node, Semicolon => True);
3501 end if;
3503 if Nkind (Node) in N_Subexpr
3504 and then Do_Range_Check (Node)
3505 then
3506 Write_Str ("}");
3507 end if;
3509 for J in 1 .. Paren_Count (Node) loop
3510 Write_Char (')');
3511 end loop;
3513 Dump_Node := Save_Dump_Node;
3514 end Sprint_Node_Actual;
3516 ----------------------
3517 -- Sprint_Node_List --
3518 ----------------------
3520 procedure Sprint_Node_List (List : List_Id; New_Lines : Boolean := False) is
3521 Node : Node_Id;
3523 begin
3524 if Is_Non_Empty_List (List) then
3525 Node := First (List);
3527 loop
3528 Sprint_Node (Node);
3529 Next (Node);
3530 exit when Node = Empty;
3531 end loop;
3532 end if;
3534 if New_Lines and then Column /= 1 then
3535 Write_Eol;
3536 end if;
3537 end Sprint_Node_List;
3539 ----------------------
3540 -- Sprint_Node_Sloc --
3541 ----------------------
3543 procedure Sprint_Node_Sloc (Node : Node_Id) is
3544 begin
3545 Sprint_Node (Node);
3547 if Debug_Generated_Code and then Present (Dump_Node) then
3548 Set_Sloc (Dump_Node, Sloc (Node));
3549 Dump_Node := Empty;
3550 end if;
3551 end Sprint_Node_Sloc;
3553 ---------------------
3554 -- Sprint_Opt_Node --
3555 ---------------------
3557 procedure Sprint_Opt_Node (Node : Node_Id) is
3558 begin
3559 if Present (Node) then
3560 Write_Char (' ');
3561 Sprint_Node (Node);
3562 end if;
3563 end Sprint_Opt_Node;
3565 --------------------------
3566 -- Sprint_Opt_Node_List --
3567 --------------------------
3569 procedure Sprint_Opt_Node_List (List : List_Id) is
3570 begin
3571 if Present (List) then
3572 Sprint_Node_List (List);
3573 end if;
3574 end Sprint_Opt_Node_List;
3576 ---------------------------------
3577 -- Sprint_Opt_Paren_Comma_List --
3578 ---------------------------------
3580 procedure Sprint_Opt_Paren_Comma_List (List : List_Id) is
3581 begin
3582 if Is_Non_Empty_List (List) then
3583 Write_Char (' ');
3584 Sprint_Paren_Comma_List (List);
3585 end if;
3586 end Sprint_Opt_Paren_Comma_List;
3588 -----------------------------
3589 -- Sprint_Paren_Comma_List --
3590 -----------------------------
3592 procedure Sprint_Paren_Comma_List (List : List_Id) is
3593 N : Node_Id;
3594 Node_Exists : Boolean := False;
3596 begin
3598 if Is_Non_Empty_List (List) then
3600 if Dump_Original_Only then
3601 N := First (List);
3602 while Present (N) loop
3603 if not Is_Rewrite_Insertion (N) then
3604 Node_Exists := True;
3605 exit;
3606 end if;
3608 Next (N);
3609 end loop;
3611 if not Node_Exists then
3612 return;
3613 end if;
3614 end if;
3616 Write_Str_With_Col_Check ("(");
3617 Sprint_Comma_List (List);
3618 Write_Char (')');
3619 end if;
3620 end Sprint_Paren_Comma_List;
3622 ----------------------
3623 -- Sprint_Right_Opnd --
3624 ----------------------
3626 procedure Sprint_Right_Opnd (N : Node_Id) is
3627 Opnd : constant Node_Id := Right_Opnd (N);
3629 begin
3630 if Paren_Count (Opnd) /= 0
3631 or else Op_Prec (Nkind (Opnd)) > Op_Prec (Nkind (N))
3632 then
3633 Sprint_Node (Opnd);
3635 else
3636 Write_Char ('(');
3637 Sprint_Node (Opnd);
3638 Write_Char (')');
3639 end if;
3640 end Sprint_Right_Opnd;
3642 ------------------
3643 -- Update_Itype --
3644 ------------------
3646 procedure Update_Itype (Node : Node_Id) is
3647 begin
3648 if Present (Etype (Node))
3649 and then Is_Itype (Etype (Node))
3650 and then Debug_Generated_Code
3651 then
3652 Set_Sloc (Etype (Node), Sloc (Node));
3653 end if;
3654 end Update_Itype;
3656 ---------------------
3657 -- Write_Char_Sloc --
3658 ---------------------
3660 procedure Write_Char_Sloc (C : Character) is
3661 begin
3662 if Debug_Generated_Code and then C /= ' ' then
3663 Set_Debug_Sloc;
3664 end if;
3666 Write_Char (C);
3667 end Write_Char_Sloc;
3669 --------------------------------
3670 -- Write_Condition_And_Reason --
3671 --------------------------------
3673 procedure Write_Condition_And_Reason (Node : Node_Id) is
3674 Cond : constant Node_Id := Condition (Node);
3675 Image : constant String := RT_Exception_Code'Image
3676 (RT_Exception_Code'Val
3677 (UI_To_Int (Reason (Node))));
3679 begin
3680 if Present (Cond) then
3682 -- If condition is a single entity, or NOT with a single entity,
3683 -- output all on one line, since it will likely fit just fine.
3685 if Is_Entity_Name (Cond)
3686 or else (Nkind (Cond) = N_Op_Not
3687 and then Is_Entity_Name (Right_Opnd (Cond)))
3688 then
3689 Write_Str_With_Col_Check (" when ");
3690 Sprint_Node (Cond);
3691 Write_Char (' ');
3693 -- Otherwise for more complex condition, multiple lines
3695 else
3696 Write_Str_With_Col_Check (" when");
3697 Indent := Indent + 2;
3698 Write_Indent;
3699 Sprint_Node (Cond);
3700 Write_Indent;
3701 Indent := Indent - 2;
3702 end if;
3704 -- If no condition, just need a space (all on one line)
3706 else
3707 Write_Char (' ');
3708 end if;
3710 -- Write the reason
3712 Write_Char ('"');
3714 for J in 4 .. Image'Last loop
3715 if Image (J) = '_' then
3716 Write_Char (' ');
3717 else
3718 Write_Char (Fold_Lower (Image (J)));
3719 end if;
3720 end loop;
3722 Write_Str ("""]");
3723 end Write_Condition_And_Reason;
3725 --------------------------------
3726 -- Write_Corresponding_Source --
3727 --------------------------------
3729 procedure Write_Corresponding_Source (S : String) is
3730 Loc : Source_Ptr;
3731 Src : Source_Buffer_Ptr;
3733 begin
3734 -- Ignore if not in dump source text mode, or if in freeze actions
3736 if Dump_Source_Text and then Freeze_Indent = 0 then
3738 -- Ignore null string
3740 if S = "" then
3741 return;
3742 end if;
3744 -- Ignore space or semicolon at end of given string
3746 if S (S'Last) = ' ' or else S (S'Last) = ';' then
3747 Write_Corresponding_Source (S (S'First .. S'Last - 1));
3748 return;
3749 end if;
3751 -- Loop to look at next lines not yet printed in source file
3753 for L in
3754 Last_Line_Printed + 1 .. Last_Source_Line (Current_Source_File)
3755 loop
3756 Src := Source_Text (Current_Source_File);
3757 Loc := Line_Start (L, Current_Source_File);
3759 -- If comment, keep looking
3761 if Src (Loc .. Loc + 1) = "--" then
3762 null;
3764 -- Search to first non-blank
3766 else
3767 while Src (Loc) not in Line_Terminator loop
3769 -- Non-blank found
3771 if Src (Loc) /= ' ' and then Src (Loc) /= ASCII.HT then
3773 -- Loop through characters in string to see if we match
3775 for J in S'Range loop
3777 -- If mismatch, then not the case we are looking for
3779 if Src (Loc) /= S (J) then
3780 return;
3781 end if;
3783 Loc := Loc + 1;
3784 end loop;
3786 -- If we fall through, string matched, if white space or
3787 -- semicolon after the matched string, this is the case
3788 -- we are looking for.
3790 if Src (Loc) in Line_Terminator
3791 or else Src (Loc) = ' '
3792 or else Src (Loc) = ASCII.HT
3793 or else Src (Loc) = ';'
3794 then
3795 -- So output source lines up to and including this one
3797 Write_Source_Lines (L);
3798 return;
3799 end if;
3800 end if;
3802 Loc := Loc + 1;
3803 end loop;
3804 end if;
3806 -- Line was all blanks, or a comment line, keep looking
3808 end loop;
3809 end if;
3810 end Write_Corresponding_Source;
3812 -----------------------
3813 -- Write_Discr_Specs --
3814 -----------------------
3816 procedure Write_Discr_Specs (N : Node_Id) is
3817 Specs : List_Id;
3818 Spec : Node_Id;
3820 begin
3821 Specs := Discriminant_Specifications (N);
3823 if Present (Specs) then
3824 Write_Str_With_Col_Check (" (");
3825 Spec := First (Specs);
3827 loop
3828 Sprint_Node (Spec);
3829 Next (Spec);
3830 exit when Spec = Empty;
3832 -- Add semicolon, unless we are printing original tree and the
3833 -- next specification is part of a list (but not the first
3834 -- element of that list)
3836 if not Dump_Original_Only or else not Prev_Ids (Spec) then
3837 Write_Str ("; ");
3838 end if;
3839 end loop;
3841 Write_Char (')');
3842 end if;
3843 end Write_Discr_Specs;
3845 -----------------
3846 -- Write_Ekind --
3847 -----------------
3849 procedure Write_Ekind (E : Entity_Id) is
3850 S : constant String := Entity_Kind'Image (Ekind (E));
3852 begin
3853 Name_Len := S'Length;
3854 Name_Buffer (1 .. Name_Len) := S;
3855 Set_Casing (Mixed_Case);
3856 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
3857 end Write_Ekind;
3859 --------------
3860 -- Write_Id --
3861 --------------
3863 procedure Write_Id (N : Node_Id) is
3864 begin
3865 -- Deal with outputting Itype
3867 -- Note: if we are printing the full tree with -gnatds, then we may
3868 -- end up picking up the Associated_Node link from a generic template
3869 -- here which overlaps the Entity field, but as documented, Write_Itype
3870 -- is defended against junk calls.
3872 if Nkind (N) in N_Entity then
3873 Write_Itype (N);
3874 elsif Nkind (N) in N_Has_Entity then
3875 Write_Itype (Entity (N));
3876 end if;
3878 -- Case of a defining identifier
3880 if Nkind (N) = N_Defining_Identifier then
3882 -- If defining identifier has an interface name (and no
3883 -- address clause), then we output the interface name.
3885 if (Is_Imported (N) or else Is_Exported (N))
3886 and then Present (Interface_Name (N))
3887 and then No (Address_Clause (N))
3888 then
3889 String_To_Name_Buffer (Strval (Interface_Name (N)));
3890 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
3892 -- If no interface name (or inactive because there was
3893 -- an address clause), then just output the Chars name.
3895 else
3896 Write_Name_With_Col_Check (Chars (N));
3897 end if;
3899 -- Case of selector of an expanded name where the expanded name
3900 -- has an associated entity, output this entity. Check that the
3901 -- entity or associated node is of the right kind, see above.
3903 elsif Nkind (Parent (N)) = N_Expanded_Name
3904 and then Selector_Name (Parent (N)) = N
3905 and then Present (Entity_Or_Associated_Node (Parent (N)))
3906 and then Nkind (Entity (Parent (N))) in N_Entity
3907 then
3908 Write_Id (Entity (Parent (N)));
3910 -- For any other node with an associated entity, output it
3912 elsif Nkind (N) in N_Has_Entity
3913 and then Present (Entity_Or_Associated_Node (N))
3914 and then Nkind (Entity_Or_Associated_Node (N)) in N_Entity
3915 then
3916 Write_Id (Entity (N));
3918 -- All other cases, we just print the Chars field
3920 else
3921 Write_Name_With_Col_Check (Chars (N));
3922 end if;
3923 end Write_Id;
3925 -----------------------
3926 -- Write_Identifiers --
3927 -----------------------
3929 function Write_Identifiers (Node : Node_Id) return Boolean is
3930 begin
3931 Sprint_Node (Defining_Identifier (Node));
3932 Update_Itype (Defining_Identifier (Node));
3934 -- The remainder of the declaration must be printed unless we are
3935 -- printing the original tree and this is not the last identifier
3937 return
3938 not Dump_Original_Only or else not More_Ids (Node);
3940 end Write_Identifiers;
3942 ------------------------
3943 -- Write_Implicit_Def --
3944 ------------------------
3946 procedure Write_Implicit_Def (E : Entity_Id) is
3947 Ind : Node_Id;
3949 begin
3950 case Ekind (E) is
3951 when E_Array_Subtype =>
3952 Write_Str_With_Col_Check ("subtype ");
3953 Write_Id (E);
3954 Write_Str_With_Col_Check (" is ");
3955 Write_Id (Base_Type (E));
3956 Write_Str_With_Col_Check (" (");
3958 Ind := First_Index (E);
3959 while Present (Ind) loop
3960 Sprint_Node (Ind);
3961 Next_Index (Ind);
3963 if Present (Ind) then
3964 Write_Str (", ");
3965 end if;
3966 end loop;
3968 Write_Str (");");
3970 when E_Signed_Integer_Subtype | E_Enumeration_Subtype =>
3971 Write_Str_With_Col_Check ("subtype ");
3972 Write_Id (E);
3973 Write_Str (" is ");
3974 Write_Id (Etype (E));
3975 Write_Str_With_Col_Check (" range ");
3976 Sprint_Node (Scalar_Range (E));
3977 Write_Str (";");
3979 when others =>
3980 Write_Str_With_Col_Check ("type ");
3981 Write_Id (E);
3982 Write_Str_With_Col_Check (" is <");
3983 Write_Ekind (E);
3984 Write_Str (">;");
3985 end case;
3987 end Write_Implicit_Def;
3989 ------------------
3990 -- Write_Indent --
3991 ------------------
3993 procedure Write_Indent is
3994 Loc : constant Source_Ptr := Sloc (Dump_Node);
3996 begin
3997 if Indent_Annull_Flag then
3998 Indent_Annull_Flag := False;
3999 else
4000 -- Deal with Dump_Source_Text output. Note that we ignore implicit
4001 -- label declarations, since they typically have the sloc of the
4002 -- corresponding label, which really messes up the -gnatL output.
4004 if Dump_Source_Text
4005 and then Loc > No_Location
4006 and then Nkind (Dump_Node) /= N_Implicit_Label_Declaration
4007 then
4008 if Get_Source_File_Index (Loc) = Current_Source_File then
4009 Write_Source_Lines
4010 (Get_Physical_Line_Number (Sloc (Dump_Node)));
4011 end if;
4012 end if;
4014 Write_Eol;
4016 for J in 1 .. Indent loop
4017 Write_Char (' ');
4018 end loop;
4019 end if;
4020 end Write_Indent;
4022 ------------------------------
4023 -- Write_Indent_Identifiers --
4024 ------------------------------
4026 function Write_Indent_Identifiers (Node : Node_Id) return Boolean is
4027 begin
4028 -- We need to start a new line for every node, except in the case
4029 -- where we are printing the original tree and this is not the first
4030 -- defining identifier in the list.
4032 if not Dump_Original_Only or else not Prev_Ids (Node) then
4033 Write_Indent;
4035 -- If printing original tree and this is not the first defining
4036 -- identifier in the list, then the previous call to this procedure
4037 -- printed only the name, and we add a comma to separate the names.
4039 else
4040 Write_Str (", ");
4041 end if;
4043 Sprint_Node (Defining_Identifier (Node));
4045 -- The remainder of the declaration must be printed unless we are
4046 -- printing the original tree and this is not the last identifier
4048 return
4049 not Dump_Original_Only or else not More_Ids (Node);
4050 end Write_Indent_Identifiers;
4052 -----------------------------------
4053 -- Write_Indent_Identifiers_Sloc --
4054 -----------------------------------
4056 function Write_Indent_Identifiers_Sloc (Node : Node_Id) return Boolean is
4057 begin
4058 -- We need to start a new line for every node, except in the case
4059 -- where we are printing the original tree and this is not the first
4060 -- defining identifier in the list.
4062 if not Dump_Original_Only or else not Prev_Ids (Node) then
4063 Write_Indent;
4065 -- If printing original tree and this is not the first defining
4066 -- identifier in the list, then the previous call to this procedure
4067 -- printed only the name, and we add a comma to separate the names.
4069 else
4070 Write_Str (", ");
4071 end if;
4073 Set_Debug_Sloc;
4074 Sprint_Node (Defining_Identifier (Node));
4076 -- The remainder of the declaration must be printed unless we are
4077 -- printing the original tree and this is not the last identifier
4079 return not Dump_Original_Only or else not More_Ids (Node);
4080 end Write_Indent_Identifiers_Sloc;
4082 ----------------------
4083 -- Write_Indent_Str --
4084 ----------------------
4086 procedure Write_Indent_Str (S : String) is
4087 begin
4088 Write_Corresponding_Source (S);
4089 Write_Indent;
4090 Write_Str (S);
4091 end Write_Indent_Str;
4093 ---------------------------
4094 -- Write_Indent_Str_Sloc --
4095 ---------------------------
4097 procedure Write_Indent_Str_Sloc (S : String) is
4098 begin
4099 Write_Corresponding_Source (S);
4100 Write_Indent;
4101 Write_Str_Sloc (S);
4102 end Write_Indent_Str_Sloc;
4104 -----------------
4105 -- Write_Itype --
4106 -----------------
4108 procedure Write_Itype (Typ : Entity_Id) is
4110 procedure Write_Header (T : Boolean := True);
4111 -- Write type if T is True, subtype if T is false
4113 ------------------
4114 -- Write_Header --
4115 ------------------
4117 procedure Write_Header (T : Boolean := True) is
4118 begin
4119 if T then
4120 Write_Str ("[type ");
4121 else
4122 Write_Str ("[subtype ");
4123 end if;
4125 Write_Name_With_Col_Check (Chars (Typ));
4126 Write_Str (" is ");
4127 end Write_Header;
4129 -- Start of processing for Write_Itype
4131 begin
4132 if Nkind (Typ) in N_Entity
4133 and then Is_Itype (Typ)
4134 and then not Itype_Printed (Typ)
4135 then
4136 -- Itype to be printed
4138 declare
4139 B : constant Node_Id := Etype (Typ);
4140 X : Node_Id;
4141 P : constant Node_Id := Parent (Typ);
4143 S : constant Saved_Output_Buffer := Save_Output_Buffer;
4144 -- Save current output buffer
4146 Old_Sloc : Source_Ptr;
4147 -- Save sloc of related node, so it is not modified when
4148 -- printing with -gnatD.
4150 begin
4151 -- Write indentation at start of line
4153 for J in 1 .. Indent loop
4154 Write_Char (' ');
4155 end loop;
4157 -- If we have a constructed declaration for the itype, print it
4159 if Present (P)
4160 and then Nkind (P) in N_Declaration
4161 and then Defining_Entity (P) = Typ
4162 then
4163 -- We must set Itype_Printed true before the recursive call to
4164 -- print the node, otherwise we get an infinite recursion.
4166 Set_Itype_Printed (Typ, True);
4168 -- Write the declaration enclosed in [], avoiding new line
4169 -- at start of declaration, and semicolon at end.
4171 -- Note: The itype may be imported from another unit, in which
4172 -- case we do not want to modify the Sloc of the declaration.
4173 -- Otherwise the itype may appear to be in the current unit,
4174 -- and the back-end will reject a reference out of scope.
4176 Write_Char ('[');
4177 Indent_Annull_Flag := True;
4178 Old_Sloc := Sloc (P);
4179 Sprint_Node (P);
4180 Set_Sloc (P, Old_Sloc);
4181 Write_Erase_Char (';');
4183 -- If no constructed declaration, then we have to concoct the
4184 -- source corresponding to the type entity that we have at hand.
4186 else
4187 case Ekind (Typ) is
4189 -- Access types and subtypes
4191 when Access_Kind =>
4192 Write_Header (Ekind (Typ) = E_Access_Type);
4194 if Can_Never_Be_Null (Typ) then
4195 Write_Str ("not null ");
4196 end if;
4198 Write_Str ("access ");
4200 if Is_Access_Constant (Typ) then
4201 Write_Str ("constant ");
4202 end if;
4204 Write_Id (Directly_Designated_Type (Typ));
4206 -- Array types
4208 when E_Array_Type =>
4209 Write_Header;
4210 Write_Str ("array (");
4212 X := First_Index (Typ);
4213 loop
4214 Sprint_Node (X);
4216 if not Is_Constrained (Typ) then
4217 Write_Str (" range <>");
4218 end if;
4220 Next_Index (X);
4221 exit when No (X);
4222 Write_Str (", ");
4223 end loop;
4225 Write_Str (") of ");
4226 X := Component_Type (Typ);
4228 -- Preserve sloc of component type, which is defined
4229 -- elsewhere than the itype (see comment above).
4231 Old_Sloc := Sloc (X);
4232 Sprint_Node (X);
4233 Set_Sloc (X, Old_Sloc);
4235 -- Array subtypes
4237 -- Preserve Sloc of index subtypes, as above
4239 when E_Array_Subtype =>
4240 Write_Header (False);
4241 Write_Id (Etype (Typ));
4242 Write_Str (" (");
4244 X := First_Index (Typ);
4245 loop
4246 Old_Sloc := Sloc (X);
4247 Sprint_Node (X);
4248 Set_Sloc (X, Old_Sloc);
4249 Next_Index (X);
4250 exit when No (X);
4251 Write_Str (", ");
4252 end loop;
4254 Write_Char (')');
4256 -- Signed integer types, and modular integer subtypes,
4257 -- and also enumeration subtypes.
4259 when E_Signed_Integer_Type |
4260 E_Signed_Integer_Subtype |
4261 E_Modular_Integer_Subtype |
4262 E_Enumeration_Subtype =>
4264 Write_Header (Ekind (Typ) = E_Signed_Integer_Type);
4266 if Ekind (Typ) = E_Signed_Integer_Type then
4267 Write_Str ("new ");
4268 end if;
4270 Write_Id (B);
4272 -- Print bounds if different from base type
4274 declare
4275 L : constant Node_Id := Type_Low_Bound (Typ);
4276 H : constant Node_Id := Type_High_Bound (Typ);
4277 LE : Node_Id;
4278 HE : Node_Id;
4280 begin
4281 -- B can either be a scalar type, in which case the
4282 -- declaration of Typ may constrain it with different
4283 -- bounds, or a private type, in which case we know
4284 -- that the declaration of Typ cannot have a scalar
4285 -- constraint.
4287 if Is_Scalar_Type (B) then
4288 LE := Type_Low_Bound (B);
4289 HE := Type_High_Bound (B);
4290 else
4291 LE := Empty;
4292 HE := Empty;
4293 end if;
4295 if No (LE)
4296 or else (True
4297 and then Nkind (L) = N_Integer_Literal
4298 and then Nkind (H) = N_Integer_Literal
4299 and then Nkind (LE) = N_Integer_Literal
4300 and then Nkind (HE) = N_Integer_Literal
4301 and then UI_Eq (Intval (L), Intval (LE))
4302 and then UI_Eq (Intval (H), Intval (HE)))
4303 then
4304 null;
4306 else
4307 Write_Str (" range ");
4308 Sprint_Node (Type_Low_Bound (Typ));
4309 Write_Str (" .. ");
4310 Sprint_Node (Type_High_Bound (Typ));
4311 end if;
4312 end;
4314 -- Modular integer types
4316 when E_Modular_Integer_Type =>
4317 Write_Header;
4318 Write_Str ("mod ");
4319 Write_Uint_With_Col_Check (Modulus (Typ), Auto);
4321 -- Floating point types and subtypes
4323 when E_Floating_Point_Type |
4324 E_Floating_Point_Subtype =>
4326 Write_Header (Ekind (Typ) = E_Floating_Point_Type);
4328 if Ekind (Typ) = E_Floating_Point_Type then
4329 Write_Str ("new ");
4330 end if;
4332 Write_Id (Etype (Typ));
4334 if Digits_Value (Typ) /= Digits_Value (Etype (Typ)) then
4335 Write_Str (" digits ");
4336 Write_Uint_With_Col_Check
4337 (Digits_Value (Typ), Decimal);
4338 end if;
4340 -- Print bounds if not different from base type
4342 declare
4343 L : constant Node_Id := Type_Low_Bound (Typ);
4344 H : constant Node_Id := Type_High_Bound (Typ);
4345 LE : constant Node_Id := Type_Low_Bound (B);
4346 HE : constant Node_Id := Type_High_Bound (B);
4348 begin
4349 if Nkind (L) = N_Real_Literal
4350 and then Nkind (H) = N_Real_Literal
4351 and then Nkind (LE) = N_Real_Literal
4352 and then Nkind (HE) = N_Real_Literal
4353 and then UR_Eq (Realval (L), Realval (LE))
4354 and then UR_Eq (Realval (H), Realval (HE))
4355 then
4356 null;
4358 else
4359 Write_Str (" range ");
4360 Sprint_Node (Type_Low_Bound (Typ));
4361 Write_Str (" .. ");
4362 Sprint_Node (Type_High_Bound (Typ));
4363 end if;
4364 end;
4366 -- Record subtypes
4368 when E_Record_Subtype | E_Record_Subtype_With_Private =>
4369 Write_Header (False);
4370 Write_Str ("record");
4371 Indent_Begin;
4373 declare
4374 C : Entity_Id;
4375 begin
4376 C := First_Entity (Typ);
4377 while Present (C) loop
4378 Write_Indent;
4379 Write_Id (C);
4380 Write_Str (" : ");
4381 Write_Id (Etype (C));
4382 Next_Entity (C);
4383 end loop;
4384 end;
4386 Indent_End;
4387 Write_Indent_Str (" end record");
4389 -- Class-Wide types
4391 when E_Class_Wide_Type |
4392 E_Class_Wide_Subtype =>
4393 Write_Header (Ekind (Typ) = E_Class_Wide_Type);
4394 Write_Name_With_Col_Check (Chars (Etype (Typ)));
4395 Write_Str ("'Class");
4397 -- Subprogram types
4399 when E_Subprogram_Type =>
4400 Write_Header;
4402 if Etype (Typ) = Standard_Void_Type then
4403 Write_Str ("procedure");
4404 else
4405 Write_Str ("function");
4406 end if;
4408 if Present (First_Entity (Typ)) then
4409 Write_Str (" (");
4411 declare
4412 Param : Entity_Id;
4414 begin
4415 Param := First_Entity (Typ);
4416 loop
4417 Write_Id (Param);
4418 Write_Str (" : ");
4420 if Ekind (Param) = E_In_Out_Parameter then
4421 Write_Str ("in out ");
4422 elsif Ekind (Param) = E_Out_Parameter then
4423 Write_Str ("out ");
4424 end if;
4426 Write_Id (Etype (Param));
4427 Next_Entity (Param);
4428 exit when No (Param);
4429 Write_Str (", ");
4430 end loop;
4432 Write_Char (')');
4433 end;
4434 end if;
4436 if Etype (Typ) /= Standard_Void_Type then
4437 Write_Str (" return ");
4438 Write_Id (Etype (Typ));
4439 end if;
4441 when E_String_Literal_Subtype =>
4442 declare
4443 LB : constant Uint :=
4444 Expr_Value (String_Literal_Low_Bound (Typ));
4445 Len : constant Uint :=
4446 String_Literal_Length (Typ);
4447 begin
4448 Write_Header (False);
4449 Write_Str ("String (");
4450 Write_Int (UI_To_Int (LB));
4451 Write_Str (" .. ");
4452 Write_Int (UI_To_Int (LB + Len) - 1);
4453 Write_Str (");");
4454 end;
4456 -- For all other Itypes, print ??? (fill in later)
4458 when others =>
4459 Write_Header (True);
4460 Write_Str ("???");
4462 end case;
4463 end if;
4465 -- Add terminating bracket and restore output buffer
4467 Write_Char (']');
4468 Write_Eol;
4469 Restore_Output_Buffer (S);
4470 end;
4472 Set_Itype_Printed (Typ);
4473 end if;
4474 end Write_Itype;
4476 -------------------------------
4477 -- Write_Name_With_Col_Check --
4478 -------------------------------
4480 procedure Write_Name_With_Col_Check (N : Name_Id) is
4481 J : Natural;
4482 K : Natural;
4483 L : Natural;
4485 begin
4486 Get_Name_String (N);
4488 -- Deal with -gnatdI which replaces any sequence Cnnnb where C is an
4489 -- upper case letter, nnn is one or more digits and b is a lower case
4490 -- letter by C...b, so that listings do not depend on serial numbers.
4492 if Debug_Flag_II then
4493 J := 1;
4494 while J < Name_Len - 1 loop
4495 if Name_Buffer (J) in 'A' .. 'Z'
4496 and then Name_Buffer (J + 1) in '0' .. '9'
4497 then
4498 K := J + 1;
4499 while K < Name_Len loop
4500 exit when Name_Buffer (K) not in '0' .. '9';
4501 K := K + 1;
4502 end loop;
4504 if Name_Buffer (K) in 'a' .. 'z' then
4505 L := Name_Len - K + 1;
4507 Name_Buffer (J + 4 .. J + L + 3) :=
4508 Name_Buffer (K .. Name_Len);
4509 Name_Buffer (J + 1 .. J + 3) := "...";
4510 Name_Len := J + L + 3;
4511 J := J + 5;
4513 else
4514 J := K;
4515 end if;
4517 else
4518 J := J + 1;
4519 end if;
4520 end loop;
4521 end if;
4523 -- Fall through for normal case
4525 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
4526 end Write_Name_With_Col_Check;
4528 ------------------------------------
4529 -- Write_Name_With_Col_Check_Sloc --
4530 ------------------------------------
4532 procedure Write_Name_With_Col_Check_Sloc (N : Name_Id) is
4533 begin
4534 Get_Name_String (N);
4535 Write_Str_With_Col_Check_Sloc (Name_Buffer (1 .. Name_Len));
4536 end Write_Name_With_Col_Check_Sloc;
4538 --------------------
4539 -- Write_Operator --
4540 --------------------
4542 procedure Write_Operator (N : Node_Id; S : String) is
4543 F : Natural := S'First;
4544 T : Natural := S'Last;
4546 begin
4547 -- If no overflow check, just write string out, and we are done
4549 if not Do_Overflow_Check (N) then
4550 Write_Str_Sloc (S);
4552 -- If overflow check, we want to surround the operator with curly
4553 -- brackets, but not include spaces within the brackets.
4555 else
4556 if S (F) = ' ' then
4557 Write_Char (' ');
4558 F := F + 1;
4559 end if;
4561 if S (T) = ' ' then
4562 T := T - 1;
4563 end if;
4565 Write_Char ('{');
4566 Write_Str_Sloc (S (F .. T));
4567 Write_Char ('}');
4569 if S (S'Last) = ' ' then
4570 Write_Char (' ');
4571 end if;
4572 end if;
4573 end Write_Operator;
4575 -----------------------
4576 -- Write_Param_Specs --
4577 -----------------------
4579 procedure Write_Param_Specs (N : Node_Id) is
4580 Specs : constant List_Id := Parameter_Specifications (N);
4581 Specs_Present : constant Boolean := Is_Non_Empty_List (Specs);
4583 Ent : Entity_Id;
4584 Extras : Node_Id;
4585 Spec : Node_Id;
4586 Formal : Node_Id;
4588 Output : Boolean := False;
4589 -- Set true if we output at least one parameter
4591 begin
4592 -- Write out explicit specs from Parameter_Speficiations list
4594 if Specs_Present then
4595 Write_Str_With_Col_Check (" (");
4596 Output := True;
4598 Spec := First (Specs);
4599 loop
4600 Sprint_Node (Spec);
4601 Formal := Defining_Identifier (Spec);
4602 Next (Spec);
4603 exit when Spec = Empty;
4605 -- Add semicolon, unless we are printing original tree and the
4606 -- next specification is part of a list (but not the first element
4607 -- of that list).
4609 if not Dump_Original_Only or else not Prev_Ids (Spec) then
4610 Write_Str ("; ");
4611 end if;
4612 end loop;
4613 end if;
4615 -- See if we have extra formals
4617 if Nkind_In (N, N_Function_Specification,
4618 N_Procedure_Specification)
4619 then
4620 Ent := Defining_Entity (N);
4622 -- Loop to write extra formals (if any)
4624 if Present (Ent) and then Is_Subprogram (Ent) then
4625 Extras := Extra_Formals (Ent);
4627 if Present (Extras) then
4628 if not Specs_Present then
4629 Write_Str_With_Col_Check (" (");
4630 Output := True;
4631 end if;
4633 Formal := Extras;
4634 while Present (Formal) loop
4635 if Specs_Present or else Formal /= Extras then
4636 Write_Str ("; ");
4637 end if;
4639 Write_Name_With_Col_Check (Chars (Formal));
4640 Write_Str (" : ");
4641 Write_Name_With_Col_Check (Chars (Etype (Formal)));
4642 Formal := Extra_Formal (Formal);
4643 end loop;
4644 end if;
4645 end if;
4646 end if;
4648 if Output then
4649 Write_Char (')');
4650 end if;
4651 end Write_Param_Specs;
4653 -----------------------
4654 -- Write_Rewrite_Str --
4655 -----------------------
4657 procedure Write_Rewrite_Str (S : String) is
4658 begin
4659 if not Dump_Generated_Only then
4660 if S'Length = 3 and then S = ">>>" then
4661 Write_Str (">>>");
4662 else
4663 Write_Str_With_Col_Check (S);
4664 end if;
4665 end if;
4666 end Write_Rewrite_Str;
4668 -----------------------
4669 -- Write_Source_Line --
4670 -----------------------
4672 procedure Write_Source_Line (L : Physical_Line_Number) is
4673 Loc : Source_Ptr;
4674 Src : Source_Buffer_Ptr;
4675 Scn : Source_Ptr;
4677 begin
4678 if Dump_Source_Text then
4679 Src := Source_Text (Current_Source_File);
4680 Loc := Line_Start (L, Current_Source_File);
4681 Write_Eol;
4683 -- See if line is a comment line, if not, and if not line one,
4684 -- precede with blank line.
4686 Scn := Loc;
4687 while Src (Scn) = ' ' or else Src (Scn) = ASCII.HT loop
4688 Scn := Scn + 1;
4689 end loop;
4691 if (Src (Scn) in Line_Terminator
4692 or else Src (Scn .. Scn + 1) /= "--")
4693 and then L /= 1
4694 then
4695 Write_Eol;
4696 end if;
4698 -- Now write the source text of the line
4700 Write_Str ("-- ");
4701 Write_Int (Int (L));
4702 Write_Str (": ");
4704 while Src (Loc) not in Line_Terminator loop
4705 Write_Char (Src (Loc));
4706 Loc := Loc + 1;
4707 end loop;
4708 end if;
4709 end Write_Source_Line;
4711 ------------------------
4712 -- Write_Source_Lines --
4713 ------------------------
4715 procedure Write_Source_Lines (L : Physical_Line_Number) is
4716 begin
4717 while Last_Line_Printed < L loop
4718 Last_Line_Printed := Last_Line_Printed + 1;
4719 Write_Source_Line (Last_Line_Printed);
4720 end loop;
4721 end Write_Source_Lines;
4723 --------------------
4724 -- Write_Str_Sloc --
4725 --------------------
4727 procedure Write_Str_Sloc (S : String) is
4728 begin
4729 for J in S'Range loop
4730 Write_Char_Sloc (S (J));
4731 end loop;
4732 end Write_Str_Sloc;
4734 ------------------------------
4735 -- Write_Str_With_Col_Check --
4736 ------------------------------
4738 procedure Write_Str_With_Col_Check (S : String) is
4739 begin
4740 if Int (S'Last) + Column > Sprint_Line_Limit then
4741 Write_Indent_Str (" ");
4743 if S (S'First) = ' ' then
4744 Write_Str (S (S'First + 1 .. S'Last));
4745 else
4746 Write_Str (S);
4747 end if;
4749 else
4750 Write_Str (S);
4751 end if;
4752 end Write_Str_With_Col_Check;
4754 -----------------------------------
4755 -- Write_Str_With_Col_Check_Sloc --
4756 -----------------------------------
4758 procedure Write_Str_With_Col_Check_Sloc (S : String) is
4759 begin
4760 if Int (S'Last) + Column > Sprint_Line_Limit then
4761 Write_Indent_Str (" ");
4763 if S (S'First) = ' ' then
4764 Write_Str_Sloc (S (S'First + 1 .. S'Last));
4765 else
4766 Write_Str_Sloc (S);
4767 end if;
4769 else
4770 Write_Str_Sloc (S);
4771 end if;
4772 end Write_Str_With_Col_Check_Sloc;
4774 ---------------------------
4775 -- Write_Subprogram_Name --
4776 ---------------------------
4778 procedure Write_Subprogram_Name (N : Node_Id) is
4779 begin
4780 if not Comes_From_Source (N)
4781 and then Is_Entity_Name (N)
4782 then
4783 declare
4784 Ent : constant Entity_Id := Entity (N);
4785 begin
4786 if not In_Extended_Main_Source_Unit (Ent)
4787 and then
4788 Is_Predefined_File_Name
4789 (Unit_File_Name (Get_Source_Unit (Ent)))
4790 then
4791 -- Run-time routine name, output name with a preceding dollar
4792 -- making sure that we do not get a line split between them.
4794 Col_Check (Length_Of_Name (Chars (Ent)) + 1);
4795 Write_Char ('$');
4796 Write_Name (Chars (Ent));
4797 return;
4798 end if;
4799 end;
4800 end if;
4802 -- Normal case, not a run-time routine name
4804 Sprint_Node (N);
4805 end Write_Subprogram_Name;
4807 -------------------------------
4808 -- Write_Uint_With_Col_Check --
4809 -------------------------------
4811 procedure Write_Uint_With_Col_Check (U : Uint; Format : UI_Format) is
4812 begin
4813 Col_Check (UI_Decimal_Digits_Hi (U));
4814 UI_Write (U, Format);
4815 end Write_Uint_With_Col_Check;
4817 ------------------------------------
4818 -- Write_Uint_With_Col_Check_Sloc --
4819 ------------------------------------
4821 procedure Write_Uint_With_Col_Check_Sloc (U : Uint; Format : UI_Format) is
4822 begin
4823 Col_Check (UI_Decimal_Digits_Hi (U));
4824 Set_Debug_Sloc;
4825 UI_Write (U, Format);
4826 end Write_Uint_With_Col_Check_Sloc;
4828 -------------------------------------
4829 -- Write_Ureal_With_Col_Check_Sloc --
4830 -------------------------------------
4832 procedure Write_Ureal_With_Col_Check_Sloc (U : Ureal) is
4833 D : constant Uint := Denominator (U);
4834 N : constant Uint := Numerator (U);
4835 begin
4836 Col_Check (UI_Decimal_Digits_Hi (D) + UI_Decimal_Digits_Hi (N) + 4);
4837 Set_Debug_Sloc;
4838 UR_Write (U, Brackets => True);
4839 end Write_Ureal_With_Col_Check_Sloc;
4841 end Sprint;