This commit is contained in:
Zahary Karadjov 2014-03-10 01:57:08 +02:00
commit d5798b43de
3 changed files with 29 additions and 15 deletions

View file

@ -899,6 +899,21 @@ proc makeDeref(n: PNode): PNode =
addSon(result, a) addSon(result, a)
t = skipTypes(t.sons[0], {tyGenericInst}) t = skipTypes(t.sons[0], {tyGenericInst})
proc readTypeParameter(c: PContext, ty: PType,
paramName: PIdent, info: TLineInfo): PNode =
internalAssert ty.kind == tyGenericInst
let ty = ty.skipGenericAlias
let tbody = ty.sons[0]
for s in countup(0, tbody.len-2):
let tParam = tbody.sons[s]
if tParam.sym.name == paramName:
let rawTyp = ty.sons[s + 1]
if rawTyp.kind == tyStatic:
return rawTyp.n
else:
let foundTyp = makeTypeDesc(c, rawTyp)
return newSymNode(copySym(tParam.sym).linkTo(foundTyp), info)
proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode = proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
## returns nil if it's not a built-in field access ## returns nil if it's not a built-in field access
checkSonsLen(n, 2) checkSonsLen(n, 2)
@ -932,18 +947,7 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
markUsed(n, f) markUsed(n, f)
return return
of tyGenericInst: of tyGenericInst:
assert ty.sons[0].kind == tyGenericBody return readTypeParameter(c, ty, i, n.info)
let tbody = ty.sons[0]
for s in countup(0, tbody.len-2):
let tParam = tbody.sons[s]
if tParam.sym.name == i:
let rawTyp = ty.sons[s + 1]
if rawTyp.kind == tyStatic:
return rawTyp.n
else:
let foundTyp = makeTypeDesc(c, rawTyp)
return newSymNode(copySym(tParam.sym).linkTo(foundTyp), n.info)
return
of tyObject, tyTuple: of tyObject, tyTuple:
if ty.n.kind == nkRecList: if ty.n.kind == nkRecList:
for field in ty.n.sons: for field in ty.n.sons:
@ -990,6 +994,10 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
n.typ = f.typ n.typ = f.typ
result = n result = n
# we didn't find any field, let's look for a generic param
if result == nil and n.sons[0].typ.kind == tyGenericInst:
result = readTypeParameter(c, n.sons[0].typ, i, n.info)
proc dotTransformation(c: PContext, n: PNode): PNode = proc dotTransformation(c: PContext, n: PNode): PNode =
if isSymChoice(n.sons[1]): if isSymChoice(n.sons[1]):
result = newNodeI(nkDotCall, n.info) result = newNodeI(nkDotCall, n.info)

View file

@ -181,7 +181,8 @@ proc replaceTypeVarsN(cl: var TReplTypeVars, n: PNode): PNode =
of nkStaticExpr: of nkStaticExpr:
var n = prepareNode(cl, n) var n = prepareNode(cl, n)
n = reResolveCallsWithTypedescParams(cl, n) n = reResolveCallsWithTypedescParams(cl, n)
result = cl.c.semExpr(cl.c, n) result = if cl.allowMetaTypes: n
else: cl.c.semExpr(cl.c, n)
else: else:
var length = sonsLen(n) var length = sonsLen(n)
if length > 0: if length > 0:
@ -341,6 +342,7 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
result = replaceTypeVarsT(cl, lastSon(t)) result = replaceTypeVarsT(cl, lastSon(t))
of tyFromExpr: of tyFromExpr:
if cl.allowMetaTypes: return
var n = prepareNode(cl, t.n) var n = prepareNode(cl, t.n)
n = cl.c.semConstExpr(cl.c, n) n = cl.c.semConstExpr(cl.c, n)
if n.typ.kind == tyTypeDesc: if n.typ.kind == tyTypeDesc:

View file

@ -1,6 +1,6 @@
discard """ discard """
file: "tstaticparams.nim" file: "tstaticparams.nim"
output: "abracadabra\ntest\n3\n15" output: "abracadabra\ntest\n3\n15\4"
""" """
type type
@ -41,3 +41,7 @@ type
var m: AffineTransform3D[float] var m: AffineTransform3D[float]
echo high(m) echo high(m)
proc getRows(mtx: Matrix): int =
result = mtx.M
echo getRows(m)