cString => cSourceString; tyCString => tyCstring so that error msgs show cstring, not cString (#17744)

This commit is contained in:
Timothee Cour 2021-04-17 02:14:09 -07:00 • committed by GitHub
commit 7e94420847
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 79 additions and 79 deletions

View file

@ -379,7 +379,7 @@ type
tySequence, tySequence,
tyProc, tyProc,
tyPointer, tyOpenArray, tyPointer, tyOpenArray,
tyString, tyCString, tyForward, tyString, tyCstring, tyForward,
tyInt, tyInt8, tyInt16, tyInt32, tyInt64, # signed integers tyInt, tyInt8, tyInt16, tyInt32, tyInt64, # signed integers
tyFloat, tyFloat32, tyFloat64, tyFloat128, tyFloat, tyFloat32, tyFloat64, tyFloat128,
tyUInt, tyUInt8, tyUInt16, tyUInt32, tyUInt64, tyUInt, tyUInt8, tyUInt16, tyUInt32, tyUInt64,
@ -1005,13 +1005,13 @@ const
tyBool, tyChar, tyEnum, tyArray, tyObject, tyBool, tyChar, tyEnum, tyArray, tyObject,
tySet, tyTuple, tyRange, tyPtr, tyRef, tyVar, tyLent, tySequence, tyProc, tySet, tyTuple, tyRange, tyPtr, tyRef, tyVar, tyLent, tySequence, tyProc,
tyPointer, tyPointer,
tyOpenArray, tyString, tyCString, tyInt..tyInt64, tyFloat..tyFloat128, tyOpenArray, tyString, tyCstring, tyInt..tyInt64, tyFloat..tyFloat128,
tyUInt..tyUInt64} tyUInt..tyUInt64}
IntegralTypes* = {tyBool, tyChar, tyEnum, tyInt..tyInt64, IntegralTypes* = {tyBool, tyChar, tyEnum, tyInt..tyInt64,
tyFloat..tyFloat128, tyUInt..tyUInt64} # weird name because it contains tyFloat tyFloat..tyFloat128, tyUInt..tyUInt64} # weird name because it contains tyFloat
ConstantDataTypes*: TTypeKinds = {tyArray, tySet, ConstantDataTypes*: TTypeKinds = {tyArray, tySet,
tyTuple, tySequence} tyTuple, tySequence}
NilableTypes*: TTypeKinds = {tyPointer, tyCString, tyRef, tyPtr, NilableTypes*: TTypeKinds = {tyPointer, tyCstring, tyRef, tyPtr,
tyProc, tyError} # TODO tyProc, tyError} # TODO
PtrLikeKinds*: TTypeKinds = {tyPointer, tyPtr} # for VM PtrLikeKinds*: TTypeKinds = {tyPointer, tyPtr} # for VM
PersistentNodeFlags*: TNodeFlags = {nfBase2, nfBase8, nfBase16, PersistentNodeFlags*: TNodeFlags = {nfBase2, nfBase8, nfBase16,

View file

@ -178,7 +178,7 @@ proc genOpenArraySlice(p: BProc; q: PNode; formalType, destType: PType): (Rope,
else: else:
result = ("($3*)($1)+($2)" % [rdLoc(a), rdLoc(b), dest], result = ("($3*)($1)+($2)" % [rdLoc(a), rdLoc(b), dest],
lengthExpr) lengthExpr)
of tyUncheckedArray, tyCString: of tyUncheckedArray, tyCstring:
result = ("($3*)($1)+($2)" % [rdLoc(a), rdLoc(b), dest], result = ("($3*)($1)+($2)" % [rdLoc(a), rdLoc(b), dest],
lengthExpr) lengthExpr)
of tyString, tySequence: of tyString, tySequence:

View file

@ -399,7 +399,7 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
[rdLoc(dest), rdLoc(src), getSize(p.config, dest.t)]) [rdLoc(dest), rdLoc(src), getSize(p.config, dest.t)])
else: else:
linefmt(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)]) linefmt(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)])
of tyPtr, tyPointer, tyChar, tyBool, tyEnum, tyCString, of tyPtr, tyPointer, tyChar, tyBool, tyEnum, tyCstring,
tyInt..tyUInt64, tyRange, tyVar, tyLent, tyNil: tyInt..tyUInt64, tyRange, tyVar, tyLent, tyNil:
linefmt(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)]) linefmt(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)])
else: internalError(p.config, "genAssignment: " & $ty.kind) else: internalError(p.config, "genAssignment: " & $ty.kind)
@ -449,7 +449,7 @@ proc genDeepCopy(p: BProc; dest, src: TLoc) =
[rdLoc(dest), rdLoc(src), getSize(p.config, dest.t)]) [rdLoc(dest), rdLoc(src), getSize(p.config, dest.t)])
else: else:
linefmt(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)]) linefmt(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)])
of tyPointer, tyChar, tyBool, tyEnum, tyCString, of tyPointer, tyChar, tyBool, tyEnum, tyCstring,
tyInt..tyUInt64, tyRange, tyVar, tyLent: tyInt..tyUInt64, tyRange, tyVar, tyLent:
linefmt(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)]) linefmt(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)])
else: internalError(p.config, "genDeepCopy: " & $ty.kind) else: internalError(p.config, "genDeepCopy: " & $ty.kind)
@ -1016,7 +1016,7 @@ proc genBracketExpr(p: BProc; n: PNode; d: var TLoc) =
of tyArray: genArrayElem(p, n, n[0], n[1], d) of tyArray: genArrayElem(p, n, n[0], n[1], d)
of tyOpenArray, tyVarargs: genOpenArrayElem(p, n, n[0], n[1], d) of tyOpenArray, tyVarargs: genOpenArrayElem(p, n, n[0], n[1], d)
of tySequence, tyString: genSeqElem(p, n, n[0], n[1], d) of tySequence, tyString: genSeqElem(p, n, n[0], n[1], d)
of tyCString: genCStringElem(p, n, n[0], n[1], d) of tyCstring: genCStringElem(p, n, n[0], n[1], d)
of tyTuple: genTupleElem(p, n, d) of tyTuple: genTupleElem(p, n, d)
else: internalError(p.config, n.info, "expr(nkBracketExpr, " & $ty.kind & ')') else: internalError(p.config, n.info, "expr(nkBracketExpr, " & $ty.kind & ')')
discard getTypeDesc(p.module, n.typ) discard getTypeDesc(p.module, n.typ)
@ -1666,7 +1666,7 @@ proc genRepr(p: BProc, e: PNode, d: var TLoc) =
putIntoDest(p, d, e, putIntoDest(p, d, e,
ropecg(p.module, "#reprOpenArray($1, $2)", [rdLoc(b), ropecg(p.module, "#reprOpenArray($1, $2)", [rdLoc(b),
genTypeInfoV1(p.module, elemType(t), e.info)]), a.storage) genTypeInfoV1(p.module, elemType(t), e.info)]), a.storage)
of tyCString, tyArray, tyRef, tyPtr, tyPointer, tyNil, tySequence: of tyCstring, tyArray, tyRef, tyPtr, tyPointer, tyNil, tySequence:
putIntoDest(p, d, e, putIntoDest(p, d, e,
ropecg(p.module, "#reprAny($1, $2)", [ ropecg(p.module, "#reprAny($1, $2)", [
rdLoc(a), genTypeInfoV1(p.module, t, e.info)]), a.storage) rdLoc(a), genTypeInfoV1(p.module, t, e.info)]), a.storage)
@ -1745,7 +1745,7 @@ proc genArrayLen(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
else: else:
if op == mHigh: unaryExpr(p, e, d, "($1.Field1-1)") if op == mHigh: unaryExpr(p, e, d, "($1.Field1-1)")
else: unaryExpr(p, e, d, "$1.Field1") else: unaryExpr(p, e, d, "$1.Field1")
of tyCString: of tyCstring:
if op == mHigh: unaryExpr(p, e, d, "($1 ? (#nimCStrLen($1)-1) : -1)") if op == mHigh: unaryExpr(p, e, d, "($1 ? (#nimCStrLen($1)-1) : -1)")
else: unaryExpr(p, e, d, "($1 ? #nimCStrLen($1) : 0)") else: unaryExpr(p, e, d, "($1 ? #nimCStrLen($1) : 0)")
of tyString: of tyString:
@ -2920,7 +2920,7 @@ proc getDefaultValue(p: BProc; typ: PType; info: TLineInfo): Rope =
of tyBool: result = rope"NIM_FALSE" of tyBool: result = rope"NIM_FALSE"
of tyEnum, tyChar, tyInt..tyInt64, tyUInt..tyUInt64: result = rope"0" of tyEnum, tyChar, tyInt..tyInt64, tyUInt..tyUInt64: result = rope"0"
of tyFloat..tyFloat128: result = rope"0.0" of tyFloat..tyFloat128: result = rope"0.0"
of tyCString, tyVar, tyLent, tyPointer, tyPtr, tyUntyped, of tyCstring, tyVar, tyLent, tyPointer, tyPtr, tyUntyped,
tyTyped, tyTypeDesc, tyStatic, tyRef, tyNil: tyTyped, tyTypeDesc, tyStatic, tyRef, tyNil:
result = rope"NIM_NIL" result = rope"NIM_NIL"
of tyString, tySequence: of tyString, tySequence:
@ -3187,7 +3187,7 @@ proc genBracedInit(p: BProc, n: PNode; isConst: bool; optionalType: PType): Rope
of tyObject: of tyObject:
result = genConstObjConstr(p, n, isConst) result = genConstObjConstr(p, n, isConst)
of tyString, tyCString: of tyString, tyCstring:
if optSeqDestructors in p.config.globalOptions and n.kind != nkNilLit and ty == tyString: if optSeqDestructors in p.config.globalOptions and n.kind != nkNilLit and ty == tyString:
result = genStringLiteralV2Const(p.module, n, isConst) result = genStringLiteralV2Const(p.module, n, isConst)
else: else:

View file

@ -85,7 +85,7 @@ proc specializeResetT(p: BProc, accessor: Rope, typ: PType) =
lineCg(p, cpsStmts, "$1 = NIM_NIL;$n", [accessor]) lineCg(p, cpsStmts, "$1 = NIM_NIL;$n", [accessor])
of tyChar, tyBool, tyEnum, tyInt..tyUInt64: of tyChar, tyBool, tyEnum, tyInt..tyUInt64:
lineCg(p, cpsStmts, "$1 = 0;$n", [accessor]) lineCg(p, cpsStmts, "$1 = 0;$n", [accessor])
of tyCString, tyPointer, tyPtr, tyVar, tyLent: of tyCstring, tyPointer, tyPtr, tyVar, tyLent:
lineCg(p, cpsStmts, "$1 = NIM_NIL;$n", [accessor]) lineCg(p, cpsStmts, "$1 = NIM_NIL;$n", [accessor])
else: else:
discard discard

View file

@ -189,7 +189,7 @@ proc mapType(conf: ConfigRef; typ: PType; kind: TSymKind): TCTypeKind =
of tySequence: result = ctNimSeq of tySequence: result = ctNimSeq
of tyProc: result = if typ.callConv != ccClosure: ctProc else: ctStruct of tyProc: result = if typ.callConv != ccClosure: ctProc else: ctStruct
of tyString: result = ctNimStr of tyString: result = ctNimStr
of tyCString: result = ctCString of tyCstring: result = ctCString
of tyInt..tyUInt64: of tyInt..tyUInt64:
result = TCTypeKind(ord(typ.kind) - ord(tyInt) + ord(ctInt)) result = TCTypeKind(ord(typ.kind) - ord(tyInt) + ord(ctInt))
of tyStatic: of tyStatic:
@ -292,7 +292,7 @@ proc getSimpleTypeDesc(m: BModule, typ: PType): Rope =
else: else:
discard cgsym(m, "NimStringDesc") discard cgsym(m, "NimStringDesc")
result = typeNameOrLiteral(m, typ, "NimStringDesc*") result = typeNameOrLiteral(m, typ, "NimStringDesc*")
of tyCString: result = typeNameOrLiteral(m, typ, "NCSTRING") of tyCstring: result = typeNameOrLiteral(m, typ, "NCSTRING")
of tyBool: result = typeNameOrLiteral(m, typ, "NIM_BOOL") of tyBool: result = typeNameOrLiteral(m, typ, "NIM_BOOL")
of tyChar: result = typeNameOrLiteral(m, typ, "NIM_CHAR") of tyChar: result = typeNameOrLiteral(m, typ, "NIM_CHAR")
of tyNil: result = typeNameOrLiteral(m, typ, "void*") of tyNil: result = typeNameOrLiteral(m, typ, "void*")
@ -1452,7 +1452,7 @@ proc genTypeInfoV1(m: BModule, t: PType; info: TLineInfo): Rope =
case t.kind case t.kind
of tyEmpty, tyVoid: result = rope"0" of tyEmpty, tyVoid: result = rope"0"
of tyPointer, tyBool, tyChar, tyCString, tyString, tyInt..tyUInt64, tyVar, tyLent: of tyPointer, tyBool, tyChar, tyCstring, tyString, tyInt..tyUInt64, tyVar, tyLent:
genTypeInfoAuxBase(m, t, t, result, rope"0", info) genTypeInfoAuxBase(m, t, t, result, rope"0", info)
of tyStatic: of tyStatic:
if t.n != nil: result = genTypeInfoV1(m, lastSon t, info) if t.n != nil: result = genTypeInfoV1(m, lastSon t, info)

View file

@ -139,7 +139,7 @@ proc matchType(c: PContext; f, a: PType; m: var MatchCon): bool =
if result: if result:
when logBindings: echo "A adding ", f, " ", ak when logBindings: echo "A adding ", f, " ", ak
m.inferred.add((f, ak)) m.inferred.add((f, ak))
elif m.magic == mArrGet and ak.kind in {tyArray, tyOpenArray, tySequence, tyVarargs, tyCString, tyString}: elif m.magic == mArrGet and ak.kind in {tyArray, tyOpenArray, tySequence, tyVarargs, tyCstring, tyString}:
when logBindings: echo "B adding ", f, " ", lastSon ak when logBindings: echo "B adding ", f, " ", lastSon ak
m.inferred.add((f, lastSon ak)) m.inferred.add((f, lastSon ak))
result = true result = true
@ -165,7 +165,7 @@ proc matchType(c: PContext; f, a: PType; m: var MatchCon): bool =
result = false result = false
of tyEnum, tyObject, tyDistinct: of tyEnum, tyObject, tyDistinct:
result = sameType(f, a) result = sameType(f, a)
of tyEmpty, tyString, tyCString, tyPointer, tyNil, tyUntyped, tyTyped, tyVoid: of tyEmpty, tyString, tyCstring, tyPointer, tyNil, tyUntyped, tyTyped, tyVoid:
result = a.skipTypes(ignorableForArgType).kind == f.kind result = a.skipTypes(ignorableForArgType).kind == f.kind
of tyBool, tyChar, tyInt..tyUInt64: of tyBool, tyChar, tyInt..tyUInt64:
let ak = a.skipTypes(ignorableForArgType) let ak = a.skipTypes(ignorableForArgType)

View file

@ -92,7 +92,7 @@ proc mapType(conf: ConfigRef, t: ast.PType): ptr libffi.Type =
else: result = nil else: result = nil
of tyFloat, tyFloat64: result = addr libffi.type_double of tyFloat, tyFloat64: result = addr libffi.type_double
of tyFloat32: result = addr libffi.type_float of tyFloat32: result = addr libffi.type_float
of tyVar, tyLent, tyPointer, tyPtr, tyRef, tyCString, tySequence, tyString, tyUntyped, of tyVar, tyLent, tyPointer, tyPtr, tyRef, tyCstring, tySequence, tyString, tyUntyped,
tyTyped, tyTypeDesc, tyProc, tyArray, tyStatic, tyNil: tyTyped, tyTypeDesc, tyProc, tyArray, tyStatic, tyNil:
result = addr libffi.type_pointer result = addr libffi.type_pointer
of tyDistinct, tyAlias, tySink: of tyDistinct, tyAlias, tySink:
@ -205,7 +205,7 @@ proc pack(conf: ConfigRef, v: PNode, typ: PType, res: pointer) =
of tyFloat32: awr(float32, v.floatVal) of tyFloat32: awr(float32, v.floatVal)
of tyFloat64: awr(float64, v.floatVal) of tyFloat64: awr(float64, v.floatVal)
of tyPointer, tyProc, tyCString, tyString: of tyPointer, tyProc, tyCstring, tyString:
if v.kind == nkNilLit: if v.kind == nkNilLit:
# nothing to do since the memory is 0 initialized anyway # nothing to do since the memory is 0 initialized anyway
discard discard
@ -386,7 +386,7 @@ proc unpack(conf: ConfigRef, x: pointer, typ: PType, n: PNode): PNode =
result = unpackObject(conf, x, typ, n) result = unpackObject(conf, x, typ, n)
of tyArray: of tyArray:
result = unpackArray(conf, x, typ, n) result = unpackArray(conf, x, typ, n)
of tyCString, tyString: of tyCstring, tyString:
let p = rd(cstring, x) let p = rd(cstring, x)
if p.isNil: if p.isNil:
setNil() setNil()
@ -402,7 +402,7 @@ proc unpack(conf: ConfigRef, x: pointer, typ: PType, n: PNode): PNode =
proc fficast*(conf: ConfigRef, x: PNode, destTyp: PType): PNode = proc fficast*(conf: ConfigRef, x: PNode, destTyp: PType): PNode =
if x.kind == nkPtrLit and x.typ.kind in {tyPtr, tyRef, tyVar, tyLent, tyPointer, if x.kind == nkPtrLit and x.typ.kind in {tyPtr, tyRef, tyVar, tyLent, tyPointer,
tyProc, tyCString, tyString, tyProc, tyCstring, tyString,
tySequence}: tySequence}:
result = newNodeIT(x.kind, x.info, destTyp) result = newNodeIT(x.kind, x.info, destTyp)
result.intVal = x.intVal result.intVal = x.intVal

View file

@ -210,7 +210,7 @@ proc mapType(typ: PType): TJSTypeKind =
if t.n != nil: result = mapType(lastSon t) if t.n != nil: result = mapType(lastSon t)
else: result = etyNone else: result = etyNone
of tyProc: result = etyProc of tyProc: result = etyProc
of tyCString: result = etyString of tyCstring: result = etyString
of tyConcept, tyIterable: doAssert false of tyConcept, tyIterable: doAssert false
proc mapType(p: PProc; typ: PType): TJSTypeKind = proc mapType(p: PProc; typ: PType): TJSTypeKind =
@ -1047,14 +1047,14 @@ proc needsNoCopy(p: PProc; y: PNode): bool =
return y.kind in nodeKindsNeedNoCopy or return y.kind in nodeKindsNeedNoCopy or
((mapType(y.typ) != etyBaseIndex or (y.kind == nkSym and y.sym.kind == skParam)) and ((mapType(y.typ) != etyBaseIndex or (y.kind == nkSym and y.sym.kind == skParam)) and
(skipTypes(y.typ, abstractInst).kind in (skipTypes(y.typ, abstractInst).kind in
{tyRef, tyPtr, tyLent, tyVar, tyCString, tyProc, tyOwned} + IntegralTypes)) {tyRef, tyPtr, tyLent, tyVar, tyCstring, tyProc, tyOwned} + IntegralTypes))
proc genAsgnAux(p: PProc, x, y: PNode, noCopyNeeded: bool) = proc genAsgnAux(p: PProc, x, y: PNode, noCopyNeeded: bool) =
var a, b: TCompRes var a, b: TCompRes
var xtyp = mapType(p, x.typ) var xtyp = mapType(p, x.typ)
# disable `[]=` for cstring # disable `[]=` for cstring
if x.kind == nkBracketExpr and x.len >= 2 and x[0].typ.skipTypes(abstractInst).kind == tyCString: if x.kind == nkBracketExpr and x.len >= 2 and x[0].typ.skipTypes(abstractInst).kind == tyCstring:
localError(p.config, x.info, "cstring doesn't support `[]=` operator") localError(p.config, x.info, "cstring doesn't support `[]=` operator")
gen(p, x, a) gen(p, x, a)
@ -1263,14 +1263,14 @@ proc genArrayAccess(p: PProc, n: PNode, r: var TCompRes) =
var ty = skipTypes(n[0].typ, abstractVarRange) var ty = skipTypes(n[0].typ, abstractVarRange)
if ty.kind in {tyRef, tyPtr, tyLent, tyOwned}: ty = skipTypes(ty.lastSon, abstractVarRange) if ty.kind in {tyRef, tyPtr, tyLent, tyOwned}: ty = skipTypes(ty.lastSon, abstractVarRange)
case ty.kind case ty.kind
of tyArray, tyOpenArray, tySequence, tyString, tyCString, tyVarargs: of tyArray, tyOpenArray, tySequence, tyString, tyCstring, tyVarargs:
genArrayAddr(p, n, r) genArrayAddr(p, n, r)
of tyTuple: of tyTuple:
genFieldAddr(p, n, r) genFieldAddr(p, n, r)
else: internalError(p.config, n.info, "expr(nkBracketExpr, " & $ty.kind & ')') else: internalError(p.config, n.info, "expr(nkBracketExpr, " & $ty.kind & ')')
r.typ = mapType(n.typ) r.typ = mapType(n.typ)
if r.res == nil: internalError(p.config, n.info, "genArrayAccess") if r.res == nil: internalError(p.config, n.info, "genArrayAccess")
if ty.kind == tyCString: if ty.kind == tyCstring:
r.res = "$1.charCodeAt($2)" % [r.address, r.res] r.res = "$1.charCodeAt($2)" % [r.address, r.res]
elif r.typ == etyBaseIndex: elif r.typ == etyBaseIndex:
if needsTemp(p, n[0]): if needsTemp(p, n[0]):
@ -1340,7 +1340,7 @@ proc genAddr(p: PProc, n: PNode, r: var TCompRes) =
else: else:
let kindOfIndexedExpr = skipTypes(n[0][0].typ, abstractVarRange).kind let kindOfIndexedExpr = skipTypes(n[0][0].typ, abstractVarRange).kind
case kindOfIndexedExpr case kindOfIndexedExpr
of tyArray, tyOpenArray, tySequence, tyString, tyCString, tyVarargs: of tyArray, tyOpenArray, tySequence, tyString, tyCstring, tyVarargs:
genArrayAddr(p, n[0], r) genArrayAddr(p, n[0], r)
of tyTuple: of tyTuple:
genFieldAddr(p, n[0], r) genFieldAddr(p, n[0], r)
@ -1744,7 +1744,7 @@ proc createVar(p: PProc, typ: PType, indirect: bool): Rope =
result = putToSeq("null", indirect) result = putToSeq("null", indirect)
of tySequence, tyString: of tySequence, tyString:
result = putToSeq("[]", indirect) result = putToSeq("[]", indirect)
of tyCString, tyProc: of tyCstring, tyProc:
result = putToSeq("null", indirect) result = putToSeq("null", indirect)
of tyStatic: of tyStatic:
if t.n != nil: if t.n != nil:
@ -2030,7 +2030,7 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) =
gen(p, n[1], lhs) gen(p, n[1], lhs)
gen(p, n[2], rhs) gen(p, n[2], rhs)
if skipTypes(n[1].typ, abstractVarRange).kind == tyCString: if skipTypes(n[1].typ, abstractVarRange).kind == tyCstring:
let (b, tmp) = maybeMakeTemp(p, n[2], rhs) let (b, tmp) = maybeMakeTemp(p, n[2], rhs)
r.res = "if (null != $1) { if (null == $2) $2 = $3; else $2 += $3; }" % r.res = "if (null != $1) { if (null == $2) $2 = $3; else $2 += $3; }" %
[b, lhs.rdLoc, tmp] [b, lhs.rdLoc, tmp]
@ -2087,7 +2087,7 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) =
of mLengthStr, mLengthSeq, mLengthOpenArray, mLengthArray: of mLengthStr, mLengthSeq, mLengthOpenArray, mLengthArray:
var x: TCompRes var x: TCompRes
gen(p, n[1], x) gen(p, n[1], x)
if skipTypes(n[1].typ, abstractInst).kind == tyCString: if skipTypes(n[1].typ, abstractInst).kind == tyCstring:
let (a, tmp) = maybeMakeTemp(p, n[1], x) let (a, tmp) = maybeMakeTemp(p, n[1], x)
r.res = "(($1) == null ? 0 : ($2).length)" % [a, tmp] r.res = "(($1) == null ? 0 : ($2).length)" % [a, tmp]
else: else:
@ -2096,7 +2096,7 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) =
of mHigh: of mHigh:
var x: TCompRes var x: TCompRes
gen(p, n[1], x) gen(p, n[1], x)
if skipTypes(n[1].typ, abstractInst).kind == tyCString: if skipTypes(n[1].typ, abstractInst).kind == tyCstring:
let (a, tmp) = maybeMakeTemp(p, n[1], x) let (a, tmp) = maybeMakeTemp(p, n[1], x)
r.res = "(($1) == null ? -1 : ($2).length - 1)" % [a, tmp] r.res = "(($1) == null ? -1 : ($2).length - 1)" % [a, tmp]
else: else:

