summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-07-09 08:09:00 +0200
committerAraq <rumpf_a@web.de>2012-07-09 08:09:00 +0200
commit121d4e0fc2d05d7fd3ee8dab3a8c1663c9e5a5c3 (patch)
treee81d1e5d44967dbd8a69918434d33c2c36d73c58
parent795afb0021094d069b5f77d4b7ba6c9e5fc5d803 (diff)
downloadNim-121d4e0fc2d05d7fd3ee8dab3a8c1663c9e5a5c3.tar.gz
'addSon' for types deprecated for 'int literal type' analysis
-rwxr-xr-xcompiler/ast.nim15
-rwxr-xr-xcompiler/ccgtypes.nim6
-rwxr-xr-xcompiler/evals.nim2
-rw-r--r--compiler/lambdalifting.nim11
-rwxr-xr-xcompiler/magicsys.nim10
-rwxr-xr-xcompiler/rodread.nim6
-rwxr-xr-xcompiler/semdata.nim8
-rwxr-xr-xcompiler/semfold.nim4
-rwxr-xr-xcompiler/seminst.nim2
-rwxr-xr-xcompiler/semtempl.nim2
-rwxr-xr-xcompiler/semtypinst.nim8
-rwxr-xr-xcompiler/sigmatch.nim6
-rwxr-xr-xcompiler/types.nim2
13 files changed, 49 insertions, 33 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim
index e3528dece..9cd741cf1 100755
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -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 = @[]
diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim
index 4bbfc072f..0de731598 100755
--- a/compiler/ccgtypes.nim
+++ b/compiler/ccgtypes.nim
@@ -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?
diff --git a/compiler/evals.nim b/compiler/evals.nim
index 3ef2f4f3b..dd975eb91 100755
--- a/compiler/evals.nim
+++ b/compiler/evals.nim
@@ -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)
 
diff --git a/compiler/lambdalifting.nim b/compiler/lambdalifting.nim
index ab824b92a..feaeb96c4 100644
--- a/compiler/lambdalifting.nim
+++ b/compiler/lambdalifting.nim
@@ -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
diff --git a/compiler/magicsys.nim b/compiler/magicsys.nim
index fcfc35ff1..19d19b5f9 100755
--- a/compiler/magicsys.nim
+++ b/compiler/magicsys.nim
@@ -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
diff --git a/compiler/rodread.nim b/compiler/rodread.nim
index c3123161b..a600d14c1 100755
--- a/compiler/rodread.nim
+++ b/compiler/rodread.nim
@@ -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
diff --git a/compiler/semdata.nim b/compiler/semdata.nim
index 9eff8c4f4..b524881da 100755
--- a/compiler/semdata.nim
+++ b/compiler/semdata.nim
@@ -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)
diff --git a/compiler/semfold.nim b/compiler/semfold.nim
index 061a29fad..9a6665229 100755
--- a/compiler/semfold.nim
+++ b/compiler/semfold.nim
@@ -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
diff --git a/compiler/seminst.nim b/compiler/seminst.nim
index a2f4129ea..47806af62 100755
--- a/compiler/seminst.nim
+++ b/compiler/seminst.nim
@@ -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)
diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim
index b0debc75b..b09f50306 100755
--- a/compiler/semtempl.nim
+++ b/compiler/semtempl.nim
@@ -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)
diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim
index bfd706bea..ab7478a54 100755
--- a/compiler/semtypinst.nim
+++ b/compiler/semtypinst.nim
@@ -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)
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 4a7ba9587..bb3a24823 100755
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -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
diff --git a/compiler/types.nim b/compiler/types.nim
index 3a9352a0d..cbf36b16d 100755
--- a/compiler/types.nim
+++ b/compiler/types.nim
@@ -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: