mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 01:14:41 +00:00
'addSon' for types deprecated for 'int literal type' analysis
This commit is contained in:
@@ -718,7 +718,6 @@ proc lastSon*(n: PType): PType {.inline.}
|
||||
proc newSons*(father: PNode, length: int)
|
||||
proc newSons*(father: PType, length: int)
|
||||
proc addSon*(father, son: PNode)
|
||||
proc addSon*(father, son: PType)
|
||||
proc delSon*(father: PNode, idx: int)
|
||||
proc hasSonWith*(n: PNode, kind: TNodeKind): bool
|
||||
proc hasSubnodeWith*(n: PNode, kind: TNodeKind): bool
|
||||
@@ -996,11 +995,6 @@ proc newSons(father: PType, length: int) =
|
||||
else:
|
||||
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 =
|
||||
if isNil(n.sons): result = 0
|
||||
else: result = len(n.sons)
|
||||
@@ -1011,6 +1005,15 @@ proc newSons(father: PNode, length: int) =
|
||||
else:
|
||||
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) =
|
||||
assert son != nil
|
||||
if isNil(father.sons): father.sons = @[]
|
||||
|
||||
@@ -847,10 +847,10 @@ proc genArrayInfo(m: BModule, typ: PType, name: PRope) =
|
||||
proc fakeClosureType(owner: PSym): PType =
|
||||
# we generate the same RTTI as for a tuple[pointer, ref tuple[]]
|
||||
result = newType(tyTuple, owner)
|
||||
result.addSon(newType(tyPointer, owner))
|
||||
result.rawAddSon(newType(tyPointer, owner))
|
||||
var r = newType(tyRef, owner)
|
||||
r.addSon(newType(tyTuple, owner))
|
||||
result.addSon(r)
|
||||
r.rawAddSon(newType(tyTuple, owner))
|
||||
result.rawAddSon(r)
|
||||
|
||||
type
|
||||
TTypeInfoReason = enum ## for what do we need the type info?
|
||||
|
||||
@@ -592,7 +592,7 @@ proc evalAddr(c: PEvalContext, n: PNode, flags: TEvalFlags): PNode =
|
||||
if isSpecial(result): return
|
||||
var a = result
|
||||
var t = newType(tyPtr, c.module)
|
||||
addSon(t, a.typ)
|
||||
addSonSkipIntLit(t, a.typ)
|
||||
result = newNodeIT(nkRefTy, n.info, t)
|
||||
addSon(result, a)
|
||||
|
||||
|
||||
@@ -164,10 +164,11 @@ proc newEnv(outerProc: PSym, up: PEnv, n: PNode): PEnv =
|
||||
|
||||
proc addField(tup: PType, s: PSym) =
|
||||
var field = newSym(skField, s.name, s.owner)
|
||||
field.typ = s.typ
|
||||
let t = skipIntLit(s.typ)
|
||||
field.typ = t
|
||||
field.position = sonsLen(tup)
|
||||
addSon(tup.n, newSymNode(field))
|
||||
addSon(tup, s.typ)
|
||||
rawAddSon(tup, t)
|
||||
|
||||
proc addCapturedVar(e: PEnv, v: PSym) =
|
||||
for x in e.capturedVars:
|
||||
@@ -183,7 +184,7 @@ proc addDep(e, d: PEnv, owner: PSym): PSym =
|
||||
result.typ = newType(tyRef, owner)
|
||||
result.position = pos
|
||||
assert d.tup != nil
|
||||
addSon(result.typ, d.tup)
|
||||
rawAddSon(result.typ, d.tup)
|
||||
addField(e.tup, result)
|
||||
e.deps.add((d, result))
|
||||
|
||||
@@ -223,7 +224,7 @@ proc addClosureParam(i: PInnerContext, e: PEnv) =
|
||||
cp.info = i.fn.info
|
||||
incl(cp.flags, sfFromGeneric)
|
||||
cp.typ = newType(tyRef, i.fn)
|
||||
addSon(cp.typ, e.tup)
|
||||
rawAddSon(cp.typ, e.tup)
|
||||
i.closureParam = cp
|
||||
addHiddenParam(i.fn, i.closureParam)
|
||||
#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)
|
||||
result.info = e.attachedNode.info
|
||||
result.typ = newType(tyRef, o.fn)
|
||||
result.typ.addSon(e.tup)
|
||||
result.typ.rawAddSon(e.tup)
|
||||
e.closure = result
|
||||
else:
|
||||
result = e.closure
|
||||
|
||||
@@ -92,6 +92,16 @@ proc getIntLitType*(literal: PNode): PType =
|
||||
result = copyType(ti, ti.owner, false)
|
||||
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) =
|
||||
let i = result.intVal
|
||||
case platform.IntSize
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
|
||||
import
|
||||
os, options, strutils, nversion, ast, astalgo, msgs, platform, condsyms,
|
||||
ropes, idents, crc, idgen, rodutils, memfiles
|
||||
ropes, idents, crc, idgen, types, rodutils, memfiles
|
||||
|
||||
type
|
||||
TReasonForRecompile* = enum ## all the reasons that can trigger recompilation
|
||||
@@ -335,10 +335,10 @@ proc decodeType(r: PRodReader, info: TLineInfo): PType =
|
||||
inc(r.pos)
|
||||
if r.s[r.pos] == ')': inc(r.pos)
|
||||
else: InternalError(info, "decodeType ^(" & r.s[r.pos])
|
||||
addSon(result, nil)
|
||||
rawAddSon(result, nil)
|
||||
else:
|
||||
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 =
|
||||
result = nil
|
||||
|
||||
@@ -180,15 +180,15 @@ proc addToLib(lib: PLib, sym: PSym) =
|
||||
|
||||
proc makePtrType(c: PContext, baseType: PType): PType =
|
||||
result = newTypeS(tyPtr, c)
|
||||
addSon(result, baseType.AssertNotNil)
|
||||
addSonSkipIntLit(result, baseType.AssertNotNil)
|
||||
|
||||
proc makeVarType(c: PContext, baseType: PType): PType =
|
||||
result = newTypeS(tyVar, c)
|
||||
addSon(result, baseType.AssertNotNil)
|
||||
addSonSkipIntLit(result, baseType.AssertNotNil)
|
||||
|
||||
proc makeTypeDesc*(c: PContext, typ: PType): PType =
|
||||
result = newTypeS(tyTypeDesc, c)
|
||||
result.addSon(typ.AssertNotNil)
|
||||
result.addSonSkipIntLit(typ.AssertNotNil)
|
||||
|
||||
proc newTypeS(kind: TTypeKind, c: PContext): PType =
|
||||
result = newType(kind, getCurrOwner())
|
||||
@@ -205,7 +205,7 @@ proc makeRangeType*(c: PContext, first, last: biggestInt,
|
||||
addSon(n, newIntNode(nkIntLit, last))
|
||||
result = newTypeS(tyRange, c)
|
||||
result.n = n
|
||||
addSon(result, getSysType(tyInt)) # basetype of range
|
||||
rawAddSon(result, getSysType(tyInt)) # basetype of range
|
||||
|
||||
proc markUsed*(n: PNode, s: PSym) =
|
||||
incl(s.flags, sfUsed)
|
||||
|
||||
@@ -115,7 +115,7 @@ proc makeRange(typ: PType, first, last: biggestInt): PType =
|
||||
addSon(n, newIntNode(nkIntLit, max(first, last)))
|
||||
result = newType(tyRange, typ.owner)
|
||||
result.n = n
|
||||
addSon(result, skipTypes(typ, {tyRange}))
|
||||
addSonSkipIntLit(result, skipTypes(typ, {tyRange}))
|
||||
|
||||
proc makeRangeF(typ: PType, first, last: biggestFloat): PType =
|
||||
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)))
|
||||
result = newType(tyRange, typ.owner)
|
||||
result.n = n
|
||||
addSon(result, skipTypes(typ, {tyRange}))
|
||||
addSonSkipIntLit(result, skipTypes(typ, {tyRange}))
|
||||
|
||||
proc getIntervalType*(m: TMagic, n: PNode): PType =
|
||||
# Nimrod requires interval arithmetic for ``range`` types. Lots of tedious
|
||||
|
||||
@@ -172,7 +172,7 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable,
|
||||
semParamList(c, n.sons[ParamsPos], nil, result)
|
||||
else:
|
||||
result.typ = newTypeS(tyProc, c)
|
||||
addSon(result.typ, nil)
|
||||
rawAddSon(result.typ, nil)
|
||||
result.typ.callConv = fn.typ.callConv
|
||||
ParamsTypeCheck(c, result.typ)
|
||||
var oldPrc = GenericCacheGet(c, entry)
|
||||
|
||||
@@ -113,7 +113,7 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
|
||||
# use ``stmt`` as implicit result type
|
||||
s.typ = newTypeS(tyProc, c)
|
||||
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]))
|
||||
else:
|
||||
semParamList(c, n.sons[ParamsPos], nil, s)
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
# 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) =
|
||||
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):
|
||||
# if one of the params is not concrete, we cannot do anything
|
||||
# but we already raised an error!
|
||||
addSon(result, header.sons[i])
|
||||
rawAddSon(result, header.sons[i])
|
||||
|
||||
var newbody = ReplaceTypeVarsT(cl, lastSon(body))
|
||||
newbody.flags = newbody.flags + t.flags + body.flags
|
||||
result.flags = result.flags + newbody.flags
|
||||
newbody.callConv = body.callConv
|
||||
newbody.n = ReplaceTypeVarsN(cl, lastSon(body).n)
|
||||
addSon(result, newbody)
|
||||
rawAddSon(result, newbody)
|
||||
checkPartialConstructedType(cl.info, newbody)
|
||||
else:
|
||||
for i in countup(1, sonsLen(t) - 1):
|
||||
@@ -214,6 +214,8 @@ proc ReplaceTypeVarsT*(cl: var TReplTypeVars, t: PType): PType =
|
||||
of tyGenericBody:
|
||||
InternalError(cl.info, "ReplaceTypeVarsT: tyGenericBody")
|
||||
result = ReplaceTypeVarsT(cl, lastSon(t))
|
||||
of tyInt:
|
||||
result = skipIntLit(t)
|
||||
else:
|
||||
if containsGenericType(t):
|
||||
result = copyType(t, t.owner, false)
|
||||
|
||||
@@ -139,9 +139,9 @@ proc concreteType(mapping: TIdTable, t: PType): PType =
|
||||
of tyArrayConstr:
|
||||
# make it an array
|
||||
result = newType(tyArray, t.owner)
|
||||
addSon(result, t.sons[0]) # XXX: t.owner is wrong for ID!
|
||||
addSon(result, t.sons[1]) # XXX: semantic checking for the type?
|
||||
of tyNil:
|
||||
addSonSkipIntLit(result, t.sons[0]) # XXX: t.owner is wrong for ID!
|
||||
addSonSkipIntLit(result, t.sons[1]) # XXX: semantic checking for the type?
|
||||
of tyNil:
|
||||
result = nil # what should it be?
|
||||
of tyGenericParam:
|
||||
result = t
|
||||
|
||||
@@ -103,7 +103,7 @@ proc getOrdValue(n: PNode): biggestInt =
|
||||
result = 0
|
||||
|
||||
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 =
|
||||
if a.kind == tyArray:
|
||||
|
||||
Reference in New Issue
Block a user