1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 -- This package contains low level output routines used by the compiler
35 -- for writing error messages and informational output. It is also used
36 -- by the debug source file output routines (see Sprintf.Print_Eol).
38 with Hostparm
; use Hostparm
;
39 with Types
; use Types
;
42 pragma Elaborate_Body
;
44 type Output_Proc
is access procedure (S
: String);
45 -- This type is used for the Set_Special_Output procedure. If this
46 -- procedure is called, then instead of lines being written to
47 -- standard error or standard output, a call is made to the given
48 -- procedure for each line, passing the line with an end of line
49 -- character (which is a single ASCII.LF character, even in systems
50 -- which normally use CR/LF or some other sequence for line end).
56 procedure Set_Special_Output
(P
: Output_Proc
);
57 -- Sets subsequent output to call procedure P. If P is null, then
58 -- the call cancels the effect of a previous call, reverting the
59 -- output to standard error or standard output depending on the
60 -- mode at the time of previous call. Any exception generated by
61 -- by calls to P is simply propagated to the caller of the routine
62 -- causing the write operation.
64 procedure Cancel_Special_Output
;
65 -- Cancels the effect of a call to Set_Special_Output, if any.
66 -- The output is then directed to standard error or standard output
67 -- depending on the last call to Set_Standard_Error or Set_Standard_Output.
68 -- It is never an error to call Cancel_Special_Output. It has the same
69 -- effect as calling Set_Special_Output (null).
71 procedure Set_Standard_Error
;
72 -- Sets subsequent output to appear on the standard error file (whatever
73 -- that might mean for the host operating system, if anything) when
74 -- no special output is in effect. When a special output is in effect,
75 -- the output will appear on standard error only after special output
76 -- has been cancelled.
78 procedure Set_Standard_Output
;
79 -- Sets subsequent output to appear on the standard output file (whatever
80 -- that might mean for the host operating system, if anything) when
81 -- no special output is in effect. When a special output is in effect,
82 -- the output will appear on standard output only after special output
83 -- has been cancelled. Output to standard output is the default mode
84 -- before any call to either of the Set procedures.
86 procedure Write_Char
(C
: Character);
87 -- Write one character to the standard output file. Note that the
88 -- character should not be LF or CR (use Write_Eol for end of line)
90 procedure Write_Erase_Char
(C
: Character);
91 -- If last character in buffer matches C, erase it, otherwise no effect
94 -- Write an end of line (whatever is required by the system in use,
95 -- e.g. CR/LF for DOS, or LF for Unix) to the standard output file.
96 -- This routine also empties the line buffer, actually writing it
97 -- to the file. Note that Write_Eol is the only routine that causes
98 -- any actual output to be written. Trailing spaces are removed.
100 procedure Write_Eol_Keep_Blanks
;
101 -- Similar as Write_Eol, except that trailing spaces are not removed
103 procedure Write_Int
(Val
: Int
);
104 -- Write an integer value with no leading blanks or zeroes. Negative
105 -- values are preceded by a minus sign).
107 procedure Write_Spaces
(N
: Nat
);
110 procedure Write_Str
(S
: String);
111 -- Write a string of characters to the standard output file. Note that
112 -- end of line is normally handled separately using WRITE_EOL, but it
113 -- is allowed for the string to contain LF (but not CR) characters,
114 -- which are properly interpreted as end of line characters. The string
115 -- may also contain horizontal tab characters.
117 procedure Write_Line
(S
: String);
118 -- Equivalent to Write_Str (S) followed by Write_Eol;
120 function Column
return Pos
;
121 pragma Inline
(Column
);
122 -- Returns the number of the column about to be written (e.g. a value
123 -- of 1 means the current line is empty).
125 -------------------------
126 -- Buffer Save/Restore --
127 -------------------------
129 -- This facility allows the current line buffer to be saved and restored
131 type Saved_Output_Buffer
is private;
132 -- Type used for Save/Restore_Buffer
134 Buffer_Max
: constant := Hostparm
.Max_Line_Length
;
135 -- Maximal size of a buffered output line
137 function Save_Output_Buffer
return Saved_Output_Buffer
;
138 -- Save current line buffer and reset line buffer to empty
140 procedure Restore_Output_Buffer
(S
: Saved_Output_Buffer
);
141 -- Restore previously saved output buffer. The value in S is not affected
142 -- so it is legtimate to restore a buffer more than once.
144 --------------------------
145 -- Debugging Procedures --
146 --------------------------
148 -- The following procedures are intended only for debugging purposes,
149 -- for temporary insertion into the text in environments where a debugger
150 -- is not available. They all have non-standard very short lower case
151 -- names, precisely to make sure that they are only used for debugging!
153 procedure w
(C
: Character);
154 -- Dump quote, character, quote, followed by line return
156 procedure w
(S
: String);
157 -- Dump string followed by line return
159 procedure w
(V
: Int
);
160 -- Dump integer followed by line return
162 procedure w
(B
: Boolean);
163 -- Dump Boolean followed by line return
165 procedure w
(L
: String; C
: Character);
166 -- Dump contents of string followed by blank, quote, character, quote
168 procedure w
(L
: String; S
: String);
169 -- Dump two strings separated by blanks, followed by line return
171 procedure w
(L
: String; V
: Int
);
172 -- Dump contents of string followed by blank, integer, line return
174 procedure w
(L
: String; B
: Boolean);
175 -- Dump contents of string followed by blank, Boolean, line return
178 -- Note: the following buffer and column position are maintained by the
179 -- subprograms defined in this package, and cannot be directly modified or
180 -- accessed by a client.
182 Buffer
: String (1 .. Buffer_Max
+ 1);
183 for Buffer
'Alignment use 4;
184 -- Buffer used to build output line. We do line buffering because it
185 -- is needed for the support of the debug-generated-code option (-gnatD).
186 -- Historically it was first added because on VMS, line buffering is
187 -- needed with certain file formats. So in any case line buffering must
188 -- be retained for this purpose, even if other reasons disappear. Note
189 -- any attempt to write more output to a line than can fit in the buffer
190 -- will be silently ignored. The alignment clause improves the efficiency
191 -- of the save/restore procedures.
193 Next_Col
: Positive range 1 .. Buffer
'Length + 1 := 1;
194 -- Column about to be written
196 type Saved_Output_Buffer
is record
197 Buffer
: String (1 .. Buffer_Max
+ 1);