[m-rev.] diff: java switch on enums

Peter Wang novalazy at gmail.com
Mon Aug 1 13:09:58 AEST 2011


Branches: main

A recent change caused the MLDS backend to generate Java switch statements for
enumerations.  Mercury enumerations are represented by objects with an int
field, and neither the object nor the field are valid within case labels.
This fixes bug #209.

compiler/mlds_to_java.m:
	Write the integer value of the enumeration constant directly in case
	labels.

diff --git a/compiler/mlds_to_java.m b/compiler/mlds_to_java.m
index 686aff9..46d6166 100644
--- a/compiler/mlds_to_java.m
+++ b/compiler/mlds_to_java.m
@@ -4385,7 +4385,11 @@ output_case_cond(Info, Indent, Context, Match, !IO) :-
         Match = match_value(Val),
         indent_line(Info, Context, Indent, !IO),
         io.write_string("case ", !IO),
-        output_rval(Info, Val, !IO),
+        ( Val = ml_const(mlconst_enum(N, _)) ->
+            io.write_int(N, !IO)
+        ;
+            output_rval(Info, Val, !IO)
+        ),
         io.write_string(":\n", !IO)
     ;
         Match = match_range(_, _),

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list