View file

@ -128,7 +128,7 @@ proc genTypeInfo(p: PProc, typ: PType): Rope =
case t.kind case t.kind
of tyDistinct: of tyDistinct:
result = genTypeInfo(p, t[0]) result = genTypeInfo(p, t[0])
of tyPointer, tyProc, tyBool, tyChar, tyCString, tyString, tyInt..tyUInt64: of tyPointer, tyProc, tyBool, tyChar, tyCstring, tyString, tyInt..tyUInt64:
var s = var s =
"var $1 = {size: 0,kind: $2,base: null,node: null,finalizer: null};$n" % "var $1 = {size: 0,kind: $2,base: null,node: null,finalizer: null};$n" %
[result, rope(ord(t.kind))] [result, rope(ord(t.kind))]

View file

@ -825,7 +825,7 @@ proc ownedClosureOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
proc fillBody(c: var TLiftCtx; t: PType; body, x, y: PNode) = proc fillBody(c: var TLiftCtx; t: PType; body, x, y: PNode) =
case t.kind case t.kind
of tyNone, tyEmpty, tyVoid: discard of tyNone, tyEmpty, tyVoid: discard
of tyPointer, tySet, tyBool, tyChar, tyEnum, tyInt..tyUInt64, tyCString, of tyPointer, tySet, tyBool, tyChar, tyEnum, tyInt..tyUInt64, tyCstring,
tyPtr, tyUncheckedArray, tyVar, tyLent: tyPtr, tyUncheckedArray, tyVar, tyLent:
defaultOp(c, t, body, x, y) defaultOp(c, t, body, x, y)
of tyRef: of tyRef:

