]> thyrsus.com Git - mad.git/commitdiff
Better header inclusion computation.
authorEric S. Raymond <esr@thyrsus,com>
Fri, 30 Jan 2004 22:34:56 +0000 (22:34 +0000)
committerEric S. Raymond <esr@thyrsus,com>
Fri, 30 Jan 2004 22:34:56 +0000 (22:34 +0000)
mad

diff --git a/mad b/mad
index 88139700bae8e448298fca1aa07a20d681cc355d..5739de69bd1fd3897e3f83c4ea1e89c532c526c4 100755 (executable)
--- a/mad
+++ b/mad
@@ -300,7 +300,7 @@ def p_expression_binop2(t):
     global headers
     op = t[2][1:-1].lower()
     t[0] = (op, t[1], t[3])
-    if op == 'pow':
+    if op == 'pow' and "math" not in headers:
         headers.append("math")
 
 def p_expression_not(t):
@@ -341,7 +341,7 @@ def p_function_application(t):
     'expression : FUNCALL application'
     t[0] = ('apply', t[1], tuple(t[2]))
     global headers
-    if t[1] in ('elog.', 'sqrt.'):
+    if t[1] in ('elog.', 'sqrt.') and "math" not in headers:
         headers.append("math")
 
 def p_expression_application(t):
@@ -617,8 +617,8 @@ def print_statement(statement):
 
 def generate(out):
     out.write("/* generated by the MAD compiler */\n\n")
-    if headers:
-        out.write('#include <math.h>\n\n')
+    for header in headers:
+        out.write('#include <%s.h>\n\n' % header)
 
     if integers:
         out.write('int ' + ', '.join(integers) + ';\t/* INTEGER */\n')
@@ -700,7 +700,6 @@ if __name__ == '__main__':
 
     # Perform global analysis
     analyze()
-    print "Baz!", headers
 
     if (dump_tuples):
         for t in deck: