[m-rev.] for review: Java: fix an assignment bug

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Jan 15 19:33:37 AEDT 2003


On 15-Jan-2003, Michael Wybrow <mjwybrow at cs.mu.OZ.AU> wrote:
> 
> mercury/compiler/mlds_to_java.m:
>         Fix a bug in the Java back-end where incorrect code was being
> 	generated for assignments if the Lval was a field with type 
> 	enum_type.
...
>  	( 
> -		{ Lval = var(_, VarType) }, 
> +		(
> +			{ Lval = var(_, VarType) }
> +		;
> +			{ Lval = field(_, _, _, VarType, _) }
> +		),
>  	    	{ type_is_object(VarType) } 

That's OK, but the name "VarType" is misleading -- I suggest
using "LvalType" instead.

Also, a more robust (future-proof) way of writing it would be
to extract the code for computing an lval's type out into
a separate subroutine with determinism `det'.
That is, the test here would be just

		{ type_is_object(mlds_lval_type(Lval))

and mlds_lval_type/1 would be defined as e.g.

	:- func mlds_lval_type(mlds__lval) = mlds__type.
	mlds_lval_type(var(_, VarType)) = VarType.
	mlds_lval_type(field(_, _, _, FieldType, _)) = FieldType.
	mlds_lval_type(mem_ref(_, PtrType) = 
		( PtrType = mlds__ptr_type(Type) ->
			Type
		;
			func_error("mlds_lval_type: mem_ref of non-pointer")
		).

(This subroutine could go either in mlds_to_java.m or in ml_util.m.)

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