macros are now checked to not produce cyclic ASTs

This commit is contained in:
Andreas Rumpf
2017-02-08 11:33:36 +01:00
parent 6656f0d713
commit 4ec39b6a8f
2 changed files with 13 additions and 2 deletions

View File

@@ -121,7 +121,6 @@ proc wrapInComesFrom*(info: TLineInfo; res: PNode): PNode =
else:
result = newNodeI(nkPar, info)
result.add res
result.flags.incl nfNone
proc evalTemplate*(n: PNode, tmpl, genSymOwner: PSym; fromHlo=false): PNode =
inc(evalTemplateCounter)

View File

@@ -237,6 +237,14 @@ when false:
result.handleIsOperator = proc (n: PNode): PNode =
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 =
# recompute the types as 'eval' isn't guaranteed to construct types nor
# that the types are sound:
@@ -246,7 +254,11 @@ proc fixupTypeAfterEval(c: PContext, evaluated, eOrig: PNode): PNode =
else:
result = evaluated
let expectedType = eOrig.typ.skipTypes({tyStatic})
semmacrosanity.annotateType(result, expectedType)
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)
else:
result = semExprWithType(c, evaluated)
#result = fitNode(c, e.typ, result) inlined with special case: