[Mumps2Py:] [107] lint removal

[ Thread Index | Date Index | More lists.mumps2py.org/discuss Archives ]


Revision: 107
Author:   pgallot
Date:     2008-02-13 23:15:54 +0000 (Wed, 13 Feb 2008)

Log Message:
-----------
lint removal

Modified Paths:
--------------
    trunk/mumps2py/tokprepass.py


Modified: trunk/mumps2py/tokprepass.py
===================================================================
--- trunk/mumps2py/tokprepass.py	2008-02-13 21:03:29 UTC (rev 106)
+++ trunk/mumps2py/tokprepass.py	2008-02-13 23:15:54 UTC (rev 107)
@@ -19,7 +19,6 @@
 tokprepass contains code for massaging the intermediate tokens before
 translating a module into Python.
 """
-import re
 from tokens import *
 
 def fix_indent_levels(token, state):
@@ -38,10 +37,34 @@
 ##  print "%s: current indent level: %d, next command indent level: %d" % \
 ##        (token.dscr(),token.indentlevel, new_indentlevel)
 
+def fix_vars(tokenlist):
+    """fixes variable names for Python and tags indexed variables"""
+    vars_dict = {}
+    for token in tokenlist:
+        if vars_dict.has_key(token.varname):
+            vars_dict[token.varname].append(token)
+        else:
+            vars_dict[token.varname] = [ token, ]
+    for var in vars_dict.keys():
+        is_indexed = False
+        for token in vars_dict[var]:
+            is_indexed = is_indexed or token.__dict__.has_key('indices')
+        if is_indexed:
+            for token in vars_dict[var]:
+                if not token.__dict__.has_key('indices'):
+                    token.indices = None
+
+        if var[0] == '%':
+            if len(var) == 1:
+                new_varname = "var"
+            else:
+                new_varname = 'var_' + var[1:]
+            for token in vars_dict[var]:
+                token.varname = new_varname
+
 def findall_localvars(token, state):
     """ find all subtoken LOCALVAR instances """
     token.extract_subtokens(state['collection'], (LOCALVAR, ))
-    
 
 def prepass(a_mumps_module):
     """ Calls various functions to massage the tokens within a module."""
@@ -67,27 +90,5 @@
             if not token.__dict__.has_key('indices'):
                 token.indices = None
 
-    vars_dict = {}
-    for token in localvars_state['collection'][LOCALVAR]:
-        if vars_dict.has_key(token.varname):
-            vars_dict[token.varname].append(token)
-        else:
-            vars_dict[token.varname] = [ token, ]
-    for var in vars_dict.keys():
-        is_indexed = False
-        for token in vars_dict[var]:
-            is_indexed = is_indexed or token.__dict__.has_key('indices')
-        if is_indexed:
-            for token in vars_dict[var]:
-                if not token.__dict__.has_key('indices'):
-                    token.indices = None
-
-        if re.search(r'[%]', var):
-            if len(var) == 1:
-                new_varname = "var"
-            else:
-                new_varname = re.sub(r'[%]', '_', var)
-                if new_varname[0] == '_':
-                    new_varname = 'var' + new_varname
-            for token in vars_dict[var]:
-                token.varname = new_varname
+    if localvars_state['collection'].has_key(LOCALVAR):
+        fix_vars(localvars_state['collection'][LOCALVAR],)


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/