remove more global variables in the Nim compiler
This commit is contained in:
parent
12bd1c494c
commit
669a564492
77 changed files with 679 additions and 679 deletions
|
|
@ -17,7 +17,7 @@ import compiler / [options, commands, modules, sem,
|
|||
passes, passaux, msgs, nimconf,
|
||||
extccomp, condsyms,
|
||||
sigmatch, ast, scriptconfig,
|
||||
idents, modulegraphs, vm, prefixmatches]
|
||||
idents, modulegraphs, vm, prefixmatches, lineinfos]
|
||||
|
||||
when defined(windows):
|
||||
import winlean
|
||||
|
|
@ -109,7 +109,7 @@ proc sexp(s: Suggest): SexpNode =
|
|||
let qp = if s.qualifiedPath.isNil: @[] else: s.qualifiedPath
|
||||
result = convertSexp([
|
||||
s.section,
|
||||
s.symkind,
|
||||
TSymKind s.symkind,
|
||||
qp.map(newSString),
|
||||
s.filePath,
|
||||
s.forth,
|
||||
|
|
@ -141,20 +141,19 @@ proc listEpc(): SexpNode =
|
|||
methodDesc.add(docstring)
|
||||
result.add(methodDesc)
|
||||
|
||||
proc findNode(n: PNode): PSym =
|
||||
proc findNode(n: PNode; trackPos: TLineInfo): PSym =
|
||||
#echo "checking node ", n.info
|
||||
if n.kind == nkSym:
|
||||
if isTracked(n.info, n.sym.name.s.len): return n.sym
|
||||
if isTracked(n.info, trackPos, n.sym.name.s.len): return n.sym
|
||||
else:
|
||||
for i in 0 ..< safeLen(n):
|
||||
let res = n.sons[i].findNode
|
||||
let res = findNode(n[i], trackPos)
|
||||
if res != nil: return res
|
||||
|
||||
proc symFromInfo(graph: ModuleGraph; gTrackPos: TLineInfo): PSym =
|
||||
let m = graph.getModule(gTrackPos.fileIndex)
|
||||
#echo m.isNil, " I knew it ", gTrackPos.fileIndex
|
||||
proc symFromInfo(graph: ModuleGraph; trackPos: TLineInfo): PSym =
|
||||
let m = graph.getModule(trackPos.fileIndex)
|
||||
if m != nil and m.ast != nil:
|
||||
result = m.ast.findNode
|
||||
result = findNode(m.ast, trackPos)
|
||||
|
||||
proc execute(cmd: IdeCmd, file, dirtyfile: string, line, col: int;
|
||||
graph: ModuleGraph; cache: IdentCache) =
|
||||
|
|
@ -163,12 +162,12 @@ proc execute(cmd: IdeCmd, file, dirtyfile: string, line, col: int;
|
|||
"[" & $line & ":" & $col & "]")
|
||||
conf.ideCmd = cmd
|
||||
if cmd == ideChk:
|
||||
msgs.structuredErrorHook = errorHook
|
||||
msgs.writelnHook = myLog
|
||||
conf.structuredErrorHook = errorHook
|
||||
conf.writelnHook = myLog
|
||||
else:
|
||||
msgs.structuredErrorHook = nil
|
||||
msgs.writelnHook = myLog
|
||||
if cmd == ideUse and suggestVersion != 0:
|
||||
conf.structuredErrorHook = nil
|
||||
conf.writelnHook = myLog
|
||||
if cmd == ideUse and conf.suggestVersion != 0:
|
||||
graph.resetAllModules()
|
||||
var isKnownFile = true
|
||||
let dirtyIdx = fileInfoIdx(conf, file, isKnownFile)
|
||||
|
|
@ -176,14 +175,14 @@ proc execute(cmd: IdeCmd, file, dirtyfile: string, line, col: int;
|
|||
if dirtyfile.len != 0: msgs.setDirtyFile(conf, dirtyIdx, dirtyfile)
|
||||
else: msgs.setDirtyFile(conf, dirtyIdx, nil)
|
||||
|
||||
gTrackPos = newLineInfo(dirtyIdx, line, col)
|
||||
gTrackPosAttached = false
|
||||
conf.m.trackPos = newLineInfo(dirtyIdx, line, col)
|
||||
conf.m.trackPosAttached = false
|
||||
conf.errorCounter = 0
|
||||
if suggestVersion == 1:
|
||||
if conf.suggestVersion == 1:
|
||||
graph.usageSym = nil
|
||||
if not isKnownFile:
|
||||
graph.compileProject(cache)
|
||||
if suggestVersion == 0 and conf.ideCmd in {ideUse, ideDus} and
|
||||
if conf.suggestVersion == 0 and conf.ideCmd in {ideUse, ideDus} and
|
||||
dirtyfile.len == 0:
|
||||
discard "no need to recompile anything"
|
||||
else:
|
||||
|
|
@ -193,11 +192,11 @@ proc execute(cmd: IdeCmd, file, dirtyfile: string, line, col: int;
|
|||
if conf.ideCmd != ideMod:
|
||||
graph.compileProject(cache, modIdx)
|
||||
if conf.ideCmd in {ideUse, ideDus}:
|
||||
let u = if suggestVersion != 1: graph.symFromInfo(gTrackPos) else: graph.usageSym
|
||||
let u = if conf.suggestVersion != 1: graph.symFromInfo(conf.m.trackPos) else: graph.usageSym
|
||||
if u != nil:
|
||||
listUsages(conf, u)
|
||||
else:
|
||||
localError(conf, gTrackPos, "found no symbol at this position " & $gTrackPos)
|
||||
localError(conf, conf.m.trackPos, "found no symbol at this position " & (conf $ conf.m.trackPos))
|
||||
|
||||
proc executeEpc(cmd: IdeCmd, args: SexpNode;
|
||||
graph: ModuleGraph; cache: IdentCache) =
|
||||
|
|
@ -457,16 +456,16 @@ proc mainThread(graph: ModuleGraph; cache: IdentCache) =
|
|||
else:
|
||||
writelnToChannel(line)
|
||||
|
||||
msgs.writelnHook = wrHook
|
||||
suggestionResultHook = sugResultHook
|
||||
conf.writelnHook = wrHook
|
||||
conf.suggestionResultHook = sugResultHook
|
||||
graph.doStopCompile = proc (): bool = requests.peek() > 0
|
||||
var idle = 0
|
||||
var cachedMsgs: CachedMsgs = @[]
|
||||
while true:
|
||||
let (hasData, req) = requests.tryRecv()
|
||||
if hasData:
|
||||
msgs.writelnHook = wrHook
|
||||
suggestionResultHook = sugResultHook
|
||||
conf.writelnHook = wrHook
|
||||
conf.suggestionResultHook = sugResultHook
|
||||
execCmd(req, graph, cache, cachedMsgs)
|
||||
idle = 0
|
||||
else:
|
||||
|
|
@ -475,11 +474,11 @@ proc mainThread(graph: ModuleGraph; cache: IdentCache) =
|
|||
if idle == 20 and gRefresh:
|
||||
# we use some nimsuggest activity to enable a lazy recompile:
|
||||
conf.ideCmd = ideChk
|
||||
msgs.writelnHook = proc (s: string) = discard
|
||||
conf.writelnHook = proc (s: string) = discard
|
||||
cachedMsgs.setLen 0
|
||||
msgs.structuredErrorHook = proc (conf: ConfigRef; info: TLineInfo; msg: string; sev: Severity) =
|
||||
conf.structuredErrorHook = proc (conf: ConfigRef; info: TLineInfo; msg: string; sev: Severity) =
|
||||
cachedMsgs.add(CachedMsg(info: info, msg: msg, sev: sev))
|
||||
suggestionResultHook = proc (s: Suggest) = discard
|
||||
conf.suggestionResultHook = proc (s: Suggest) = discard
|
||||
recompileFullProject(graph, cache)
|
||||
|
||||
var
|
||||
|
|
@ -502,8 +501,8 @@ proc mainCommand(graph: ModuleGraph; cache: IdentCache) =
|
|||
# do not stop after the first error:
|
||||
conf.errorMax = high(int)
|
||||
# do not print errors, but log them
|
||||
msgs.writelnHook = proc (s: string) = log(s)
|
||||
msgs.structuredErrorHook = nil
|
||||
conf.writelnHook = proc (s: string) = log(s)
|
||||
conf.structuredErrorHook = nil
|
||||
|
||||
# compile the project before showing any input so that we already
|
||||
# can answer questions right away:
|
||||
|
|
@ -555,8 +554,8 @@ proc processCmdLine*(pass: TCmdLinePass, cmd: string; conf: ConfigRef) =
|
|||
gMode = mepc
|
||||
conf.verbosity = 0 # Port number gotta be first.
|
||||
of "debug": incl(conf.globalOptions, optIdeDebug)
|
||||
of "v2": suggestVersion = 0
|
||||
of "v1": suggestVersion = 1
|
||||
of "v2": conf.suggestVersion = 0
|
||||
of "v1": conf.suggestVersion = 1
|
||||
of "tester":
|
||||
gMode = mstdin
|
||||
gEmitEof = true
|
||||
|
|
@ -568,7 +567,7 @@ proc processCmdLine*(pass: TCmdLinePass, cmd: string; conf: ConfigRef) =
|
|||
else:
|
||||
gRefresh = true
|
||||
of "maxresults":
|
||||
suggestMaxResults = parseInt(p.val)
|
||||
conf.suggestMaxResults = parseInt(p.val)
|
||||
else: processSwitch(pass, p, conf)
|
||||
of cmdArgument:
|
||||
let a = unixToNativePath(p.key)
|
||||
|
|
@ -589,7 +588,7 @@ proc handleCmdLine(cache: IdentCache; conf: ConfigRef) =
|
|||
else:
|
||||
processCmdLine(passCmd1, "", conf)
|
||||
if gMode != mstdin:
|
||||
msgs.writelnHook = proc (msg: string) = discard
|
||||
conf.writelnHook = proc (msg: string) = discard
|
||||
if conf.projectName != "":
|
||||
try:
|
||||
conf.projectFull = canonicalizePath(conf, conf.projectName)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue