From 18d6a9f5054bf7f1c76e48c3eb8da0fb96ccdccb Mon Sep 17 00:00:00 2001 From: Grzegorz Kossakowski Date: Wed, 1 Feb 2012 15:16:14 +0100 Subject: Fixed handling of empty keys in emitSWITCH. The problem of emitSWITCH not handling empty keys popped up when I tried to implement unfolding of pattern alternatives in genicode instead of in typers/explicitouter. This change makes perfect sense in isolation as bytecode allows LOOKUPSWITCHes that have only default case. I actually verified that this kind of bytecode is generated by javac when one has switch statement with only default case defined. Review by @paulp or @dragos. --- src/fjbg/ch/epfl/lamp/fjbg/JExtendedCode.java | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/fjbg/ch/epfl') diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JExtendedCode.java b/src/fjbg/ch/epfl/lamp/fjbg/JExtendedCode.java index 8b0338ed29..d4c5417260 100644 --- a/src/fjbg/ch/epfl/lamp/fjbg/JExtendedCode.java +++ b/src/fjbg/ch/epfl/lamp/fjbg/JExtendedCode.java @@ -596,6 +596,16 @@ public class JExtendedCode extends JCode { double minDensity) { assert keys.length == branches.length; + //The special case for empty keys. It makes sense to allow + //empty keys and generate LOOKUPSWITCH with defaultBranch + //only. This is exactly what javac does for switch statement + //that has only a default case. + if (keys.length == 0) { + emitLOOKUPSWITCH(keys, branches, defaultBranch); + return; + } + //the rest of the code assumes that keys.length > 0 + // sorting the tables // FIXME use quicksort for (int i = 1; i < keys.length; i++) { -- cgit v1.2.3