[m-rev.] for review: debugging tabling procedures
Fergus Henderson
fjh at cs.mu.OZ.AU
Tue Nov 12 05:02:47 AEDT 2002
On 08-Nov-2002, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> @@ -3417,6 +3506,666 @@
> }
>
> static MR_Next
> +MR_trace_cmd_table(char **words, int word_count,
> + MR_Trace_Cmd_Info *cmd, MR_Event_Info *event_info,
> + MR_Event_Details *event_details, MR_Code **jumpaddr)
> +{
...
> + MR_register_all_modules_and_procs(MR_mdb_out, MR_TRUE);
> + matches = MR_search_for_matching_procedures(&spec);
> + if (matches.match_proc_next == 0) {
> + fflush(MR_mdb_out);
> + fprintf(MR_mdb_err,
> + "mdb: there is no such procedure.\n");
> + return KEEP_INTERACTING;
> + } else if (matches.match_proc_next == 1) {
> + proc = matches.match_procs[0];
> + } else {
> + char buf[100];
> + char *line2;
> +
> + fflush(MR_mdb_out);
> + fprintf(MR_mdb_err, "Ambiguous procedure specification. "
> + "The matches are:\n");
> + for (i = 0; i < matches.match_proc_next; i++)
> + {
> + fprintf(MR_mdb_out, "%d: ", i);
> + MR_print_proc_id_and_nl(MR_mdb_out,
> + matches.match_procs[i]);
> + }
> +
> + sprintf(buf, "\nWhich procedure's table do you want to print "
> + "(0-%d)? ",
> + matches.match_proc_next - 1);
> + line2 = MR_trace_getline(buf, MR_mdb_in, MR_mdb_out);
> + n = -1;
> + if (line2 == NULL || !MR_trace_is_natural_number(line2, &n)) {
> + n = -1;
> + fprintf(MR_mdb_out, "none of them\n");
> + } else if (n < 0 || n >= matches.match_proc_next) {
> + n = -1;
> + fprintf(MR_mdb_out, "invalid choice\n");
> + }
> +
> + if (line2 != NULL) {
> + MR_free(line2);
> + }
> +
> + if (n >= 0) {
> + proc = matches.match_procs[n];
> + } else {
> + return KEEP_INTERACTING;
> + }
> + }
It would be nicer to abstract that part out into a separate subroutine, IMHO.
It does a single, easily describable thing -- select a single matching
procedure -- and the coupling between the part and the rest of the routine
is quite minor.
MR_Proc_Entry *
MR_select_matching_procedure(const MR_Proc_Spec *spec,
const char *ambiguity_question)
{
...
}
static MR_Next
MR_trace_cmd_table(...)
{
proc = MR_select_matching_procedure(&spec,
"Which procedure's table do you want to print");
if (proc == NULL) {
return KEEP_INTERACTING;
}
...
}
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list