preparations for C++ template support
This commit is contained in:
parent
e2147c9f0d
commit
6004280522
6 changed files with 25 additions and 21 deletions
|
|
@ -229,8 +229,9 @@ proc genOptAsgnTuple(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||||
flags - {needToCopy}
|
flags - {needToCopy}
|
||||||
else:
|
else:
|
||||||
flags
|
flags
|
||||||
for i in 0 .. <dest.t.len:
|
let t = skipTypes(dest.t, abstractInst)
|
||||||
let t = dest.t.sons[i]
|
for i in 0 .. <t.len:
|
||||||
|
let t = t.sons[i]
|
||||||
let field = ropef("Field$1", i.toRope)
|
let field = ropef("Field$1", i.toRope)
|
||||||
genAssignment(p, optAsgnLoc(dest, t, field),
|
genAssignment(p, optAsgnLoc(dest, t, field),
|
||||||
optAsgnLoc(src, t, field), newflags)
|
optAsgnLoc(src, t, field), newflags)
|
||||||
|
|
@ -328,7 +329,9 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||||
linefmt(p, cpsStmts, "$1 = $2;$n", rdLoc(dest), rdLoc(src))
|
linefmt(p, cpsStmts, "$1 = $2;$n", rdLoc(dest), rdLoc(src))
|
||||||
of tyObject:
|
of tyObject:
|
||||||
# XXX: check for subtyping?
|
# XXX: check for subtyping?
|
||||||
if not isObjLackingTypeField(ty):
|
if ty.isImportedCppType:
|
||||||
|
linefmt(p, cpsStmts, "$1 = $2;$n", rdLoc(dest), rdLoc(src))
|
||||||
|
elif not isObjLackingTypeField(ty):
|
||||||
genGenericAsgn(p, dest, src, flags)
|
genGenericAsgn(p, dest, src, flags)
|
||||||
elif needsComplexAssignment(ty):
|
elif needsComplexAssignment(ty):
|
||||||
if ty.sons[0].isNil and asgnComplexity(ty.n) <= 4:
|
if ty.sons[0].isNil and asgnComplexity(ty.n) <= 4:
|
||||||
|
|
@ -411,7 +414,7 @@ proc putDataIntoDest(p: BProc, d: var TLoc, t: PType, r: PRope) =
|
||||||
var a: TLoc
|
var a: TLoc
|
||||||
if d.k != locNone:
|
if d.k != locNone:
|
||||||
# need to generate an assignment here
|
# need to generate an assignment here
|
||||||
initLoc(a, locData, getUniqueType(t), OnUnknown)
|
initLoc(a, locData, t, OnUnknown)
|
||||||
a.r = r
|
a.r = r
|
||||||
if lfNoDeepCopy in d.flags: genAssignment(p, d, a, {})
|
if lfNoDeepCopy in d.flags: genAssignment(p, d, a, {})
|
||||||
else: genAssignment(p, d, a, {needToCopy})
|
else: genAssignment(p, d, a, {needToCopy})
|
||||||
|
|
@ -419,14 +422,14 @@ proc putDataIntoDest(p: BProc, d: var TLoc, t: PType, r: PRope) =
|
||||||
# we cannot call initLoc() here as that would overwrite
|
# we cannot call initLoc() here as that would overwrite
|
||||||
# the flags field!
|
# the flags field!
|
||||||
d.k = locData
|
d.k = locData
|
||||||
d.t = getUniqueType(t)
|
d.t = t
|
||||||
d.r = r
|
d.r = r
|
||||||
|
|
||||||
proc putIntoDest(p: BProc, d: var TLoc, t: PType, r: PRope) =
|
proc putIntoDest(p: BProc, d: var TLoc, t: PType, r: PRope) =
|
||||||
var a: TLoc
|
var a: TLoc
|
||||||
if d.k != locNone:
|
if d.k != locNone:
|
||||||
# need to generate an assignment here
|
# need to generate an assignment here
|
||||||
initLoc(a, locExpr, getUniqueType(t), OnUnknown)
|
initLoc(a, locExpr, t, OnUnknown)
|
||||||
a.r = r
|
a.r = r
|
||||||
if lfNoDeepCopy in d.flags: genAssignment(p, d, a, {})
|
if lfNoDeepCopy in d.flags: genAssignment(p, d, a, {})
|
||||||
else: genAssignment(p, d, a, {needToCopy})
|
else: genAssignment(p, d, a, {needToCopy})
|
||||||
|
|
@ -434,7 +437,7 @@ proc putIntoDest(p: BProc, d: var TLoc, t: PType, r: PRope) =
|
||||||
# we cannot call initLoc() here as that would overwrite
|
# we cannot call initLoc() here as that would overwrite
|
||||||
# the flags field!
|
# the flags field!
|
||||||
d.k = locExpr
|
d.k = locExpr
|
||||||
d.t = getUniqueType(t)
|
d.t = t
|
||||||
d.r = r
|
d.r = r
|
||||||
|
|
||||||
proc binaryStmt(p: BProc, e: PNode, d: var TLoc, frmt: string) =
|
proc binaryStmt(p: BProc, e: PNode, d: var TLoc, frmt: string) =
|
||||||
|
|
@ -684,7 +687,7 @@ proc genDeref(p: BProc, e: PNode, d: var TLoc; enforceDeref=false) =
|
||||||
# so the '&' and '*' cancel out:
|
# so the '&' and '*' cancel out:
|
||||||
putIntoDest(p, d, a.t.sons[0], rdLoc(a))
|
putIntoDest(p, d, a.t.sons[0], rdLoc(a))
|
||||||
else:
|
else:
|
||||||
putIntoDest(p, d, a.t.sons[0], ropef("(*$1)", [rdLoc(a)]))
|
putIntoDest(p, d, e.typ, ropef("(*$1)", [rdLoc(a)]))
|
||||||
|
|
||||||
proc genAddr(p: BProc, e: PNode, d: var TLoc) =
|
proc genAddr(p: BProc, e: PNode, d: var TLoc) =
|
||||||
# careful 'addr(myptrToArray)' needs to get the ampersand:
|
# careful 'addr(myptrToArray)' needs to get the ampersand:
|
||||||
|
|
@ -710,7 +713,7 @@ proc genRecordFieldAux(p: BProc, e: PNode, d, a: var TLoc): PType =
|
||||||
if e.sons[1].kind != nkSym: internalError(e.info, "genRecordFieldAux")
|
if e.sons[1].kind != nkSym: internalError(e.info, "genRecordFieldAux")
|
||||||
d.inheritLocation(a)
|
d.inheritLocation(a)
|
||||||
discard getTypeDesc(p.module, a.t) # fill the record's fields.loc
|
discard getTypeDesc(p.module, a.t) # fill the record's fields.loc
|
||||||
result = a.t
|
result = a.t.getUniqueType
|
||||||
|
|
||||||
proc genTupleElem(p: BProc, e: PNode, d: var TLoc) =
|
proc genTupleElem(p: BProc, e: PNode, d: var TLoc) =
|
||||||
var
|
var
|
||||||
|
|
@ -719,7 +722,7 @@ proc genTupleElem(p: BProc, e: PNode, d: var TLoc) =
|
||||||
initLocExpr(p, e.sons[0], a)
|
initLocExpr(p, e.sons[0], a)
|
||||||
d.inheritLocation(a)
|
d.inheritLocation(a)
|
||||||
discard getTypeDesc(p.module, a.t) # fill the record's fields.loc
|
discard getTypeDesc(p.module, a.t) # fill the record's fields.loc
|
||||||
var ty = a.t
|
var ty = a.t.getUniqueType
|
||||||
var r = rdLoc(a)
|
var r = rdLoc(a)
|
||||||
case e.sons[1].kind
|
case e.sons[1].kind
|
||||||
of nkIntLit..nkUInt64Lit: i = int(e.sons[1].intVal)
|
of nkIntLit..nkUInt64Lit: i = int(e.sons[1].intVal)
|
||||||
|
|
|
||||||
|
|
@ -298,7 +298,10 @@ proc genProcParams(m: BModule, t: PType, rettype, params: var PRope,
|
||||||
params = con("(", params)
|
params = con("(", params)
|
||||||
|
|
||||||
proc isImportedType(t: PType): bool =
|
proc isImportedType(t: PType): bool =
|
||||||
result = (t.sym != nil) and (sfImportc in t.sym.flags)
|
result = t.sym != nil and sfImportc in t.sym.flags
|
||||||
|
|
||||||
|
proc isImportedCppType(t: PType): bool =
|
||||||
|
result = t.sym != nil and sfInfixCall in t.sym.flags
|
||||||
|
|
||||||
proc typeNameOrLiteral(t: PType, literal: string): PRope =
|
proc typeNameOrLiteral(t: PType, literal: string): PRope =
|
||||||
if (t.sym != nil) and (sfImportc in t.sym.flags) and (t.sym.magic == mNone):
|
if (t.sym != nil) and (sfImportc in t.sym.flags) and (t.sym.magic == mNone):
|
||||||
|
|
|
||||||
|
|
@ -75,8 +75,7 @@ proc getUniqueType*(key: PType): PType =
|
||||||
if key == nil: return
|
if key == nil: return
|
||||||
var k = key.kind
|
var k = key.kind
|
||||||
case k
|
case k
|
||||||
of tyBool, tyChar,
|
of tyBool, tyChar, tyInt..tyUInt64:
|
||||||
tyInt..tyUInt64:
|
|
||||||
# no canonicalization for integral types, so that e.g. ``pid_t`` is
|
# no canonicalization for integral types, so that e.g. ``pid_t`` is
|
||||||
# produced instead of ``NI``.
|
# produced instead of ``NI``.
|
||||||
result = key
|
result = key
|
||||||
|
|
@ -86,8 +85,7 @@ proc getUniqueType*(key: PType): PType =
|
||||||
if result == nil:
|
if result == nil:
|
||||||
gCanonicalTypes[k] = key
|
gCanonicalTypes[k] = key
|
||||||
result = key
|
result = key
|
||||||
of tyTypeDesc, tyTypeClasses, tyGenericParam,
|
of tyTypeDesc, tyTypeClasses, tyGenericParam, tyFromExpr, tyFieldAccessor:
|
||||||
tyFromExpr, tyFieldAccessor:
|
|
||||||
internalError("GetUniqueType")
|
internalError("GetUniqueType")
|
||||||
of tyDistinct:
|
of tyDistinct:
|
||||||
if key.deepCopy != nil: result = key
|
if key.deepCopy != nil: result = key
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ proc emitLazily(s: PSym): bool {.inline.} =
|
||||||
proc initLoc(result: var TLoc, k: TLocKind, typ: PType, s: TStorageLoc) =
|
proc initLoc(result: var TLoc, k: TLocKind, typ: PType, s: TStorageLoc) =
|
||||||
result.k = k
|
result.k = k
|
||||||
result.s = s
|
result.s = s
|
||||||
result.t = getUniqueType(typ)
|
result.t = typ
|
||||||
result.r = nil
|
result.r = nil
|
||||||
result.flags = {}
|
result.flags = {}
|
||||||
|
|
||||||
|
|
@ -61,7 +61,7 @@ proc fillLoc(a: var TLoc, k: TLocKind, typ: PType, r: PRope, s: TStorageLoc) =
|
||||||
# fills the loc if it is not already initialized
|
# fills the loc if it is not already initialized
|
||||||
if a.k == locNone:
|
if a.k == locNone:
|
||||||
a.k = k
|
a.k = k
|
||||||
a.t = getUniqueType(typ)
|
a.t = typ
|
||||||
a.s = s
|
a.s = s
|
||||||
if a.r == nil: a.r = r
|
if a.r == nil: a.r = r
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -178,9 +178,9 @@ proc semStmtScope(c: PContext, n: PNode): PNode
|
||||||
proc typeAllowedCheck(info: TLineInfo; typ: PType; kind: TSymKind) =
|
proc typeAllowedCheck(info: TLineInfo; typ: PType; kind: TSymKind) =
|
||||||
let t = typeAllowed(typ, kind)
|
let t = typeAllowed(typ, kind)
|
||||||
if t != nil:
|
if t != nil:
|
||||||
if t == typ: localError(info, "invalid type: " & typeToString(typ))
|
if t == typ: localError(info, "invalid type: '" & typeToString(typ) & "'")
|
||||||
else: localError(info, "invalid type: " & typeToString(t) &
|
else: localError(info, "invalid type: '" & typeToString(t) &
|
||||||
" in this context: " & typeToString(typ))
|
"' in this context: '" & typeToString(typ) & "'")
|
||||||
|
|
||||||
proc paramsTypeCheck(c: PContext, typ: PType) {.inline.} =
|
proc paramsTypeCheck(c: PContext, typ: PType) {.inline.} =
|
||||||
typeAllowedCheck(typ.n.info, typ, skConst)
|
typeAllowedCheck(typ.n.info, typ, skConst)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ discard """
|
||||||
cmd: "nim check $options $file"
|
cmd: "nim check $options $file"
|
||||||
errormsg: "'proc' is not a concrete type"
|
errormsg: "'proc' is not a concrete type"
|
||||||
errormsg: "'Foo' is not a concrete type."
|
errormsg: "'Foo' is not a concrete type."
|
||||||
errormsg: "invalid type: 'TBaseMed'"
|
errormsg: "invalid type: 'proc' in this context: 'TBaseMed'"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue