preparations of making compiler/msgs.nim free of global variables
This commit is contained in:
parent
2a7fc84c86
commit
bf6c2c5ccf
38 changed files with 179 additions and 183 deletions
|
|
@ -15,13 +15,13 @@ import
|
||||||
ast, hashes, intsets, strutils, options, msgs, ropes, idents, rodutils
|
ast, hashes, intsets, strutils, options, msgs, ropes, idents, rodutils
|
||||||
|
|
||||||
proc hashNode*(p: RootRef): Hash
|
proc hashNode*(p: RootRef): Hash
|
||||||
proc treeToYaml*(n: PNode, indent: int = 0, maxRecDepth: int = - 1): Rope
|
proc treeToYaml*(conf: ConfigRef; n: PNode, indent: int = 0, maxRecDepth: int = - 1): Rope
|
||||||
# Convert a tree into its YAML representation; this is used by the
|
# Convert a tree into its YAML representation; this is used by the
|
||||||
# YAML code generator and it is invaluable for debugging purposes.
|
# YAML code generator and it is invaluable for debugging purposes.
|
||||||
# If maxRecDepht <> -1 then it won't print the whole graph.
|
# If maxRecDepht <> -1 then it won't print the whole graph.
|
||||||
proc typeToYaml*(n: PType, indent: int = 0, maxRecDepth: int = - 1): Rope
|
proc typeToYaml*(conf: ConfigRef; n: PType, indent: int = 0, maxRecDepth: int = - 1): Rope
|
||||||
proc symToYaml*(n: PSym, indent: int = 0, maxRecDepth: int = - 1): Rope
|
proc symToYaml*(conf: ConfigRef; n: PSym, indent: int = 0, maxRecDepth: int = - 1): Rope
|
||||||
proc lineInfoToStr*(info: TLineInfo): Rope
|
proc lineInfoToStr*(conf: ConfigRef; info: TLineInfo): Rope
|
||||||
|
|
||||||
# ----------------------- node sets: ---------------------------------------
|
# ----------------------- node sets: ---------------------------------------
|
||||||
proc objectSetContains*(t: TObjectSet, obj: RootRef): bool
|
proc objectSetContains*(t: TObjectSet, obj: RootRef): bool
|
||||||
|
|
@ -63,9 +63,9 @@ proc nextIdentIter*(ti: var TIdentIter, tab: TStrTable): PSym
|
||||||
|
|
||||||
# these are for debugging only: They are not really deprecated, but I want
|
# these are for debugging only: They are not really deprecated, but I want
|
||||||
# the warning so that release versions do not contain debugging statements:
|
# the warning so that release versions do not contain debugging statements:
|
||||||
proc debug*(n: PSym) {.deprecated.}
|
proc debug*(conf: ConfigRef; n: PSym) {.deprecated.}
|
||||||
proc debug*(n: PType) {.deprecated.}
|
proc debug*(conf: ConfigRef; n: PType) {.deprecated.}
|
||||||
proc debug*(n: PNode) {.deprecated.}
|
proc debug*(conf: ConfigRef; n: PNode) {.deprecated.}
|
||||||
|
|
||||||
template mdbg*: bool {.dirty.} =
|
template mdbg*: bool {.dirty.} =
|
||||||
when compiles(c.module):
|
when compiles(c.module):
|
||||||
|
|
@ -250,16 +250,16 @@ proc flagsToStr[T](flags: set[T]): Rope =
|
||||||
add(result, makeYamlString($x))
|
add(result, makeYamlString($x))
|
||||||
result = "[" & result & "]"
|
result = "[" & result & "]"
|
||||||
|
|
||||||
proc lineInfoToStr(info: TLineInfo): Rope =
|
proc lineInfoToStr(conf: ConfigRef; info: TLineInfo): Rope =
|
||||||
result = "[$1, $2, $3]" % [makeYamlString(toFilename(info)),
|
result = "[$1, $2, $3]" % [makeYamlString(toFilename(conf, info)),
|
||||||
rope(toLinenumber(info)),
|
rope(toLinenumber(info)),
|
||||||
rope(toColumn(info))]
|
rope(toColumn(info))]
|
||||||
|
|
||||||
proc treeToYamlAux(n: PNode, marker: var IntSet,
|
proc treeToYamlAux(conf: ConfigRef; n: PNode, marker: var IntSet,
|
||||||
indent, maxRecDepth: int): Rope
|
indent, maxRecDepth: int): Rope
|
||||||
proc symToYamlAux(n: PSym, marker: var IntSet,
|
proc symToYamlAux(conf: ConfigRef; n: PSym, marker: var IntSet,
|
||||||
indent, maxRecDepth: int): Rope
|
indent, maxRecDepth: int): Rope
|
||||||
proc typeToYamlAux(n: PType, marker: var IntSet,
|
proc typeToYamlAux(conf: ConfigRef; n: PType, marker: var IntSet,
|
||||||
indent, maxRecDepth: int): Rope
|
indent, maxRecDepth: int): Rope
|
||||||
|
|
||||||
proc ropeConstr(indent: int, c: openArray[Rope]): Rope =
|
proc ropeConstr(indent: int, c: openArray[Rope]): Rope =
|
||||||
|
|
@ -273,7 +273,7 @@ proc ropeConstr(indent: int, c: openArray[Rope]): Rope =
|
||||||
inc(i, 2)
|
inc(i, 2)
|
||||||
addf(result, "$N$1}", [rspaces(indent)])
|
addf(result, "$N$1}", [rspaces(indent)])
|
||||||
|
|
||||||
proc symToYamlAux(n: PSym, marker: var IntSet, indent: int,
|
proc symToYamlAux(conf: ConfigRef; n: PSym, marker: var IntSet, indent: int,
|
||||||
maxRecDepth: int): Rope =
|
maxRecDepth: int): Rope =
|
||||||
if n == nil:
|
if n == nil:
|
||||||
result = rope("null")
|
result = rope("null")
|
||||||
|
|
@ -281,20 +281,20 @@ proc symToYamlAux(n: PSym, marker: var IntSet, indent: int,
|
||||||
result = "\"$1 @$2\"" % [rope(n.name.s), rope(
|
result = "\"$1 @$2\"" % [rope(n.name.s), rope(
|
||||||
strutils.toHex(cast[ByteAddress](n), sizeof(n) * 2))]
|
strutils.toHex(cast[ByteAddress](n), sizeof(n) * 2))]
|
||||||
else:
|
else:
|
||||||
var ast = treeToYamlAux(n.ast, marker, indent + 2, maxRecDepth - 1)
|
var ast = treeToYamlAux(conf, n.ast, marker, indent + 2, maxRecDepth - 1)
|
||||||
result = ropeConstr(indent, [rope("kind"),
|
result = ropeConstr(indent, [rope("kind"),
|
||||||
makeYamlString($n.kind),
|
makeYamlString($n.kind),
|
||||||
rope("name"), makeYamlString(n.name.s),
|
rope("name"), makeYamlString(n.name.s),
|
||||||
rope("typ"), typeToYamlAux(n.typ, marker,
|
rope("typ"), typeToYamlAux(conf, n.typ, marker,
|
||||||
indent + 2, maxRecDepth - 1),
|
indent + 2, maxRecDepth - 1),
|
||||||
rope("info"), lineInfoToStr(n.info),
|
rope("info"), lineInfoToStr(conf, n.info),
|
||||||
rope("flags"), flagsToStr(n.flags),
|
rope("flags"), flagsToStr(n.flags),
|
||||||
rope("magic"), makeYamlString($n.magic),
|
rope("magic"), makeYamlString($n.magic),
|
||||||
rope("ast"), ast, rope("options"),
|
rope("ast"), ast, rope("options"),
|
||||||
flagsToStr(n.options), rope("position"),
|
flagsToStr(n.options), rope("position"),
|
||||||
rope(n.position)])
|
rope(n.position)])
|
||||||
|
|
||||||
proc typeToYamlAux(n: PType, marker: var IntSet, indent: int,
|
proc typeToYamlAux(conf: ConfigRef; n: PType, marker: var IntSet, indent: int,
|
||||||
maxRecDepth: int): Rope =
|
maxRecDepth: int): Rope =
|
||||||
if n == nil:
|
if n == nil:
|
||||||
result = rope("null")
|
result = rope("null")
|
||||||
|
|
@ -306,15 +306,15 @@ proc typeToYamlAux(n: PType, marker: var IntSet, indent: int,
|
||||||
result = rope("[")
|
result = rope("[")
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
if i > 0: add(result, ",")
|
if i > 0: add(result, ",")
|
||||||
addf(result, "$N$1$2", [rspaces(indent + 4), typeToYamlAux(n.sons[i],
|
addf(result, "$N$1$2", [rspaces(indent + 4), typeToYamlAux(conf, n.sons[i],
|
||||||
marker, indent + 4, maxRecDepth - 1)])
|
marker, indent + 4, maxRecDepth - 1)])
|
||||||
addf(result, "$N$1]", [rspaces(indent + 2)])
|
addf(result, "$N$1]", [rspaces(indent + 2)])
|
||||||
else:
|
else:
|
||||||
result = rope("null")
|
result = rope("null")
|
||||||
result = ropeConstr(indent, [rope("kind"),
|
result = ropeConstr(indent, [rope("kind"),
|
||||||
makeYamlString($n.kind),
|
makeYamlString($n.kind),
|
||||||
rope("sym"), symToYamlAux(n.sym, marker,
|
rope("sym"), symToYamlAux(conf, n.sym, marker,
|
||||||
indent + 2, maxRecDepth - 1), rope("n"), treeToYamlAux(n.n, marker,
|
indent + 2, maxRecDepth - 1), rope("n"), treeToYamlAux(conf, n.n, marker,
|
||||||
indent + 2, maxRecDepth - 1), rope("flags"), flagsToStr(n.flags),
|
indent + 2, maxRecDepth - 1), rope("flags"), flagsToStr(n.flags),
|
||||||
rope("callconv"),
|
rope("callconv"),
|
||||||
makeYamlString(CallingConvToStr[n.callConv]),
|
makeYamlString(CallingConvToStr[n.callConv]),
|
||||||
|
|
@ -322,7 +322,7 @@ proc typeToYamlAux(n: PType, marker: var IntSet, indent: int,
|
||||||
rope("align"), rope(n.align),
|
rope("align"), rope(n.align),
|
||||||
rope("sons"), result])
|
rope("sons"), result])
|
||||||
|
|
||||||
proc treeToYamlAux(n: PNode, marker: var IntSet, indent: int,
|
proc treeToYamlAux(conf: ConfigRef; n: PNode, marker: var IntSet, indent: int,
|
||||||
maxRecDepth: int): Rope =
|
maxRecDepth: int): Rope =
|
||||||
if n == nil:
|
if n == nil:
|
||||||
result = rope("null")
|
result = rope("null")
|
||||||
|
|
@ -330,7 +330,7 @@ proc treeToYamlAux(n: PNode, marker: var IntSet, indent: int,
|
||||||
var istr = rspaces(indent + 2)
|
var istr = rspaces(indent + 2)
|
||||||
result = "{$N$1\"kind\": $2" % [istr, makeYamlString($n.kind)]
|
result = "{$N$1\"kind\": $2" % [istr, makeYamlString($n.kind)]
|
||||||
if maxRecDepth != 0:
|
if maxRecDepth != 0:
|
||||||
addf(result, ",$N$1\"info\": $2", [istr, lineInfoToStr(n.info)])
|
addf(result, ",$N$1\"info\": $2", [istr, lineInfoToStr(conf, n.info)])
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkCharLit..nkInt64Lit:
|
of nkCharLit..nkInt64Lit:
|
||||||
addf(result, ",$N$1\"intVal\": $2", [istr, rope(n.intVal)])
|
addf(result, ",$N$1\"intVal\": $2", [istr, rope(n.intVal)])
|
||||||
|
|
@ -344,7 +344,7 @@ proc treeToYamlAux(n: PNode, marker: var IntSet, indent: int,
|
||||||
addf(result, ",$N$1\"strVal\": $2", [istr, makeYamlString(n.strVal)])
|
addf(result, ",$N$1\"strVal\": $2", [istr, makeYamlString(n.strVal)])
|
||||||
of nkSym:
|
of nkSym:
|
||||||
addf(result, ",$N$1\"sym\": $2",
|
addf(result, ",$N$1\"sym\": $2",
|
||||||
[istr, symToYamlAux(n.sym, marker, indent + 2, maxRecDepth)])
|
[istr, symToYamlAux(conf, n.sym, marker, indent + 2, maxRecDepth)])
|
||||||
of nkIdent:
|
of nkIdent:
|
||||||
if n.ident != nil:
|
if n.ident != nil:
|
||||||
addf(result, ",$N$1\"ident\": $2", [istr, makeYamlString(n.ident.s)])
|
addf(result, ",$N$1\"ident\": $2", [istr, makeYamlString(n.ident.s)])
|
||||||
|
|
@ -355,27 +355,27 @@ proc treeToYamlAux(n: PNode, marker: var IntSet, indent: int,
|
||||||
addf(result, ",$N$1\"sons\": [", [istr])
|
addf(result, ",$N$1\"sons\": [", [istr])
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
if i > 0: add(result, ",")
|
if i > 0: add(result, ",")
|
||||||
addf(result, "$N$1$2", [rspaces(indent + 4), treeToYamlAux(n.sons[i],
|
addf(result, "$N$1$2", [rspaces(indent + 4), treeToYamlAux(conf, n.sons[i],
|
||||||
marker, indent + 4, maxRecDepth - 1)])
|
marker, indent + 4, maxRecDepth - 1)])
|
||||||
addf(result, "$N$1]", [istr])
|
addf(result, "$N$1]", [istr])
|
||||||
addf(result, ",$N$1\"typ\": $2",
|
addf(result, ",$N$1\"typ\": $2",
|
||||||
[istr, typeToYamlAux(n.typ, marker, indent + 2, maxRecDepth)])
|
[istr, typeToYamlAux(conf, n.typ, marker, indent + 2, maxRecDepth)])
|
||||||
addf(result, "$N$1}", [rspaces(indent)])
|
addf(result, "$N$1}", [rspaces(indent)])
|
||||||
|
|
||||||
proc treeToYaml(n: PNode, indent: int = 0, maxRecDepth: int = - 1): Rope =
|
proc treeToYaml(conf: ConfigRef; n: PNode, indent: int = 0, maxRecDepth: int = - 1): Rope =
|
||||||
var marker = initIntSet()
|
var marker = initIntSet()
|
||||||
result = treeToYamlAux(n, marker, indent, maxRecDepth)
|
result = treeToYamlAux(conf, n, marker, indent, maxRecDepth)
|
||||||
|
|
||||||
proc typeToYaml(n: PType, indent: int = 0, maxRecDepth: int = - 1): Rope =
|
proc typeToYaml(conf: ConfigRef; n: PType, indent: int = 0, maxRecDepth: int = - 1): Rope =
|
||||||
var marker = initIntSet()
|
var marker = initIntSet()
|
||||||
result = typeToYamlAux(n, marker, indent, maxRecDepth)
|
result = typeToYamlAux(conf, n, marker, indent, maxRecDepth)
|
||||||
|
|
||||||
proc symToYaml(n: PSym, indent: int = 0, maxRecDepth: int = - 1): Rope =
|
proc symToYaml(conf: ConfigRef; n: PSym, indent: int = 0, maxRecDepth: int = - 1): Rope =
|
||||||
var marker = initIntSet()
|
var marker = initIntSet()
|
||||||
result = symToYamlAux(n, marker, indent, maxRecDepth)
|
result = symToYamlAux(conf, n, marker, indent, maxRecDepth)
|
||||||
|
|
||||||
proc debugTree*(n: PNode, indent: int, maxRecDepth: int; renderType=false): Rope
|
proc debugTree*(conf: ConfigRef; n: PNode, indent: int, maxRecDepth: int; renderType=false): Rope
|
||||||
proc debugType(n: PType, maxRecDepth=100): Rope =
|
proc debugType(conf: ConfigRef; n: PType, maxRecDepth=100): Rope =
|
||||||
if n == nil:
|
if n == nil:
|
||||||
result = rope("null")
|
result = rope("null")
|
||||||
else:
|
else:
|
||||||
|
|
@ -385,7 +385,7 @@ proc debugType(n: PType, maxRecDepth=100): Rope =
|
||||||
add(result, n.sym.name.s)
|
add(result, n.sym.name.s)
|
||||||
if n.kind in IntegralTypes and n.n != nil:
|
if n.kind in IntegralTypes and n.n != nil:
|
||||||
add(result, ", node: ")
|
add(result, ", node: ")
|
||||||
add(result, debugTree(n.n, 2, maxRecDepth-1, renderType=true))
|
add(result, debugTree(conf, n.n, 2, maxRecDepth-1, renderType=true))
|
||||||
if (n.kind != tyString) and (sonsLen(n) > 0) and maxRecDepth != 0:
|
if (n.kind != tyString) and (sonsLen(n) > 0) and maxRecDepth != 0:
|
||||||
add(result, "(")
|
add(result, "(")
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
|
|
@ -393,13 +393,13 @@ proc debugType(n: PType, maxRecDepth=100): Rope =
|
||||||
if n.sons[i] == nil:
|
if n.sons[i] == nil:
|
||||||
add(result, "null")
|
add(result, "null")
|
||||||
else:
|
else:
|
||||||
add(result, debugType(n.sons[i], maxRecDepth-1))
|
add(result, debugType(conf, n.sons[i], maxRecDepth-1))
|
||||||
if n.kind == tyObject and n.n != nil:
|
if n.kind == tyObject and n.n != nil:
|
||||||
add(result, ", node: ")
|
add(result, ", node: ")
|
||||||
add(result, debugTree(n.n, 2, maxRecDepth-1, renderType=true))
|
add(result, debugTree(conf, n.n, 2, maxRecDepth-1, renderType=true))
|
||||||
add(result, ")")
|
add(result, ")")
|
||||||
|
|
||||||
proc debugTree(n: PNode, indent: int, maxRecDepth: int;
|
proc debugTree(conf: ConfigRef; n: PNode, indent: int, maxRecDepth: int;
|
||||||
renderType=false): Rope =
|
renderType=false): Rope =
|
||||||
if n == nil:
|
if n == nil:
|
||||||
result = rope("null")
|
result = rope("null")
|
||||||
|
|
@ -409,7 +409,7 @@ proc debugTree(n: PNode, indent: int, maxRecDepth: int;
|
||||||
[istr, makeYamlString($n.kind)]
|
[istr, makeYamlString($n.kind)]
|
||||||
when defined(useNodeIds):
|
when defined(useNodeIds):
|
||||||
addf(result, ",$N$1\"id\": $2", [istr, rope(n.id)])
|
addf(result, ",$N$1\"id\": $2", [istr, rope(n.id)])
|
||||||
addf(result, ",$N$1\"info\": $2", [istr, lineInfoToStr(n.info)])
|
addf(result, ",$N$1\"info\": $2", [istr, lineInfoToStr(conf, n.info)])
|
||||||
if maxRecDepth != 0:
|
if maxRecDepth != 0:
|
||||||
addf(result, ",$N$1\"flags\": $2", [istr, rope($n.flags)])
|
addf(result, ",$N$1\"flags\": $2", [istr, rope($n.flags)])
|
||||||
case n.kind
|
case n.kind
|
||||||
|
|
@ -429,7 +429,7 @@ proc debugTree(n: PNode, indent: int, maxRecDepth: int;
|
||||||
# [istr, symToYaml(n.sym, indent, maxRecDepth),
|
# [istr, symToYaml(n.sym, indent, maxRecDepth),
|
||||||
# rope(n.sym.id)])
|
# rope(n.sym.id)])
|
||||||
if renderType and n.sym.typ != nil:
|
if renderType and n.sym.typ != nil:
|
||||||
addf(result, ",$N$1\"typ\": $2", [istr, debugType(n.sym.typ, 2)])
|
addf(result, ",$N$1\"typ\": $2", [istr, debugType(conf, n.sym.typ, 2)])
|
||||||
of nkIdent:
|
of nkIdent:
|
||||||
if n.ident != nil:
|
if n.ident != nil:
|
||||||
addf(result, ",$N$1\"ident\": $2", [istr, makeYamlString(n.ident.s)])
|
addf(result, ",$N$1\"ident\": $2", [istr, makeYamlString(n.ident.s)])
|
||||||
|
|
@ -440,12 +440,12 @@ proc debugTree(n: PNode, indent: int, maxRecDepth: int;
|
||||||
addf(result, ",$N$1\"sons\": [", [istr])
|
addf(result, ",$N$1\"sons\": [", [istr])
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
if i > 0: add(result, ",")
|
if i > 0: add(result, ",")
|
||||||
addf(result, "$N$1$2", [rspaces(indent + 4), debugTree(n.sons[i],
|
addf(result, "$N$1$2", [rspaces(indent + 4), debugTree(conf, n.sons[i],
|
||||||
indent + 4, maxRecDepth - 1, renderType)])
|
indent + 4, maxRecDepth - 1, renderType)])
|
||||||
addf(result, "$N$1]", [istr])
|
addf(result, "$N$1]", [istr])
|
||||||
addf(result, "$N$1}", [rspaces(indent)])
|
addf(result, "$N$1}", [rspaces(indent)])
|
||||||
|
|
||||||
proc debug(n: PSym) =
|
proc debug(conf: ConfigRef; n: PSym) =
|
||||||
if n == nil:
|
if n == nil:
|
||||||
echo("null")
|
echo("null")
|
||||||
elif n.kind == skUnknown:
|
elif n.kind == skUnknown:
|
||||||
|
|
@ -454,13 +454,13 @@ proc debug(n: PSym) =
|
||||||
#writeLine(stdout, $symToYaml(n, 0, 1))
|
#writeLine(stdout, $symToYaml(n, 0, 1))
|
||||||
echo("$1_$2: $3, $4, $5, $6" % [
|
echo("$1_$2: $3, $4, $5, $6" % [
|
||||||
n.name.s, $n.id, $flagsToStr(n.flags), $flagsToStr(n.loc.flags),
|
n.name.s, $n.id, $flagsToStr(n.flags), $flagsToStr(n.loc.flags),
|
||||||
$lineInfoToStr(n.info), $n.kind])
|
$lineInfoToStr(conf, n.info), $n.kind])
|
||||||
|
|
||||||
proc debug(n: PType) =
|
proc debug(conf: ConfigRef; n: PType) =
|
||||||
echo($debugType(n))
|
echo($debugType(conf, n))
|
||||||
|
|
||||||
proc debug(n: PNode) =
|
proc debug(conf: ConfigRef; n: PNode) =
|
||||||
echo($debugTree(n, 0, 100))
|
echo($debugTree(conf, n, 0, 100))
|
||||||
|
|
||||||
proc nextTry(h, maxHash: Hash): Hash =
|
proc nextTry(h, maxHash: Hash): Hash =
|
||||||
result = ((5 * h) + 1) and maxHash
|
result = ((5 * h) + 1) and maxHash
|
||||||
|
|
|
||||||
|
|
@ -370,7 +370,7 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||||
#echo p.currLineInfo, " requesting"
|
#echo p.currLineInfo, " requesting"
|
||||||
linefmt(p, cpsStmts, "#memTrackerWrite((void*)$1, $2, $3, $4);$n",
|
linefmt(p, cpsStmts, "#memTrackerWrite((void*)$1, $2, $3, $4);$n",
|
||||||
addrLoc(dest), rope getSize(dest.t),
|
addrLoc(dest), rope getSize(dest.t),
|
||||||
makeCString(p.currLineInfo.toFullPath),
|
makeCString(toFullPath(p.config, p.currLineInfo)),
|
||||||
rope p.currLineInfo.safeLineNm)
|
rope p.currLineInfo.safeLineNm)
|
||||||
|
|
||||||
proc genDeepCopy(p: BProc; dest, src: TLoc) =
|
proc genDeepCopy(p: BProc; dest, src: TLoc) =
|
||||||
|
|
|
||||||
|
|
@ -1028,7 +1028,7 @@ proc genBreakPoint(p: BProc, t: PNode) =
|
||||||
genLineDir(p, t) # BUGFIX
|
genLineDir(p, t) # BUGFIX
|
||||||
appcg(p.module, p.module.g.breakpoints,
|
appcg(p.module, p.module.g.breakpoints,
|
||||||
"#dbgRegisterBreakpoint($1, (NCSTRING)$2, (NCSTRING)$3);$n", [
|
"#dbgRegisterBreakpoint($1, (NCSTRING)$2, (NCSTRING)$3);$n", [
|
||||||
rope(toLinenumber(t.info)), makeCString(toFilename(t.info)),
|
rope(toLinenumber(t.info)), makeCString(toFilename(p.config, t.info)),
|
||||||
makeCString(name)])
|
makeCString(name)])
|
||||||
|
|
||||||
proc genWatchpoint(p: BProc, n: PNode) =
|
proc genWatchpoint(p: BProc, n: PNode) =
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ proc mangleName(m: BModule; s: PSym): Rope =
|
||||||
result = s.name.s.mangle.rope
|
result = s.name.s.mangle.rope
|
||||||
add(result, idOrSig(s, m.module.name.s, m.sigConflicts))
|
add(result, idOrSig(s, m.module.name.s, m.sigConflicts))
|
||||||
s.loc.r = result
|
s.loc.r = result
|
||||||
writeMangledName(m.ndi, s)
|
writeMangledName(m.ndi, s, m.config)
|
||||||
|
|
||||||
proc mangleParamName(m: BModule; s: PSym): Rope =
|
proc mangleParamName(m: BModule; s: PSym): Rope =
|
||||||
## we cannot use 'sigConflicts' here since we have a BModule, not a BProc.
|
## we cannot use 'sigConflicts' here since we have a BModule, not a BProc.
|
||||||
|
|
@ -63,7 +63,7 @@ proc mangleParamName(m: BModule; s: PSym): Rope =
|
||||||
res.add "_0"
|
res.add "_0"
|
||||||
result = res.rope
|
result = res.rope
|
||||||
s.loc.r = result
|
s.loc.r = result
|
||||||
writeMangledName(m.ndi, s)
|
writeMangledName(m.ndi, s, m.config)
|
||||||
|
|
||||||
proc mangleLocalName(p: BProc; s: PSym): Rope =
|
proc mangleLocalName(p: BProc; s: PSym): Rope =
|
||||||
assert s.kind in skLocalVars+{skTemp}
|
assert s.kind in skLocalVars+{skTemp}
|
||||||
|
|
@ -81,7 +81,7 @@ proc mangleLocalName(p: BProc; s: PSym): Rope =
|
||||||
result.add "_" & rope(counter+1)
|
result.add "_" & rope(counter+1)
|
||||||
p.sigConflicts.inc(key)
|
p.sigConflicts.inc(key)
|
||||||
s.loc.r = result
|
s.loc.r = result
|
||||||
if s.kind != skTemp: writeMangledName(p.module.ndi, s)
|
if s.kind != skTemp: writeMangledName(p.module.ndi, s, p.config)
|
||||||
|
|
||||||
proc scopeMangledParam(p: BProc; param: PSym) =
|
proc scopeMangledParam(p: BProc; param: PSym) =
|
||||||
## parameter generation only takes BModule, not a BProc, so we have to
|
## parameter generation only takes BModule, not a BProc, so we have to
|
||||||
|
|
|
||||||
|
|
@ -193,7 +193,7 @@ proc genCLineDir(r: var Rope, filename: string, line: int; conf: ConfigRef) =
|
||||||
[rope(makeSingleLineCString(filename)), rope(line)])
|
[rope(makeSingleLineCString(filename)), rope(line)])
|
||||||
|
|
||||||
proc genCLineDir(r: var Rope, info: TLineInfo; conf: ConfigRef) =
|
proc genCLineDir(r: var Rope, info: TLineInfo; conf: ConfigRef) =
|
||||||
genCLineDir(r, info.toFullPath, info.safeLineNm, conf)
|
genCLineDir(r, toFullPath(conf, info), info.safeLineNm, conf)
|
||||||
|
|
||||||
proc freshLineInfo(p: BProc; info: TLineInfo): bool =
|
proc freshLineInfo(p: BProc; info: TLineInfo): bool =
|
||||||
if p.lastLineInfo.line != info.line or
|
if p.lastLineInfo.line != info.line or
|
||||||
|
|
@ -212,12 +212,12 @@ proc genLineDir(p: BProc, t: PNode) =
|
||||||
|
|
||||||
if optEmbedOrigSrc in p.config.globalOptions:
|
if optEmbedOrigSrc in p.config.globalOptions:
|
||||||
add(p.s(cpsStmts), ~"//" & sourceLine(p.config, tt.info) & rnl)
|
add(p.s(cpsStmts), ~"//" & sourceLine(p.config, tt.info) & rnl)
|
||||||
genCLineDir(p.s(cpsStmts), tt.info.toFullPath, line, p.config)
|
genCLineDir(p.s(cpsStmts), toFullPath(p.config, tt.info), line, p.config)
|
||||||
if ({optStackTrace, optEndb} * p.options == {optStackTrace, optEndb}) and
|
if ({optStackTrace, optEndb} * p.options == {optStackTrace, optEndb}) and
|
||||||
(p.prc == nil or sfPure notin p.prc.flags):
|
(p.prc == nil or sfPure notin p.prc.flags):
|
||||||
if freshLineInfo(p, tt.info):
|
if freshLineInfo(p, tt.info):
|
||||||
linefmt(p, cpsStmts, "#endb($1, $2);$N",
|
linefmt(p, cpsStmts, "#endb($1, $2);$N",
|
||||||
line.rope, makeCString(toFilename(tt.info)))
|
line.rope, makeCString(toFilename(p.config, tt.info)))
|
||||||
elif ({optLineTrace, optStackTrace} * p.options ==
|
elif ({optLineTrace, optStackTrace} * p.options ==
|
||||||
{optLineTrace, optStackTrace}) and
|
{optLineTrace, optStackTrace}) and
|
||||||
(p.prc == nil or sfPure notin p.prc.flags) and tt.info.fileIndex != InvalidFileIDX:
|
(p.prc == nil or sfPure notin p.prc.flags) and tt.info.fileIndex != InvalidFileIDX:
|
||||||
|
|
@ -1249,7 +1249,7 @@ proc rawNewModule(g: BModuleList; module: PSym, filename: string): BModule =
|
||||||
excl(result.postInitProc.options, optStackTrace)
|
excl(result.postInitProc.options, optStackTrace)
|
||||||
let ndiName = if optCDebug in g.config.globalOptions: changeFileExt(completeCFilePath(g.config, filename), "ndi")
|
let ndiName = if optCDebug in g.config.globalOptions: changeFileExt(completeCFilePath(g.config, filename), "ndi")
|
||||||
else: ""
|
else: ""
|
||||||
open(result.ndi, ndiName)
|
open(result.ndi, ndiName, g.config)
|
||||||
|
|
||||||
proc nullify[T](arr: var T) =
|
proc nullify[T](arr: var T) =
|
||||||
for i in low(arr)..high(arr):
|
for i in low(arr)..high(arr):
|
||||||
|
|
@ -1299,12 +1299,12 @@ proc resetModule*(m: BModule) =
|
||||||
proc resetCgenModules*(g: BModuleList) =
|
proc resetCgenModules*(g: BModuleList) =
|
||||||
for m in cgenModules(g): resetModule(m)
|
for m in cgenModules(g): resetModule(m)
|
||||||
|
|
||||||
proc rawNewModule(g: BModuleList; module: PSym): BModule =
|
proc rawNewModule(g: BModuleList; module: PSym; conf: ConfigRef): BModule =
|
||||||
result = rawNewModule(g, module, module.position.FileIndex.toFullPath)
|
result = rawNewModule(g, module, toFullPath(conf, module.position.FileIndex))
|
||||||
|
|
||||||
proc newModule(g: BModuleList; module: PSym): BModule =
|
proc newModule(g: BModuleList; module: PSym; conf: ConfigRef): BModule =
|
||||||
# we should create only one cgen module for each module sym
|
# we should create only one cgen module for each module sym
|
||||||
result = rawNewModule(g, module)
|
result = rawNewModule(g, module, conf)
|
||||||
growCache g.modules, module.position
|
growCache g.modules, module.position
|
||||||
g.modules[module.position] = result
|
g.modules[module.position] = result
|
||||||
|
|
||||||
|
|
@ -1315,7 +1315,7 @@ template injectG() {.dirty.} =
|
||||||
|
|
||||||
proc myOpen(graph: ModuleGraph; module: PSym; cache: IdentCache): PPassContext =
|
proc myOpen(graph: ModuleGraph; module: PSym; cache: IdentCache): PPassContext =
|
||||||
injectG()
|
injectG()
|
||||||
result = newModule(g, module)
|
result = newModule(g, module, graph.config)
|
||||||
if optGenIndex in graph.config.globalOptions and g.generatedHeader == nil:
|
if optGenIndex in graph.config.globalOptions and g.generatedHeader == nil:
|
||||||
let f = if graph.config.headerFile.len > 0: graph.config.headerFile
|
let f = if graph.config.headerFile.len > 0: graph.config.headerFile
|
||||||
else: graph.config.projectFull
|
else: graph.config.projectFull
|
||||||
|
|
@ -1358,7 +1358,7 @@ proc getCFile(m: BModule): string =
|
||||||
|
|
||||||
proc myOpenCached(graph: ModuleGraph; module: PSym, rd: PRodReader): PPassContext =
|
proc myOpenCached(graph: ModuleGraph; module: PSym, rd: PRodReader): PPassContext =
|
||||||
injectG()
|
injectG()
|
||||||
var m = newModule(g, module)
|
var m = newModule(g, module, graph.config)
|
||||||
readMergeInfo(getCFile(m), m)
|
readMergeInfo(getCFile(m), m)
|
||||||
result = m
|
result = m
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -289,14 +289,14 @@ proc processPath(conf: ConfigRef; path: string, info: TLineInfo,
|
||||||
else:
|
else:
|
||||||
conf.projectPath / path
|
conf.projectPath / path
|
||||||
try:
|
try:
|
||||||
result = pathSubs(conf, p, info.toFullPath().splitFile().dir)
|
result = pathSubs(conf, p, toFullPath(conf, info).splitFile().dir)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
localError(conf, info, "invalid path: " & p)
|
localError(conf, info, "invalid path: " & p)
|
||||||
result = p
|
result = p
|
||||||
|
|
||||||
proc processCfgPath(conf: ConfigRef; path: string, info: TLineInfo): string =
|
proc processCfgPath(conf: ConfigRef; path: string, info: TLineInfo): string =
|
||||||
let path = if path[0] == '"': strutils.unescape(path) else: path
|
let path = if path[0] == '"': strutils.unescape(path) else: path
|
||||||
let basedir = info.toFullPath().splitFile().dir
|
let basedir = toFullPath(conf, info).splitFile().dir
|
||||||
let p = if os.isAbsolute(path) or '$' in path:
|
let p = if os.isAbsolute(path) or '$' in path:
|
||||||
path
|
path
|
||||||
else:
|
else:
|
||||||
|
|
@ -322,7 +322,7 @@ proc trackDirty(conf: ConfigRef; arg: string, info: TLineInfo) =
|
||||||
|
|
||||||
let dirtyOriginalIdx = fileInfoIdx(conf, a[1])
|
let dirtyOriginalIdx = fileInfoIdx(conf, a[1])
|
||||||
if dirtyOriginalIdx.int32 >= 0:
|
if dirtyOriginalIdx.int32 >= 0:
|
||||||
msgs.setDirtyFile(dirtyOriginalIdx, a[0])
|
msgs.setDirtyFile(conf, dirtyOriginalIdx, a[0])
|
||||||
|
|
||||||
gTrackPos = newLineInfo(dirtyOriginalIdx, line, column)
|
gTrackPos = newLineInfo(dirtyOriginalIdx, line, column)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ type
|
||||||
blocks: seq[TBlock]
|
blocks: seq[TBlock]
|
||||||
|
|
||||||
proc debugInfo(info: TLineInfo): string =
|
proc debugInfo(info: TLineInfo): string =
|
||||||
result = info.toFilename & ":" & $info.line
|
result = $info.line #info.toFilename & ":" & $info.line
|
||||||
|
|
||||||
proc codeListing(c: ControlFlowGraph, result: var string, start=0; last = -1) =
|
proc codeListing(c: ControlFlowGraph, result: var string, start=0; last = -1) =
|
||||||
# for debugging purposes
|
# for debugging purposes
|
||||||
|
|
|
||||||
|
|
@ -190,7 +190,7 @@ proc genComment(d: PDoc, n: PNode): string =
|
||||||
result = ""
|
result = ""
|
||||||
var dummyHasToc: bool
|
var dummyHasToc: bool
|
||||||
if n.comment != nil:
|
if n.comment != nil:
|
||||||
renderRstToOut(d[], parseRst(n.comment, toFilename(n.info),
|
renderRstToOut(d[], parseRst(n.comment, toFilename(d.conf, n.info),
|
||||||
toLinenumber(n.info), toColumn(n.info),
|
toLinenumber(n.info), toColumn(n.info),
|
||||||
dummyHasToc, d.options, d.conf), result)
|
dummyHasToc, d.options, d.conf), result)
|
||||||
|
|
||||||
|
|
@ -307,13 +307,13 @@ when false:
|
||||||
result = findDocComment(n.sons[i])
|
result = findDocComment(n.sons[i])
|
||||||
if result != nil: return
|
if result != nil: return
|
||||||
|
|
||||||
proc extractDocComment*(s: PSym, d: PDoc = nil): string =
|
proc extractDocComment*(s: PSym, d: PDoc): string =
|
||||||
let n = findDocComment(s.ast)
|
let n = findDocComment(s.ast)
|
||||||
result = ""
|
result = ""
|
||||||
if not n.isNil:
|
if not n.isNil:
|
||||||
if not d.isNil:
|
if not d.isNil:
|
||||||
var dummyHasToc: bool
|
var dummyHasToc: bool
|
||||||
renderRstToOut(d[], parseRst(n.comment, toFilename(n.info),
|
renderRstToOut(d[], parseRst(n.comment, toFilename(d.conf, n.info),
|
||||||
toLinenumber(n.info), toColumn(n.info),
|
toLinenumber(n.info), toColumn(n.info),
|
||||||
dummyHasToc, d.options + {roSkipPounds}),
|
dummyHasToc, d.options + {roSkipPounds}),
|
||||||
result)
|
result)
|
||||||
|
|
@ -502,7 +502,7 @@ proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind) =
|
||||||
let docItemSeeSrc = getConfigVar(d.conf, "doc.item.seesrc")
|
let docItemSeeSrc = getConfigVar(d.conf, "doc.item.seesrc")
|
||||||
if docItemSeeSrc.len > 0:
|
if docItemSeeSrc.len > 0:
|
||||||
let cwd = canonicalizePath(d.conf, getCurrentDir())
|
let cwd = canonicalizePath(d.conf, getCurrentDir())
|
||||||
var path = n.info.toFullPath
|
var path = toFullPath(d.conf, n.info)
|
||||||
if path.startsWith(cwd):
|
if path.startsWith(cwd):
|
||||||
path = path[cwd.len+1 .. ^1].replace('\\', '/')
|
path = path[cwd.len+1 .. ^1].replace('\\', '/')
|
||||||
let gitUrl = getConfigVar(d.conf, "git.url")
|
let gitUrl = getConfigVar(d.conf, "git.url")
|
||||||
|
|
|
||||||
|
|
@ -35,11 +35,11 @@ template closeImpl(body: untyped) {.dirty.} =
|
||||||
|
|
||||||
proc close(graph: ModuleGraph; p: PPassContext, n: PNode): PNode =
|
proc close(graph: ModuleGraph; p: PPassContext, n: PNode): PNode =
|
||||||
closeImpl:
|
closeImpl:
|
||||||
writeOutput(g.doc, g.module.filename, HtmlExt, useWarning)
|
writeOutput(g.doc, toFilename(graph.config, FileIndex g.module.position), HtmlExt, useWarning)
|
||||||
|
|
||||||
proc closeJson(graph: ModuleGraph; p: PPassContext, n: PNode): PNode =
|
proc closeJson(graph: ModuleGraph; p: PPassContext, n: PNode): PNode =
|
||||||
closeImpl:
|
closeImpl:
|
||||||
writeOutputJson(g.doc, g.module.filename, ".json", useWarning)
|
writeOutputJson(g.doc, toFilename(graph.config, FileIndex g.module.position), ".json", useWarning)
|
||||||
|
|
||||||
proc processNode(c: PPassContext, n: PNode): PNode =
|
proc processNode(c: PPassContext, n: PNode): PNode =
|
||||||
result = n
|
result = n
|
||||||
|
|
@ -55,7 +55,7 @@ proc myOpen(graph: ModuleGraph; module: PSym; cache: IdentCache): PPassContext =
|
||||||
var g: PGen
|
var g: PGen
|
||||||
new(g)
|
new(g)
|
||||||
g.module = module
|
g.module = module
|
||||||
var d = newDocumentor(module.filename, graph.config)
|
var d = newDocumentor(toFilename(graph.config, FileIndex module.position), graph.config)
|
||||||
d.hasToc = true
|
d.hasToc = true
|
||||||
g.doc = d
|
g.doc = d
|
||||||
result = g
|
result = g
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ proc readOutput(p: Process): (string, int) =
|
||||||
result[1] = p.waitForExit
|
result[1] = p.waitForExit
|
||||||
|
|
||||||
proc opGorge*(cmd, input, cache: string, info: TLineInfo; conf: ConfigRef): (string, int) =
|
proc opGorge*(cmd, input, cache: string, info: TLineInfo; conf: ConfigRef): (string, int) =
|
||||||
let workingDir = parentDir(info.toFullPath)
|
let workingDir = parentDir(toFullPath(conf, info))
|
||||||
if cache.len > 0:# and optForceFullMake notin gGlobalOptions:
|
if cache.len > 0:# and optForceFullMake notin gGlobalOptions:
|
||||||
let h = secureHash(cmd & "\t" & input & "\t" & cache)
|
let h = secureHash(cmd & "\t" & input & "\t" & cache)
|
||||||
let filename = options.toGeneratedFile(conf, "gorge_" & $h, "txt")
|
let filename = options.toGeneratedFile(conf, "gorge_" & $h, "txt")
|
||||||
|
|
|
||||||
|
|
@ -143,8 +143,8 @@ proc myImportModule(c: PContext, n: PNode): PSym =
|
||||||
var err = ""
|
var err = ""
|
||||||
for i in countup(recursion, L-1):
|
for i in countup(recursion, L-1):
|
||||||
if i > recursion: err.add "\n"
|
if i > recursion: err.add "\n"
|
||||||
err.add toFullPath(c.graph.importStack[i]) & " imports " &
|
err.add toFullPath(c.config, c.graph.importStack[i]) & " imports " &
|
||||||
toFullPath(c.graph.importStack[i+1])
|
toFullPath(c.config, c.graph.importStack[i+1])
|
||||||
c.recursiveDep = err
|
c.recursiveDep = err
|
||||||
result = importModuleAs(c, n, gImportModule(c.graph, c.module, f, c.cache))
|
result = importModuleAs(c, n, gImportModule(c.graph, c.module, f, c.cache))
|
||||||
#echo "set back to ", L
|
#echo "set back to ", L
|
||||||
|
|
|
||||||
|
|
@ -537,7 +537,7 @@ proc genLineDir(p: PProc, n: PNode) =
|
||||||
let line = toLinenumber(n.info)
|
let line = toLinenumber(n.info)
|
||||||
if optLineDir in p.options:
|
if optLineDir in p.options:
|
||||||
lineF(p, "// line $2 \"$1\"$n",
|
lineF(p, "// line $2 \"$1\"$n",
|
||||||
[rope(toFilename(n.info)), rope(line)])
|
[rope(toFilename(p.config, n.info)), rope(line)])
|
||||||
if {optStackTrace, optEndb} * p.options == {optStackTrace, optEndb} and
|
if {optStackTrace, optEndb} * p.options == {optStackTrace, optEndb} and
|
||||||
((p.prc == nil) or sfPure notin p.prc.flags):
|
((p.prc == nil) or sfPure notin p.prc.flags):
|
||||||
useMagic(p, "endb")
|
useMagic(p, "endb")
|
||||||
|
|
@ -1907,7 +1907,7 @@ proc genProcBody(p: PProc, prc: PSym): Rope =
|
||||||
if hasFrameInfo(p):
|
if hasFrameInfo(p):
|
||||||
result = frameCreate(p,
|
result = frameCreate(p,
|
||||||
makeJSString(prc.owner.name.s & '.' & prc.name.s),
|
makeJSString(prc.owner.name.s & '.' & prc.name.s),
|
||||||
makeJSString(toFilename(prc.info)))
|
makeJSString(toFilename(p.config, prc.info)))
|
||||||
else:
|
else:
|
||||||
result = nil
|
result = nil
|
||||||
if p.beforeRetNeeded:
|
if p.beforeRetNeeded:
|
||||||
|
|
@ -2200,7 +2200,7 @@ proc genModule(p: PProc, n: PNode) =
|
||||||
if optStackTrace in p.options:
|
if optStackTrace in p.options:
|
||||||
add(p.body, frameCreate(p,
|
add(p.body, frameCreate(p,
|
||||||
makeJSString("module " & p.module.module.name.s),
|
makeJSString("module " & p.module.module.name.s),
|
||||||
makeJSString(toFilename(p.module.module.info))))
|
makeJSString(toFilename(p.config, p.module.module.info))))
|
||||||
genStmt(p, n)
|
genStmt(p, n)
|
||||||
if optStackTrace in p.options:
|
if optStackTrace in p.options:
|
||||||
add(p.body, frameDestroy(p))
|
add(p.body, frameDestroy(p))
|
||||||
|
|
@ -2262,7 +2262,7 @@ proc myClose(graph: ModuleGraph; b: PPassContext, n: PNode): PNode =
|
||||||
if passes.skipCodegen(m.config, n): return n
|
if passes.skipCodegen(m.config, n): return n
|
||||||
if sfMainModule in m.module.flags:
|
if sfMainModule in m.module.flags:
|
||||||
let ext = "js"
|
let ext = "js"
|
||||||
let f = if globals.classes.len == 0: toFilename(FileIndex m.module.position)
|
let f = if globals.classes.len == 0: toFilename(m.config, FileIndex m.module.position)
|
||||||
else: "nimsystem"
|
else: "nimsystem"
|
||||||
let code = wholeCode(graph, m)
|
let code = wholeCode(graph, m)
|
||||||
let outfile =
|
let outfile =
|
||||||
|
|
|
||||||
|
|
@ -717,7 +717,7 @@ proc handleCRLF(L: var TLexer, pos: int): int =
|
||||||
if optEmbedOrigSrc in L.config.globalOptions:
|
if optEmbedOrigSrc in L.config.globalOptions:
|
||||||
let lineStart = cast[ByteAddress](L.buf) + L.lineStart
|
let lineStart = cast[ByteAddress](L.buf) + L.lineStart
|
||||||
let line = newString(cast[cstring](lineStart), col)
|
let line = newString(cast[cstring](lineStart), col)
|
||||||
addSourceLine(L.fileIdx, line)
|
addSourceLine(L.config, L.fileIdx, line)
|
||||||
|
|
||||||
case L.buf[pos]
|
case L.buf[pos]
|
||||||
of CR:
|
of CR:
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ proc skipAlias*(s: PSym; n: PNode; conf: ConfigRef): PSym =
|
||||||
else:
|
else:
|
||||||
result = s.owner
|
result = s.owner
|
||||||
if conf.cmd == cmdPretty:
|
if conf.cmd == cmdPretty:
|
||||||
prettybase.replaceDeprecated(n.info, s, result)
|
prettybase.replaceDeprecated(conf, n.info, s, result)
|
||||||
else:
|
else:
|
||||||
message(conf, n.info, warnDeprecated, "use " & result.name.s & " instead; " &
|
message(conf, n.info, warnDeprecated, "use " & result.name.s & " instead; " &
|
||||||
s.name.s)
|
s.name.s)
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ proc createObj*(g: ModuleGraph; owner: PSym, info: TLineInfo; final=true): PType
|
||||||
else:
|
else:
|
||||||
rawAddSon(result, getCompilerProc(g, "RootObj").typ)
|
rawAddSon(result, getCompilerProc(g, "RootObj").typ)
|
||||||
result.n = newNodeI(nkRecList, info)
|
result.n = newNodeI(nkRecList, info)
|
||||||
let s = newSym(skType, getIdent("Env_" & info.toFilename),
|
let s = newSym(skType, getIdent("Env_" & toFilename(g.config, info)),
|
||||||
owner, info, owner.options)
|
owner, info, owner.options)
|
||||||
incl s.flags, sfAnon
|
incl s.flags, sfAnon
|
||||||
s.typ = result
|
s.typ = result
|
||||||
|
|
|
||||||
|
|
@ -35,10 +35,10 @@ proc writeDepsFile(g: ModuleGraph; project: string) =
|
||||||
let f = open(changeFileExt(project, "deps"), fmWrite)
|
let f = open(changeFileExt(project, "deps"), fmWrite)
|
||||||
for m in g.modules:
|
for m in g.modules:
|
||||||
if m != nil:
|
if m != nil:
|
||||||
f.writeLine(toFullPath(m.position.FileIndex))
|
f.writeLine(toFullPath(g.config, m.position.FileIndex))
|
||||||
for k in g.inclToMod.keys:
|
for k in g.inclToMod.keys:
|
||||||
if g.getModule(k).isNil: # don't repeat includes which are also modules
|
if g.getModule(k).isNil: # don't repeat includes which are also modules
|
||||||
f.writeLine(k.toFullPath)
|
f.writeLine(toFullPath(g.config, k))
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
proc commandGenDepend(graph: ModuleGraph; cache: IdentCache) =
|
proc commandGenDepend(graph: ModuleGraph; cache: IdentCache) =
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ proc getModuleName*(conf: ConfigRef; n: PNode): string =
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkStrLit, nkRStrLit, nkTripleStrLit:
|
of nkStrLit, nkRStrLit, nkTripleStrLit:
|
||||||
try:
|
try:
|
||||||
result = pathSubs(conf, n.strVal, n.info.toFullPath().splitFile().dir)
|
result = pathSubs(conf, n.strVal, toFullPath(conf, n.info).splitFile().dir)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
localError(conf, n.info, "invalid path: " & n.strVal)
|
localError(conf, n.info, "invalid path: " & n.strVal)
|
||||||
result = n.strVal
|
result = n.strVal
|
||||||
|
|
@ -177,7 +177,7 @@ proc getModuleName*(conf: ConfigRef; n: PNode): string =
|
||||||
proc checkModuleName*(conf: ConfigRef; n: PNode; doLocalError=true): FileIndex =
|
proc checkModuleName*(conf: ConfigRef; n: PNode; doLocalError=true): FileIndex =
|
||||||
# This returns the full canonical path for a given module import
|
# This returns the full canonical path for a given module import
|
||||||
let modulename = getModuleName(conf, n)
|
let modulename = getModuleName(conf, n)
|
||||||
let fullPath = findModule(conf, modulename, n.info.toFullPath)
|
let fullPath = findModule(conf, modulename, toFullPath(conf, n.info))
|
||||||
if fullPath.len == 0:
|
if fullPath.len == 0:
|
||||||
if doLocalError:
|
if doLocalError:
|
||||||
let m = if modulename.len > 0: modulename else: $n
|
let m = if modulename.len > 0: modulename else: $n
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ proc newModule(graph: ModuleGraph; fileIdx: FileIndex): PSym =
|
||||||
new(result)
|
new(result)
|
||||||
result.id = -1 # for better error checking
|
result.id = -1 # for better error checking
|
||||||
result.kind = skModule
|
result.kind = skModule
|
||||||
let filename = fileIdx.toFullPath
|
let filename = toFullPath(graph.config, fileIdx)
|
||||||
result.name = getIdent(splitFile(filename).name)
|
result.name = getIdent(splitFile(filename).name)
|
||||||
if not isNimIdentifier(result.name.s):
|
if not isNimIdentifier(result.name.s):
|
||||||
rawMessage(graph.config, errGenerated, "invalid module name: " & result.name.s)
|
rawMessage(graph.config, errGenerated, "invalid module name: " & result.name.s)
|
||||||
|
|
@ -50,7 +50,9 @@ proc newModule(graph: ModuleGraph; fileIdx: FileIndex): PSym =
|
||||||
strTableAdd(result.tab, result) # a module knows itself
|
strTableAdd(result.tab, result) # a module knows itself
|
||||||
let existing = strTableGet(packSym.tab, result.name)
|
let existing = strTableGet(packSym.tab, result.name)
|
||||||
if existing != nil and existing.info.fileIndex != result.info.fileIndex:
|
if existing != nil and existing.info.fileIndex != result.info.fileIndex:
|
||||||
localError(graph.config, result.info, "module names need to be unique per Nimble package; module clashes with " & existing.info.fileIndex.toFullPath)
|
localError(graph.config, result.info,
|
||||||
|
"module names need to be unique per Nimble package; module clashes with " &
|
||||||
|
toFullPath(graph.config, existing.info.fileIndex))
|
||||||
# strTableIncl() for error corrections:
|
# strTableIncl() for error corrections:
|
||||||
discard strTableIncl(packSym.tab, result)
|
discard strTableIncl(packSym.tab, result)
|
||||||
|
|
||||||
|
|
@ -73,7 +75,7 @@ proc compileModule*(graph: ModuleGraph; fileIdx: FileIndex; cache: IdentCache, f
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
discard
|
discard
|
||||||
result.id = getModuleId(fileIdx, toFullPath(fileIdx))
|
result.id = getModuleId(fileIdx, toFullPath(graph.config, fileIdx))
|
||||||
discard processModule(graph, result,
|
discard processModule(graph, result,
|
||||||
if sfMainModule in flags and graph.config.projectIsStdin: stdin.llStreamOpen else: nil,
|
if sfMainModule in flags and graph.config.projectIsStdin: stdin.llStreamOpen else: nil,
|
||||||
rd, cache)
|
rd, cache)
|
||||||
|
|
|
||||||
|
|
@ -157,13 +157,6 @@ proc newLineInfo*(fileInfoIdx: FileIndex, line, col: int): TLineInfo =
|
||||||
proc newLineInfo*(conf: ConfigRef; filename: string, line, col: int): TLineInfo {.inline.} =
|
proc newLineInfo*(conf: ConfigRef; filename: string, line, col: int): TLineInfo {.inline.} =
|
||||||
result = newLineInfo(fileInfoIdx(conf, filename), line, col)
|
result = newLineInfo(fileInfoIdx(conf, filename), line, col)
|
||||||
|
|
||||||
when false:
|
|
||||||
fileInfos.add(newFileInfo("", "command line"))
|
|
||||||
var gCmdLineInfo* = newLineInfo(FileIndex(0), 1, 1)
|
|
||||||
|
|
||||||
fileInfos.add(newFileInfo("", "compilation artifact"))
|
|
||||||
var gCodegenLineInfo* = newLineInfo(FileIndex(1), 1, 1)
|
|
||||||
|
|
||||||
proc raiseRecoverableError*(msg: string) {.noinline, noreturn.} =
|
proc raiseRecoverableError*(msg: string) {.noinline, noreturn.} =
|
||||||
raise newException(ERecoverableError, msg)
|
raise newException(ERecoverableError, msg)
|
||||||
|
|
||||||
|
|
@ -184,7 +177,7 @@ var
|
||||||
|
|
||||||
errorOutputs* = {eStdOut, eStdErr}
|
errorOutputs* = {eStdOut, eStdErr}
|
||||||
writelnHook*: proc (output: string) {.closure.}
|
writelnHook*: proc (output: string) {.closure.}
|
||||||
structuredErrorHook*: proc (info: TLineInfo; msg: string; severity: Severity) {.closure.}
|
structuredErrorHook*: proc (config: ConfigRef; info: TLineInfo; msg: string; severity: Severity) {.closure.}
|
||||||
|
|
||||||
proc concat(strings: openarray[string]): string =
|
proc concat(strings: openarray[string]): string =
|
||||||
var totalLen = 0
|
var totalLen = 0
|
||||||
|
|
@ -234,26 +227,26 @@ proc getInfoContext*(index: int): TLineInfo =
|
||||||
if i >=% L: result = unknownLineInfo()
|
if i >=% L: result = unknownLineInfo()
|
||||||
else: result = msgContext[i]
|
else: result = msgContext[i]
|
||||||
|
|
||||||
template toFilename*(fileIdx: FileIndex): string =
|
template toFilename*(conf: ConfigRef; fileIdx: FileIndex): string =
|
||||||
(if fileIdx.int32 < 0: "???" else: fileInfos[fileIdx.int32].projPath)
|
(if fileIdx.int32 < 0: "???" else: fileInfos[fileIdx.int32].projPath)
|
||||||
|
|
||||||
proc toFullPath*(fileIdx: FileIndex): string =
|
proc toFullPath*(conf: ConfigRef; fileIdx: FileIndex): string =
|
||||||
if fileIdx.int32 < 0: result = "???"
|
if fileIdx.int32 < 0: result = "???"
|
||||||
else: result = fileInfos[fileIdx.int32].fullPath
|
else: result = fileInfos[fileIdx.int32].fullPath
|
||||||
|
|
||||||
proc setDirtyFile*(fileIdx: FileIndex; filename: string) =
|
proc setDirtyFile*(conf: ConfigRef; fileIdx: FileIndex; filename: string) =
|
||||||
assert fileIdx.int32 >= 0
|
assert fileIdx.int32 >= 0
|
||||||
fileInfos[fileIdx.int32].dirtyFile = filename
|
fileInfos[fileIdx.int32].dirtyFile = filename
|
||||||
|
|
||||||
proc setHash*(fileIdx: FileIndex; hash: string) =
|
proc setHash*(conf: ConfigRef; fileIdx: FileIndex; hash: string) =
|
||||||
assert fileIdx.int32 >= 0
|
assert fileIdx.int32 >= 0
|
||||||
shallowCopy(fileInfos[fileIdx.int32].hash, hash)
|
shallowCopy(fileInfos[fileIdx.int32].hash, hash)
|
||||||
|
|
||||||
proc getHash*(fileIdx: FileIndex): string =
|
proc getHash*(conf: ConfigRef; fileIdx: FileIndex): string =
|
||||||
assert fileIdx.int32 >= 0
|
assert fileIdx.int32 >= 0
|
||||||
shallowCopy(result, fileInfos[fileIdx.int32].hash)
|
shallowCopy(result, fileInfos[fileIdx.int32].hash)
|
||||||
|
|
||||||
proc toFullPathConsiderDirty*(fileIdx: FileIndex): string =
|
proc toFullPathConsiderDirty*(conf: ConfigRef; fileIdx: FileIndex): string =
|
||||||
if fileIdx.int32 < 0:
|
if fileIdx.int32 < 0:
|
||||||
result = "???"
|
result = "???"
|
||||||
elif not fileInfos[fileIdx.int32].dirtyFile.isNil:
|
elif not fileInfos[fileIdx.int32].dirtyFile.isNil:
|
||||||
|
|
@ -261,11 +254,11 @@ proc toFullPathConsiderDirty*(fileIdx: FileIndex): string =
|
||||||
else:
|
else:
|
||||||
result = fileInfos[fileIdx.int32].fullPath
|
result = fileInfos[fileIdx.int32].fullPath
|
||||||
|
|
||||||
template toFilename*(info: TLineInfo): string =
|
template toFilename*(conf: ConfigRef; info: TLineInfo): string =
|
||||||
info.fileIndex.toFilename
|
toFilename(conf, info.fileIndex)
|
||||||
|
|
||||||
template toFullPath*(info: TLineInfo): string =
|
template toFullPath*(conf: ConfigRef; info: TLineInfo): string =
|
||||||
info.fileIndex.toFullPath
|
toFullPath(conf, info.fileIndex)
|
||||||
|
|
||||||
proc toMsgFilename*(conf: ConfigRef; info: TLineInfo): string =
|
proc toMsgFilename*(conf: ConfigRef; info: TLineInfo): string =
|
||||||
if info.fileIndex.int32 < 0:
|
if info.fileIndex.int32 < 0:
|
||||||
|
|
@ -281,17 +274,17 @@ proc toLinenumber*(info: TLineInfo): int {.inline.} =
|
||||||
proc toColumn*(info: TLineInfo): int {.inline.} =
|
proc toColumn*(info: TLineInfo): int {.inline.} =
|
||||||
result = info.col
|
result = info.col
|
||||||
|
|
||||||
proc toFileLine*(info: TLineInfo): string {.inline.} =
|
proc toFileLine*(conf: ConfigRef; info: TLineInfo): string {.inline.} =
|
||||||
result = info.toFilename & ":" & $info.line
|
result = toFilename(conf, info) & ":" & $info.line
|
||||||
|
|
||||||
proc toFileLineCol*(info: TLineInfo): string {.inline.} =
|
proc toFileLineCol*(conf: ConfigRef; info: TLineInfo): string {.inline.} =
|
||||||
result = info.toFilename & "(" & $info.line & ", " & $info.col & ")"
|
result = toFilename(conf, info) & "(" & $info.line & ", " & $info.col & ")"
|
||||||
|
|
||||||
proc `$`*(info: TLineInfo): string = toFileLineCol(info)
|
proc `$`*(conf: ConfigRef; info: TLineInfo): string = toFileLineCol(conf, info)
|
||||||
|
|
||||||
proc `??`* (info: TLineInfo, filename: string): bool =
|
proc `??`* (conf: ConfigRef; info: TLineInfo, filename: string): bool =
|
||||||
# only for debugging purposes
|
# only for debugging purposes
|
||||||
result = filename in info.toFilename
|
result = filename in toFilename(conf, info)
|
||||||
|
|
||||||
const trackPosInvalidFileIdx* = FileIndex(-2) # special marker so that no suggestions
|
const trackPosInvalidFileIdx* = FileIndex(-2) # special marker so that no suggestions
|
||||||
# are produced within comments and string literals
|
# are produced within comments and string literals
|
||||||
|
|
@ -428,7 +421,7 @@ proc writeContext(conf: ConfigRef; lastinfo: TLineInfo) =
|
||||||
for i in countup(0, len(msgContext) - 1):
|
for i in countup(0, len(msgContext) - 1):
|
||||||
if msgContext[i] != lastinfo and msgContext[i] != info:
|
if msgContext[i] != lastinfo and msgContext[i] != info:
|
||||||
if structuredErrorHook != nil:
|
if structuredErrorHook != nil:
|
||||||
structuredErrorHook(msgContext[i], instantiationFrom,
|
structuredErrorHook(conf, msgContext[i], instantiationFrom,
|
||||||
Severity.Error)
|
Severity.Error)
|
||||||
else:
|
else:
|
||||||
styledMsgWriteln(styleBright,
|
styledMsgWriteln(styleBright,
|
||||||
|
|
@ -474,7 +467,7 @@ proc rawMessage*(conf: ConfigRef; msg: TMsgKind, args: openArray[string]) =
|
||||||
let s = msgKindToString(msg) % args
|
let s = msgKindToString(msg) % args
|
||||||
|
|
||||||
if structuredErrorHook != nil:
|
if structuredErrorHook != nil:
|
||||||
structuredErrorHook(unknownLineInfo(), s & (if kind != nil: KindFormat % kind else: ""), sev)
|
structuredErrorHook(conf, unknownLineInfo(), s & (if kind != nil: KindFormat % kind else: ""), sev)
|
||||||
|
|
||||||
if not ignoreMsgBecauseOfIdeTools(conf, msg):
|
if not ignoreMsgBecauseOfIdeTools(conf, msg):
|
||||||
if kind != nil:
|
if kind != nil:
|
||||||
|
|
@ -548,7 +541,7 @@ proc liMessage(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
|
||||||
|
|
||||||
if not ignoreMsg:
|
if not ignoreMsg:
|
||||||
if structuredErrorHook != nil:
|
if structuredErrorHook != nil:
|
||||||
structuredErrorHook(info, s & (if kind != nil: KindFormat % kind else: ""), sev)
|
structuredErrorHook(conf, info, s & (if kind != nil: KindFormat % kind else: ""), sev)
|
||||||
if not ignoreMsgBecauseOfIdeTools(conf, msg):
|
if not ignoreMsgBecauseOfIdeTools(conf, msg):
|
||||||
if kind != nil:
|
if kind != nil:
|
||||||
styledMsgWriteln(styleBright, x, resetStyle, color, title, resetStyle, s,
|
styledMsgWriteln(styleBright, x, resetStyle, color, title, resetStyle, s,
|
||||||
|
|
@ -600,7 +593,7 @@ template assertNotNil*(conf: ConfigRef; e): untyped =
|
||||||
template internalAssert*(conf: ConfigRef, e: bool) =
|
template internalAssert*(conf: ConfigRef, e: bool) =
|
||||||
if not e: internalError(conf, $instantiationInfo())
|
if not e: internalError(conf, $instantiationInfo())
|
||||||
|
|
||||||
proc addSourceLine*(fileIdx: FileIndex, line: string) =
|
proc addSourceLine*(conf: ConfigRef; fileIdx: FileIndex, line: string) =
|
||||||
fileInfos[fileIdx.int32].lines.add line.rope
|
fileInfos[fileIdx.int32].lines.add line.rope
|
||||||
|
|
||||||
proc sourceLine*(conf: ConfigRef; i: TLineInfo): Rope =
|
proc sourceLine*(conf: ConfigRef; i: TLineInfo): Rope =
|
||||||
|
|
@ -608,8 +601,8 @@ proc sourceLine*(conf: ConfigRef; i: TLineInfo): Rope =
|
||||||
|
|
||||||
if not optPreserveOrigSource(conf) and fileInfos[i.fileIndex.int32].lines.len == 0:
|
if not optPreserveOrigSource(conf) and fileInfos[i.fileIndex.int32].lines.len == 0:
|
||||||
try:
|
try:
|
||||||
for line in lines(i.toFullPath):
|
for line in lines(toFullPath(conf, i)):
|
||||||
addSourceLine i.fileIndex, line.string
|
addSourceLine conf, i.fileIndex, line.string
|
||||||
except IOError:
|
except IOError:
|
||||||
discard
|
discard
|
||||||
assert i.fileIndex.int32 < fileInfos.len
|
assert i.fileIndex.int32 < fileInfos.len
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
## This module implements the generation of ``.ndi`` files for better debugging
|
## This module implements the generation of ``.ndi`` files for better debugging
|
||||||
## support of Nim code. "ndi" stands for "Nim debug info".
|
## support of Nim code. "ndi" stands for "Nim debug info".
|
||||||
|
|
||||||
import ast, msgs, ropes
|
import ast, msgs, ropes, options
|
||||||
|
|
||||||
type
|
type
|
||||||
NdiFile* = object
|
NdiFile* = object
|
||||||
|
|
@ -18,19 +18,19 @@ type
|
||||||
f: File
|
f: File
|
||||||
buf: string
|
buf: string
|
||||||
|
|
||||||
proc doWrite(f: var NdiFile; s: PSym) =
|
proc doWrite(f: var NdiFile; s: PSym; conf: ConfigRef) =
|
||||||
f.buf.setLen 0
|
f.buf.setLen 0
|
||||||
f.buf.add s.info.line.int
|
f.buf.add s.info.line.int
|
||||||
f.buf.add "\t"
|
f.buf.add "\t"
|
||||||
f.buf.add s.info.col.int
|
f.buf.add s.info.col.int
|
||||||
f.f.write(s.name.s, "\t")
|
f.f.write(s.name.s, "\t")
|
||||||
f.f.writeRope(s.loc.r)
|
f.f.writeRope(s.loc.r)
|
||||||
f.f.writeLine("\t", s.info.toFullPath, "\t", f.buf)
|
f.f.writeLine("\t", toFullPath(conf, s.info), "\t", f.buf)
|
||||||
|
|
||||||
template writeMangledName*(f: NdiFile; s: PSym) =
|
template writeMangledName*(f: NdiFile; s: PSym; conf: ConfigRef) =
|
||||||
if f.enabled: doWrite(f, s)
|
if f.enabled: doWrite(f, s, conf)
|
||||||
|
|
||||||
proc open*(f: var NdiFile; filename: string) =
|
proc open*(f: var NdiFile; filename: string; conf: ConfigRef) =
|
||||||
f.enabled = filename.len > 0
|
f.enabled = filename.len > 0
|
||||||
if f.enabled:
|
if f.enabled:
|
||||||
f.f = open(filename, fmWrite, 8000)
|
f.f = open(filename, fmWrite, 8000)
|
||||||
|
|
|
||||||
|
|
@ -93,8 +93,8 @@ proc beautifyName(s: string, k: TSymKind): string =
|
||||||
result.add s[i]
|
result.add s[i]
|
||||||
inc i
|
inc i
|
||||||
|
|
||||||
proc replaceInFile(info: TLineInfo; newName: string) =
|
proc replaceInFile(conf: ConfigRef; info: TLineInfo; newName: string) =
|
||||||
loadFile(info)
|
loadFile(conf, info)
|
||||||
|
|
||||||
let line = gSourceFiles[info.fileIndex.int].lines[info.line.int-1]
|
let line = gSourceFiles[info.fileIndex.int].lines[info.line.int-1]
|
||||||
var first = min(info.col.int, line.len)
|
var first = min(info.col.int, line.len)
|
||||||
|
|
@ -116,7 +116,7 @@ proc checkStyle(conf: ConfigRef; info: TLineInfo, s: string, k: TSymKind; sym: P
|
||||||
if s != beau:
|
if s != beau:
|
||||||
if gStyleCheck == StyleCheck.Auto:
|
if gStyleCheck == StyleCheck.Auto:
|
||||||
sym.name = getIdent(beau)
|
sym.name = getIdent(beau)
|
||||||
replaceInFile(info, beau)
|
replaceInFile(conf, info, beau)
|
||||||
else:
|
else:
|
||||||
message(conf, info, hintName, beau)
|
message(conf, info, hintName, beau)
|
||||||
|
|
||||||
|
|
@ -136,7 +136,7 @@ template styleCheckDef*(info: TLineInfo; s: PSym) =
|
||||||
template styleCheckDef*(s: PSym) =
|
template styleCheckDef*(s: PSym) =
|
||||||
styleCheckDef(s.info, s, s.kind)
|
styleCheckDef(s.info, s, s.kind)
|
||||||
|
|
||||||
proc styleCheckUseImpl(info: TLineInfo; s: PSym) =
|
proc styleCheckUseImpl(conf: ConfigRef; info: TLineInfo; s: PSym) =
|
||||||
if info.fileIndex.int < 0: return
|
if info.fileIndex.int < 0: return
|
||||||
# we simply convert it to what it looks like in the definition
|
# we simply convert it to what it looks like in the definition
|
||||||
# for consistency
|
# for consistency
|
||||||
|
|
@ -147,7 +147,7 @@ proc styleCheckUseImpl(info: TLineInfo; s: PSym) =
|
||||||
if s.kind in {skType, skGenericParam} and sfAnon in s.flags: return
|
if s.kind in {skType, skGenericParam} and sfAnon in s.flags: return
|
||||||
let newName = s.name.s
|
let newName = s.name.s
|
||||||
|
|
||||||
replaceInFile(info, newName)
|
replaceInFile(conf, info, newName)
|
||||||
#if newName == "File": writeStackTrace()
|
#if newName == "File": writeStackTrace()
|
||||||
|
|
||||||
template styleCheckUse*(info: TLineInfo; s: PSym) =
|
template styleCheckUse*(info: TLineInfo; s: PSym) =
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
import strutils, lexbase, streams
|
import strutils, lexbase, streams
|
||||||
import ".." / [ast, msgs, idents]
|
import ".." / [ast, msgs, idents, options]
|
||||||
from os import splitFile
|
from os import splitFile
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
@ -21,14 +21,14 @@ type
|
||||||
var
|
var
|
||||||
gSourceFiles*: seq[TSourceFile] = @[]
|
gSourceFiles*: seq[TSourceFile] = @[]
|
||||||
|
|
||||||
proc loadFile*(info: TLineInfo) =
|
proc loadFile*(conf: ConfigRef; info: TLineInfo) =
|
||||||
let i = info.fileIndex.int
|
let i = info.fileIndex.int
|
||||||
if i >= gSourceFiles.len:
|
if i >= gSourceFiles.len:
|
||||||
gSourceFiles.setLen(i+1)
|
gSourceFiles.setLen(i+1)
|
||||||
if gSourceFiles[i].lines.isNil:
|
if gSourceFiles[i].lines.isNil:
|
||||||
gSourceFiles[i].fileIdx = info.fileIndex
|
gSourceFiles[i].fileIdx = info.fileIndex
|
||||||
gSourceFiles[i].lines = @[]
|
gSourceFiles[i].lines = @[]
|
||||||
let path = info.toFullPath
|
let path = toFullPath(conf, info)
|
||||||
gSourceFiles[i].fullpath = path
|
gSourceFiles[i].fullpath = path
|
||||||
gSourceFiles[i].isNimfixFile = path.splitFile.ext == ".nimfix"
|
gSourceFiles[i].isNimfixFile = path.splitFile.ext == ".nimfix"
|
||||||
# we want to die here for IOError:
|
# we want to die here for IOError:
|
||||||
|
|
@ -61,8 +61,8 @@ proc differ*(line: string, a, b: int, x: string): bool =
|
||||||
let y = line[a..b]
|
let y = line[a..b]
|
||||||
result = cmpIgnoreStyle(y, x) == 0 and y != x
|
result = cmpIgnoreStyle(y, x) == 0 and y != x
|
||||||
|
|
||||||
proc replaceDeprecated*(info: TLineInfo; oldSym, newSym: PIdent) =
|
proc replaceDeprecated*(conf: ConfigRef; info: TLineInfo; oldSym, newSym: PIdent) =
|
||||||
loadFile(info)
|
loadFile(conf, info)
|
||||||
|
|
||||||
let line = gSourceFiles[info.fileIndex.int32].lines[info.line.int-1]
|
let line = gSourceFiles[info.fileIndex.int32].lines[info.line.int-1]
|
||||||
var first = min(info.col.int, line.len)
|
var first = min(info.col.int, line.len)
|
||||||
|
|
@ -79,11 +79,11 @@ proc replaceDeprecated*(info: TLineInfo; oldSym, newSym: PIdent) =
|
||||||
gSourceFiles[info.fileIndex.int32].dirty = true
|
gSourceFiles[info.fileIndex.int32].dirty = true
|
||||||
#if newSym.s == "File": writeStackTrace()
|
#if newSym.s == "File": writeStackTrace()
|
||||||
|
|
||||||
proc replaceDeprecated*(info: TLineInfo; oldSym, newSym: PSym) =
|
proc replaceDeprecated*(conf: ConfigRef; info: TLineInfo; oldSym, newSym: PSym) =
|
||||||
replaceDeprecated(info, oldSym.name, newSym.name)
|
replaceDeprecated(conf, info, oldSym.name, newSym.name)
|
||||||
|
|
||||||
proc replaceComment*(info: TLineInfo) =
|
proc replaceComment*(conf: ConfigRef; info: TLineInfo) =
|
||||||
loadFile(info)
|
loadFile(conf, info)
|
||||||
|
|
||||||
let line = gSourceFiles[info.fileIndex.int32].lines[info.line.int-1]
|
let line = gSourceFiles[info.fileIndex.int32].lines[info.line.int-1]
|
||||||
var first = info.col.int
|
var first = info.col.int
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,7 @@ proc processImplicits(conf: ConfigRef; implicits: seq[string], nodeKind: TNodeKi
|
||||||
a: var TPassContextArray; m: PSym) =
|
a: var TPassContextArray; m: PSym) =
|
||||||
# XXX fixme this should actually be relative to the config file!
|
# XXX fixme this should actually be relative to the config file!
|
||||||
let gCmdLineInfo = newLineInfo(FileIndex(0), 1, 1)
|
let gCmdLineInfo = newLineInfo(FileIndex(0), 1, 1)
|
||||||
let relativeTo = m.info.toFullPath
|
let relativeTo = toFullPath(conf, m.info)
|
||||||
for module in items(implicits):
|
for module in items(implicits):
|
||||||
# implicit imports should not lead to a module importing itself
|
# implicit imports should not lead to a module importing itself
|
||||||
if m.position != resolveMod(conf, module, relativeTo).int32:
|
if m.position != resolveMod(conf, module, relativeTo).int32:
|
||||||
|
|
@ -201,7 +201,7 @@ proc processModule*(graph: ModuleGraph; module: PSym, stream: PLLStream,
|
||||||
elif rd == nil:
|
elif rd == nil:
|
||||||
openPasses(graph, a, module, cache)
|
openPasses(graph, a, module, cache)
|
||||||
if stream == nil:
|
if stream == nil:
|
||||||
let filename = fileIdx.toFullPathConsiderDirty
|
let filename = toFullPathConsiderDirty(graph.config, fileIdx)
|
||||||
s = llStreamOpen(filename, fmRead)
|
s = llStreamOpen(filename, fmRead)
|
||||||
if s == nil:
|
if s == nil:
|
||||||
rawMessage(graph.config, errCannotOpenFile, filename)
|
rawMessage(graph.config, errCannotOpenFile, filename)
|
||||||
|
|
|
||||||
|
|
@ -404,7 +404,7 @@ proc relativeFile(c: PContext; n: PNode; ext=""): string =
|
||||||
var s = expectStrLit(c, n)
|
var s = expectStrLit(c, n)
|
||||||
if ext.len > 0 and splitFile(s).ext == "":
|
if ext.len > 0 and splitFile(s).ext == "":
|
||||||
s = addFileExt(s, ext)
|
s = addFileExt(s, ext)
|
||||||
result = parentDir(n.info.toFullPath) / s
|
result = parentDir(toFullPath(c.config, n.info)) / s
|
||||||
if not fileExists(result):
|
if not fileExists(result):
|
||||||
if isAbsolute(s): result = s
|
if isAbsolute(s): result = s
|
||||||
else:
|
else:
|
||||||
|
|
@ -426,7 +426,7 @@ proc processCompile(c: PContext, n: PNode) =
|
||||||
if it.kind in {nkPar, nkTupleConstr} and it.len == 2:
|
if it.kind in {nkPar, nkTupleConstr} and it.len == 2:
|
||||||
let s = getStrLit(c, it, 0)
|
let s = getStrLit(c, it, 0)
|
||||||
let dest = getStrLit(c, it, 1)
|
let dest = getStrLit(c, it, 1)
|
||||||
var found = parentDir(n.info.toFullPath) / s
|
var found = parentDir(toFullPath(c.config, n.info)) / s
|
||||||
for f in os.walkFiles(found):
|
for f in os.walkFiles(found):
|
||||||
let nameOnly = extractFilename(f)
|
let nameOnly = extractFilename(f)
|
||||||
var cf = Cfile(cname: f,
|
var cf = Cfile(cname: f,
|
||||||
|
|
@ -435,7 +435,7 @@ proc processCompile(c: PContext, n: PNode) =
|
||||||
extccomp.addExternalFileToCompile(c.config, cf)
|
extccomp.addExternalFileToCompile(c.config, cf)
|
||||||
else:
|
else:
|
||||||
let s = expectStrLit(c, n)
|
let s = expectStrLit(c, n)
|
||||||
var found = parentDir(n.info.toFullPath) / s
|
var found = parentDir(toFullPath(c.config, n.info)) / s
|
||||||
if not fileExists(found):
|
if not fileExists(found):
|
||||||
if isAbsolute(s): found = s
|
if isAbsolute(s): found = s
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,8 @@ proc expandIncludes(graph: ModuleGraph, module: PSym, n: PNode,
|
||||||
var f = checkModuleName(graph.config, a.sons[i])
|
var f = checkModuleName(graph.config, a.sons[i])
|
||||||
if f != InvalidFileIDX:
|
if f != InvalidFileIDX:
|
||||||
if containsOrIncl(includedFiles, f.int):
|
if containsOrIncl(includedFiles, f.int):
|
||||||
localError(graph.config, a.info, "recursive dependency: '$1'" % f.toFilename)
|
localError(graph.config, a.info, "recursive dependency: '$1'" %
|
||||||
|
toFilename(graph.config, f))
|
||||||
else:
|
else:
|
||||||
let nn = includeModule(graph, module, f, cache)
|
let nn = includeModule(graph, module, f, cache)
|
||||||
let nnn = expandIncludes(graph, module, nn, modulePath,
|
let nnn = expandIncludes(graph, module, nn, modulePath,
|
||||||
|
|
@ -430,7 +431,7 @@ proc reorder*(graph: ModuleGraph, n: PNode, module: PSym, cache: IdentCache): PN
|
||||||
if n.hasForbiddenPragma:
|
if n.hasForbiddenPragma:
|
||||||
return n
|
return n
|
||||||
var includedFiles = initIntSet()
|
var includedFiles = initIntSet()
|
||||||
let mpath = module.fileIdx.toFullPath
|
let mpath = toFullPath(graph.config, module.fileIdx)
|
||||||
let n = expandIncludes(graph, module, n, mpath,
|
let n = expandIncludes(graph, module, n, mpath,
|
||||||
includedFiles, cache).splitSections
|
includedFiles, cache).splitSections
|
||||||
result = newNodeI(nkStmtList, n.info)
|
result = newNodeI(nkStmtList, n.info)
|
||||||
|
|
|
||||||
|
|
@ -658,7 +658,7 @@ proc processRodFile(r: PRodReader, hash: SecureHash) =
|
||||||
inc(r.pos, 2) # skip "(\10"
|
inc(r.pos, 2) # skip "(\10"
|
||||||
inc(r.line)
|
inc(r.line)
|
||||||
while r.s[r.pos] != ')':
|
while r.s[r.pos] != ')':
|
||||||
w = r.files[decodeVInt(r.s, r.pos)].toFullPath
|
w = toFullPath(r.config, r.files[decodeVInt(r.s, r.pos)])
|
||||||
inc(r.pos) # skip ' '
|
inc(r.pos) # skip ' '
|
||||||
inclHash = parseSecureHash(decodeStr(r.s, r.pos))
|
inclHash = parseSecureHash(decodeStr(r.s, r.pos))
|
||||||
if r.reason == rrNone:
|
if r.reason == rrNone:
|
||||||
|
|
@ -865,11 +865,11 @@ proc loadMethods(r: PRodReader) =
|
||||||
r.methods.add(rrGetSym(r, d, unknownLineInfo()))
|
r.methods.add(rrGetSym(r, d, unknownLineInfo()))
|
||||||
if r.s[r.pos] == ' ': inc(r.pos)
|
if r.s[r.pos] == ' ': inc(r.pos)
|
||||||
|
|
||||||
proc getHash*(fileIdx: FileIndex): SecureHash =
|
proc getHash*(conf: ConfigRef; fileIdx: FileIndex): SecureHash =
|
||||||
if fileIdx.int32 <% gMods.len and gMods[fileIdx.int32].hashDone:
|
if fileIdx.int32 <% gMods.len and gMods[fileIdx.int32].hashDone:
|
||||||
return gMods[fileIdx.int32].hash
|
return gMods[fileIdx.int32].hash
|
||||||
|
|
||||||
result = secureHashFile(fileIdx.toFullPath)
|
result = secureHashFile(toFullPath(conf, fileIdx))
|
||||||
if fileIdx.int32 >= gMods.len: setLen(gMods, fileIdx.int32+1)
|
if fileIdx.int32 >= gMods.len: setLen(gMods, fileIdx.int32+1)
|
||||||
gMods[fileIdx.int32].hash = result
|
gMods[fileIdx.int32].hash = result
|
||||||
|
|
||||||
|
|
@ -882,8 +882,8 @@ proc checkDep(fileIdx: FileIndex; cache: IdentCache; conf: ConfigRef): TReasonFo
|
||||||
if gMods[fileIdx.int32].reason != rrEmpty:
|
if gMods[fileIdx.int32].reason != rrEmpty:
|
||||||
# reason has already been computed for this module:
|
# reason has already been computed for this module:
|
||||||
return gMods[fileIdx.int32].reason
|
return gMods[fileIdx.int32].reason
|
||||||
let filename = fileIdx.toFilename
|
let filename = toFilename(conf, fileIdx)
|
||||||
var hash = getHash(fileIdx)
|
var hash = getHash(conf, fileIdx)
|
||||||
gMods[fileIdx.int32].reason = rrNone # we need to set it here to avoid cycles
|
gMods[fileIdx.int32].reason = rrNone # we need to set it here to avoid cycles
|
||||||
result = rrNone
|
result = rrNone
|
||||||
var rodfile = toGeneratedFile(conf, conf.withPackageName(filename), RodExt)
|
var rodfile = toGeneratedFile(conf, conf.withPackageName(filename), RodExt)
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ proc fileIdx(w: PRodWriter, filename: string): int =
|
||||||
w.files[result] = filename
|
w.files[result] = filename
|
||||||
|
|
||||||
template filename*(w: PRodWriter): string =
|
template filename*(w: PRodWriter): string =
|
||||||
toFilename(FileIndex w.module.position)
|
toFilename(w.config, FileIndex w.module.position)
|
||||||
|
|
||||||
proc newRodWriter(hash: SecureHash, module: PSym; cache: IdentCache;
|
proc newRodWriter(hash: SecureHash, module: PSym; cache: IdentCache;
|
||||||
config: ConfigRef): PRodWriter =
|
config: ConfigRef): PRodWriter =
|
||||||
|
|
@ -80,20 +80,20 @@ proc newRodWriter(hash: SecureHash, module: PSym; cache: IdentCache;
|
||||||
result.converters = ""
|
result.converters = ""
|
||||||
result.methods = ""
|
result.methods = ""
|
||||||
result.init = ""
|
result.init = ""
|
||||||
result.origFile = module.info.toFullPath
|
result.origFile = toFullPath(config, module.info)
|
||||||
result.data = newStringOfCap(12_000)
|
result.data = newStringOfCap(12_000)
|
||||||
result.cache = cache
|
result.cache = cache
|
||||||
|
|
||||||
proc addModDep(w: PRodWriter, dep: string; info: TLineInfo) =
|
proc addModDep(w: PRodWriter, dep: string; info: TLineInfo) =
|
||||||
if w.modDeps.len != 0: add(w.modDeps, ' ')
|
if w.modDeps.len != 0: add(w.modDeps, ' ')
|
||||||
let resolved = findModule(w.config, dep, info.toFullPath)
|
let resolved = findModule(w.config, dep, toFullPath(w.config, info))
|
||||||
encodeVInt(fileIdx(w, resolved), w.modDeps)
|
encodeVInt(fileIdx(w, resolved), w.modDeps)
|
||||||
|
|
||||||
const
|
const
|
||||||
rodNL = "\x0A"
|
rodNL = "\x0A"
|
||||||
|
|
||||||
proc addInclDep(w: PRodWriter, dep: string; info: TLineInfo) =
|
proc addInclDep(w: PRodWriter, dep: string; info: TLineInfo) =
|
||||||
let resolved = findModule(w.config, dep, info.toFullPath)
|
let resolved = findModule(w.config, dep, toFullPath(w.config, info))
|
||||||
encodeVInt(fileIdx(w, resolved), w.inclDeps)
|
encodeVInt(fileIdx(w, resolved), w.inclDeps)
|
||||||
add(w.inclDeps, " ")
|
add(w.inclDeps, " ")
|
||||||
encodeStr($secureHashFile(resolved), w.inclDeps)
|
encodeStr($secureHashFile(resolved), w.inclDeps)
|
||||||
|
|
@ -130,7 +130,7 @@ proc encodeNode(w: PRodWriter, fInfo: TLineInfo, n: PNode,
|
||||||
result.add(',')
|
result.add(',')
|
||||||
encodeVInt(int n.info.line, result)
|
encodeVInt(int n.info.line, result)
|
||||||
result.add(',')
|
result.add(',')
|
||||||
encodeVInt(fileIdx(w, toFullPath(n.info)), result)
|
encodeVInt(fileIdx(w, toFullPath(w.config, n.info)), result)
|
||||||
elif fInfo.line != n.info.line:
|
elif fInfo.line != n.info.line:
|
||||||
result.add('?')
|
result.add('?')
|
||||||
encodeVInt(n.info.col, result)
|
encodeVInt(n.info.col, result)
|
||||||
|
|
@ -308,7 +308,7 @@ proc encodeSym(w: PRodWriter, s: PSym, result: var string) =
|
||||||
result.add(',')
|
result.add(',')
|
||||||
if s.info.line != 0'u16: encodeVInt(int s.info.line, result)
|
if s.info.line != 0'u16: encodeVInt(int s.info.line, result)
|
||||||
result.add(',')
|
result.add(',')
|
||||||
encodeVInt(fileIdx(w, toFullPath(s.info)), result)
|
encodeVInt(fileIdx(w, toFullPath(w.config, s.info)), result)
|
||||||
if s.owner != nil:
|
if s.owner != nil:
|
||||||
result.add('*')
|
result.add('*')
|
||||||
encodeVInt(s.owner.id, result)
|
encodeVInt(s.owner.id, result)
|
||||||
|
|
@ -645,7 +645,7 @@ proc process(c: PPassContext, n: PNode): PNode =
|
||||||
|
|
||||||
proc myOpen(g: ModuleGraph; module: PSym; cache: IdentCache): PPassContext =
|
proc myOpen(g: ModuleGraph; module: PSym; cache: IdentCache): PPassContext =
|
||||||
if module.id < 0: internalError(g.config, "rodwrite: module ID not set")
|
if module.id < 0: internalError(g.config, "rodwrite: module ID not set")
|
||||||
var w = newRodWriter(rodread.getHash FileIndex module.position, module, cache, g.config)
|
var w = newRodWriter(rodread.getHash(g.config, FileIndex module.position), module, cache, g.config)
|
||||||
rawAddInterfaceSym(w, module)
|
rawAddInterfaceSym(w, module)
|
||||||
result = w
|
result = w
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -599,7 +599,7 @@ proc myProcess(context: PPassContext, n: PNode): PNode =
|
||||||
rod.storeNode(c.module, result)
|
rod.storeNode(c.module, result)
|
||||||
|
|
||||||
proc testExamples(c: PContext) =
|
proc testExamples(c: PContext) =
|
||||||
let inp = toFullPath(c.module.info)
|
let inp = toFullPath(c.config, c.module.info)
|
||||||
let outp = inp.changeFileExt"" & "_examples.nim"
|
let outp = inp.changeFileExt"" & "_examples.nim"
|
||||||
renderModule(c.runnableExamples, inp, outp)
|
renderModule(c.runnableExamples, inp, outp)
|
||||||
let backend = if isDefined(c.config, "js"): "js"
|
let backend = if isDefined(c.config, "js"): "js"
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,7 @@ proc makeInstPair*(s: PSym, inst: PInstantiation): TInstantiationPair =
|
||||||
|
|
||||||
proc filename*(c: PContext): string =
|
proc filename*(c: PContext): string =
|
||||||
# the module's filename
|
# the module's filename
|
||||||
return toFilename(FileIndex c.module.position)
|
return toFilename(c.config, FileIndex c.module.position)
|
||||||
|
|
||||||
proc scopeDepth*(c: PContext): int {.inline.} =
|
proc scopeDepth*(c: PContext): int {.inline.} =
|
||||||
result = if c.currentScope != nil: c.currentScope.depthLevel
|
result = if c.currentScope != nil: c.currentScope.depthLevel
|
||||||
|
|
|
||||||
|
|
@ -1940,7 +1940,7 @@ proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
|
||||||
of mRunnableExamples:
|
of mRunnableExamples:
|
||||||
if c.config.cmd == cmdDoc and n.len >= 2 and n.lastSon.kind == nkStmtList:
|
if c.config.cmd == cmdDoc and n.len >= 2 and n.lastSon.kind == nkStmtList:
|
||||||
if sfMainModule in c.module.flags:
|
if sfMainModule in c.module.flags:
|
||||||
let inp = toFullPath(c.module.info)
|
let inp = toFullPath(c.config, c.module.info)
|
||||||
if c.runnableExamples == nil:
|
if c.runnableExamples == nil:
|
||||||
c.runnableExamples = newTree(nkStmtList,
|
c.runnableExamples = newTree(nkStmtList,
|
||||||
newTree(nkImportStmt, newStrNode(nkStrLit, expandFilename(inp))))
|
newTree(nkImportStmt, newStrNode(nkStrLit, expandFilename(inp))))
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ proc semInstantiationInfo(c: PContext, n: PNode): PNode =
|
||||||
let useFullPaths = expectIntLit(c, n.sons[2])
|
let useFullPaths = expectIntLit(c, n.sons[2])
|
||||||
let info = getInfoContext(idx)
|
let info = getInfoContext(idx)
|
||||||
var filename = newNodeIT(nkStrLit, n.info, getSysType(c.graph, n.info, tyString))
|
var filename = newNodeIT(nkStrLit, n.info, getSysType(c.graph, n.info, tyString))
|
||||||
filename.strVal = if useFullPaths != 0: info.toFullPath else: info.toFilename
|
filename.strVal = if useFullPaths != 0: toFullPath(c.config, info) else: toFilename(c.config, info)
|
||||||
var line = newNodeIT(nkIntLit, n.info, getSysType(c.graph, n.info, tyInt))
|
var line = newNodeIT(nkIntLit, n.info, getSysType(c.graph, n.info, tyInt))
|
||||||
line.intVal = toLinenumber(info)
|
line.intVal = toLinenumber(info)
|
||||||
var column = newNodeIT(nkIntLit, n.info, getSysType(c.graph, n.info, tyInt))
|
var column = newNodeIT(nkIntLit, n.info, getSysType(c.graph, n.info, tyInt))
|
||||||
|
|
|
||||||
|
|
@ -1056,7 +1056,7 @@ proc semAllTypeSections(c: PContext; n: PNode): PNode =
|
||||||
var f = checkModuleName(c.config, n.sons[i])
|
var f = checkModuleName(c.config, n.sons[i])
|
||||||
if f != InvalidFileIDX:
|
if f != InvalidFileIDX:
|
||||||
if containsOrIncl(c.includedFiles, f.int):
|
if containsOrIncl(c.includedFiles, f.int):
|
||||||
localError(c.config, n.info, errRecursiveDependencyX % f.toFilename)
|
localError(c.config, n.info, errRecursiveDependencyX % toFilename(c.config, f))
|
||||||
else:
|
else:
|
||||||
let code = gIncludeFile(c.graph, c.module, f, c.cache)
|
let code = gIncludeFile(c.graph, c.module, f, c.cache)
|
||||||
gatherStmts c, code, result
|
gatherStmts c, code, result
|
||||||
|
|
@ -1738,7 +1738,7 @@ proc evalInclude(c: PContext, n: PNode): PNode =
|
||||||
var f = checkModuleName(c.config, n.sons[i])
|
var f = checkModuleName(c.config, n.sons[i])
|
||||||
if f != InvalidFileIDX:
|
if f != InvalidFileIDX:
|
||||||
if containsOrIncl(c.includedFiles, f.int):
|
if containsOrIncl(c.includedFiles, f.int):
|
||||||
localError(c.config, n.info, errRecursiveDependencyX % f.toFilename)
|
localError(c.config, n.info, errRecursiveDependencyX % toFilename(c.config, f))
|
||||||
else:
|
else:
|
||||||
addSon(result, semStmt(c, gIncludeFile(c.graph, c.module, f, c.cache)))
|
addSon(result, semStmt(c, gIncludeFile(c.graph, c.module, f, c.cache)))
|
||||||
excl(c.includedFiles, f.int)
|
excl(c.includedFiles, f.int)
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,7 @@ proc symToSuggest(conf: ConfigRef; s: PSym, isLocal: bool, section: IdeCmd, info
|
||||||
when not defined(noDocgen):
|
when not defined(noDocgen):
|
||||||
result.doc = s.extractDocComment
|
result.doc = s.extractDocComment
|
||||||
let infox = if section in {ideUse, ideHighlight, ideOutline}: info else: s.info
|
let infox = if section in {ideUse, ideHighlight, ideOutline}: info else: s.info
|
||||||
result.filePath = toFullPath(infox)
|
result.filePath = toFullPath(conf, infox)
|
||||||
result.line = toLinenumber(infox)
|
result.line = toLinenumber(infox)
|
||||||
result.column = toColumn(infox)
|
result.column = toColumn(infox)
|
||||||
|
|
||||||
|
|
@ -342,7 +342,7 @@ proc suggestFieldAccess(c: PContext, n, field: PNode, outputs: var Suggestions)
|
||||||
when defined(nimsuggest):
|
when defined(nimsuggest):
|
||||||
if n.kind == nkSym and n.sym.kind == skError and suggestVersion == 0:
|
if n.kind == nkSym and n.sym.kind == skError and suggestVersion == 0:
|
||||||
# consider 'foo.|' where 'foo' is some not imported module.
|
# consider 'foo.|' where 'foo' is some not imported module.
|
||||||
let fullPath = findModule(c.config, n.sym.name.s, n.info.toFullPath)
|
let fullPath = findModule(c.config, n.sym.name.s, toFullPath(c.config, n.info))
|
||||||
if fullPath.len == 0:
|
if fullPath.len == 0:
|
||||||
# error: no known module name:
|
# error: no known module name:
|
||||||
typ = nil
|
typ = nil
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,7 @@ proc openParsers*(p: var TParsers, fileIdx: FileIndex, inputstream: PLLStream;
|
||||||
assert config != nil
|
assert config != nil
|
||||||
var s: PLLStream
|
var s: PLLStream
|
||||||
p.skin = skinStandard
|
p.skin = skinStandard
|
||||||
let filename = fileIdx.toFullPathConsiderDirty
|
let filename = toFullPathConsiderDirty(config, fileIdx)
|
||||||
var pipe = parsePipe(filename, inputstream, cache, config)
|
var pipe = parsePipe(filename, inputstream, cache, config)
|
||||||
p.config() = config
|
p.config() = config
|
||||||
if pipe != nil: s = evalPipe(p, pipe, filename, inputstream)
|
if pipe != nil: s = evalPipe(p, pipe, filename, inputstream)
|
||||||
|
|
@ -160,7 +160,7 @@ proc parseFile*(fileIdx: FileIndex; cache: IdentCache; config: ConfigRef): PNode
|
||||||
var
|
var
|
||||||
p: TParsers
|
p: TParsers
|
||||||
f: File
|
f: File
|
||||||
let filename = fileIdx.toFullPathConsiderDirty
|
let filename = toFullPathConsiderDirty(config, fileIdx)
|
||||||
if not open(f, filename):
|
if not open(f, filename):
|
||||||
rawMessage(config, errGenerated, "cannot open file: " & filename)
|
rawMessage(config, errGenerated, "cannot open file: " & filename)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ proc stackTraceAux(c: PCtx; x: PStackFrame; pc: int; recursionLimit=100) =
|
||||||
stackTraceAux(c, x.next, x.comesFrom, recursionLimit-1)
|
stackTraceAux(c, x.next, x.comesFrom, recursionLimit-1)
|
||||||
var info = c.debug[pc]
|
var info = c.debug[pc]
|
||||||
# we now use the same format as in system/except.nim
|
# we now use the same format as in system/except.nim
|
||||||
var s = substr(toFilename(info), 0)
|
var s = substr(toFilename(c.config, info), 0)
|
||||||
# this 'substr' prevents a strange corruption. XXX This needs to be
|
# this 'substr' prevents a strange corruption. XXX This needs to be
|
||||||
# investigated eventually but first attempts to fix it broke everything
|
# investigated eventually but first attempts to fix it broke everything
|
||||||
# see the araq-wip-fixed-writebarrier branch.
|
# see the araq-wip-fixed-writebarrier branch.
|
||||||
|
|
@ -1358,7 +1358,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
# c.debug[pc].line.int - countLines(regs[rb].strVal) ?
|
# c.debug[pc].line.int - countLines(regs[rb].strVal) ?
|
||||||
var error: string
|
var error: string
|
||||||
let ast = parseString(regs[rb].node.strVal, c.cache, c.config,
|
let ast = parseString(regs[rb].node.strVal, c.cache, c.config,
|
||||||
c.debug[pc].toFullPath, c.debug[pc].line.int,
|
toFullPath(c.config, c.debug[pc]), c.debug[pc].line.int,
|
||||||
proc (conf: ConfigRef; info: TLineInfo; msg: TMsgKind; arg: string) =
|
proc (conf: ConfigRef; info: TLineInfo; msg: TMsgKind; arg: string) =
|
||||||
if error.isNil and msg <= errMax:
|
if error.isNil and msg <= errMax:
|
||||||
error = formatMsg(conf, info, msg, arg))
|
error = formatMsg(conf, info, msg, arg))
|
||||||
|
|
@ -1373,7 +1373,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
decodeB(rkNode)
|
decodeB(rkNode)
|
||||||
var error: string
|
var error: string
|
||||||
let ast = parseString(regs[rb].node.strVal, c.cache, c.config,
|
let ast = parseString(regs[rb].node.strVal, c.cache, c.config,
|
||||||
c.debug[pc].toFullPath, c.debug[pc].line.int,
|
toFullPath(c.config, c.debug[pc]), c.debug[pc].line.int,
|
||||||
proc (conf: ConfigRef; info: TLineInfo; msg: TMsgKind; arg: string) =
|
proc (conf: ConfigRef; info: TLineInfo; msg: TMsgKind; arg: string) =
|
||||||
if error.isNil and msg <= errMax:
|
if error.isNil and msg <= errMax:
|
||||||
error = formatMsg(conf, info, msg, arg))
|
error = formatMsg(conf, info, msg, arg))
|
||||||
|
|
@ -1392,7 +1392,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
of opcNGetFile:
|
of opcNGetFile:
|
||||||
decodeB(rkNode)
|
decodeB(rkNode)
|
||||||
let n = regs[rb].node
|
let n = regs[rb].node
|
||||||
regs[ra].node = newStrNode(nkStrLit, n.info.toFilename)
|
regs[ra].node = newStrNode(nkStrLit, toFilename(c.config, n.info))
|
||||||
regs[ra].node.info = n.info
|
regs[ra].node.info = n.info
|
||||||
regs[ra].node.typ = n.typ
|
regs[ra].node.typ = n.typ
|
||||||
of opcNGetLine:
|
of opcNGetLine:
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import ast, types, msgs, os, streams, options, idents
|
||||||
|
|
||||||
proc opSlurp*(file: string, info: TLineInfo, module: PSym; conf: ConfigRef): string =
|
proc opSlurp*(file: string, info: TLineInfo, module: PSym; conf: ConfigRef): string =
|
||||||
try:
|
try:
|
||||||
var filename = parentDir(info.toFullPath) / file
|
var filename = parentDir(toFullPath(conf, info)) / file
|
||||||
if not fileExists(filename):
|
if not fileExists(filename):
|
||||||
filename = findFile(conf, file)
|
filename = findFile(conf, file)
|
||||||
result = readFile(filename)
|
result = readFile(filename)
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,8 @@ type
|
||||||
TGenFlag = enum gfAddrOf, gfFieldAccess
|
TGenFlag = enum gfAddrOf, gfFieldAccess
|
||||||
TGenFlags = set[TGenFlag]
|
TGenFlags = set[TGenFlag]
|
||||||
|
|
||||||
proc debugInfo(info: TLineInfo): string =
|
proc debugInfo(c: PCtx; info: TLineInfo): string =
|
||||||
result = info.toFilename.splitFile.name & ":" & $info.line
|
result = toFilename(c.config, info).splitFile.name & ":" & $info.line
|
||||||
|
|
||||||
proc codeListing(c: PCtx, result: var string, start=0; last = -1) =
|
proc codeListing(c: PCtx, result: var string, start=0; last = -1) =
|
||||||
# first iteration: compute all necessary labels:
|
# first iteration: compute all necessary labels:
|
||||||
|
|
@ -85,7 +85,7 @@ proc codeListing(c: PCtx, result: var string, start=0; last = -1) =
|
||||||
else:
|
else:
|
||||||
result.addf("\t$#\tr$#, $#", ($opc).substr(3), x.regA, x.regBx-wordExcess)
|
result.addf("\t$#\tr$#, $#", ($opc).substr(3), x.regA, x.regBx-wordExcess)
|
||||||
result.add("\t#")
|
result.add("\t#")
|
||||||
result.add(debugInfo(c.debug[i]))
|
result.add(debugInfo(c, c.debug[i]))
|
||||||
result.add("\n")
|
result.add("\n")
|
||||||
inc i
|
inc i
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,8 +74,8 @@ proc writelnToChannel(line: string) =
|
||||||
proc sugResultHook(s: Suggest) =
|
proc sugResultHook(s: Suggest) =
|
||||||
results.send(s)
|
results.send(s)
|
||||||
|
|
||||||
proc errorHook(info: TLineInfo; msg: string; sev: Severity) =
|
proc errorHook(conf: ConfigRef; info: TLineInfo; msg: string; sev: Severity) =
|
||||||
results.send(Suggest(section: ideChk, filePath: toFullPath(info),
|
results.send(Suggest(section: ideChk, filePath: toFullPath(conf, info),
|
||||||
line: toLinenumber(info), column: toColumn(info), doc: msg,
|
line: toLinenumber(info), column: toColumn(info), doc: msg,
|
||||||
forth: $sev))
|
forth: $sev))
|
||||||
|
|
||||||
|
|
@ -173,8 +173,8 @@ proc execute(cmd: IdeCmd, file, dirtyfile: string, line, col: int;
|
||||||
var isKnownFile = true
|
var isKnownFile = true
|
||||||
let dirtyIdx = fileInfoIdx(conf, file, isKnownFile)
|
let dirtyIdx = fileInfoIdx(conf, file, isKnownFile)
|
||||||
|
|
||||||
if dirtyfile.len != 0: msgs.setDirtyFile(dirtyIdx, dirtyfile)
|
if dirtyfile.len != 0: msgs.setDirtyFile(conf, dirtyIdx, dirtyfile)
|
||||||
else: msgs.setDirtyFile(dirtyIdx, nil)
|
else: msgs.setDirtyFile(conf, dirtyIdx, nil)
|
||||||
|
|
||||||
gTrackPos = newLineInfo(dirtyIdx, line, col)
|
gTrackPos = newLineInfo(dirtyIdx, line, col)
|
||||||
gTrackPosAttached = false
|
gTrackPosAttached = false
|
||||||
|
|
@ -432,7 +432,7 @@ proc execCmd(cmd: string; graph: ModuleGraph; cache: IdentCache; cachedMsgs: Cac
|
||||||
results.send(Suggest(section: ideKnown, quality: ord(fileInfoKnown(conf, orig))))
|
results.send(Suggest(section: ideKnown, quality: ord(fileInfoKnown(conf, orig))))
|
||||||
else:
|
else:
|
||||||
if conf.ideCmd == ideChk:
|
if conf.ideCmd == ideChk:
|
||||||
for cm in cachedMsgs: errorHook(cm.info, cm.msg, cm.sev)
|
for cm in cachedMsgs: errorHook(conf, cm.info, cm.msg, cm.sev)
|
||||||
execute(conf.ideCmd, orig, dirtyfile, line, col, graph, cache)
|
execute(conf.ideCmd, orig, dirtyfile, line, col, graph, cache)
|
||||||
sentinel()
|
sentinel()
|
||||||
|
|
||||||
|
|
@ -477,7 +477,7 @@ proc mainThread(graph: ModuleGraph; cache: IdentCache) =
|
||||||
conf.ideCmd = ideChk
|
conf.ideCmd = ideChk
|
||||||
msgs.writelnHook = proc (s: string) = discard
|
msgs.writelnHook = proc (s: string) = discard
|
||||||
cachedMsgs.setLen 0
|
cachedMsgs.setLen 0
|
||||||
msgs.structuredErrorHook = proc (info: TLineInfo; msg: string; sev: Severity) =
|
msgs.structuredErrorHook = proc (conf: ConfigRef; info: TLineInfo; msg: string; sev: Severity) =
|
||||||
cachedMsgs.add(CachedMsg(info: info, msg: msg, sev: sev))
|
cachedMsgs.add(CachedMsg(info: info, msg: msg, sev: sev))
|
||||||
suggestionResultHook = proc (s: Suggest) = discard
|
suggestionResultHook = proc (s: Suggest) = discard
|
||||||
recompileFullProject(graph, cache)
|
recompileFullProject(graph, cache)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue