mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-18 05:20:31 +00:00
cString => cSourceString; tyCString => tyCstring so that error msgs show cstring, not cString (#17744)
This commit is contained in:
@@ -379,7 +379,7 @@ type
|
||||
tySequence,
|
||||
tyProc,
|
||||
tyPointer, tyOpenArray,
|
||||
tyString, tyCString, tyForward,
|
||||
tyString, tyCstring, tyForward,
|
||||
tyInt, tyInt8, tyInt16, tyInt32, tyInt64, # signed integers
|
||||
tyFloat, tyFloat32, tyFloat64, tyFloat128,
|
||||
tyUInt, tyUInt8, tyUInt16, tyUInt32, tyUInt64,
|
||||
@@ -1005,13 +1005,13 @@ const
|
||||
tyBool, tyChar, tyEnum, tyArray, tyObject,
|
||||
tySet, tyTuple, tyRange, tyPtr, tyRef, tyVar, tyLent, tySequence, tyProc,
|
||||
tyPointer,
|
||||
tyOpenArray, tyString, tyCString, tyInt..tyInt64, tyFloat..tyFloat128,
|
||||
tyOpenArray, tyString, tyCstring, tyInt..tyInt64, tyFloat..tyFloat128,
|
||||
tyUInt..tyUInt64}
|
||||
IntegralTypes* = {tyBool, tyChar, tyEnum, tyInt..tyInt64,
|
||||
tyFloat..tyFloat128, tyUInt..tyUInt64} # weird name because it contains tyFloat
|
||||
ConstantDataTypes*: TTypeKinds = {tyArray, tySet,
|
||||
tyTuple, tySequence}
|
||||
NilableTypes*: TTypeKinds = {tyPointer, tyCString, tyRef, tyPtr,
|
||||
NilableTypes*: TTypeKinds = {tyPointer, tyCstring, tyRef, tyPtr,
|
||||
tyProc, tyError} # TODO
|
||||
PtrLikeKinds*: TTypeKinds = {tyPointer, tyPtr} # for VM
|
||||
PersistentNodeFlags*: TNodeFlags = {nfBase2, nfBase8, nfBase16,
|
||||
|
||||
@@ -178,7 +178,7 @@ proc genOpenArraySlice(p: BProc; q: PNode; formalType, destType: PType): (Rope,
|
||||
else:
|
||||
result = ("($3*)($1)+($2)" % [rdLoc(a), rdLoc(b), dest],
|
||||
lengthExpr)
|
||||
of tyUncheckedArray, tyCString:
|
||||
of tyUncheckedArray, tyCstring:
|
||||
result = ("($3*)($1)+($2)" % [rdLoc(a), rdLoc(b), dest],
|
||||
lengthExpr)
|
||||
of tyString, tySequence:
|
||||
|
||||
@@ -399,7 +399,7 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||
[rdLoc(dest), rdLoc(src), getSize(p.config, dest.t)])
|
||||
else:
|
||||
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:
|
||||
linefmt(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)])
|
||||
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)])
|
||||
else:
|
||||
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:
|
||||
linefmt(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)])
|
||||
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 tyOpenArray, tyVarargs: genOpenArrayElem(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)
|
||||
else: internalError(p.config, n.info, "expr(nkBracketExpr, " & $ty.kind & ')')
|
||||
discard getTypeDesc(p.module, n.typ)
|
||||
@@ -1666,7 +1666,7 @@ proc genRepr(p: BProc, e: PNode, d: var TLoc) =
|
||||
putIntoDest(p, d, e,
|
||||
ropecg(p.module, "#reprOpenArray($1, $2)", [rdLoc(b),
|
||||
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,
|
||||
ropecg(p.module, "#reprAny($1, $2)", [
|
||||
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:
|
||||
if op == mHigh: unaryExpr(p, e, d, "($1.Field1-1)")
|
||||
else: unaryExpr(p, e, d, "$1.Field1")
|
||||
of tyCString:
|
||||
of tyCstring:
|
||||
if op == mHigh: unaryExpr(p, e, d, "($1 ? (#nimCStrLen($1)-1) : -1)")
|
||||
else: unaryExpr(p, e, d, "($1 ? #nimCStrLen($1) : 0)")
|
||||
of tyString:
|
||||
@@ -2920,7 +2920,7 @@ proc getDefaultValue(p: BProc; typ: PType; info: TLineInfo): Rope =
|
||||
of tyBool: result = rope"NIM_FALSE"
|
||||
of tyEnum, tyChar, tyInt..tyInt64, tyUInt..tyUInt64: result = rope"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:
|
||||
result = rope"NIM_NIL"
|
||||
of tyString, tySequence:
|
||||
@@ -3187,7 +3187,7 @@ proc genBracedInit(p: BProc, n: PNode; isConst: bool; optionalType: PType): Rope
|
||||
|
||||
of tyObject:
|
||||
result = genConstObjConstr(p, n, isConst)
|
||||
of tyString, tyCString:
|
||||
of tyString, tyCstring:
|
||||
if optSeqDestructors in p.config.globalOptions and n.kind != nkNilLit and ty == tyString:
|
||||
result = genStringLiteralV2Const(p.module, n, isConst)
|
||||
else:
|
||||
|
||||
@@ -85,7 +85,7 @@ proc specializeResetT(p: BProc, accessor: Rope, typ: PType) =
|
||||
lineCg(p, cpsStmts, "$1 = NIM_NIL;$n", [accessor])
|
||||
of tyChar, tyBool, tyEnum, tyInt..tyUInt64:
|
||||
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])
|
||||
else:
|
||||
discard
|
||||
|
||||
@@ -189,7 +189,7 @@ proc mapType(conf: ConfigRef; typ: PType; kind: TSymKind): TCTypeKind =
|
||||
of tySequence: result = ctNimSeq
|
||||
of tyProc: result = if typ.callConv != ccClosure: ctProc else: ctStruct
|
||||
of tyString: result = ctNimStr
|
||||
of tyCString: result = ctCString
|
||||
of tyCstring: result = ctCString
|
||||
of tyInt..tyUInt64:
|
||||
result = TCTypeKind(ord(typ.kind) - ord(tyInt) + ord(ctInt))
|
||||
of tyStatic:
|
||||
@@ -292,7 +292,7 @@ proc getSimpleTypeDesc(m: BModule, typ: PType): Rope =
|
||||
else:
|
||||
discard cgsym(m, "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 tyChar: result = typeNameOrLiteral(m, typ, "NIM_CHAR")
|
||||
of tyNil: result = typeNameOrLiteral(m, typ, "void*")
|
||||
@@ -1452,7 +1452,7 @@ proc genTypeInfoV1(m: BModule, t: PType; info: TLineInfo): Rope =
|
||||
|
||||
case t.kind
|
||||
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)
|
||||
of tyStatic:
|
||||
if t.n != nil: result = genTypeInfoV1(m, lastSon t, info)
|
||||
|
||||
@@ -139,7 +139,7 @@ proc matchType(c: PContext; f, a: PType; m: var MatchCon): bool =
|
||||
if result:
|
||||
when logBindings: echo "A adding ", 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
|
||||
m.inferred.add((f, lastSon ak))
|
||||
result = true
|
||||
@@ -165,7 +165,7 @@ proc matchType(c: PContext; f, a: PType; m: var MatchCon): bool =
|
||||
result = false
|
||||
of tyEnum, tyObject, tyDistinct:
|
||||
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
|
||||
of tyBool, tyChar, tyInt..tyUInt64:
|
||||
let ak = a.skipTypes(ignorableForArgType)
|
||||
|
||||
@@ -92,7 +92,7 @@ proc mapType(conf: ConfigRef, t: ast.PType): ptr libffi.Type =
|
||||
else: result = nil
|
||||
of tyFloat, tyFloat64: result = addr libffi.type_double
|
||||
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:
|
||||
result = addr libffi.type_pointer
|
||||
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 tyFloat64: awr(float64, v.floatVal)
|
||||
|
||||
of tyPointer, tyProc, tyCString, tyString:
|
||||
of tyPointer, tyProc, tyCstring, tyString:
|
||||
if v.kind == nkNilLit:
|
||||
# nothing to do since the memory is 0 initialized anyway
|
||||
discard
|
||||
@@ -386,7 +386,7 @@ proc unpack(conf: ConfigRef, x: pointer, typ: PType, n: PNode): PNode =
|
||||
result = unpackObject(conf, x, typ, n)
|
||||
of tyArray:
|
||||
result = unpackArray(conf, x, typ, n)
|
||||
of tyCString, tyString:
|
||||
of tyCstring, tyString:
|
||||
let p = rd(cstring, x)
|
||||
if p.isNil:
|
||||
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 =
|
||||
if x.kind == nkPtrLit and x.typ.kind in {tyPtr, tyRef, tyVar, tyLent, tyPointer,
|
||||
tyProc, tyCString, tyString,
|
||||
tyProc, tyCstring, tyString,
|
||||
tySequence}:
|
||||
result = newNodeIT(x.kind, x.info, destTyp)
|
||||
result.intVal = x.intVal
|
||||
|
||||
@@ -210,7 +210,7 @@ proc mapType(typ: PType): TJSTypeKind =
|
||||
if t.n != nil: result = mapType(lastSon t)
|
||||
else: result = etyNone
|
||||
of tyProc: result = etyProc
|
||||
of tyCString: result = etyString
|
||||
of tyCstring: result = etyString
|
||||
of tyConcept, tyIterable: doAssert false
|
||||
|
||||
proc mapType(p: PProc; typ: PType): TJSTypeKind =
|
||||
@@ -1047,14 +1047,14 @@ proc needsNoCopy(p: PProc; y: PNode): bool =
|
||||
return y.kind in nodeKindsNeedNoCopy or
|
||||
((mapType(y.typ) != etyBaseIndex or (y.kind == nkSym and y.sym.kind == skParam)) and
|
||||
(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) =
|
||||
var a, b: TCompRes
|
||||
var xtyp = mapType(p, x.typ)
|
||||
|
||||
# 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")
|
||||
|
||||
gen(p, x, a)
|
||||
@@ -1263,14 +1263,14 @@ proc genArrayAccess(p: PProc, n: PNode, r: var TCompRes) =
|
||||
var ty = skipTypes(n[0].typ, abstractVarRange)
|
||||
if ty.kind in {tyRef, tyPtr, tyLent, tyOwned}: ty = skipTypes(ty.lastSon, abstractVarRange)
|
||||
case ty.kind
|
||||
of tyArray, tyOpenArray, tySequence, tyString, tyCString, tyVarargs:
|
||||
of tyArray, tyOpenArray, tySequence, tyString, tyCstring, tyVarargs:
|
||||
genArrayAddr(p, n, r)
|
||||
of tyTuple:
|
||||
genFieldAddr(p, n, r)
|
||||
else: internalError(p.config, n.info, "expr(nkBracketExpr, " & $ty.kind & ')')
|
||||
r.typ = mapType(n.typ)
|
||||
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]
|
||||
elif r.typ == etyBaseIndex:
|
||||
if needsTemp(p, n[0]):
|
||||
@@ -1340,7 +1340,7 @@ proc genAddr(p: PProc, n: PNode, r: var TCompRes) =
|
||||
else:
|
||||
let kindOfIndexedExpr = skipTypes(n[0][0].typ, abstractVarRange).kind
|
||||
case kindOfIndexedExpr
|
||||
of tyArray, tyOpenArray, tySequence, tyString, tyCString, tyVarargs:
|
||||
of tyArray, tyOpenArray, tySequence, tyString, tyCstring, tyVarargs:
|
||||
genArrayAddr(p, n[0], r)
|
||||
of tyTuple:
|
||||
genFieldAddr(p, n[0], r)
|
||||
@@ -1744,7 +1744,7 @@ proc createVar(p: PProc, typ: PType, indirect: bool): Rope =
|
||||
result = putToSeq("null", indirect)
|
||||
of tySequence, tyString:
|
||||
result = putToSeq("[]", indirect)
|
||||
of tyCString, tyProc:
|
||||
of tyCstring, tyProc:
|
||||
result = putToSeq("null", indirect)
|
||||
of tyStatic:
|
||||
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[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)
|
||||
r.res = "if (null != $1) { if (null == $2) $2 = $3; else $2 += $3; }" %
|
||||
[b, lhs.rdLoc, tmp]
|
||||
@@ -2087,7 +2087,7 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) =
|
||||
of mLengthStr, mLengthSeq, mLengthOpenArray, mLengthArray:
|
||||
var x: TCompRes
|
||||
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)
|
||||
r.res = "(($1) == null ? 0 : ($2).length)" % [a, tmp]
|
||||
else:
|
||||
@@ -2096,7 +2096,7 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) =
|
||||
of mHigh:
|
||||
var x: TCompRes
|
||||
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)
|
||||
r.res = "(($1) == null ? -1 : ($2).length - 1)" % [a, tmp]
|
||||
else:
|
||||
|
||||
@@ -128,7 +128,7 @@ proc genTypeInfo(p: PProc, typ: PType): Rope =
|
||||
case t.kind
|
||||
of tyDistinct:
|
||||
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 $1 = {size: 0,kind: $2,base: null,node: null,finalizer: null};$n" %
|
||||
[result, rope(ord(t.kind))]
|
||||
|
||||
@@ -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) =
|
||||
case t.kind
|
||||
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:
|
||||
defaultOp(c, t, body, x, y)
|
||||
of tyRef:
|
||||
|
||||
@@ -68,7 +68,7 @@ proc getSysType*(g: ModuleGraph; info: TLineInfo; kind: TTypeKind): PType =
|
||||
of tyBool: result = sysTypeFromName("bool")
|
||||
of tyChar: result = sysTypeFromName("char")
|
||||
of tyString: result = sysTypeFromName("string")
|
||||
of tyCString: result = sysTypeFromName("cstring")
|
||||
of tyCstring: result = sysTypeFromName("cstring")
|
||||
of tyPointer: result = sysTypeFromName("pointer")
|
||||
of tyNil: result = newSysType(g, tyNil, g.config.target.ptrSize)
|
||||
else: internalError(g.config, "request for typekind: " & $kind)
|
||||
|
||||
@@ -1283,7 +1283,7 @@ proc typeNilability(typ: PType): Nilability =
|
||||
# echo "typeNilability ", $typ.flags, " ", $typ.kind
|
||||
result = if tfNotNil in typ.flags:
|
||||
Safe
|
||||
elif typ.kind in {tyRef, tyCString, tyPtr, tyPointer}:
|
||||
elif typ.kind in {tyRef, tyCstring, tyPtr, tyPointer}:
|
||||
#
|
||||
# tyVar ? tyVarargs ? tySink ? tyLent ?
|
||||
# TODO spec? tests?
|
||||
|
||||
@@ -375,7 +375,7 @@ proc semLowHigh(c: PContext, n: PNode, m: TMagic): PNode =
|
||||
n[1] = semExprWithType(c, n[1], {efDetermineType})
|
||||
var typ = skipTypes(n[1].typ, abstractVarRange + {tyTypeDesc, tyUserTypeClassInst})
|
||||
case typ.kind
|
||||
of tySequence, tyString, tyCString, tyOpenArray, tyVarargs:
|
||||
of tySequence, tyString, tyCstring, tyOpenArray, tyVarargs:
|
||||
n.typ = getSysType(c.graph, n.info, tyInt)
|
||||
of tyArray:
|
||||
n.typ = typ[0] # indextype
|
||||
@@ -1508,7 +1508,7 @@ proc semSubscript(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||
arr = arr.base
|
||||
|
||||
case arr.kind
|
||||
of tyArray, tyOpenArray, tyVarargs, tySequence, tyString, tyCString,
|
||||
of tyArray, tyOpenArray, tyVarargs, tySequence, tyString, tyCstring,
|
||||
tyUncheckedArray:
|
||||
if n.len != 2: return nil
|
||||
n[0] = makeDeref(n[0])
|
||||
|
||||
@@ -143,7 +143,7 @@ proc evalOp(m: TMagic, n, a, b, c: PNode; idgen: IdGenerator; g: ModuleGraph): P
|
||||
elif a.kind in {nkStrLit..nkTripleStrLit}:
|
||||
if a.typ.kind == tyString:
|
||||
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)
|
||||
else:
|
||||
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)
|
||||
of mHigh:
|
||||
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:
|
||||
result = newFloatNodeT(lastFloat(n[1].typ), n, g)
|
||||
else:
|
||||
|
||||
@@ -92,7 +92,7 @@ proc annotateType*(n: PNode, t: PType; conf: ConfigRef) =
|
||||
else:
|
||||
globalError(conf, n.info, "integer literal must have some int type")
|
||||
of nkStrLit..nkTripleStrLit:
|
||||
if x.kind in {tyString, tyCString}:
|
||||
if x.kind in {tyString, tyCstring}:
|
||||
n.typ = t
|
||||
else:
|
||||
globalError(conf, n.info, "string literal must be of some string type")
|
||||
|
||||
@@ -696,7 +696,7 @@ proc paramType(op: PType, i: int): PType =
|
||||
if op != nil and i < op.len: result = op[i]
|
||||
|
||||
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}):
|
||||
message(tracked.config, n.info, warnUnsafeCode, renderTree(n))
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType =
|
||||
of tyTuple:
|
||||
if v.len == 2:
|
||||
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):
|
||||
localError(c.config, v[0].info, errOrdinalTypeExpected & "; given: " & typeToString(v[0].typ, preferDesc))
|
||||
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)
|
||||
else:
|
||||
localError(c.config, v.info, errWrongNumberOfVariables)
|
||||
of tyString, tyCString:
|
||||
of tyString, tyCstring:
|
||||
strVal = v
|
||||
x = counter
|
||||
else:
|
||||
@@ -2037,7 +2037,7 @@ proc processMagicType(c: PContext, m: PSym) =
|
||||
if optSeqDestructors in c.config.globalOptions:
|
||||
incl m.typ.flags, tfHasAsgn
|
||||
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))
|
||||
of mPointer: setMagicIntegral(c.config, m, tyPointer, c.config.target.ptrSize)
|
||||
of mNil: setMagicType(c.config, m, tyNil, c.config.target.ptrSize)
|
||||
|
||||
@@ -260,7 +260,7 @@ proc sumGeneric(t: PType): int =
|
||||
of tyGenericParam, tyUntyped, tyTyped: break
|
||||
of tyAlias, tySink: t = t.lastSon
|
||||
of tyBool, tyChar, tyEnum, tyObject, tyPointer,
|
||||
tyString, tyCString, tyInt..tyInt64, tyFloat..tyFloat128,
|
||||
tyString, tyCstring, tyInt..tyInt64, tyFloat..tyFloat128,
|
||||
tyUInt..tyUInt64, tyCompositeTypeClass:
|
||||
return isvar
|
||||
else:
|
||||
@@ -1383,7 +1383,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
|
||||
# 'pointer' is NOT compatible to regionized pointers
|
||||
# so 'dealloc(regionPtr)' fails:
|
||||
if a.len == 1: result = isConvertible
|
||||
of tyCString: result = isConvertible
|
||||
of tyCstring: result = isConvertible
|
||||
else: discard
|
||||
of tyString:
|
||||
case a.kind
|
||||
@@ -1394,10 +1394,10 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
|
||||
result = isEqual
|
||||
of tyNil: result = isNone
|
||||
else: discard
|
||||
of tyCString:
|
||||
of tyCstring:
|
||||
# conversion from string to cstring is automatic:
|
||||
case a.kind
|
||||
of tyCString:
|
||||
of tyCstring:
|
||||
if tfNotNil in f.flags and tfNotNil notin a.flags:
|
||||
result = isNilConversion
|
||||
else:
|
||||
@@ -2436,7 +2436,7 @@ proc matchesAux(c: PContext, n, nOrig: PNode, m: var TCandidate, marker: var Int
|
||||
n[a] = prepareOperand(c, n[a])
|
||||
if skipTypes(n[a].typ, abstractVar-{tyTypeDesc}).kind==tyString:
|
||||
m.call.add implicitConv(nkHiddenStdConv,
|
||||
getSysType(c.graph, n[a].info, tyCString),
|
||||
getSysType(c.graph, n[a].info, tyCstring),
|
||||
copyTree(n[a]), m, c)
|
||||
else:
|
||||
m.call.add copyTree(n[a])
|
||||
|
||||
@@ -242,7 +242,7 @@ proc computeSizeAlign(conf: ConfigRef; typ: PType) =
|
||||
else:
|
||||
typ.size = 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
|
||||
if base == typ:
|
||||
# this is not the correct location to detect ``type A = ptr A``
|
||||
|
||||
@@ -8,13 +8,13 @@ type
|
||||
name*: string
|
||||
children*: seq[Child]
|
||||
|
||||
C = enum cSourceNode, cString
|
||||
C = enum cSourceNode, cSourceString
|
||||
|
||||
Child* = ref object
|
||||
case kind*: C:
|
||||
of cSourceNode:
|
||||
node*: SourceNode
|
||||
of cString:
|
||||
of cSourceString:
|
||||
s*: string
|
||||
|
||||
SourceMap* = ref object
|
||||
@@ -44,7 +44,7 @@ type
|
||||
|
||||
|
||||
proc child*(s: string): Child =
|
||||
Child(kind: cString, s: s)
|
||||
Child(kind: cSourceString, s: s)
|
||||
|
||||
|
||||
proc child*(node: SourceNode): Child =
|
||||
@@ -72,7 +72,7 @@ proc text*(sourceNode: SourceNode, depth: int): string =
|
||||
let empty = " "
|
||||
result = &"{repeat(empty, depth)}SourceNode({sourceNode.source}:{sourceNode.line}:{sourceNode.column}):\n"
|
||||
for child in sourceNode.children:
|
||||
if child.kind == cString:
|
||||
if child.kind == cSourceString:
|
||||
result.add(&"{repeat(empty, depth + 1)}{child.s}\n")
|
||||
else:
|
||||
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)) =
|
||||
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)
|
||||
else:
|
||||
child.node.walk(fn)
|
||||
|
||||
@@ -497,14 +497,14 @@ proc transformConv(c: PTransf, n: PNode): PNode =
|
||||
result.typ = takeType(n.typ, n[1].typ, c.graph, c.idgen)
|
||||
#echo n.info, " came here and produced ", typeToString(result.typ),
|
||||
# " from ", typeToString(n.typ), " and ", typeToString(n[1].typ)
|
||||
of tyCString:
|
||||
of tyCstring:
|
||||
if source.kind == tyString:
|
||||
result = newTransNode(nkStringToCString, n, 1)
|
||||
result[0] = transform(c, n[1])
|
||||
else:
|
||||
result = transformSons(c, n)
|
||||
of tyString:
|
||||
if source.kind == tyCString:
|
||||
if source.kind == tyCstring:
|
||||
result = newTransNode(nkCStringToString, n, 1)
|
||||
result[0] = transform(c, n[1])
|
||||
else:
|
||||
|
||||
@@ -116,7 +116,7 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
|
||||
result = t
|
||||
of tyNil:
|
||||
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
|
||||
of tyOrdinal:
|
||||
if kind != skParam: result = t
|
||||
|
||||
@@ -503,7 +503,7 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
|
||||
result = typeToString(t[0])
|
||||
elif prefer in {preferResolved, preferMixed}:
|
||||
case t.kind
|
||||
of IntegralTypes + {tyFloat..tyFloat128} + {tyString, tyCString}:
|
||||
of IntegralTypes + {tyFloat..tyFloat128} + {tyString, tyCstring}:
|
||||
result = typeToStr[t.kind]
|
||||
of tyGenericBody:
|
||||
result = typeToString(t.lastSon)
|
||||
@@ -762,7 +762,7 @@ proc firstOrd*(conf: ConfigRef; t: PType): Int128 =
|
||||
of tyOrdinal:
|
||||
if t.len > 0: result = firstOrd(conf, lastSon(t))
|
||||
else: internalError(conf, "invalid kind for firstOrd(" & $t.kind & ')')
|
||||
of tyUncheckedArray, tyCString:
|
||||
of tyUncheckedArray, tyCstring:
|
||||
result = Zero
|
||||
else:
|
||||
internalError(conf, "invalid kind for firstOrd(" & $t.kind & ')')
|
||||
@@ -1129,7 +1129,7 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
|
||||
return true
|
||||
|
||||
case a.kind
|
||||
of tyEmpty, tyChar, tyBool, tyNil, tyPointer, tyString, tyCString,
|
||||
of tyEmpty, tyChar, tyBool, tyNil, tyPointer, tyString, tyCstring,
|
||||
tyInt..tyUInt64, tyTyped, tyUntyped, tyVoid:
|
||||
result = sameFlags(a, b)
|
||||
of tyStatic, tyFromExpr:
|
||||
|
||||
@@ -399,7 +399,7 @@ proc opConv(c: PCtx; dest: var TFullReg, src: TFullReg, desttyp, srctyp: PType):
|
||||
dest.node.strVal = $src.floatVal
|
||||
of tyString:
|
||||
dest.node.strVal = src.node.strVal
|
||||
of tyCString:
|
||||
of tyCstring:
|
||||
if src.node.kind == nkBracket:
|
||||
# Array of chars
|
||||
var strVal = ""
|
||||
|
||||
@@ -257,7 +257,7 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo;
|
||||
result.add t.n[1].copyTree
|
||||
of tyPointer: result = atomicType("pointer", mPointer)
|
||||
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 tyInt8: result = atomicType("int8", mInt8)
|
||||
of tyInt16: result = atomicType("int16", mInt16)
|
||||
|
||||
@@ -190,7 +190,7 @@ proc getSlotKind(t: PType): TSlotKind =
|
||||
case t.skipTypes(abstractRange-{tyTypeDesc}).kind
|
||||
of tyBool, tyChar, tyEnum, tyOrdinal, tyInt..tyInt64, tyUInt..tyUInt64:
|
||||
slotTempInt
|
||||
of tyString, tyCString:
|
||||
of tyString, tyCstring:
|
||||
slotTempStr
|
||||
of tyFloat..tyFloat128:
|
||||
slotTempFloat
|
||||
@@ -1053,7 +1053,7 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) =
|
||||
of mLengthStr:
|
||||
case n[1].typ.kind
|
||||
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
|
||||
of mIncl, mExcl:
|
||||
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])
|
||||
case n[1].typ.skipTypes(abstractVar-{tyTypeDesc}).kind:
|
||||
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)
|
||||
c.freeTemp(tmp)
|
||||
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 tmp = c.genx(ri)
|
||||
if le[0].typ.skipTypes(abstractVarRange-{tyTypeDesc}).kind in {
|
||||
tyString, tyCString}:
|
||||
tyString, tyCstring}:
|
||||
c.preventFalseAlias(le, opcWrStrIdx, dest, idx, tmp)
|
||||
else:
|
||||
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) =
|
||||
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
|
||||
genArrAccessOpcode(c, n, dest, opc, flags)
|
||||
elif arrayType == tyTypeDesc:
|
||||
@@ -1813,7 +1813,7 @@ proc getNullValue(typ: PType, info: TLineInfo; conf: ConfigRef): PNode =
|
||||
result = newNodeIT(nkUIntLit, info, t)
|
||||
of tyFloat..tyFloat128:
|
||||
result = newNodeIT(nkFloatLit, info, t)
|
||||
of tyCString, tyString:
|
||||
of tyCstring, tyString:
|
||||
result = newNodeIT(nkStrLit, info, t)
|
||||
result.strVal = ""
|
||||
of tyVar, tyLent, tyPointer, tyPtr, tyUntyped,
|
||||
|
||||
@@ -121,7 +121,7 @@ proc storeAny(s: var string; t: PType; a: PNode; stored: var IntSet;
|
||||
s.add(", ")
|
||||
storeAny(s, t.lastSon, a, stored, conf)
|
||||
s.add("]")
|
||||
of tyString, tyCString:
|
||||
of tyString, tyCstring:
|
||||
if a.kind == nkNilLit: s.add("null")
|
||||
else: s.add(escapeJson(a.strVal))
|
||||
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)
|
||||
else: raiseParseErr(p, "']' end of ref-address pair expected")
|
||||
else: raiseParseErr(p, "int for pointer type expected")
|
||||
of tyString, tyCString:
|
||||
of tyString, tyCstring:
|
||||
case p.kind
|
||||
of jsonNull:
|
||||
result = newNode(nkNilLit)
|
||||
|
||||
@@ -322,12 +322,12 @@ proc base*(x: Any): Any =
|
||||
proc isNil*(x: Any): bool =
|
||||
## `isNil` for an `x` that represents a cstring, proc or
|
||||
## 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)[])
|
||||
|
||||
const pointerLike =
|
||||
when defined(gcDestructors): {tyCString, tyRef, tyPtr, tyPointer, tyProc}
|
||||
else: {tyString, tyCString, tyRef, tyPtr, tyPointer, tySequence, tyProc}
|
||||
when defined(gcDestructors): {tyCstring, tyRef, tyPtr, tyPointer, tyProc}
|
||||
else: {tyString, tyCstring, tyRef, tyPtr, tyPointer, tySequence, tyProc}
|
||||
|
||||
proc getPointer*(x: Any): pointer =
|
||||
## 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 =
|
||||
## 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)[]
|
||||
|
||||
proc assign*(x, y: Any) =
|
||||
|
||||
@@ -167,7 +167,7 @@ when false:
|
||||
of tyPointer: k = "range"
|
||||
of tyOpenArray: k = "openarray"
|
||||
of tyString: k = "string"
|
||||
of tyCString: k = "cstring"
|
||||
of tyCstring: k = "cstring"
|
||||
of tyInt: k = "int"
|
||||
of tyInt32: k = "int32"
|
||||
else: k = "other"
|
||||
|
||||
@@ -40,7 +40,7 @@ type
|
||||
tyPointer,
|
||||
tyOpenArray,
|
||||
tyString,
|
||||
tyCString,
|
||||
tyCstring,
|
||||
tyForward,
|
||||
tyInt,
|
||||
tyInt8,
|
||||
|
||||
@@ -281,7 +281,7 @@ when not defined(useNimRtl):
|
||||
of tyString:
|
||||
let sp = cast[ptr string](p)
|
||||
reprStrAux(result, sp[].cstring, sp[].len)
|
||||
of tyCString:
|
||||
of tyCstring:
|
||||
let cs = cast[ptr cstring](p)[]
|
||||
if cs.isNil: add result, "nil"
|
||||
else: reprStrAux(result, cs, cs.len)
|
||||
|
||||
@@ -200,7 +200,7 @@ proc reprAux(result: var string, p: pointer, typ: PNimType,
|
||||
var fp: int
|
||||
{. emit: "`fp` = `p`;\n" .}
|
||||
add(result, reprStr(cast[string](p)))
|
||||
of tyCString:
|
||||
of tyCstring:
|
||||
var fp: cstring
|
||||
{. emit: "`fp` = `p`;\n" .}
|
||||
if fp.isNil:
|
||||
|
||||
Reference in New Issue
Block a user