compiler_ropes: ropeToStr -> $
This commit is contained in:
parent
b4e4ea8d1b
commit
c40249cd43
13 changed files with 32 additions and 37 deletions
|
|
@ -452,17 +452,16 @@ proc debug(n: PSym) =
|
||||||
elif n.kind == skUnknown:
|
elif n.kind == skUnknown:
|
||||||
msgWriteln("skUnknown")
|
msgWriteln("skUnknown")
|
||||||
else:
|
else:
|
||||||
#writeln(stdout, ropeToStr(symToYaml(n, 0, 1)))
|
#writeln(stdout, $symToYaml(n, 0, 1))
|
||||||
msgWriteln("$1_$2: $3, $4, $5, $6" % [
|
msgWriteln("$1_$2: $3, $4, $5, $6" % [
|
||||||
n.name.s, $n.id, flagsToStr(n.flags).ropeToStr,
|
n.name.s, $n.id, $flagsToStr(n.flags), $flagsToStr(n.loc.flags),
|
||||||
flagsToStr(n.loc.flags).ropeToStr, lineInfoToStr(n.info).ropeToStr,
|
$lineInfoToStr(n.info), $n.kind])
|
||||||
$n.kind])
|
|
||||||
|
|
||||||
proc debug(n: PType) =
|
proc debug(n: PType) =
|
||||||
msgWriteln(ropeToStr(debugType(n)))
|
msgWriteln($debugType(n))
|
||||||
|
|
||||||
proc debug(n: PNode) =
|
proc debug(n: PNode) =
|
||||||
msgWriteln(ropeToStr(debugTree(n, 0, 100)))
|
msgWriteln($debugTree(n, 0, 100))
|
||||||
|
|
||||||
const
|
const
|
||||||
EmptySeq = @[]
|
EmptySeq = @[]
|
||||||
|
|
|
||||||
|
|
@ -243,24 +243,24 @@ proc encodeNode(w: PRodWriter, fInfo: TLineInfo, n: PNode,
|
||||||
encodeNode(w, n.info, n.sons[i], result)
|
encodeNode(w, n.info, n.sons[i], result)
|
||||||
add(result, ')')
|
add(result, ')')
|
||||||
|
|
||||||
proc encodeLoc(w: PRodWriter, loc: TLoc, result: var string) =
|
proc encodeLoc(w: PRodWriter, loc: TLoc, result: var string) =
|
||||||
var oldLen = result.len
|
var oldLen = result.len
|
||||||
result.add('<')
|
result.add('<')
|
||||||
if loc.k != low(loc.k): encodeVInt(ord(loc.k), result)
|
if loc.k != low(loc.k): encodeVInt(ord(loc.k), result)
|
||||||
if loc.s != low(loc.s):
|
if loc.s != low(loc.s):
|
||||||
add(result, '*')
|
add(result, '*')
|
||||||
encodeVInt(ord(loc.s), result)
|
encodeVInt(ord(loc.s), result)
|
||||||
if loc.flags != {}:
|
if loc.flags != {}:
|
||||||
add(result, '$')
|
add(result, '$')
|
||||||
encodeVInt(cast[int32](loc.flags), result)
|
encodeVInt(cast[int32](loc.flags), result)
|
||||||
if loc.t != nil:
|
if loc.t != nil:
|
||||||
add(result, '^')
|
add(result, '^')
|
||||||
encodeVInt(cast[int32](loc.t.id), result)
|
encodeVInt(cast[int32](loc.t.id), result)
|
||||||
pushType(w, loc.t)
|
pushType(w, loc.t)
|
||||||
if loc.r != nil:
|
if loc.r != nil:
|
||||||
add(result, '!')
|
add(result, '!')
|
||||||
encodeStr(ropeToStr(loc.r), result)
|
encodeStr($loc.r, result)
|
||||||
if loc.a != 0:
|
if loc.a != 0:
|
||||||
add(result, '?')
|
add(result, '?')
|
||||||
encodeVInt(loc.a, result)
|
encodeVInt(loc.a, result)
|
||||||
if oldLen + 1 == result.len:
|
if oldLen + 1 == result.len:
|
||||||
|
|
@ -317,7 +317,7 @@ proc encodeLib(w: PRodWriter, lib: PLib, info: TLineInfo, result: var string) =
|
||||||
add(result, '|')
|
add(result, '|')
|
||||||
encodeVInt(ord(lib.kind), result)
|
encodeVInt(ord(lib.kind), result)
|
||||||
add(result, '|')
|
add(result, '|')
|
||||||
encodeStr(ropeToStr(lib.name), result)
|
encodeStr($lib.name, result)
|
||||||
add(result, '|')
|
add(result, '|')
|
||||||
encodeNode(w, info, lib.path, result)
|
encodeNode(w, info, lib.path, result)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -413,7 +413,7 @@ proc genInfixCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
||||||
assert(typ.kind == tyProc)
|
assert(typ.kind == tyProc)
|
||||||
var length = sonsLen(ri)
|
var length = sonsLen(ri)
|
||||||
assert(sonsLen(typ) == sonsLen(typ.n))
|
assert(sonsLen(typ) == sonsLen(typ.n))
|
||||||
# don't call 'ropeToStr' here for efficiency:
|
# don't call '$' here for efficiency:
|
||||||
let pat = ri.sons[0].sym.loc.r.data
|
let pat = ri.sons[0].sym.loc.r.data
|
||||||
internalAssert pat != nil
|
internalAssert pat != nil
|
||||||
if pat.contains({'#', '(', '@', '\''}):
|
if pat.contains({'#', '(', '@', '\''}):
|
||||||
|
|
@ -462,7 +462,7 @@ proc genNamedParamCall(p: BProc, ri: PNode, d: var TLoc) =
|
||||||
var length = sonsLen(ri)
|
var length = sonsLen(ri)
|
||||||
assert(sonsLen(typ) == sonsLen(typ.n))
|
assert(sonsLen(typ) == sonsLen(typ.n))
|
||||||
|
|
||||||
# don't call 'ropeToStr' here for efficiency:
|
# don't call '$' here for efficiency:
|
||||||
let pat = ri.sons[0].sym.loc.r.data
|
let pat = ri.sons[0].sym.loc.r.data
|
||||||
internalAssert pat != nil
|
internalAssert pat != nil
|
||||||
var start = 3
|
var start = 3
|
||||||
|
|
|
||||||
|
|
@ -1730,7 +1730,7 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
||||||
mParseBiggestFloat:
|
mParseBiggestFloat:
|
||||||
var opr = e.sons[0].sym
|
var opr = e.sons[0].sym
|
||||||
if lfNoDecl notin opr.loc.flags:
|
if lfNoDecl notin opr.loc.flags:
|
||||||
discard cgsym(p.module, opr.loc.r.ropeToStr)
|
discard cgsym(p.module, $opr.loc.r)
|
||||||
genCall(p, e, d)
|
genCall(p, e, d)
|
||||||
of mReset: genReset(p, e)
|
of mReset: genReset(p, e)
|
||||||
of mEcho: genEcho(p, e[1].skipConv)
|
of mEcho: genEcho(p, e[1].skipConv)
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ proc writeTypeCache(a: TIdTable, s: var string) =
|
||||||
s.add(' ')
|
s.add(' ')
|
||||||
encodeVInt(id, s)
|
encodeVInt(id, s)
|
||||||
s.add(':')
|
s.add(':')
|
||||||
encodeStr(PRope(value).ropeToStr, s)
|
encodeStr($PRope(value), s)
|
||||||
inc i
|
inc i
|
||||||
s.add('}')
|
s.add('}')
|
||||||
|
|
||||||
|
|
@ -280,11 +280,11 @@ proc readMergeSections(cfilename: string, m: var TMergeSections) =
|
||||||
proc mergeRequired*(m: BModule): bool =
|
proc mergeRequired*(m: BModule): bool =
|
||||||
for i in cfsHeaders..cfsProcs:
|
for i in cfsHeaders..cfsProcs:
|
||||||
if m.s[i] != nil:
|
if m.s[i] != nil:
|
||||||
#echo "not empty: ", i, " ", ropeToStr(m.s[i])
|
#echo "not empty: ", i, " ", m.s[i]
|
||||||
return true
|
return true
|
||||||
for i in low(TCProcSection)..high(TCProcSection):
|
for i in low(TCProcSection)..high(TCProcSection):
|
||||||
if m.initProc.s(i) != nil:
|
if m.initProc.s(i) != nil:
|
||||||
#echo "not empty: ", i, " ", ropeToStr(m.initProc.s[i])
|
#echo "not empty: ", i, " ", m.initProc.s[i]
|
||||||
return true
|
return true
|
||||||
|
|
||||||
proc mergeFiles*(cfilename: string, m: BModule) =
|
proc mergeFiles*(cfilename: string, m: BModule) =
|
||||||
|
|
|
||||||
|
|
@ -936,7 +936,7 @@ proc genAsmOrEmitStmt(p: BProc, t: PNode, isAsmStmt=false): PRope =
|
||||||
if sym.kind in {skProc, skIterator, skClosureIterator, skMethod}:
|
if sym.kind in {skProc, skIterator, skClosureIterator, skMethod}:
|
||||||
var a: TLoc
|
var a: TLoc
|
||||||
initLocExpr(p, t.sons[i], a)
|
initLocExpr(p, t.sons[i], a)
|
||||||
res.add(rdLoc(a).ropeToStr)
|
res.add($rdLoc(a))
|
||||||
else:
|
else:
|
||||||
var r = sym.loc.r
|
var r = sym.loc.r
|
||||||
if r == nil:
|
if r == nil:
|
||||||
|
|
@ -944,7 +944,7 @@ proc genAsmOrEmitStmt(p: BProc, t: PNode, isAsmStmt=false): PRope =
|
||||||
# it doesn't matter much:
|
# it doesn't matter much:
|
||||||
r = mangleName(sym)
|
r = mangleName(sym)
|
||||||
sym.loc.r = r # but be consequent!
|
sym.loc.r = r # but be consequent!
|
||||||
res.add(r.ropeToStr)
|
res.add($r)
|
||||||
else: internalError(t.sons[i].info, "genAsmOrEmitStmt()")
|
else: internalError(t.sons[i].info, "genAsmOrEmitStmt()")
|
||||||
|
|
||||||
if isAsmStmt and hasGnuAsm in CC[cCompiler].props:
|
if isAsmStmt and hasGnuAsm in CC[cCompiler].props:
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ proc ropecg(m: BModule, frmt: TFormatStr, args: varargs[PRope]): PRope =
|
||||||
while frmt[i] in Digits:
|
while frmt[i] in Digits:
|
||||||
j = (j * 10) + ord(frmt[i]) - ord('0')
|
j = (j * 10) + ord(frmt[i]) - ord('0')
|
||||||
inc(i)
|
inc(i)
|
||||||
app(result, cgsym(m, args[j-1].ropeToStr))
|
app(result, cgsym(m, $args[j-1]))
|
||||||
var start = i
|
var start = i
|
||||||
while i < length:
|
while i < length:
|
||||||
if frmt[i] != '$' and frmt[i] != '#': inc(i)
|
if frmt[i] != '$' and frmt[i] != '#': inc(i)
|
||||||
|
|
@ -555,8 +555,7 @@ proc symInDynamicLib(m: BModule, sym: PSym) =
|
||||||
params.app(rdLoc(a))
|
params.app(rdLoc(a))
|
||||||
params.app(", ")
|
params.app(", ")
|
||||||
let load = ropef("\t$1 = ($2) ($3$4));$n",
|
let load = ropef("\t$1 = ($2) ($3$4));$n",
|
||||||
[tmp, getTypeDesc(m, sym.typ),
|
[tmp, getTypeDesc(m, sym.typ), params, makeCString($extname)])
|
||||||
params, makeCString(ropeToStr(extname))])
|
|
||||||
var last = lastSon(n)
|
var last = lastSon(n)
|
||||||
if last.kind == nkHiddenStdConv: last = last.sons[1]
|
if last.kind == nkHiddenStdConv: last = last.sons[1]
|
||||||
internalAssert(last.kind == nkStrLit)
|
internalAssert(last.kind == nkStrLit)
|
||||||
|
|
@ -570,8 +569,7 @@ proc symInDynamicLib(m: BModule, sym: PSym) =
|
||||||
else:
|
else:
|
||||||
appcg(m, m.s[cfsDynLibInit],
|
appcg(m, m.s[cfsDynLibInit],
|
||||||
"\t$1 = ($2) #nimGetProcAddr($3, $4);$n",
|
"\t$1 = ($2) #nimGetProcAddr($3, $4);$n",
|
||||||
[tmp, getTypeDesc(m, sym.typ),
|
[tmp, getTypeDesc(m, sym.typ), lib.name, makeCString($extname)])
|
||||||
lib.name, makeCString(ropeToStr(extname))])
|
|
||||||
appf(m.s[cfsVars], "$2 $1;$n", [sym.loc.r, getTypeDesc(m, sym.loc.t)])
|
appf(m.s[cfsVars], "$2 $1;$n", [sym.loc.r, getTypeDesc(m, sym.loc.t)])
|
||||||
|
|
||||||
proc varInDynamicLib(m: BModule, sym: PSym) =
|
proc varInDynamicLib(m: BModule, sym: PSym) =
|
||||||
|
|
@ -584,8 +582,7 @@ proc varInDynamicLib(m: BModule, sym: PSym) =
|
||||||
inc(m.labels, 2)
|
inc(m.labels, 2)
|
||||||
appcg(m, m.s[cfsDynLibInit],
|
appcg(m, m.s[cfsDynLibInit],
|
||||||
"$1 = ($2*) #nimGetProcAddr($3, $4);$n",
|
"$1 = ($2*) #nimGetProcAddr($3, $4);$n",
|
||||||
[tmp, getTypeDesc(m, sym.typ),
|
[tmp, getTypeDesc(m, sym.typ), lib.name, makeCString($extname)])
|
||||||
lib.name, makeCString(ropeToStr(extname))])
|
|
||||||
appf(m.s[cfsVars], "$2* $1;$n",
|
appf(m.s[cfsVars], "$2* $1;$n",
|
||||||
[sym.loc.r, getTypeDesc(m, sym.loc.t)])
|
[sym.loc.r, getTypeDesc(m, sym.loc.t)])
|
||||||
|
|
||||||
|
|
@ -1255,7 +1252,7 @@ proc writeModule(m: BModule, pending: bool) =
|
||||||
var code = genModule(m, cfile)
|
var code = genModule(m, cfile)
|
||||||
when hasTinyCBackend:
|
when hasTinyCBackend:
|
||||||
if gCmd == cmdRun:
|
if gCmd == cmdRun:
|
||||||
tccgen.compileCCode(ropeToStr(code))
|
tccgen.compileCCode($code)
|
||||||
return
|
return
|
||||||
|
|
||||||
if shouldRecompile(code, cfile):
|
if shouldRecompile(code, cfile):
|
||||||
|
|
|
||||||
|
|
@ -436,7 +436,7 @@ proc genJSONItem(d: PDoc, n, nameNode: PNode, k: TSymKind): JsonNode =
|
||||||
if not isVisible(nameNode): return
|
if not isVisible(nameNode): return
|
||||||
var
|
var
|
||||||
name = getName(d, nameNode)
|
name = getName(d, nameNode)
|
||||||
comm = genRecComment(d, n).ropeToStr()
|
comm = $genRecComment(d, n)
|
||||||
r: TSrcGen
|
r: TSrcGen
|
||||||
|
|
||||||
initTokRender(r, n, {renderNoBody, renderNoComments, renderDocComments})
|
initTokRender(r, n, {renderNoBody, renderNoComments, renderDocComments})
|
||||||
|
|
|
||||||
|
|
@ -874,7 +874,7 @@ proc genFieldAddr(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
if b.sons[1].kind != nkSym: internalError(b.sons[1].info, "genFieldAddr")
|
if b.sons[1].kind != nkSym: internalError(b.sons[1].info, "genFieldAddr")
|
||||||
var f = b.sons[1].sym
|
var f = b.sons[1].sym
|
||||||
if f.loc.r == nil: f.loc.r = mangleName(f)
|
if f.loc.r == nil: f.loc.r = mangleName(f)
|
||||||
r.res = makeJSString(ropeToStr(f.loc.r))
|
r.res = makeJSString($f.loc.r)
|
||||||
internalAssert a.typ != etyBaseIndex
|
internalAssert a.typ != etyBaseIndex
|
||||||
r.address = a.res
|
r.address = a.res
|
||||||
r.kind = resExpr
|
r.kind = resExpr
|
||||||
|
|
|
||||||
|
|
@ -776,7 +776,7 @@ proc rawMessage*(msg: TMsgKind, arg: string) =
|
||||||
|
|
||||||
proc writeSurroundingSrc(info: TLineInfo) =
|
proc writeSurroundingSrc(info: TLineInfo) =
|
||||||
const indent = " "
|
const indent = " "
|
||||||
msgWriteln(indent & info.sourceLine.ropeToStr)
|
msgWriteln(indent & $info.sourceLine)
|
||||||
msgWriteln(indent & spaces(info.col) & '^')
|
msgWriteln(indent & spaces(info.col) & '^')
|
||||||
|
|
||||||
proc formatMsg*(info: TLineInfo, msg: TMsgKind, arg: string): string =
|
proc formatMsg*(info: TLineInfo, msg: TMsgKind, arg: string): string =
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ proc validateExternCName(s: PSym, info: TLineInfo) =
|
||||||
## Valid identifiers are those alphanumeric including the underscore not
|
## Valid identifiers are those alphanumeric including the underscore not
|
||||||
## starting with a number. If the check fails, a generic error will be
|
## starting with a number. If the check fails, a generic error will be
|
||||||
## displayed to the user.
|
## displayed to the user.
|
||||||
let target = ropeToStr(s.loc.r)
|
let target = $s.loc.r
|
||||||
if target.len < 1 or target[0] notin IdentStartChars or
|
if target.len < 1 or target[0] notin IdentStartChars or
|
||||||
not target.allCharsInSet(IdentChars):
|
not target.allCharsInSet(IdentChars):
|
||||||
localError(info, errGenerated, "invalid exported symbol")
|
localError(info, errGenerated, "invalid exported symbol")
|
||||||
|
|
|
||||||
|
|
@ -186,7 +186,7 @@ proc encodeLoc(w: PRodWriter, loc: TLoc, result: var string) =
|
||||||
pushType(w, loc.t)
|
pushType(w, loc.t)
|
||||||
if loc.r != nil:
|
if loc.r != nil:
|
||||||
add(result, '!')
|
add(result, '!')
|
||||||
encodeStr(ropeToStr(loc.r), result)
|
encodeStr($loc.r, result)
|
||||||
if oldLen + 1 == result.len:
|
if oldLen + 1 == result.len:
|
||||||
# no data was necessary, so remove the '<' again:
|
# no data was necessary, so remove the '<' again:
|
||||||
setLen(result, oldLen)
|
setLen(result, oldLen)
|
||||||
|
|
@ -241,7 +241,7 @@ proc encodeLib(w: PRodWriter, lib: PLib, info: TLineInfo, result: var string) =
|
||||||
add(result, '|')
|
add(result, '|')
|
||||||
encodeVInt(ord(lib.kind), result)
|
encodeVInt(ord(lib.kind), result)
|
||||||
add(result, '|')
|
add(result, '|')
|
||||||
encodeStr(ropeToStr(lib.name), result)
|
encodeStr($lib.name, result)
|
||||||
add(result, '|')
|
add(result, '|')
|
||||||
encodeNode(w, info, lib.path, result)
|
encodeNode(w, info, lib.path, result)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,6 @@ proc prepend*(a: var PRope, b: PRope)
|
||||||
proc toRope*(s: string): PRope
|
proc toRope*(s: string): PRope
|
||||||
proc toRope*(i: BiggestInt): PRope
|
proc toRope*(i: BiggestInt): PRope
|
||||||
proc writeRopeIfNotEqual*(r: PRope, filename: string): bool
|
proc writeRopeIfNotEqual*(r: PRope, filename: string): bool
|
||||||
proc ropeToStr*(p: PRope): string
|
|
||||||
proc ropef*(frmt: TFormatStr, args: varargs[PRope]): PRope
|
proc ropef*(frmt: TFormatStr, args: varargs[PRope]): PRope
|
||||||
proc appf*(c: var PRope, frmt: TFormatStr, args: varargs[PRope])
|
proc appf*(c: var PRope, frmt: TFormatStr, args: varargs[PRope])
|
||||||
proc ropeEqualsFile*(r: PRope, f: string): bool
|
proc ropeEqualsFile*(r: PRope, f: string): bool
|
||||||
|
|
@ -180,7 +179,7 @@ proc newRecRopeToStr(result: var string, resultLen: var int, r: PRope) =
|
||||||
inc(resultLen, it.length)
|
inc(resultLen, it.length)
|
||||||
assert(resultLen <= len(result))
|
assert(resultLen <= len(result))
|
||||||
|
|
||||||
proc ropeToStr(p: PRope): string =
|
proc `$`*(p: PRope): string =
|
||||||
if p == nil:
|
if p == nil:
|
||||||
result = ""
|
result = ""
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue