]> thyrsus.com Git - mad.git/commitdiff
Eliminate a global.
authorEric S. Raymond <esr@thyrsus,com>
Thu, 19 Feb 2004 03:17:30 +0000 (03:17 +0000)
committerEric S. Raymond <esr@thyrsus,com>
Thu, 19 Feb 2004 03:17:30 +0000 (03:17 +0000)
mad

diff --git a/mad b/mad
index af12b41ad75a7287a7d5f9fa2b2d588f4280bcac..0fc7a15bfca7ba66a98f8217631913db7066a9d5 100755 (executable)
--- 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',