'addSon' for types deprecated for 'int literal type' analysis

This commit is contained in:
Araq
2012-07-09 08:09:00 +02:00
parent 795afb0021
commit 121d4e0fc2
13 changed files with 49 additions and 33 deletions

View File

@@ -718,7 +718,6 @@ proc lastSon*(n: PType): PType {.inline.}
proc newSons*(father: PNode, length: int) proc newSons*(father: PNode, length: int)
proc newSons*(father: PType, length: int) proc newSons*(father: PType, length: int)
proc addSon*(father, son: PNode) proc addSon*(father, son: PNode)
proc addSon*(father, son: PType)
proc delSon*(father: PNode, idx: int) proc delSon*(father: PNode, idx: int)
proc hasSonWith*(n: PNode, kind: TNodeKind): bool proc hasSonWith*(n: PNode, kind: TNodeKind): bool
proc hasSubnodeWith*(n: PNode, kind: TNodeKind): bool proc hasSubnodeWith*(n: PNode, kind: TNodeKind): bool
@@ -996,11 +995,6 @@ proc newSons(father: PType, length: int) =
else: else:
setlen(father.sons, length) setlen(father.sons, length)
proc addSon(father, son: PType) =
if isNil(father.sons): father.sons = @[]
add(father.sons, son)
#assert((father.kind != tyGenericInvokation) or (son.kind != tyGenericInst))
proc sonsLen(n: PNode): int = proc sonsLen(n: PNode): int =
if isNil(n.sons): result = 0 if isNil(n.sons): result = 0
else: result = len(n.sons) else: result = len(n.sons)
@@ -1011,6 +1005,15 @@ proc newSons(father: PNode, length: int) =
else: else:
setlen(father.sons, length) setlen(father.sons, length)
proc addSon*(father, son: PType) {.deprecated.} =
if isNil(father.sons): father.sons = @[]
add(father.sons, son)
#assert((father.kind != tyGenericInvokation) or (son.kind != tyGenericInst))
proc rawAddSon*(father, son: PType) =
if isNil(father.sons): father.sons = @[]
add(father.sons, son)
proc addSon(father, son: PNode) = proc addSon(father, son: PNode) =
assert son != nil assert son != nil
if isNil(father.sons): father.sons = @[] if isNil(father.sons): father.sons = @[]

View File

@@ -847,10 +847,10 @@ proc genArrayInfo(m: BModule, typ: PType, name: PRope) =
proc fakeClosureType(owner: PSym): PType = proc fakeClosureType(owner: PSym): PType =
# we generate the same RTTI as for a tuple[pointer, ref tuple[]] # we generate the same RTTI as for a tuple[pointer, ref tuple[]]
result = newType(tyTuple, owner) result = newType(tyTuple, owner)
result.addSon(newType(tyPointer, owner)) result.rawAddSon(newType(tyPointer, owner))
var r = newType(tyRef, owner) var r = newType(tyRef, owner)
r.addSon(newType(tyTuple, owner)) r.rawAddSon(newType(tyTuple, owner))
result.addSon(r) result.rawAddSon(r)
type type
TTypeInfoReason = enum ## for what do we need the type info? TTypeInfoReason = enum ## for what do we need the type info?

View File

@@ -592,7 +592,7 @@ proc evalAddr(c: PEvalContext, n: PNode, flags: TEvalFlags): PNode =
if isSpecial(result): return if isSpecial(result): return
var a = result var a = result
var t = newType(tyPtr, c.module) var t = newType(tyPtr, c.module)
addSon(t, a.typ) addSonSkipIntLit(t, a.typ)
result = newNodeIT(nkRefTy, n.info, t) result = newNodeIT(nkRefTy, n.info, t)
addSon(result, a) addSon(result, a)

View File

