constant folding for cnst[i] and cnst.attr

This commit is contained in:
Araq 2011-10-29 23:54:50 +02:00
commit 299390a585
5 changed files with 78 additions and 49 deletions

View file

@ -719,7 +719,9 @@ proc transform(c: PTransf, n: PNode): PTransNode =
else:
result = transformSons(c, n)
var cnst = getConstExpr(c.module, PNode(result))
if cnst != nil and (cnst.kind != nkBracket or cnst.len == 0):
# we inline constants if they are not complex constants:
if cnst != nil and (cnst.kind notin {nkCurly, nkPar, nkBracket} or
cnst.len == 0):
result = PTransNode(cnst) # do not miss an optimization
proc processTransf(context: PPassContext, n: PNode): PNode =