diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2018-05-27 22:52:10 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-05-27 22:52:10 +0200 |
commit | c640bd2d1bb283bcbd87da11d6b16e5f9bd39bdc (patch) | |
tree | 3e9aaf0d7f4398635a683ccac506285416a5138b /compiler/msgs.nim | |
parent | 545b1582cddb27aba75ac791f8f89e33c6d1ca5a (diff) | |
download | Nim-c640bd2d1bb283bcbd87da11d6b16e5f9bd39bdc.tar.gz |
cleanup compiler/prettybase to not use redudant global variables
Diffstat (limited to 'compiler/msgs.nim')
-rw-r--r-- | compiler/msgs.nim | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/compiler/msgs.nim b/compiler/msgs.nim index 197d6ca2a..62948e81e 100644 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -105,7 +105,6 @@ proc newLineInfo*(conf: ConfigRef; filename: string, line, col: int): TLineInfo proc raiseRecoverableError*(msg: string) {.noinline, noreturn.} = raise newException(ERecoverableError, msg) -proc sourceLine*(conf: ConfigRef; i: TLineInfo): Rope proc concat(strings: openarray[string]): string = var totalLen = 0 @@ -409,6 +408,24 @@ proc resetAttributes*(conf: ConfigRef) = if {optUseColors, optStdout} * conf.globalOptions == {optUseColors}: terminal.resetAttributes(stderr) +proc addSourceLine(conf: ConfigRef; fileIdx: FileIndex, line: string) = + conf.m.fileInfos[fileIdx.int32].lines.add line + +proc sourceLine*(conf: ConfigRef; i: TLineInfo): string = + if i.fileIndex.int32 < 0: return "" + + if not optPreserveOrigSource(conf) and conf.m.fileInfos[i.fileIndex.int32].lines.len == 0: + try: + for line in lines(toFullPath(conf, i)): + addSourceLine conf, i.fileIndex, line.string + except IOError: + discard + assert i.fileIndex.int32 < conf.m.fileInfos.len + # can happen if the error points to EOF: + if i.line.int > conf.m.fileInfos[i.fileIndex.int32].lines.len: return "" + + result = conf.m.fileInfos[i.fileIndex.int32].lines[i.line.int-1] + proc writeSurroundingSrc(conf: ConfigRef; info: TLineInfo) = const indent = " " msgWriteln(conf, indent & $sourceLine(conf, info)) @@ -518,24 +535,6 @@ template assertNotNil*(conf: ConfigRef; e): untyped = template internalAssert*(conf: ConfigRef, e: bool) = if not e: internalError(conf, $instantiationInfo()) -proc addSourceLine*(conf: ConfigRef; fileIdx: FileIndex, line: string) = - conf.m.fileInfos[fileIdx.int32].lines.add line.rope - -proc sourceLine*(conf: ConfigRef; i: TLineInfo): Rope = - if i.fileIndex.int32 < 0: return nil - - if not optPreserveOrigSource(conf) and conf.m.fileInfos[i.fileIndex.int32].lines.len == 0: - try: - for line in lines(toFullPath(conf, i)): - addSourceLine conf, i.fileIndex, line.string - except IOError: - discard - assert i.fileIndex.int32 < conf.m.fileInfos.len - # can happen if the error points to EOF: - if i.line.int > conf.m.fileInfos[i.fileIndex.int32].lines.len: return nil - - result = conf.m.fileInfos[i.fileIndex.int32].lines[i.line.int-1] - proc quotedFilename*(conf: ConfigRef; i: TLineInfo): Rope = assert i.fileIndex.int32 >= 0 if optExcessiveStackTrace in conf.globalOptions: |