From b4ea670c8f263f0a453cf96db0fd5a2bd4735a3c Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Fri, 30 Jan 2004 22:34:56 +0000 Subject: [PATCH] Better header inclusion computation. --- mad | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mad b/mad index 8813970..5739de6 100755 --- 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 \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: -- 2.43.0