View file

@ -68,7 +68,7 @@ proc getSysType*(g: ModuleGraph; info: TLineInfo; kind: TTypeKind): PType =
of tyBool: result = sysTypeFromName("bool") of tyBool: result = sysTypeFromName("bool")
of tyChar: result = sysTypeFromName("char") of tyChar: result = sysTypeFromName("char")
of tyString: result = sysTypeFromName("string") of tyString: result = sysTypeFromName("string")
of tyCString: result = sysTypeFromName("cstring") of tyCstring: result = sysTypeFromName("cstring")
of tyPointer: result = sysTypeFromName("pointer") of tyPointer: result = sysTypeFromName("pointer")
of tyNil: result = newSysType(g, tyNil, g.config.target.ptrSize) of tyNil: result = newSysType(g, tyNil, g.config.target.ptrSize)
else: internalError(g.config, "request for typekind: " & $kind) else: internalError(g.config, "request for typekind: " & $kind)

View file

@ -1283,7 +1283,7 @@ proc typeNilability(typ: PType): Nilability =
# echo "typeNilability ", $typ.flags, " ", $typ.kind # echo "typeNilability ", $typ.flags, " ", $typ.kind
result = if tfNotNil in typ.flags: result = if tfNotNil in typ.flags:
Safe Safe
elif typ.kind in {tyRef, tyCString, tyPtr, tyPointer}: elif typ.kind in {tyRef, tyCstring, tyPtr, tyPointer}:
# #
# tyVar ? tyVarargs ? tySink ? tyLent ? # tyVar ? tyVarargs ? tySink ? tyLent ?
# TODO spec? tests? # TODO spec? tests?

