[pypy-svn] r13059 - in pypy/dist/pypy: annotation tool

pedronis at codespeak.net pedronis at codespeak.net
Sat Jun 4 19:44:34 CEST 2005


Author: pedronis
Date: Sat Jun  4 19:44:33 2005
New Revision: 13059

Modified:
   pypy/dist/pypy/annotation/classdef.py
   pypy/dist/pypy/tool/ansi_print.py
Log:
move method demotion check to a more natural position (repeated warnings are avoided)



Modified: pypy/dist/pypy/annotation/classdef.py
==============================================================================
--- pypy/dist/pypy/annotation/classdef.py	(original)
+++ pypy/dist/pypy/annotation/classdef.py	Sat Jun  4 19:44:33 2005
@@ -93,8 +93,25 @@
                     value.class_ = cls # remember that this is really a method
             self.add_source_for_attribute(name, sources.get(name, cls), self)
 
+    def attr_mutated(self, homedef, attrdef): # reflow from attr read positions
+        s_newvalue = attrdef.getvalue()
+        # check for method demotion
+        if isinstance(s_newvalue, SomePBC):
+            attr = attrdef.name
+            meth = False
+            for func, classdef  in s_newvalue.prebuiltinstances.items():
+                if isclassdef(classdef):
+                    meth = True
+                    break
+            if meth and getattr(homedef.cls, attr, None) is None:
+                self.bookkeeper.warning("demoting method %s to base class %s" % (attrdef.name, homedef))
+
+        for position in attrdef.read_locations:
+            self.bookkeeper.annotator.reflowfromposition(position)        
+
     def add_source_for_attribute(self, attr, source, clsdef=None):
-        attrdef = self.find_attribute(attr)
+        homedef = self.locate_attribute(attr)
+        attrdef = homedef.attrs[attr]
         attrdef.sources[source] = clsdef
         if attrdef.read_locations:
             # we should reflow from all the reader's position,
@@ -103,8 +120,7 @@
             s_prev_value = attrdef.s_value
             s_next_value = attrdef.getvalue()
             if s_prev_value != s_next_value:
-                for position in attrdef.read_locations:
-                    self.bookkeeper.annotator.reflowfromposition(position)
+                self.attr_mutated(homedef, attrdef)
 
     def locate_attribute(self, attr):
         for cdef in self.getmro():
@@ -176,9 +192,8 @@
             newattr.merge(subattr)
         self.attrs[attr] = newattr
 
-        # reflow from all factories
-        for position in newattr.read_locations:
-            self.bookkeeper.annotator.reflowfromposition(position)
+        # reflow from all read positions
+        self.attr_mutated(self, newattr)
 
     def generalize_attr(self, attr, s_value=None):
         # if the attribute exists in a superclass, generalize there.
@@ -224,8 +239,7 @@
         if uplookup is not None:
             d[upfunc] = uplookup
         elif meth:
-            if not self.check_missing_attribute_update(name):
-                self.bookkeeper.warning("demoting method %s to base class %s" % (name,self))
+            self.check_missing_attribute_update(name)
         if d:
             return SomePBC(d)
         else:

Modified: pypy/dist/pypy/tool/ansi_print.py
==============================================================================
--- pypy/dist/pypy/tool/ansi_print.py	(original)
+++ pypy/dist/pypy/tool/ansi_print.py	Sat Jun  4 19:44:33 2005
@@ -4,9 +4,20 @@
 
 import sys
 
+f = None
+n = 0
+
 def ansi_print(text, esc, file=None):
     if file is None: file = sys.stderr
     text = text.rstrip()
+    global f,n
+    if not text.startswith('faking') and esc == "31":
+        if not f:
+            f = open("warnings.log",'w')
+        n += 1
+        f.write("<<< %03d\n"  % n)
+        f.write(text+'\n')
+        f.flush()
     if sys.platform != "win32" and file.isatty():
         text = ('\x1b[%sm' % esc  +  
                 text +



More information about the Pypy-commit mailing list