From: Eric S. Raymond Date: Thu, 19 Feb 2004 03:17:30 +0000 (+0000) Subject: Eliminate a global. X-Git-Tag: 1.0~67 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=0e879672a1c7db4a48327c6a3756389562d87efb;p=mad.git Eliminate a global. --- diff --git a/mad b/mad index af12b41..0fc7a15 100755 --- a/mad +++ b/mad @@ -125,22 +125,14 @@ sourceline = 0 # Current source line for error messages deck = [] # List of tuples generated by parsing targets = {} # Dictionary of targets of TRANSFERs headers = [] # Required .h file basenames -funcnames = [] # List of function names +funcnames = ["main."] # List of function names dimensions = {} # Dictionary of array depths arraydepths = {} # Dictionary of array dimensions -returntypes = {} # Dictionary of function returntypes +returntypes = {"main.":'int'} # Dictionary of function returntypes static = {} # Dictionary of static char variables format = {} # Dictionary of format strings hasmain = False # Does this program have a main line? -def initfunc(f): - global currentfunc - currentfunc = f - funcnames.append(currentfunc) - -initfunc("main.") -returntypes['main.'] = 'int' - # Program level def p_program(t): @@ -205,7 +197,6 @@ def p_end_of_functions(t): ## ENTRY def p_entry(t): "statement : ENTRY TO FUNCALL" - initfunc(t[3]) t[0] = ('entry', t[3]) ## ERROR RETURN @@ -533,7 +524,7 @@ dummycount = 0 # Count of FOR VALUES statements def analyze(): "Gather variable types and determine function boundaries." - global deck, currentfunc, hasmain + global deck, hasmain global sourcefile, sourceline # We may need to generate a pseudo-function call for i in range(len(deck)): @@ -565,9 +556,6 @@ def analyze(): elif statement[0] == 'dimension': for (var, dimlist) in statement[1]: dimensions[var] = dimlist - elif statement[0] == 'entry': - currentfunc = statement[1] - funcline = sourceline elif statement[0] == 'integer': for var in statement[1:]: typedict[var] = 'int' @@ -612,10 +600,7 @@ def analyze(): # Do type deductions from format fields for card in deck: (sourcefile, sourceline, label, statement) = card - if statement[0] == 'entry': - currentfunc = statement[1] - funcline = sourceline - elif statement[0] == 'read': + if statement[0] == 'read': if statement[1] not in format: nonfatal("uninitialized format string" +`statement[1]`) else: @@ -631,6 +616,7 @@ def analyze(): # expression evaluation until we can't deduce any more int or bool # type bindings for variables. Everything else just defaults to # double. + currentfunc = None while True: deductions = 0 for card in deck: @@ -891,7 +877,6 @@ def lptcodes(res): return res def print_C_statement(statement): - global currentfunc if statement[0] in ('boolean', 'dimension', 'external_function',