|
1 | | -# |
2 | | -# |
3 | | -# The Nim Compiler |
4 | | -# (c) Copyright 2021 Saem Ghani |
5 | | -# |
6 | | -# See the file "copying.txt", included in this |
7 | | -# distribution, for details about the copyright. |
8 | | -# |
9 | | - |
10 | | -## module handles reporting errors, it's used in conjunction with errorhandling |
11 | | -## |
12 | | -## Todo: |
13 | | -## * write an error reporting proc that handles string conversion and also |
14 | | -## determines which error handling strategy to use doNothing, raise, etc. |
15 | | - |
16 | | -import |
17 | | - compiler/ast/[ |
18 | | - ast, |
19 | | - errorhandling, |
20 | | - renderer, |
21 | | - reports, |
22 | | - ] |
23 | | - |
24 | | -when defined(nimDebugUnreportedErrors): |
25 | | - import std/tables |
26 | | - |
27 | | -from compiler/front/options import ConfigRef |
28 | | -from compiler/front/msgs import TErrorHandling, astDiagToLegacyReportKind |
29 | | - |
30 | | -export compilerInstInfo, walkErrors, errorKind |
31 | | -# export because keeping the declaration in `errorhandling` acts as a reminder |
32 | | -# of what the contract is with the subtleties around line and column info |
33 | | -# overloading |
34 | | - |
35 | | -proc errorHandling*(err: PNode): TErrorHandling = |
36 | | - ## which error handling strategy should be used given the error, use with |
37 | | - ## `msg.liMessage` when reporting errors. |
38 | | - assert err.isError, "err can't be nil and must be an nkError" |
39 | | - case err.diag.astDiagToLegacyReportKind: |
40 | | - of rsemCustomGlobalError: doRaise |
41 | | - of rsemFatalError: doAbort |
42 | | - else: doNothing |
43 | | - |
44 | | -template localReport*(conf: ConfigRef, node: PNode) = |
45 | | - ## Write out existing sem report that is stored in the nkError node |
46 | | - {.line.}: |
47 | | - assert node.kind == nkError, $node.kind |
48 | | - |
49 | | - when defined(nimDebugUnreportedErrors): |
50 | | - conf.unreportedErrors.del node.id |
51 | | - for err in walkErrors(conf, node): |
52 | | - conf.unreportedErrors.del err.id |
53 | | - |
54 | | - for err in walkErrors(conf, node): |
55 | | - if true or canReport(conf, err): |
56 | | - handleReport(conf, err.diag, instLoc(), node.errorHandling) |
| 1 | +# TODO: remove |
0 commit comments