[m-rev.] for review: Java: fix an assignment bug
Michael Wybrow
mjwybrow at cs.mu.OZ.AU
Thu Jan 16 15:44:39 AEDT 2003
On Wed, 15 Jan 2003, Fergus Henderson wrote:
>
> 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'.
In that case, you'll probably have no problems in signing off on
the following diff instead -- it's mostly yours, though I did
correct a missing parenthesis in your sample code. :-)
Index: mlds_to_java.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_java.m,v
retrieving revision 1.33
diff -u -r1.33 mlds_to_java.m
--- mlds_to_java.m 24 Nov 2002 03:57:26 -0000 1.33
+++ mlds_to_java.m 16 Jan 2003 04:36:29 -0000
@@ -162,6 +162,19 @@
; Builtin = user_type
).
+ % Given an lval, return its type.
+ %
+:- 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")
+ ).
+
% Succeeds iff the Rval represents an integer constant.
%
:- pred rval_is_int_const(mlds__rval).
@@ -2448,15 +2461,14 @@
output_lval(Lval),
io__write_string(" = "),
(
- { Lval = var(_, VarType) },
- { type_is_object(VarType) }
-
+ { LvalType = mlds_lval_type(Lval) },
+ { type_is_object(LvalType) }
->
% If the Lval is a an object.
( { rval_is_int_const(Rval) } ->
io__write_string("new "),
- output_type(VarType),
+ output_type(LvalType),
io__write_string("("),
output_rval(Rval),
io__write_string(")")
--------------------------------------------------------------------------
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