attempt to improve line information for '!=' etc. templates
This commit is contained in:
parent
52d1a637b9
commit
5659a1662e
1 changed files with 13 additions and 32 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# The Nimrod Compiler
|
# The Nimrod Compiler
|
||||||
# (c) Copyright 2012 Andreas Rumpf
|
# (c) Copyright 2013 Andreas Rumpf
|
||||||
#
|
#
|
||||||
# See the file "copying.txt", included in this
|
# See the file "copying.txt", included in this
|
||||||
# distribution, for details about the copyright.
|
# distribution, for details about the copyright.
|
||||||
|
|
@ -16,9 +16,14 @@ import
|
||||||
type
|
type
|
||||||
TemplCtx {.pure, final.} = object
|
TemplCtx {.pure, final.} = object
|
||||||
owner, genSymOwner: PSym
|
owner, genSymOwner: PSym
|
||||||
|
instLines: bool # use the instantiation lines numbers
|
||||||
mapping: TIdTable # every gensym'ed symbol needs to be mapped to some
|
mapping: TIdTable # every gensym'ed symbol needs to be mapped to some
|
||||||
# new symbol
|
# new symbol
|
||||||
|
|
||||||
|
proc copyNode(ctx: TemplCtx, a, b: PNode): PNode =
|
||||||
|
result = copyNode(a)
|
||||||
|
if ctx.instLines: result.info = b.info
|
||||||
|
|
||||||
proc evalTemplateAux(templ, actual: PNode, c: var TemplCtx, result: PNode) =
|
proc evalTemplateAux(templ, actual: PNode, c: var TemplCtx, result: PNode) =
|
||||||
case templ.kind
|
case templ.kind
|
||||||
of nkSym:
|
of nkSym:
|
||||||
|
|
@ -37,43 +42,17 @@ proc evalTemplateAux(templ, actual: PNode, c: var TemplCtx, result: PNode) =
|
||||||
x = copySym(s, false)
|
x = copySym(s, false)
|
||||||
x.owner = c.genSymOwner
|
x.owner = c.genSymOwner
|
||||||
IdTablePut(c.mapping, s, x)
|
IdTablePut(c.mapping, s, x)
|
||||||
result.add newSymNode(x, templ.info)
|
result.add newSymNode(x, if c.instLines: actual.info else: templ.info)
|
||||||
else:
|
else:
|
||||||
result.add copyNode(templ)
|
result.add copyNode(c, templ, actual)
|
||||||
of nkNone..nkIdent, nkType..nkNilLit: # atom
|
of nkNone..nkIdent, nkType..nkNilLit: # atom
|
||||||
result.add copyNode(templ)
|
result.add copyNode(c, templ, actual)
|
||||||
else:
|
else:
|
||||||
var res = copyNode(templ)
|
var res = copyNode(c, templ, actual)
|
||||||
for i in countup(0, sonsLen(templ) - 1):
|
for i in countup(0, sonsLen(templ) - 1):
|
||||||
evalTemplateAux(templ.sons[i], actual, c, res)
|
evalTemplateAux(templ.sons[i], actual, c, res)
|
||||||
result.add res
|
result.add res
|
||||||
|
|
||||||
when false:
|
|
||||||
proc evalTemplateAux(templ, actual: PNode, c: var TemplCtx): PNode =
|
|
||||||
case templ.kind
|
|
||||||
of nkSym:
|
|
||||||
var s = templ.sym
|
|
||||||
if s.owner.id == c.owner.id:
|
|
||||||
if s.kind == skParam:
|
|
||||||
result = copyTree(actual.sons[s.position])
|
|
||||||
else:
|
|
||||||
InternalAssert sfGenSym in s.flags
|
|
||||||
var x = PSym(IdTableGet(c.mapping, s))
|
|
||||||
if x == nil:
|
|
||||||
x = copySym(s, false)
|
|
||||||
x.owner = c.genSymOwner
|
|
||||||
IdTablePut(c.mapping, s, x)
|
|
||||||
result = newSymNode(x, templ.info)
|
|
||||||
else:
|
|
||||||
result = copyNode(templ)
|
|
||||||
of nkNone..nkIdent, nkType..nkNilLit: # atom
|
|
||||||
result = copyNode(templ)
|
|
||||||
else:
|
|
||||||
result = copyNode(templ)
|
|
||||||
newSons(result, sonsLen(templ))
|
|
||||||
for i in countup(0, sonsLen(templ) - 1):
|
|
||||||
result.sons[i] = evalTemplateAux(templ.sons[i], actual, c)
|
|
||||||
|
|
||||||
proc evalTemplateArgs(n: PNode, s: PSym): PNode =
|
proc evalTemplateArgs(n: PNode, s: PSym): PNode =
|
||||||
# if the template has zero arguments, it can be called without ``()``
|
# if the template has zero arguments, it can be called without ``()``
|
||||||
# `n` is then a nkSym or something similar
|
# `n` is then a nkSym or something similar
|
||||||
|
|
@ -118,7 +97,9 @@ proc evalTemplate*(n: PNode, tmpl, genSymOwner: PSym): PNode =
|
||||||
renderTree(result, {renderNoComments}))
|
renderTree(result, {renderNoComments}))
|
||||||
else:
|
else:
|
||||||
result = copyNode(body)
|
result = copyNode(body)
|
||||||
#evalTemplateAux(body, args, ctx, result)
|
ctx.instLines = body.kind notin {nkStmtList, nkStmtListExpr,
|
||||||
|
nkBlockStmt, nkBlockExpr}
|
||||||
|
if ctx.instLines: result.info = n.info
|
||||||
for i in countup(0, safeLen(body) - 1):
|
for i in countup(0, safeLen(body) - 1):
|
||||||
evalTemplateAux(body.sons[i], args, ctx, result)
|
evalTemplateAux(body.sons[i], args, ctx, result)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue