more refactoring

This commit is contained in:
Andreas Rumpf 2018-05-27 15:22:17 +02:00
commit 18a3833d60
11 changed files with 36 additions and 33 deletions

View file

@ -998,8 +998,8 @@ const
skMethod, skConverter} skMethod, skConverter}
var ggDebug* {.deprecated.}: bool ## convenience switch for trying out things var ggDebug* {.deprecated.}: bool ## convenience switch for trying out things
var #var
gMainPackageId*: int # gMainPackageId*: int
proc isCallExpr*(n: PNode): bool = proc isCallExpr*(n: PNode): bool =
result = n.kind in nkCallKinds result = n.kind in nkCallKinds

View file

@ -25,7 +25,7 @@ template closeImpl(body: untyped) {.dirty.} =
var g = PGen(p) var g = PGen(p)
let useWarning = sfMainModule notin g.module.flags let useWarning = sfMainModule notin g.module.flags
#echo g.module.name.s, " ", g.module.owner.id, " ", gMainPackageId #echo g.module.name.s, " ", g.module.owner.id, " ", gMainPackageId
if (g.module.owner.id == gMainPackageId and optWholeProject in g.doc.conf.globalOptions) or if (g.module.owner.id == g.doc.conf.mainPackageId and optWholeProject in g.doc.conf.globalOptions) or
sfMainModule in g.module.flags: sfMainModule in g.module.flags:
body body
try: try:

View file

@ -15,7 +15,7 @@ import
wordrecg, sem, semdata, idents, passes, docgen, extccomp, wordrecg, sem, semdata, idents, passes, docgen, extccomp,
cgen, jsgen, json, nversion, cgen, jsgen, json, nversion,
platform, nimconf, importer, passaux, depends, vm, vmdef, types, idgen, platform, nimconf, importer, passaux, depends, vm, vmdef, types, idgen,
docgen2, service, parser, modules, ccgutils, sigmatch, ropes, docgen2, parser, modules, ccgutils, sigmatch, ropes,
modulegraphs, tables, rod, lineinfos modulegraphs, tables, rod, lineinfos
from magicsys import resetSysTypes from magicsys import resetSysTypes

View file

