support cstring in case (#20130)
* implement case for cstring for now just converts to string on C backend * custom implementation for cstring * remove leftover * revert even more * add nil + fix packages weird variant literal bug * update docs
This commit is contained in:
parent
1f838d9af1
commit
a95b6391fd
13 changed files with 126 additions and 18 deletions
|
|
@ -873,8 +873,9 @@ proc genCaseJS(p: PProc, n: PNode, r: var TCompRes) =
|
|||
totalRange = 0
|
||||
genLineDir(p, n)
|
||||
gen(p, n[0], cond)
|
||||
let stringSwitch = skipTypes(n[0].typ, abstractVar).kind == tyString
|
||||
if stringSwitch:
|
||||
let typeKind = skipTypes(n[0].typ, abstractVar).kind
|
||||
let anyString = typeKind in {tyString, tyCstring}
|
||||
if typeKind == tyString:
|
||||
useMagic(p, "toJSStr")
|
||||
lineF(p, "switch (toJSStr($1)) {$n", [cond.rdLoc])
|
||||
else:
|
||||
|
|
@ -899,10 +900,11 @@ proc genCaseJS(p: PProc, n: PNode, r: var TCompRes) =
|
|||
lineF(p, "case $1:$n", [cond.rdLoc])
|
||||
inc(v.intVal)
|
||||
else:
|
||||
if stringSwitch:
|
||||
if anyString:
|
||||
case e.kind
|
||||
of nkStrLit..nkTripleStrLit: lineF(p, "case $1:$n",
|
||||
[makeJSString(e.strVal, false)])
|
||||
of nkNilLit: lineF(p, "case null:$n", [])
|
||||
else: internalError(p.config, e.info, "jsgen.genCaseStmt: 2")
|
||||
else:
|
||||
gen(p, e, cond)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue