[m-rev.] for review: browser parameters

Zoltan Somogyi zs at cs.mu.OZ.AU
Mon Apr 15 12:31:25 AEST 2002


For review by Mark.

Make the commands that update the browser parameters within the browser itself
affect the parameter settings only for the current browser caller type (print,
print all, or browse).

browser/browse_info.m:
	Add the current call type to the browser state.

	Add a more convenient mechanism for setting the parameters only for a
	specified caller type.

	Make some existing code look nicer.

browser/browse.m:
	When setting parameters, set them only for the current caller type.

Zoltan.

cvs diff: Diffing .
Index: browse.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/browse.m,v
retrieving revision 1.27
diff -u -b -r1.27 browse.m
--- browse.m	24 Feb 2002 11:53:21 -0000	1.27
+++ browse.m	5 Apr 2002 04:27:23 -0000
@@ -198,7 +198,7 @@
 	is cc_multi.
 
 browse__print_common(BrowserTerm, OutputStream, Caller, MaybeFormat, State) -->
-	{ Info = browser_info__init(BrowserTerm, MaybeFormat, State) },
+	{ Info = browser_info__init(BrowserTerm, Caller, MaybeFormat, State) },
 	io__set_output_stream(OutputStream, OldStream),
 	{ browser_info__get_format(Info, Caller, MaybeFormat, Format) },
 	%
@@ -257,7 +257,7 @@
 
 browse_common(Debugger, Object, InputStream, OutputStream, MaybeFormat,
 		MaybeMark, State0, State) -->
-	{ Info0 = browser_info__init(Object, MaybeFormat, State0) },
+	{ Info0 = browser_info__init(Object, browse, MaybeFormat, State0) },
 	io__set_input_stream(InputStream, OldInputStream),
 	io__set_output_stream(OutputStream, OldOutputStream),
 	% startup_message,
@@ -350,7 +350,8 @@
 		{ Quit = no },
 		{ Info = Info0 }
 	; { Command = set(Setting) },
-		{ set_browse_param(Setting, Info0, Info) },
+		{ set_browse_param(Info0 ^ caller_type, Setting,
+			Info0, Info) },
 		{ Quit = no }
 	; { Command = ls },
 		portray(Debugger, browse, no, Info0),
@@ -416,15 +417,15 @@
 		{ true }
 	).
 
-:- pred set_browse_param(setting, browser_info, browser_info).
-:- mode set_browse_param(in, in, out) is det.
+:- pred set_browse_param(browse_caller_type::in, setting::in,
+	browser_info::in, browser_info::out) is det.
 
-set_browse_param(Setting, Info0, Info) :-
+set_browse_param(CallerType, Setting, Info0, Info) :-
 	%
 	% XXX We can't yet give options to the `set' command.
 	%
 	No = bool__no,
-	browser_info__set_param(No, No, No, No, No, No, No, Setting, 
+	browser_info__set_param(yes(CallerType), No, No, No, No, Setting, 
 			Info0 ^ state, NewState),
 	Info = Info0 ^ state := NewState.
 
Index: browser_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/browser_info.m,v
retrieving revision 1.8
diff -u -b -r1.8 browser_info.m
--- browser_info.m	24 Feb 2002 11:53:21 -0000	1.8
+++ browser_info.m	5 Apr 2002 04:26:11 -0000
@@ -42,6 +42,8 @@
 					% The list of directories to take,
 					% starting from the root, to reach
 					% the current subterm.
+			caller_type	:: browse_caller_type,
+					% What command caller the browser?
 			format		:: maybe(portray_format),
 					% Format specified as an option to the
 					% mdb command.
@@ -100,8 +102,8 @@
 	% Initialise a new browser_info.  The optional portray_format
 	% overrides the default format.
 	%
-:- func browser_info__init(browser_term, maybe(portray_format),
-	browser_persistent_state) = browser_info.
+:- func browser_info__init(browser_term, browse_caller_type,
+	maybe(portray_format), browser_persistent_state) = browser_info.
 
 	% Get the format to use for the given caller type.  The optional
 	% portray_format overrides the current default.
@@ -129,14 +131,22 @@
 :- pred browser_info__init_persistent_state(browser_persistent_state).
 :- mode browser_info__init_persistent_state(out) is det.
 
-	% Update a setting in the browser state.  The first six arguments
-	% indicate the presence of the `set' options -P, -B, -A, -f, -p,
-	% and -v, in that order.
+	% Update a setting in the browser state.  The first seven arguments
+	% indicate the presence of the `set' options -P, -B, -A, -f, -r, -v
+	% and -p, in that order.
 	%
 :- pred browser_info__set_param(bool::in, bool::in, bool::in, bool::in,
 		bool::in, bool::in, bool::in, setting::in, 
-		browser_persistent_state::in, browser_persistent_state::out) 
-		is det.
+	browser_persistent_state::in, browser_persistent_state::out) is det.
+
+	% Update a setting in the browser state.  The first argument
+	% indicates the presence of at most one of the options -P, -B, -A,
+	% while the next four indicate the presence of -f, -r, -v and -p,
+	% in that order.
+	%
+:- pred browser_info__set_param(maybe(browse_caller_type)::in, bool::in,
+	bool::in, bool::in, bool::in, setting::in, 
+	browser_persistent_state::in, browser_persistent_state::out) is det.
 
 %---------------------------------------------------------------------------%
 