@ -65,7 +65,7 @@ proc compileModule*(graph: ModuleGraph; fileIdx: FileIndex; cache: IdentCache, f
var rd: PRodReader var rd: PRodReader
result.flags = result.flags + flags result.flags = result.flags + flags
if sfMainModule in result.flags: if sfMainModule in result.flags:
gMainPackageId = result.owner.id graph.config.mainPackageId = result.owner.id
when false: when false:
if conf.cmd in {cmdCompileToC, cmdCompileToCpp, cmdCheck, cmdIdeTools}: if conf.cmd in {cmdCompileToC, cmdCompileToCpp, cmdCheck, cmdIdeTools}:
@ -107,7 +107,7 @@ proc importModule*(graph: ModuleGraph; s: PSym, fileIdx: FileIndex;
# localError(result.info, errAttemptToRedefine, result.name.s) # localError(result.info, errAttemptToRedefine, result.name.s)
# restore the notes for outer module: # restore the notes for outer module:
graph.config.notes = graph.config.notes =
if s.owner.id == gMainPackageId: graph.config.mainPackageNotes if s.owner.id == graph.config.mainPackageId: graph.config.mainPackageNotes
else: graph.config.foreignPackageNotes else: graph.config.foreignPackageNotes
proc includeModule*(graph: ModuleGraph; s: PSym, fileIdx: FileIndex; proc includeModule*(graph: ModuleGraph; s: PSym, fileIdx: FileIndex;

View file

@ -20,7 +20,7 @@ when defined(i386) and defined(windows) and defined(vcc):
import import
commands, lexer, condsyms, options, msgs, nversion, nimconf, ropes, commands, lexer, condsyms, options, msgs, nversion, nimconf, ropes,
extccomp, strutils, os, osproc, platform, main, parseopt, service, extccomp, strutils, os, osproc, platform, main, parseopt,
nodejs, scriptconfig, idents, modulegraphs, lineinfos nodejs, scriptconfig, idents, modulegraphs, lineinfos
when hasTinyCBackend: when hasTinyCBackend:
@ -37,6 +37,25 @@ proc prependCurDir(f: string): string =
else: else:
result = f result = f
proc processCmdLine(pass: TCmdLinePass, cmd: string; config: ConfigRef) =
var p = parseopt.initOptParser(cmd)
var argsCount = 0
while true:
parseopt.next(p)
case p.kind
of cmdEnd: break
of cmdLongoption, cmdShortOption:
if p.key == " ":
p.key = "-"
if processArgument(pass, p, argsCount, config): break
else:
processSwitch(pass, p, config)
of cmdArgument:
if processArgument(pass, p, argsCount, config): break
if pass == passCmd2:
if optRun notin config.globalOptions and config.arguments.len > 0 and config.command.normalize != "run":
rawMessage(config, errGenerated, errArgsNeedRunOption)
proc handleCmdLine(cache: IdentCache; conf: ConfigRef) = proc handleCmdLine(cache: IdentCache; conf: ConfigRef) =
condsyms.initDefines(conf.symbols) condsyms.initDefines(conf.symbols)
if paramCount() == 0: if paramCount() == 0:

View file

@ -186,6 +186,7 @@ type
foreignPackageNotes*: TNoteKinds foreignPackageNotes*: TNoteKinds
notes*: TNoteKinds notes*: TNoteKinds
mainPackageNotes*: TNoteKinds mainPackageNotes*: TNoteKinds
mainPackageId*: int
errorCounter*: int errorCounter*: int
hintCounter*: int hintCounter*: int
warnCounter*: int warnCounter*: int

View file

@ -133,7 +133,7 @@ proc rawSkipComment(p: var TParser, node: PNode) =
if node.comment == nil: node.comment = "" if node.comment == nil: node.comment = ""
when defined(nimpretty): when defined(nimpretty):
if p.tok.commentOffsetB > p.tok.commentOffsetA: if p.tok.commentOffsetB > p.tok.commentOffsetA:
add node.comment, fileSection(p.lex.fileIdx, p.tok.commentOffsetA, p.tok.commentOffsetB) add node.comment, fileSection(p.lex.config, p.lex.fileIdx, p.tok.commentOffsetA, p.tok.commentOffsetB)
else: else:
add node.comment, p.tok.literal add node.comment, p.tok.literal
else: else:

View file

@ -330,14 +330,15 @@ proc ulitAux(g: TSrcGen; n: PNode, x: BiggestInt, size: int): string =
proc atom(g: TSrcGen; n: PNode): string = proc atom(g: TSrcGen; n: PNode): string =
when defined(nimpretty): when defined(nimpretty):
doAssert g.config != nil, "g.config not initialized!"
let comment = if n.info.commentOffsetA < n.info.commentOffsetB: let comment = if n.info.commentOffsetA < n.info.commentOffsetB:
" " & fileSection(g.fid, n.info.commentOffsetA, n.info.commentOffsetB) " " & fileSection(g.config, g.fid, n.info.commentOffsetA, n.info.commentOffsetB)
else: else:
"" ""
if n.info.offsetA <= n.info.offsetB: if n.info.offsetA <= n.info.offsetB:
# for some constructed tokens this can not be the case and we're better # for some constructed tokens this can not be the case and we're better
# off to not mess with the offset then. # off to not mess with the offset then.
return fileSection(g.fid, n.info.offsetA, n.info.offsetB) & comment return fileSection(g.config, g.fid, n.info.offsetA, n.info.offsetB) & comment
var f: float32 var f: float32
case n.kind case n.kind
of nkEmpty: result = "" of nkEmpty: result = ""

View file

@ -505,7 +505,7 @@ proc myOpen(graph: ModuleGraph; module: PSym; cache: IdentCache): PPassContext =
graph.systemModule = module graph.systemModule = module
c.topLevelScope = openScope(c) c.topLevelScope = openScope(c)
# don't be verbose unless the module belongs to the main package: # don't be verbose unless the module belongs to the main package:
if module.owner.id == gMainPackageId: if module.owner.id == graph.config.mainPackageId:
graph.config.notes = graph.config.mainPackageNotes graph.config.notes = graph.config.mainPackageNotes
else: else:
if graph.config.mainPackageNotes == {}: graph.config.mainPackageNotes = graph.config.notes if graph.config.mainPackageNotes == {}: graph.config.mainPackageNotes = graph.config.notes

View file

@ -26,25 +26,6 @@ var
# in caas mode, the list of defines and options will be given at start-up? # in caas mode, the list of defines and options will be given at start-up?
# it's enough to check that the previous compilation command is the same? # it's enough to check that the previous compilation command is the same?
proc processCmdLine*(pass: TCmdLinePass, cmd: string; config: ConfigRef) =
var p = parseopt.initOptParser(cmd)
var argsCount = 0
while true:
parseopt.next(p)
case p.kind
of cmdEnd: break
of cmdLongoption, cmdShortOption:
if p.key == " ":
p.key = "-"
if processArgument(pass, p, argsCount, config): break
else:
processSwitch(pass, p, config)
of cmdArgument:
if processArgument(pass, p, argsCount, config): break
if pass == passCmd2:
if optRun notin config.globalOptions and config.arguments.len > 0 and config.command.normalize != "run":
rawMessage(config, errGenerated, errArgsNeedRunOption)
proc serve*(cache: IdentCache; action: proc (cache: IdentCache){.nimcall.}; config: ConfigRef) = proc serve*(cache: IdentCache; action: proc (cache: IdentCache){.nimcall.}; config: ConfigRef) =
template execute(cmd) = template execute(cmd) =
curCaasCmd = cmd curCaasCmd = cmd

View file

@ -12,7 +12,7 @@
when not defined(nimpretty): when not defined(nimpretty):
{.error: "This needs to be compiled with --define:nimPretty".} {.error: "This needs to be compiled with --define:nimPretty".}
import ../compiler / [idents, msgs, ast, syntaxes, renderer] import ../compiler / [idents, msgs, ast, syntaxes, renderer, options]
import parseopt, strutils, os import parseopt, strutils, os
@ -40,8 +40,9 @@ proc writeVersion() =
quit(0) quit(0)
proc prettyPrint(infile: string) = proc prettyPrint(infile: string) =
let fileIdx = fileInfoIdx(infile) let conf = newConfigRef()
let tree = parseFile(fileIdx, newIdentCache()) let fileIdx = fileInfoIdx(conf, infile)
let tree = parseFile(fileIdx, newIdentCache(), conf)
let outfile = changeFileExt(infile, ".pretty.nim") let outfile = changeFileExt(infile, ".pretty.nim")
renderModule(tree, infile, outfile, {}, fileIdx) renderModule(tree, infile, outfile, {}, fileIdx)