View file

@ -375,7 +375,7 @@ proc semLowHigh(c: PContext, n: PNode, m: TMagic): PNode =
n[1] = semExprWithType(c, n[1], {efDetermineType}) n[1] = semExprWithType(c, n[1], {efDetermineType})
var typ = skipTypes(n[1].typ, abstractVarRange + {tyTypeDesc, tyUserTypeClassInst}) var typ = skipTypes(n[1].typ, abstractVarRange + {tyTypeDesc, tyUserTypeClassInst})
case typ.kind case typ.kind
of tySequence, tyString, tyCString, tyOpenArray, tyVarargs: of tySequence, tyString, tyCstring, tyOpenArray, tyVarargs:
n.typ = getSysType(c.graph, n.info, tyInt) n.typ = getSysType(c.graph, n.info, tyInt)
of tyArray: of tyArray:
n.typ = typ[0] # indextype n.typ = typ[0] # indextype
@ -1508,7 +1508,7 @@ proc semSubscript(c: PContext, n: PNode, flags: TExprFlags): PNode =
arr = arr.base arr = arr.base
case arr.kind case arr.kind
of tyArray, tyOpenArray, tyVarargs, tySequence, tyString, tyCString, of tyArray, tyOpenArray, tyVarargs, tySequence, tyString, tyCstring,
tyUncheckedArray: tyUncheckedArray:
if n.len != 2: return nil if n.len != 2: return nil
n[0] = makeDeref(n[0]) n[0] = makeDeref(n[0])

