This commit is contained in:
Araq 2014-08-19 10:01:46 +02:00
commit b5248d9037
3 changed files with 21 additions and 14 deletions

View file

@ -390,29 +390,30 @@ proc symToYaml(n: PSym, indent: int = 0, maxRecDepth: int = - 1): PRope =
var marker = initIntSet() var marker = initIntSet()
result = symToYamlAux(n, marker, indent, maxRecDepth) result = symToYamlAux(n, marker, indent, maxRecDepth)
proc debugTree(n: PNode, indent: int, maxRecDepth: int): PRope proc debugTree(n: PNode, indent: int, maxRecDepth: int; renderType=false): PRope
proc debugType(n: PType): PRope = proc debugType(n: PType, maxRecDepth=100): PRope =
if n == nil: if n == nil:
result = toRope("null") result = toRope("null")
else: else:
result = toRope($n.kind) result = toRope($n.kind)
if n.sym != nil: if n.sym != nil:
app(result, " ") app(result, " ")
app(result, n.sym.name.s) app(result, n.sym.name.s)
if (n.kind != tyString) and (sonsLen(n) > 0): if (n.kind != tyString) and (sonsLen(n) > 0) and maxRecDepth != 0:
app(result, "(") app(result, "(")
for i in countup(0, sonsLen(n) - 1): for i in countup(0, sonsLen(n) - 1):
if i > 0: app(result, ", ") if i > 0: app(result, ", ")
if n.sons[i] == nil: if n.sons[i] == nil:
app(result, "null") app(result, "null")
else: else:
app(result, debugType(n.sons[i])) app(result, debugType(n.sons[i], maxRecDepth-1))
if n.kind == tyObject and n.n != nil: if n.kind == tyObject and n.n != nil:
app(result, ", node: ") app(result, ", node: ")
app(result, debugTree(n.n, 2, 100)) app(result, debugTree(n.n, 2, maxRecDepth-1, renderType=true))
app(result, ")") app(result, ")")
proc debugTree(n: PNode, indent: int, maxRecDepth: int): PRope = proc debugTree(n: PNode, indent: int, maxRecDepth: int;
renderType=false): PRope =
if n == nil: if n == nil:
result = toRope("null") result = toRope("null")
else: else:
@ -436,6 +437,8 @@ proc debugTree(n: PNode, indent: int, maxRecDepth: int): PRope =
[istr, toRope(n.sym.name.s), toRope(n.sym.id)]) [istr, toRope(n.sym.name.s), toRope(n.sym.id)])
# [istr, symToYaml(n.sym, indent, maxRecDepth), # [istr, symToYaml(n.sym, indent, maxRecDepth),
# toRope(n.sym.id)]) # toRope(n.sym.id)])
if renderType and n.sym.typ != nil:
appf(result, ",$N$1\"typ\": $2", [istr, debugType(n.sym.typ, 2)])
of nkIdent: of nkIdent:
if n.ident != nil: if n.ident != nil:
appf(result, ",$N$1\"ident\": $2", [istr, makeYamlString(n.ident.s)]) appf(result, ",$N$1\"ident\": $2", [istr, makeYamlString(n.ident.s)])
@ -447,7 +450,7 @@ proc debugTree(n: PNode, indent: int, maxRecDepth: int): PRope =
for i in countup(0, sonsLen(n) - 1): for i in countup(0, sonsLen(n) - 1):
if i > 0: app(result, ",") if i > 0: app(result, ",")
appf(result, "$N$1$2", [spaces(indent + 4), debugTree(n.sons[i], appf(result, "$N$1$2", [spaces(indent + 4), debugTree(n.sons[i],
indent + 4, maxRecDepth - 1)]) indent + 4, maxRecDepth - 1, renderType)])
appf(result, "$N$1]", [istr]) appf(result, "$N$1]", [istr])
appf(result, ",$N$1\"info\": $2", [istr, lineInfoToStr(n.info)]) appf(result, ",$N$1\"info\": $2", [istr, lineInfoToStr(n.info)])
appf(result, "$N$1}", [spaces(indent)]) appf(result, "$N$1}", [spaces(indent)])

View file

@ -723,7 +723,7 @@ proc discriminatorTableName(m: BModule, objtype: PType, d: PSym): PRope =
if objtype.sym == nil: if objtype.sym == nil:
internalError(d.info, "anonymous obj with discriminator") internalError(d.info, "anonymous obj with discriminator")
result = ropef("NimDT_$1_$2", [ result = ropef("NimDT_$1_$2", [
toRope(objtype.sym.name.s.mangle), toRope(d.name.s.mangle)]) toRope(objtype.id), toRope(d.name.s.mangle)])
proc discriminatorTableDecl(m: BModule, objtype: PType, d: PSym): PRope = proc discriminatorTableDecl(m: BModule, objtype: PType, d: PSym): PRope =
discard cgsym(m, "TNimNode") discard cgsym(m, "TNimNode")

View file

@ -94,6 +94,10 @@ proc getUniqueType*(key: PType): PType =
else: result = getUniqueType(lastSon(key)) else: result = getUniqueType(lastSon(key))
of tyGenericInst, tyOrdinal, tyMutable, tyConst, tyIter, tyStatic: of tyGenericInst, tyOrdinal, tyMutable, tyConst, tyIter, tyStatic:
result = getUniqueType(lastSon(key)) result = getUniqueType(lastSon(key))
#let obj = lastSon(key)
#if obj.sym != nil and obj.sym.name.s == "TOption":
# echo "for ", typeToString(key), " I returned "
# debug result
of tyArrayConstr, tyGenericInvokation, tyGenericBody, of tyArrayConstr, tyGenericInvokation, tyGenericBody,
tyOpenArray, tyArray, tySet, tyRange, tyTuple, tyOpenArray, tyArray, tySet, tyRange, tyTuple,
tyPtr, tyRef, tySequence, tyForward, tyVarargs, tyProxy, tyVar: tyPtr, tyRef, tySequence, tyForward, tyVarargs, tyProxy, tyVar:
@ -126,7 +130,7 @@ proc getUniqueType*(key: PType): PType =
if t != nil and sameType(t, key): if t != nil and sameType(t, key):
return t return t
idTablePut(gTypeTable[k], key, key) idTablePut(gTypeTable[k], key, key)
result = key result = key
of tyEnum: of tyEnum:
result = PType(idTableGet(gTypeTable[k], key)) result = PType(idTableGet(gTypeTable[k], key))
if result == nil: if result == nil: