diff options
author | alaviss <alaviss@users.noreply.github.com> | 2019-06-30 10:30:37 +0000 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-06-30 12:30:37 +0200 |
commit | e259f80fc70f1e9b405e68bc820ce8ea5ff500f0 (patch) | |
tree | 5cd0e2edb35ecdf190960e66da9156e918440936 /compiler | |
parent | 7113c1e931b3183b3416aec24eb2c13a87619636 (diff) | |
download | Nim-e259f80fc70f1e9b405e68bc820ce8ea5ff500f0.tar.gz |
msgs, ccgstmts: fixes #11572 (#11621)
* [refactor] msgs: toFilename now return just the filename The C codegen uses just the file name for stacktrace when excessiveStackTrace is off (see quotedName), so there aren't any reason for other codegen to not do the same. The file name is now cached in TFileInfo.shortName, which was introduced for nimsuggest, and went unused after several refactoring of the compiler. A toProjPath() proc has been added for the previous behavior of toFilename(). * ccgstmt: use quotedFilename() for raiseExceptionEx This is the same proc used for stacktrace when --stacktrace:on Fixes #11572 * msgs: handle case where file name is not available
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/ccgstmts.nim | 2 | ||||
-rw-r--r-- | compiler/msgs.nim | 21 |
2 files changed, 15 insertions, 8 deletions
diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index 5ddf78a76..7c5286d90 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -690,7 +690,7 @@ proc genRaiseStmt(p: BProc, t: PNode) = lineCg(p, cpsStmts, "#raiseExceptionEx((#Exception*)$1, $2, $3, $4, $5);$n", [e, makeCString(typ.sym.name.s), makeCString(if p.prc != nil: p.prc.name.s else: p.module.module.name.s), - makeCString(toFileName(p.config, t.info)), toLinenumber(t.info)]) + quotedFilename(p.config, t.info), toLinenumber(t.info)]) if optNimV2 in p.config.globalOptions: lineCg(p, cpsStmts, "$1 = NIM_NIL;$n", [e]) else: diff --git a/compiler/msgs.nim b/compiler/msgs.nim index 436260d4b..892f1af36 100644 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -40,9 +40,8 @@ proc newFileInfo(fullPath: AbsoluteFile, projPath: RelativeFile): TFileInfo = #shallow(result.fullPath) result.projPath = projPath #shallow(result.projPath) - let fileName = fullPath.extractFilename - result.shortName = fileName.changeFileExt("") - result.quotedName = fileName.makeCString + result.shortName = fullPath.extractFilename + result.quotedName = result.shortName.makeCString result.quotedFullName = fullPath.string.makeCString result.lines = @[] when defined(nimpretty): @@ -165,7 +164,11 @@ template toFilename*(conf: ConfigRef; fileIdx: FileIndex): string = if fileIdx.int32 < 0 or conf == nil: "???" else: - conf.m.fileInfos[fileIdx.int32].projPath.string + conf.m.fileInfos[fileIdx.int32].shortName + +proc toProjPath*(conf: ConfigRef; fileIdx: FileIndex): string = + if fileIdx.int32 < 0 or conf == nil: "???" + else: conf.m.fileInfos[fileIdx.int32].projPath.string proc toFullPath*(conf: ConfigRef; fileIdx: FileIndex): string = if fileIdx.int32 < 0 or conf == nil: result = "???" @@ -195,6 +198,9 @@ proc toFullPathConsiderDirty*(conf: ConfigRef; fileIdx: FileIndex): AbsoluteFile template toFilename*(conf: ConfigRef; info: TLineInfo): string = toFilename(conf, info.fileIndex) +template toProjPath*(conf: ConfigRef; info: TLineInfo): string = + toProjPath(conf, info.fileIndex) + template toFullPath*(conf: ConfigRef; info: TLineInfo): string = toFullPath(conf, info.fileIndex) @@ -204,7 +210,7 @@ template toFullPathConsiderDirty*(conf: ConfigRef; info: TLineInfo): string = proc toMsgFilename*(conf: ConfigRef; info: FileIndex): string = let absPath = toFullPath(conf, info) - relPath = toFilename(conf, info) + relPath = toProjPath(conf, info) result = if (optListFullPaths in conf.globalOptions) or (relPath.len > absPath.len) or (relPath.count("..") > 2): @@ -560,8 +566,9 @@ template internalAssert*(conf: ConfigRef, e: bool) = if not e: internalError(conf, $instantiationInfo()) proc quotedFilename*(conf: ConfigRef; i: TLineInfo): Rope = - assert i.fileIndex.int32 >= 0 - if optExcessiveStackTrace in conf.globalOptions: + if i.fileIndex.int32 < 0: + result = makeCString "???" + elif optExcessiveStackTrace in conf.globalOptions: result = conf.m.fileInfos[i.fileIndex.int32].quotedFullName else: result = conf.m.fileInfos[i.fileIndex.int32].quotedName |