1.1 --- a/micropython/common.py Sat May 10 02:32:20 2008 +0200
1.2 +++ b/micropython/common.py Sun May 11 18:20:27 2008 +0200
1.3 @@ -19,12 +19,25 @@
1.4 this program. If not, see <http://www.gnu.org/licenses/>.
1.5 """
1.6
1.7 +try:
1.8 + set
1.9 +except NameError:
1.10 + from sets import Set as set
1.11 +
1.12 +# Errors.
1.13 +
1.14 class ProcessingError(Exception):
1.15
1.16 "A processing error."
1.17
1.18 pass
1.19
1.20 +class InspectError(ProcessingError):
1.21 +
1.22 + "An error during the module inspection process."
1.23 +
1.24 + pass
1.25 +
1.26 class NodeProcessingError(ProcessingError):
1.27
1.28 "A processing error associated with a particular program node."
1.29 @@ -40,4 +53,65 @@
1.30 def __str__(self):
1.31 return repr(self)
1.32
1.33 +class TranslateError(NodeProcessingError):
1.34 +
1.35 + "An error during the module translation process."
1.36 +
1.37 + pass
1.38 +
1.39 +# Inspection representations.
1.40 +
1.41 +class AtLeast:
1.42 +
1.43 + "A special representation for numbers of a given value or greater."
1.44 +
1.45 + def __init__(self, count):
1.46 + self.count = count
1.47 +
1.48 + def __eq__(self, other):
1.49 + return 0
1.50 +
1.51 + __lt__ = __le__ = __eq__
1.52 +
1.53 + def __ne__(self, other):
1.54 + return 1
1.55 +
1.56 + def __gt__(self, other):
1.57 + if isinstance(other, AtLeast):
1.58 + return 0
1.59 + else:
1.60 + return self.count > other
1.61 +
1.62 + def __ge__(self, other):
1.63 + if isinstance(other, AtLeast):
1.64 + return 0
1.65 + else:
1.66 + return self.count >= other
1.67 +
1.68 + def __iadd__(self, other):
1.69 + if isinstance(other, AtLeast):
1.70 + self.count += other.count
1.71 + else:
1.72 + self.count += other
1.73 + return self
1.74 +
1.75 + def __radd__(self, other):
1.76 + if isinstance(other, AtLeast):
1.77 + return AtLeast(self.count + other.count)
1.78 + else:
1.79 + return AtLeast(self.count + other)
1.80 +
1.81 + def __repr__(self):
1.82 + return "AtLeast(%r)" % self.count
1.83 +
1.84 +class Naming:
1.85 +
1.86 + "A mix-in providing naming conveniences."
1.87 +
1.88 + def full_name(self):
1.89 + if self.name is not None:
1.90 + return self.parent.full_name() + "." + self.name
1.91 + else:
1.92 + return self.parent.full_name()
1.93 +
1.94 # vim: tabstop=4 expandtab shiftwidth=4