@@ -164,10 +164,11 @@ proc newEnv(outerProc: PSym, up: PEnv, n: PNode): PEnv =
proc addField(tup: PType, s: PSym) = proc addField(tup: PType, s: PSym) =
var field = newSym(skField, s.name, s.owner) var field = newSym(skField, s.name, s.owner)
field.typ = s.typ let t = skipIntLit(s.typ)
field.typ = t
field.position = sonsLen(tup) field.position = sonsLen(tup)
addSon(tup.n, newSymNode(field)) addSon(tup.n, newSymNode(field))
addSon(tup, s.typ) rawAddSon(tup, t)
proc addCapturedVar(e: PEnv, v: PSym) = proc addCapturedVar(e: PEnv, v: PSym) =
for x in e.capturedVars: for x in e.capturedVars:
@@ -183,7 +184,7 @@ proc addDep(e, d: PEnv, owner: PSym): PSym =
result.typ = newType(tyRef, owner) result.typ = newType(tyRef, owner)
result.position = pos result.position = pos
assert d.tup != nil assert d.tup != nil
addSon(result.typ, d.tup) rawAddSon(result.typ, d.tup)
addField(e.tup, result) addField(e.tup, result)
e.deps.add((d, result)) e.deps.add((d, result))
@@ -223,7 +224,7 @@ proc addClosureParam(i: PInnerContext, e: PEnv) =
cp.info = i.fn.info cp.info = i.fn.info
incl(cp.flags, sfFromGeneric) incl(cp.flags, sfFromGeneric)
cp.typ = newType(tyRef, i.fn) cp.typ = newType(tyRef, i.fn)
addSon(cp.typ, e.tup) rawAddSon(cp.typ, e.tup)
i.closureParam = cp i.closureParam = cp
addHiddenParam(i.fn, i.closureParam) addHiddenParam(i.fn, i.closureParam)
#echo "closure param added for ", i.fn.name.s, " ", i.fn.id #echo "closure param added for ", i.fn.name.s, " ", i.fn.id
@@ -408,7 +409,7 @@ proc getClosureVar(o: POuterContext, e: PEnv): PSym =
incl(result.flags, sfShadowed) incl(result.flags, sfShadowed)
result.info = e.attachedNode.info result.info = e.attachedNode.info
result.typ = newType(tyRef, o.fn) result.typ = newType(tyRef, o.fn)
result.typ.addSon(e.tup) result.typ.rawAddSon(e.tup)
e.closure = result e.closure = result
else: else:
result = e.closure result = e.closure

View File

@@ -92,6 +92,16 @@ proc getIntLitType*(literal: PNode): PType =
result = copyType(ti, ti.owner, false) result = copyType(ti, ti.owner, false)
result.n = literal result.n = literal
proc skipIntLit*(t: PType): PType {.inline.} =
if t.kind == tyInt and t.n != nil:
result = getSysType(tyInt)
else:
result = t
proc AddSonSkipIntLit*(father, son: PType) =
if isNil(father.sons): father.sons = @[]
add(father.sons, son.skipIntLit)
proc setIntLitType*(result: PNode) = proc setIntLitType*(result: PNode) =
let i = result.intVal let i = result.intVal
case platform.IntSize case platform.IntSize

View File

@@ -88,7 +88,7 @@
import import
os, options, strutils, nversion, ast, astalgo, msgs, platform, condsyms, os, options, strutils, nversion, ast, astalgo, msgs, platform, condsyms,
ropes, idents, crc, idgen, rodutils, memfiles ropes, idents, crc, idgen, types, rodutils, memfiles
type type
TReasonForRecompile* = enum ## all the reasons that can trigger recompilation TReasonForRecompile* = enum ## all the reasons that can trigger recompilation
@@ -335,10 +335,10 @@ proc decodeType(r: PRodReader, info: TLineInfo): PType =
inc(r.pos) inc(r.pos)
if r.s[r.pos] == ')': inc(r.pos) if r.s[r.pos] == ')': inc(r.pos)
else: InternalError(info, "decodeType ^(" & r.s[r.pos]) else: InternalError(info, "decodeType ^(" & r.s[r.pos])
addSon(result, nil) rawAddSon(result, nil)
else: else:
var d = decodeVInt(r.s, r.pos) var d = decodeVInt(r.s, r.pos)
addSon(result, rrGetType(r, d, info)) rawAddSon(result, rrGetType(r, d, info))
proc decodeLib(r: PRodReader, info: TLineInfo): PLib = proc decodeLib(r: PRodReader, info: TLineInfo): PLib =
result = nil result = nil

View File

