[m-dev.] for review: update error messages in typecheck.m to use stuff from error_util.m

Robert Ernst Johann JESCHOFNIK rejj at cat.cs.mu.OZ.AU
Wed Dec 22 12:56:56 AEDT 1999


Hi.

This isn't really for review - more like a pre-review. This is something I
started a week or two ago, and is (obviously) as yet nowhere near
complete. After looking through the code in typecheck.m, I have found that
it will be very hard to change the error messages in this way in some
places..

Anyway, here is the start I have made. If anyone thinks it is a worthwhile
venture, I'll continue it.

rob
--

typecheck.m:
        Begin changing the generation of error messages to use the
        functionality provided by error_util.m

Index: typecheck.m
===================================================================
RCS file: /home/mercury1/repository//mercury/compiler/typecheck.m,v
retrieving revision 1.268
diff -u -r1.268 typecheck.m
--- typecheck.m	1999/12/08 09:44:56	1.268
+++ typecheck.m	1999/12/22 01:51:01
@@ -4129,10 +4129,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").
 
 %-----------------------------------------------------------------------------%
 
@@ -4143,22 +4147,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).
 
 %-----------------------------------------------------------------------------%
 
@@ -5333,6 +5348,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