WIP implementation of except ExcType as ident syntax. Refs #3691.

This commit is contained in:
Dominik Picheta 2017-02-01 00:32:56 +01:00
commit e8c46d29cd
4 changed files with 82 additions and 3 deletions

View file

@ -701,6 +701,35 @@ proc transformCall(c: PTransf, n: PNode): PTransNode =
else:
result = s.PTransNode
proc transformExceptBranch(c: PTransf, n: PNode): PTransNode =
result = transformSons(c, n)
if n[0].kind == nkInfix:
let excTypeNode = n[0][1]
let actions = newTransNode(nkStmtList, n[1].info, 2)
# Generating `let exc = (excType)(getCurrentException())`
let excCall = PTransNode(callCodegenProc("getCurrentException", ast.emptyNode))
let convNode = newTransNode(nkHiddenSubConv, n[1].info, 2)
convNode[0] = PTransNode(ast.emptyNode)
convNode[1] = excCall
PNode(convNode).typ = excTypeNode.typ.toRef()
let identDefs = newTransNode(nkIdentDefs, n[1].info, 3)
identDefs[0] = PTransNode(n[0][2])
identDefs[1] = PTransNode(ast.emptyNode)
identDefs[2] = convNode
let letSection = newTransNode(nkLetSection, n[1].info, 1)
letSection[0] = identDefs
actions[0] = letSection
actions[1] = transformSons(c, n[1])
result[1] = actions
# Replace the `Exception as foobar` with just `Exception`.
result[0] = result[0][1]
#debug(PNode(result))
#echo(PNode(result))
proc dontInlineConstant(orig, cnst: PNode): bool {.inline.} =
# symbols that expand to a complex constant (array, etc.) should not be
# inlined, unless it's the empty array:
@ -851,6 +880,8 @@ proc transform(c: PTransf, n: PNode): PTransNode =
if a.kind == nkSym:
n.sons[1] = transformSymAux(c, a)
return PTransNode(n)
of nkExceptBranch:
result = transformExceptBranch(c, n)
else:
result = transformSons(c, n)
when false: