Fix regeneration of multi-file dependencies
[hcoop/domtool2.git] / src / errormsg.sml
index 25b7161..5c04589 100644 (file)
@@ -6,6 +6,7 @@ structure ErrorMsg :> ERRORMSG =
   struct
     (* Initial values of compiler state variables *)
     val anyErrors = ref false
+    val anyWarnings = ref false
     val errorText = ref ""
     val fileName = ref ""
     val lineNum = ref 1
@@ -17,14 +18,14 @@ structure ErrorMsg :> ERRORMSG =
 
     (* Reset compiler to initial state *)
     fun reset() = (anyErrors:=false;
+                  anyWarnings:=false;
                   errorText:="";
                    fileName:="";
                    lineNum:=1;
                    linePos:=[1];
                    sourceStream:=TextIO.stdIn)
 
-    (* Print the given error message *)
-    fun error posopt (msg:string) =
+    fun notify f prefix posopt (msg:string) =
       let
         val (startpos, endpos) = Option.getOpt (posopt, (0, 0))
         fun look(pos,a::rest,n) =
@@ -34,13 +35,16 @@ structure ErrorMsg :> ERRORMSG =
           else look(pos,rest,n-1)
           | look _ = print "0.0"
       in
-        anyErrors := true;
+        f ();
         print (!fileName); print ":";
         look(startpos, !linePos, !lineNum);
         if startpos=endpos then () else (print "-"; look(endpos, !linePos, !lineNum));
-        app print [":error: ", msg, "\n"]
+        app print [":", prefix, ": ", msg, "\n"]
       end
 
+    val error = notify (fn () => anyErrors := true) "error"
+    val warning = notify (fn () => anyWarnings := true) "warning"
+
       val dummyLoc = (0, 0)
 
       exception Error