View file

@ -143,7 +143,7 @@ proc evalOp(m: TMagic, n, a, b, c: PNode; idgen: IdGenerator; g: ModuleGraph): P
elif a.kind in {nkStrLit..nkTripleStrLit}: elif a.kind in {nkStrLit..nkTripleStrLit}:
if a.typ.kind == tyString: if a.typ.kind == tyString:
result = newIntNodeT(toInt128(a.strVal.len), n, idgen, g) result = newIntNodeT(toInt128(a.strVal.len), n, idgen, g)
elif a.typ.kind == tyCString: elif a.typ.kind == tyCstring:
result = newIntNodeT(toInt128(nimCStrLen(a.strVal)), n, idgen, g) result = newIntNodeT(toInt128(nimCStrLen(a.strVal)), n, idgen, g)
else: else:
result = newIntNodeT(toInt128(a.len), n, idgen, g) result = newIntNodeT(toInt128(a.len), n, idgen, g)
@ -578,7 +578,7 @@ proc getConstExpr(m: PSym, n: PNode; idgen: IdGenerator; g: ModuleGraph): PNode
result = newIntNodeT(firstOrd(g.config, n[1].typ), n, idgen, g) result = newIntNodeT(firstOrd(g.config, n[1].typ), n, idgen, g)
of mHigh: of mHigh:
if skipTypes(n[1].typ, abstractVar+{tyUserTypeClassInst}).kind notin if skipTypes(n[1].typ, abstractVar+{tyUserTypeClassInst}).kind notin
{tySequence, tyString, tyCString, tyOpenArray, tyVarargs}: {tySequence, tyString, tyCstring, tyOpenArray, tyVarargs}:
if skipTypes(n[1].typ, abstractVarRange).kind in tyFloat..tyFloat64: if skipTypes(n[1].typ, abstractVarRange).kind in tyFloat..tyFloat64:
result = newFloatNodeT(lastFloat(n[1].typ), n, g) result = newFloatNodeT(lastFloat(n[1].typ), n, g)
else: else:

View file

@ -92,7 +92,7 @@ proc annotateType*(n: PNode, t: PType; conf: ConfigRef) =
else: else:
globalError(conf, n.info, "integer literal must have some int type") globalError(conf, n.info, "integer literal must have some int type")
of nkStrLit..nkTripleStrLit: of nkStrLit..nkTripleStrLit:
if x.kind in {tyString, tyCString}: if x.kind in {tyString, tyCstring}:
n.typ = t n.typ = t
else: else:
globalError(conf, n.info, "string literal must be of some string type") globalError(conf, n.info, "string literal must be of some string type")

View file

@ -696,7 +696,7 @@ proc paramType(op: PType, i: int): PType =
if op != nil and i < op.len: result = op[i] if op != nil and i < op.len: result = op[i]
proc cstringCheck(tracked: PEffects; n: PNode) = proc cstringCheck(tracked: PEffects; n: PNode) =
if n[0].typ.kind == tyCString and (let a = skipConv(n[1]); if n[0].typ.kind == tyCstring and (let a = skipConv(n[1]);
a.typ.kind == tyString and a.kind notin {nkStrLit..nkTripleStrLit}): a.typ.kind == tyString and a.kind notin {nkStrLit..nkTripleStrLit}):
message(tracked.config, n.info, warnUnsafeCode, renderTree(n)) message(tracked.config, n.info, warnUnsafeCode, renderTree(n))

View file

@ -95,7 +95,7 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType =
of tyTuple: of tyTuple:
if v.len == 2: if v.len == 2:
strVal = v[1] # second tuple part is the string value strVal = v[1] # second tuple part is the string value
if skipTypes(strVal.typ, abstractInst).kind in {tyString, tyCString}: if skipTypes(strVal.typ, abstractInst).kind in {tyString, tyCstring}:
if not isOrdinalType(v[0].typ, allowEnumWithHoles=true): if not isOrdinalType(v[0].typ, allowEnumWithHoles=true):
localError(c.config, v[0].info, errOrdinalTypeExpected & "; given: " & typeToString(v[0].typ, preferDesc)) localError(c.config, v[0].info, errOrdinalTypeExpected & "; given: " & typeToString(v[0].typ, preferDesc))
x = toInt64(getOrdValue(v[0])) # first tuple part is the ordinal x = toInt64(getOrdValue(v[0])) # first tuple part is the ordinal
@ -104,7 +104,7 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType =
localError(c.config, strVal.info, errStringLiteralExpected) localError(c.config, strVal.info, errStringLiteralExpected)
else: else:
localError(c.config, v.info, errWrongNumberOfVariables) localError(c.config, v.info, errWrongNumberOfVariables)
of tyString, tyCString: of tyString, tyCstring:
strVal = v strVal = v
x = counter x = counter
else: else:
@ -2037,7 +2037,7 @@ proc processMagicType(c: PContext, m: PSym) =
if optSeqDestructors in c.config.globalOptions: if optSeqDestructors in c.config.globalOptions:
incl m.typ.flags, tfHasAsgn incl m.typ.flags, tfHasAsgn
of mCstring: of mCstring:
setMagicIntegral(c.config, m, tyCString, c.config.target.ptrSize) setMagicIntegral(c.config, m, tyCstring, c.config.target.ptrSize)
rawAddSon(m.typ, getSysType(c.graph, m.info, tyChar)) rawAddSon(m.typ, getSysType(c.graph, m.info, tyChar))
of mPointer: setMagicIntegral(c.config, m, tyPointer, c.config.target.ptrSize) of mPointer: setMagicIntegral(c.config, m, tyPointer, c.config.target.ptrSize)
of mNil: setMagicType(c.config, m, tyNil, c.config.target.ptrSize) of mNil: setMagicType(c.config, m, tyNil, c.config.target.ptrSize)