@@ -233,8 +243,8 @@
 
 %---------------------------------------------------------------------------%
 
-browser_info__init(BrowserTerm, MaybeFormat, State) =
-	browser_info(BrowserTerm, [], MaybeFormat, State, no).
+browser_info__init(BrowserTerm, CallerType, MaybeFormat, State) =
+	browser_info(BrowserTerm, [], CallerType, MaybeFormat, State, no).
 
 browser_info__get_format(Info, Caller, MaybeFormat, Format) :-
 	(
@@ -292,10 +302,10 @@
 	%		term will be shown.
 	%
 browser_info__init_persistent_state(State) :-
-	State = browser_persistent_state(Print, Browse, PrintAll),
 	caller_type_print_defaults(Print),
 	caller_type_browse_defaults(Browse),
-	caller_type_print_all_defaults(PrintAll).
+	caller_type_print_all_defaults(PrintAll),
+	State = browser_persistent_state(Print, Browse, PrintAll).
 
 :- pred caller_type_print_defaults(caller_params).
 :- mode caller_type_print_defaults(out) is det.
@@ -330,17 +340,36 @@
 	Pretty = format_params(3, 10, 80, 2),
 	Params = caller_params(DefaultFormat, Flat, RawPretty, Verbose, Pretty).
 
-browser_info__set_param(P0, B0, A0, F0, Pr0, V0, NPr0, Setting, State0, State):-
+browser_info__set_param(MaybeCallerType, F0, Pr0, V0, NPr0, Setting, State0,
+		State) :-
+	affected_caller_types(MaybeCallerType, P, B, A),
+	browser_info__set_param(P, B, A, F0, Pr0, V0, NPr0, Setting, State0,
+		State).
+
+browser_info__set_param(P0, B0, A0, F0, Pr0, V0, NPr0, Setting, State0,
+		State) :-
 	default_all_yes(P0, B0, A0, P, B, A),
 	default_all_yes(F0, Pr0, V0, NPr0, F, Pr, V, NPr),
-	maybe_set_param(P, F, Pr, V, NPr, Setting, State0 ^ print_params, 
-			PParams),
-	maybe_set_param(B, F, Pr, V, NPr, Setting, State0 ^ browse_params, 
-			BParams),
-	maybe_set_param(A, F, Pr, V, NPr, Setting, State0 ^ print_all_params,
-			AParams),
+	PParams0 = State0 ^ print_params,
+	BParams0 = State0 ^ browse_params,
+	AParams0 = State0 ^ print_all_params,
+	maybe_set_param(P, F, Pr, V, NPr, Setting, PParams0, PParams),
+	maybe_set_param(B, F, Pr, V, NPr, Setting, BParams0, BParams),
+	maybe_set_param(A, F, Pr, V, NPr, Setting, AParams0, AParams),
 	State = browser_persistent_state(PParams, BParams, AParams).
 
+:- pred affected_caller_types(maybe(browse_caller_type)::in,
+	bool::out, bool::out, bool::out) is det.
+
+	%
+	% If no caller type is specified, the command by default
+	% applies to _all_ caller types.
+	%
+affected_caller_types(no,             yes, yes, yes).
+affected_caller_types(yes(print),     yes, no, no).
+affected_caller_types(yes(browse),    no, yes, no).
+affected_caller_types(yes(print_all), no, no, yes).
+
 :- pred default_all_yes(bool, bool, bool, bool, bool, bool).
 :- mode default_all_yes(in, in, in, out, out, out) is det.
 
@@ -368,8 +397,8 @@
 
 default_all_yes(A0, B0, C0, D0, A, B, C, D) :-
 	%
-	% If none of the flags are set, the command by default
-	% applies to _all_ caller types/formats.
+	% If none of the format flags are set, the command by default
+	% applies to _all_ formats.
 	%
 	(
 		A0 = no,
@@ -399,15 +428,17 @@
 	->
 		Params = Params0 ^ default_format := NewFormat
 	;
-		maybe_set_param_2(F, Setting, Params0 ^ flat_params, FParams),
-		maybe_set_param_2(Pr, Setting, Params0 ^ raw_pretty_params,
-				PrParams),
-		maybe_set_param_2(V, Setting, Params0 ^ verbose_params,
-				VParams),
-		maybe_set_param_2(NPr, Setting, Params0 ^ pretty_params,
-				NPrParams),
-		Params = caller_params(Params0 ^ default_format, FParams,
-				PrParams, VParams, NPrParams)
+		Format0 = Params0 ^ default_format,
+		FParams0 = Params0 ^ flat_params,
+		PrParams0 = Params0 ^ raw_pretty_params,
+		VParams0 = Params0 ^ verbose_params,
+		NPrParams0 = Params0 ^ pretty_params,
+		maybe_set_param_2(F, Setting, FParams0, FParams),
+		maybe_set_param_2(Pr, Setting, PrParams0, PrParams),
+		maybe_set_param_2(V, Setting, VParams0, VParams),
+		maybe_set_param_2(NPr, Setting, NPrParams0, NPrParams),
+		Params = caller_params(Format0,
+			FParams, PrParams, VParams, NPrParams)
 	).
 
 :- pred maybe_set_param_2(bool, setting, format_params, format_params).
--------------------------------------------------------------------------
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