mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 22:10:33 +00:00
nimrod dump can now produce a machine readable json report
The data in the report includes necessary information for starting the compiler service and setting up the project paths in the IDE. the default verbosity of 1 is now set in the compiler code to fix an issue with verbosity being temporary set to 1 during config parsing even when it's explicitly overridden on the command-line. compiler/lexbase was temporary renamed to nimlexbase as a work-around for a codegen naming conflict with lib/pure/lexbase resulting in linking errors (further investigation needed).
This commit is contained in:
@@ -60,7 +60,7 @@ iterator chosen(packages: PStringTable): string =
|
||||
|
||||
proc addBabelPath(p: string, info: TLineInfo) =
|
||||
if not contains(options.searchPaths, p):
|
||||
Message(info, hintPath, p)
|
||||
if gVerbosity >= 1: Message(info, hintPath, p)
|
||||
lists.PrependStr(options.lazyPaths, p)
|
||||
|
||||
proc addPathWithNimFiles(p: string, info: TLineInfo) =
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
## is needed for incremental compilation.
|
||||
|
||||
import
|
||||
ast, astalgo, ropes, options, strutils, lexbase, msgs, cgendata, rodutils,
|
||||
ast, astalgo, ropes, options, strutils, nimlexbase, msgs, cgendata, rodutils,
|
||||
intsets, platform, llstream
|
||||
|
||||
# Careful! Section marks need to contain a tabulator so that they cannot
|
||||
@@ -119,8 +119,8 @@ proc skipWhite(L: var TBaseLexer) =
|
||||
var pos = L.bufpos
|
||||
while true:
|
||||
case ^pos
|
||||
of CR: pos = lexbase.HandleCR(L, pos)
|
||||
of LF: pos = lexbase.HandleLF(L, pos)
|
||||
of CR: pos = nimlexbase.HandleCR(L, pos)
|
||||
of LF: pos = nimlexbase.HandleLF(L, pos)
|
||||
of ' ': inc pos
|
||||
else: break
|
||||
L.bufpos = pos
|
||||
@@ -129,8 +129,8 @@ proc skipUntilCmd(L: var TBaseLexer) =
|
||||
var pos = L.bufpos
|
||||
while true:
|
||||
case ^pos
|
||||
of CR: pos = lexbase.HandleCR(L, pos)
|
||||
of LF: pos = lexbase.HandleLF(L, pos)
|
||||
of CR: pos = nimlexbase.HandleCR(L, pos)
|
||||
of LF: pos = nimlexbase.HandleLF(L, pos)
|
||||
of '\0': break
|
||||
of '/':
|
||||
if ^(pos+1) == '*' and ^(pos+2) == '\t':
|
||||
@@ -153,11 +153,11 @@ when false:
|
||||
while true:
|
||||
case buf[pos]
|
||||
of CR:
|
||||
pos = lexbase.HandleCR(L, pos)
|
||||
pos = nimlexbase.HandleCR(L, pos)
|
||||
buf = L.buf
|
||||
result.data.add(tnl)
|
||||
of LF:
|
||||
pos = lexbase.HandleLF(L, pos)
|
||||
pos = nimlexbase.HandleLF(L, pos)
|
||||
buf = L.buf
|
||||
result.data.add(tnl)
|
||||
of '\0':
|
||||
@@ -179,11 +179,11 @@ proc readVerbatimSection(L: var TBaseLexer): PRope =
|
||||
while true:
|
||||
case buf[pos]
|
||||
of CR:
|
||||
pos = lexbase.HandleCR(L, pos)
|
||||
pos = nimlexbase.HandleCR(L, pos)
|
||||
buf = L.buf
|
||||
r.add(tnl)
|
||||
of LF:
|
||||
pos = lexbase.HandleLF(L, pos)
|
||||
pos = nimlexbase.HandleLF(L, pos)
|
||||
buf = L.buf
|
||||
r.add(tnl)
|
||||
of '\0':
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
# This module handles the conditional symbols.
|
||||
|
||||
import
|
||||
ast, astalgo, msgs, hashes, platform, strutils, idents
|
||||
ast, astalgo, hashes, platform, strutils, idents
|
||||
|
||||
var gSymbols*: TStrTable
|
||||
|
||||
@@ -35,14 +35,12 @@ proc isDefined*(symbol: PIdent): bool =
|
||||
proc isDefined*(symbol: string): bool =
|
||||
result = isDefined(getIdent(symbol))
|
||||
|
||||
proc ListSymbols*() =
|
||||
iterator definedSymbolNames*: string =
|
||||
var it: TTabIter
|
||||
var s = InitTabIter(it, gSymbols)
|
||||
OutWriteln("-- List of currently defined symbols --")
|
||||
while s != nil:
|
||||
if s.position == 1: OutWriteln(s.name.s)
|
||||
while s != nil:
|
||||
if s.position == 1: yield s.name.s
|
||||
s = nextIter(it, gSymbols)
|
||||
OutWriteln("-- End of list --")
|
||||
|
||||
proc countDefinedSymbols*(): int =
|
||||
var it: TTabIter
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
# DOS or Macintosh text files, even when it is not the native format.
|
||||
|
||||
import
|
||||
hashes, options, msgs, strutils, platform, idents, lexbase, llstream,
|
||||
hashes, options, msgs, strutils, platform, idents, nimlexbase, llstream,
|
||||
wordrecg
|
||||
|
||||
const
|
||||
@@ -530,10 +530,10 @@ proc HandleCRLF(L: var TLexer, pos: int): int =
|
||||
case L.buf[pos]
|
||||
of CR:
|
||||
registerLine()
|
||||
result = lexbase.HandleCR(L, pos)
|
||||
result = nimlexbase.HandleCR(L, pos)
|
||||
of LF:
|
||||
registerLine()
|
||||
result = lexbase.HandleLF(L, pos)
|
||||
result = nimlexbase.HandleLF(L, pos)
|
||||
else: result = pos
|
||||
|
||||
proc getString(L: var TLexer, tok: var TToken, rawMode: bool) =
|
||||
@@ -559,7 +559,7 @@ proc getString(L: var TLexer, tok: var TToken, rawMode: bool) =
|
||||
pos = HandleCRLF(L, pos)
|
||||
buf = L.buf
|
||||
add(tok.literal, tnl)
|
||||
of lexbase.EndOfFile:
|
||||
of nimlexbase.EndOfFile:
|
||||
var line2 = L.linenumber
|
||||
L.LineNumber = line
|
||||
lexMessagePos(L, errClosingTripleQuoteExpected, L.lineStart)
|
||||
@@ -581,7 +581,7 @@ proc getString(L: var TLexer, tok: var TToken, rawMode: bool) =
|
||||
else:
|
||||
inc(pos) # skip '"'
|
||||
break
|
||||
elif c in {CR, LF, lexbase.EndOfFile}:
|
||||
elif c in {CR, LF, nimlexbase.EndOfFile}:
|
||||
lexMessage(L, errClosingQuoteExpected)
|
||||
break
|
||||
elif (c == '\\') and not rawMode:
|
||||
@@ -680,7 +680,7 @@ proc scanComment(L: var TLexer, tok: var TToken) =
|
||||
var col = getColNumber(L, pos)
|
||||
while true:
|
||||
var lastBackslash = -1
|
||||
while buf[pos] notin {CR, LF, lexbase.EndOfFile}:
|
||||
while buf[pos] notin {CR, LF, nimlexbase.EndOfFile}:
|
||||
if buf[pos] == '\\': lastBackslash = pos+1
|
||||
add(tok.literal, buf[pos])
|
||||
inc(pos)
|
||||
@@ -688,7 +688,7 @@ proc scanComment(L: var TLexer, tok: var TToken) =
|
||||
# a backslash is a continuation character if only followed by spaces
|
||||
# plus a newline:
|
||||
while buf[lastBackslash] == ' ': inc(lastBackslash)
|
||||
if buf[lastBackslash] notin {CR, LF, lexbase.EndOfFile}:
|
||||
if buf[lastBackslash] notin {CR, LF, nimlexbase.EndOfFile}:
|
||||
# false positive:
|
||||
lastBackslash = -1
|
||||
|
||||
@@ -841,7 +841,7 @@ proc rawGetTok(L: var TLexer, tok: var TToken) =
|
||||
else:
|
||||
if c in OpChars:
|
||||
getOperator(L, tok)
|
||||
elif c == lexbase.EndOfFile:
|
||||
elif c == nimlexbase.EndOfFile:
|
||||
tok.toktype = tkEof
|
||||
else:
|
||||
tok.literal = c & ""
|
||||
|
||||
@@ -14,7 +14,7 @@ import
|
||||
llstream, strutils, ast, astalgo, lexer, syntaxes, renderer, options, msgs,
|
||||
os, lists, condsyms, rodread, rodwrite, ropes, trees, times,
|
||||
wordrecg, sem, semdata, idents, passes, docgen, extccomp,
|
||||
cgen, jsgen, cgendata,
|
||||
cgen, jsgen, cgendata, json, nversion,
|
||||
platform, nimconf, importer, passaux, depends, evals, types, idgen,
|
||||
tables, docgen2, service, magicsys, parser, crc, ccgutils
|
||||
|
||||
@@ -392,6 +392,15 @@ proc wantMainModule =
|
||||
|
||||
gProjectMainIdx = addFileExt(gProjectFull, nimExt).fileInfoIdx
|
||||
|
||||
proc requireMainModuleOption =
|
||||
if optMainModule.len == 0:
|
||||
Fatal(gCmdLineInfo, errMainModuleMustBeSpecified)
|
||||
else:
|
||||
gProjectName = optMainModule
|
||||
gProjectFull = gProjectPath / gProjectName
|
||||
|
||||
gProjectMainIdx = addFileExt(gProjectFull, nimExt).fileInfoIdx
|
||||
|
||||
proc resetMemory =
|
||||
resetCompilationLists()
|
||||
ccgutils.resetCaches()
|
||||
@@ -529,9 +538,30 @@ proc MainCommand =
|
||||
wantMainModule()
|
||||
CommandGenDepend()
|
||||
of "dump":
|
||||
gCmd = cmdDump
|
||||
condsyms.ListSymbols()
|
||||
for it in iterSearchPath(searchPaths): MsgWriteln(it)
|
||||
gcmd = cmdDump
|
||||
if getconfigvar("dump.format") == "json":
|
||||
requireMainModuleOption()
|
||||
|
||||
var definedSymbols = newJArray()
|
||||
for s in definedSymbolNames(): definedSymbols.elems.add(%s)
|
||||
|
||||
var libpaths = newJArray()
|
||||
for dir in itersearchpath(searchpaths): libpaths.elems.add(%dir)
|
||||
|
||||
var dumpdata = % [
|
||||
(key: "version", val: %VersionAsString),
|
||||
(key: "project_path", val: %gProjectFull),
|
||||
(key: "defined_symbols", val: definedSymbols),
|
||||
(key: "lib_paths", val: libpaths)
|
||||
]
|
||||
|
||||
outWriteLn($dumpdata)
|
||||
else:
|
||||
outWriteLn("-- list of currently defined symbols --")
|
||||
for s in definedSymbolNames(): outWriteLn(s)
|
||||
outWriteLn("-- end of list --")
|
||||
|
||||
for it in iterSearchPath(searchpaths): msgWriteLn(it)
|
||||
of "check":
|
||||
gCmd = cmdCheck
|
||||
wantMainModule()
|
||||
@@ -568,7 +598,7 @@ proc MainCommand =
|
||||
else:
|
||||
rawMessage(errInvalidCommandX, command)
|
||||
|
||||
if msgs.gErrorCounter == 0 and gCmd notin {cmdInterpret, cmdRun}:
|
||||
if msgs.gErrorCounter == 0 and gCmd notin {cmdInterpret, cmdRun, cmdDump}:
|
||||
rawMessage(hintSuccessX, [$gLinesCompiled,
|
||||
formatFloat(epochTime() - gLastCmdTime, ffDecimal, 3),
|
||||
formatSize(getTotalMem())])
|
||||
|
||||
@@ -83,7 +83,9 @@ type
|
||||
errInvalidCommandX, errXOnlyAtModuleScope,
|
||||
errXNeedsParamObjectType,
|
||||
errTemplateInstantiationTooNested, errInstantiationFrom,
|
||||
errInvalidIndexValueForTuple, errCommandExpectsFilename, errXExpected,
|
||||
errInvalidIndexValueForTuple, errCommandExpectsFilename,
|
||||
errMainModuleMustBeSpecified,
|
||||
errXExpected,
|
||||
errInvalidSectionStart, errGridTableNotImplemented, errGeneralParseError,
|
||||
errNewSectionExpected, errWhitespaceExpected, errXisNoValidIndexFile,
|
||||
errCannotRenderX, errVarVarTypeNotAllowed, errInstantiateXExplicitely,
|
||||
@@ -301,6 +303,7 @@ const
|
||||
errInstantiationFrom: "instantiation from here",
|
||||
errInvalidIndexValueForTuple: "invalid index value for tuple subscript",
|
||||
errCommandExpectsFilename: "command expects a filename argument",
|
||||
errMainModuleMustBeSpecified: "please, specify a main module in the project configuration file",
|
||||
errXExpected: "\'$1\' expected",
|
||||
errInvalidSectionStart: "invalid section start",
|
||||
errGridTableNotImplemented: "grid table is not implemented",
|
||||
|
||||
@@ -99,14 +99,14 @@ var
|
||||
searchPaths*, lazyPaths*: TLinkedList
|
||||
outFile*: string = ""
|
||||
headerFile*: string = ""
|
||||
gVerbosity*: int # how verbose the compiler is
|
||||
gVerbosity* = 1 # how verbose the compiler is
|
||||
gNumberOfProcessors*: int # number of processors
|
||||
gWholeProject*: bool # for 'doc2': output any dependency
|
||||
gEvalExpr* = "" # expression for idetools --eval
|
||||
gLastCmdTime*: float # when caas is enabled, we measure each command
|
||||
gListFullPaths*: bool
|
||||
isServing*: bool = false
|
||||
|
||||
|
||||
proc importantComments*(): bool {.inline.} = gCmd in {cmdDoc, cmdIdeTools}
|
||||
proc usesNativeGC*(): bool {.inline.} = gSelectedGC >= gcRefc
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
# standard library.
|
||||
|
||||
import
|
||||
llstream, nhashes, strutils, lexbase
|
||||
llstream, nhashes, strutils, nimlexbase
|
||||
|
||||
type
|
||||
TCfgEventKind* = enum
|
||||
|
||||
@@ -55,7 +55,6 @@ path="$lib/pure/unidecode"
|
||||
@end
|
||||
|
||||
# additional options always passed to the compiler:
|
||||
--verbosity: "1"
|
||||
--parallel_build: "0" # 0 to auto-detect number of processors
|
||||
|
||||
hint[LineTooLong]=off
|
||||
|
||||
Reference in New Issue
Block a user