]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/ada/sprint.adb
Correct a function pre/postcondition [PR102403].
[thirdparty/gcc.git] / gcc / ada / sprint.adb
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-2021, 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 ------------------------------------------------------------------------------
25
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 Einfo.Entities; use Einfo.Entities;
33 with Einfo.Utils; use Einfo.Utils;
34 with Lib; use Lib;
35 with Namet; use Namet;
36 with Nlists; use Nlists;
37 with Opt; use Opt;
38 with Output; use Output;
39 with Rtsfind; use Rtsfind;
40 with Sem_Eval; use Sem_Eval;
41 with Sem_Util; use Sem_Util;
42 with Sinfo; use Sinfo;
43 with Sinfo.Nodes; use Sinfo.Nodes;
44 with Sinfo.Utils; use Sinfo.Utils;
45 with Sinput; use Sinput;
46 with Sinput.D; use Sinput.D;
47 with Snames; use Snames;
48 with Stand; use Stand;
49 with Stringt; use Stringt;
50 with Uintp; use Uintp;
51 with Uname; use Uname;
52 with Urealp; use Urealp;
53
54 package body Sprint is
55 Current_Source_File : Source_File_Index;
56 -- Index of source file whose generated code is being dumped
57
58 Dump_Node : Node_Id := Empty;
59 -- This is set to the current node, used for printing line numbers. In
60 -- Debug_Generated_Code mode, Dump_Node is set to the current node
61 -- requiring Sloc fixup, until Set_Debug_Sloc is called to set the proper
62 -- value. The call clears it back to Empty.
63
64 First_Debug_Sloc : Source_Ptr;
65 -- Sloc of first byte of the current output file if we are generating a
66 -- source debug file.
67
68 Debug_Sloc : Source_Ptr;
69 -- Sloc of first byte of line currently being written if we are
70 -- generating a source debug file.
71
72 Dump_Original_Only : Boolean;
73 -- Set True if the -gnatdo (dump original tree) flag is set
74
75 Dump_Generated_Only : Boolean;
76 -- Set True if the -gnatdG (dump generated tree) debug flag is set
77 -- or for Print_Generated_Code (-gnatG) or Dump_Generated_Code (-gnatD).
78
79 Dump_Freeze_Null : Boolean;
80 -- Set True if empty freeze nodes and non-source null statements output.
81 -- Note that freeze nodes containing freeze actions are always output,
82 -- as are freeze nodes for itypes, which in general have the effect of
83 -- causing elaboration of the itype.
84
85 Freeze_Indent : Int := 0;
86 -- Keep track of freeze indent level (controls output of blank lines before
87 -- procedures within expression freeze actions). Relevant only if we are
88 -- not in Dump_Source_Text mode, since in Dump_Source_Text mode we don't
89 -- output these blank lines in any case.
90
91 Indent : Int := 0;
92 -- Number of columns for current line output indentation
93
94 Indent_Annull_Flag : Boolean := False;
95 -- Set True if subsequent Write_Indent call to be ignored, gets reset
96 -- by this call, so it is only active to suppress a single indent call.
97
98 Last_Line_Printed : Physical_Line_Number;
99 -- This keeps track of the physical line number of the last source line
100 -- that has been output. The value is only valid in Dump_Source_Text mode.
101
102 -------------------------------
103 -- Operator Precedence Table --
104 -------------------------------
105
106 -- This table is used to decide whether a subexpression needs to be
107 -- parenthesized. The rule is that if an operand of an operator (which
108 -- for this purpose includes AND THEN and OR ELSE) is itself an operator
109 -- with a lower precedence than the operator (or equal precedence if
110 -- appearing as the right operand), then parentheses are required.
111
112 Op_Prec : constant array (N_Subexpr) of Short_Short_Integer :=
113 (N_Op_And => 1,
114 N_Op_Or => 1,
115 N_Op_Xor => 1,
116 N_And_Then => 1,
117 N_Or_Else => 1,
118
119 N_In => 2,
120 N_Not_In => 2,
121 N_Op_Eq => 2,
122 N_Op_Ge => 2,
123 N_Op_Gt => 2,
124 N_Op_Le => 2,
125 N_Op_Lt => 2,
126 N_Op_Ne => 2,
127
128 N_Op_Add => 3,
129 N_Op_Concat => 3,
130 N_Op_Subtract => 3,
131 N_Op_Plus => 3,
132 N_Op_Minus => 3,
133
134 N_Op_Divide => 4,
135 N_Op_Mod => 4,
136 N_Op_Rem => 4,
137 N_Op_Multiply => 4,
138
139 N_Op_Expon => 5,
140 N_Op_Abs => 5,
141 N_Op_Not => 5,
142
143 others => 6);
144
145 procedure Sprint_Left_Opnd (N : Node_Id);
146 -- Print left operand of operator, parenthesizing if necessary
147
148 procedure Sprint_Right_Opnd (N : Node_Id);
149 -- Print right operand of operator, parenthesizing if necessary
150
151 -----------------------
152 -- Local Subprograms --
153 -----------------------
154
155 procedure Col_Check (N : Nat);
156 -- Check that at least N characters remain on current line, and if not,
157 -- then start an extra line with two characters extra indentation for
158 -- continuing text on the next line.
159
160 procedure Extra_Blank_Line;
161 -- In some situations we write extra blank lines to separate the generated
162 -- code to make it more readable. However, these extra blank lines are not
163 -- generated in Dump_Source_Text mode, since there the source text lines
164 -- output with preceding blank lines are quite sufficient as separators.
165 -- This procedure writes a blank line if Dump_Source_Text is False.
166
167 procedure Indent_Annull;
168 -- Causes following call to Write_Indent to be ignored. This is used when
169 -- a higher level node wants to stop a lower level node from starting a
170 -- new line, when it would otherwise be inclined to do so (e.g. the case
171 -- of an accept statement called from an accept alternative with a guard)
172
173 procedure Indent_Begin;
174 -- Increase indentation level
175
176 procedure Indent_End;
177 -- Decrease indentation level
178
179 procedure Print_Debug_Line (S : String);
180 -- Used to print output lines in Debug_Generated_Code mode (this is used
181 -- as the argument for a call to Set_Special_Output in package Output).
182
183 procedure Set_Debug_Sloc;
184 -- If Dump_Node is non-empty, this routine sets the appropriate value
185 -- in its Sloc field, from the current location in the debug source file
186 -- that is currently being written.
187
188 procedure Sprint_And_List (List : List_Id);
189 -- Print the given list with items separated by vertical "and"
190
191 procedure Sprint_Aspect_Specifications
192 (Node : Node_Id;
193 Semicolon : Boolean);
194 -- Node is a declaration node that has aspect specifications (Has_Aspects
195 -- flag set True). It outputs the aspect specifications. For the case
196 -- of Semicolon = True, it is called after outputting the terminating
197 -- semicolon for the related node. The effect is to remove the semicolon
198 -- and print the aspect specifications followed by a terminating semicolon.
199 -- For the case of Semicolon False, no semicolon is removed or output, and
200 -- all the aspects are printed on a single line.
201
202 procedure Sprint_Bar_List (List : List_Id);
203 -- Print the given list with items separated by vertical bars
204
205 procedure Sprint_End_Label
206 (Node : Node_Id;
207 Default : Node_Id);
208 -- Print the end label for a Handled_Sequence_Of_Statements in a body.
209 -- If there is no end label, use the defining identifier of the enclosing
210 -- construct. If the end label is present, treat it as a reference to the
211 -- defining entity of the construct: this guarantees that it carries the
212 -- proper sloc information for debugging purposes.
213
214 procedure Sprint_Node_Actual (Node : Node_Id);
215 -- This routine prints its node argument. It is a lower level routine than
216 -- Sprint_Node, in that it does not bother about rewritten trees.
217
218 procedure Sprint_Node_Sloc (Node : Node_Id);
219 -- Like Sprint_Node, but in addition, in Debug_Generated_Code mode,
220 -- sets the Sloc of the current debug node to be a copy of the Sloc
221 -- of the sprinted node Node. Note that this is done after printing
222 -- Node, so that the Sloc is the proper updated value for the debug file.
223
224 procedure Update_Itype (Node : Node_Id);
225 -- Update the Sloc of an itype that is not attached to the tree, when
226 -- debugging expanded code. This routine is called from nodes whose
227 -- type can be an Itype, such as defining_identifiers that may be of
228 -- an anonymous access type, or ranges in slices.
229
230 procedure Write_Char_Sloc (C : Character);
231 -- Like Write_Char, except that if C is non-blank, Set_Debug_Sloc is
232 -- called to ensure that the current node has a proper Sloc set.
233
234 procedure Write_Condition_And_Reason (Node : Node_Id);
235 -- Write Condition and Reason codes of Raise_xxx_Error node
236
237 procedure Write_Corresponding_Source (S : String);
238 -- If S is a string with a single keyword (possibly followed by a space),
239 -- and if the next non-comment non-blank source line matches this keyword,
240 -- then output all source lines up to this matching line.
241
242 procedure Write_Discr_Specs (N : Node_Id);
243 -- Output discriminant specification for node, which is any of the type
244 -- declarations that can have discriminants.
245
246 procedure Write_Ekind (E : Entity_Id);
247 -- Write the String corresponding to the Ekind without "E_"
248
249 procedure Write_Id (N : Node_Id);
250 -- N is a node with a Chars field. This procedure writes the name that
251 -- will be used in the generated code associated with the name. For a
252 -- node with no associated entity, this is simply the Chars field. For
253 -- the case where there is an entity associated with the node, we print
254 -- the name associated with the entity (since it may have been encoded).
255 -- One other special case is that an entity has an active external name
256 -- (i.e. an external name present with no address clause), then this
257 -- external name is output. This procedure also deals with outputting
258 -- declarations of referenced itypes, if not output earlier.
259
260 function Write_Identifiers (Node : Node_Id) return Boolean;
261 -- Handle node where the grammar has a list of defining identifiers, but
262 -- the tree has a separate declaration for each identifier. Handles the
263 -- printing of the defining identifier, and returns True if the type and
264 -- initialization information is to be printed, False if it is to be
265 -- skipped (the latter case happens when printing defining identifiers
266 -- other than the first in the original tree output case).
267
268 procedure Write_Implicit_Def (E : Entity_Id);
269 pragma Warnings (Off, Write_Implicit_Def);
270 -- Write the definition of the implicit type E according to its Ekind
271 -- For now a debugging procedure, but might be used in the future.
272
273 procedure Write_Indent;
274 -- Start a new line and write indentation spacing
275
276 function Write_Indent_Identifiers (Node : Node_Id) return Boolean;
277 -- Like Write_Identifiers except that each new printed declaration
278 -- is at the start of a new line.
279
280 function Write_Indent_Identifiers_Sloc (Node : Node_Id) return Boolean;
281 -- Like Write_Indent_Identifiers except that in Debug_Generated_Code
282 -- mode, the Sloc of the current debug node is set to point to the
283 -- first output identifier.
284
285 procedure Write_Indent_Str (S : String);
286 -- Start a new line and write indent spacing followed by given string
287
288 procedure Write_Indent_Str_Sloc (S : String);
289 -- Like Write_Indent_Str, but in addition, in Debug_Generated_Code mode,
290 -- the Sloc of the current node is set to the first non-blank character
291 -- in the string S.
292
293 procedure Write_Itype (Typ : Entity_Id);
294 -- If Typ is an Itype that has not been written yet, write it. If Typ is
295 -- any other kind of entity or tree node, the call is ignored.
296
297 procedure Write_Name_With_Col_Check (N : Name_Id);
298 -- Write name (using Write_Name) with initial column check, and possible
299 -- initial Write_Indent (to get new line) if current line is too full.
300
301 procedure Write_Name_With_Col_Check_Sloc (N : Name_Id);
302 -- Like Write_Name_With_Col_Check but in addition, in Debug_Generated_Code
303 -- mode, sets Sloc of current debug node to first character of name.
304
305 procedure Write_Operator (N : Node_Id; S : String);
306 -- Like Write_Str_Sloc, used for operators, encloses the string in
307 -- characters {} if the Do_Overflow flag is set on the node N.
308
309 procedure Write_Param_Specs (N : Node_Id);
310 -- Output parameter specifications for node N (which is a subprogram, or
311 -- entry or entry family or access-subprogram-definition, all of which
312 -- have a Parameter_Specificatioons field).
313
314 procedure Write_Rewrite_Str (S : String);
315 -- Writes out a string (typically containing <<< or >>>}) for a node
316 -- created by rewriting the tree. Suppressed if we are outputting the
317 -- generated code only, since in this case we don't specially mark nodes
318 -- created by rewriting).
319
320 procedure Write_Source_Line (L : Physical_Line_Number);
321 -- If writing of interspersed source lines is enabled, then write the given
322 -- line from the source file, preceded by Eol, then an extra blank line if
323 -- the line has at least one blank, is not a comment and is not line one,
324 -- then "--" and the line number followed by period followed by text of the
325 -- source line (without terminating Eol). If interspersed source line
326 -- output not enabled, then the call has no effect.
327
328 procedure Write_Source_Lines (L : Physical_Line_Number);
329 -- If writing of interspersed source lines is enabled, then writes source
330 -- lines Last_Line_Printed + 1 .. L, and updates Last_Line_Printed. If
331 -- interspersed source line output not enabled, then call has no effect.
332
333 procedure Write_Str_Sloc (S : String);
334 -- Like Write_Str, but sets debug Sloc of current debug node to first
335 -- non-blank character if a current debug node is active.
336
337 procedure Write_Str_With_Col_Check (S : String);
338 -- Write string (using Write_Str) with initial column check, and possible
339 -- initial Write_Indent (to get new line) if current line is too full.
340
341 procedure Write_Str_With_Col_Check_Sloc (S : String);
342 -- Like Write_Str_With_Col_Check, but sets debug Sloc of current debug
343 -- node to first non-blank character if a current debug node is active.
344
345 procedure Write_Subprogram_Name (N : Node_Id);
346 -- N is the Name field of a function call or procedure statement call.
347 -- The effect of the call is to output the name, preceded by a $ if the
348 -- call is identified as an implicit call to a run time routine.
349
350 procedure Write_Uint_With_Col_Check (U : Uint; Format : UI_Format);
351 -- Write Uint (using UI_Write) with initial column check, and possible
352 -- initial Write_Indent (to get new line) if current line is too full.
353 -- The format parameter determines the output format (see UI_Write).
354
355 procedure Write_Uint_With_Col_Check_Sloc (U : Uint; Format : UI_Format);
356 -- Write Uint (using UI_Write) with initial column check, and possible
357 -- initial Write_Indent (to get new line) if current line is too full.
358 -- The format parameter determines the output format (see UI_Write).
359 -- In addition, in Debug_Generated_Code mode, sets the current node
360 -- Sloc to the first character of the output value.
361
362 procedure Write_Ureal_With_Col_Check_Sloc (U : Ureal);
363 -- Write Ureal (using same output format as UR_Write) with column checks
364 -- and a possible initial Write_Indent (to get new line) if current line
365 -- is too full. In addition, in Debug_Generated_Code mode, sets the
366 -- current node Sloc to the first character of the output value.
367
368 ---------------
369 -- Col_Check --
370 ---------------
371
372 procedure Col_Check (N : Nat) is
373 begin
374 if N + Column > Sprint_Line_Limit then
375 Write_Indent_Str (" ");
376 end if;
377 end Col_Check;
378
379 ----------------------
380 -- Extra_Blank_Line --
381 ----------------------
382
383 procedure Extra_Blank_Line is
384 begin
385 if not Dump_Source_Text then
386 Write_Indent;
387 end if;
388 end Extra_Blank_Line;
389
390 -------------------
391 -- Indent_Annull --
392 -------------------
393
394 procedure Indent_Annull is
395 begin
396 Indent_Annull_Flag := True;
397 end Indent_Annull;
398
399 ------------------
400 -- Indent_Begin --
401 ------------------
402
403 procedure Indent_Begin is
404 begin
405 Indent := Indent + 3;
406 end Indent_Begin;
407
408 ----------------
409 -- Indent_End --
410 ----------------
411
412 procedure Indent_End is
413 begin
414 Indent := Indent - 3;
415 end Indent_End;
416
417 --------
418 -- pg --
419 --------
420
421 procedure pg (Arg : Union_Id) is
422 begin
423 Dump_Generated_Only := True;
424 Dump_Original_Only := False;
425 Dump_Freeze_Null := True;
426 Current_Source_File := No_Source_File;
427 Push_Output;
428 Set_Standard_Output;
429
430 if Arg in List_Range then
431 Sprint_Node_List (List_Id (Arg), New_Lines => True);
432
433 elsif Arg in Node_Range then
434 Sprint_Node (Node_Id (Arg));
435
436 else
437 null;
438 end if;
439
440 Write_Eol;
441 Pop_Output;
442 end pg;
443
444 --------
445 -- po --
446 --------
447
448 procedure po (Arg : Union_Id) is
449 begin
450 Dump_Generated_Only := False;
451 Dump_Original_Only := True;
452 Dump_Freeze_Null := False;
453 Current_Source_File := No_Source_File;
454 Push_Output;
455 Set_Standard_Output;
456
457 if Arg in List_Range then
458 Sprint_Node_List (List_Id (Arg), New_Lines => True);
459
460 elsif Arg in Node_Range then
461 Sprint_Node (Node_Id (Arg));
462
463 else
464 null;
465 end if;
466
467 Write_Eol;
468 Pop_Output;
469 end po;
470
471 ----------------------
472 -- Print_Debug_Line --
473 ----------------------
474
475 procedure Print_Debug_Line (S : String) is
476 begin
477 Write_Debug_Line (S, Debug_Sloc);
478 end Print_Debug_Line;
479
480 --------
481 -- ps --
482 --------
483
484 procedure ps (Arg : Union_Id) is
485 begin
486 Dump_Generated_Only := False;
487 Dump_Original_Only := False;
488 Dump_Freeze_Null := False;
489 Current_Source_File := No_Source_File;
490 Push_Output;
491 Set_Standard_Output;
492
493 if Arg in List_Range then
494 Sprint_Node_List (List_Id (Arg), New_Lines => True);
495
496 elsif Arg in Node_Range then
497 Sprint_Node (Node_Id (Arg));
498
499 else
500 null;
501 end if;
502
503 Write_Eol;
504 Pop_Output;
505 end ps;
506
507 --------------------
508 -- Set_Debug_Sloc --
509 --------------------
510
511 procedure Set_Debug_Sloc is
512 begin
513 if Debug_Generated_Code and then Present (Dump_Node) then
514 declare
515 Loc : constant Source_Ptr := Sloc (Dump_Node);
516
517 begin
518 -- Do not change the location of nodes defined in package Standard
519 -- and nodes of pragmas scanned by Targparm.
520
521 if Loc <= Standard_Location then
522 null;
523
524 -- Update the location of a node which is part of the current .dg
525 -- output. This situation occurs in comma separated parameter
526 -- declarations since each parameter references the same parameter
527 -- type node (ie. obj1, obj2 : <param-type>).
528
529 -- Note: This case is needed here since we cannot use the routine
530 -- In_Extended_Main_Code_Unit with nodes whose location is a .dg
531 -- file.
532
533 elsif Loc >= First_Debug_Sloc then
534 Set_Sloc (Dump_Node, Debug_Sloc + Source_Ptr (Column - 1));
535
536 -- Do not change the location of nodes which are not part of the
537 -- generated code
538
539 elsif not In_Extended_Main_Code_Unit (Loc) then
540 null;
541
542 else
543 Set_Sloc (Dump_Node, Debug_Sloc + Source_Ptr (Column - 1));
544 end if;
545 end;
546
547 -- We do not know the actual end location in the generated code and
548 -- it could be much closer than in the source code, so play safe.
549
550 if Nkind (Dump_Node) in N_Case_Statement | N_If_Statement then
551 Set_End_Location (Dump_Node, Debug_Sloc + Source_Ptr (Column - 1));
552 end if;
553
554 Dump_Node := Empty;
555 end if;
556 end Set_Debug_Sloc;
557
558 -----------------
559 -- Source_Dump --
560 -----------------
561
562 procedure Source_Dump is
563
564 procedure Underline;
565 -- Put underline under string we just printed
566
567 ---------------
568 -- Underline --
569 ---------------
570
571 procedure Underline is
572 Col : constant Int := Column;
573
574 begin
575 Write_Eol;
576
577 while Col > Column loop
578 Write_Char ('-');
579 end loop;
580
581 Write_Eol;
582 end Underline;
583
584 -- Start of processing for Source_Dump
585
586 begin
587 Dump_Generated_Only := Debug_Flag_G or
588 Print_Generated_Code or
589 Debug_Generated_Code;
590 Dump_Original_Only := Debug_Flag_O;
591 Dump_Freeze_Null := Debug_Flag_S or Debug_Flag_G;
592
593 -- Note that we turn off the tree dump flags immediately, before
594 -- starting the dump. This avoids generating two copies of the dump
595 -- if an abort occurs after printing the dump, and more importantly,
596 -- avoids an infinite loop if an abort occurs during the dump.
597
598 if Debug_Flag_Z then
599 Current_Source_File := No_Source_File;
600 Debug_Flag_Z := False;
601 Write_Eol;
602 Write_Eol;
603 Write_Str ("Source recreated from tree of Standard (spec)");
604 Underline;
605 Sprint_Node (Standard_Package_Node);
606 Write_Eol;
607 Write_Eol;
608 end if;
609
610 if Debug_Flag_S or Dump_Generated_Only or Dump_Original_Only then
611 Debug_Flag_G := False;
612 Debug_Flag_O := False;
613 Debug_Flag_S := False;
614 First_Debug_Sloc := No_Location;
615
616 -- Dump requested units
617
618 for U in Main_Unit .. Last_Unit loop
619 Current_Source_File := Source_Index (U);
620
621 -- Dump all units if -gnatdf set, otherwise dump only the source
622 -- files that are in the extended main source. Note that, if we
623 -- are generating debug files, generating that of the main unit
624 -- has an effect on the outcome of In_Extended_Main_Source_Unit
625 -- because slocs are rewritten, so we also test for equality of
626 -- Cunit_Entity to work around this effect.
627
628 if Debug_Flag_F
629 or else In_Extended_Main_Source_Unit (Cunit_Entity (U))
630 or else Cunit_Entity (U) = Cunit_Entity (Main_Unit)
631 then
632 -- If we are generating debug files, setup to write them
633
634 if Debug_Generated_Code then
635 Set_Special_Output (Print_Debug_Line'Access);
636 Create_Debug_Source (Source_Index (U), Debug_Sloc);
637 First_Debug_Sloc := Debug_Sloc;
638 Write_Source_Line (1);
639 Last_Line_Printed := 1;
640
641 -- If this unit has the same entity as the main unit, for
642 -- example is the spec of a stand-alone instantiation of
643 -- a package and the main unit is the body, its debug file
644 -- will also be the same. Therefore, we need to print again
645 -- the main unit to have both units in the debug file.
646
647 if U /= Main_Unit
648 and then Cunit_Entity (U) = Cunit_Entity (Main_Unit)
649 then
650 Sprint_Node (Cunit (Main_Unit));
651 Write_Eol;
652 end if;
653
654 Sprint_Node (Cunit (U));
655 Write_Source_Lines (Last_Source_Line (Current_Source_File));
656 Write_Eol;
657 Close_Debug_Source;
658 Cancel_Special_Output;
659
660 -- Normal output to standard output file
661
662 else
663 Write_Str ("Source recreated from tree for ");
664 Write_Unit_Name (Unit_Name (U));
665 Underline;
666 Write_Source_Line (1);
667 Last_Line_Printed := 1;
668 Sprint_Node (Cunit (U));
669 Write_Source_Lines (Last_Source_Line (Current_Source_File));
670 Write_Eol;
671 Write_Eol;
672 end if;
673 end if;
674 end loop;
675 end if;
676 end Source_Dump;
677
678 ---------------------
679 -- Sprint_And_List --
680 ---------------------
681
682 procedure Sprint_And_List (List : List_Id) is
683 Node : Node_Id;
684 begin
685 if Is_Non_Empty_List (List) then
686 Node := First (List);
687 loop
688 Sprint_Node (Node);
689 Next (Node);
690 exit when Node = Empty;
691 Write_Str (" and ");
692 end loop;
693 end if;
694 end Sprint_And_List;
695
696 ----------------------------------
697 -- Sprint_Aspect_Specifications --
698 ----------------------------------
699
700 procedure Sprint_Aspect_Specifications
701 (Node : Node_Id;
702 Semicolon : Boolean)
703 is
704 AS : constant List_Id := Aspect_Specifications (Node);
705 A : Node_Id;
706
707 begin
708 if Semicolon then
709 Write_Erase_Char (';');
710 Indent := Indent + 2;
711 Write_Indent;
712 Write_Str ("with ");
713 Indent := Indent + 5;
714
715 else
716 Write_Str (" with ");
717 end if;
718
719 A := First (AS);
720 loop
721 Sprint_Node (Identifier (A));
722
723 if Class_Present (A) then
724 Write_Str ("'Class");
725 end if;
726
727 if Present (Expression (A)) then
728 Write_Str (" => ");
729 Sprint_Node (Expression (A));
730 end if;
731
732 Next (A);
733
734 exit when No (A);
735 Write_Char (',');
736
737 if Semicolon then
738 Write_Indent;
739 end if;
740 end loop;
741
742 if Semicolon then
743 Indent := Indent - 7;
744 Write_Char (';');
745 end if;
746 end Sprint_Aspect_Specifications;
747
748 ---------------------
749 -- Sprint_Bar_List --
750 ---------------------
751
752 procedure Sprint_Bar_List (List : List_Id) is
753 Node : Node_Id;
754 begin
755 if Is_Non_Empty_List (List) then
756 Node := First (List);
757 loop
758 Sprint_Node (Node);
759 Next (Node);
760 exit when Node = Empty;
761 Write_Str (" | ");
762 end loop;
763 end if;
764 end Sprint_Bar_List;
765
766 ----------------------
767 -- Sprint_End_Label --
768 ----------------------
769
770 procedure Sprint_End_Label
771 (Node : Node_Id;
772 Default : Node_Id)
773 is
774 begin
775 if Present (Node)
776 and then Present (End_Label (Node))
777 and then Is_Entity_Name (End_Label (Node))
778 then
779 Set_Entity (End_Label (Node), Default);
780
781 -- For a function whose name is an operator, use the qualified name
782 -- created for the defining entity.
783
784 if Nkind (End_Label (Node)) = N_Operator_Symbol then
785 Set_Chars (End_Label (Node), Chars (Default));
786 end if;
787
788 Sprint_Node (End_Label (Node));
789 else
790 Sprint_Node (Default);
791 end if;
792 end Sprint_End_Label;
793
794 -----------------------
795 -- Sprint_Comma_List --
796 -----------------------
797
798 procedure Sprint_Comma_List (List : List_Id) is
799 Node : Node_Id;
800
801 begin
802 if Is_Non_Empty_List (List) then
803 Node := First (List);
804 loop
805 Sprint_Node (Node);
806 Next (Node);
807 exit when Node = Empty;
808
809 if not Is_Rewrite_Insertion (Node)
810 or else not Dump_Original_Only
811 then
812 Write_Str (", ");
813 end if;
814 end loop;
815 end if;
816 end Sprint_Comma_List;
817
818 --------------------------
819 -- Sprint_Indented_List --
820 --------------------------
821
822 procedure Sprint_Indented_List (List : List_Id) is
823 begin
824 Indent_Begin;
825 Sprint_Node_List (List);
826 Indent_End;
827 end Sprint_Indented_List;
828
829 ---------------------
830 -- Sprint_Left_Opnd --
831 ---------------------
832
833 procedure Sprint_Left_Opnd (N : Node_Id) is
834 Opnd : constant Node_Id := Left_Opnd (N);
835
836 begin
837 if Paren_Count (Opnd) /= 0
838 or else Op_Prec (Nkind (Opnd)) >= Op_Prec (Nkind (N))
839 then
840 Sprint_Node (Opnd);
841
842 else
843 Write_Char ('(');
844 Sprint_Node (Opnd);
845 Write_Char (')');
846 end if;
847 end Sprint_Left_Opnd;
848
849 -----------------
850 -- Sprint_Node --
851 -----------------
852
853 procedure Sprint_Node (Node : Node_Id) is
854 begin
855 if Is_Rewrite_Insertion (Node) then
856 if not Dump_Original_Only then
857
858 -- For special cases of nodes that always output <<< >>>
859 -- do not duplicate the output at this point.
860
861 if Nkind (Node) = N_Freeze_Entity
862 or else Nkind (Node) = N_Freeze_Generic_Entity
863 or else Nkind (Node) = N_Implicit_Label_Declaration
864 then
865 Sprint_Node_Actual (Node);
866
867 -- Normal case where <<< >>> may be required
868
869 else
870 Write_Rewrite_Str ("<<<");
871 Sprint_Node_Actual (Node);
872 Write_Rewrite_Str (">>>");
873 end if;
874 end if;
875
876 elsif Is_Rewrite_Substitution (Node) then
877
878 -- Case of dump generated only
879
880 if Dump_Generated_Only then
881 Sprint_Node_Actual (Node);
882
883 -- Case of dump original only
884
885 elsif Dump_Original_Only then
886 Sprint_Node_Actual (Original_Node (Node));
887
888 -- Case of both being dumped
889
890 else
891 Sprint_Node_Actual (Original_Node (Node));
892 Write_Rewrite_Str ("<<<");
893 Sprint_Node_Actual (Node);
894 Write_Rewrite_Str (">>>");
895 end if;
896
897 else
898 Sprint_Node_Actual (Node);
899 end if;
900 end Sprint_Node;
901
902 ------------------------
903 -- Sprint_Node_Actual --
904 ------------------------
905
906 procedure Sprint_Node_Actual (Node : Node_Id) is
907 Save_Dump_Node : constant Node_Id := Dump_Node;
908
909 begin
910 if Node = Empty then
911 return;
912 end if;
913
914 for J in 1 .. Paren_Count (Node) loop
915 Write_Str_With_Col_Check ("(");
916 end loop;
917
918 -- Setup current dump node
919
920 Dump_Node := Node;
921
922 if Nkind (Node) in N_Subexpr
923 and then Do_Range_Check (Node)
924 then
925 Write_Str_With_Col_Check ("{");
926 end if;
927
928 -- Select print circuit based on node kind
929
930 case Nkind (Node) is
931 when N_Abort_Statement =>
932 Write_Indent_Str_Sloc ("abort ");
933 Sprint_Comma_List (Names (Node));
934 Write_Char (';');
935
936 when N_Abortable_Part =>
937 Set_Debug_Sloc;
938 Write_Str_Sloc ("abort ");
939 Sprint_Indented_List (Statements (Node));
940
941 when N_Abstract_Subprogram_Declaration =>
942 Write_Indent;
943 Sprint_Node (Specification (Node));
944 Write_Str_With_Col_Check (" is ");
945 Write_Str_Sloc ("abstract;");
946
947 when N_Accept_Alternative =>
948 Sprint_Node_List (Pragmas_Before (Node));
949
950 if Present (Condition (Node)) then
951 Write_Indent_Str ("when ");
952 Sprint_Node (Condition (Node));
953 Write_Str (" => ");
954 Indent_Annull;
955 end if;
956
957 Sprint_Node_Sloc (Accept_Statement (Node));
958 Sprint_Node_List (Statements (Node));
959
960 when N_Accept_Statement =>
961 Write_Indent_Str_Sloc ("accept ");
962 Write_Id (Entry_Direct_Name (Node));
963
964 if Present (Entry_Index (Node)) then
965 Write_Str_With_Col_Check (" (");
966 Sprint_Node (Entry_Index (Node));
967 Write_Char (')');
968 end if;
969
970 Write_Param_Specs (Node);
971
972 if Present (Handled_Statement_Sequence (Node)) then
973 Write_Str_With_Col_Check (" do");
974 Sprint_Node (Handled_Statement_Sequence (Node));
975 Write_Indent_Str ("end ");
976 Write_Id (Entry_Direct_Name (Node));
977 end if;
978
979 Write_Char (';');
980
981 when N_Access_Definition =>
982
983 -- Ada 2005 (AI-254)
984
985 if Present (Access_To_Subprogram_Definition (Node)) then
986 Sprint_Node (Access_To_Subprogram_Definition (Node));
987 else
988 -- Ada 2005 (AI-231)
989
990 if Null_Exclusion_Present (Node) then
991 Write_Str ("not null ");
992 end if;
993
994 Write_Str_With_Col_Check_Sloc ("access ");
995
996 if All_Present (Node) then
997 Write_Str ("all ");
998 elsif Constant_Present (Node) then
999 Write_Str ("constant ");
1000 end if;
1001
1002 Sprint_Node (Subtype_Mark (Node));
1003 end if;
1004
1005 when N_Access_Function_Definition =>
1006
1007 -- Ada 2005 (AI-231)
1008
1009 if Null_Exclusion_Present (Node) then
1010 Write_Str ("not null ");
1011 end if;
1012
1013 Write_Str_With_Col_Check_Sloc ("access ");
1014
1015 if Protected_Present (Node) then
1016 Write_Str_With_Col_Check ("protected ");
1017 end if;
1018
1019 Write_Str_With_Col_Check ("function");
1020 Write_Param_Specs (Node);
1021 Write_Str_With_Col_Check (" return ");
1022 Sprint_Node (Result_Definition (Node));
1023
1024 when N_Access_Procedure_Definition =>
1025
1026 -- Ada 2005 (AI-231)
1027
1028 if Null_Exclusion_Present (Node) then
1029 Write_Str ("not null ");
1030 end if;
1031
1032 Write_Str_With_Col_Check_Sloc ("access ");
1033
1034 if Protected_Present (Node) then
1035 Write_Str_With_Col_Check ("protected ");
1036 end if;
1037
1038 Write_Str_With_Col_Check ("procedure");
1039 Write_Param_Specs (Node);
1040
1041 when N_Access_To_Object_Definition =>
1042 Write_Str_With_Col_Check_Sloc ("access ");
1043
1044 if All_Present (Node) then
1045 Write_Str_With_Col_Check ("all ");
1046 elsif Constant_Present (Node) then
1047 Write_Str_With_Col_Check ("constant ");
1048 end if;
1049
1050 -- Ada 2005 (AI-231)
1051
1052 if Null_Exclusion_Present (Node) then
1053 Write_Str ("not null ");
1054 end if;
1055
1056 Sprint_Node (Subtype_Indication (Node));
1057
1058 when N_Aggregate =>
1059 if Null_Record_Present (Node) then
1060 Write_Str_With_Col_Check_Sloc ("(null record)");
1061
1062 else
1063 Write_Str_With_Col_Check_Sloc ("(");
1064
1065 if Present (Expressions (Node)) then
1066 Sprint_Comma_List (Expressions (Node));
1067
1068 if not Is_Empty_List (Component_Associations (Node)) then
1069 Write_Str (", ");
1070 end if;
1071 end if;
1072
1073 if not Is_Empty_List (Component_Associations (Node)) then
1074 Indent_Begin;
1075
1076 declare
1077 Nd : Node_Id;
1078
1079 begin
1080 Nd := First (Component_Associations (Node));
1081
1082 loop
1083 Write_Indent;
1084 Sprint_Node (Nd);
1085 Next (Nd);
1086 exit when No (Nd);
1087
1088 if not Is_Rewrite_Insertion (Nd)
1089 or else not Dump_Original_Only
1090 then
1091 Write_Str (", ");
1092 end if;
1093 end loop;
1094 end;
1095
1096 Indent_End;
1097 end if;
1098
1099 Write_Char (')');
1100 end if;
1101
1102 when N_Allocator =>
1103 Write_Str_With_Col_Check_Sloc ("new ");
1104
1105 -- Ada 2005 (AI-231)
1106
1107 if Null_Exclusion_Present (Node) then
1108 Write_Str ("not null ");
1109 end if;
1110
1111 Sprint_Node (Expression (Node));
1112
1113 if Present (Storage_Pool (Node)) then
1114 Write_Str_With_Col_Check ("[storage_pool = ");
1115 Sprint_Node (Storage_Pool (Node));
1116 Write_Char (']');
1117 end if;
1118
1119 when N_And_Then =>
1120 Sprint_Left_Opnd (Node);
1121 Write_Str_Sloc (" and then ");
1122 Sprint_Right_Opnd (Node);
1123
1124 -- Note: the following code for N_Aspect_Specification is not
1125 -- normally used, since we deal with aspects as part of a
1126 -- declaration, but it is here in case we deliberately try
1127 -- to print an N_Aspect_Speficiation node (e.g. from GDB).
1128
1129 when N_Aspect_Specification =>
1130 Sprint_Node (Identifier (Node));
1131 Write_Str (" => ");
1132 Sprint_Node (Expression (Node));
1133
1134 when N_Assignment_Statement =>
1135 Write_Indent;
1136 Sprint_Node (Name (Node));
1137 Write_Str_Sloc (" := ");
1138 Sprint_Node (Expression (Node));
1139 Write_Char (';');
1140
1141 when N_Asynchronous_Select =>
1142 Write_Indent_Str_Sloc ("select");
1143 Indent_Begin;
1144 Sprint_Node (Triggering_Alternative (Node));
1145 Indent_End;
1146
1147 -- Note: let the printing of Abortable_Part handle outputting
1148 -- the ABORT keyword, so that the Sloc can be set correctly.
1149
1150 Write_Indent_Str ("then ");
1151 Sprint_Node (Abortable_Part (Node));
1152 Write_Indent_Str ("end select;");
1153
1154 when N_At_Clause =>
1155 Write_Indent_Str_Sloc ("for ");
1156 Write_Id (Identifier (Node));
1157 Write_Str_With_Col_Check (" use at ");
1158 Sprint_Node (Expression (Node));
1159 Write_Char (';');
1160
1161 when N_Attribute_Definition_Clause =>
1162 Write_Indent_Str_Sloc ("for ");
1163 Sprint_Node (Name (Node));
1164 Write_Char (''');
1165 Write_Name_With_Col_Check (Chars (Node));
1166 Write_Str_With_Col_Check (" use ");
1167 Sprint_Node (Expression (Node));
1168 Write_Char (';');
1169
1170 when N_Attribute_Reference =>
1171 if Is_Procedure_Attribute_Name (Attribute_Name (Node)) then
1172 Write_Indent;
1173 end if;
1174
1175 Sprint_Node (Prefix (Node));
1176 Write_Char_Sloc (''');
1177 Write_Name_With_Col_Check (Attribute_Name (Node));
1178 Sprint_Paren_Comma_List (Expressions (Node));
1179
1180 if Is_Procedure_Attribute_Name (Attribute_Name (Node)) then
1181 Write_Char (';');
1182 end if;
1183
1184 when N_Block_Statement =>
1185 Write_Indent;
1186
1187 if Present (Identifier (Node))
1188 and then (not Has_Created_Identifier (Node)
1189 or else not Dump_Original_Only)
1190 then
1191 Write_Rewrite_Str ("<<<");
1192 Write_Id (Identifier (Node));
1193 Write_Str (" : ");
1194 Write_Rewrite_Str (">>>");
1195 end if;
1196
1197 if Present (Declarations (Node)) then
1198 Write_Str_With_Col_Check_Sloc ("declare");
1199 Sprint_Indented_List (Declarations (Node));
1200 Write_Indent;
1201 end if;
1202
1203 Write_Str_With_Col_Check_Sloc ("begin");
1204 Sprint_Node (Handled_Statement_Sequence (Node));
1205 Write_Indent_Str ("end");
1206
1207 if Present (Identifier (Node))
1208 and then (not Has_Created_Identifier (Node)
1209 or else not Dump_Original_Only)
1210 then
1211 Write_Rewrite_Str ("<<<");
1212 Write_Char (' ');
1213 Write_Id (Identifier (Node));
1214 Write_Rewrite_Str (">>>");
1215 end if;
1216
1217 Write_Char (';');
1218
1219 when N_Call_Marker =>
1220 null;
1221
1222 -- Enable the following code for debugging purposes only
1223
1224 -- Write_Indent_Str ("#");
1225 -- Write_Id (Target (Node));
1226 -- Write_Char ('#');
1227
1228 when N_Case_Expression =>
1229 declare
1230 Has_Parens : constant Boolean := Paren_Count (Node) > 0;
1231 Alt : Node_Id;
1232
1233 begin
1234 -- The syntax for case_expression does not include parentheses,
1235 -- but sometimes parentheses are required, so unconditionally
1236 -- generate them here unless already present.
1237
1238 if not Has_Parens then
1239 Write_Char ('(');
1240 end if;
1241
1242 Write_Str_With_Col_Check_Sloc ("case ");
1243 Sprint_Node (Expression (Node));
1244 Write_Str_With_Col_Check (" is");
1245
1246 Alt := First (Alternatives (Node));
1247 loop
1248 Sprint_Node (Alt);
1249 Next (Alt);
1250 exit when No (Alt);
1251 Write_Char (',');
1252 end loop;
1253
1254 if not Has_Parens then
1255 Write_Char (')');
1256 end if;
1257 end;
1258
1259 when N_Case_Expression_Alternative =>
1260 Write_Str_With_Col_Check (" when ");
1261 Sprint_Bar_List (Discrete_Choices (Node));
1262 Write_Str (" => ");
1263 Sprint_Node (Expression (Node));
1264
1265 when N_Case_Statement =>
1266 Write_Indent_Str_Sloc ("case ");
1267 Sprint_Node (Expression (Node));
1268 Write_Str (" is");
1269 Sprint_Indented_List (Alternatives (Node));
1270 Write_Indent_Str ("end case;");
1271
1272 when N_Case_Statement_Alternative =>
1273 Write_Indent_Str_Sloc ("when ");
1274 Sprint_Bar_List (Discrete_Choices (Node));
1275 Write_Str (" => ");
1276 Sprint_Indented_List (Statements (Node));
1277
1278 when N_Character_Literal =>
1279 if Column > Sprint_Line_Limit - 2 then
1280 Write_Indent_Str (" ");
1281 end if;
1282
1283 Write_Char_Sloc (''');
1284 Write_Char_Code (UI_To_CC (Char_Literal_Value (Node)));
1285 Write_Char (''');
1286
1287 when N_Code_Statement =>
1288 Write_Indent;
1289 Set_Debug_Sloc;
1290 Sprint_Node (Expression (Node));
1291 Write_Char (';');
1292
1293 when N_Compilation_Unit =>
1294 Sprint_Node_List (Context_Items (Node));
1295 Sprint_Opt_Node_List (Declarations (Aux_Decls_Node (Node)));
1296
1297 if Private_Present (Node) then
1298 Write_Indent_Str ("private ");
1299 Indent_Annull;
1300 end if;
1301
1302 Sprint_Node_Sloc (Unit (Node));
1303
1304 if Present (Actions (Aux_Decls_Node (Node)))
1305 or else
1306 Present (Pragmas_After (Aux_Decls_Node (Node)))
1307 then
1308 Write_Indent;
1309 end if;
1310
1311 Sprint_Opt_Node_List (Actions (Aux_Decls_Node (Node)));
1312 Sprint_Opt_Node_List (Pragmas_After (Aux_Decls_Node (Node)));
1313
1314 when N_Compilation_Unit_Aux =>
1315 null; -- nothing to do, never used, see above
1316
1317 when N_Component_Association =>
1318 Set_Debug_Sloc;
1319 Sprint_Bar_List (Choices (Node));
1320 Write_Str (" => ");
1321
1322 -- Ada 2005 (AI-287): Print the box if present
1323
1324 if Box_Present (Node) then
1325 Write_Str_With_Col_Check ("<>");
1326 else
1327 Sprint_Node (Expression (Node));
1328 end if;
1329
1330 when N_Iterated_Component_Association =>
1331 Set_Debug_Sloc;
1332 Write_Str (" for ");
1333 Write_Id (Defining_Identifier (Node));
1334 Write_Str (" in ");
1335 Sprint_Bar_List (Discrete_Choices (Node));
1336 Write_Str (" => ");
1337 Sprint_Node (Expression (Node));
1338
1339 when N_Iterated_Element_Association =>
1340 Set_Debug_Sloc;
1341 if Present (Iterator_Specification (Node)) then
1342 Sprint_Node (Iterator_Specification (Node));
1343 else
1344 Sprint_Node (Loop_Parameter_Specification (Node));
1345 end if;
1346
1347 if Present (Key_Expression (Node)) then
1348 Write_Str (" use ");
1349 Sprint_Node (Key_Expression (Node));
1350 end if;
1351
1352 Write_Str (" => ");
1353 Sprint_Node (Expression (Node));
1354
1355 when N_Component_Clause =>
1356 Write_Indent;
1357 Sprint_Node (Component_Name (Node));
1358 Write_Str_Sloc (" at ");
1359 Sprint_Node (Position (Node));
1360 Write_Char (' ');
1361 Write_Str_With_Col_Check ("range ");
1362 Sprint_Node (First_Bit (Node));
1363 Write_Str (" .. ");
1364 Sprint_Node (Last_Bit (Node));
1365 Write_Char (';');
1366
1367 when N_Component_Definition =>
1368 Set_Debug_Sloc;
1369
1370 -- Ada 2005 (AI-230): Access definition components
1371
1372 if Present (Access_Definition (Node)) then
1373 Sprint_Node (Access_Definition (Node));
1374
1375 elsif Present (Subtype_Indication (Node)) then
1376 if Aliased_Present (Node) then
1377 Write_Str_With_Col_Check ("aliased ");
1378 end if;
1379
1380 -- Ada 2005 (AI-231)
1381
1382 if Null_Exclusion_Present (Node) then
1383 Write_Str (" not null ");
1384 end if;
1385
1386 Sprint_Node (Subtype_Indication (Node));
1387
1388 else
1389 Write_Str (" ??? ");
1390 end if;
1391
1392 when N_Component_Declaration =>
1393 if Write_Indent_Identifiers_Sloc (Node) then
1394 Write_Str (" : ");
1395 Sprint_Node (Component_Definition (Node));
1396
1397 if Present (Expression (Node)) then
1398 Write_Str (" := ");
1399 Sprint_Node (Expression (Node));
1400 end if;
1401
1402 Write_Char (';');
1403 end if;
1404
1405 when N_Component_List =>
1406 if Null_Present (Node) then
1407 Indent_Begin;
1408 Write_Indent_Str_Sloc ("null");
1409 Write_Char (';');
1410 Indent_End;
1411
1412 else
1413 Set_Debug_Sloc;
1414 Sprint_Indented_List (Component_Items (Node));
1415 Sprint_Node (Variant_Part (Node));
1416 end if;
1417
1418 when N_Compound_Statement =>
1419 Write_Indent_Str ("do");
1420 Indent_Begin;
1421 Sprint_Node_List (Actions (Node));
1422 Indent_End;
1423 Write_Indent_Str ("end;");
1424
1425 when N_Conditional_Entry_Call =>
1426 Write_Indent_Str_Sloc ("select");
1427 Indent_Begin;
1428 Sprint_Node (Entry_Call_Alternative (Node));
1429 Indent_End;
1430 Write_Indent_Str ("else");
1431 Sprint_Indented_List (Else_Statements (Node));
1432 Write_Indent_Str ("end select;");
1433
1434 when N_Constrained_Array_Definition =>
1435 Write_Str_With_Col_Check_Sloc ("array ");
1436 Sprint_Paren_Comma_List (Discrete_Subtype_Definitions (Node));
1437 Write_Str (" of ");
1438
1439 Sprint_Node (Component_Definition (Node));
1440
1441 -- A contract node should not appear in the tree. It is a semantic
1442 -- node attached to entry and [generic] subprogram entities. But we
1443 -- still provide meaningful output, in case called from the debugger.
1444
1445 when N_Contract =>
1446 declare
1447 P : Node_Id;
1448
1449 begin
1450 Indent_Begin;
1451 Write_Str ("N_Contract node");
1452 Write_Eol;
1453
1454 Write_Indent_Str ("Pre_Post_Conditions");
1455 Indent_Begin;
1456
1457 P := Pre_Post_Conditions (Node);
1458 while Present (P) loop
1459 Sprint_Node (P);
1460 P := Next_Pragma (P);
1461 end loop;
1462
1463 Write_Eol;
1464 Indent_End;
1465
1466 Write_Indent_Str ("Contract_Test_Cases");
1467 Indent_Begin;
1468
1469 P := Contract_Test_Cases (Node);
1470 while Present (P) loop
1471 Sprint_Node (P);
1472 P := Next_Pragma (P);
1473 end loop;
1474
1475 Write_Eol;
1476 Indent_End;
1477
1478 Write_Indent_Str ("Classifications");
1479 Indent_Begin;
1480
1481 P := Classifications (Node);
1482 while Present (P) loop
1483 Sprint_Node (P);
1484 P := Next_Pragma (P);
1485 end loop;
1486
1487 Write_Eol;
1488 Indent_End;
1489 Indent_End;
1490 end;
1491
1492 when N_Decimal_Fixed_Point_Definition =>
1493 Write_Str_With_Col_Check_Sloc ("delta ");
1494 Sprint_Node (Delta_Expression (Node));
1495 Write_Str_With_Col_Check (" digits ");
1496 Sprint_Node (Digits_Expression (Node));
1497 Sprint_Opt_Node (Real_Range_Specification (Node));
1498
1499 when N_Defining_Character_Literal =>
1500 Write_Name_With_Col_Check_Sloc (Chars (Node));
1501
1502 when N_Defining_Identifier =>
1503 Set_Debug_Sloc;
1504 Write_Id (Node);
1505
1506 when N_Defining_Operator_Symbol =>
1507 Write_Name_With_Col_Check_Sloc (Chars (Node));
1508
1509 when N_Defining_Program_Unit_Name =>
1510 Set_Debug_Sloc;
1511 Sprint_Node (Name (Node));
1512 Write_Char ('.');
1513 Write_Id (Defining_Identifier (Node));
1514
1515 when N_Delay_Alternative =>
1516 Sprint_Node_List (Pragmas_Before (Node));
1517
1518 if Present (Condition (Node)) then
1519 Write_Indent;
1520 Write_Str_With_Col_Check ("when ");
1521 Sprint_Node (Condition (Node));
1522 Write_Str (" => ");
1523 Indent_Annull;
1524 end if;
1525
1526 Sprint_Node_Sloc (Delay_Statement (Node));
1527 Sprint_Node_List (Statements (Node));
1528
1529 when N_Delay_Relative_Statement =>
1530 Write_Indent_Str_Sloc ("delay ");
1531 Sprint_Node (Expression (Node));
1532 Write_Char (';');
1533
1534 when N_Delay_Until_Statement =>
1535 Write_Indent_Str_Sloc ("delay until ");
1536 Sprint_Node (Expression (Node));
1537 Write_Char (';');
1538
1539 when N_Delta_Constraint =>
1540 Write_Str_With_Col_Check_Sloc ("delta ");
1541 Sprint_Node (Delta_Expression (Node));
1542 Sprint_Opt_Node (Range_Constraint (Node));
1543
1544 when N_Derived_Type_Definition =>
1545 if Abstract_Present (Node) then
1546 Write_Str_With_Col_Check ("abstract ");
1547 end if;
1548
1549 Write_Str_With_Col_Check ("new ");
1550
1551 -- Ada 2005 (AI-231)
1552
1553 if Null_Exclusion_Present (Node) then
1554 Write_Str_With_Col_Check ("not null ");
1555 end if;
1556
1557 Sprint_Node (Subtype_Indication (Node));
1558
1559 if Present (Interface_List (Node)) then
1560 Write_Str_With_Col_Check (" and ");
1561 Sprint_And_List (Interface_List (Node));
1562 Write_Str_With_Col_Check (" with ");
1563 end if;
1564
1565 if Present (Record_Extension_Part (Node)) then
1566 if No (Interface_List (Node)) then
1567 Write_Str_With_Col_Check (" with ");
1568 end if;
1569
1570 Sprint_Node (Record_Extension_Part (Node));
1571 end if;
1572
1573 when N_Designator =>
1574 Sprint_Node (Name (Node));
1575 Write_Char_Sloc ('.');
1576 Write_Id (Identifier (Node));
1577
1578 when N_Digits_Constraint =>
1579 Write_Str_With_Col_Check_Sloc ("digits ");
1580 Sprint_Node (Digits_Expression (Node));
1581 Sprint_Opt_Node (Range_Constraint (Node));
1582
1583 when N_Discriminant_Association =>
1584 Set_Debug_Sloc;
1585
1586 if Present (Selector_Names (Node)) then
1587 Sprint_Bar_List (Selector_Names (Node));
1588 Write_Str (" => ");
1589 end if;
1590
1591 Set_Debug_Sloc;
1592 Sprint_Node (Expression (Node));
1593
1594 when N_Discriminant_Specification =>
1595 Set_Debug_Sloc;
1596
1597 if Write_Identifiers (Node) then
1598 Write_Str (" : ");
1599
1600 if Null_Exclusion_Present (Node) then
1601 Write_Str ("not null ");
1602 end if;
1603
1604 Sprint_Node (Discriminant_Type (Node));
1605
1606 if Present (Expression (Node)) then
1607 Write_Str (" := ");
1608 Sprint_Node (Expression (Node));
1609 end if;
1610 else
1611 Write_Str (", ");
1612 end if;
1613
1614 when N_Elsif_Part =>
1615 Write_Indent_Str_Sloc ("elsif ");
1616 Sprint_Node (Condition (Node));
1617 Write_Str_With_Col_Check (" then");
1618 Sprint_Indented_List (Then_Statements (Node));
1619
1620 when N_Empty =>
1621 null;
1622
1623 when N_Entry_Body =>
1624 Write_Indent_Str_Sloc ("entry ");
1625 Write_Id (Defining_Identifier (Node));
1626 Sprint_Node (Entry_Body_Formal_Part (Node));
1627 Write_Str_With_Col_Check (" is");
1628 Sprint_Indented_List (Declarations (Node));
1629 Write_Indent_Str ("begin");
1630 Sprint_Node (Handled_Statement_Sequence (Node));
1631 Write_Indent_Str ("end ");
1632 Write_Id (Defining_Identifier (Node));
1633 Write_Char (';');
1634
1635 when N_Entry_Body_Formal_Part =>
1636 if Present (Entry_Index_Specification (Node)) then
1637 Write_Str_With_Col_Check_Sloc (" (");
1638 Sprint_Node (Entry_Index_Specification (Node));
1639 Write_Char (')');
1640 end if;
1641
1642 Write_Param_Specs (Node);
1643 Write_Str_With_Col_Check_Sloc (" when ");
1644 Sprint_Node (Condition (Node));
1645
1646 when N_Entry_Call_Alternative =>
1647 Sprint_Node_List (Pragmas_Before (Node));
1648 Sprint_Node_Sloc (Entry_Call_Statement (Node));
1649 Sprint_Node_List (Statements (Node));
1650
1651 when N_Entry_Call_Statement =>
1652 Write_Indent;
1653 Sprint_Node_Sloc (Name (Node));
1654 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
1655 Write_Char (';');
1656
1657 when N_Entry_Declaration =>
1658 Write_Indent_Str_Sloc ("entry ");
1659 Write_Id (Defining_Identifier (Node));
1660
1661 if Present (Discrete_Subtype_Definition (Node)) then
1662 Write_Str_With_Col_Check (" (");
1663 Sprint_Node (Discrete_Subtype_Definition (Node));
1664 Write_Char (')');
1665 end if;
1666
1667 Write_Param_Specs (Node);
1668 Write_Char (';');
1669
1670 when N_Entry_Index_Specification =>
1671 Write_Str_With_Col_Check_Sloc ("for ");
1672 Write_Id (Defining_Identifier (Node));
1673 Write_Str_With_Col_Check (" in ");
1674 Sprint_Node (Discrete_Subtype_Definition (Node));
1675
1676 when N_Enumeration_Representation_Clause =>
1677 Write_Indent_Str_Sloc ("for ");
1678 Write_Id (Identifier (Node));
1679 Write_Str_With_Col_Check (" use ");
1680 Sprint_Node (Array_Aggregate (Node));
1681 Write_Char (';');
1682
1683 when N_Enumeration_Type_Definition =>
1684 Set_Debug_Sloc;
1685
1686 -- Skip attempt to print Literals field if it's not there and
1687 -- we are in package Standard (case of Character, which is
1688 -- handled specially (without an explicit literals list).
1689
1690 if Sloc (Node) > Standard_Location
1691 or else Present (Literals (Node))
1692 then
1693 Sprint_Paren_Comma_List (Literals (Node));
1694 end if;
1695
1696 when N_Error =>
1697 Write_Str_With_Col_Check_Sloc ("<error>");
1698
1699 when N_Exception_Declaration =>
1700 if Write_Indent_Identifiers (Node) then
1701 Write_Str_With_Col_Check (" : ");
1702
1703 if Is_Statically_Allocated (Defining_Identifier (Node)) then
1704 Write_Str_With_Col_Check ("static ");
1705 end if;
1706
1707 Write_Str_Sloc ("exception");
1708
1709 if Present (Expression (Node)) then
1710 Write_Str (" := ");
1711 Sprint_Node (Expression (Node));
1712 end if;
1713
1714 Write_Char (';');
1715 end if;
1716
1717 when N_Exception_Handler =>
1718 Write_Indent_Str_Sloc ("when ");
1719
1720 if Present (Choice_Parameter (Node)) then
1721 Sprint_Node (Choice_Parameter (Node));
1722 Write_Str (" : ");
1723 end if;
1724
1725 Sprint_Bar_List (Exception_Choices (Node));
1726 Write_Str (" => ");
1727 Sprint_Indented_List (Statements (Node));
1728
1729 when N_Exception_Renaming_Declaration =>
1730 Write_Indent;
1731 Set_Debug_Sloc;
1732 Sprint_Node (Defining_Identifier (Node));
1733 Write_Str_With_Col_Check (" : exception renames ");
1734 Sprint_Node (Name (Node));
1735 Write_Char (';');
1736
1737 when N_Exit_Statement =>
1738 Write_Indent_Str_Sloc ("exit");
1739 Sprint_Opt_Node (Name (Node));
1740
1741 if Present (Condition (Node)) then
1742 Write_Str_With_Col_Check (" when ");
1743 Sprint_Node (Condition (Node));
1744 end if;
1745
1746 Write_Char (';');
1747
1748 when N_Expanded_Name =>
1749 Sprint_Node (Prefix (Node));
1750 Write_Char_Sloc ('.');
1751 Sprint_Node (Selector_Name (Node));
1752
1753 when N_Explicit_Dereference =>
1754 Sprint_Node (Prefix (Node));
1755 Write_Char_Sloc ('.');
1756 Write_Str_Sloc ("all");
1757
1758 when N_Expression_With_Actions =>
1759 Indent_Begin;
1760 Write_Indent_Str_Sloc ("do ");
1761 Indent_Begin;
1762 Sprint_Node_List (Actions (Node));
1763 Indent_End;
1764 Write_Indent;
1765 Write_Str_With_Col_Check_Sloc ("in ");
1766 Sprint_Node (Expression (Node));
1767 Write_Str_With_Col_Check (" end");
1768 Indent_End;
1769 Write_Indent;
1770
1771 when N_Expression_Function =>
1772 Write_Indent;
1773 Sprint_Node_Sloc (Specification (Node));
1774 Write_Str (" is");
1775 Indent_Begin;
1776 Write_Indent;
1777 Sprint_Node (Expression (Node));
1778 Write_Char (';');
1779 Indent_End;
1780
1781 when N_Extended_Return_Statement =>
1782 Write_Indent_Str_Sloc ("return ");
1783 Sprint_Node_List (Return_Object_Declarations (Node));
1784
1785 if Present (Handled_Statement_Sequence (Node)) then
1786 Write_Str_With_Col_Check (" do");
1787 Sprint_Node (Handled_Statement_Sequence (Node));
1788 Write_Indent_Str ("end return;");
1789 else
1790 Write_Indent_Str (";");
1791 end if;
1792
1793 when N_Delta_Aggregate =>
1794 Write_Str_With_Col_Check_Sloc ("(");
1795 Sprint_Node (Expression (Node));
1796 Write_Str_With_Col_Check (" with delta ");
1797 Sprint_Comma_List (Component_Associations (Node));
1798 Write_Char (')');
1799
1800 when N_Extension_Aggregate =>
1801 Write_Str_With_Col_Check_Sloc ("(");
1802 Sprint_Node (Ancestor_Part (Node));
1803 Write_Str_With_Col_Check (" with ");
1804
1805 if Null_Record_Present (Node) then
1806 Write_Str_With_Col_Check ("null record");
1807 else
1808 if Present (Expressions (Node)) then
1809 Sprint_Comma_List (Expressions (Node));
1810
1811 if Present (Component_Associations (Node)) then
1812 Write_Str (", ");
1813 end if;
1814 end if;
1815
1816 if Present (Component_Associations (Node)) then
1817 Sprint_Comma_List (Component_Associations (Node));
1818 end if;
1819 end if;
1820
1821 Write_Char (')');
1822
1823 when N_Floating_Point_Definition =>
1824 Write_Str_With_Col_Check_Sloc ("digits ");
1825 Sprint_Node (Digits_Expression (Node));
1826 Sprint_Opt_Node (Real_Range_Specification (Node));
1827
1828 when N_Formal_Decimal_Fixed_Point_Definition =>
1829 Write_Str_With_Col_Check_Sloc ("delta <> digits <>");
1830
1831 when N_Formal_Derived_Type_Definition =>
1832 Write_Str_With_Col_Check_Sloc ("new ");
1833 Sprint_Node (Subtype_Mark (Node));
1834
1835 if Present (Interface_List (Node)) then
1836 Write_Str_With_Col_Check (" and ");
1837 Sprint_And_List (Interface_List (Node));
1838 end if;
1839
1840 if Private_Present (Node) then
1841 Write_Str_With_Col_Check (" with private");
1842 end if;
1843
1844 when N_Formal_Abstract_Subprogram_Declaration =>
1845 Write_Indent_Str_Sloc ("with ");
1846 Sprint_Node (Specification (Node));
1847
1848 Write_Str_With_Col_Check (" is abstract");
1849
1850 if Box_Present (Node) then
1851 Write_Str_With_Col_Check (" <>");
1852 elsif Present (Default_Name (Node)) then
1853 Write_Str_With_Col_Check (" ");
1854 Sprint_Node (Default_Name (Node));
1855 end if;
1856
1857 Write_Char (';');
1858
1859 when N_Formal_Concrete_Subprogram_Declaration =>
1860 Write_Indent_Str_Sloc ("with ");
1861 Sprint_Node (Specification (Node));
1862
1863 if Box_Present (Node) then
1864 Write_Str_With_Col_Check (" is <>");
1865 elsif Present (Default_Name (Node)) then
1866 Write_Str_With_Col_Check (" is ");
1867 Sprint_Node (Default_Name (Node));
1868 end if;
1869
1870 Write_Char (';');
1871
1872 when N_Formal_Discrete_Type_Definition =>
1873 Write_Str_With_Col_Check_Sloc ("<>");
1874
1875 when N_Formal_Floating_Point_Definition =>
1876 Write_Str_With_Col_Check_Sloc ("digits <>");
1877
1878 when N_Formal_Modular_Type_Definition =>
1879 Write_Str_With_Col_Check_Sloc ("mod <>");
1880
1881 when N_Formal_Object_Declaration =>
1882 Set_Debug_Sloc;
1883
1884 if Write_Indent_Identifiers (Node) then
1885 Write_Str (" : ");
1886
1887 if In_Present (Node) then
1888 Write_Str_With_Col_Check ("in ");
1889 end if;
1890
1891 if Out_Present (Node) then
1892 Write_Str_With_Col_Check ("out ");
1893 end if;
1894
1895 if Present (Subtype_Mark (Node)) then
1896
1897 -- Ada 2005 (AI-423): Formal object with null exclusion
1898
1899 if Null_Exclusion_Present (Node) then
1900 Write_Str ("not null ");
1901 end if;
1902
1903 Sprint_Node (Subtype_Mark (Node));
1904
1905 -- Ada 2005 (AI-423): Formal object with access definition
1906
1907 else
1908 pragma Assert (Present (Access_Definition (Node)));
1909
1910 Sprint_Node (Access_Definition (Node));
1911 end if;
1912
1913 if Present (Default_Expression (Node)) then
1914 Write_Str (" := ");
1915 Sprint_Node (Default_Expression (Node));
1916 end if;
1917
1918 Write_Char (';');
1919 end if;
1920
1921 when N_Formal_Ordinary_Fixed_Point_Definition =>
1922 Write_Str_With_Col_Check_Sloc ("delta <>");
1923
1924 when N_Formal_Package_Declaration =>
1925 Write_Indent_Str_Sloc ("with package ");
1926 Write_Id (Defining_Identifier (Node));
1927 Write_Str_With_Col_Check (" is new ");
1928 Sprint_Node (Name (Node));
1929 Write_Str_With_Col_Check (" (<>);");
1930
1931 when N_Formal_Private_Type_Definition =>
1932 if Abstract_Present (Node) then
1933 Write_Str_With_Col_Check ("abstract ");
1934 end if;
1935
1936 if Tagged_Present (Node) then
1937 Write_Str_With_Col_Check ("tagged ");
1938 end if;
1939
1940 if Limited_Present (Node) then
1941 Write_Str_With_Col_Check ("limited ");
1942 end if;
1943
1944 Write_Str_With_Col_Check_Sloc ("private");
1945
1946 when N_Formal_Incomplete_Type_Definition =>
1947 if Tagged_Present (Node) then
1948 Write_Str_With_Col_Check ("is tagged ");
1949 end if;
1950
1951 when N_Formal_Signed_Integer_Type_Definition =>
1952 Write_Str_With_Col_Check_Sloc ("range <>");
1953
1954 when N_Formal_Type_Declaration =>
1955 Write_Indent_Str_Sloc ("type ");
1956 Write_Id (Defining_Identifier (Node));
1957
1958 if Present (Discriminant_Specifications (Node)) then
1959 Write_Discr_Specs (Node);
1960 elsif Unknown_Discriminants_Present (Node) then
1961 Write_Str_With_Col_Check ("(<>)");
1962 end if;
1963
1964 if Nkind (Formal_Type_Definition (Node)) /=
1965 N_Formal_Incomplete_Type_Definition
1966 then
1967 Write_Str_With_Col_Check (" is ");
1968 end if;
1969
1970 Sprint_Node (Formal_Type_Definition (Node));
1971 Write_Char (';');
1972
1973 when N_Free_Statement =>
1974 Write_Indent_Str_Sloc ("free ");
1975 Sprint_Node (Expression (Node));
1976 Write_Char (';');
1977
1978 when N_Freeze_Entity =>
1979 if Dump_Original_Only then
1980 null;
1981
1982 -- A freeze node is output if it has some effect (i.e. non-empty
1983 -- actions, or freeze node for an itype, which causes elaboration
1984 -- of the itype), and is also always output if Dump_Freeze_Null
1985 -- is set True.
1986
1987 elsif Present (Actions (Node))
1988 or else Is_Itype (Entity (Node))
1989 or else Dump_Freeze_Null
1990 then
1991 Write_Indent;
1992 Write_Rewrite_Str ("<<<");
1993 Write_Str_With_Col_Check_Sloc ("freeze ");
1994 Write_Id (Entity (Node));
1995 Write_Str (" [");
1996
1997 if No (Actions (Node)) then
1998 Write_Char (']');
1999
2000 else
2001 -- Output freeze actions. We increment Freeze_Indent during
2002 -- this output to avoid generating extra blank lines before
2003 -- any procedures included in the freeze actions.
2004
2005 Freeze_Indent := Freeze_Indent + 1;
2006 Sprint_Indented_List (Actions (Node));
2007 Freeze_Indent := Freeze_Indent - 1;
2008 Write_Indent_Str ("]");
2009 end if;
2010
2011 Write_Rewrite_Str (">>>");
2012 end if;
2013
2014 when N_Freeze_Generic_Entity =>
2015 if Dump_Original_Only then
2016 null;
2017
2018 else
2019 Write_Indent;
2020 Write_Str_With_Col_Check_Sloc ("freeze_generic ");
2021 Write_Id (Entity (Node));
2022 end if;
2023
2024 when N_Full_Type_Declaration =>
2025 Write_Indent_Str_Sloc ("type ");
2026 Sprint_Node (Defining_Identifier (Node));
2027 Write_Discr_Specs (Node);
2028 Write_Str_With_Col_Check (" is ");
2029 Sprint_Node (Type_Definition (Node));
2030 Write_Char (';');
2031
2032 when N_Function_Call =>
2033 Set_Debug_Sloc;
2034 Write_Subprogram_Name (Name (Node));
2035 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
2036
2037 when N_Function_Instantiation =>
2038 Write_Indent_Str_Sloc ("function ");
2039 Sprint_Node (Defining_Unit_Name (Node));
2040 Write_Str_With_Col_Check (" is new ");
2041 Sprint_Node (Name (Node));
2042 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
2043 Write_Char (';');
2044
2045 when N_Function_Specification =>
2046 Write_Str_With_Col_Check_Sloc ("function ");
2047 Sprint_Node (Defining_Unit_Name (Node));
2048 Write_Param_Specs (Node);
2049 Write_Str_With_Col_Check (" return ");
2050
2051 -- Ada 2005 (AI-231)
2052
2053 if Nkind (Result_Definition (Node)) /= N_Access_Definition
2054 and then Null_Exclusion_Present (Node)
2055 then
2056 Write_Str (" not null ");
2057 end if;
2058
2059 Sprint_Node (Result_Definition (Node));
2060
2061 when N_Generic_Association =>
2062 Set_Debug_Sloc;
2063
2064 if Present (Selector_Name (Node)) then
2065 Sprint_Node (Selector_Name (Node));
2066 Write_Str (" => ");
2067 end if;
2068
2069 Sprint_Node (Explicit_Generic_Actual_Parameter (Node));
2070
2071 when N_Generic_Function_Renaming_Declaration =>
2072 Write_Indent_Str_Sloc ("generic function ");
2073 Sprint_Node (Defining_Unit_Name (Node));
2074 Write_Str_With_Col_Check (" renames ");
2075 Sprint_Node (Name (Node));
2076 Write_Char (';');
2077
2078 when N_Generic_Package_Declaration =>
2079 Extra_Blank_Line;
2080 Write_Indent_Str_Sloc ("generic ");
2081 Sprint_Indented_List (Generic_Formal_Declarations (Node));
2082 Write_Indent;
2083 Sprint_Node (Specification (Node));
2084 Write_Char (';');
2085
2086 when N_Generic_Package_Renaming_Declaration =>
2087 Write_Indent_Str_Sloc ("generic package ");
2088 Sprint_Node (Defining_Unit_Name (Node));
2089 Write_Str_With_Col_Check (" renames ");
2090 Sprint_Node (Name (Node));
2091 Write_Char (';');
2092
2093 when N_Generic_Procedure_Renaming_Declaration =>
2094 Write_Indent_Str_Sloc ("generic procedure ");
2095 Sprint_Node (Defining_Unit_Name (Node));
2096 Write_Str_With_Col_Check (" renames ");
2097 Sprint_Node (Name (Node));
2098 Write_Char (';');
2099
2100 when N_Generic_Subprogram_Declaration =>
2101 Extra_Blank_Line;
2102 Write_Indent_Str_Sloc ("generic ");
2103 Sprint_Indented_List (Generic_Formal_Declarations (Node));
2104 Write_Indent;
2105 Sprint_Node (Specification (Node));
2106 Write_Char (';');
2107
2108 when N_Goto_Statement =>
2109 Write_Indent_Str_Sloc ("goto ");
2110 Sprint_Node (Name (Node));
2111 Write_Char (';');
2112
2113 if Nkind (Next (Node)) = N_Label then
2114 Write_Indent;
2115 end if;
2116
2117 when N_Goto_When_Statement =>
2118 Write_Indent_Str_Sloc ("goto ");
2119 Sprint_Node (Name (Node));
2120 Write_Str (" when ");
2121 Sprint_Node (Condition (Node));
2122 Write_Char (';');
2123
2124 when N_Handled_Sequence_Of_Statements =>
2125 Set_Debug_Sloc;
2126 Sprint_Indented_List (Statements (Node));
2127
2128 if Present (Exception_Handlers (Node)) then
2129 Write_Indent_Str ("exception");
2130 Indent_Begin;
2131 Sprint_Node_List (Exception_Handlers (Node));
2132 Indent_End;
2133 end if;
2134
2135 if Present (At_End_Proc (Node)) then
2136 Write_Indent_Str ("at end");
2137 Indent_Begin;
2138 Write_Indent;
2139 Sprint_Node (At_End_Proc (Node));
2140 Write_Char (';');
2141 Indent_End;
2142 end if;
2143
2144 when N_Identifier =>
2145 Set_Debug_Sloc;
2146 Write_Id (Node);
2147
2148 when N_If_Expression =>
2149 declare
2150 Has_Parens : constant Boolean := Paren_Count (Node) > 0;
2151 Condition : constant Node_Id := First (Expressions (Node));
2152 Then_Expr : constant Node_Id := Next (Condition);
2153
2154 begin
2155 -- The syntax for if_expression does not include parentheses,
2156 -- but sometimes parentheses are required, so unconditionally
2157 -- generate them here unless already present.
2158
2159 if not Has_Parens then
2160 Write_Char ('(');
2161 end if;
2162
2163 Write_Str_With_Col_Check_Sloc ("if ");
2164 Sprint_Node (Condition);
2165 Write_Str_With_Col_Check (" then ");
2166
2167 -- Defense against junk here
2168
2169 if Present (Then_Expr) then
2170 Sprint_Node (Then_Expr);
2171
2172 if Present (Next (Then_Expr)) then
2173 Write_Str_With_Col_Check (" else ");
2174 Sprint_Node (Next (Then_Expr));
2175 end if;
2176 end if;
2177
2178 if not Has_Parens then
2179 Write_Char (')');
2180 end if;
2181 end;
2182
2183 when N_If_Statement =>
2184 Write_Indent_Str_Sloc ("if ");
2185 Sprint_Node (Condition (Node));
2186 Write_Str_With_Col_Check (" then");
2187 Sprint_Indented_List (Then_Statements (Node));
2188 Sprint_Opt_Node_List (Elsif_Parts (Node));
2189
2190 if Present (Else_Statements (Node)) then
2191 Write_Indent_Str ("else");
2192 Sprint_Indented_List (Else_Statements (Node));
2193 end if;
2194
2195 Write_Indent_Str ("end if;");
2196
2197 when N_Implicit_Label_Declaration =>
2198 if not Dump_Original_Only then
2199 Write_Indent;
2200 Write_Rewrite_Str ("<<<");
2201 Set_Debug_Sloc;
2202 Write_Id (Defining_Identifier (Node));
2203 Write_Str (" : ");
2204 Write_Str_With_Col_Check ("label");
2205 Write_Rewrite_Str (">>>");
2206 end if;
2207
2208 when N_In =>
2209 Sprint_Left_Opnd (Node);
2210 Write_Str_Sloc (" in ");
2211
2212 if Present (Right_Opnd (Node)) then
2213 Sprint_Right_Opnd (Node);
2214 else
2215 Sprint_Bar_List (Alternatives (Node));
2216 end if;
2217
2218 when N_Incomplete_Type_Declaration =>
2219 Write_Indent_Str_Sloc ("type ");
2220 Write_Id (Defining_Identifier (Node));
2221
2222 if Present (Discriminant_Specifications (Node)) then
2223 Write_Discr_Specs (Node);
2224 elsif Unknown_Discriminants_Present (Node) then
2225 Write_Str_With_Col_Check ("(<>)");
2226 end if;
2227
2228 Write_Char (';');
2229
2230 when N_Index_Or_Discriminant_Constraint =>
2231 Set_Debug_Sloc;
2232 Sprint_Paren_Comma_List (Constraints (Node));
2233
2234 when N_Indexed_Component =>
2235 Sprint_Node_Sloc (Prefix (Node));
2236 Sprint_Opt_Paren_Comma_List (Expressions (Node));
2237
2238 when N_Integer_Literal =>
2239 if Print_In_Hex (Node) then
2240 Write_Uint_With_Col_Check_Sloc (Intval (Node), Hex);
2241 else
2242 Write_Uint_With_Col_Check_Sloc (Intval (Node), Auto);
2243 end if;
2244
2245 when N_Iteration_Scheme =>
2246 if Present (Condition (Node)) then
2247 Write_Str_With_Col_Check_Sloc ("while ");
2248 Sprint_Node (Condition (Node));
2249 else
2250 Write_Str_With_Col_Check_Sloc ("for ");
2251
2252 if Present (Iterator_Specification (Node)) then
2253 Sprint_Node (Iterator_Specification (Node));
2254 else
2255 Sprint_Node (Loop_Parameter_Specification (Node));
2256 end if;
2257 end if;
2258
2259 Write_Char (' ');
2260
2261 when N_Iterator_Specification =>
2262 Set_Debug_Sloc;
2263 Write_Id (Defining_Identifier (Node));
2264
2265 if Present (Subtype_Indication (Node)) then
2266 Write_Str_With_Col_Check (" : ");
2267 Sprint_Node (Subtype_Indication (Node));
2268 end if;
2269
2270 if Of_Present (Node) then
2271 Write_Str_With_Col_Check (" of ");
2272 else
2273 Write_Str_With_Col_Check (" in ");
2274 end if;
2275
2276 if Reverse_Present (Node) then
2277 Write_Str_With_Col_Check ("reverse ");
2278 end if;
2279
2280 Sprint_Node (Name (Node));
2281
2282 when N_Itype_Reference =>
2283 Write_Indent_Str_Sloc ("reference ");
2284 Write_Id (Itype (Node));
2285
2286 when N_Label =>
2287 Write_Indent_Str_Sloc ("<<");
2288 Write_Id (Identifier (Node));
2289 Write_Str (">>");
2290
2291 when N_Loop_Parameter_Specification =>
2292 Set_Debug_Sloc;
2293 Write_Id (Defining_Identifier (Node));
2294 Write_Str_With_Col_Check (" in ");
2295
2296 if Reverse_Present (Node) then
2297 Write_Str_With_Col_Check ("reverse ");
2298 end if;
2299
2300 Sprint_Node (Discrete_Subtype_Definition (Node));
2301
2302 when N_Loop_Statement =>
2303 Write_Indent;
2304
2305 if Present (Identifier (Node))
2306 and then (not Has_Created_Identifier (Node)
2307 or else not Dump_Original_Only)
2308 then
2309 Write_Rewrite_Str ("<<<");
2310 Write_Id (Identifier (Node));
2311 Write_Str (" : ");
2312 Write_Rewrite_Str (">>>");
2313 Sprint_Node (Iteration_Scheme (Node));
2314 Write_Str_With_Col_Check_Sloc ("loop");
2315 Sprint_Indented_List (Statements (Node));
2316 Write_Indent_Str ("end loop ");
2317 Write_Rewrite_Str ("<<<");
2318 Write_Id (Identifier (Node));
2319 Write_Rewrite_Str (">>>");
2320 Write_Char (';');
2321
2322 else
2323 Sprint_Node (Iteration_Scheme (Node));
2324 Write_Str_With_Col_Check_Sloc ("loop");
2325 Sprint_Indented_List (Statements (Node));
2326 Write_Indent_Str ("end loop;");
2327 end if;
2328
2329 when N_Mod_Clause =>
2330 Sprint_Node_List (Pragmas_Before (Node));
2331 Write_Str_With_Col_Check_Sloc ("at mod ");
2332 Sprint_Node (Expression (Node));
2333
2334 when N_Modular_Type_Definition =>
2335 Write_Str_With_Col_Check_Sloc ("mod ");
2336 Sprint_Node (Expression (Node));
2337
2338 when N_Not_In =>
2339 Sprint_Left_Opnd (Node);
2340 Write_Str_Sloc (" not in ");
2341
2342 if Present (Right_Opnd (Node)) then
2343 Sprint_Right_Opnd (Node);
2344 else
2345 Sprint_Bar_List (Alternatives (Node));
2346 end if;
2347
2348 when N_Null =>
2349 Write_Str_With_Col_Check_Sloc ("null");
2350
2351 when N_Null_Statement =>
2352 if Comes_From_Source (Node)
2353 or else Dump_Freeze_Null
2354 or else not Is_List_Member (Node)
2355 or else (No (Prev (Node)) and then No (Next (Node)))
2356 then
2357 Write_Indent_Str_Sloc ("null;");
2358 end if;
2359
2360 when N_Number_Declaration =>
2361 Set_Debug_Sloc;
2362
2363 if Write_Indent_Identifiers (Node) then
2364 Write_Str_With_Col_Check (" : constant ");
2365 Write_Str (" := ");
2366 Sprint_Node (Expression (Node));
2367 Write_Char (';');
2368 end if;
2369
2370 when N_Object_Declaration =>
2371 Set_Debug_Sloc;
2372
2373 if Write_Indent_Identifiers (Node) then
2374 declare
2375 Def_Id : constant Entity_Id := Defining_Identifier (Node);
2376
2377 begin
2378 Write_Str_With_Col_Check (" : ");
2379
2380 if Is_Statically_Allocated (Def_Id) then
2381 Write_Str_With_Col_Check ("static ");
2382 end if;
2383
2384 if Aliased_Present (Node) then
2385 Write_Str_With_Col_Check ("aliased ");
2386 end if;
2387
2388 if Constant_Present (Node) then
2389 Write_Str_With_Col_Check ("constant ");
2390 end if;
2391
2392 -- Ada 2005 (AI-231)
2393
2394 if Null_Exclusion_Present (Node) then
2395 Write_Str_With_Col_Check ("not null ");
2396 end if;
2397
2398 -- Print type. We used to print the Object_Definition from
2399 -- the node, but it is much more useful to print the Etype
2400 -- of the defining identifier for the case where the nominal
2401 -- type is an unconstrained array type. For example, this
2402 -- will be a clear reference to the Itype with the bounds
2403 -- in the case of a type like String. The object after
2404 -- all is constrained, even if its nominal subtype is
2405 -- unconstrained.
2406
2407 declare
2408 Odef : constant Node_Id := Object_Definition (Node);
2409
2410 begin
2411 if Nkind (Odef) = N_Identifier
2412 and then Present (Etype (Odef))
2413 and then Is_Array_Type (Etype (Odef))
2414 and then not Is_Constrained (Etype (Odef))
2415 and then Present (Etype (Def_Id))
2416 then
2417 Sprint_Node (Etype (Def_Id));
2418
2419 -- In other cases, the nominal type is fine to print
2420
2421 else
2422 Sprint_Node (Odef);
2423 end if;
2424 end;
2425
2426 if Present (Expression (Node))
2427 and then Expression (Node) /= Error
2428 and then not No_Initialization (Node)
2429 then
2430 Write_Str (" := ");
2431 Sprint_Node (Expression (Node));
2432 end if;
2433
2434 Write_Char (';');
2435
2436 -- Handle implicit importation and implicit exportation of
2437 -- object declarations:
2438 -- $pragma import (Convention_Id, Def_Id, "...");
2439 -- $pragma export (Convention_Id, Def_Id, "...");
2440
2441 if Is_Internal (Def_Id)
2442 and then Present (Interface_Name (Def_Id))
2443 then
2444 Write_Indent_Str_Sloc ("$pragma ");
2445
2446 if Is_Imported (Def_Id) then
2447 Write_Str ("import (");
2448
2449 else pragma Assert (Is_Exported (Def_Id));
2450 Write_Str ("export (");
2451 end if;
2452
2453 declare
2454 Prefix : constant String := "Convention_";
2455 S : constant String := Convention (Def_Id)'Img;
2456
2457 begin
2458 Name_Len := S'Last - Prefix'Last;
2459 Name_Buffer (1 .. Name_Len) :=
2460 S (Prefix'Last + 1 .. S'Last);
2461 Set_Casing (All_Lower_Case);
2462 Write_Str (Name_Buffer (1 .. Name_Len));
2463 end;
2464
2465 Write_Str (", ");
2466 Write_Id (Def_Id);
2467 Write_Str (", ");
2468 Write_String_Table_Entry
2469 (Strval (Interface_Name (Def_Id)));
2470 Write_Str (");");
2471 end if;
2472 end;
2473 end if;
2474
2475 when N_Object_Renaming_Declaration =>
2476 Write_Indent;
2477 Set_Debug_Sloc;
2478 Sprint_Node (Defining_Identifier (Node));
2479
2480 -- Ada 2005 (AI-230): Access renamings
2481
2482 if Present (Access_Definition (Node)) then
2483 Write_Str (" : ");
2484 Sprint_Node (Access_Definition (Node));
2485
2486 elsif Present (Subtype_Mark (Node)) then
2487 Write_Str (" : ");
2488
2489 -- Ada 2005 (AI-423): Object renaming with a null exclusion
2490
2491 if Null_Exclusion_Present (Node) then
2492 Write_Str ("not null ");
2493 end if;
2494
2495 Sprint_Node (Subtype_Mark (Node));
2496
2497 -- AI12-0275: Object_Renaming_Declaration without explicit subtype
2498
2499 elsif Ada_Version >= Ada_2022 then
2500 null;
2501
2502 else
2503 Write_Str (" : ??? ");
2504 end if;
2505
2506 Write_Str_With_Col_Check (" renames ");
2507 Sprint_Node (Name (Node));
2508 Write_Char (';');
2509
2510 when N_Op_Abs =>
2511 Write_Operator (Node, "abs ");
2512 Sprint_Right_Opnd (Node);
2513
2514 when N_Op_Add =>
2515 Sprint_Left_Opnd (Node);
2516 Write_Operator (Node, " + ");
2517 Sprint_Right_Opnd (Node);
2518
2519 when N_Op_And =>
2520 Sprint_Left_Opnd (Node);
2521 Write_Operator (Node, " and ");
2522 Sprint_Right_Opnd (Node);
2523
2524 when N_Op_Concat =>
2525 Sprint_Left_Opnd (Node);
2526 Write_Operator (Node, " & ");
2527 Sprint_Right_Opnd (Node);
2528
2529 when N_Op_Divide =>
2530 Sprint_Left_Opnd (Node);
2531 Write_Char (' ');
2532 if Rounded_Result (Node) then
2533 Write_Char ('@');
2534 end if;
2535 Write_Operator (Node, "/ ");
2536 Sprint_Right_Opnd (Node);
2537
2538 when N_Op_Eq =>
2539 Sprint_Left_Opnd (Node);
2540 Write_Operator (Node, " = ");
2541 Sprint_Right_Opnd (Node);
2542
2543 when N_Op_Expon =>
2544 Sprint_Left_Opnd (Node);
2545 Write_Operator (Node, " ** ");
2546 Sprint_Right_Opnd (Node);
2547
2548 when N_Op_Ge =>
2549 Sprint_Left_Opnd (Node);
2550 Write_Operator (Node, " >= ");
2551 Sprint_Right_Opnd (Node);
2552
2553 when N_Op_Gt =>
2554 Sprint_Left_Opnd (Node);
2555 Write_Operator (Node, " > ");
2556 Sprint_Right_Opnd (Node);
2557
2558 when N_Op_Le =>
2559 Sprint_Left_Opnd (Node);
2560 Write_Operator (Node, " <= ");
2561 Sprint_Right_Opnd (Node);
2562
2563 when N_Op_Lt =>
2564 Sprint_Left_Opnd (Node);
2565 Write_Operator (Node, " < ");
2566 Sprint_Right_Opnd (Node);
2567
2568 when N_Op_Minus =>
2569 Write_Operator (Node, "-");
2570 Sprint_Right_Opnd (Node);
2571
2572 when N_Op_Mod =>
2573 Sprint_Left_Opnd (Node);
2574 Write_Operator (Node, " mod ");
2575 Sprint_Right_Opnd (Node);
2576
2577 when N_Op_Multiply =>
2578 Sprint_Left_Opnd (Node);
2579 Write_Char (' ');
2580 if Rounded_Result (Node) then
2581 Write_Char ('@');
2582 end if;
2583 Write_Operator (Node, "* ");
2584 Sprint_Right_Opnd (Node);
2585
2586 when N_Op_Ne =>
2587 Sprint_Left_Opnd (Node);
2588 Write_Operator (Node, " /= ");
2589 Sprint_Right_Opnd (Node);
2590
2591 when N_Op_Not =>
2592 Write_Operator (Node, "not ");
2593 Sprint_Right_Opnd (Node);
2594
2595 when N_Op_Or =>
2596 Sprint_Left_Opnd (Node);
2597 Write_Operator (Node, " or ");
2598 Sprint_Right_Opnd (Node);
2599
2600 when N_Op_Plus =>
2601 Write_Operator (Node, "+");
2602 Sprint_Right_Opnd (Node);
2603
2604 when N_Op_Rem =>
2605 Sprint_Left_Opnd (Node);
2606 Write_Operator (Node, " rem ");
2607 Sprint_Right_Opnd (Node);
2608
2609 when N_Op_Shift =>
2610 Set_Debug_Sloc;
2611 Write_Id (Node);
2612 Write_Char ('!');
2613 Write_Str_With_Col_Check ("(");
2614 Sprint_Node (Left_Opnd (Node));
2615 Write_Str (", ");
2616 Sprint_Node (Right_Opnd (Node));
2617 Write_Char (')');
2618
2619 when N_Op_Subtract =>
2620 Sprint_Left_Opnd (Node);
2621 Write_Operator (Node, " - ");
2622 Sprint_Right_Opnd (Node);
2623
2624 when N_Op_Xor =>
2625 Sprint_Left_Opnd (Node);
2626 Write_Operator (Node, " xor ");
2627 Sprint_Right_Opnd (Node);
2628
2629 when N_Operator_Symbol =>
2630 Write_Name_With_Col_Check_Sloc (Chars (Node));
2631
2632 when N_Ordinary_Fixed_Point_Definition =>
2633 Write_Str_With_Col_Check_Sloc ("delta ");
2634 Sprint_Node (Delta_Expression (Node));
2635 Sprint_Opt_Node (Real_Range_Specification (Node));
2636
2637 when N_Or_Else =>
2638 Sprint_Left_Opnd (Node);
2639 Write_Str_Sloc (" or else ");
2640 Sprint_Right_Opnd (Node);
2641
2642 when N_Others_Choice =>
2643 if All_Others (Node) then
2644 Write_Str_With_Col_Check ("all ");
2645 end if;
2646
2647 Write_Str_With_Col_Check_Sloc ("others");
2648
2649 when N_Package_Body =>
2650 Extra_Blank_Line;
2651 Write_Indent_Str_Sloc ("package body ");
2652 Sprint_Node (Defining_Unit_Name (Node));
2653 Write_Str (" is");
2654 Sprint_Indented_List (Declarations (Node));
2655
2656 if Present (Handled_Statement_Sequence (Node)) then
2657 Write_Indent_Str ("begin");
2658 Sprint_Node (Handled_Statement_Sequence (Node));
2659 end if;
2660
2661 Write_Indent_Str ("end ");
2662 Sprint_End_Label
2663 (Handled_Statement_Sequence (Node), Defining_Unit_Name (Node));
2664 Write_Char (';');
2665
2666 when N_Package_Body_Stub =>
2667 Write_Indent_Str_Sloc ("package body ");
2668 Sprint_Node (Defining_Identifier (Node));
2669 Write_Str_With_Col_Check (" is separate;");
2670
2671 when N_Package_Declaration =>
2672 Extra_Blank_Line;
2673 Write_Indent;
2674 Sprint_Node_Sloc (Specification (Node));
2675 Write_Char (';');
2676
2677 -- If this is an instantiation, get the aspects from the original
2678 -- instantiation node.
2679
2680 if Is_Generic_Instance (Defining_Entity (Node))
2681 and then Has_Aspects
2682 (Package_Instantiation (Defining_Entity (Node)))
2683 then
2684 Sprint_Aspect_Specifications
2685 (Package_Instantiation (Defining_Entity (Node)),
2686 Semicolon => True);
2687 end if;
2688
2689 when N_Package_Instantiation =>
2690 Extra_Blank_Line;
2691 Write_Indent_Str_Sloc ("package ");
2692 Sprint_Node (Defining_Unit_Name (Node));
2693 Write_Str (" is new ");
2694 Sprint_Node (Name (Node));
2695 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
2696 Write_Char (';');
2697
2698 when N_Package_Renaming_Declaration =>
2699 Write_Indent_Str_Sloc ("package ");
2700 Sprint_Node (Defining_Unit_Name (Node));
2701 Write_Str_With_Col_Check (" renames ");
2702 Sprint_Node (Name (Node));
2703 Write_Char (';');
2704
2705 when N_Package_Specification =>
2706 Write_Str_With_Col_Check_Sloc ("package ");
2707 Sprint_Node (Defining_Unit_Name (Node));
2708
2709 if Nkind (Parent (Node)) = N_Generic_Package_Declaration
2710 and then Has_Aspects (Parent (Node))
2711 then
2712 Sprint_Aspect_Specifications
2713 (Parent (Node), Semicolon => False);
2714
2715 -- An instantiation is rewritten as a package declaration, but
2716 -- the aspects belong to the instantiation node.
2717
2718 elsif Nkind (Parent (Node)) = N_Package_Declaration then
2719 declare
2720 Pack : constant Entity_Id := Defining_Entity (Node);
2721
2722 begin
2723 if not Is_Generic_Instance (Pack) then
2724 if Has_Aspects (Parent (Node)) then
2725 Sprint_Aspect_Specifications
2726 (Parent (Node), Semicolon => False);
2727 end if;
2728 end if;
2729 end;
2730 end if;
2731
2732 Write_Str (" is");
2733 Sprint_Indented_List (Visible_Declarations (Node));
2734
2735 if Present (Private_Declarations (Node)) then
2736 Write_Indent_Str ("private");
2737 Sprint_Indented_List (Private_Declarations (Node));
2738 end if;
2739
2740 Write_Indent_Str ("end ");
2741 Sprint_Node (Defining_Unit_Name (Node));
2742
2743 when N_Parameter_Association =>
2744 Sprint_Node_Sloc (Selector_Name (Node));
2745 Write_Str (" => ");
2746 Sprint_Node (Explicit_Actual_Parameter (Node));
2747
2748 when N_Parameter_Specification =>
2749 Set_Debug_Sloc;
2750
2751 if Write_Identifiers (Node) then
2752 Write_Str (" : ");
2753
2754 if In_Present (Node) then
2755 Write_Str_With_Col_Check ("in ");
2756 end if;
2757
2758 if Out_Present (Node) then
2759 Write_Str_With_Col_Check ("out ");
2760 end if;
2761
2762 -- Ada 2005 (AI-231): Parameter specification may carry null
2763 -- exclusion. Do not print it now if this is an access formal,
2764 -- it is emitted when the access definition is displayed.
2765
2766 if Null_Exclusion_Present (Node)
2767 and then Nkind (Parameter_Type (Node)) /= N_Access_Definition
2768 then
2769 Write_Str ("not null ");
2770 end if;
2771
2772 if Aliased_Present (Node) then
2773 Write_Str ("aliased ");
2774 end if;
2775
2776 Sprint_Node (Parameter_Type (Node));
2777
2778 if Present (Expression (Node)) then
2779 Write_Str (" := ");
2780 Sprint_Node (Expression (Node));
2781 end if;
2782 else
2783 Write_Str (", ");
2784 end if;
2785
2786 when N_Pop_Constraint_Error_Label =>
2787 Write_Indent_Str ("%pop_constraint_error_label");
2788
2789 when N_Pop_Program_Error_Label =>
2790 Write_Indent_Str ("%pop_program_error_label");
2791
2792 when N_Pop_Storage_Error_Label =>
2793 Write_Indent_Str ("%pop_storage_error_label");
2794
2795 when N_Private_Extension_Declaration =>
2796 Write_Indent_Str_Sloc ("type ");
2797 Write_Id (Defining_Identifier (Node));
2798
2799 if Present (Discriminant_Specifications (Node)) then
2800 Write_Discr_Specs (Node);
2801 elsif Unknown_Discriminants_Present (Node) then
2802 Write_Str_With_Col_Check ("(<>)");
2803 end if;
2804
2805 Write_Str_With_Col_Check (" is new ");
2806 Sprint_Node (Subtype_Indication (Node));
2807
2808 if Present (Interface_List (Node)) then
2809 Write_Str_With_Col_Check (" and ");
2810 Sprint_And_List (Interface_List (Node));
2811 end if;
2812
2813 Write_Str_With_Col_Check (" with private;");
2814
2815 when N_Private_Type_Declaration =>
2816 Write_Indent_Str_Sloc ("type ");
2817 Write_Id (Defining_Identifier (Node));
2818
2819 if Present (Discriminant_Specifications (Node)) then
2820 Write_Discr_Specs (Node);
2821 elsif Unknown_Discriminants_Present (Node) then
2822 Write_Str_With_Col_Check ("(<>)");
2823 end if;
2824
2825 Write_Str (" is ");
2826
2827 if Tagged_Present (Node) then
2828 Write_Str_With_Col_Check ("tagged ");
2829 end if;
2830
2831 if Limited_Present (Node) then
2832 Write_Str_With_Col_Check ("limited ");
2833 end if;
2834
2835 Write_Str_With_Col_Check ("private;");
2836
2837 when N_Push_Constraint_Error_Label =>
2838 Write_Indent_Str ("%push_constraint_error_label (");
2839
2840 if Present (Exception_Label (Node)) then
2841 Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2842 end if;
2843
2844 Write_Str (")");
2845
2846 when N_Push_Program_Error_Label =>
2847 Write_Indent_Str ("%push_program_error_label (");
2848
2849 if Present (Exception_Label (Node)) then
2850 Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2851 end if;
2852
2853 Write_Str (")");
2854
2855 when N_Push_Storage_Error_Label =>
2856 Write_Indent_Str ("%push_storage_error_label (");
2857
2858 if Present (Exception_Label (Node)) then
2859 Write_Name_With_Col_Check (Chars (Exception_Label (Node)));
2860 end if;
2861
2862 Write_Str (")");
2863
2864 when N_Pragma =>
2865 Write_Indent_Str_Sloc ("pragma ");
2866 Write_Name_With_Col_Check (Pragma_Name_Unmapped (Node));
2867
2868 if Present (Pragma_Argument_Associations (Node)) then
2869 Sprint_Opt_Paren_Comma_List
2870 (Pragma_Argument_Associations (Node));
2871 end if;
2872
2873 Write_Char (';');
2874
2875 when N_Pragma_Argument_Association =>
2876 Set_Debug_Sloc;
2877
2878 if Chars (Node) /= No_Name then
2879 Write_Name_With_Col_Check (Chars (Node));
2880 Write_Str (" => ");
2881 end if;
2882
2883 Sprint_Node (Expression (Node));
2884
2885 when N_Procedure_Call_Statement =>
2886 Write_Indent;
2887 Set_Debug_Sloc;
2888 Write_Subprogram_Name (Name (Node));
2889 Sprint_Opt_Paren_Comma_List (Parameter_Associations (Node));
2890 Write_Char (';');
2891
2892 when N_Procedure_Instantiation =>
2893 Write_Indent_Str_Sloc ("procedure ");
2894 Sprint_Node (Defining_Unit_Name (Node));
2895 Write_Str_With_Col_Check (" is new ");
2896 Sprint_Node (Name (Node));
2897 Sprint_Opt_Paren_Comma_List (Generic_Associations (Node));
2898 Write_Char (';');
2899
2900 when N_Procedure_Specification =>
2901 Write_Str_With_Col_Check_Sloc ("procedure ");
2902 Sprint_Node (Defining_Unit_Name (Node));
2903 Write_Param_Specs (Node);
2904
2905 when N_Protected_Body =>
2906 Write_Indent_Str_Sloc ("protected body ");
2907 Write_Id (Defining_Identifier (Node));
2908 Write_Str (" is");
2909 Sprint_Indented_List (Declarations (Node));
2910 Write_Indent_Str ("end ");
2911 Write_Id (Defining_Identifier (Node));
2912 Write_Char (';');
2913
2914 when N_Protected_Body_Stub =>
2915 Write_Indent_Str_Sloc ("protected body ");
2916 Write_Id (Defining_Identifier (Node));
2917 Write_Str_With_Col_Check (" is separate;");
2918
2919 when N_Protected_Definition =>
2920 Set_Debug_Sloc;
2921 Sprint_Indented_List (Visible_Declarations (Node));
2922
2923 if Present (Private_Declarations (Node)) then
2924 Write_Indent_Str ("private");
2925 Sprint_Indented_List (Private_Declarations (Node));
2926 end if;
2927
2928 Write_Indent_Str ("end ");
2929
2930 when N_Protected_Type_Declaration =>
2931 Write_Indent_Str_Sloc ("protected type ");
2932 Sprint_Node (Defining_Identifier (Node));
2933 Write_Discr_Specs (Node);
2934
2935 if Present (Interface_List (Node)) then
2936 Write_Str (" is new ");
2937 Sprint_And_List (Interface_List (Node));
2938 Write_Str (" with ");
2939 else
2940 Write_Str (" is");
2941 end if;
2942
2943 Sprint_Node (Protected_Definition (Node));
2944 Write_Id (Defining_Identifier (Node));
2945 Write_Char (';');
2946
2947 when N_Qualified_Expression =>
2948 Sprint_Node (Subtype_Mark (Node));
2949 Write_Char_Sloc (''');
2950
2951 -- Print expression, make sure we have at least one level of
2952 -- parentheses around the expression. For cases of qualified
2953 -- expressions in the source, this is always the case, but
2954 -- for generated qualifications, there may be no explicit
2955 -- parentheses present.
2956
2957 if Paren_Count (Expression (Node)) /= 0 then
2958 Sprint_Node (Expression (Node));
2959
2960 else
2961 Write_Char ('(');
2962 Sprint_Node (Expression (Node));
2963
2964 -- Odd case, for the qualified expressions used in machine
2965 -- code the argument may be a procedure call, resulting in
2966 -- a junk semicolon before the right parent, get rid of it.
2967
2968 Write_Erase_Char (';');
2969
2970 -- Now we can add the terminating right paren
2971
2972 Write_Char (')');
2973 end if;
2974
2975 when N_Quantified_Expression =>
2976 Write_Str (" for");
2977
2978 if All_Present (Node) then
2979 Write_Str (" all ");
2980 else
2981 Write_Str (" some ");
2982 end if;
2983
2984 if Present (Iterator_Specification (Node)) then
2985 Sprint_Node (Iterator_Specification (Node));
2986 else
2987 Sprint_Node (Loop_Parameter_Specification (Node));
2988 end if;
2989
2990 Write_Str (" => ");
2991 Sprint_Node (Condition (Node));
2992
2993 when N_Raise_Expression =>
2994 declare
2995 Has_Parens : constant Boolean := Paren_Count (Node) > 0;
2996
2997 begin
2998 -- The syntax for raise_expression does not include parentheses
2999 -- but sometimes parentheses are required, so unconditionally
3000 -- generate them here unless already present.
3001
3002 if not Has_Parens then
3003 Write_Char ('(');
3004 end if;
3005
3006 Write_Str_With_Col_Check_Sloc ("raise ");
3007 Sprint_Node (Name (Node));
3008
3009 if Present (Expression (Node)) then
3010 Write_Str_With_Col_Check (" with ");
3011 Sprint_Node (Expression (Node));
3012 end if;
3013
3014 if not Has_Parens then
3015 Write_Char (')');
3016 end if;
3017 end;
3018
3019 when N_Raise_Constraint_Error =>
3020
3021 -- This node can be used either as a subexpression or as a
3022 -- statement form. The following test is a reasonably reliable
3023 -- way to distinguish the two cases.
3024
3025 if Is_List_Member (Node)
3026 and then Nkind (Parent (Node)) not in N_Subexpr
3027 then
3028 Write_Indent;
3029 end if;
3030
3031 Write_Str_With_Col_Check_Sloc ("[constraint_error");
3032 Write_Condition_And_Reason (Node);
3033
3034 when N_Raise_Program_Error =>
3035
3036 -- This node can be used either as a subexpression or as a
3037 -- statement form. The following test is a reasonably reliable
3038 -- way to distinguish the two cases.
3039
3040 if Is_List_Member (Node)
3041 and then Nkind (Parent (Node)) not in N_Subexpr
3042 then
3043 Write_Indent;
3044 end if;
3045
3046 Write_Str_With_Col_Check_Sloc ("[program_error");
3047 Write_Condition_And_Reason (Node);
3048
3049 when N_Raise_Storage_Error =>
3050
3051 -- This node can be used either as a subexpression or as a
3052 -- statement form. The following test is a reasonably reliable
3053 -- way to distinguish the two cases.
3054
3055 if Is_List_Member (Node)
3056 and then Nkind (Parent (Node)) not in N_Subexpr
3057 then
3058 Write_Indent;
3059 end if;
3060
3061 Write_Str_With_Col_Check_Sloc ("[storage_error");
3062 Write_Condition_And_Reason (Node);
3063
3064 when N_Raise_Statement =>
3065 Write_Indent_Str_Sloc ("raise ");
3066 Sprint_Node (Name (Node));
3067
3068 if Present (Expression (Node)) then
3069 Write_Str_With_Col_Check_Sloc (" with ");
3070 Sprint_Node (Expression (Node));
3071 end if;
3072
3073 Write_Char (';');
3074
3075 when N_Raise_When_Statement =>
3076 Write_Indent_Str_Sloc ("raise ");
3077 Sprint_Node (Name (Node));
3078 Write_Str (" when ");
3079 Sprint_Node (Condition (Node));
3080
3081 if Present (Expression (Node)) then
3082 Write_Str_With_Col_Check_Sloc (" with ");
3083 Sprint_Node (Expression (Node));
3084 end if;
3085
3086 Write_Char (';');
3087
3088 when N_Range =>
3089 Sprint_Node (Low_Bound (Node));
3090 Write_Str_Sloc (" .. ");
3091 if Present (Etype (Node))
3092 and then Is_Fixed_Lower_Bound_Index_Subtype (Etype (Node))
3093 then
3094 Write_Str ("<>");
3095 else
3096 Sprint_Node (High_Bound (Node));
3097 end if;
3098 Update_Itype (Node);
3099
3100 when N_Range_Constraint =>
3101 Write_Str_With_Col_Check_Sloc ("range ");
3102 Sprint_Node (Range_Expression (Node));
3103
3104 when N_Real_Literal =>
3105 Write_Ureal_With_Col_Check_Sloc (Realval (Node));
3106
3107 when N_Real_Range_Specification =>
3108 Write_Str_With_Col_Check_Sloc ("range ");
3109 Sprint_Node (Low_Bound (Node));
3110 Write_Str (" .. ");
3111 Sprint_Node (High_Bound (Node));
3112
3113 when N_Record_Definition =>
3114 if Abstract_Present (Node) then
3115 Write_Str_With_Col_Check ("abstract ");
3116 end if;
3117
3118 if Tagged_Present (Node) then
3119 Write_Str_With_Col_Check ("tagged ");
3120 end if;
3121
3122 if Limited_Present (Node) then
3123 Write_Str_With_Col_Check ("limited ");
3124 end if;
3125
3126 if Null_Present (Node) then
3127 Write_Str_With_Col_Check_Sloc ("null record");
3128
3129 else
3130 Write_Str_With_Col_Check_Sloc ("record");
3131 Sprint_Node (Component_List (Node));
3132 Write_Indent_Str ("end record");
3133 end if;
3134
3135 when N_Record_Representation_Clause =>
3136 Write_Indent_Str_Sloc ("for ");
3137 Sprint_Node (Identifier (Node));
3138 Write_Str_With_Col_Check (" use record ");
3139
3140 if Present (Mod_Clause (Node)) then
3141 Sprint_Node (Mod_Clause (Node));
3142 end if;
3143
3144 Sprint_Indented_List (Component_Clauses (Node));
3145 Write_Indent_Str ("end record;");
3146
3147 when N_Reference =>
3148 Sprint_Node (Prefix (Node));
3149 Write_Str_With_Col_Check_Sloc ("'reference");
3150
3151 when N_Requeue_Statement =>
3152 Write_Indent_Str_Sloc ("requeue ");
3153 Sprint_Node (Name (Node));
3154
3155 if Abort_Present (Node) then
3156 Write_Str_With_Col_Check (" with abort");
3157 end if;
3158
3159 Write_Char (';');
3160
3161 when N_Return_When_Statement =>
3162 Write_Indent_Str_Sloc ("return ");
3163 Sprint_Node (Expression (Node));
3164 Write_Str (" when ");
3165 Sprint_Node (Condition (Node));
3166 Write_Char (';');
3167
3168 when N_SCIL_Dispatch_Table_Tag_Init =>
3169 Write_Indent_Str ("[N_SCIL_Dispatch_Table_Tag_Init]");
3170
3171 when N_SCIL_Dispatching_Call =>
3172 Write_Indent_Str ("[N_SCIL_Dispatching_Node]");
3173
3174 when N_SCIL_Membership_Test =>
3175 Write_Indent_Str ("[N_SCIL_Membership_Test]");
3176
3177 when N_Simple_Return_Statement =>
3178 if Present (Expression (Node)) then
3179 Write_Indent_Str_Sloc ("return ");
3180 Sprint_Node (Expression (Node));
3181 Write_Char (';');
3182 else
3183 Write_Indent_Str_Sloc ("return;");
3184 end if;
3185
3186 when N_Selective_Accept =>
3187 Write_Indent_Str_Sloc ("select");
3188
3189 declare
3190 Alt_Node : Node_Id;
3191 begin
3192 Alt_Node := First (Select_Alternatives (Node));
3193 loop
3194 Indent_Begin;
3195 Sprint_Node (Alt_Node);
3196 Indent_End;
3197 Next (Alt_Node);
3198 exit when No (Alt_Node);
3199 Write_Indent_Str ("or");
3200 end loop;
3201 end;
3202
3203 if Present (Else_Statements (Node)) then
3204 Write_Indent_Str ("else");
3205 Sprint_Indented_List (Else_Statements (Node));
3206 end if;
3207
3208 Write_Indent_Str ("end select;");
3209
3210 when N_Signed_Integer_Type_Definition =>
3211 Write_Str_With_Col_Check_Sloc ("range ");
3212 Sprint_Node (Low_Bound (Node));
3213 Write_Str (" .. ");
3214 Sprint_Node (High_Bound (Node));
3215
3216 when N_Single_Protected_Declaration =>
3217 Write_Indent_Str_Sloc ("protected ");
3218 Write_Id (Defining_Identifier (Node));
3219 Write_Str (" is");
3220 Sprint_Node (Protected_Definition (Node));
3221 Write_Id (Defining_Identifier (Node));
3222 Write_Char (';');
3223
3224 when N_Single_Task_Declaration =>
3225 Write_Indent_Str_Sloc ("task ");
3226 Sprint_Node (Defining_Identifier (Node));
3227
3228 if Present (Task_Definition (Node)) then
3229 Write_Str (" is");
3230 Sprint_Node (Task_Definition (Node));
3231 end if;
3232
3233 Write_Char (';');
3234
3235 when N_Selected_Component =>
3236 Sprint_Node (Prefix (Node));
3237 Write_Char_Sloc ('.');
3238 Sprint_Node (Selector_Name (Node));
3239
3240 when N_Slice =>
3241 Set_Debug_Sloc;
3242 Sprint_Node (Prefix (Node));
3243 Write_Str_With_Col_Check (" (");
3244 Sprint_Node (Discrete_Range (Node));
3245 Write_Char (')');
3246
3247 when N_String_Literal =>
3248 if String_Length (Strval (Node)) + Column > Sprint_Line_Limit then
3249 Write_Indent_Str (" ");
3250 end if;
3251
3252 Set_Debug_Sloc;
3253 Write_String_Table_Entry (Strval (Node));
3254
3255 when N_Subprogram_Body =>
3256
3257 -- Output extra blank line unless we are in freeze actions
3258
3259 if Freeze_Indent = 0 then
3260 Extra_Blank_Line;
3261 end if;
3262
3263 Write_Indent;
3264
3265 if Present (Corresponding_Spec (Node)) then
3266 Sprint_Node_Sloc (Parent (Corresponding_Spec (Node)));
3267 else
3268 Sprint_Node_Sloc (Specification (Node));
3269 end if;
3270
3271 Write_Str (" is");
3272
3273 Sprint_Indented_List (Declarations (Node));
3274 Write_Indent_Str ("begin");
3275 Sprint_Node (Handled_Statement_Sequence (Node));
3276
3277 Write_Indent_Str ("end ");
3278
3279 Sprint_End_Label
3280 (Handled_Statement_Sequence (Node),
3281 Defining_Unit_Name (Specification (Node)));
3282 Write_Char (';');
3283
3284 if Is_List_Member (Node)
3285 and then Present (Next (Node))
3286 and then Nkind (Next (Node)) /= N_Subprogram_Body
3287 then
3288 Write_Indent;
3289 end if;
3290
3291 when N_Subprogram_Body_Stub =>
3292 Write_Indent;
3293 Sprint_Node_Sloc (Specification (Node));
3294 Write_Str_With_Col_Check (" is separate;");
3295
3296 when N_Subprogram_Declaration =>
3297 Write_Indent;
3298 Sprint_Node_Sloc (Specification (Node));
3299
3300 if Nkind (Specification (Node)) = N_Procedure_Specification
3301 and then Null_Present (Specification (Node))
3302 then
3303 Write_Str_With_Col_Check (" is null");
3304 end if;
3305
3306 Write_Char (';');
3307
3308 when N_Subprogram_Renaming_Declaration =>
3309 Write_Indent;
3310 Sprint_Node (Specification (Node));
3311 Write_Str_With_Col_Check_Sloc (" renames ");
3312 Sprint_Node (Name (Node));
3313 Write_Char (';');
3314
3315 when N_Subtype_Declaration =>
3316 Write_Indent_Str_Sloc ("subtype ");
3317 Sprint_Node (Defining_Identifier (Node));
3318 Write_Str (" is ");
3319
3320 -- Ada 2005 (AI-231)
3321
3322 if Null_Exclusion_Present (Node) then
3323 Write_Str ("not null ");
3324 end if;
3325
3326 Sprint_Node (Subtype_Indication (Node));
3327 Write_Char (';');
3328
3329 when N_Subtype_Indication =>
3330 Sprint_Node_Sloc (Subtype_Mark (Node));
3331 Write_Char (' ');
3332 Sprint_Node (Constraint (Node));
3333
3334 when N_Subunit =>
3335 Write_Indent_Str_Sloc ("separate (");
3336 Sprint_Node (Name (Node));
3337 Write_Char (')');
3338 Extra_Blank_Line;
3339 Sprint_Node (Proper_Body (Node));
3340
3341 when N_Target_Name =>
3342 Write_Char ('@');
3343
3344 when N_Task_Body =>
3345 Write_Indent_Str_Sloc ("task body ");
3346 Write_Id (Defining_Identifier (Node));
3347 Write_Str (" is");
3348 Sprint_Indented_List (Declarations (Node));
3349 Write_Indent_Str ("begin");
3350 Sprint_Node (Handled_Statement_Sequence (Node));
3351 Write_Indent_Str ("end ");
3352 Sprint_End_Label
3353 (Handled_Statement_Sequence (Node), Defining_Identifier (Node));
3354 Write_Char (';');
3355
3356 when N_Task_Body_Stub =>
3357 Write_Indent_Str_Sloc ("task body ");
3358 Write_Id (Defining_Identifier (Node));
3359 Write_Str_With_Col_Check (" is separate;");
3360
3361 when N_Task_Definition =>
3362 Set_Debug_Sloc;
3363 Sprint_Indented_List (Visible_Declarations (Node));
3364
3365 if Present (Private_Declarations (Node)) then
3366 Write_Indent_Str ("private");
3367 Sprint_Indented_List (Private_Declarations (Node));
3368 end if;
3369
3370 Write_Indent_Str ("end ");
3371 Sprint_End_Label (Node, Defining_Identifier (Parent (Node)));
3372
3373 when N_Task_Type_Declaration =>
3374 Write_Indent_Str_Sloc ("task type ");
3375 Sprint_Node (Defining_Identifier (Node));
3376 Write_Discr_Specs (Node);
3377
3378 if Present (Interface_List (Node)) then
3379 Write_Str (" is new ");
3380 Sprint_And_List (Interface_List (Node));
3381 end if;
3382
3383 if Present (Task_Definition (Node)) then
3384 if No (Interface_List (Node)) then
3385 Write_Str (" is");
3386 else
3387 Write_Str (" with ");
3388 end if;
3389
3390 Sprint_Node (Task_Definition (Node));
3391 end if;
3392
3393 Write_Char (';');
3394
3395 when N_Terminate_Alternative =>
3396 Sprint_Node_List (Pragmas_Before (Node));
3397 Write_Indent;
3398
3399 if Present (Condition (Node)) then
3400 Write_Str_With_Col_Check ("when ");
3401 Sprint_Node (Condition (Node));
3402 Write_Str (" => ");
3403 end if;
3404
3405 Write_Str_With_Col_Check_Sloc ("terminate;");
3406 Sprint_Node_List (Pragmas_After (Node));
3407
3408 when N_Timed_Entry_Call =>
3409 Write_Indent_Str_Sloc ("select");
3410 Indent_Begin;
3411 Sprint_Node (Entry_Call_Alternative (Node));
3412 Indent_End;
3413 Write_Indent_Str ("or");
3414 Indent_Begin;
3415 Sprint_Node (Delay_Alternative (Node));
3416 Indent_End;
3417 Write_Indent_Str ("end select;");
3418
3419 when N_Triggering_Alternative =>
3420 Sprint_Node_List (Pragmas_Before (Node));
3421 Sprint_Node_Sloc (Triggering_Statement (Node));
3422 Sprint_Node_List (Statements (Node));
3423
3424 when N_Type_Conversion =>
3425 Set_Debug_Sloc;
3426 Sprint_Node (Subtype_Mark (Node));
3427 Col_Check (4);
3428
3429 if Conversion_OK (Node) then
3430 Write_Char ('?');
3431 end if;
3432
3433 if Float_Truncate (Node) then
3434 Write_Char ('^');
3435 end if;
3436
3437 if Rounded_Result (Node) then
3438 Write_Char ('@');
3439 end if;
3440
3441 Write_Char ('(');
3442 Sprint_Node (Expression (Node));
3443 Write_Char (')');
3444
3445 when N_Unchecked_Expression =>
3446 Col_Check (10);
3447 Write_Str ("`(");
3448 Sprint_Node_Sloc (Expression (Node));
3449 Write_Char (')');
3450
3451 when N_Unchecked_Type_Conversion =>
3452 Sprint_Node (Subtype_Mark (Node));
3453 Write_Char ('!');
3454 Write_Str_With_Col_Check ("(");
3455 Sprint_Node_Sloc (Expression (Node));
3456 Write_Char (')');
3457
3458 when N_Unconstrained_Array_Definition =>
3459 Write_Str_With_Col_Check_Sloc ("array (");
3460
3461 declare
3462 Node1 : Node_Id;
3463 begin
3464 Node1 := First (Subtype_Marks (Node));
3465 loop
3466 Sprint_Node (Node1);
3467 Write_Str_With_Col_Check (" range <>");
3468 Next (Node1);
3469 exit when Node1 = Empty;
3470 Write_Str (", ");
3471 end loop;
3472 end;
3473
3474 Write_Str (") of ");
3475 Sprint_Node (Component_Definition (Node));
3476
3477 when N_Unused_At_Start | N_Unused_At_End =>
3478 Write_Indent_Str ("***** Error, unused node encountered *****");
3479 Write_Eol;
3480
3481 when N_Use_Package_Clause =>
3482 Write_Indent_Str_Sloc ("use ");
3483 Sprint_Node_Sloc (Name (Node));
3484 Write_Char (';');
3485
3486 when N_Use_Type_Clause =>
3487 Write_Indent_Str_Sloc ("use type ");
3488 Sprint_Node_Sloc (Subtype_Mark (Node));
3489 Write_Char (';');
3490
3491 when N_Validate_Unchecked_Conversion =>
3492 Write_Indent_Str_Sloc ("validate unchecked_conversion (");
3493 Sprint_Node (Source_Type (Node));
3494 Write_Str (", ");
3495 Sprint_Node (Target_Type (Node));
3496 Write_Str (");");
3497
3498 when N_Variable_Reference_Marker =>
3499 null;
3500
3501 -- Enable the following code for debugging purposes only
3502
3503 -- if Is_Read (Node) and then Is_Write (Node) then
3504 -- Write_Indent_Str ("rw#");
3505
3506 -- elsif Is_Read (Node) then
3507 -- Write_Indent_Str ("r#");
3508
3509 -- else
3510 -- pragma Assert (Is_Write (Node));
3511 -- Write_Indent_Str ("w#");
3512 -- end if;
3513
3514 -- Write_Id (Target (Node));
3515 -- Write_Char ('#');
3516
3517 when N_Variant =>
3518 Write_Indent_Str_Sloc ("when ");
3519 Sprint_Bar_List (Discrete_Choices (Node));
3520 Write_Str (" => ");
3521 Sprint_Node (Component_List (Node));
3522
3523 when N_Variant_Part =>
3524 Indent_Begin;
3525 Write_Indent_Str_Sloc ("case ");
3526 Sprint_Node (Name (Node));
3527 Write_Str (" is ");
3528 Sprint_Indented_List (Variants (Node));
3529 Write_Indent_Str ("end case");
3530 Indent_End;
3531
3532 when N_With_Clause =>
3533
3534 -- Special test, if we are dumping the original tree only,
3535 -- then we want to eliminate the bogus with clauses that
3536 -- correspond to the non-existent children of Text_IO.
3537
3538 if Dump_Original_Only
3539 and then Is_Text_IO_Special_Unit (Name (Node))
3540 then
3541 null;
3542
3543 -- Normal case, output the with clause
3544
3545 else
3546 if First_Name (Node) or else not Dump_Original_Only then
3547
3548 -- Ada 2005 (AI-50217): Print limited with_clauses
3549
3550 if Private_Present (Node) and Limited_Present (Node) then
3551 Write_Indent_Str ("limited private with ");
3552
3553 elsif Private_Present (Node) then
3554 Write_Indent_Str ("private with ");
3555
3556 elsif Limited_Present (Node) then
3557 Write_Indent_Str ("limited with ");
3558
3559 else
3560 Write_Indent_Str ("with ");
3561 end if;
3562
3563 else
3564 Write_Str (", ");
3565 end if;
3566
3567 Sprint_Node_Sloc (Name (Node));
3568
3569 if Last_Name (Node) or else not Dump_Original_Only then
3570 Write_Char (';');
3571 end if;
3572 end if;
3573 end case;
3574
3575 -- Print aspects, except for special case of package declaration,
3576 -- where the aspects are printed inside the package specification.
3577
3578 if Has_Aspects (Node)
3579 and then Nkind (Node) not in
3580 N_Generic_Package_Declaration | N_Package_Declaration
3581 and then not Is_Empty_List (Aspect_Specifications (Node))
3582 then
3583 Sprint_Aspect_Specifications (Node, Semicolon => True);
3584 end if;
3585
3586 if Nkind (Node) in N_Subexpr and then Do_Range_Check (Node) then
3587 Write_Str ("}");
3588 end if;
3589
3590 for J in 1 .. Paren_Count (Node) loop
3591 Write_Char (')');
3592 end loop;
3593
3594 Dump_Node := Save_Dump_Node;
3595 end Sprint_Node_Actual;
3596
3597 ----------------------
3598 -- Sprint_Node_List --
3599 ----------------------
3600
3601 procedure Sprint_Node_List (List : List_Id; New_Lines : Boolean := False) is
3602 Node : Node_Id;
3603
3604 begin
3605 if Is_Non_Empty_List (List) then
3606 Node := First (List);
3607
3608 loop
3609 Sprint_Node (Node);
3610 Next (Node);
3611 exit when Node = Empty;
3612 end loop;
3613 end if;
3614
3615 if New_Lines and then Column /= 1 then
3616 Write_Eol;
3617 end if;
3618 end Sprint_Node_List;
3619
3620 ----------------------
3621 -- Sprint_Node_Sloc --
3622 ----------------------
3623
3624 procedure Sprint_Node_Sloc (Node : Node_Id) is
3625 begin
3626 Sprint_Node (Node);
3627
3628 if Debug_Generated_Code and then Present (Dump_Node) then
3629 Set_Sloc (Dump_Node, Sloc (Node));
3630 Dump_Node := Empty;
3631 end if;
3632 end Sprint_Node_Sloc;
3633
3634 ---------------------
3635 -- Sprint_Opt_Node --
3636 ---------------------
3637
3638 procedure Sprint_Opt_Node (Node : Node_Id) is
3639 begin
3640 if Present (Node) then
3641 Write_Char (' ');
3642 Sprint_Node (Node);
3643 end if;
3644 end Sprint_Opt_Node;
3645
3646 --------------------------
3647 -- Sprint_Opt_Node_List --
3648 --------------------------
3649
3650 procedure Sprint_Opt_Node_List (List : List_Id) is
3651 begin
3652 if Present (List) then
3653 Sprint_Node_List (List);
3654 end if;
3655 end Sprint_Opt_Node_List;
3656
3657 ---------------------------------
3658 -- Sprint_Opt_Paren_Comma_List --
3659 ---------------------------------
3660
3661 procedure Sprint_Opt_Paren_Comma_List (List : List_Id) is
3662 begin
3663 if Is_Non_Empty_List (List) then
3664 Write_Char (' ');
3665 Sprint_Paren_Comma_List (List);
3666 end if;
3667 end Sprint_Opt_Paren_Comma_List;
3668
3669 -----------------------------
3670 -- Sprint_Paren_Comma_List --
3671 -----------------------------
3672
3673 procedure Sprint_Paren_Comma_List (List : List_Id) is
3674 N : Node_Id;
3675 Node_Exists : Boolean := False;
3676
3677 begin
3678
3679 if Is_Non_Empty_List (List) then
3680
3681 if Dump_Original_Only then
3682 N := First (List);
3683 while Present (N) loop
3684 if not Is_Rewrite_Insertion (N) then
3685 Node_Exists := True;
3686 exit;
3687 end if;
3688
3689 Next (N);
3690 end loop;
3691
3692 if not Node_Exists then
3693 return;
3694 end if;
3695 end if;
3696
3697 Write_Str_With_Col_Check ("(");
3698 Sprint_Comma_List (List);
3699 Write_Char (')');
3700 end if;
3701 end Sprint_Paren_Comma_List;
3702
3703 ----------------------
3704 -- Sprint_Right_Opnd --
3705 ----------------------
3706
3707 procedure Sprint_Right_Opnd (N : Node_Id) is
3708 Opnd : constant Node_Id := Right_Opnd (N);
3709
3710 begin
3711 if Paren_Count (Opnd) /= 0
3712 or else Op_Prec (Nkind (Opnd)) > Op_Prec (Nkind (N))
3713 then
3714 Sprint_Node (Opnd);
3715
3716 else
3717 Write_Char ('(');
3718 Sprint_Node (Opnd);
3719 Write_Char (')');
3720 end if;
3721 end Sprint_Right_Opnd;
3722
3723 ------------------
3724 -- Update_Itype --
3725 ------------------
3726
3727 procedure Update_Itype (Node : Node_Id) is
3728 begin
3729 if Present (Etype (Node))
3730 and then Is_Itype (Etype (Node))
3731 and then Debug_Generated_Code
3732 then
3733 Set_Sloc (Etype (Node), Sloc (Node));
3734 end if;
3735 end Update_Itype;
3736
3737 ---------------------
3738 -- Write_Char_Sloc --
3739 ---------------------
3740
3741 procedure Write_Char_Sloc (C : Character) is
3742 begin
3743 if Debug_Generated_Code and then C /= ' ' then
3744 Set_Debug_Sloc;
3745 end if;
3746
3747 Write_Char (C);
3748 end Write_Char_Sloc;
3749
3750 --------------------------------
3751 -- Write_Condition_And_Reason --
3752 --------------------------------
3753
3754 procedure Write_Condition_And_Reason (Node : Node_Id) is
3755 Cond : constant Node_Id := Condition (Node);
3756 Image : constant String := RT_Exception_Code'Image
3757 (RT_Exception_Code'Val
3758 (UI_To_Int (Reason (Node))));
3759
3760 begin
3761 if Present (Cond) then
3762
3763 -- If condition is a single entity, or NOT with a single entity,
3764 -- output all on one line, since it will likely fit just fine.
3765
3766 if Is_Entity_Name (Cond)
3767 or else (Nkind (Cond) = N_Op_Not
3768 and then Is_Entity_Name (Right_Opnd (Cond)))
3769 then
3770 Write_Str_With_Col_Check (" when ");
3771 Sprint_Node (Cond);
3772 Write_Char (' ');
3773
3774 -- Otherwise for more complex condition, multiple lines
3775
3776 else
3777 Write_Str_With_Col_Check (" when");
3778 Indent := Indent + 2;
3779 Write_Indent;
3780 Sprint_Node (Cond);
3781 Write_Indent;
3782 Indent := Indent - 2;
3783 end if;
3784
3785 -- If no condition, just need a space (all on one line)
3786
3787 else
3788 Write_Char (' ');
3789 end if;
3790
3791 -- Write the reason
3792
3793 Write_Char ('"');
3794
3795 for J in 4 .. Image'Last loop
3796 if Image (J) = '_' then
3797 Write_Char (' ');
3798 else
3799 Write_Char (Fold_Lower (Image (J)));
3800 end if;
3801 end loop;
3802
3803 Write_Str ("""]");
3804 end Write_Condition_And_Reason;
3805
3806 --------------------------------
3807 -- Write_Corresponding_Source --
3808 --------------------------------
3809
3810 procedure Write_Corresponding_Source (S : String) is
3811 Loc : Source_Ptr;
3812 Src : Source_Buffer_Ptr;
3813
3814 begin
3815 -- Ignore if there is no current source file, or we're not in dump
3816 -- source text mode, or if in freeze actions.
3817
3818 if Current_Source_File > No_Source_File
3819 and then Dump_Source_Text
3820 and then Freeze_Indent = 0
3821 then
3822
3823 -- Ignore null string
3824
3825 if S = "" then
3826 return;
3827 end if;
3828
3829 -- Ignore space or semicolon at end of given string
3830
3831 if S (S'Last) = ' ' or else S (S'Last) = ';' then
3832 Write_Corresponding_Source (S (S'First .. S'Last - 1));
3833 return;
3834 end if;
3835
3836 -- Loop to look at next lines not yet printed in source file
3837
3838 for L in
3839 Last_Line_Printed + 1 .. Last_Source_Line (Current_Source_File)
3840 loop
3841 Src := Source_Text (Current_Source_File);
3842 Loc := Line_Start (L, Current_Source_File);
3843
3844 -- If comment, keep looking
3845
3846 if Src (Loc .. Loc + 1) = "--" then
3847 null;
3848
3849 -- Search to first non-blank
3850
3851 else
3852 while Src (Loc) not in Line_Terminator loop
3853
3854 -- Non-blank found
3855
3856 if Src (Loc) /= ' ' and then Src (Loc) /= ASCII.HT then
3857
3858 -- Loop through characters in string to see if we match
3859
3860 for J in S'Range loop
3861
3862 -- If mismatch, then not the case we are looking for
3863
3864 if Src (Loc) /= S (J) then
3865 return;
3866 end if;
3867
3868 Loc := Loc + 1;
3869 end loop;
3870
3871 -- If we fall through, string matched, if white space or
3872 -- semicolon after the matched string, this is the case
3873 -- we are looking for.
3874
3875 if Src (Loc) in Line_Terminator
3876 or else Src (Loc) = ' '
3877 or else Src (Loc) = ASCII.HT
3878 or else Src (Loc) = ';'
3879 then
3880 -- So output source lines up to and including this one
3881
3882 Write_Source_Lines (L);
3883 return;
3884 end if;
3885 end if;
3886
3887 Loc := Loc + 1;
3888 end loop;
3889 end if;
3890
3891 -- Line was all blanks, or a comment line, keep looking
3892
3893 end loop;
3894 end if;
3895 end Write_Corresponding_Source;
3896
3897 -----------------------
3898 -- Write_Discr_Specs --
3899 -----------------------
3900
3901 procedure Write_Discr_Specs (N : Node_Id) is
3902 Specs : List_Id;
3903 Spec : Node_Id;
3904
3905 begin
3906 Specs := Discriminant_Specifications (N);
3907
3908 if Present (Specs) then
3909 Write_Str_With_Col_Check (" (");
3910 Spec := First (Specs);
3911
3912 loop
3913 Sprint_Node (Spec);
3914 Next (Spec);
3915 exit when Spec = Empty;
3916
3917 -- Add semicolon, unless we are printing original tree and the
3918 -- next specification is part of a list (but not the first
3919 -- element of that list)
3920
3921 if not Dump_Original_Only or else not Prev_Ids (Spec) then
3922 Write_Str ("; ");
3923 end if;
3924 end loop;
3925
3926 Write_Char (')');
3927 end if;
3928 end Write_Discr_Specs;
3929
3930 -----------------
3931 -- Write_Ekind --
3932 -----------------
3933
3934 procedure Write_Ekind (E : Entity_Id) is
3935 S : constant String := Entity_Kind'Image (Ekind (E));
3936
3937 begin
3938 Name_Len := S'Length;
3939 Name_Buffer (1 .. Name_Len) := S;
3940 Set_Casing (Mixed_Case);
3941 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
3942 end Write_Ekind;
3943
3944 --------------
3945 -- Write_Id --
3946 --------------
3947
3948 procedure Write_Id (N : Node_Id) is
3949 begin
3950 -- Deal with outputting Itype
3951
3952 -- Note: if we are printing the full tree with -gnatds, then we may
3953 -- end up picking up the Associated_Node link from a generic template
3954 -- here which overlaps the Entity field, but as documented, Write_Itype
3955 -- is defended against junk calls.
3956
3957 if Nkind (N) in N_Entity then
3958 Write_Itype (N);
3959 elsif Nkind (N) in N_Has_Entity then
3960 Write_Itype (Entity (N));
3961 end if;
3962
3963 -- Case of a defining identifier
3964
3965 if Nkind (N) = N_Defining_Identifier then
3966
3967 -- If defining identifier has an interface name (and no
3968 -- address clause), then we output the interface name.
3969
3970 if (Is_Imported (N) or else Is_Exported (N))
3971 and then Present (Interface_Name (N))
3972 and then No (Address_Clause (N))
3973 then
3974 String_To_Name_Buffer (Strval (Interface_Name (N)));
3975 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
3976
3977 -- If no interface name (or inactive because there was
3978 -- an address clause), then just output the Chars name.
3979
3980 else
3981 Write_Name_With_Col_Check (Chars (N));
3982 end if;
3983
3984 -- Case of selector of an expanded name where the expanded name
3985 -- has an associated entity, output this entity. Check that the
3986 -- entity or associated node is of the right kind, see above.
3987
3988 elsif Nkind (Parent (N)) = N_Expanded_Name
3989 and then Selector_Name (Parent (N)) = N
3990 and then Present (Entity_Or_Associated_Node (Parent (N)))
3991 and then Nkind (Entity (Parent (N))) in N_Entity
3992 then
3993 Write_Id (Entity (Parent (N)));
3994
3995 -- For any other node with an associated entity, output it
3996
3997 elsif Nkind (N) in N_Has_Entity
3998 and then Present (Entity_Or_Associated_Node (N))
3999 and then Nkind (Entity_Or_Associated_Node (N)) in N_Entity
4000 then
4001 Write_Id (Entity (N));
4002
4003 -- All other cases, we just print the Chars field
4004
4005 else
4006 Write_Name_With_Col_Check (Chars (N));
4007 end if;
4008 end Write_Id;
4009
4010 -----------------------
4011 -- Write_Identifiers --
4012 -----------------------
4013
4014 function Write_Identifiers (Node : Node_Id) return Boolean is
4015 begin
4016 Sprint_Node (Defining_Identifier (Node));
4017 Update_Itype (Defining_Identifier (Node));
4018
4019 -- The remainder of the declaration must be printed unless we are
4020 -- printing the original tree and this is not the last identifier
4021
4022 return
4023 not Dump_Original_Only or else not More_Ids (Node);
4024
4025 end Write_Identifiers;
4026
4027 ------------------------
4028 -- Write_Implicit_Def --
4029 ------------------------
4030
4031 procedure Write_Implicit_Def (E : Entity_Id) is
4032 Ind : Node_Id;
4033
4034 begin
4035 case Ekind (E) is
4036 when E_Array_Subtype =>
4037 Write_Str_With_Col_Check ("subtype ");
4038 Write_Id (E);
4039 Write_Str_With_Col_Check (" is ");
4040 Write_Id (Base_Type (E));
4041 Write_Str_With_Col_Check (" (");
4042
4043 Ind := First_Index (E);
4044 while Present (Ind) loop
4045 Sprint_Node (Ind);
4046 Next_Index (Ind);
4047
4048 if Present (Ind) then
4049 Write_Str (", ");
4050 end if;
4051 end loop;
4052
4053 Write_Str (");");
4054
4055 when E_Enumeration_Subtype
4056 | E_Signed_Integer_Subtype
4057 =>
4058 Write_Str_With_Col_Check ("subtype ");
4059 Write_Id (E);
4060 Write_Str (" is ");
4061 Write_Id (Etype (E));
4062 Write_Str_With_Col_Check (" range ");
4063 Sprint_Node (Scalar_Range (E));
4064 Write_Str (";");
4065
4066 when others =>
4067 Write_Str_With_Col_Check ("type ");
4068 Write_Id (E);
4069 Write_Str_With_Col_Check (" is <");
4070 Write_Ekind (E);
4071 Write_Str (">;");
4072 end case;
4073 end Write_Implicit_Def;
4074
4075 ------------------
4076 -- Write_Indent --
4077 ------------------
4078
4079 procedure Write_Indent is
4080 Loc : constant Source_Ptr := Sloc (Dump_Node);
4081
4082 begin
4083 if Indent_Annull_Flag then
4084 Indent_Annull_Flag := False;
4085 else
4086 -- Deal with Dump_Source_Text output. Note that we ignore implicit
4087 -- label declarations, since they typically have the sloc of the
4088 -- corresponding label, which really messes up the -gnatL output.
4089
4090 if Dump_Source_Text
4091 and then Loc > No_Location
4092 and then Nkind (Dump_Node) /= N_Implicit_Label_Declaration
4093 then
4094 if Get_Source_File_Index (Loc) = Current_Source_File then
4095 Write_Source_Lines
4096 (Get_Physical_Line_Number (Sloc (Dump_Node)));
4097 end if;
4098 end if;
4099
4100 Write_Eol;
4101
4102 for J in 1 .. Indent loop
4103 Write_Char (' ');
4104 end loop;
4105 end if;
4106 end Write_Indent;
4107
4108 ------------------------------
4109 -- Write_Indent_Identifiers --
4110 ------------------------------
4111
4112 function Write_Indent_Identifiers (Node : Node_Id) return Boolean is
4113 begin
4114 -- We need to start a new line for every node, except in the case
4115 -- where we are printing the original tree and this is not the first
4116 -- defining identifier in the list.
4117
4118 if not Dump_Original_Only or else not Prev_Ids (Node) then
4119 Write_Indent;
4120
4121 -- If printing original tree and this is not the first defining
4122 -- identifier in the list, then the previous call to this procedure
4123 -- printed only the name, and we add a comma to separate the names.
4124
4125 else
4126 Write_Str (", ");
4127 end if;
4128
4129 Sprint_Node (Defining_Identifier (Node));
4130
4131 -- The remainder of the declaration must be printed unless we are
4132 -- printing the original tree and this is not the last identifier
4133
4134 return
4135 not Dump_Original_Only or else not More_Ids (Node);
4136 end Write_Indent_Identifiers;
4137
4138 -----------------------------------
4139 -- Write_Indent_Identifiers_Sloc --
4140 -----------------------------------
4141
4142 function Write_Indent_Identifiers_Sloc (Node : Node_Id) return Boolean is
4143 begin
4144 -- We need to start a new line for every node, except in the case
4145 -- where we are printing the original tree and this is not the first
4146 -- defining identifier in the list.
4147
4148 if not Dump_Original_Only or else not Prev_Ids (Node) then
4149 Write_Indent;
4150
4151 -- If printing original tree and this is not the first defining
4152 -- identifier in the list, then the previous call to this procedure
4153 -- printed only the name, and we add a comma to separate the names.
4154
4155 else
4156 Write_Str (", ");
4157 end if;
4158
4159 Set_Debug_Sloc;
4160 Sprint_Node (Defining_Identifier (Node));
4161
4162 -- The remainder of the declaration must be printed unless we are
4163 -- printing the original tree and this is not the last identifier
4164
4165 return not Dump_Original_Only or else not More_Ids (Node);
4166 end Write_Indent_Identifiers_Sloc;
4167
4168 ----------------------
4169 -- Write_Indent_Str --
4170 ----------------------
4171
4172 procedure Write_Indent_Str (S : String) is
4173 begin
4174 Write_Corresponding_Source (S);
4175 Write_Indent;
4176 Write_Str (S);
4177 end Write_Indent_Str;
4178
4179 ---------------------------
4180 -- Write_Indent_Str_Sloc --
4181 ---------------------------
4182
4183 procedure Write_Indent_Str_Sloc (S : String) is
4184 begin
4185 Write_Corresponding_Source (S);
4186 Write_Indent;
4187 Write_Str_Sloc (S);
4188 end Write_Indent_Str_Sloc;
4189
4190 -----------------
4191 -- Write_Itype --
4192 -----------------
4193
4194 procedure Write_Itype (Typ : Entity_Id) is
4195
4196 procedure Write_Header (T : Boolean := True);
4197 -- Write type if T is True, subtype if T is false
4198
4199 ------------------
4200 -- Write_Header --
4201 ------------------
4202
4203 procedure Write_Header (T : Boolean := True) is
4204 begin
4205 if T then
4206 Write_Str ("[type ");
4207 else
4208 Write_Str ("[subtype ");
4209 end if;
4210
4211 Write_Name_With_Col_Check (Chars (Typ));
4212 Write_Str (" is ");
4213 end Write_Header;
4214
4215 -- Start of processing for Write_Itype
4216
4217 begin
4218 if Nkind (Typ) in N_Entity
4219 and then Is_Itype (Typ)
4220 and then not Itype_Printed (Typ)
4221 then
4222 -- Itype to be printed
4223
4224 declare
4225 B : constant Node_Id := Etype (Typ);
4226 P : constant Node_Id := Parent (Typ);
4227 S : constant Saved_Output_Buffer := Save_Output_Buffer;
4228 -- Save current output buffer
4229
4230 Old_Sloc : Source_Ptr;
4231 -- Save sloc of related node, so it is not modified when
4232 -- printing with -gnatD.
4233
4234 X : Node_Id;
4235
4236 begin
4237 -- Write indentation at start of line
4238
4239 for J in 1 .. Indent loop
4240 Write_Char (' ');
4241 end loop;
4242
4243 -- If we have a constructed declaration for the itype, print it
4244
4245 if Present (P)
4246 and then Nkind (P) in N_Declaration
4247 and then Defining_Entity (P) = Typ
4248 then
4249 -- We must set Itype_Printed true before the recursive call to
4250 -- print the node, otherwise we get an infinite recursion.
4251
4252 Set_Itype_Printed (Typ, True);
4253
4254 -- Write the declaration enclosed in [], avoiding new line
4255 -- at start of declaration, and semicolon at end.
4256
4257 -- Note: The itype may be imported from another unit, in which
4258 -- case we do not want to modify the Sloc of the declaration.
4259 -- Otherwise the itype may appear to be in the current unit,
4260 -- and the back-end will reject a reference out of scope.
4261
4262 Write_Char ('[');
4263 Indent_Annull_Flag := True;
4264 Old_Sloc := Sloc (P);
4265 Sprint_Node (P);
4266 Set_Sloc (P, Old_Sloc);
4267 Write_Erase_Char (';');
4268
4269 -- If no constructed declaration, then we have to concoct the
4270 -- source corresponding to the type entity that we have at hand.
4271
4272 else
4273 case Ekind (Typ) is
4274
4275 -- Access types and subtypes
4276
4277 when Access_Kind =>
4278 Write_Header (Ekind (Typ) = E_Access_Type);
4279
4280 if Can_Never_Be_Null (Typ) then
4281 Write_Str ("not null ");
4282 end if;
4283
4284 Write_Str ("access ");
4285
4286 if Is_Access_Constant (Typ) then
4287 Write_Str ("constant ");
4288 end if;
4289
4290 Write_Id (Directly_Designated_Type (Typ));
4291
4292 -- Array types
4293
4294 when E_Array_Type =>
4295 Write_Header;
4296 Write_Str ("array (");
4297
4298 X := First_Index (Typ);
4299 loop
4300 Sprint_Node (X);
4301
4302 if not Is_Constrained (Typ) then
4303 Write_Str (" range <>");
4304 end if;
4305
4306 Next_Index (X);
4307 exit when No (X);
4308 Write_Str (", ");
4309 end loop;
4310
4311 Write_Str (") of ");
4312 X := Component_Type (Typ);
4313
4314 -- Preserve sloc of component type, which is defined
4315 -- elsewhere than the itype (see comment above).
4316
4317 Old_Sloc := Sloc (X);
4318 Sprint_Node (X);
4319 Set_Sloc (X, Old_Sloc);
4320
4321 -- Array subtypes
4322
4323 -- Preserve Sloc of index subtypes, as above
4324
4325 when E_Array_Subtype =>
4326 Write_Header (False);
4327 Write_Id (Etype (Typ));
4328 Write_Str (" (");
4329
4330 X := First_Index (Typ);
4331 loop
4332 Old_Sloc := Sloc (X);
4333 Sprint_Node (X);
4334 Set_Sloc (X, Old_Sloc);
4335 Next_Index (X);
4336 exit when No (X);
4337 Write_Str (", ");
4338 end loop;
4339
4340 Write_Char (')');
4341
4342 -- Signed integer types, and modular integer subtypes,
4343 -- and also enumeration subtypes.
4344
4345 when E_Enumeration_Subtype
4346 | E_Modular_Integer_Subtype
4347 | E_Signed_Integer_Subtype
4348 | E_Signed_Integer_Type
4349 =>
4350 Write_Header (Ekind (Typ) = E_Signed_Integer_Type);
4351
4352 if Ekind (Typ) = E_Signed_Integer_Type then
4353 Write_Str ("new ");
4354 end if;
4355
4356 Write_Id (B);
4357
4358 -- Print bounds if different from base type
4359
4360 declare
4361 L : constant Node_Id := Type_Low_Bound (Typ);
4362 H : constant Node_Id := Type_High_Bound (Typ);
4363 BL : Node_Id;
4364 BH : Node_Id;
4365
4366 begin
4367 -- B can either be a scalar type, in which case the
4368 -- declaration of Typ may constrain it with different
4369 -- bounds, or a private type, in which case we know
4370 -- that the declaration of Typ cannot have a scalar
4371 -- constraint.
4372
4373 if Is_Scalar_Type (B) then
4374 BL := Type_Low_Bound (B);
4375 BH := Type_High_Bound (B);
4376 else
4377 BL := Empty;
4378 BH := Empty;
4379 end if;
4380
4381 if No (BL)
4382 or else (True
4383 and then Nkind (L) = N_Integer_Literal
4384 and then Nkind (H) = N_Integer_Literal
4385 and then Nkind (BL) = N_Integer_Literal
4386 and then Nkind (BH) = N_Integer_Literal
4387 and then UI_Eq (Intval (L), Intval (BL))
4388 and then UI_Eq (Intval (H), Intval (BH)))
4389 then
4390 null;
4391
4392 else
4393 Write_Str (" range ");
4394 Sprint_Node (L);
4395 Write_Str (" .. ");
4396 Sprint_Node (H);
4397 end if;
4398 end;
4399
4400 -- Modular integer types
4401
4402 when E_Modular_Integer_Type =>
4403 Write_Header;
4404 Write_Str ("mod ");
4405 Write_Uint_With_Col_Check (Modulus (Typ), Auto);
4406
4407 -- Floating-point types and subtypes
4408
4409 when E_Floating_Point_Subtype
4410 | E_Floating_Point_Type
4411 =>
4412 Write_Header (Ekind (Typ) = E_Floating_Point_Type);
4413
4414 if Ekind (Typ) = E_Floating_Point_Type then
4415 Write_Str ("new ");
4416 end if;
4417
4418 Write_Id (B);
4419
4420 if Digits_Value (Typ) /= Digits_Value (B) then
4421 Write_Str (" digits ");
4422 Write_Uint_With_Col_Check
4423 (Digits_Value (Typ), Decimal);
4424 end if;
4425
4426 -- Print bounds if not different from base type
4427
4428 declare
4429 L : constant Node_Id := Type_Low_Bound (Typ);
4430 H : constant Node_Id := Type_High_Bound (Typ);
4431 BL : constant Node_Id := Type_Low_Bound (B);
4432 BH : constant Node_Id := Type_High_Bound (B);
4433
4434 begin
4435 if True
4436 and then Nkind (L) = N_Real_Literal
4437 and then Nkind (H) = N_Real_Literal
4438 and then Nkind (BL) = N_Real_Literal
4439 and then Nkind (BH) = N_Real_Literal
4440 and then UR_Eq (Realval (L), Realval (BL))
4441 and then UR_Eq (Realval (H), Realval (BH))
4442 then
4443 null;
4444
4445 else
4446 Write_Str (" range ");
4447 Sprint_Node (L);
4448 Write_Str (" .. ");
4449 Sprint_Node (H);
4450 end if;
4451 end;
4452
4453 -- Ordinary fixed-point types and subtypes
4454
4455 when E_Ordinary_Fixed_Point_Subtype
4456 | E_Ordinary_Fixed_Point_Type
4457 =>
4458 Write_Header (Ekind (Typ) = E_Ordinary_Fixed_Point_Type);
4459
4460 Write_Str ("delta ");
4461 Write_Ureal_With_Col_Check_Sloc (Delta_Value (Typ));
4462 Write_Str (" range ");
4463 Sprint_Node (Type_Low_Bound (Typ));
4464 Write_Str (" .. ");
4465 Sprint_Node (Type_High_Bound (Typ));
4466
4467 -- Decimal fixed-point types and subtypes
4468
4469 when E_Decimal_Fixed_Point_Subtype
4470 | E_Decimal_Fixed_Point_Type
4471 =>
4472 Write_Header (Ekind (Typ) = E_Decimal_Fixed_Point_Type);
4473
4474 Write_Str ("delta ");
4475 Write_Ureal_With_Col_Check_Sloc (Delta_Value (Typ));
4476 Write_Str (" digits ");
4477 Write_Uint_With_Col_Check (Digits_Value (Typ), Decimal);
4478
4479 -- Record subtypes
4480
4481 when E_Record_Subtype
4482 | E_Record_Subtype_With_Private
4483 =>
4484 Write_Header (False);
4485 Write_Str ("record");
4486 Indent_Begin;
4487
4488 declare
4489 C : Entity_Id;
4490 begin
4491 C := First_Entity (Typ);
4492 while Present (C) loop
4493 Write_Indent;
4494 Write_Id (C);
4495 Write_Str (" : ");
4496 Write_Id (Etype (C));
4497 Next_Entity (C);
4498 end loop;
4499 end;
4500
4501 Indent_End;
4502 Write_Indent_Str (" end record");
4503
4504 -- Class-Wide types
4505
4506 when E_Class_Wide_Subtype
4507 | E_Class_Wide_Type
4508 =>
4509 Write_Header (Ekind (Typ) = E_Class_Wide_Type);
4510 Write_Name_With_Col_Check (Chars (Etype (Typ)));
4511 Write_Str ("'Class");
4512
4513 -- Subprogram types
4514
4515 when E_Subprogram_Type =>
4516 Write_Header;
4517
4518 if Etype (Typ) = Standard_Void_Type then
4519 Write_Str ("procedure");
4520 else
4521 Write_Str ("function");
4522 end if;
4523
4524 if Present (First_Entity (Typ)) then
4525 Write_Str (" (");
4526
4527 declare
4528 Param : Entity_Id;
4529
4530 begin
4531 Param := First_Entity (Typ);
4532 loop
4533 Write_Id (Param);
4534 Write_Str (" : ");
4535
4536 if Ekind (Param) = E_In_Out_Parameter then
4537 Write_Str ("in out ");
4538 elsif Ekind (Param) = E_Out_Parameter then
4539 Write_Str ("out ");
4540 end if;
4541
4542 Write_Id (Etype (Param));
4543 Next_Entity (Param);
4544 exit when No (Param);
4545 Write_Str (", ");
4546 end loop;
4547
4548 if Present (Extra_Formals (Typ)) then
4549 Param := Extra_Formals (Typ);
4550
4551 while Present (Param) loop
4552 Write_Str (", ");
4553 Write_Id (Param);
4554 Write_Str (" : ");
4555 Write_Id (Etype (Param));
4556
4557 Param := Extra_Formal (Param);
4558 end loop;
4559 end if;
4560
4561 Write_Char (')');
4562 end;
4563
4564 elsif Present (Extra_Formals (Typ)) then
4565 declare
4566 Param : Entity_Id;
4567
4568 begin
4569 Write_Str (" (");
4570
4571 Param := Extra_Formals (Typ);
4572
4573 while Present (Param) loop
4574 Write_Id (Param);
4575 Write_Str (" : ");
4576 Write_Id (Etype (Param));
4577
4578 if Present (Extra_Formal (Param)) then
4579 Write_Str (", ");
4580 end if;
4581
4582 Param := Extra_Formal (Param);
4583 end loop;
4584
4585 Write_Char (')');
4586 end;
4587 end if;
4588
4589 if Etype (Typ) /= Standard_Void_Type then
4590 Write_Str (" return ");
4591 Write_Id (Etype (Typ));
4592 end if;
4593
4594 when E_String_Literal_Subtype =>
4595 declare
4596 L : constant Uint :=
4597 Expr_Value (String_Literal_Low_Bound (Typ));
4598 Len : constant Uint :=
4599 String_Literal_Length (Typ);
4600 begin
4601 Write_Header (False);
4602 Write_Str ("String (");
4603 Write_Int (UI_To_Int (L));
4604 Write_Str (" .. ");
4605 Write_Int (UI_To_Int (L + Len) - 1);
4606 Write_Str (");");
4607 end;
4608
4609 -- For all other Itypes, print a triple ? (fill in later
4610 -- if needed).
4611
4612 when others =>
4613 Write_Header (True);
4614 Write_Str ("???");
4615 end case;
4616 end if;
4617
4618 -- Add terminating bracket and restore output buffer
4619
4620 Write_Char (']');
4621 Write_Eol;
4622 Restore_Output_Buffer (S);
4623 end;
4624
4625 Set_Itype_Printed (Typ);
4626 end if;
4627 end Write_Itype;
4628
4629 -------------------------------
4630 -- Write_Name_With_Col_Check --
4631 -------------------------------
4632
4633 procedure Write_Name_With_Col_Check (N : Name_Id) is
4634 J : Natural;
4635 K : Natural;
4636 L : Natural;
4637
4638 begin
4639 -- Avoid crashing on invalid Name_Ids
4640
4641 if not Is_Valid_Name (N) then
4642 Write_Str ("<invalid name ");
4643 Write_Int (Int (N));
4644 Write_Str (">");
4645 return;
4646 end if;
4647
4648 Get_Name_String (N);
4649
4650 -- Deal with -gnatdI which replaces any sequence Cnnnb where C is an
4651 -- upper case letter, nnn is one or more digits and b is a lower case
4652 -- letter by C...b, so that listings do not depend on serial numbers.
4653
4654 if Debug_Flag_II then
4655 J := 1;
4656 while J < Name_Len - 1 loop
4657 if Name_Buffer (J) in 'A' .. 'Z'
4658 and then Name_Buffer (J + 1) in '0' .. '9'
4659 then
4660 K := J + 1;
4661 while K < Name_Len loop
4662 exit when Name_Buffer (K) not in '0' .. '9';
4663 K := K + 1;
4664 end loop;
4665
4666 if Name_Buffer (K) in 'a' .. 'z' then
4667 L := Name_Len - K + 1;
4668
4669 Name_Buffer (J + 4 .. J + L + 3) :=
4670 Name_Buffer (K .. Name_Len);
4671 Name_Buffer (J + 1 .. J + 3) := "...";
4672 Name_Len := J + L + 3;
4673 J := J + 5;
4674
4675 else
4676 J := K;
4677 end if;
4678
4679 else
4680 J := J + 1;
4681 end if;
4682 end loop;
4683 end if;
4684
4685 -- Fall through for normal case
4686
4687 Write_Str_With_Col_Check (Name_Buffer (1 .. Name_Len));
4688 end Write_Name_With_Col_Check;
4689
4690 ------------------------------------
4691 -- Write_Name_With_Col_Check_Sloc --
4692 ------------------------------------
4693
4694 procedure Write_Name_With_Col_Check_Sloc (N : Name_Id) is
4695 begin
4696 -- Avoid crashing on invalid Name_Ids
4697
4698 if not Is_Valid_Name (N) then
4699 Write_Str ("<invalid name ");
4700 Write_Int (Int (N));
4701 Write_Str (">");
4702 return;
4703 end if;
4704
4705 Get_Name_String (N);
4706 Write_Str_With_Col_Check_Sloc (Name_Buffer (1 .. Name_Len));
4707 end Write_Name_With_Col_Check_Sloc;
4708
4709 --------------------
4710 -- Write_Operator --
4711 --------------------
4712
4713 procedure Write_Operator (N : Node_Id; S : String) is
4714 F : Natural := S'First;
4715 T : Natural := S'Last;
4716
4717 begin
4718 -- If no overflow check, just write string out, and we are done
4719
4720 if not Do_Overflow_Check (N) then
4721 Write_Str_Sloc (S);
4722
4723 -- If overflow check, we want to surround the operator with curly
4724 -- brackets, but not include spaces within the brackets.
4725
4726 else
4727 if S (F) = ' ' then
4728 Write_Char (' ');
4729 F := F + 1;
4730 end if;
4731
4732 if S (T) = ' ' then
4733 T := T - 1;
4734 end if;
4735
4736 Write_Char ('{');
4737 Write_Str_Sloc (S (F .. T));
4738 Write_Char ('}');
4739
4740 if S (S'Last) = ' ' then
4741 Write_Char (' ');
4742 end if;
4743 end if;
4744 end Write_Operator;
4745
4746 -----------------------
4747 -- Write_Param_Specs --
4748 -----------------------
4749
4750 procedure Write_Param_Specs (N : Node_Id) is
4751 Specs : constant List_Id := Parameter_Specifications (N);
4752 Specs_Present : constant Boolean := Is_Non_Empty_List (Specs);
4753
4754 Ent : Entity_Id;
4755 Extras : Node_Id;
4756 Spec : Node_Id;
4757 Formal : Node_Id;
4758
4759 Output : Boolean := False;
4760 -- Set true if we output at least one parameter
4761
4762 begin
4763 -- Write out explicit specs from Parameter_Speficiations list
4764
4765 if Specs_Present then
4766 Write_Str_With_Col_Check (" (");
4767 Output := True;
4768
4769 Spec := First (Specs);
4770 loop
4771 Sprint_Node (Spec);
4772 Formal := Defining_Identifier (Spec);
4773 Next (Spec);
4774 exit when Spec = Empty;
4775
4776 -- Add semicolon, unless we are printing original tree and the
4777 -- next specification is part of a list (but not the first element
4778 -- of that list).
4779
4780 if not Dump_Original_Only or else not Prev_Ids (Spec) then
4781 Write_Str ("; ");
4782 end if;
4783 end loop;
4784 end if;
4785
4786 -- See if we have extra formals
4787
4788 if Nkind (N) in N_Function_Specification | N_Procedure_Specification then
4789 Ent := Defining_Entity (N);
4790
4791 -- Loop to write extra formals (if any)
4792
4793 if Present (Ent) and then Is_Subprogram (Ent) then
4794 Extras := Extra_Formals (Ent);
4795
4796 if Present (Extras) then
4797 if not Specs_Present then
4798 Write_Str_With_Col_Check (" (");
4799 Output := True;
4800 end if;
4801
4802 Formal := Extras;
4803 while Present (Formal) loop
4804 if Specs_Present or else Formal /= Extras then
4805 Write_Str ("; ");
4806 end if;
4807
4808 Write_Name_With_Col_Check (Chars (Formal));
4809 Write_Str (" : ");
4810 Write_Name_With_Col_Check (Chars (Etype (Formal)));
4811 Formal := Extra_Formal (Formal);
4812 end loop;
4813 end if;
4814 end if;
4815 end if;
4816
4817 if Output then
4818 Write_Char (')');
4819 end if;
4820 end Write_Param_Specs;
4821
4822 -----------------------
4823 -- Write_Rewrite_Str --
4824 -----------------------
4825
4826 procedure Write_Rewrite_Str (S : String) is
4827 begin
4828 if not Dump_Generated_Only then
4829 if S'Length = 3 and then S = ">>>" then
4830 Write_Str (">>>");
4831 else
4832 Write_Str_With_Col_Check (S);
4833 end if;
4834 end if;
4835 end Write_Rewrite_Str;
4836
4837 -----------------------
4838 -- Write_Source_Line --
4839 -----------------------
4840
4841 procedure Write_Source_Line (L : Physical_Line_Number) is
4842 Loc : Source_Ptr;
4843 Src : Source_Buffer_Ptr;
4844 Scn : Source_Ptr;
4845
4846 begin
4847 if Dump_Source_Text then
4848 Src := Source_Text (Current_Source_File);
4849 Loc := Line_Start (L, Current_Source_File);
4850 Write_Eol;
4851
4852 -- See if line is a comment line, if not, and if not line one,
4853 -- precede with blank line.
4854
4855 Scn := Loc;
4856 while Src (Scn) = ' ' or else Src (Scn) = ASCII.HT loop
4857 Scn := Scn + 1;
4858 end loop;
4859
4860 if (Src (Scn) in Line_Terminator
4861 or else Src (Scn .. Scn + 1) /= "--")
4862 and then L /= 1
4863 then
4864 Write_Eol;
4865 end if;
4866
4867 -- Now write the source text of the line
4868
4869 Write_Str ("-- ");
4870 Write_Int (Int (L));
4871 Write_Str (": ");
4872
4873 -- We need to check for EOF here, in case the last line of the source
4874 -- file does not have a Line_Terminator.
4875
4876 while Src (Loc) not in Line_Terminator | EOF loop
4877 Write_Char (Src (Loc));
4878 Loc := Loc + 1;
4879 end loop;
4880 end if;
4881 end Write_Source_Line;
4882
4883 ------------------------
4884 -- Write_Source_Lines --
4885 ------------------------
4886
4887 procedure Write_Source_Lines (L : Physical_Line_Number) is
4888 begin
4889 while Last_Line_Printed < L loop
4890 Last_Line_Printed := Last_Line_Printed + 1;
4891 Write_Source_Line (Last_Line_Printed);
4892 end loop;
4893 end Write_Source_Lines;
4894
4895 --------------------
4896 -- Write_Str_Sloc --
4897 --------------------
4898
4899 procedure Write_Str_Sloc (S : String) is
4900 begin
4901 for J in S'Range loop
4902 Write_Char_Sloc (S (J));
4903 end loop;
4904 end Write_Str_Sloc;
4905
4906 ------------------------------
4907 -- Write_Str_With_Col_Check --
4908 ------------------------------
4909
4910 procedure Write_Str_With_Col_Check (S : String) is
4911 begin
4912 if Int (S'Last) + Column > Sprint_Line_Limit then
4913 Write_Indent_Str (" ");
4914
4915 if S (S'First) = ' ' then
4916 Write_Str (S (S'First + 1 .. S'Last));
4917 else
4918 Write_Str (S);
4919 end if;
4920
4921 else
4922 Write_Str (S);
4923 end if;
4924 end Write_Str_With_Col_Check;
4925
4926 -----------------------------------
4927 -- Write_Str_With_Col_Check_Sloc --
4928 -----------------------------------
4929
4930 procedure Write_Str_With_Col_Check_Sloc (S : String) is
4931 begin
4932 if Int (S'Last) + Column > Sprint_Line_Limit then
4933 Write_Indent_Str (" ");
4934
4935 if S (S'First) = ' ' then
4936 Write_Str_Sloc (S (S'First + 1 .. S'Last));
4937 else
4938 Write_Str_Sloc (S);
4939 end if;
4940
4941 else
4942 Write_Str_Sloc (S);
4943 end if;
4944 end Write_Str_With_Col_Check_Sloc;
4945
4946 ---------------------------
4947 -- Write_Subprogram_Name --
4948 ---------------------------
4949
4950 procedure Write_Subprogram_Name (N : Node_Id) is
4951 begin
4952 if not Comes_From_Source (N)
4953 and then Is_Entity_Name (N)
4954 then
4955 declare
4956 Ent : constant Entity_Id := Entity (N);
4957 begin
4958 if not In_Extended_Main_Source_Unit (Ent)
4959 and then In_Predefined_Unit (Ent)
4960 then
4961 -- Run-time routine name, output name with a preceding dollar
4962 -- making sure that we do not get a line split between them.
4963
4964 Col_Check (Length_Of_Name (Chars (Ent)) + 1);
4965 Write_Char ('$');
4966 Write_Name (Chars (Ent));
4967 return;
4968 end if;
4969 end;
4970 end if;
4971
4972 -- Normal case, not a run-time routine name
4973
4974 Sprint_Node (N);
4975 end Write_Subprogram_Name;
4976
4977 -------------------------------
4978 -- Write_Uint_With_Col_Check --
4979 -------------------------------
4980
4981 procedure Write_Uint_With_Col_Check (U : Uint; Format : UI_Format) is
4982 begin
4983 Col_Check (UI_Decimal_Digits_Hi (U));
4984 UI_Write (U, Format);
4985 end Write_Uint_With_Col_Check;
4986
4987 ------------------------------------
4988 -- Write_Uint_With_Col_Check_Sloc --
4989 ------------------------------------
4990
4991 procedure Write_Uint_With_Col_Check_Sloc (U : Uint; Format : UI_Format) is
4992 begin
4993 Col_Check (UI_Decimal_Digits_Hi (U));
4994 Set_Debug_Sloc;
4995 UI_Write (U, Format);
4996 end Write_Uint_With_Col_Check_Sloc;
4997
4998 -------------------------------------
4999 -- Write_Ureal_With_Col_Check_Sloc --
5000 -------------------------------------
5001
5002 procedure Write_Ureal_With_Col_Check_Sloc (U : Ureal) is
5003 D : constant Uint := Denominator (U);
5004 N : constant Uint := Numerator (U);
5005 begin
5006 Col_Check (UI_Decimal_Digits_Hi (D) + UI_Decimal_Digits_Hi (N) + 4);
5007 Set_Debug_Sloc;
5008 UR_Write (U, Brackets => True);
5009 end Write_Ureal_With_Col_Check_Sloc;
5010
5011 end Sprint;