[m-rev.] for review: Bug fix for enumerated types in grade Java
James Goddard
goddardjames at yahoo.com
Wed Jan 7 15:34:35 AEDT 2004
Estimated hours taken: 9
Branches: main
Bug fix for enumerated type switch statements in Java.
compiler/mlds_to_java.m:
Modified rval_is_enum_object/1 so that it considers field selections
as well as vars.
This fixes a problem that arose in producing the switch statement for
fold_bits/7 in library/sparse_bitset, where the enumerated type was
not detected, so it was trying to switch on an Object:
(mercury.sparse_bitset.fold_bits_7_p_3_env_0) env_ptr).Dir_8
as opposed to:
(mercury.sparse_bitset.fold_bits_7_p_3_env_0) env_ptr).Dir_8.value
which is what it should have.
After making this change, it was also necessary to correct a call in
output_initializer_body from output_rval_maybe_with_enum to just
plain output_rval, since at that point it is known that the Rval is
not an enum object.
The standard library will now compile without error in grade java.
Index: mlds_to_java.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_java.m,v
retrieving revision 1.49
diff -u -d -r1.49 mlds_to_java.m
--- mlds_to_java.m 22 Dec 2003 23:37:33 -0000 1.49
+++ mlds_to_java.m 7 Jan 2004 04:26:43 -0000
@@ -212,9 +212,14 @@
:- mode rval_is_enum_object(in) is semidet.
rval_is_enum_object(Rval) :-
- Rval = lval(Lval),
+ Rval = lval(Lval),
+ (
Lval = var(_, VarType),
- type_is_enum(VarType).
+ type_is_enum(VarType)
+ ;
+ Lval = field(_, _, _, FieldType, _),
+ type_is_enum(FieldType)
+ ).
% Succeeds iff a given string matches the unqualified
% interface name of a interface in Mercury's Java runtime system.
@@ -1471,10 +1476,11 @@
io__write_string("("),
output_type(Type),
io__write_string(") "),
- output_rval_maybe_with_enum(Rval, ModuleName)
+ output_rval(Rval, ModuleName)
;
output_rval_maybe_with_enum(Rval, ModuleName)
).
+
output_initializer_body(init_struct(StructType, FieldInits), _MaybeType,
ModuleName) -->
io__write_string("new "),
@@ -3219,6 +3225,13 @@
% Output an Rval and if the Rval is an enumeration object
% append the string ".value", so we can access its value
% field.
+ % XXX Note that this is necessary in some places, but not in others.
+ % For example, it is important to do so for switch statements, as
+ % the argument of a switch _must_ be an integer in Java. However,
+ % adding the .value to assignments breaks some casting...
+ % At some point, we need to go through all the places where
+ % output_rval and output_rval_maybe_with_enum are called and make
+ % sure the correct one is being used.
%
:- pred output_rval_maybe_with_enum(mlds__rval, mlds_module_name,
io__state, io__state).
--------------------------------------------------------------------------
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