This commit is contained in:
Araq 2015-06-25 11:15:36 +02:00
commit 47dce26886
2 changed files with 11 additions and 4 deletions

View file

@ -437,6 +437,9 @@ proc evalOp(m: TMagic, n, a, b, c: PNode): PNode =
mNLen..mNError, mEqRef, mSlurp, mStaticExec, mNGenSym, mSpawn, mNLen..mNError, mEqRef, mSlurp, mStaticExec, mNGenSym, mSpawn,
mParallel, mPlugin: mParallel, mPlugin:
discard discard
of mEqProc:
result = newIntNodeT(ord(
exprStructuralEquivalent(a, b, strictSymEquality=true)), n)
else: internalError(a.info, "evalOp(" & $m & ')') else: internalError(a.info, "evalOp(" & $m & ')')
proc getConstIfExpr(c: PSym, n: PNode): PNode = proc getConstIfExpr(c: PSym, n: PNode): PNode =

View file

@ -36,13 +36,16 @@ proc cyclicTree*(n: PNode): bool =
var s = newNodeI(nkEmpty, n.info) var s = newNodeI(nkEmpty, n.info)
result = cyclicTreeAux(n, s) result = cyclicTreeAux(n, s)
proc exprStructuralEquivalent*(a, b: PNode): bool = proc exprStructuralEquivalent*(a, b: PNode; strictSymEquality=false): bool =
result = false result = false
if a == b: if a == b:
result = true result = true
elif (a != nil) and (b != nil) and (a.kind == b.kind): elif (a != nil) and (b != nil) and (a.kind == b.kind):
case a.kind case a.kind
of nkSym: of nkSym:
if strictSymEquality:
result = a.sym == b.sym
else:
# don't go nuts here: same symbol as string is enough: # don't go nuts here: same symbol as string is enough:
result = a.sym.name.id == b.sym.name.id result = a.sym.name.id == b.sym.name.id
of nkIdent: result = a.ident.id == b.ident.id of nkIdent: result = a.ident.id == b.ident.id
@ -53,7 +56,8 @@ proc exprStructuralEquivalent*(a, b: PNode): bool =
else: else:
if sonsLen(a) == sonsLen(b): if sonsLen(a) == sonsLen(b):
for i in countup(0, sonsLen(a) - 1): for i in countup(0, sonsLen(a) - 1):
if not exprStructuralEquivalent(a.sons[i], b.sons[i]): return if not exprStructuralEquivalent(a.sons[i], b.sons[i],
strictSymEquality): return
result = true result = true
proc sameTree*(a, b: PNode): bool = proc sameTree*(a, b: PNode): bool =