[m-dev.] for review: Added a new format "newpretty" to the browser.

Mark Anthony BROWN dougl at cs.mu.OZ.AU
Thu Feb 8 17:17:51 AEDT 2001


Hi,

This looks great.

There's one more issue I thought of, but forgot to mention earlier -- you
will probably need to update the test cases, if you haven't done so already.
To do this:

	- Use CVS to check out the `tests' module.  You should do this
	  either in the `mercury' directory that you have already
	  checked out, or in the parent of this directory.
	
	- Run the bootcheck script in tools/bootcheck.  This will run
	  the tests if they have been checked out.

	- Look in the tests/debugger directory to see if the output of
	  the browser test cases matches the expected output.

	- If they don't match, but the output is as it should be, then
	  update the *.exp (and maybe *.exp2) files to reflect the new
	  output.  Changes to these files should be committed at the same
	  time as the rest of the changes.

Cheers,
Mark.

Sarvamanan THURAIRATNAM writes:
> 
> Estimated hours taken : 180 
> 
> For Mark Brown to Review. 
> 
> Added a new pretty printing format to the term browser. This new format
> helps put a limit on the size of the term printed during debugging.
> This limit is specified by setting the number of lines you want the term to be
> printed on and the width of these lines. Refer to sized_pretty.m for 
> Examples.
> 
> browser/sized_pretty.m: 
> 	New file that does what's described above. 
> 
> browser/browse.m: 
> browser/browser_info.m: 
> browser/parse.m: 
> trace/mercury_trace_browse.c: 
> trace/mercury_trace_browse.h: 
> trace/mercury_trace_internal.c: 
> 	Modified to accommodate the new format. 
> 
> This is a relative diff between the newest version of the code and the 
> previous version I posted:
> 
> --- /home/stude/s/sthur/OldFiles/browser_info.m	Tue Feb  6 12:07:22 2001
> +++ /home/stude/s/sthur/Review/mercury/browser/browser_info.m	Tue Feb  6 12:14:44 2001
> @@ -1,5 +1,5 @@
>  %---------------------------------------------------------------------------%
> -% Copyright (C) 2001 The University of Melbourne.
> +% Copyright (C) 2000-2001 The University of Melbourne.
>  % This file may only be copied under the terms of the GNU Library General
>  % Public License - see the file COPYING.LIB in the Mercury distribution.
>  %---------------------------------------------------------------------------%
> @@ -55,10 +55,11 @@
>  :- type portray_format
>  	--->	flat
>  	;	raw_pretty	% calls pprint module directly, without first 
> -				% attempting to manipulate the term in any way
> +				% attempting to manipulate the term in any way.
>  	;	verbose
> -	;	pretty.		% allows user to specify the no of lines in
> -				% which the term has to be printed
> +	;	pretty.		% It allows the user to specify the maximum 
> +				% number of lines which the term has to be 
> +				% printed within.
>  
>  :- type format_params
>  	--->	format_params(
> --- /home/stude/s/sthur/OldFiles/sized_pretty.m	Tue Feb  6 11:50:25 2001
> +++ /home/stude/s/sthur/Review/mercury/browser/sized_pretty.m	Tue Feb  6 13:21:13 2001
> @@ -1,5 +1,5 @@
>  %---------------------------------------------------------------------------%
> -% Copyright (C) 1998-2001 The University of Melbourne.
> +% Copyright (C) 2001 The University of Melbourne.
>  % This file may only be copied under the terms of the GNU Library General
>  % Public License - see the file COPYING.LIB in the Mercury distribution.
>  %---------------------------------------------------------------------------%
> @@ -182,9 +182,9 @@
>  :- type maybe_deconstructed(T)
>  	--->	not_deconstructed
>  	;	deconstructed(
> -			string,		% Functor 
> -			int,		% Arity
> -			list(maybe(pair(T, size_annotated_term(T)))) % arguments
> +			string,			% Functor 
> +			int,			% Arity
> +			size_annotated_args(T) 	% arguments
>  		).
>  
>  	% The exact type indicates the term has been fully deconstructed.
> @@ -205,6 +205,9 @@
>  			maybe_deconstructed(T)
>  		).
>  
> +:- type size_annotated_args(T) == 
> +	list(maybe(pair(T, size_annotated_term(T)))). 
> +
>  :- typeclass measure(T) where [
>  	func max_measure(T, T) = T is det,
>  	func zero_measure = T is det,
> @@ -218,12 +221,15 @@
>  		% given a term, it's arity, and a limit, this method decides
>  		% the partial limit that each of the argument should be
>  		% given. It's arguments in order are term, measure parameter(s),
> -		% limit, arity, a flag, size of the Functor, partial limit,
> -		% adjusted limit, adjusted measure parameter(s).
> +		% limit, arity, a flag (once the limit for the subterms 
> +		% is determined the subterms are flagged with this limit), size 
> +		% of the Functor, partial limit, adjusted limit, adjusted 
> +		% measure parameter(s).
>  		% Also a term is not deconstructed unless it has enough space
> -		% to print functor and the functors of it's arguments. But in
> -		% some cases this check is not needed that's why the booleen is
> -		% included.
> +		% to print functor and the functors of it's arguments.
> +		% If the bool is `yes', we check that there is enough space to 
> +		% print the functor and the functors of its arguments before 
> +		% deconstructing the term. 
>  	pred measured_split(univ::in, MeasureParams::in, T::in, int::in,
>  	     bool::in, T::out, maybe(T)::out, T::out, MeasureParams::out) is det
>  		
> @@ -299,9 +305,9 @@
>  %------------------------------------------------------------------------------%
>  	% annotating the arguments.
>  :- pred annotate_args_with_size(assoc_list(maybe(T), univ)::in,
> -	MeasureParams::in, T::in, T::in, T::out, bool::in, bool::out,
> -	list(maybe(pair(T, size_annotated_term(T))))::out)
> -	is det <= measure_with_params(T, MeasureParams).
> +	MeasureParams::in, T::in, T::in, T::out, bool::in, bool::out, 
> +	size_annotated_args(T)::out) is det <= measure_with_params(T, 
> +	MeasureParams).
>  
>  annotate_args_with_size([], _, _, SoFar, SoFar, Exact, Exact, []).
>  annotate_args_with_size([Flag - Arg | FlaggedArgs], Params, Limit,
> @@ -341,7 +347,7 @@
>  %------------------------------------------------------------------------------%
>  	% Annotates the arguments with zero limit.
>  :- pred annotate_args_with_zero_size(assoc_list(maybe(T), univ)::in, T::in,
> -	list(maybe(pair(T, size_annotated_term(T))))::out) is det <= measure(T).
> +	size_annotated_args(T)::out) is det <= measure(T).
>  
>  annotate_args_with_zero_size([], _, []).
>  annotate_args_with_zero_size([Flag - Univ | FlaggedArgs], ZeroMeasure,
> @@ -463,9 +469,8 @@
>  	% represented would be annoted again with a new limit
>  	% (SplitLimit). The rest of the terms are left alone.
>  :- pred process_args(MeasureParams::in, 
> -	list(maybe(pair(T, size_annotated_term(T))))::in, T::in, T::in, 
> -	list(maybe(pair(T, size_annotated_term(T))))::out, T::out)
> -	is det <= measure_with_params(T, MeasureParams).
> +	size_annotated_args(T)::in, T::in, T::in, size_annotated_args(T)::out, 
> +	T::out) is det <= measure_with_params(T, MeasureParams).
>  
>  process_args(_, [], _, _, [], zero_measure).
>  process_args(Params, [HeadArg | Rest], ArgLimit, SplitLimit, 
> @@ -530,8 +535,7 @@
>  %------------------------------------------------------------------------------%
>  	% Assumes that every argument must be on a different line
>  	% or all of them should be on the same line.
> -:- func to_doc_sized_2(string, int, 
> -	list(maybe(pair(T, size_annotated_term(T))))) = doc.
> +:- func to_doc_sized_2(string, int, size_annotated_args(T)) = doc.
>  
>  to_doc_sized_2(Functor, _Arity, []) = text(Functor).
>  
> @@ -729,9 +733,9 @@
>  	% that each argument is a different line or they are all on 
>  	% the same line. But this requires you to determine which case
>  	% likely to happen before hand. For example if a term is to be
> -	% on one line, you should do subtract_size_count(size_count(0, 
> -	% LineLength), size_count(0, arglength)) rather than
> -	% subtract_size_count(size_count(1, 0), size_count(0, arglength)).
> +	% on one line, you should do subtract_size_count(character_count(
> +	% LineLength), charater_count(arglength)) rather than
> +	% subtract_size_count(line_count(1), character_count(arglength)).
>  	% The reason that this situation cannot be detected in this code is:
>  	% A term can be printed on a single line only if, all of it's 
>  	% arguments can be printed on the same line. And you cannot determine
> @@ -806,9 +810,10 @@
>  
>  size_count_split(Univ, Params, Limit, Arity, Check, FunctorSize, 
>  		Flag, NewLimit, NewParams) :-
> +	% LineWidth is length of the line in which the functor is printed.
>  	Params = measure_params(LineWidth),
>      	deconstruct(univ_value(Univ), Functor, ActualArity, Args),
> -    	FSize = string__length(Functor) + 2*(ActualArity),
> +    	FSize = string__length(Functor) + 2 * (ActualArity),
>      	( Check = yes ->
>      		get_arg_length(Args, TotalLength, MaxArgLength),
>  		int__max(MaxArgLength, (string__length(Functor) + 1), MaxLength)
> @@ -826,8 +831,12 @@
>      	;
>  		(
>  			Limit = line_count(LineLimit),
> -			(LineLimit >= (Arity + 1), 
> -			(LineWidth - 2) >= MaxLength) 
> +			% we need one line for the functor and atleast 
> +			% one line for each argument
> +			LineLimit >= (Arity + 1),
> +			% linewidth is decreased by two characters to account 
> +			% for indentation
> +			(LineWidth - 2) >= MaxLength
>  		->
>  			Line = (LineLimit - 1) // Arity,
>  			Flag = yes(line_count(Line)),
> @@ -836,10 +845,14 @@
>  	    		NewParams = measure_params(LineWidth - 2)
>  		;
>  			Limit = line_count(LineLimit),
> -			LineLimit > 0, 
> +			LineLimit > 0,
> +			% Since every term is part of a bigger term (in this 
> +			% context anyway) it will have a comma, space and a 
> +			% newline at the end of it (Hence the "- 3").
>  			LineWidth - 3 >= (FSize + TotalLength) 
>  		->
> -	    		Char = (LineWidth - 3 - FSize + Arity - 1) // Arity ,
> +	    		% "Arity - 1" is for rounding up.
> +			Char = (LineWidth - 3 - FSize + Arity - 1) // Arity ,
>  	    		Flag = yes(character_count(Char)),
>  	    		FunctorSize = character_count(FSize),
>  	    		NewLimit = character_count(LineWidth - 3),
> @@ -848,13 +861,15 @@
>  			Limit = character_count(CharLimit),
>  			CharLimit >= (FSize + TotalLength)
>  		->
> -	   		Char = (CharLimit - FSize + Arity - 1)// Arity,
> +	   		Char = (CharLimit - FSize + Arity - 1) // Arity,
>  	   		Flag = yes(character_count(Char)),
>  	   		FunctorSize = character_count(FSize),
>  	   		NewLimit = Limit,
>  	   		NewParams = Params
>  		;
> -	   		Flag = no, 
> +	   		Flag = no,
> +			% If a term is not deconstructed, it is printed as
> +			% "functor/Arity". The "+ 2" accounts for that.
>  	   		FunctorSize = 
>  				character_count(string__length(Functor) + 2),
>  	   		NewLimit = Limit, 
> 
> --------------------------------------------------------------------------
> 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
> --------------------------------------------------------------------------
> 

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