[Mumps2Py:] [176] The analyze tokens report now has hyperlinks to another report which lists routines that use that particular token type .

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


Revision: 176
Author:   pgallot
Date:     2008-03-13 16:24:05 +0000 (Thu, 13 Mar 2008)

Log Message:
-----------
The analyze tokens report now has hyperlinks to another report which lists routines that use that particular token type. 

NOTE: clicking on a token type parses the entire list of routines (again), so it can be very slow with larger files.
NOTE: the hyperlinks are only created for token types whose count is less than 1000.  It's an arbitrary limit, but this report is most valuable looking at smaller sets of data.

Modified Paths:
--------------
    trunk/mumps2py_ui.pyw


Modified: trunk/mumps2py_ui.pyw
===================================================================
--- trunk/mumps2py_ui.pyw	2008-03-13 16:04:02 UTC (rev 175)
+++ trunk/mumps2py_ui.pyw	2008-03-13 16:24:05 UTC (rev 176)
@@ -21,8 +21,8 @@
 import mumps2py
 import mumps2py_test
 
-from mumps2py.tokens import LABEL, COMMENT, TEXTVAL, EMPTYLINE, ENTRYREF, \
-     STRINGLITERAL, NUMLITERAL
+from mumps2py.tokens import (TOKEN_REVERSE_DICT, LABEL, COMMENT, TEXTVAL,
+                             EMPTYLINE, ENTRYREF, STRINGLITERAL, NUMLITERAL)
 
 from Tkinter import *
 import tkFileDialog
@@ -399,6 +399,44 @@
             for ref in ref_dict[r_name]:
                 rpt_window.insert(END, "%s\n" % str(ref))
             
+    def extract_rpt(self, toktype, mod_list):
+        """ finds any instances in the modlist of toktype"""
+        ref_dict = {}
+        title = "routines containing %s" % \
+                TOKEN_REVERSE_DICT.get(toktype, str(toktype))
+        rpt_window = self.info_window(title)
+        try:
+            self.busy()
+            input_file = fileinput.input(mod_list[0].input_file)
+            for the_module in mod_list:
+                instances = {}
+                mod_name = the_module.mod_name
+                if the_module.tokenlist_isempty():
+                    mumps2py.parse_routine(the_module, input_file)
+                for token in the_module.tokenized():
+                    token.extract_subtokens(instances, (toktype, ))
+
+                if instances.get(toktype, None):
+                    ref_dict[mod_name] = instances[toktype]
+
+                the_module.empty_tokenlist() # keep memory usage down
+        except mumps2py.ParseError, err:
+            self.message(err.error_msg(),
+                         "Parse Error in " + the_module.mod_name)
+        finally:
+            fileinput.close()
+            self.busy(False)
+
+        routine_list = ref_dict.keys()
+        routine_list.sort()
+        for r_name in routine_list:
+            rpt_window.tag_configure(r_name, foreground = 'blue')
+            rpt_window.tag_bind(r_name, '<1>', lambda e, s = self, \
+                                n = r_name: s.select_mod(n))
+            rpt_window.insert(END, "\n%s\n" % r_name, r_name)
+            for ref in ref_dict[r_name]:
+                rpt_window.insert(END, "%s\n" % str(ref))
+            
     def parse_fromlinemodule(self, popup):
         """parse from the module containing the line specified by popup"""
         start_line = int(self.entry_val.get())
@@ -588,9 +626,20 @@
             analysis = [(v, k) for k, v in toks.items()]
             analysis.sort(reverse = True)
 
-            analysis_window = self.info_window("Token type frequency count")
-            for count, toktype_key in analysis:
-                analysis_window.insert(END, "%s: %d\n" % (toktype_key, count))
+            rpt_window = self.info_window("Token type frequency count",
+                                          width = 40)
+            for count, toktype in analysis:
+                toktype_key = TOKEN_REVERSE_DICT.get(toktype, toktype)
+                tag = "toktype_%d" % toktype
+                if count < 1000: # arbitrary limit
+                    rpt_window.tag_configure(tag, foreground = 'blue')
+                    rpt_window.tag_bind(tag, '<1>', lambda e, s = self,
+                                        t = toktype, l = modules_list:
+                                        s.extract_rpt(t, l))
+                    rpt_window.insert(END, toktype_key, tag)
+                    rpt_window.insert(END, ": %d\n" % count)
+                else:
+                    rpt_window.insert(END, "%s: %d\n" % (toktype_key, count))
 
     def file_close(self):
         """ clear out all the information for what was just open"""


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