1.1 --- a/viewer.py Thu Feb 15 20:32:37 2007 +0100
1.2 +++ b/viewer.py Fri Feb 16 00:13:09 2007 +0100
1.3 @@ -166,7 +166,7 @@
1.4 self.stream.write("%s\n" % node.op)
1.5 self._popup_start()
1.6 self.stream.write("<div class='invocations'>\n")
1.7 - self._invocations_list(node._op_call)
1.8 + self._invocations_list(node._op_call.active())
1.9 self.stream.write("</div>\n")
1.10 self._popup_end()
1.11 self.stream.write("</span>\n")
1.12 @@ -180,7 +180,7 @@
1.13
1.14 def visitClass(self, node):
1.15 definition = node._node
1.16 - definitions = getattr(node, "_nodes", [definition])
1.17 + definitions = definition.active()
1.18 structure = definition.expr.ref
1.19 self.stream.write("<div class='class' id='%s'>\n" % self._url(structure.full_name()))
1.20 self.stream.write("<div>\n")
1.21 @@ -235,14 +235,14 @@
1.22 self.stream.write("<span class='iterator'>\n")
1.23 self._keyword("for")
1.24 self._popup_start()
1.25 - self._invocations(node._next_call)
1.26 + self._invocations(node._next_call.active())
1.27 self._popup_end()
1.28 self.stream.write("</span>\n")
1.29 self.dispatch(node.assign)
1.30 self.stream.write("<span class='iterator'>\n")
1.31 self._keyword("in")
1.32 self._popup_start()
1.33 - self._invocations(node._iter_call)
1.34 + self._invocations(node._iter_call.active())
1.35 self._popup_end()
1.36 self.stream.write("</span>\n")
1.37 self.dispatch(node.list)
1.38 @@ -267,7 +267,7 @@
1.39 self.stream.write("<span class='name'>\n")
1.40 self.stream.write(node.modname)
1.41 self._popup_start()
1.42 - self._types([node._modname])
1.43 + self._types(node._modname.active())
1.44 self._popup_end()
1.45 self.stream.write("</span>\n")
1.46 self._keyword("import")
1.47 @@ -289,9 +289,9 @@
1.48
1.49 def visitFunction(self, node):
1.50 definition = node._node
1.51 - definitions = [n for n in getattr(node, "_nodes", [definition]) if not isinstance(n, Subprogram)]
1.52 - subprogram = definition.expr.ref
1.53 - subprograms = [n for n in getattr(node, "_nodes", [subprogram]) if isinstance(n, Subprogram)]
1.54 + definitions = [n for n in definition.active() if not isinstance(n, Subprogram)]
1.55 + subprogram = node._subprogram
1.56 + subprograms = subprogram.active()
1.57 self.stream.write("<div class='function' id='%s'>\n" % self._url(subprogram.full_name()))
1.58 self.stream.write("<div>\n")
1.59 self._keyword("def")
1.60 @@ -329,7 +329,7 @@
1.61 self.stream.write("<div class='if'>\n")
1.62 first = 1
1.63 conditional = node._node
1.64 - conditionals = getattr(node, "_nodes", [conditional])
1.65 + conditionals = conditional.active()
1.66 for compare, stmt in node.tests:
1.67 self.stream.write("<div>\n")
1.68 self.stream.write("<span class='conditional'>\n")
1.69 @@ -338,7 +338,7 @@
1.70 else:
1.71 self._keyword("elif")
1.72 self._popup_start()
1.73 - self._invocations(conditional.test)
1.74 + self._invocations([c.test for c in conditionals])
1.75 self._popup_end()
1.76 self.stream.write("</span>\n")
1.77 self.dispatch(compare)
1.78 @@ -425,7 +425,7 @@
1.79
1.80 def visitReturn(self, node):
1.81 value = node._node
1.82 - values = getattr(node, "_nodes", [value])
1.83 + values = value.active()
1.84 self.stream.write("<div class='return'>\n")
1.85 self.stream.write("<span class='returns'>\n")
1.86 self._keyword("return")
1.87 @@ -497,7 +497,7 @@
1.88 self.stream.write("<span class='conditional'>\n")
1.89 self._keyword("while")
1.90 self._popup_start()
1.91 - self._invocations(node._test_call)
1.92 + self._invocations(node._test_call.active())
1.93 self._popup_end()
1.94 self.stream.write("</span>\n")
1.95 self.dispatch(node.test)
1.96 @@ -525,8 +525,8 @@
1.97 self.stream.write(symbol)
1.98 self._popup_start()
1.99 self.stream.write("<div class='invocations'>\n")
1.100 - self._invocations_list(node._left_call)
1.101 - self._invocations_list(node._right_call)
1.102 + self._invocations_list(node._left_call.active())
1.103 + self._invocations_list(node._right_call.active())
1.104 self.stream.write("</div>\n")
1.105 self._popup_end()
1.106 self.stream.write("</span>\n")
1.107 @@ -539,7 +539,7 @@
1.108 self.stream.write(symbol)
1.109 self._popup_start()
1.110 self.stream.write("<div class='invocations'>\n")
1.111 - self._invocations_list(node._unary_call)
1.112 + self._invocations_list(node._unary_call.active())
1.113 self.stream.write("</div>\n")
1.114 self._popup_end()
1.115 self.stream.write("</span>\n")
1.116 @@ -563,7 +563,7 @@
1.117
1.118 def visitAssAttr(self, node):
1.119 target = node._node
1.120 - targets = getattr(node, "_nodes", [target])
1.121 + targets = target.active()
1.122 self.stream.write("<span class='assattr'>\n")
1.123 self.dispatch(node.expr)
1.124 self.stream.write("<span class='attr'>\n")
1.125 @@ -584,7 +584,7 @@
1.126
1.127 def visitAssName(self, node):
1.128 target = node._node
1.129 - targets = getattr(node, "_nodes", [target])
1.130 + targets = target.active()
1.131 self._name_start(target.name)
1.132 self._popup_start()
1.133 self._scopes(targets)
1.134 @@ -601,13 +601,13 @@
1.135
1.136 def visitCallFunc(self, node):
1.137 target = node._node
1.138 - targets = getattr(node, "_nodes", [target])
1.139 + targets = target.active()
1.140 self.stream.write("<span class='callfunc'>\n")
1.141 self.dispatch(node.node)
1.142 self.stream.write("<span class='call'>\n")
1.143 self.stream.write("(")
1.144 self._popup_start()
1.145 - self._invocations(target)
1.146 + self._invocations(targets)
1.147 self._popup_end()
1.148 self.stream.write("</span>\n")
1.149 first = 1
1.150 @@ -660,7 +660,7 @@
1.151
1.152 def visitGetattr(self, node):
1.153 target = node._node
1.154 - targets = getattr(node, "_nodes", [target])
1.155 + targets = target.active()
1.156 self.stream.write("<span class='getattr'>\n")
1.157 self.dispatch(node.expr)
1.158 self.stream.write("<span class='attr'>\n")
1.159 @@ -681,9 +681,9 @@
1.160
1.161 def visitLambda(self, node):
1.162 definition = node._node
1.163 - definitions = [n for n in getattr(node, "_nodes", [definition]) if not isinstance(n, Subprogram)]
1.164 - subprogram = definition.expr.ref
1.165 - subprograms = [n for n in getattr(node, "_nodes", [subprogram]) if isinstance(n, Subprogram)]
1.166 + definitions = [n for n in definition.active() if not isinstance(n, Subprogram)]
1.167 + subprogram = node._subprogram
1.168 + subprograms = subprogram.active()
1.169 self.stream.write("<span class='lambda'>\n")
1.170 self._keyword("lambda")
1.171 self._parameters(subprogram, subprograms)
1.172 @@ -700,7 +700,7 @@
1.173
1.174 def visitName(self, node):
1.175 target = node._node
1.176 - targets = getattr(node, "_nodes", [target])
1.177 + targets = target.active()
1.178 self._name_start(target.name)
1.179 self._popup_start()
1.180 self._scopes(targets)
1.181 @@ -908,8 +908,8 @@
1.182 def _op(self, node):
1.183 self.stream.write("<div class='invocations'>\n")
1.184 if hasattr(node, "_left_call") and hasattr(node, "_right_call"):
1.185 - self._invocations_list(node._left_call)
1.186 - self._invocations_list(node._right_call)
1.187 + self._invocations_list(node._left_call.active())
1.188 + self._invocations_list(node._right_call.active())
1.189 else:
1.190 _node = node._node
1.191 if isinstance(_node, Not):
1.192 @@ -917,24 +917,27 @@
1.193 self._invocations_list(_node)
1.194 self.stream.write("</div>\n")
1.195
1.196 - def _invocations(self, node):
1.197 + def _invocations(self, nodes):
1.198 self.stream.write("<div class='invocations'>\n")
1.199 - self._invocations_list(node)
1.200 + self._invocations_list(nodes)
1.201 self.stream.write("</div>\n")
1.202
1.203 - def _invocations_list(self, node):
1.204 - if hasattr(node, "invocations"):
1.205 - for invocation in node.invocations:
1.206 - fn = getattr(invocation, "copy_of", invocation).full_name()
1.207 - module = invocation.module.name
1.208 - name = invocation.name
1.209 - structures = [x.name for x in invocation.structures]
1.210 - qualified_name = ".".join([module] + structures + [name])
1.211 - self.stream.write("<div class='invocation'>")
1.212 - self.stream.write("<a href='%s.html#%s'>" % (self._url(module), self._url(fn)))
1.213 - self.stream.write(self._text(qualified_name))
1.214 - self.stream.write("</a>")
1.215 - self.stream.write("</div>\n")
1.216 + def _invocations_list(self, nodes):
1.217 + invocations = []
1.218 + for node in nodes:
1.219 + if hasattr(node, "invocations"):
1.220 + invocations += node.invocations
1.221 + for invocation in unique(invocations):
1.222 + fn = getattr(invocation, "copy_of", invocation).full_name()
1.223 + module = invocation.module.name
1.224 + name = invocation.name
1.225 + structures = [x.name for x in invocation.structures]
1.226 + qualified_name = ".".join([module] + structures + [name])
1.227 + self.stream.write("<div class='invocation'>")
1.228 + self.stream.write("<a href='%s.html#%s'>" % (self._url(module), self._url(fn)))
1.229 + self.stream.write(self._text(qualified_name))
1.230 + self.stream.write("</a>")
1.231 + self.stream.write("</div>\n")
1.232
1.233 def _types(self, nodes):
1.234 self.stream.write("<div class='types'>\n")
1.235 @@ -972,6 +975,7 @@
1.236 self.stream.write("</div>\n")
1.237
1.238 def _types_list(self, types):
1.239 + types = unique(types)
1.240 for type in types:
1.241 fn = type.type.full_name()
1.242 self.stream.write("<div class='type'>")
1.243 @@ -1050,9 +1054,14 @@
1.244 def flatten(lists):
1.245 result = []
1.246 for l in lists:
1.247 - for attr in l:
1.248 - if attr not in result:
1.249 - result.append(attr)
1.250 + result += unique(l)
1.251 + return result
1.252 +
1.253 +def unique(l):
1.254 + result = []
1.255 + for i in l:
1.256 + if i not in result:
1.257 + result.append(i)
1.258 return result
1.259
1.260 # Convenience functions.