diff options
author | Araq <rumpf_a@web.de> | 2015-01-22 13:32:20 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2015-01-23 00:36:58 +0100 |
commit | 60042805222d1261592db9d782df96ae190d71d5 (patch) | |
tree | 7ac4060d24ea3e799c1e6cfa0fbf0d54231f4c7a /compiler | |
parent | e2147c9f0d57ad03cd2c1fbf386b90fcbc1c658f (diff) | |
download | Nim-60042805222d1261592db9d782df96ae190d71d5.tar.gz |
preparations for C++ template support
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/ccgexprs.nim | 23 | ||||
-rw-r--r-- | compiler/ccgtypes.nim | 5 | ||||
-rw-r--r-- | compiler/ccgutils.nim | 6 | ||||
-rw-r--r-- | compiler/cgen.nim | 4 | ||||
-rw-r--r-- | compiler/sem.nim | 6 |
5 files changed, 24 insertions, 20 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 90aefd7d6..98fb25899 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -229,8 +229,9 @@ proc genOptAsgnTuple(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = flags - {needToCopy} else: flags - for i in 0 .. <dest.t.len: - let t = dest.t.sons[i] + let t = skipTypes(dest.t, abstractInst) + for i in 0 .. <t.len: + let t = t.sons[i] let field = ropef("Field$1", i.toRope) genAssignment(p, optAsgnLoc(dest, t, field), 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)) of tyObject: # 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) elif needsComplexAssignment(ty): 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 if d.k != locNone: # need to generate an assignment here - initLoc(a, locData, getUniqueType(t), OnUnknown) + initLoc(a, locData, t, OnUnknown) a.r = r if lfNoDeepCopy in d.flags: genAssignment(p, d, a, {}) 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 # the flags field! d.k = locData - d.t = getUniqueType(t) + d.t = t d.r = r proc putIntoDest(p: BProc, d: var TLoc, t: PType, r: PRope) = var a: TLoc if d.k != locNone: # need to generate an assignment here - initLoc(a, locExpr, getUniqueType(t), OnUnknown) + initLoc(a, locExpr, t, OnUnknown) a.r = r if lfNoDeepCopy in d.flags: genAssignment(p, d, a, {}) 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 # the flags field! d.k = locExpr - d.t = getUniqueType(t) + d.t = t d.r = r 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: putIntoDest(p, d, a.t.sons[0], rdLoc(a)) 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) = # 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") d.inheritLocation(a) 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) = var @@ -719,7 +722,7 @@ proc genTupleElem(p: BProc, e: PNode, d: var TLoc) = initLocExpr(p, e.sons[0], a) d.inheritLocation(a) 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) case e.sons[1].kind of nkIntLit..nkUInt64Lit: i = int(e.sons[1].intVal) diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 12dd2a8de..cfddd0efe 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -298,7 +298,10 @@ proc genProcParams(m: BModule, t: PType, rettype, params: var PRope, params = con("(", params) 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 = if (t.sym != nil) and (sfImportc in t.sym.flags) and (t.sym.magic == mNone): diff --git a/compiler/ccgutils.nim b/compiler/ccgutils.nim index 7396c0bf8..1e1fcd6fb 100644 --- a/compiler/ccgutils.nim +++ b/compiler/ccgutils.nim @@ -75,8 +75,7 @@ proc getUniqueType*(key: PType): PType = if key == nil: return var k = key.kind case k - of tyBool, tyChar, - tyInt..tyUInt64: + of tyBool, tyChar, tyInt..tyUInt64: # no canonicalization for integral types, so that e.g. ``pid_t`` is # produced instead of ``NI``. result = key @@ -86,8 +85,7 @@ proc getUniqueType*(key: PType): PType = if result == nil: gCanonicalTypes[k] = key result = key - of tyTypeDesc, tyTypeClasses, tyGenericParam, - tyFromExpr, tyFieldAccessor: + of tyTypeDesc, tyTypeClasses, tyGenericParam, tyFromExpr, tyFieldAccessor: internalError("GetUniqueType") of tyDistinct: if key.deepCopy != nil: result = key diff --git a/compiler/cgen.nim b/compiler/cgen.nim index f3fa6a63e..480c131ae 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -53,7 +53,7 @@ proc emitLazily(s: PSym): bool {.inline.} = proc initLoc(result: var TLoc, k: TLocKind, typ: PType, s: TStorageLoc) = result.k = k result.s = s - result.t = getUniqueType(typ) + result.t = typ result.r = nil 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 if a.k == locNone: a.k = k - a.t = getUniqueType(typ) + a.t = typ a.s = s if a.r == nil: a.r = r diff --git a/compiler/sem.nim b/compiler/sem.nim index 5e7ce6bb7..90037fccd 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -178,9 +178,9 @@ proc semStmtScope(c: PContext, n: PNode): PNode proc typeAllowedCheck(info: TLineInfo; typ: PType; kind: TSymKind) = let t = typeAllowed(typ, kind) if t != nil: - if t == typ: localError(info, "invalid type: " & typeToString(typ)) - else: localError(info, "invalid type: " & typeToString(t) & - " in this context: " & typeToString(typ)) + if t == typ: localError(info, "invalid type: '" & typeToString(typ) & "'") + else: localError(info, "invalid type: '" & typeToString(t) & + "' in this context: '" & typeToString(typ) & "'") proc paramsTypeCheck(c: PContext, typ: PType) {.inline.} = typeAllowedCheck(typ.n.info, typ, skConst) |