From: Eric S. Raymond Date: Wed, 18 Feb 2004 20:48:50 +0000 (+0000) Subject: Prevent code generation when there are nonfatal errors. X-Git-Tag: 1.0~77 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=1af35e03e57177dde18d87282c71c0bb94cfd514;p=mad.git Prevent code generation when there are nonfatal errors. --- diff --git a/mad b/mad index 6ac653c..7e2c92a 100755 --- 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)