@@ -180,15 +180,15 @@ proc addToLib(lib: PLib, sym: PSym) =
proc makePtrType(c: PContext, baseType: PType): PType = proc makePtrType(c: PContext, baseType: PType): PType =
result = newTypeS(tyPtr, c) result = newTypeS(tyPtr, c)
addSon(result, baseType.AssertNotNil) addSonSkipIntLit(result, baseType.AssertNotNil)
proc makeVarType(c: PContext, baseType: PType): PType = proc makeVarType(c: PContext, baseType: PType): PType =
result = newTypeS(tyVar, c) result = newTypeS(tyVar, c)
addSon(result, baseType.AssertNotNil) addSonSkipIntLit(result, baseType.AssertNotNil)
proc makeTypeDesc*(c: PContext, typ: PType): PType = proc makeTypeDesc*(c: PContext, typ: PType): PType =
result = newTypeS(tyTypeDesc, c) result = newTypeS(tyTypeDesc, c)
result.addSon(typ.AssertNotNil) result.addSonSkipIntLit(typ.AssertNotNil)
proc newTypeS(kind: TTypeKind, c: PContext): PType = proc newTypeS(kind: TTypeKind, c: PContext): PType =
result = newType(kind, getCurrOwner()) result = newType(kind, getCurrOwner())
@@ -205,7 +205,7 @@ proc makeRangeType*(c: PContext, first, last: biggestInt,
addSon(n, newIntNode(nkIntLit, last)) addSon(n, newIntNode(nkIntLit, last))
result = newTypeS(tyRange, c) result = newTypeS(tyRange, c)
result.n = n result.n = n
addSon(result, getSysType(tyInt)) # basetype of range rawAddSon(result, getSysType(tyInt)) # basetype of range
proc markUsed*(n: PNode, s: PSym) = proc markUsed*(n: PNode, s: PSym) =
incl(s.flags, sfUsed) incl(s.flags, sfUsed)

View File

@@ -115,7 +115,7 @@ proc makeRange(typ: PType, first, last: biggestInt): PType =
addSon(n, newIntNode(nkIntLit, max(first, last))) addSon(n, newIntNode(nkIntLit, max(first, last)))
result = newType(tyRange, typ.owner) result = newType(tyRange, typ.owner)
result.n = n result.n = n
addSon(result, skipTypes(typ, {tyRange})) addSonSkipIntLit(result, skipTypes(typ, {tyRange}))
proc makeRangeF(typ: PType, first, last: biggestFloat): PType = proc makeRangeF(typ: PType, first, last: biggestFloat): PType =
var n = newNode(nkRange) var n = newNode(nkRange)
@@ -123,7 +123,7 @@ proc makeRangeF(typ: PType, first, last: biggestFloat): PType =
addSon(n, newFloatNode(nkFloatLit, max(first.float, last.float))) addSon(n, newFloatNode(nkFloatLit, max(first.float, last.float)))
result = newType(tyRange, typ.owner) result = newType(tyRange, typ.owner)
result.n = n result.n = n
addSon(result, skipTypes(typ, {tyRange})) addSonSkipIntLit(result, skipTypes(typ, {tyRange}))
proc getIntervalType*(m: TMagic, n: PNode): PType = proc getIntervalType*(m: TMagic, n: PNode): PType =
# Nimrod requires interval arithmetic for ``range`` types. Lots of tedious # Nimrod requires interval arithmetic for ``range`` types. Lots of tedious

View File

@@ -172,7 +172,7 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable,
semParamList(c, n.sons[ParamsPos], nil, result) semParamList(c, n.sons[ParamsPos], nil, result)
else: else:
result.typ = newTypeS(tyProc, c) result.typ = newTypeS(tyProc, c)
addSon(result.typ, nil) rawAddSon(result.typ, nil)
result.typ.callConv = fn.typ.callConv result.typ.callConv = fn.typ.callConv
ParamsTypeCheck(c, result.typ) ParamsTypeCheck(c, result.typ)
var oldPrc = GenericCacheGet(c, entry) var oldPrc = GenericCacheGet(c, entry)

View File

@@ -113,7 +113,7 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
# use ``stmt`` as implicit result type # use ``stmt`` as implicit result type
s.typ = newTypeS(tyProc, c) s.typ = newTypeS(tyProc, c)
s.typ.n = newNodeI(nkFormalParams, n.info) s.typ.n = newNodeI(nkFormalParams, n.info)
addSon(s.typ, newTypeS(tyStmt, c)) rawAddSon(s.typ, newTypeS(tyStmt, c))
addSon(s.typ.n, newNodeIT(nkType, n.info, s.typ.sons[0])) addSon(s.typ.n, newNodeIT(nkType, n.info, s.typ.sons[0]))
else: else:
semParamList(c, n.sons[ParamsPos], nil, s) semParamList(c, n.sons[ParamsPos], nil, s)

View File

@@ -9,7 +9,7 @@
# This module does the instantiation of generic types. # This module does the instantiation of generic types.
import ast, astalgo, msgs, types, semdata, renderer import ast, astalgo, msgs, types, magicsys, semdata, renderer
proc checkPartialConstructedType(info: TLineInfo, t: PType) = proc checkPartialConstructedType(info: TLineInfo, t: PType) =
if tfAcyclic in t.flags and skipTypes(t, abstractInst).kind != tyObject: if tfAcyclic in t.flags and skipTypes(t, abstractInst).kind != tyObject:
@@ -167,14 +167,14 @@ proc handleGenericInvokation(cl: var TReplTypeVars, t: PType): PType =
for i in countup(0, sonsLen(t) - 1): for i in countup(0, sonsLen(t) - 1):
# if one of the params is not concrete, we cannot do anything # if one of the params is not concrete, we cannot do anything
# but we already raised an error! # but we already raised an error!
addSon(result, header.sons[i]) rawAddSon(result, header.sons[i])
var newbody = ReplaceTypeVarsT(cl, lastSon(body)) var newbody = ReplaceTypeVarsT(cl, lastSon(body))
newbody.flags = newbody.flags + t.flags + body.flags newbody.flags = newbody.flags + t.flags + body.flags
result.flags = result.flags + newbody.flags result.flags = result.flags + newbody.flags
newbody.callConv = body.callConv newbody.callConv = body.callConv
newbody.n = ReplaceTypeVarsN(cl, lastSon(body).n) newbody.n = ReplaceTypeVarsN(cl, lastSon(body).n)
addSon(result, newbody) rawAddSon(result, newbody)
checkPartialConstructedType(cl.info, newbody) checkPartialConstructedType(cl.info, newbody)
else: else:
for i in countup(1, sonsLen(t) - 1): for i in countup(1, sonsLen(t) - 1):
@@ -214,6 +214,8 @@ proc ReplaceTypeVarsT*(cl: var TReplTypeVars, t: PType): PType =
of tyGenericBody: of tyGenericBody:
InternalError(cl.info, "ReplaceTypeVarsT: tyGenericBody") InternalError(cl.info, "ReplaceTypeVarsT: tyGenericBody")
result = ReplaceTypeVarsT(cl, lastSon(t)) result = ReplaceTypeVarsT(cl, lastSon(t))
of tyInt:
result = skipIntLit(t)
else: else:
if containsGenericType(t): if containsGenericType(t):
result = copyType(t, t.owner, false) result = copyType(t, t.owner, false)

View File

@@ -139,9 +139,9 @@ proc concreteType(mapping: TIdTable, t: PType): PType =
of tyArrayConstr: of tyArrayConstr:
# make it an array # make it an array
result = newType(tyArray, t.owner) result = newType(tyArray, t.owner)
addSon(result, t.sons[0]) # XXX: t.owner is wrong for ID! addSonSkipIntLit(result, t.sons[0]) # XXX: t.owner is wrong for ID!
addSon(result, t.sons[1]) # XXX: semantic checking for the type? addSonSkipIntLit(result, t.sons[1]) # XXX: semantic checking for the type?
of tyNil: of tyNil:
result = nil # what should it be? result = nil # what should it be?
of tyGenericParam: of tyGenericParam:
result = t result = t

View File

@@ -103,7 +103,7 @@ proc getOrdValue(n: PNode): biggestInt =
result = 0 result = 0
proc isIntLit*(t: PType): bool {.inline.} = proc isIntLit*(t: PType): bool {.inline.} =
result = t.n != nil and t.n.kind == nkIntLit result = t.kind == tyInt and t.n != nil and t.n.kind == nkIntLit
proc isCompatibleToCString(a: PType): bool = proc isCompatibleToCString(a: PType): bool =
if a.kind == tyArray: if a.kind == tyArray: