1.1 --- a/annotate.py Fri Feb 16 00:50:41 2007 +0100
1.2 +++ b/annotate.py Sun Feb 18 00:37:57 2007 +0100
1.3 @@ -1364,6 +1364,9 @@
1.4
1.5 __getitem__ = load
1.6
1.7 + def has_key(self, name):
1.8 + return self.names.has_key(name)
1.9 +
1.10 def revoke(self, name, type):
1.11
1.12 "Revoke from the entry for the given 'name' the specified 'type'."
2.1 --- a/lib/builtins.py Fri Feb 16 00:50:41 2007 +0100
2.2 +++ b/lib/builtins.py Sun Feb 18 00:37:57 2007 +0100
2.3 @@ -31,6 +31,8 @@
2.4 return self.__add__(other)
2.5
2.6 class bool:
2.7 + __atomic__ = 1
2.8 +
2.9 def __bool__(self):
2.10 return self
2.11
2.12 @@ -70,6 +72,8 @@
2.13 pass
2.14
2.15 class float:
2.16 + __atomic__ = 1
2.17 +
2.18 def __iadd__(self, other):
2.19 if isinstance(other, int):
2.20 return float()
2.21 @@ -283,6 +287,8 @@
2.22 return self != 0
2.23
2.24 class int:
2.25 + __atomic__ = 1
2.26 +
2.27 def __iadd__(self, other):
2.28 if isinstance(other, int):
2.29 return int()
2.30 @@ -477,6 +483,8 @@
2.31 return bool()
2.32
2.33 class long:
2.34 + __atomic__ = 1
2.35 +
2.36 def __iadd__(self, other):
2.37 if isinstance(other, int):
2.38 return long()
2.39 @@ -586,6 +594,8 @@
2.40 return self != 0
2.41
2.42 class none:
2.43 + __atomic__ = 1
2.44 +
2.45 def __bool__(self):
2.46 return False
2.47
2.48 @@ -593,6 +603,8 @@
2.49 return "None"
2.50
2.51 class str:
2.52 + __atomic__ = 1
2.53 +
2.54 def __init__(self, x=None):
2.55 x.__str__()
2.56
2.57 @@ -725,19 +737,19 @@
2.58 pass
2.59
2.60 class AttributeError(Exception):
2.61 - pass
2.62 + __atomic__ = 1
2.63
2.64 class IndexError(Exception):
2.65 - pass
2.66 + __atomic__ = 1
2.67
2.68 class StopIteration(Exception):
2.69 - pass
2.70 + __atomic__ = 1
2.71
2.72 class TypeError(Exception):
2.73 - pass
2.74 + __atomic__ = 1
2.75
2.76 class NotImplementedType:
2.77 - pass
2.78 + __atomic__ = 1
2.79
2.80 # General functions.
2.81
3.1 --- a/simplified.py Fri Feb 16 00:50:41 2007 +0100
3.2 +++ b/simplified.py Sun Feb 18 00:37:57 2007 +0100
3.3 @@ -87,6 +87,18 @@
3.4 naming.set(obj, name)
3.5 return naming.get(obj)
3.6
3.7 +# Named nodes are those which can be referenced in some way.
3.8 +
3.9 +class WithName:
3.10 +
3.11 + "Node naming."
3.12 +
3.13 + def __init__(self):
3.14 + self._full_name = name(self, self.name or "$untitled")
3.15 +
3.16 + def full_name(self):
3.17 + return self._full_name
3.18 +
3.19 # Elementary visitor support.
3.20
3.21 class Visitor(ASTVisitor):
3.22 @@ -359,6 +371,23 @@
3.23
3.24 return node
3.25
3.26 +# Comparable nodes based on naming.
3.27 +
3.28 +class Comparable(Node):
3.29 +
3.30 + "Comparable nodes implementing the 'full_name' method."
3.31 +
3.32 + def __eq__(self, other):
3.33 + # NOTE: Single instance: all instances are the same
3.34 + # NOTE: Multiple instances: all instances are different
3.35 + if hasattr(other, "full_name"):
3.36 + return self.full_name() == other.full_name()
3.37 + else:
3.38 + return NotImplemented
3.39 +
3.40 + def __hash__(self):
3.41 + return id(self)
3.42 +
3.43 # These are the supported "operations" described by simplified program nodes.
3.44
3.45 class Pass(Node): "A placeholder node corresponding to pass."
3.46 @@ -454,18 +483,6 @@
3.47 self.share_locals = 1
3.48 Invoke.__init__(self, *args, **kw)
3.49
3.50 -# Named nodes are those which can be referenced in some way.
3.51 -
3.52 -class WithName:
3.53 -
3.54 - "Node naming."
3.55 -
3.56 - def __init__(self):
3.57 - self._full_name = name(self, self.name or "$untitled")
3.58 -
3.59 - def full_name(self):
3.60 - return self._full_name
3.61 -
3.62 # Program structure nodes.
3.63
3.64 class Subprogram(Node, WithName):
3.65 @@ -476,21 +493,6 @@
3.66 Node.__init__(self, *args, **kw)
3.67 WithName.__init__(self)
3.68
3.69 -class Comparable(Node):
3.70 -
3.71 - "Comparable nodes implementing the 'full_name' method."
3.72 -
3.73 - def __eq__(self, other):
3.74 - # NOTE: Single instance: all instances are the same
3.75 - # NOTE: Multiple instances: all instances are different
3.76 - if hasattr(other, "full_name"):
3.77 - return self.full_name() == other.full_name()
3.78 - else:
3.79 - return NotImplemented
3.80 -
3.81 - def __hash__(self):
3.82 - return id(self)
3.83 -
3.84 class Module(Comparable):
3.85
3.86 "A Python module."
3.87 @@ -574,6 +576,16 @@
3.88 else:
3.89 return attribute
3.90
3.91 +class SelectiveMultipleInstanceClass(MultipleInstanceClass):
3.92 +
3.93 + "A Python class which provides multiple instances depending on the class."
3.94 +
3.95 + def _get_key(self, node):
3.96 + if self.namespace.has_key("__atomic__"):
3.97 + return id(self)
3.98 + else:
3.99 + return MultipleInstanceClass._get_key(self, node)
3.100 +
3.101 class Instance(Structure):
3.102
3.103 "An instance."
3.104 @@ -629,6 +641,8 @@
3.105 def __hash__(self):
3.106 return id(self)
3.107
3.108 +# Additional program and AST nodes.
3.109 +
3.110 class Self:
3.111
3.112 """
3.113 @@ -661,4 +675,8 @@
3.114 global Class
3.115 Class = MultipleInstanceClass
3.116
3.117 +def set_selective_multiple_instance_mode():
3.118 + global Class
3.119 + Class = SelectiveMultipleInstanceClass
3.120 +
3.121 # vim: tabstop=4 expandtab shiftwidth=4
4.1 --- a/test.py Fri Feb 16 00:50:41 2007 +0100
4.2 +++ b/test.py Sun Feb 18 00:37:57 2007 +0100
4.3 @@ -10,6 +10,8 @@
4.4 simplified.set_single_instance_mode()
4.5 elif "-m" in sys.argv:
4.6 simplified.set_multiple_instance_mode()
4.7 + elif "-ms" in sys.argv:
4.8 + simplified.set_selective_multiple_instance_mode()
4.9
4.10 import viewer
4.11 from annotate import AnnotationError, Importer, load