for review: line numbers for output streams
Fergus Henderson
fjh at cs.mu.oz.au
Wed Apr 9 22:31:05 AEST 1997
This change was requested by Peter Szeredi and is also needed for
us to output proper #line directives in the generated C code.
Tom, can you please review this one?
library/io.m:
Add predicates io__output_line_number/{3,4}
and io__set_output_line_number/{3,4}.
Previously we only supported line numbers for input streams.
Most of the functionality for this was already implemented --
we already computed the line numbers for output streams, there
was just no way to access them.
Index: io.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/io.m,v
retrieving revision 1.114
diff -u -r1.114 io.m
--- io.m 1997/02/24 01:41:22 1.114
+++ io.m 1997/04/09 12:14:42
@@ -413,6 +413,29 @@
% For stdout this is the string "<standard output>".
% For stderr this is the string "<standard error>".
+:- pred io__get_output_line_number(int, io__state, io__state).
+:- mode io__get_output_line_number(out, di, uo) is det.
+% Return the line number of the current output stream.
+% Lines are normally numbered starting at 1
+% (but this can be overridden by calling io__set_output_line_number).
+
+:- pred io__get_output_line_number(io__output_stream, int,
+ io__state, io__state).
+:- mode io__get_output_line_number(in, out, di, uo) is det.
+% Return the line number of the specified output stream.
+% Lines are normally numbered starting at 1
+% (but this can be overridden by calling io__set_output_line_number).
+
+:- pred io__set_output_line_number(int, io__state, io__state).
+:- mode io__set_output_line_number(in, di, uo) is det.
+% Set the line number of the current output stream.
+
+:- pred io__set_output_line_number(io__output_stream, int,
+ io__state, io__state).
+:- mode io__set_output_line_number(in, in, di, uo) is det.
+% Set the line number of the specified output stream.
+
+
%-----------------------------------------------------------------------------%
% Binary input predicates.
@@ -1851,6 +1874,32 @@
:- pragma(c_code,
io__set_line_number(Stream::in, LineNum::in, IO0::di, IO::uo),
+"{
+ MercuryFile *stream = (MercuryFile *) Stream;
+ stream->line_number = LineNum;
+ update_io(IO0, IO);
+}").
+
+:- pragma(c_code, io__get_output_line_number(LineNum::out, IO0::di, IO::uo), "
+ LineNum = mercury_current_text_output->line_number;
+ update_io(IO0, IO);
+").
+
+:- pragma(c_code,
+ io__get_output_line_number(Stream::in, LineNum::out, IO0::di, IO::uo),
+"{
+ MercuryFile *stream = (MercuryFile *) Stream;
+ LineNum = stream->line_number;
+ update_io(IO0, IO);
+}").
+
+:- pragma(c_code, io__set_output_line_number(LineNum::in, IO0::di, IO::uo), "
+ mercury_current_text_output->line_number = LineNum;
+ update_io(IO0, IO);
+").
+
+:- pragma(c_code,
+ io__set_output_line_number(Stream::in, LineNum::in, IO0::di, IO::uo),
"{
MercuryFile *stream = (MercuryFile *) Stream;
stream->line_number = LineNum;
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the developers
mailing list