[m-dev.] diff: begin using functionality from error_util in typecheck.m

Robert Ernst Johann JESCHOFNIK rejj at students.cs.mu.oz.au
Thu Feb 10 17:15:19 AEDT 2000


Hi.

This stuff was previously reviewed, but I didn't get around to commiting
it yet since it is only a start - I still have to go through and fix up
the rest of the error messages as well.

However, I'm going to commit this much now, so that it is out of the way
and won't show up with my next change to typecheck.



here's the diff again, just to remind you.

Rob

Index: typecheck.m
===================================================================
RCS file: /home/mercury1/repository//mercury/compiler/typecheck.m,v
retrieving revision 1.269
diff -u -r1.269 typecheck.m
--- typecheck.m	2000/01/13 06:17:14	1.269
+++ typecheck.m	2000/01/27 03:09:45
@@ -4500,10 +4500,14 @@
 
 report_error_no_clauses(PredId, PredInfo, ModuleInfo) -->
 	{ pred_info_context(PredInfo, Context) },
-	prog_out__write_context(Context),
-	io__write_string("Error: no clauses for "),
-	hlds_out__write_pred_id(ModuleInfo, PredId),
-	io__write_string(".\n").
+	{ error_util__describe_one_pred_name(ModuleInfo, PredId, PredName) },
+	{ ErrorMsg0 = [ "Error: no clauses for ", PredName, "." ] },
+	{ error_util__list_to_pieces(ErrorMsg0, ErrorMsg) },
+	error_util__write_error_pieces(Context, 0, ErrorMsg).
+	% prog_out__write_context(Context),
+	% io__write_string("Error: no clauses for "),
+	% hlds_out__write_pred_id(ModuleInfo, PredId),
+	% io__write_string(".\n").
 
 %-----------------------------------------------------------------------------%
 
@@ -4514,22 +4518,33 @@
 
 report_warning_too_much_overloading(TypeCheckInfo) -->
 	{ typecheck_info_get_context(TypeCheckInfo, Context) },
-	write_context_and_pred_id(TypeCheckInfo),
-	prog_out__write_context(Context),
-	report_warning("  warning: highly ambiguous overloading.\n"),
+	{ make_pred_id_preamble(TypeCheckInfo, Preamble) },
+	%write_context_and_pred_id(TypeCheckInfo),
+	%prog_out__write_context(Context),
+	%report_warning("  warning: highly ambiguous overloading.\n"),
+	{ SmallWarning = [ Preamble,
+				"warning: highly ambiguous overloading." ] },
 	globals__io_lookup_bool_option(verbose_errors, VerboseErrors),
 	( { VerboseErrors = yes } ->
-		prog_out__write_context(Context),
-		io__write_string(
-		    "  This may cause type-checking to be very slow.\n"
-		),
-		prog_out__write_context(Context),
-		io__write_string(
-		    "  It may also make your code difficult to understand.\n"
-		)
-	;
-		[]
-	).
+		%prog_out__write_context(Context),
+		%io__write_string(
+		%    "  This may cause type-checking to be very slow.\n"
+		%),
+		%prog_out__write_context(Context),
+		%io__write_string(
+		%    "  It may also make your code difficult to understand.\n"
+		%)
+		{ VerboseWarning = [ "This may cause type-checking to be very",
+					"slow. It may also make your code",
+					"difficult to understand." ] },
+		{ list__append(SmallWarning, VerboseWarning, Warning0) }
+	;
+		%[]
+		{ Warning0 = SmallWarning }
+	%).
+	),
+	{ error_util__list_to_pieces(Warning0, Warning) },
+	error_util__report_warning(Context, 0, Warning).
 
 %-----------------------------------------------------------------------------%
 
@@ -5728,6 +5743,25 @@
 	hlds_out__write_pred_id(ModuleInfo, PredId),
 	io__write_string(":\n").
 
+	% This is intended to superceed the above predicate - It performs the
+	% same action, but instead of just writing to the output straight away
+	% the resultant string is passed back to the caller to deal with.
+	% This allows `nicer' handling of error messages, since this string
+	% can be used by the predicates in error_util.m
+	%
+	% The string generated by this predicate is of the form:
+	%   "In clause for module:pred/N :"
+:- pred make_pred_id_preamble(typecheck_info, string).
+:- mode make_pred_id_preamble(typecheck_info_no_io, out) is det.
+
+make_pred_id_preamble(TypeCheckInfo, Preamble) :-
+	typecheck_info_get_module_info(TypeCheckInfo, Module),
+	typecheck_info_get_predid(TypeCheckInfo, PredID),
+	error_util__describe_one_pred_name(Module, PredID, PredName),
+	Words = "In clause for ",
+	Colon = ":",
+	string__append(Words, PredName, Preamble0),
+	string__append(Preamble0, Colon, Preamble).
 %-----------------------------------------------------------------------------%
 
 :- pred report_ambiguity_error(typecheck_info, type_assign, type_assign,


--------------------------------------------------------------------------
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