View file

@ -260,7 +260,7 @@ proc sumGeneric(t: PType): int =
of tyGenericParam, tyUntyped, tyTyped: break of tyGenericParam, tyUntyped, tyTyped: break
of tyAlias, tySink: t = t.lastSon of tyAlias, tySink: t = t.lastSon
of tyBool, tyChar, tyEnum, tyObject, tyPointer, of tyBool, tyChar, tyEnum, tyObject, tyPointer,
tyString, tyCString, tyInt..tyInt64, tyFloat..tyFloat128, tyString, tyCstring, tyInt..tyInt64, tyFloat..tyFloat128,
tyUInt..tyUInt64, tyCompositeTypeClass: tyUInt..tyUInt64, tyCompositeTypeClass:
return isvar return isvar
else: else:
@ -1383,7 +1383,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
# 'pointer' is NOT compatible to regionized pointers # 'pointer' is NOT compatible to regionized pointers
# so 'dealloc(regionPtr)' fails: # so 'dealloc(regionPtr)' fails:
if a.len == 1: result = isConvertible if a.len == 1: result = isConvertible
of tyCString: result = isConvertible of tyCstring: result = isConvertible
else: discard else: discard
of tyString: of tyString:
case a.kind case a.kind
@ -1394,10 +1394,10 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
result = isEqual result = isEqual
of tyNil: result = isNone of tyNil: result = isNone
else: discard else: discard
of tyCString: of tyCstring:
# conversion from string to cstring is automatic: # conversion from string to cstring is automatic:
case a.kind case a.kind
of tyCString: of tyCstring:
if tfNotNil in f.flags and tfNotNil notin a.flags: if tfNotNil in f.flags and tfNotNil notin a.flags:
result = isNilConversion result = isNilConversion
else: else:
@ -2436,7 +2436,7 @@ proc matchesAux(c: PContext, n, nOrig: PNode, m: var TCandidate, marker: var Int
n[a] = prepareOperand(c, n[a]) n[a] = prepareOperand(c, n[a])
if skipTypes(n[a].typ, abstractVar-{tyTypeDesc}).kind==tyString: if skipTypes(n[a].typ, abstractVar-{tyTypeDesc}).kind==tyString:
m.call.add implicitConv(nkHiddenStdConv, m.call.add implicitConv(nkHiddenStdConv,
getSysType(c.graph, n[a].info, tyCString), getSysType(c.graph, n[a].info, tyCstring),
copyTree(n[a]), m, c) copyTree(n[a]), m, c)
else: else:
m.call.add copyTree(n[a]) m.call.add copyTree(n[a])

View file

@ -242,7 +242,7 @@ proc computeSizeAlign(conf: ConfigRef; typ: PType) =
else: else:
typ.size = conf.target.ptrSize typ.size = conf.target.ptrSize
typ.align = int16(conf.target.ptrSize) typ.align = int16(conf.target.ptrSize)
of tyCString, tySequence, tyPtr, tyRef, tyVar, tyLent: of tyCstring, tySequence, tyPtr, tyRef, tyVar, tyLent:
let base = typ.lastSon let base = typ.lastSon
if base == typ: if base == typ:
# this is not the correct location to detect ``type A = ptr A`` # this is not the correct location to detect ``type A = ptr A``

View file

@ -8,13 +8,13 @@ type
name*: string name*: string
children*: seq[Child] children*: seq[Child]
C = enum cSourceNode, cString C = enum cSourceNode, cSourceString
Child* = ref object Child* = ref object
case kind*: C: case kind*: C:
of cSourceNode: of cSourceNode:
node*: SourceNode node*: SourceNode
of cString: of cSourceString:
s*: string s*: string
SourceMap* = ref object SourceMap* = ref object
@ -44,7 +44,7 @@ type
proc child*(s: string): Child = proc child*(s: string): Child =
Child(kind: cString, s: s) Child(kind: cSourceString, s: s)
proc child*(node: SourceNode): Child = proc child*(node: SourceNode): Child =
@ -72,7 +72,7 @@ proc text*(sourceNode: SourceNode, depth: int): string =
let empty = " " let empty = " "
result = &"{repeat(empty, depth)}SourceNode({sourceNode.source}:{sourceNode.line}:{sourceNode.column}):\n" result = &"{repeat(empty, depth)}SourceNode({sourceNode.source}:{sourceNode.line}:{sourceNode.column}):\n"
for child in sourceNode.children: for child in sourceNode.children:
if child.kind == cString: if child.kind == cSourceString:
result.add(&"{repeat(empty, depth + 1)}{child.s}\n") result.add(&"{repeat(empty, depth + 1)}{child.s}\n")
else: else:
result.add(child.node.text(depth + 1)) result.add(child.node.text(depth + 1))
@ -308,7 +308,7 @@ proc addMapping*(map: SourceMapGenerator, mapping: Mapping) =
proc walk*(node: SourceNode, fn: proc(line: string, original: SourceNode)) = proc walk*(node: SourceNode, fn: proc(line: string, original: SourceNode)) =
for child in node.children: for child in node.children:
if child.kind == cString and child.s.len > 0: if child.kind == cSourceString and child.s.len > 0:
fn(child.s, node) fn(child.s, node)
else: else:
child.node.walk(fn) child.node.walk(fn)

View file

@ -497,14 +497,14 @@ proc transformConv(c: PTransf, n: PNode): PNode =
result.typ = takeType(n.typ, n[1].typ, c.graph, c.idgen) result.typ = takeType(n.typ, n[1].typ, c.graph, c.idgen)
#echo n.info, " came here and produced ", typeToString(result.typ), #echo n.info, " came here and produced ", typeToString(result.typ),
# " from ", typeToString(n.typ), " and ", typeToString(n[1].typ) # " from ", typeToString(n.typ), " and ", typeToString(n[1].typ)
of tyCString: of tyCstring:
if source.kind == tyString: if source.kind == tyString:
result = newTransNode(nkStringToCString, n, 1) result = newTransNode(nkStringToCString, n, 1)
result[0] = transform(c, n[1]) result[0] = transform(c, n[1])
else: else:
result = transformSons(c, n) result = transformSons(c, n)
of tyString: of tyString:
if source.kind == tyCString: if source.kind == tyCstring:
result = newTransNode(nkCStringToString, n, 1) result = newTransNode(nkCStringToString, n, 1)
result[0] = transform(c, n[1]) result[0] = transform(c, n[1])
else: else:

View file

@ -116,7 +116,7 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
result = t result = t
of tyNil: of tyNil:
if kind != skConst and kind != skParam: result = t if kind != skConst and kind != skParam: result = t
of tyString, tyBool, tyChar, tyEnum, tyInt..tyUInt64, tyCString, tyPointer: of tyString, tyBool, tyChar, tyEnum, tyInt..tyUInt64, tyCstring, tyPointer:
result = nil result = nil
of tyOrdinal: of tyOrdinal:
if kind != skParam: result = t if kind != skParam: result = t

View file

@ -503,7 +503,7 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
result = typeToString(t[0]) result = typeToString(t[0])
elif prefer in {preferResolved, preferMixed}: elif prefer in {preferResolved, preferMixed}:
case t.kind case t.kind
of IntegralTypes + {tyFloat..tyFloat128} + {tyString, tyCString}: of IntegralTypes + {tyFloat..tyFloat128} + {tyString, tyCstring}:
result = typeToStr[t.kind] result = typeToStr[t.kind]
of tyGenericBody: of tyGenericBody:
result = typeToString(t.lastSon) result = typeToString(t.lastSon)
@ -762,7 +762,7 @@ proc firstOrd*(conf: ConfigRef; t: PType): Int128 =
of tyOrdinal: of tyOrdinal:
if t.len > 0: result = firstOrd(conf, lastSon(t)) if t.len > 0: result = firstOrd(conf, lastSon(t))
else: internalError(conf, "invalid kind for firstOrd(" & $t.kind & ')') else: internalError(conf, "invalid kind for firstOrd(" & $t.kind & ')')
of tyUncheckedArray, tyCString: of tyUncheckedArray, tyCstring:
result = Zero result = Zero
else: else:
internalError(conf, "invalid kind for firstOrd(" & $t.kind & ')') internalError(conf, "invalid kind for firstOrd(" & $t.kind & ')')
@ -1129,7 +1129,7 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
return true return true
case a.kind case a.kind
of tyEmpty, tyChar, tyBool, tyNil, tyPointer, tyString, tyCString, of tyEmpty, tyChar, tyBool, tyNil, tyPointer, tyString, tyCstring,
tyInt..tyUInt64, tyTyped, tyUntyped, tyVoid: tyInt..tyUInt64, tyTyped, tyUntyped, tyVoid:
result = sameFlags(a, b) result = sameFlags(a, b)
of tyStatic, tyFromExpr: of tyStatic, tyFromExpr:

View file

@ -399,7 +399,7 @@ proc opConv(c: PCtx; dest: var TFullReg, src: TFullReg, desttyp, srctyp: PType):
dest.node.strVal = $src.floatVal dest.node.strVal = $src.floatVal
of tyString: of tyString:
dest.node.strVal = src.node.strVal dest.node.strVal = src.node.strVal
of tyCString: of tyCstring:
if src.node.kind == nkBracket: if src.node.kind == nkBracket:
# Array of chars # Array of chars
var strVal = "" var strVal = ""

View file

@ -257,7 +257,7 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo;
result.add t.n[1].copyTree result.add t.n[1].copyTree
of tyPointer: result = atomicType("pointer", mPointer) of tyPointer: result = atomicType("pointer", mPointer)
of tyString: result = atomicType("string", mString) of tyString: result = atomicType("string", mString)
of tyCString: result = atomicType("cstring", mCstring) of tyCstring: result = atomicType("cstring", mCstring)
of tyInt: result = atomicType("int", mInt) of tyInt: result = atomicType("int", mInt)
of tyInt8: result = atomicType("int8", mInt8) of tyInt8: result = atomicType("int8", mInt8)
of tyInt16: result = atomicType("int16", mInt16) of tyInt16: result = atomicType("int16", mInt16)

View file

@ -190,7 +190,7 @@ proc getSlotKind(t: PType): TSlotKind =
case t.skipTypes(abstractRange-{tyTypeDesc}).kind case t.skipTypes(abstractRange-{tyTypeDesc}).kind
of tyBool, tyChar, tyEnum, tyOrdinal, tyInt..tyInt64, tyUInt..tyUInt64: of tyBool, tyChar, tyEnum, tyOrdinal, tyInt..tyInt64, tyUInt..tyUInt64:
slotTempInt slotTempInt
of tyString, tyCString: of tyString, tyCstring:
slotTempStr slotTempStr
of tyFloat..tyFloat128: of tyFloat..tyFloat128:
slotTempFloat slotTempFloat
@ -1053,7 +1053,7 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) =
of mLengthStr: of mLengthStr:
case n[1].typ.kind case n[1].typ.kind
of tyString: genUnaryABI(c, n, dest, opcLenStr) of tyString: genUnaryABI(c, n, dest, opcLenStr)
of tyCString: genUnaryABI(c, n, dest, opcLenCstring) of tyCstring: genUnaryABI(c, n, dest, opcLenCstring)
else: doAssert false, $n[1].typ.kind else: doAssert false, $n[1].typ.kind
of mIncl, mExcl: of mIncl, mExcl:
unused(c, n, dest) unused(c, n, dest)
@ -1199,7 +1199,7 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) =
let tmp = c.genx(n[1]) let tmp = c.genx(n[1])
case n[1].typ.skipTypes(abstractVar-{tyTypeDesc}).kind: case n[1].typ.skipTypes(abstractVar-{tyTypeDesc}).kind:
of tyString: c.gABI(n, opcLenStr, dest, tmp, 1) of tyString: c.gABI(n, opcLenStr, dest, tmp, 1)
of tyCString: c.gABI(n, opcLenCstring, dest, tmp, 1) of tyCstring: c.gABI(n, opcLenCstring, dest, tmp, 1)
else: c.gABI(n, opcLenSeq, dest, tmp, 1) else: c.gABI(n, opcLenSeq, dest, tmp, 1)
c.freeTemp(tmp) c.freeTemp(tmp)
of mEcho: of mEcho:
@ -1530,7 +1530,7 @@ proc genAsgn(c: PCtx; le, ri: PNode; requiresCopy: bool) =
let idx = c.genIndex(le[1], le[0].typ) let idx = c.genIndex(le[1], le[0].typ)
let tmp = c.genx(ri) let tmp = c.genx(ri)
if le[0].typ.skipTypes(abstractVarRange-{tyTypeDesc}).kind in { if le[0].typ.skipTypes(abstractVarRange-{tyTypeDesc}).kind in {
tyString, tyCString}: tyString, tyCstring}:
c.preventFalseAlias(le, opcWrStrIdx, dest, idx, tmp) c.preventFalseAlias(le, opcWrStrIdx, dest, idx, tmp)
else: else:
c.preventFalseAlias(le, opcWrArr, dest, idx, tmp) c.preventFalseAlias(le, opcWrArr, dest, idx, tmp)
@ -1775,7 +1775,7 @@ proc genCheckedObjAccess(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags) =
proc genArrAccess(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags) = proc genArrAccess(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags) =
let arrayType = n[0].typ.skipTypes(abstractVarRange-{tyTypeDesc}).kind let arrayType = n[0].typ.skipTypes(abstractVarRange-{tyTypeDesc}).kind
if arrayType in {tyString, tyCString}: if arrayType in {tyString, tyCstring}:
let opc = if gfNodeAddr in flags: opcLdStrIdxAddr else: opcLdStrIdx let opc = if gfNodeAddr in flags: opcLdStrIdxAddr else: opcLdStrIdx
genArrAccessOpcode(c, n, dest, opc, flags) genArrAccessOpcode(c, n, dest, opc, flags)
elif arrayType == tyTypeDesc: elif arrayType == tyTypeDesc:
@ -1813,7 +1813,7 @@ proc getNullValue(typ: PType, info: TLineInfo; conf: ConfigRef): PNode =
result = newNodeIT(nkUIntLit, info, t) result = newNodeIT(nkUIntLit, info, t)
of tyFloat..tyFloat128: of tyFloat..tyFloat128:
result = newNodeIT(nkFloatLit, info, t) result = newNodeIT(nkFloatLit, info, t)
of tyCString, tyString: of tyCstring, tyString:
result = newNodeIT(nkStrLit, info, t) result = newNodeIT(nkStrLit, info, t)
result.strVal = "" result.strVal = ""
of tyVar, tyLent, tyPointer, tyPtr, tyUntyped, of tyVar, tyLent, tyPointer, tyPtr, tyUntyped,

