mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-03 19:52:36 +00:00
fixes C++ compilation
This commit is contained in:
@@ -101,8 +101,9 @@ proc toConstLenV3(len: int): string =
|
||||
result = rope((len shl 1) or 1)
|
||||
|
||||
proc genStringLiteralDataOnlyV3(m: BModule, s: string; result: Rope; isConst: bool) =
|
||||
# TODO: fixme: perhaps use makeCString for clarity for C
|
||||
m.s[cfsStrData].addf("static $4 NIM_CHAR $1[$2] = $3;$n",
|
||||
[result, rope(s.len), makeCString(s),
|
||||
[result, rope(s.len), makeCCharArray(s),
|
||||
rope(if isConst: "const" else: "")])
|
||||
|
||||
proc genStringLiteralV3(m: BModule; n: PNode; isConst: bool; result: var Rope) =
|
||||
@@ -114,12 +115,12 @@ proc genStringLiteralV3(m: BModule; n: PNode; isConst: bool; result: var Rope) =
|
||||
result.add tmp
|
||||
cgsym(m, "NimStringV3")
|
||||
# string literal not found in the cache:
|
||||
m.s[cfsStrData].addf("static $4 NimStringV3 $1 = {$2, &$3};$n",
|
||||
m.s[cfsStrData].addf("static $4 NimStringV3 $1 = {$2, (NIM_CHAR*)&$3};$n",
|
||||
[tmp, toConstLenV3(n.strVal.len), pureLit, rope(if isConst: "const" else: "")])
|
||||
else:
|
||||
let tmp = getTempName(m)
|
||||
result.add tmp
|
||||
m.s[cfsStrData].addf("static $4 NimStringV3 $1 = {$2, &$3};$n",
|
||||
m.s[cfsStrData].addf("static $4 NimStringV3 $1 = {$2, (NIM_CHAR*)&$3};$n",
|
||||
[tmp, toConstLenV3(n.strVal.len), m.tmpBase & rope(id),
|
||||
rope(if isConst: "const" else: "")])
|
||||
|
||||
@@ -133,7 +134,7 @@ proc genStringLiteralV3Const(m: BModule; n: PNode; isConst: bool; result: var Ro
|
||||
genStringLiteralDataOnlyV3(m, n.strVal, pureLit, isConst)
|
||||
else:
|
||||
pureLit = m.tmpBase & rope(id)
|
||||
result.addf "{$1, &$2}", [toConstLenV3(n.strVal.len), pureLit]
|
||||
result.addf "{$1, (NIM_CHAR*)&$2}", [toConstLenV3(n.strVal.len), pureLit]
|
||||
|
||||
# ------ Version selector ---------------------------------------------------
|
||||
|
||||
|
||||
@@ -60,6 +60,22 @@ proc makeCString*(s: string): Rope =
|
||||
toCChar(s[i], result)
|
||||
result.add('\"')
|
||||
|
||||
proc makeCCharArray*(s: string): Rope =
|
||||
result = newStringOfCap(int(s.len.toFloat * 1.1) + 1)
|
||||
result.add("{")
|
||||
for i in 0..<s.len:
|
||||
# line wrapping of string litterals in cgen'd code was a bad idea, e.g. causes: bug #16265
|
||||
# It also makes reading c sources or grepping harder, for zero benefit.
|
||||
# const MaxLineLength = 64
|
||||
# if (i + 1) mod MaxLineLength == 0:
|
||||
# res.add("\"\L\"")
|
||||
if i != 0:
|
||||
result.add ", "
|
||||
result.add '\''
|
||||
toCChar(s[i], result)
|
||||
result.add '\''
|
||||
result.add('}')
|
||||
|
||||
proc newFileInfo(fullPath: AbsoluteFile, projPath: RelativeFile): TFileInfo =
|
||||
result.fullPath = fullPath
|
||||
#shallow(result.fullPath)
|
||||
|
||||
Reference in New Issue
Block a user