1.1 --- a/simplify/annotate.py Sun Jul 29 20:33:09 2007 +0200
1.2 +++ b/simplify/annotate.py Sun Jul 29 23:29:19 2007 +0200
1.3 @@ -193,7 +193,7 @@
1.4
1.5 # Add namespace details to any structure involved.
1.6
1.7 - if getattr(node, "structure", None) is not None:
1.8 + if node.structure is not None:
1.9 node.structure.namespace = Namespace()
1.10
1.11 # Initialise bases where appropriate.
1.12 @@ -285,9 +285,6 @@
1.13 system's annotation counter.
1.14 """
1.15
1.16 - if not hasattr(node, "paramtypes"):
1.17 - node.paramtypes = {}
1.18 -
1.19 for param, types in items:
1.20 if not node.paramtypes.has_key(param):
1.21 node.paramtypes[param] = set()
1.22 @@ -444,7 +441,7 @@
1.23 and storing details on the node.
1.24 """
1.25
1.26 - module = self.importer.load(import_.name, self.builtins, getattr(import_, "alias", None))
1.27 + module = self.importer.load(import_.name, self.builtins, import_.alias)
1.28 if module is not None:
1.29 self.namespace.set_types(set([module]))
1.30 else:
1.31 @@ -787,7 +784,7 @@
1.32 those raised in the namespace.
1.33 """
1.34
1.35 - if getattr(raise_, "traceback", None) is not None:
1.36 + if raise_.traceback is not None:
1.37 self.dispatch(raise_.traceback)
1.38 self.dispatch(raise_.expr)
1.39
1.40 @@ -1021,14 +1018,14 @@
1.41 # Provide the correct namespace for the invocation.
1.42 # This may be a "shared" namespace...
1.43
1.44 - if getattr(invoke, "share_locals", 0):
1.45 + if invoke.share_locals:
1.46 namespace = Namespace()
1.47 namespace.merge_namespace(self.namespace, everything=0)
1.48 using_module_namespace = self.namespace is self.module.namespace
1.49
1.50 # Or it may be a structure...
1.51
1.52 - elif getattr(target, "structure", None):
1.53 + elif target.structure:
1.54 namespace = Namespace()
1.55 using_module_namespace = 0
1.56
1.57 @@ -1044,7 +1041,7 @@
1.58 # NOTE: subprogram within itself. Do not define the name of the function
1.59 # NOTE: within a method definition.
1.60
1.61 - if getattr(target, "name", None) is not None and not getattr(target, "is_method", 0):
1.62 + if target.name is not None and not target.is_method:
1.63 namespace.store(target.name, set([Attribute(None, target)]))
1.64
1.65 # Process the subprogram.
1.66 @@ -1054,7 +1051,7 @@
1.67 # NOTE: Improve and verify this.
1.68 # If the invocation returns a value, acquire the return types.
1.69
1.70 - if getattr(target, "returns_value", 0):
1.71 + if target.returns_value:
1.72 self.namespace.set_types(target.returns)
1.73 self.annotate(invoke)
1.74
1.75 @@ -1063,7 +1060,7 @@
1.76 # logical expressions, the namespace can be modified whilst values are
1.77 # returned as results.
1.78
1.79 - if getattr(invoke, "share_locals", 0):
1.80 + if invoke.share_locals:
1.81 self.namespace.reset()
1.82
1.83 # Merge the locals snapshots.
1.84 @@ -1073,7 +1070,7 @@
1.85 # For blocks returning values (such as operations), do not merge
1.86 # snapshots or results.
1.87
1.88 - if getattr(target, "returns_value", 0):
1.89 + if target.returns_value:
1.90 self.namespace.merge_namespace(locals, everything=0, temp=0)
1.91
1.92 # For blocks not returning values (such as loops), merge
1.93 @@ -1085,8 +1082,6 @@
1.94
1.95 # Incorporate any raised exceptions.
1.96
1.97 - if not hasattr(invoke, "raises"):
1.98 - invoke.raises = set()
1.99 invoke.raises.update(target.raises)
1.100 self.namespace.raises.update(target.raises)
1.101
2.1 --- a/simplify/simplified/program.py Sun Jul 29 20:33:09 2007 +0200
2.2 +++ b/simplify/simplified/program.py Sun Jul 29 23:29:19 2007 +0200
2.3 @@ -326,7 +326,6 @@
2.4 class StoreAttr(Node): "Associate an object's attribute with a value."
2.5 class ReleaseTemp(Node): "Release a temporary value."
2.6 class Try(Node): "A try...except...else...finally grouping node."
2.7 -class Raise(Node): "An exception raising node."
2.8 class Not(Node): "A negation of an expression."
2.9 class CheckType(Node): "Check a value's type from a list of choices."
2.10 class Return(Node): "Return an evaluated expression."
2.11 @@ -362,6 +361,25 @@
2.12
2.13 # Invocations involve some more work to process calculated attributes.
2.14
2.15 +class Raise(Invoke):
2.16 +
2.17 + "An exception raising node which may behave like an invocation."
2.18 +
2.19 + def __init__(self, original=None, defining=0, expr=None, traceback=None, **kw):
2.20 +
2.21 + """
2.22 + Initialise the invocation with the following optional parameters:
2.23 +
2.24 + * The 'original' AST node represented by this invocation.
2.25 + * Whether this invocation is 'defining' (false by default).
2.26 + * The 'expr' or expression indicating the invoked subprogram.
2.27 + * The 'traceback' associated with the raised exception.
2.28 + """
2.29 +
2.30 + Invoke.__init__(self, original, defining, expr=expr, traceback=traceback, **kw)
2.31 + self.share_locals = 0
2.32 + self.raises = set()
2.33 +
2.34 class InvokeFunction(Invoke):
2.35
2.36 "A function or method invocation."
2.37 @@ -383,6 +401,7 @@
2.38 Invoke.__init__(self, original, defining, expr=expr, args=(args or []), star=star, dstar=dstar, **kw)
2.39 self.set_args(self.args)
2.40 self.share_locals = 0
2.41 + self.raises = set()
2.42
2.43 def set_args(self, args):
2.44
2.45 @@ -422,6 +441,7 @@
2.46 """
2.47
2.48 Invoke.__init__(self, original, defining, ref=ref, produces_result=produces_result, share_locals=share_locals, **kw)
2.49 + self.raises = set()
2.50
2.51 # Program structure nodes.
2.52
2.53 @@ -429,6 +449,10 @@
2.54
2.55 "A Python module."
2.56
2.57 + def __init__(self, *args, **kw):
2.58 + Node.__init__(self, *args, **kw)
2.59 + self.structure = None
2.60 +
2.61 def full_name(self):
2.62 return "module %s" % self.name
2.63
2.64 @@ -437,7 +461,7 @@
2.65 "A subprogram: functions, methods and loops."
2.66
2.67 def __init__(self, original=None, defining=0, name=None, module=None, structure=None,
2.68 - structures=None, internal=0, returns_value=1, params=None, star=None,
2.69 + structures=None, internal=0, returns_value=1, is_method=0, params=None, star=None,
2.70 dstar=None, **kw):
2.71
2.72 """
2.73 @@ -454,6 +478,8 @@
2.74 represented.
2.75 * Whether a value is returned, as specified by 'returns_value' (true
2.76 by default).
2.77 + * Whether the subprogram is a method, as specified by 'is_method'
2.78 + (false by default).
2.79 * The 'params' (a parameter list which is empty by default).
2.80 * The 'star' parameter which collects excess positional arguments.
2.81 * The 'dstar' parameter which collects unmatched keyword arguments.
2.82 @@ -461,12 +487,13 @@
2.83
2.84 Node.__init__(self, original, defining, name=name, module=module, structure=structure,
2.85 structures=structures, internal=internal, returns_value=returns_value,
2.86 - params=(params or []), star=star, dstar=dstar, **kw)
2.87 + is_method=is_method, params=(params or []), star=star, dstar=dstar, **kw)
2.88
2.89 WithName.__init__(self)
2.90 self.raises = set()
2.91 self.returns = set()
2.92 self.return_locals = set()
2.93 + self.paramtypes = {}
2.94 self.namespace = Namespace() # NOTE: Temporary.
2.95
2.96 # vim: tabstop=4 expandtab shiftwidth=4
3.1 --- a/simplify/viewer.py Sun Jul 29 20:33:09 2007 +0200
3.2 +++ b/simplify/viewer.py Sun Jul 29 23:29:19 2007 +0200
3.3 @@ -1109,7 +1109,7 @@
3.4 param, default = params[i][n]
3.5 else:
3.6 param, default = params[i]
3.7 - if hasattr(subprogram, "paramtypes"):
3.8 + if subprogram.paramtypes:
3.9 types.update(subprogram.paramtypes[param])
3.10 return self._types_container(types, "types")
3.11
3.12 @@ -1207,7 +1207,7 @@
3.13
3.14 raises = set()
3.15 for node in nodes:
3.16 - if hasattr(node, "raises") and node.raises:
3.17 + if node.raises:
3.18 raises.update(node.raises)
3.19 return self._types_container(raises, "raises")
3.20