This commit is contained in:
Araq
2016-12-20 22:42:25 +01:00
parent f484d1b20b
commit c166394024
2 changed files with 49 additions and 1 deletions

View File

@@ -174,7 +174,7 @@ proc mapTypeToAstX(t: PType; info: TLineInfo;
for i in 1 .. < t.len-1:
result.add mapTypeToAst(t.sons[i], info)
else:
result = mapTypeToAst(t.lastSon, info)
result = mapTypeToAstX(t.lastSon, info, inst, allowRecursion)
of tyGenericBody, tyOrdinal, tyUserTypeClassInst:
result = mapTypeToAst(t.lastSon, info)
of tyDistinct:

View File

@@ -0,0 +1,48 @@
discard """
output: "vec2"
"""
# bug #5131
import macros
type
vecBase[I: static[int], T] = distinct array[I, T]
vec2* = vecBase[2, float32]
proc isRange(n: NimNode, rangeLen: int = -1): bool =
if n.kind == nnkBracketExpr and $(n[0]) == "range":
if rangeLen == -1:
result = true
elif n[2].intVal - n[1].intVal + 1 == rangeLen:
result = true
proc getTypeName(t: NimNode, skipVar = false): string =
case t.kind
of nnkBracketExpr:
if $(t[0]) == "array" and t[1].isRange(2) and $(t[2]) == "float32":
result = "vec2"
elif $(t[0]) == "array" and t[1].isRange(3) and $(t[2]) == "float32":
result = "vec3"
elif $(t[0]) == "array" and t[1].isRange(4) and $(t[2]) == "float32":
result = "vec4"
elif $(t[0]) == "distinct":
result = getTypeName(t[1], skipVar)
of nnkSym:
case $t
of "vecBase": result = getTypeName(getType(t), skipVar)
of "float32": result = "float"
else:
result = $t
of nnkVarTy:
result = getTypeName(t[0])
if not skipVar:
result = "inout " & result
else:
echo "UNKNOWN TYPE: ", treeRepr(t)
assert(false, "Unknown type")
macro typeName(t: typed): string =
result = newLit(getTypeName(getType(t)))
var tt : vec2
echo typeName(tt)