summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authoralaviss <alaviss@users.noreply.github.com>2019-06-26 19:38:19 +0700
committerAndreas Rumpf <rumpf_a@web.de>2019-06-26 14:38:19 +0200
commit993b3909a83a2ebf3f435fee66dcb785daeaf929 (patch)
treee9831fa5fcffb07f9b7cee78d81569bc432c0c31 /compiler
parentb7f8031e98ea0d6e5be4c07eb096eda68294ed40 (diff)
downloadNim-993b3909a83a2ebf3f435fee66dcb785daeaf929.tar.gz
[refactor] compiler/[msgs, reorder, semstmts]: use toMsgFilename where appropriate (#11595)
* compiler/msgs: toMsgFilename now operates on FileIndex
* compiler/reorder: use toMsgFilename for compiler messages
* compiler/semstmts: respect listFullPaths for recursive deps error
Diffstat (limited to 'compiler')
-rw-r--r--compiler/msgs.nim11
-rw-r--r--compiler/reorder.nim2
-rw-r--r--compiler/semstmts.nim4
3 files changed, 9 insertions, 8 deletions
diff --git a/compiler/msgs.nim b/compiler/msgs.nim
index 3a0b25781..2491e0daa 100644
--- a/compiler/msgs.nim
+++ b/compiler/msgs.nim
@@ -195,12 +195,10 @@ template toFullPath*(conf: ConfigRef; info: TLineInfo): string =
 template toFullPathConsiderDirty*(conf: ConfigRef; info: TLineInfo): string =
   string toFullPathConsiderDirty(conf, info.fileIndex)
 
-proc toMsgFilename*(conf: ConfigRef; info: TLineInfo): string =
-  if info.fileIndex.int32 < 0:
-    return "???"
+proc toMsgFilename*(conf: ConfigRef; info: FileIndex): string =
   let
-    absPath = conf.m.fileInfos[info.fileIndex.int32].fullPath.string
-    relPath = conf.m.fileInfos[info.fileIndex.int32].projPath.string
+    absPath = toFullPath(conf, info)
+    relPath = toFilename(conf, info)
   result = if (optListFullPaths in conf.globalOptions) or
               (relPath.len > absPath.len) or
               (relPath.count("..") > 2):
@@ -208,6 +206,9 @@ proc toMsgFilename*(conf: ConfigRef; info: TLineInfo): string =
            else:
              relPath
 
+template toMsgFilename*(conf: ConfigRef; info: TLineInfo): string =
+  toMsgFilename(conf, info.fileIndex)
+
 proc toLinenumber*(info: TLineInfo): int {.inline.} =
   result = int info.line
 
diff --git a/compiler/reorder.nim b/compiler/reorder.nim
index 09168ae6a..0fb006c91 100644
--- a/compiler/reorder.nim
+++ b/compiler/reorder.nim
@@ -154,7 +154,7 @@ proc expandIncludes(graph: ModuleGraph, module: PSym, n: PNode,
         if f != InvalidFileIDX:
           if containsOrIncl(includedFiles, f.int):
             localError(graph.config, a.info, "recursive dependency: '$1'" %
-              toFilename(graph.config, f))
+              toMsgFilename(graph.config, f))
           else:
             let nn = includeModule(graph, module, f)
             let nnn = expandIncludes(graph, module, nn, modulePath,
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 906ad63d5..68da6d3b2 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -1288,7 +1288,7 @@ proc semAllTypeSections(c: PContext; n: PNode): PNode =
         var f = checkModuleName(c.config, n.sons[i])
         if f != InvalidFileIDX:
           if containsOrIncl(c.includedFiles, f.int):
-            localError(c.config, n.info, errRecursiveDependencyX % toFilename(c.config, f))
+            localError(c.config, n.info, errRecursiveDependencyX % toMsgFilename(c.config, f))
           else:
             let code = c.graph.includeFileCallback(c.graph, c.module, f)
             gatherStmts c, code, result
@@ -2023,7 +2023,7 @@ proc incMod(c: PContext, n: PNode, it: PNode, includeStmtResult: PNode) =
   var f = checkModuleName(c.config, it)
   if f != InvalidFileIDX:
     if containsOrIncl(c.includedFiles, f.int):
-      localError(c.config, n.info, errRecursiveDependencyX % toFilename(c.config, f))
+      localError(c.config, n.info, errRecursiveDependencyX % toMsgFilename(c.config, f))
     else:
       addSon(includeStmtResult, semStmt(c, c.graph.includeFileCallback(c.graph, c.module, f), {}))
       excl(c.includedFiles, f.int)