diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2018-05-27 15:22:17 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-05-27 15:22:17 +0200 |
commit | 18a3833d6085ae4edf28433ba12a27a4be3ae3b1 (patch) | |
tree | a4dc15d24b03c7657b15fdf5e5da0e087b6347f5 /compiler | |
parent | dd8a6ef3a2aa1f0200d6ddff0f1f38532e84647b (diff) | |
download | Nim-18a3833d6085ae4edf28433ba12a27a4be3ae3b1.tar.gz |
more refactoring
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/ast.nim | 4 | ||||
-rw-r--r-- | compiler/docgen2.nim | 2 | ||||
-rw-r--r-- | compiler/main.nim | 2 | ||||
-rw-r--r-- | compiler/modules.nim | 4 | ||||
-rw-r--r-- | compiler/nim.nim | 21 | ||||
-rw-r--r-- | compiler/options.nim | 1 | ||||
-rw-r--r-- | compiler/parser.nim | 2 | ||||
-rw-r--r-- | compiler/renderer.nim | 5 | ||||
-rw-r--r-- | compiler/sem.nim | 2 | ||||
-rw-r--r-- | compiler/service.nim | 19 |
10 files changed, 32 insertions, 30 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 85278f9ef..f49d44c97 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -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 diff --git a/compiler/docgen2.nim b/compiler/docgen2.nim index 0db3b89d1..2d63220de 100644 --- a/compiler/docgen2.nim +++ b/compiler/docgen2.nim @@ -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: diff --git a/compiler/main.nim b/compiler/main.nim index bf37a107d..e174bea49 100644 --- a/compiler/main.nim +++ b/compiler/main.nim @@ -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 diff --git a/compiler/modules.nim b/compiler/modules.nim index 5dde755fa..ead4ce0b5 100644 --- a/compiler/modules.nim +++ b/compiler/modules.nim @@ -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; diff --git a/compiler/nim.nim b/compiler/nim.nim index 456a7bdac..ac861b2d7 100644 --- a/compiler/nim.nim +++ b/compiler/nim.nim @@ -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: diff --git a/compiler/options.nim b/compiler/options.nim index 48713161c..d9ab9bf61 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -186,6 +186,7 @@ type foreignPackageNotes*: TNoteKinds notes*: TNoteKinds mainPackageNotes*: TNoteKinds + mainPackageId*: int errorCounter*: int hintCounter*: int warnCounter*: int diff --git a/compiler/parser.nim b/compiler/parser.nim index 621eabeb2..aedee8538 100644 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -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: diff --git a/compiler/renderer.nim b/compiler/renderer.nim index 748cf9d1c..e209112e8 100644 --- a/compiler/renderer.nim +++ b/compiler/renderer.nim @@ -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 = "" diff --git a/compiler/sem.nim b/compiler/sem.nim index 6b3287df5..12c067c22 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -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 diff --git a/compiler/service.nim b/compiler/service.nim index 47fe25ea1..0e82c03f8 100644 --- a/compiler/service.nim +++ b/compiler/service.nim @@ -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 |