diff options
author | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2012-02-01 15:16:14 +0100 |
---|---|---|
committer | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2012-02-01 15:16:14 +0100 |
commit | 18d6a9f5054bf7f1c76e48c3eb8da0fb96ccdccb (patch) | |
tree | d79df17d9dd470822a3ec8f7d572d239ea839b2a /src/fjbg/ch/epfl/lamp/fjbg | |
parent | 37bcff7956451cd74d08899e0e49c8b569d3a882 (diff) | |
download | scala-18d6a9f5054bf7f1c76e48c3eb8da0fb96ccdccb.tar.gz scala-18d6a9f5054bf7f1c76e48c3eb8da0fb96ccdccb.tar.bz2 scala-18d6a9f5054bf7f1c76e48c3eb8da0fb96ccdccb.zip |
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.
Diffstat (limited to 'src/fjbg/ch/epfl/lamp/fjbg')
-rw-r--r-- | src/fjbg/ch/epfl/lamp/fjbg/JExtendedCode.java | 10 |
1 files changed, 10 insertions, 0 deletions
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++) { |