]>
Commit | Line | Data |
---|---|---|
1 | (* L1 Compiler | |
2 | * Error messages | |
3 | * Author: Kaustuv Chaudhuri <kaustuv+@cs.cmu.edu> | |
4 | * Annotations: Alex Vaynberg <alv@andrew.cmu.edu> | |
5 | * Modified: Frank Pfenning <fp@cs.cmu.edu> | |
6 | *) | |
7 | ||
8 | signature ERRORMSG = | |
9 | sig | |
10 | (* clears out all errors from the system *) | |
11 | val reset : unit -> unit | |
12 | ||
13 | (* global flag that indicates whether there were errors *) | |
14 | val anyErrors : bool ref | |
15 | ||
16 | (* sets the error flag and prints out an error message, does NOT raise ERROR *) | |
17 | val error : Mark.ext option -> string -> unit | |
18 | (* same, but does not increment error count *) | |
19 | val warn : Mark.ext option -> string -> unit | |
20 | ||
21 | (* generic code stopping exception *) | |
22 | exception Error | |
23 | exception InternalError of string | |
24 | end | |
25 | ||
26 | structure ErrorMsg :> ERRORMSG = | |
27 | struct | |
28 | (* Initial values of compiler state variables *) | |
29 | val anyErrors = ref false | |
30 | ||
31 | fun reset() = ( anyErrors := false ) | |
32 | ||
33 | fun msg str ext note = | |
34 | (anyErrors := true; | |
35 | Option.map (TextIO.print o Mark.show) ext; | |
36 | List.app TextIO.print [":", str, ":", note, "\n"]) | |
37 | ||
38 | fun error ext note = (anyErrors := true; msg "error" ext note) | |
39 | fun warn ext note = msg "warning" ext note | |
40 | ||
41 | (* Print the given error message and then abort compilation *) | |
42 | exception Error | |
43 | exception InternalError of string | |
44 | end |