mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-15 23:54:19 +00:00
preparations for marker procs generation
This commit is contained in:
@@ -368,6 +368,22 @@ proc IfSwitchSplitPoint(p: BProc, n: PNode): int =
|
||||
if branch.kind == nkOfBranch and branchHasTooBigRange(branch):
|
||||
result = i
|
||||
|
||||
proc genCaseRange(p: BProc, branch: PNode) =
|
||||
var length = branch.len
|
||||
for j in 0 .. length-2:
|
||||
if branch[j].kind == nkRange:
|
||||
if hasSwitchRange in CC[ccompiler].props:
|
||||
appf(p.s[cpsStmts], "case $1 ... $2:$n", [
|
||||
genLiteral(p, branch[j][0]),
|
||||
genLiteral(p, branch[j][1])])
|
||||
else:
|
||||
var v = copyNode(branch[j][0])
|
||||
while v.intVal <= branch[j][1].intVal:
|
||||
appf(p.s[cpsStmts], "case $1:$n", [genLiteral(p, v)])
|
||||
Inc(v.intVal)
|
||||
else:
|
||||
appf(p.s[cpsStmts], "case $1:$n", [genLiteral(p, branch[j])])
|
||||
|
||||
proc genOrdinalCase(p: BProc, n: PNode) =
|
||||
# analyse 'case' statement:
|
||||
var splitPoint = IfSwitchSplitPoint(p, n)
|
||||
@@ -387,21 +403,8 @@ proc genOrdinalCase(p: BProc, n: PNode) =
|
||||
for i in splitPoint+1 .. < n.len:
|
||||
var branch = n[i]
|
||||
if branch.kind == nkOfBranch:
|
||||
var length = branch.len
|
||||
for j in 0 .. length-2:
|
||||
if branch[j].kind == nkRange:
|
||||
if hasSwitchRange in CC[ccompiler].props:
|
||||
appf(p.s[cpsStmts], "case $1 ... $2:$n", [
|
||||
genLiteral(p, branch[j][0]),
|
||||
genLiteral(p, branch[j][1])])
|
||||
else:
|
||||
var v = copyNode(branch[j][0])
|
||||
while v.intVal <= branch[j][1].intVal:
|
||||
appf(p.s[cpsStmts], "case $1:$n", [genLiteral(p, v)])
|
||||
Inc(v.intVal)
|
||||
else:
|
||||
appf(p.s[cpsStmts], "case $1:$n", [genLiteral(p, branch[j])])
|
||||
genStmts(p, branch[length-1])
|
||||
genCaseRange(p, branch)
|
||||
genStmts(p, branch.lastSon)
|
||||
else:
|
||||
# else part of case statement:
|
||||
appf(p.s[cpsStmts], "default:$n")
|
||||
|
||||
@@ -236,9 +236,7 @@ type
|
||||
|
||||
proc fsClose(s: PStream) = close(PFileStream(s).f)
|
||||
proc fsFlush(s: PStream) = flushFile(PFileStream(s).f)
|
||||
{.push warning[Deprecated]: off.}
|
||||
proc fsAtEnd(s: PStream): bool = return EndOfFile(PFileStream(s).f)
|
||||
{.pop.}
|
||||
proc fsSetPosition(s: PStream, pos: int) = setFilePos(PFileStream(s).f, pos)
|
||||
proc fsGetPosition(s: PStream): int = return int(getFilePos(PFileStream(s).f))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user