Merge pull request #8019 from yglukhov/proc-stacktrace

Allow stacktrace and linetrace pragmas on procs
This commit is contained in:
Andreas Rumpf 2018-06-12 17:12:13 +02:00 • committed by GitHub
commit b379547fc0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 2 deletions

View file

@ -24,8 +24,8 @@ const
wCompilerProc, wCore, wProcVar, wDeprecated, wVarargs, wCompileTime, wMerge, wCompilerProc, wCore, wProcVar, wDeprecated, wVarargs, wCompileTime, wMerge,
wBorrow, wExtern, wImportCompilerProc, wThread, wImportCpp, wImportObjC, wBorrow, wExtern, wImportCompilerProc, wThread, wImportCpp, wImportObjC,
wAsmNoStackFrame, wError, wDiscardable, wNoInit, wCodegenDecl, wAsmNoStackFrame, wError, wDiscardable, wNoInit, wCodegenDecl,
wGensym, wInject, wRaises, wTags, wLocks, wDelegator, wGcSafe, wGensym, wInject, wRaises, wTags, wLocks, wDelegator, wGcSafe, wOverride,
wOverride, wConstructor, wExportNims, wUsed, wLiftLocals} wConstructor, wExportNims, wUsed, wLiftLocals, wStacktrace, wLinetrace}
converterPragmas* = procPragmas converterPragmas* = procPragmas
methodPragmas* = procPragmas+{wBase}-{wImportCpp} methodPragmas* = procPragmas+{wBase}-{wImportCpp}
templatePragmas* = {wImmediate, wDeprecated, wError, wGensym, wInject, wDirty, templatePragmas* = {wImmediate, wDeprecated, wError, wGensym, wInject, wDirty,

View file

@ -1489,6 +1489,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
# before compiling the proc body, set as current the scope # before compiling the proc body, set as current the scope
# where the proc was declared # where the proc was declared
let oldScope = c.currentScope let oldScope = c.currentScope
let oldOptions = c.config.options
#c.currentScope = s.scope #c.currentScope = s.scope
pushOwner(c, s) pushOwner(c, s)
openScope(c) openScope(c)
@ -1569,6 +1570,8 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
popOwner(c) popOwner(c)
pushOwner(c, s) pushOwner(c, s)
s.options = c.config.options s.options = c.config.options
c.config.options = oldOptions
if sfOverriden in s.flags or s.name.s[0] == '=': semOverride(c, s, n) if sfOverriden in s.flags or s.name.s[0] == '=': semOverride(c, s, n)
if s.name.s[0] in {'.', '('}: if s.name.s[0] in {'.', '('}:
if s.name.s in [".", ".()", ".="] and {destructor, dotOperators} * c.features == {}: if s.name.s in [".", ".()", ".="] and {destructor, dotOperators} * c.features == {}:

View file

@ -119,5 +119,23 @@ when isMainModule:
verifyStackTrace expectedStackTrace: verifyStackTrace expectedStackTrace:
foo() foo()
block:
proc bar() {.stackTrace: off.} =
proc baz() = # Stack trace should be enabled
raiseTestException()
baz()
proc foo() =
bar()
const expectedStackTrace = """
tproper_stacktrace.nim(139) tproper_stacktrace
tproper_stacktrace.nim(129) foo
tproper_stacktrace.nim(125) baz
tproper_stacktrace.nim(7) raiseTestException
"""
verifyStackTrace expectedStackTrace:
foo()
echo "ok" echo "ok"