macros are now checked to not produce cyclic ASTs
This commit is contained in:
parent
6656f0d713
commit
4ec39b6a8f
2 changed files with 13 additions and 2 deletions
|
|
@ -121,7 +121,6 @@ proc wrapInComesFrom*(info: TLineInfo; res: PNode): PNode =
|
||||||
else:
|
else:
|
||||||
result = newNodeI(nkPar, info)
|
result = newNodeI(nkPar, info)
|
||||||
result.add res
|
result.add res
|
||||||
result.flags.incl nfNone
|
|
||||||
|
|
||||||
proc evalTemplate*(n: PNode, tmpl, genSymOwner: PSym; fromHlo=false): PNode =
|
proc evalTemplate*(n: PNode, tmpl, genSymOwner: PSym; fromHlo=false): PNode =
|
||||||
inc(evalTemplateCounter)
|
inc(evalTemplateCounter)
|
||||||
|
|
|
||||||
|
|
@ -237,6 +237,14 @@ when false:
|
||||||
result.handleIsOperator = proc (n: PNode): PNode =
|
result.handleIsOperator = proc (n: PNode): PNode =
|
||||||
result = isOpImpl(c, n)
|
result = isOpImpl(c, n)
|
||||||
|
|
||||||
|
proc hasCycle(n: PNode): bool =
|
||||||
|
incl n.flags, nfNone
|
||||||
|
for i in 0..<safeLen(n):
|
||||||
|
if nfNone in n[i].flags or hasCycle(n[i]):
|
||||||
|
result = true
|
||||||
|
break
|
||||||
|
excl n.flags, nfNone
|
||||||
|
|
||||||
proc fixupTypeAfterEval(c: PContext, evaluated, eOrig: PNode): PNode =
|
proc fixupTypeAfterEval(c: PContext, evaluated, eOrig: PNode): PNode =
|
||||||
# recompute the types as 'eval' isn't guaranteed to construct types nor
|
# recompute the types as 'eval' isn't guaranteed to construct types nor
|
||||||
# that the types are sound:
|
# that the types are sound:
|
||||||
|
|
@ -246,6 +254,10 @@ proc fixupTypeAfterEval(c: PContext, evaluated, eOrig: PNode): PNode =
|
||||||
else:
|
else:
|
||||||
result = evaluated
|
result = evaluated
|
||||||
let expectedType = eOrig.typ.skipTypes({tyStatic})
|
let expectedType = eOrig.typ.skipTypes({tyStatic})
|
||||||
|
if hasCycle(result):
|
||||||
|
globalError(eOrig.info, "the resulting AST is cyclic and cannot be processed further")
|
||||||
|
result = errorNode(c, eOrig)
|
||||||
|
else:
|
||||||
semmacrosanity.annotateType(result, expectedType)
|
semmacrosanity.annotateType(result, expectedType)
|
||||||
else:
|
else:
|
||||||
result = semExprWithType(c, evaluated)
|
result = semExprWithType(c, evaluated)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue