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