summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/ast.nim4
-rw-r--r--compiler/docgen2.nim2
-rw-r--r--compiler/main.nim2
-rw-r--r--compiler/modules.nim4
-rw-r--r--compiler/nim.nim21
-rw-r--r--compiler/options.nim1
-rw-r--r--compiler/parser.nim2
-rw-r--r--compiler/renderer.nim5
-rw-r--r--compiler/sem.nim2
-rw-r--r--compiler/service.nim19
-rw-r--r--tools/nimpretty.nim7
11 files changed, 36 insertions, 33 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
diff --git a/tools/nimpretty.nim b/tools/nimpretty.nim
index 396f17b0b..386eddfde 100644
--- a/tools/nimpretty.nim
+++ b/tools/nimpretty.nim
@@ -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)