remove standalone 'except' and 'finally' statements that have been deprecated for years
This commit is contained in:
parent
07d6ff4be4
commit
f755808350
1 changed files with 38 additions and 72 deletions
|
|
@ -1843,80 +1843,46 @@ proc semStmtList(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
# nkNilLit, nkEmpty}:
|
# nkNilLit, nkEmpty}:
|
||||||
# dec last
|
# dec last
|
||||||
for i in countup(0, length - 1):
|
for i in countup(0, length - 1):
|
||||||
let k = n.sons[i].kind
|
var expr = semExpr(c, n.sons[i], flags)
|
||||||
case k
|
n.sons[i] = expr
|
||||||
of nkFinally, nkExceptBranch:
|
if c.matchedConcept != nil and expr.typ != nil and
|
||||||
# stand-alone finally and except blocks are
|
(nfFromTemplate notin n.flags or i != last):
|
||||||
# transformed into regular try blocks:
|
case expr.typ.kind
|
||||||
#
|
of tyBool:
|
||||||
# var f = fopen("somefile") | var f = fopen("somefile")
|
if expr.kind == nkInfix and
|
||||||
# finally: fclose(f) | try:
|
expr[0].kind == nkSym and
|
||||||
# ... | ...
|
expr[0].sym.name.s == "==":
|
||||||
# | finally:
|
if expr[1].typ.isUnresolvedStatic:
|
||||||
# | fclose(f)
|
inferConceptStaticParam(c, expr[1], expr[2])
|
||||||
var deferPart: PNode
|
continue
|
||||||
if k == nkDefer:
|
elif expr[2].typ.isUnresolvedStatic:
|
||||||
deferPart = newNodeI(nkFinally, n.sons[i].info)
|
inferConceptStaticParam(c, expr[2], expr[1])
|
||||||
deferPart.add n.sons[i].sons[0]
|
continue
|
||||||
elif k == nkFinally:
|
|
||||||
message(n.info, warnDeprecated,
|
|
||||||
"use 'defer'; standalone 'finally'")
|
|
||||||
deferPart = n.sons[i]
|
|
||||||
else:
|
|
||||||
message(n.info, warnDeprecated,
|
|
||||||
"use an explicit 'try'; standalone 'except'")
|
|
||||||
deferPart = n.sons[i]
|
|
||||||
var tryStmt = newNodeI(nkTryStmt, n.sons[i].info)
|
|
||||||
var body = newNodeI(nkStmtList, n.sons[i].info)
|
|
||||||
if i < n.sonsLen - 1:
|
|
||||||
body.sons = n.sons[(i+1)..n.len-1]
|
|
||||||
tryStmt.addSon(body)
|
|
||||||
tryStmt.addSon(deferPart)
|
|
||||||
n.sons[i] = semTry(c, tryStmt)
|
|
||||||
n.sons.setLen(i+1)
|
|
||||||
n.typ = n.sons[i].typ
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
var expr = semExpr(c, n.sons[i], flags)
|
|
||||||
n.sons[i] = expr
|
|
||||||
if c.matchedConcept != nil and expr.typ != nil and
|
|
||||||
(nfFromTemplate notin n.flags or i != last):
|
|
||||||
case expr.typ.kind
|
|
||||||
of tyBool:
|
|
||||||
if expr.kind == nkInfix and
|
|
||||||
expr[0].kind == nkSym and
|
|
||||||
expr[0].sym.name.s == "==":
|
|
||||||
if expr[1].typ.isUnresolvedStatic:
|
|
||||||
inferConceptStaticParam(c, expr[1], expr[2])
|
|
||||||
continue
|
|
||||||
elif expr[2].typ.isUnresolvedStatic:
|
|
||||||
inferConceptStaticParam(c, expr[2], expr[1])
|
|
||||||
continue
|
|
||||||
|
|
||||||
let verdict = semConstExpr(c, n[i])
|
let verdict = semConstExpr(c, n[i])
|
||||||
if verdict.intVal == 0:
|
if verdict.intVal == 0:
|
||||||
localError(result.info, "concept predicate failed")
|
localError(result.info, "concept predicate failed")
|
||||||
of tyUnknown: continue
|
of tyUnknown: continue
|
||||||
else: discard
|
|
||||||
if n.sons[i].typ == enforceVoidContext: #or usesResult(n.sons[i]):
|
|
||||||
voidContext = true
|
|
||||||
n.typ = enforceVoidContext
|
|
||||||
if i == last and (length == 1 or efWantValue in flags):
|
|
||||||
n.typ = n.sons[i].typ
|
|
||||||
if not isEmptyType(n.typ): n.kind = nkStmtListExpr
|
|
||||||
elif i != last or voidContext:
|
|
||||||
discardCheck(c, n.sons[i])
|
|
||||||
else:
|
|
||||||
n.typ = n.sons[i].typ
|
|
||||||
if not isEmptyType(n.typ): n.kind = nkStmtListExpr
|
|
||||||
if n.sons[i].kind in LastBlockStmts or
|
|
||||||
n.sons[i].kind in nkCallKinds and n.sons[i][0].kind == nkSym and sfNoReturn in n.sons[i][0].sym.flags:
|
|
||||||
for j in countup(i + 1, length - 1):
|
|
||||||
case n.sons[j].kind
|
|
||||||
of nkPragma, nkCommentStmt, nkNilLit, nkEmpty, nkBlockExpr,
|
|
||||||
nkBlockStmt, nkState: discard
|
|
||||||
else: localError(n.sons[j].info, errStmtInvalidAfterReturn)
|
|
||||||
else: discard
|
else: discard
|
||||||
|
if n.sons[i].typ == enforceVoidContext: #or usesResult(n.sons[i]):
|
||||||
|
voidContext = true
|
||||||
|
n.typ = enforceVoidContext
|
||||||
|
if i == last and (length == 1 or efWantValue in flags):
|
||||||
|
n.typ = n.sons[i].typ
|
||||||
|
if not isEmptyType(n.typ): n.kind = nkStmtListExpr
|
||||||
|
elif i != last or voidContext:
|
||||||
|
discardCheck(c, n.sons[i])
|
||||||
|
else:
|
||||||
|
n.typ = n.sons[i].typ
|
||||||
|
if not isEmptyType(n.typ): n.kind = nkStmtListExpr
|
||||||
|
if n.sons[i].kind in LastBlockStmts or
|
||||||
|
n.sons[i].kind in nkCallKinds and n.sons[i][0].kind == nkSym and sfNoReturn in n.sons[i][0].sym.flags:
|
||||||
|
for j in countup(i + 1, length - 1):
|
||||||
|
case n.sons[j].kind
|
||||||
|
of nkPragma, nkCommentStmt, nkNilLit, nkEmpty, nkBlockExpr,
|
||||||
|
nkBlockStmt, nkState: discard
|
||||||
|
else: localError(n.sons[j].info, errStmtInvalidAfterReturn)
|
||||||
|
else: discard
|
||||||
|
|
||||||
if result.len == 1 and
|
if result.len == 1 and
|
||||||
# concept bodies should be preserved as a stmt list:
|
# concept bodies should be preserved as a stmt list:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue