more refactoring

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

View File

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

View File

@@ -25,7 +25,7 @@ template closeImpl(body: untyped) {.dirty.} =
var g = PGen(p)
let useWarning = sfMainModule notin g.module.flags
#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:
body
try:

View File

@@ -15,7 +15,7 @@ import
wordrecg, sem, semdata, idents, passes, docgen, extccomp,
cgen, jsgen, json, nversion,
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
from magicsys import resetSysTypes

View File

@@ -65,7 +65,7 @@ proc compileModule*(graph: ModuleGraph; fileIdx: FileIndex; cache: IdentCache, f
var rd: PRodReader
result.flags = result.flags + flags
if sfMainModule in result.flags:
gMainPackageId = result.owner.id
graph.config.mainPackageId = result.owner.id
when false:
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)
# restore the notes for outer module:
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
proc includeModule*(graph: ModuleGraph; s: PSym, fileIdx: FileIndex;

View File

@@ -20,7 +20,7 @@ when defined(i386) and defined(windows) and defined(vcc):
import
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
when hasTinyCBackend:
@@ -37,6 +37,25 @@ proc prependCurDir(f: string): string =
else:
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) =
condsyms.initDefines(conf.symbols)
if paramCount() == 0:

View File

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

View File

@@ -133,7 +133,7 @@ proc rawSkipComment(p: var TParser, node: PNode) =
if node.comment == nil: node.comment = ""
when defined(nimpretty):
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:
add node.comment, p.tok.literal
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 =
when defined(nimpretty):
doAssert g.config != nil, "g.config not initialized!"
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:
""
if n.info.offsetA <= n.info.offsetB:
# for some constructed tokens this can not be the case and we're better
# 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
case n.kind
of nkEmpty: result = ""

View File

@@ -505,7 +505,7 @@ proc myOpen(graph: ModuleGraph; module: PSym; cache: IdentCache): PPassContext =
graph.systemModule = module
c.topLevelScope = openScope(c)
# 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
else:
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?
# 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) =
template execute(cmd) =
curCaasCmd = cmd

View File

@@ -12,7 +12,7 @@
when not defined(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
@@ -40,8 +40,9 @@ proc writeVersion() =
quit(0)
proc prettyPrint(infile: string) =
let fileIdx = fileInfoIdx(infile)
let tree = parseFile(fileIdx, newIdentCache())
let conf = newConfigRef()
let fileIdx = fileInfoIdx(conf, infile)
let tree = parseFile(fileIdx, newIdentCache(), conf)
let outfile = changeFileExt(infile, ".pretty.nim")
renderModule(tree, infile, outfile, {}, fileIdx)