]> thyrsus.com Git - mad.git/commitdiff
Prevent code generation when there are nonfatal errors.
authorEric S. Raymond <esr@thyrsus,com>
Wed, 18 Feb 2004 20:48:50 +0000 (20:48 +0000)
committerEric S. Raymond <esr@thyrsus,com>
Wed, 18 Feb 2004 20:48:50 +0000 (20:48 +0000)
mad

diff --git a/mad b/mad
index 6ac653c0cd777713b3c490ef1bba08a268e3f7c6..7e2c92aba13f4750e0de56b17e39111c49ccfc10 100755 (executable)
--- a/mad
+++ b/mad
@@ -508,8 +508,16 @@ madmath = ('elog.','sqrt.','sin.','cos.','tan.',)
 # Map MAD intrinsics to C library functions
 madfunc_map = {'elog':'log'}
 
-def croak(msg):
+errcount = 0
+
+def nonfatal(msg):
+    global errcount
     sys.stderr.write('"%s", line %d: %s\n' % (sourcefile, sourceline, msg))
+    errcount += 1
+
+def fatal(msg):
+    nonfatal(msg)
+    sys.exit(1)
 
 # All MAD variables are global, you have to simulate locals using SAVE DATA and
 # RETURN DATA.  Thus the variable lookup tables about are straight
@@ -541,8 +549,7 @@ def analyze():
         if statement[0] == 'for':
             target = statement[1]
             if  not target in labels:
-                croak("no such label as "+`target`)
-                sys.exit(1)
+                nonfatal("no such label as "+`target`)
     # On to actual analysis
     try:
         # Mine the code for compile-time directives
@@ -605,7 +612,7 @@ def analyze():
                 funcline = sourceline
             elif statement[0] == 'read':
                 if statement[1] not in format:
-                    croak("uninitialized format string" +`statement[1]`)
+                    nonfatal("uninitialized format string" +`statement[1]`)
                 else:
                     (fmt, types) = fmt_convert(format[statement[1]])
                     for (vtype, var) in zip(types, statement[2:]):
@@ -661,9 +668,9 @@ def analyze():
                         break
                     elif prev[0] == 'entry':
                         (sourcefile,sourceline,label,statement) = deck[i-j-1]
-                        croak("multiple ENTRY points are not supported")
+                        nonfatal("multiple ENTRY points are not supported")
                 else:
-                    croak('no EXTERNAL declaration matches this ENTRY')
+                    nonfatal('no EXTERNAL declaration matches this ENTRY')
     except:
         sys.stderr.write("mad: internal error while analyzing code for line %d\n" % line)
         (exc_type, exc_value, exc_traceback) = sys.exc_info()
@@ -1147,6 +1154,9 @@ if __name__ == '__main__':
     # Perform global analysis
     analyze()
 
+    if errcount:
+        sys.exit(1)
+
     # Generate code
     if arguments == ['-']:
         generate_C_code(sys.stdout)