summaryrefslogtreecommitdiff
path: root/src/fjbg/ch/epfl
diff options
context:
space:
mode:
authorGrzegorz Kossakowski <grzegorz.kossakowski@gmail.com>2012-02-01 15:16:14 +0100
committerGrzegorz Kossakowski <grzegorz.kossakowski@gmail.com>2012-02-01 15:16:14 +0100
commit18d6a9f5054bf7f1c76e48c3eb8da0fb96ccdccb (patch)
treed79df17d9dd470822a3ec8f7d572d239ea839b2a /src/fjbg/ch/epfl
parent37bcff7956451cd74d08899e0e49c8b569d3a882 (diff)
downloadscala-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')
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JExtendedCode.java10
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++) {