View file

@ -121,7 +121,7 @@ proc storeAny(s: var string; t: PType; a: PNode; stored: var IntSet;
s.add(", ") s.add(", ")
storeAny(s, t.lastSon, a, stored, conf) storeAny(s, t.lastSon, a, stored, conf)
s.add("]") s.add("]")
of tyString, tyCString: of tyString, tyCstring:
if a.kind == nkNilLit: s.add("null") if a.kind == nkNilLit: s.add("null")
else: s.add(escapeJson(a.strVal)) else: s.add(escapeJson(a.strVal))
of tyInt..tyInt64, tyUInt..tyUInt64: s.add($a.intVal) of tyInt..tyInt64, tyUInt..tyUInt64: s.add($a.intVal)
@ -255,7 +255,7 @@ proc loadAny(p: var JsonParser, t: PType,
if p.kind == jsonArrayEnd: next(p) if p.kind == jsonArrayEnd: next(p)
else: raiseParseErr(p, "']' end of ref-address pair expected") else: raiseParseErr(p, "']' end of ref-address pair expected")
else: raiseParseErr(p, "int for pointer type expected") else: raiseParseErr(p, "int for pointer type expected")
of tyString, tyCString: of tyString, tyCstring:
case p.kind case p.kind
of jsonNull: of jsonNull:
result = newNode(nkNilLit) result = newNode(nkNilLit)

View file

@ -322,12 +322,12 @@ proc base*(x: Any): Any =
proc isNil*(x: Any): bool = proc isNil*(x: Any): bool =
## `isNil` for an `x` that represents a cstring, proc or ## `isNil` for an `x` that represents a cstring, proc or
## some pointer type. ## some pointer type.
assert x.rawType.kind in {tyCString, tyRef, tyPtr, tyPointer, tyProc} assert x.rawType.kind in {tyCstring, tyRef, tyPtr, tyPointer, tyProc}
result = isNil(cast[ppointer](x.value)[]) result = isNil(cast[ppointer](x.value)[])
const pointerLike = const pointerLike =
when defined(gcDestructors): {tyCString, tyRef, tyPtr, tyPointer, tyProc} when defined(gcDestructors): {tyCstring, tyRef, tyPtr, tyPointer, tyProc}
else: {tyString, tyCString, tyRef, tyPtr, tyPointer, tySequence, tyProc} else: {tyString, tyCstring, tyRef, tyPtr, tyPointer, tySequence, tyProc}
proc getPointer*(x: Any): pointer = proc getPointer*(x: Any): pointer =
## Retrieves the pointer value out of `x`. `x` needs to be of kind ## Retrieves the pointer value out of `x`. `x` needs to be of kind
@ -669,7 +669,7 @@ proc setString*(x: Any, y: string) =
proc getCString*(x: Any): cstring = proc getCString*(x: Any): cstring =
## Retrieves the `cstring` value out of `x`. `x` needs to represent a `cstring`. ## Retrieves the `cstring` value out of `x`. `x` needs to represent a `cstring`.
assert x.rawType.kind == tyCString assert x.rawType.kind == tyCstring
result = cast[ptr cstring](x.value)[] result = cast[ptr cstring](x.value)[]
proc assign*(x, y: Any) = proc assign*(x, y: Any) =

View file

@ -167,7 +167,7 @@ when false:
of tyPointer: k = "range" of tyPointer: k = "range"
of tyOpenArray: k = "openarray" of tyOpenArray: k = "openarray"
of tyString: k = "string" of tyString: k = "string"
of tyCString: k = "cstring" of tyCstring: k = "cstring"
of tyInt: k = "int" of tyInt: k = "int"
of tyInt32: k = "int32" of tyInt32: k = "int32"
else: k = "other" else: k = "other"

View file

@ -40,7 +40,7 @@ type
tyPointer, tyPointer,
tyOpenArray, tyOpenArray,
tyString, tyString,
tyCString, tyCstring,
tyForward, tyForward,
tyInt, tyInt,
tyInt8, tyInt8,

View file

@ -281,7 +281,7 @@ when not defined(useNimRtl):
of tyString: of tyString:
let sp = cast[ptr string](p) let sp = cast[ptr string](p)
reprStrAux(result, sp[].cstring, sp[].len) reprStrAux(result, sp[].cstring, sp[].len)
of tyCString: of tyCstring:
let cs = cast[ptr cstring](p)[] let cs = cast[ptr cstring](p)[]
if cs.isNil: add result, "nil" if cs.isNil: add result, "nil"
else: reprStrAux(result, cs, cs.len) else: reprStrAux(result, cs, cs.len)

View file

@ -200,7 +200,7 @@ proc reprAux(result: var string, p: pointer, typ: PNimType,
var fp: int var fp: int
{. emit: "`fp` = `p`;\n" .} {. emit: "`fp` = `p`;\n" .}
add(result, reprStr(cast[string](p))) add(result, reprStr(cast[string](p)))
of tyCString: of tyCstring:
var fp: cstring var fp: cstring
{. emit: "`fp` = `p`;\n" .} {. emit: "`fp` = `p`;\n" .}
if fp.isNil: if fp.isNil: