* fix #8821 JS codegen can produce extreme switch statements with case a of range * remove totalRange
This commit is contained in:
parent
07b645342a
commit
b286448a99
2 changed files with 2 additions and 10 deletions
|
|
@ -887,7 +887,6 @@ proc genRaiseStmt(p: PProc, n: PNode) =
|
||||||
proc genCaseJS(p: PProc, n: PNode, r: var TCompRes) =
|
proc genCaseJS(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
var
|
var
|
||||||
a, b, cond, stmt: TCompRes
|
a, b, cond, stmt: TCompRes
|
||||||
totalRange = 0
|
|
||||||
genLineDir(p, n)
|
genLineDir(p, n)
|
||||||
gen(p, n[0], cond)
|
gen(p, n[0], cond)
|
||||||
let typeKind = skipTypes(n[0].typ, abstractVar).kind
|
let typeKind = skipTypes(n[0].typ, abstractVar).kind
|
||||||
|
|
@ -897,7 +896,7 @@ proc genCaseJS(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
of tyString:
|
of tyString:
|
||||||
useMagic(p, "toJSStr")
|
useMagic(p, "toJSStr")
|
||||||
lineF(p, "switch (toJSStr($1)) {$n", [cond.rdLoc])
|
lineF(p, "switch (toJSStr($1)) {$n", [cond.rdLoc])
|
||||||
of tyFloat..tyFloat128:
|
of tyFloat..tyFloat128, tyInt..tyInt64, tyUInt..tyUInt64:
|
||||||
transferRange = true
|
transferRange = true
|
||||||
else:
|
else:
|
||||||
lineF(p, "switch ($1) {$n", [cond.rdLoc])
|
lineF(p, "switch ($1) {$n", [cond.rdLoc])
|
||||||
|
|
@ -926,10 +925,6 @@ proc genCaseJS(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
lineF(p, "$1 >= $2 && $1 <= $3", [cond.rdLoc, a.rdLoc, b.rdLoc])
|
lineF(p, "$1 >= $2 && $1 <= $3", [cond.rdLoc, a.rdLoc, b.rdLoc])
|
||||||
else:
|
else:
|
||||||
var v = copyNode(e[0])
|
var v = copyNode(e[0])
|
||||||
inc(totalRange, int(e[1].intVal - v.intVal))
|
|
||||||
if totalRange > 65535:
|
|
||||||
localError(p.config, n.info,
|
|
||||||
"Your case statement contains too many branches, consider using if/else instead!")
|
|
||||||
while v.intVal <= e[1].intVal:
|
while v.intVal <= e[1].intVal:
|
||||||
gen(p, v, cond)
|
gen(p, v, cond)
|
||||||
lineF(p, "case $1:$n", [cond.rdLoc])
|
lineF(p, "case $1:$n", [cond.rdLoc])
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,3 @@
|
||||||
discard """
|
|
||||||
errormsg: "Your case statement contains too many branches, consider using if/else instead!"
|
|
||||||
"""
|
|
||||||
|
|
||||||
proc isInt32(i: int): bool =
|
proc isInt32(i: int): bool =
|
||||||
case i
|
case i
|
||||||
|
|
@ -9,4 +6,4 @@ proc isInt32(i: int): bool =
|
||||||
else:
|
else:
|
||||||
return false
|
return false
|
||||||
|
|
||||||
discard isInt32(1)
|
doAssert isInt32(1) == true
|
||||||
Loading…
Add table
Add a link
Reference in a new issue