[m-dev.] for review: add predicate for reporting warnings to error_util.m

Robert Ernst Johann JESCHOFNIK rejj at cat.cs.mu.OZ.AU
Thu Dec 9 00:14:24 AEDT 1999


Estimated hours taken: 0.2

compiler/error_util.m:
  - Add comments in the interface section for write_error_pieces, and 
    list_to_pieces, briefly explaining what they do.
  - Add a new predicate, report_warning, to handle warning messages. If the
    --halt-at-warn flag is set, the exit status is set to error.

Index: compiler/error_util.m
===================================================================
RCS file: /home/mercury1/repository//mercury/compiler/error_util.m,v
retrieving revision 1.11
diff -u -r1.11 error_util.m
--- error_util.m	1999/11/12 09:08:14	1.11
+++ error_util.m	1999/12/08 13:12:26
@@ -52,13 +52,21 @@
 				% output since the last line break.
 	.
 		
-
+	% Convert a list of strings into a list of format_components,
+	% suitable for displaying as an error message.
 :- pred error_util__list_to_pieces(list(string)::in,
 		list(format_component)::out) is det.
 
+	% Display the given error message.
 :- pred write_error_pieces(prog_context::in, int::in,
 	list(format_component)::in, io__state::di, io__state::uo) is det.
 
+	% Report a warning, and set the exit status to error if the
+	% --halt-at-warn option is set. This predicate does the same this as
+	% prog_io__report_warning, except that it does a nicer job of
+	% displaying the warning message.
+:- pred report_warning(prog_context::in, int::in, list(format_component)::in,
+	io__state::di, io__state::uo) is det.
 
 	% Predicates to convert a predicate names to strings.
 
@@ -90,7 +98,7 @@
 
 :- implementation.
 
-:- import_module prog_out.
+:- import_module prog_out, globals, options.
 :- import_module bool, io, list, term, char, string, int.
 
 error_util__list_to_pieces([], []).
@@ -101,6 +109,15 @@
 	string__append(Elem1, ",", Piece1),
 	error_util__list_to_pieces([Elem2, Elem3 | Elems], Pieces1),
 	Pieces = [fixed(Piece1) | Pieces1].
+
+report_warning(Context, Indent, Components) -->
+	globals__io_lookup_bool_option(halt_at_warn, HaltAtWarn),
+	( { HaltAtWarn = yes } ->
+		io__set_exit_status(1)
+	;
+		[]
+	),
+	write_error_pieces(Context, Indent, Components).
 
 write_error_pieces(Context, Indent, Components) -->
 	{


--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list