paul@318 | 1 | #!/usr/bin/env python |
paul@318 | 2 | |
paul@318 | 3 | """ |
paul@318 | 4 | View annotated sources. |
paul@318 | 5 | |
paul@513 | 6 | Copyright (C) 2006, 2007, 2010, 2011, 2012 Paul Boddie <paul@boddie.org.uk> |
paul@318 | 7 | |
paul@318 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@318 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@318 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@318 | 11 | version. |
paul@318 | 12 | |
paul@318 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@318 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@318 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@318 | 16 | details. |
paul@318 | 17 | |
paul@318 | 18 | You should have received a copy of the GNU General Public License along with |
paul@318 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@318 | 20 | """ |
paul@318 | 21 | |
paul@353 | 22 | from micropython.common import * |
paul@318 | 23 | from micropython.data import * |
paul@555 | 24 | from micropython.errors import * |
paul@353 | 25 | from os.path import exists, extsep, join |
paul@567 | 26 | import compiler.ast |
paul@318 | 27 | import sys |
paul@318 | 28 | import os |
paul@318 | 29 | import textwrap |
paul@318 | 30 | |
paul@318 | 31 | # Classes. |
paul@318 | 32 | |
paul@318 | 33 | # HTML-related output production. |
paul@318 | 34 | |
paul@318 | 35 | html_header = """<?xml version="1.0" encoding="iso-8859-15"?> |
paul@318 | 36 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
paul@318 | 37 | <html xmlns="http://www.w3.org/1999/xhtml"> |
paul@318 | 38 | <head> |
paul@480 | 39 | <title>%(title)s</title> |
paul@318 | 40 | <style type="text/css"> |
paul@318 | 41 | html { |
paul@318 | 42 | background-color: black; color: white; |
paul@318 | 43 | } |
paul@318 | 44 | |
paul@318 | 45 | body { |
paul@318 | 46 | padding-bottom: 4em; |
paul@318 | 47 | font-size: 14pt; font-family: monospace; |
paul@318 | 48 | background-color: black; color: white; |
paul@360 | 49 | margin-top: 2em; |
paul@318 | 50 | } |
paul@318 | 51 | |
paul@353 | 52 | a { |
paul@353 | 53 | text-decoration: none; |
paul@353 | 54 | } |
paul@353 | 55 | |
paul@318 | 56 | .nowrap { white-space: nowrap; } |
paul@354 | 57 | .label { font-size: smaller; } |
paul@318 | 58 | |
paul@318 | 59 | .class { margin-top: 1em; margin-bottom: 1em; } |
paul@318 | 60 | .function { margin-top: 1em; margin-bottom: 1em; } |
paul@318 | 61 | .body { padding-left: 2em; } |
paul@370 | 62 | .for, .if, .tryexcept, .tryfinally, .while { margin-bottom: 1em; } |
paul@318 | 63 | .keyword { color: yellow; } |
paul@318 | 64 | .comment { color: blue; } |
paul@318 | 65 | .class-name { color: cyan; } |
paul@318 | 66 | .function-name { color: cyan; } |
paul@358 | 67 | .specific-ref { color: #07F; } |
paul@318 | 68 | .str { color: #FF00FF; } |
paul@318 | 69 | .doc { color: #FF00FF; margin-top: 1em; margin-bottom: 1em; } |
paul@585 | 70 | .doc.module { font-size: smaller; } |
paul@353 | 71 | |
paul@353 | 72 | .popup { |
paul@353 | 73 | display: none; |
paul@353 | 74 | position: absolute; |
paul@353 | 75 | top: 3ex; left: 0; |
paul@353 | 76 | color: white; |
paul@353 | 77 | z-index: 3; |
paul@353 | 78 | } |
paul@353 | 79 | |
paul@536 | 80 | .attributes-popup, |
paul@357 | 81 | .types-popup { |
paul@357 | 82 | display: none; |
paul@357 | 83 | position: absolute; |
paul@357 | 84 | bottom: 3ex; left: 0; |
paul@357 | 85 | color: white; |
paul@357 | 86 | z-index: 3; |
paul@357 | 87 | } |
paul@357 | 88 | |
paul@523 | 89 | .no-targets { |
paul@523 | 90 | background-color: #d00; |
paul@523 | 91 | color: white; |
paul@523 | 92 | } |
paul@523 | 93 | |
paul@536 | 94 | .attr, |
paul@357 | 95 | .accessor, |
paul@371 | 96 | .name, |
paul@371 | 97 | .operation { |
paul@353 | 98 | position: relative; |
paul@354 | 99 | background-color: #300; |
paul@353 | 100 | color: white; |
paul@353 | 101 | } |
paul@353 | 102 | |
paul@536 | 103 | .attr:hover, |
paul@357 | 104 | .accessor:hover, |
paul@371 | 105 | .name:hover, |
paul@371 | 106 | .operation:hover { |
paul@354 | 107 | background-color: #500; |
paul@354 | 108 | padding-top: 0.5ex; |
paul@354 | 109 | padding-bottom: 0.5ex; |
paul@353 | 110 | z-index: 2; |
paul@353 | 111 | } |
paul@353 | 112 | |
paul@536 | 113 | .attr:hover .attributes-popup, |
paul@357 | 114 | .accessor:hover .types-popup, |
paul@371 | 115 | .name:hover .popup, |
paul@371 | 116 | .operation:hover .popup { |
paul@353 | 117 | display: block; |
paul@353 | 118 | } |
paul@318 | 119 | |
paul@354 | 120 | .attrnames, |
paul@371 | 121 | .opnames, |
paul@371 | 122 | .scope, |
paul@371 | 123 | .typenames { |
paul@354 | 124 | padding: 0.5em; |
paul@354 | 125 | background-color: #700; |
paul@354 | 126 | } |
paul@354 | 127 | |
paul@589 | 128 | .name a, |
paul@536 | 129 | .attrnames a, |
paul@583 | 130 | .opnames a, |
paul@583 | 131 | .scope a { |
paul@371 | 132 | color: white; |
paul@371 | 133 | } |
paul@371 | 134 | |
paul@318 | 135 | .summary-class { |
paul@361 | 136 | vertical-align: top; |
paul@318 | 137 | } |
paul@318 | 138 | |
paul@480 | 139 | th.summary-class { |
paul@480 | 140 | font-weight: normal; |
paul@480 | 141 | } |
paul@480 | 142 | |
paul@318 | 143 | .summary-attr { |
paul@354 | 144 | background-color: #070; |
paul@480 | 145 | } |
paul@480 | 146 | |
paul@480 | 147 | .summary-interface, |
paul@480 | 148 | .summary-attr { |
paul@361 | 149 | font-size: smaller; |
paul@361 | 150 | } |
paul@361 | 151 | |
paul@480 | 152 | .summary-interface.complete { |
paul@480 | 153 | background-color: #050; |
paul@480 | 154 | } |
paul@480 | 155 | |
paul@480 | 156 | .summary-interface.partial { |
paul@480 | 157 | background-color: #005; |
paul@480 | 158 | } |
paul@480 | 159 | |
paul@361 | 160 | .summary-attr-absent { |
paul@361 | 161 | border-left: 0.2em solid #070; |
paul@361 | 162 | font-size: small; |
paul@361 | 163 | } |
paul@361 | 164 | |
paul@361 | 165 | .summary-class-attr { |
paul@361 | 166 | background-color: #007; |
paul@361 | 167 | font-size: smaller; |
paul@361 | 168 | } |
paul@361 | 169 | |
paul@361 | 170 | .summary-class-attr-absent { |
paul@361 | 171 | border-left: 0.2em solid #007; |
paul@361 | 172 | font-size: small; |
paul@361 | 173 | } |
paul@361 | 174 | |
paul@361 | 175 | .summary-ref { |
paul@361 | 176 | color: white; |
paul@318 | 177 | } |
paul@318 | 178 | |
paul@318 | 179 | </style> |
paul@318 | 180 | </head> |
paul@318 | 181 | <body> |
paul@318 | 182 | """ |
paul@318 | 183 | |
paul@318 | 184 | html_footer = """</body> |
paul@318 | 185 | </html> |
paul@318 | 186 | """ |
paul@318 | 187 | |
paul@318 | 188 | # Utility classes. |
paul@318 | 189 | |
paul@318 | 190 | class Writer: |
paul@318 | 191 | |
paul@318 | 192 | "A utility class providing useful HTML output methods." |
paul@318 | 193 | |
paul@318 | 194 | # Methods which return strings. |
paul@318 | 195 | |
paul@318 | 196 | def _text(self, text): |
paul@318 | 197 | return text.replace("&", "&").replace("<", "<").replace(">", ">") |
paul@318 | 198 | |
paul@318 | 199 | def _attr(self, attr): |
paul@318 | 200 | return self._text(attr).replace("'", "'").replace('"', """) |
paul@318 | 201 | |
paul@318 | 202 | def _url(self, url): |
paul@318 | 203 | return self._attr(url).replace("#", "%23").replace("-", "%2d") |
paul@318 | 204 | |
paul@318 | 205 | # Methods which write to the stream. |
paul@318 | 206 | |
paul@355 | 207 | def _span_start(self, classes=None): |
paul@355 | 208 | self.stream.write("<span class='%s'>" % (classes or "")) |
paul@355 | 209 | |
paul@353 | 210 | def _span_end(self): |
paul@353 | 211 | self.stream.write("</span>") |
paul@353 | 212 | |
paul@355 | 213 | def _span(self, value, classes=None): |
paul@355 | 214 | self._span_start(classes) |
paul@355 | 215 | self.stream.write(self._text(value)) |
paul@355 | 216 | self._span_end() |
paul@355 | 217 | |
paul@355 | 218 | def _name_start(self, classes=None): |
paul@355 | 219 | self._span_start(classes or "name") |
paul@355 | 220 | |
paul@355 | 221 | _name_end = _span_end |
paul@355 | 222 | |
paul@355 | 223 | def _name(self, name, classes=None): |
paul@355 | 224 | self._name_start(classes) |
paul@355 | 225 | self.stream.write(self._text(name)) |
paul@355 | 226 | self._name_end() |
paul@355 | 227 | |
paul@357 | 228 | def _popup_start(self, classes=None): |
paul@357 | 229 | self._span_start(classes or "popup") |
paul@355 | 230 | |
paul@355 | 231 | _popup_end = _span_end |
paul@355 | 232 | |
paul@318 | 233 | def _comment(self, comment): |
paul@355 | 234 | self._span("# %s" % comment, "comment") |
paul@355 | 235 | self.stream.write("\n") |
paul@318 | 236 | |
paul@353 | 237 | def _reserved(self, token, classes, leading=0, trailing=1): |
paul@353 | 238 | if leading: |
paul@353 | 239 | self.stream.write(" ") |
paul@355 | 240 | self._span(token, classes) |
paul@353 | 241 | if trailing: |
paul@353 | 242 | self.stream.write(" ") |
paul@353 | 243 | |
paul@353 | 244 | def _keyword(self, kw, leading=0, trailing=1): |
paul@353 | 245 | self._reserved(kw, "keyword", leading, trailing) |
paul@353 | 246 | |
paul@585 | 247 | def _doc(self, node, classes=None): |
paul@318 | 248 | if node.doc is not None: |
paul@585 | 249 | self._docstring(node.doc, classes) |
paul@370 | 250 | |
paul@585 | 251 | def _docstring(self, s, classes=None): |
paul@585 | 252 | self.stream.write("<pre class='doc%s'>" % (classes and " %s" % classes or "")) |
paul@370 | 253 | self.stream.write('"""') |
paul@370 | 254 | output = textwrap.dedent(s.replace('"""', '\\"\\"\\"')) |
paul@370 | 255 | self.stream.write(self._text(output)) |
paul@370 | 256 | self.stream.write('"""') |
paul@370 | 257 | self.stream.write("</pre>\n") |
paul@318 | 258 | |
paul@321 | 259 | def _object_name_def(self, module, obj, classes=None): |
paul@320 | 260 | |
paul@320 | 261 | """ |
paul@321 | 262 | Link to the summary for 'module' using 'obj'. The optional 'classes' |
paul@321 | 263 | can be used to customise the CSS classes employed. |
paul@320 | 264 | """ |
paul@320 | 265 | |
paul@437 | 266 | if isinstance(obj, Class) or (isinstance(obj, Function) and obj.is_method()): |
paul@437 | 267 | self._summary_link(module.full_name(), obj.full_name(), obj.name, classes) |
paul@437 | 268 | else: |
paul@437 | 269 | self._span(obj.name, classes) |
paul@320 | 270 | |
paul@365 | 271 | def _object_name_ref(self, module, obj, name=None, classes=None): |
paul@358 | 272 | |
paul@358 | 273 | """ |
paul@365 | 274 | Link to the definition for 'module' using 'obj' with the optional 'name' |
paul@365 | 275 | used as the label (instead of the name of 'obj'). The optional 'classes' |
paul@358 | 276 | can be used to customise the CSS classes employed. |
paul@358 | 277 | """ |
paul@358 | 278 | |
paul@365 | 279 | self._name_link(module.full_name(), obj.full_name(), name or obj.name, classes) |
paul@358 | 280 | |
paul@358 | 281 | def _summary_link(self, module_name, full_name, name, classes=None): |
paul@358 | 282 | self._name_link("%s-summary" % module_name, full_name, name, classes) |
paul@358 | 283 | |
paul@353 | 284 | def _name_link(self, module_name, full_name, name, classes=None): |
paul@353 | 285 | self.stream.write("<a class='%s' href='%s%sxhtml#%s'>%s</a>" % ( |
paul@358 | 286 | classes or "specific-ref", module_name, os.path.extsep, |
paul@353 | 287 | self._attr(full_name), self._text(name))) |
paul@353 | 288 | |
paul@589 | 289 | def _module_link(self, module_name, classes=None): |
paul@589 | 290 | self.stream.write("<a class='%s' href='%s%sxhtml'>%s</a>" % ( |
paul@589 | 291 | classes or "name", module_name, os.path.extsep, |
paul@589 | 292 | self._text(module_name))) |
paul@589 | 293 | |
paul@583 | 294 | def _scope(self, scope, attr): |
paul@583 | 295 | self.stream.write("<div class='scope'>" |
paul@583 | 296 | "<span class='label'>scope</span><br />%s<br/>" % scope) |
paul@583 | 297 | values = self._values_to_attribute_names(attr) |
paul@583 | 298 | if values: |
paul@583 | 299 | self.stream.write("<span class='label'>values</span><br />") |
paul@583 | 300 | self._attribute_list(values) |
paul@583 | 301 | self.stream.write("</div>\n") |
paul@354 | 302 | |
paul@354 | 303 | def _assname(self, name, node): |
paul@355 | 304 | self._span_start("assname") |
paul@383 | 305 | if not self._attrcombined(name, node): |
paul@355 | 306 | self._span(name) |
paul@355 | 307 | self._span_end() |
paul@354 | 308 | |
paul@371 | 309 | def _op(self, symbol, name=None, leading=0, trailing=1): |
paul@371 | 310 | if leading: |
paul@371 | 311 | self.stream.write(" ") |
paul@437 | 312 | self._span_start(name and "operation" or None) |
paul@371 | 313 | self._span(symbol, "operator") |
paul@371 | 314 | if name is not None: |
paul@371 | 315 | self._popup_start() |
paul@371 | 316 | self.stream.write("<div class='opnames'>") |
paul@371 | 317 | self._name_link("operator", "operator.%s" % name, name) |
paul@371 | 318 | self.stream.write("</div>\n") |
paul@371 | 319 | self._popup_end() |
paul@552 | 320 | # NOTE: Handle "is" and "in". |
paul@371 | 321 | self._span_end() |
paul@371 | 322 | if trailing: |
paul@371 | 323 | self.stream.write(" ") |
paul@371 | 324 | |
paul@536 | 325 | def _names_list_start(self, label, classes): |
paul@536 | 326 | self.stream.write("<div class='%s'><span class='label'>%s</span><br />" % (classes, label)) |
paul@536 | 327 | |
paul@536 | 328 | def _names_list_end(self): |
paul@536 | 329 | self.stream.write("</div>\n") |
paul@536 | 330 | |
paul@357 | 331 | def _names_list(self, names, label, classes): |
paul@357 | 332 | if not names: |
paul@354 | 333 | return |
paul@357 | 334 | names = list(names) |
paul@357 | 335 | names.sort() |
paul@354 | 336 | |
paul@536 | 337 | self._names_list_start(label, classes) |
paul@354 | 338 | first = 1 |
paul@357 | 339 | for name in names: |
paul@354 | 340 | if not first: |
paul@354 | 341 | self.stream.write("<br />") |
paul@357 | 342 | self.stream.write(name) |
paul@354 | 343 | first = 0 |
paul@536 | 344 | self._names_list_end() |
paul@353 | 345 | |
paul@383 | 346 | def _attrcombined(self, name, node): |
paul@383 | 347 | attrcombined = hasattr(node, "_attrcombined") and node._attrcombined.get(name) or [] |
paul@383 | 348 | |
paul@383 | 349 | for attrnames in attrcombined: |
paul@383 | 350 | if attrnames: |
paul@383 | 351 | break |
paul@383 | 352 | else: |
paul@383 | 353 | return 0 |
paul@383 | 354 | |
paul@383 | 355 | self._name_start() |
paul@383 | 356 | self.stream.write(name) |
paul@383 | 357 | self._popup_start() |
paul@383 | 358 | for attrnames in attrcombined: |
paul@383 | 359 | self._attrnames(attrnames) |
paul@383 | 360 | self._popup_end() |
paul@383 | 361 | self._name_end() |
paul@383 | 362 | return 1 |
paul@383 | 363 | |
paul@357 | 364 | def _attrnames(self, attrnames): |
paul@357 | 365 | self._names_list(attrnames, "attributes", "attrnames") |
paul@357 | 366 | |
paul@357 | 367 | def _typenames(self, typenames): |
paul@357 | 368 | self._names_list(typenames, "types", "typenames") |
paul@357 | 369 | |
paul@357 | 370 | def _accessor_start(self, target_names): |
paul@365 | 371 | if target_names: |
paul@357 | 372 | self._span_start("accessor") |
paul@357 | 373 | self._popup_start("types-popup") |
paul@357 | 374 | self._typenames(target_names) |
paul@357 | 375 | self._popup_end() |
paul@357 | 376 | |
paul@357 | 377 | def _accessor_end(self, target_names): |
paul@365 | 378 | if target_names: |
paul@357 | 379 | self._span_end() |
paul@357 | 380 | |
paul@583 | 381 | def _values_to_attribute_names(self, attr): |
paul@583 | 382 | |
paul@583 | 383 | "Get the output form of the values referenced by 'attr'." |
paul@583 | 384 | |
paul@585 | 385 | if isinstance(attr, Const): |
paul@586 | 386 | return [(repr(attr.get_value()), attr)] |
paul@585 | 387 | elif isinstance(attr, Instance): |
paul@585 | 388 | return [] |
paul@583 | 389 | |
paul@583 | 390 | values = [] |
paul@583 | 391 | for v in attr.get_values(): |
paul@585 | 392 | if isinstance(v, Const): |
paul@586 | 393 | values.append((repr(v.get_value()), v)) |
paul@585 | 394 | elif not isinstance(v, Instance): |
paul@583 | 395 | values.append((v.full_name(), v)) |
paul@583 | 396 | |
paul@583 | 397 | values.sort() |
paul@583 | 398 | return values |
paul@583 | 399 | |
paul@583 | 400 | def _attributes_to_attribute_names(self, attributes, attrname): |
paul@583 | 401 | |
paul@583 | 402 | "Get the output form of the 'attributes'." |
paul@583 | 403 | |
paul@583 | 404 | output = [] |
paul@583 | 405 | for value, target, target_name in attributes: |
paul@583 | 406 | if value and not isinstance(value, Instance): |
paul@583 | 407 | fullname = value.full_name() |
paul@583 | 408 | else: |
paul@583 | 409 | fullname = target_name + "." + attrname |
paul@583 | 410 | output.append((fullname, value)) |
paul@583 | 411 | |
paul@583 | 412 | output.sort() |
paul@583 | 413 | return output |
paul@583 | 414 | |
paul@536 | 415 | def _attribute_start(self, attrname, attributes): |
paul@536 | 416 | if attributes: |
paul@536 | 417 | self._span_start("attr") |
paul@536 | 418 | self._popup_start("attributes-popup") |
paul@536 | 419 | self._names_list_start("attributes", "attrnames") |
paul@583 | 420 | self._attribute_list(attributes) |
paul@536 | 421 | self._names_list_end() |
paul@536 | 422 | self._popup_end() |
paul@536 | 423 | |
paul@583 | 424 | def _attribute_list(self, attributes): |
paul@583 | 425 | |
paul@583 | 426 | # Mix links to attributes with labels indicating undetermined |
paul@583 | 427 | # attributes. |
paul@583 | 428 | |
paul@583 | 429 | last = None |
paul@583 | 430 | for fullname, value in attributes: |
paul@583 | 431 | if fullname != last: |
paul@583 | 432 | if last is not None: |
paul@583 | 433 | self.stream.write("<br />") |
paul@583 | 434 | if value is not None and not isinstance(value, Instance): |
paul@583 | 435 | self._object_name_ref(value.module, value, fullname, classes="attribute-name") |
paul@583 | 436 | else: |
paul@586 | 437 | self.stream.write(self._text(fullname)) |
paul@583 | 438 | last = fullname |
paul@583 | 439 | |
paul@536 | 440 | def _attribute_end(self, attributes): |
paul@536 | 441 | if attributes: |
paul@536 | 442 | self._span_end() |
paul@536 | 443 | |
paul@536 | 444 | def _get_attributes(self, possible_types, attrname): |
paul@536 | 445 | objtable = self.program.get_object_table() |
paul@536 | 446 | attributes = [] |
paul@536 | 447 | for target_name, is_static in possible_types: |
paul@536 | 448 | target = objtable.get_object(target_name) |
paul@536 | 449 | try: |
paul@536 | 450 | attr = objtable.access(target_name, attrname) |
paul@536 | 451 | except TableError: |
paul@536 | 452 | continue |
paul@536 | 453 | if attr.is_static_attribute(): |
paul@536 | 454 | for v in attr.get_values(): |
paul@536 | 455 | attributes.append((v, target, target_name)) |
paul@536 | 456 | else: |
paul@536 | 457 | attributes.append((None, target, target_name)) |
paul@536 | 458 | |
paul@536 | 459 | return attributes |
paul@536 | 460 | |
paul@318 | 461 | # Summary classes. |
paul@318 | 462 | |
paul@320 | 463 | class Summary(Writer): |
paul@318 | 464 | |
paul@319 | 465 | "Summarise classes and attributes in modules." |
paul@319 | 466 | |
paul@357 | 467 | def __init__(self, module, program): |
paul@319 | 468 | self.module = module |
paul@357 | 469 | self.program = program |
paul@318 | 470 | |
paul@319 | 471 | def to_stream(self, stream): |
paul@319 | 472 | |
paul@319 | 473 | "Write the summary to the given 'stream'." |
paul@319 | 474 | |
paul@319 | 475 | self.stream = stream |
paul@480 | 476 | self.stream.write(html_header % { |
paul@480 | 477 | "title" : "Module: %s" % self.module.full_name() |
paul@480 | 478 | }) |
paul@319 | 479 | self._write_classes(self.module) |
paul@318 | 480 | self.stream.write(html_footer) |
paul@318 | 481 | |
paul@318 | 482 | def _write_classes(self, module): |
paul@318 | 483 | |
paul@318 | 484 | all_classes = {} |
paul@318 | 485 | |
paul@318 | 486 | for obj in self.module.all_objects: |
paul@318 | 487 | if isinstance(obj, Class): |
paul@318 | 488 | all_classes[obj.name] = obj |
paul@318 | 489 | |
paul@361 | 490 | if all_classes: |
paul@361 | 491 | |
paul@361 | 492 | all_class_names = all_classes.keys() |
paul@361 | 493 | all_class_names.sort() |
paul@318 | 494 | |
paul@361 | 495 | self.stream.write("<table cellspacing='5' cellpadding='5'>\n") |
paul@361 | 496 | self.stream.write("<thead>\n") |
paul@361 | 497 | self.stream.write("<tr>\n") |
paul@361 | 498 | self.stream.write("<th>Classes</th><th>Attributes</th>\n") |
paul@361 | 499 | self.stream.write("</tr>\n") |
paul@361 | 500 | self.stream.write("</thead>\n") |
paul@318 | 501 | |
paul@361 | 502 | for name in all_class_names: |
paul@361 | 503 | self._write_class(all_classes[name]) |
paul@361 | 504 | |
paul@361 | 505 | self.stream.write("</table>\n") |
paul@318 | 506 | |
paul@318 | 507 | def _write_class(self, obj): |
paul@318 | 508 | |
paul@318 | 509 | # Write the class... |
paul@318 | 510 | |
paul@318 | 511 | self.stream.write("<tbody class='class'>\n") |
paul@318 | 512 | self.stream.write("<tr>\n") |
paul@361 | 513 | self.stream.write("<th class='summary-class' id='%s' rowspan='2'>" % self._attr(obj.full_name())) |
paul@361 | 514 | self._object_name_ref(self.module, obj, classes="class-name") |
paul@318 | 515 | self.stream.write("</th>\n") |
paul@318 | 516 | |
paul@361 | 517 | # ...and instance attribute names in order... |
paul@318 | 518 | |
paul@358 | 519 | attrs = obj.instance_attributes().values() |
paul@358 | 520 | attrs.sort(cmp=lambda x, y: cmp(x.position, y.position)) |
paul@318 | 521 | |
paul@361 | 522 | if attrs: |
paul@361 | 523 | for attr in attrs: |
paul@361 | 524 | self.stream.write("<td class='summary-attr'>%s</td>\n" % self._text(attr.name)) |
paul@361 | 525 | else: |
paul@361 | 526 | self.stream.write("<td class='summary-attr-absent'>None</td>\n") |
paul@361 | 527 | |
paul@361 | 528 | self.stream.write("</tr>\n") |
paul@361 | 529 | self.stream.write("<tr>\n") |
paul@361 | 530 | |
paul@361 | 531 | # ...and class attribute names in order. |
paul@361 | 532 | |
paul@361 | 533 | attrs = obj.class_attributes().values() |
paul@361 | 534 | attrs.sort(cmp=lambda x, y: cmp(x.position, y.position)) |
paul@361 | 535 | |
paul@361 | 536 | if attrs: |
paul@361 | 537 | for attr in attrs: |
paul@363 | 538 | if attr.is_strict_constant(): |
paul@363 | 539 | value = attr.get_value() |
paul@473 | 540 | if not isinstance(value, Const): |
paul@473 | 541 | self.stream.write("<td class='summary-class-attr' id='%s'>" % self._attr(value.full_name())) |
paul@473 | 542 | self._object_name_ref(self.module, value, attr.name, classes="summary-ref") |
paul@473 | 543 | self.stream.write("</td>\n") |
paul@473 | 544 | else: |
paul@473 | 545 | self.stream.write("<td class='summary-class-attr'>%s</td>\n" % self._text(attr.name)) |
paul@361 | 546 | else: |
paul@361 | 547 | self.stream.write("<td class='summary-class-attr'>%s</td>\n" % self._text(attr.name)) |
paul@361 | 548 | else: |
paul@361 | 549 | self.stream.write("<td class='summary-class-attr-absent'>None</td>\n") |
paul@358 | 550 | |
paul@318 | 551 | self.stream.write("</tr>\n") |
paul@318 | 552 | self.stream.write("</tbody>\n") |
paul@318 | 553 | |
paul@480 | 554 | class Interfaces(Writer): |
paul@480 | 555 | |
paul@480 | 556 | "Summarise the interfaces used by reading the object table cache." |
paul@480 | 557 | |
paul@480 | 558 | def __init__(self, program): |
paul@480 | 559 | self.program = program |
paul@480 | 560 | |
paul@480 | 561 | def to_stream(self, stream): |
paul@480 | 562 | |
paul@480 | 563 | "Write the summary to the given 'stream'." |
paul@480 | 564 | |
paul@480 | 565 | self.stream = stream |
paul@480 | 566 | self.stream.write(html_header % { |
paul@480 | 567 | "title" : "Interfaces" |
paul@480 | 568 | }) |
paul@480 | 569 | self._write_interfaces() |
paul@480 | 570 | self.stream.write(html_footer) |
paul@480 | 571 | |
paul@480 | 572 | def _write_interfaces(self): |
paul@480 | 573 | objtable = self.program.get_object_table() |
paul@480 | 574 | all_interfaces = objtable.all_cache.items() |
paul@480 | 575 | any_interfaces = objtable.any_cache.items() |
paul@480 | 576 | all_interfaces.sort() |
paul@480 | 577 | any_interfaces.sort() |
paul@480 | 578 | |
paul@480 | 579 | self.stream.write("<table cellspacing='5' cellpadding='5'>\n") |
paul@480 | 580 | self.stream.write("<thead>\n") |
paul@480 | 581 | self.stream.write("<tr>\n") |
paul@480 | 582 | self.stream.write("<th>Complete Interfaces</th>\n") |
paul@480 | 583 | self.stream.write("</tr>\n") |
paul@480 | 584 | self.stream.write("</thead>\n") |
paul@480 | 585 | self._write_interface_type(all_interfaces, "complete") |
paul@480 | 586 | self.stream.write("<thead>\n") |
paul@480 | 587 | self.stream.write("<tr>\n") |
paul@480 | 588 | self.stream.write("<th>Partial Interfaces</th>\n") |
paul@480 | 589 | self.stream.write("</tr>\n") |
paul@480 | 590 | self.stream.write("</thead>\n") |
paul@480 | 591 | self._write_interface_type(any_interfaces, "partial") |
paul@480 | 592 | self.stream.write("</table>\n") |
paul@480 | 593 | |
paul@480 | 594 | def _write_interface_type(self, interfaces, classes=""): |
paul@480 | 595 | self.stream.write("<tbody>\n") |
paul@480 | 596 | |
paul@480 | 597 | for names, objects in interfaces: |
paul@480 | 598 | if names: |
paul@481 | 599 | names = list(names) |
paul@480 | 600 | names.sort() |
paul@480 | 601 | self.stream.write("<tr>\n") |
paul@480 | 602 | self.stream.write("<td class='summary-interface %s'>%s</td>" % (classes, ", ".join(names))) |
paul@480 | 603 | self.stream.write("</tr>\n") |
paul@480 | 604 | |
paul@480 | 605 | self.stream.write("</tbody>\n") |
paul@480 | 606 | |
paul@320 | 607 | # Source code classes. |
paul@320 | 608 | |
paul@320 | 609 | class AnnotatedSource(ASTVisitor, Writer): |
paul@320 | 610 | |
paul@320 | 611 | "A module source code browser." |
paul@320 | 612 | |
paul@357 | 613 | def __init__(self, module, program): |
paul@320 | 614 | self.visitor = self |
paul@320 | 615 | self.module = module |
paul@357 | 616 | self.program = program |
paul@320 | 617 | |
paul@320 | 618 | def to_stream(self, stream): |
paul@320 | 619 | |
paul@320 | 620 | "Write the annotated code to the given 'stream'." |
paul@320 | 621 | |
paul@320 | 622 | self.stream = stream |
paul@480 | 623 | self.stream.write(html_header % { |
paul@480 | 624 | "title" : "Module: %s" % self.module.full_name() |
paul@480 | 625 | }) |
paul@353 | 626 | self.dispatch(self.module.astnode) |
paul@320 | 627 | self.stream.write(html_footer) |
paul@320 | 628 | |
paul@320 | 629 | def visitModule(self, node): |
paul@585 | 630 | self._doc(node, "module") |
paul@320 | 631 | self.default(node) |
paul@320 | 632 | |
paul@320 | 633 | # Statements. |
paul@320 | 634 | |
paul@320 | 635 | def visitAssert(self, node): |
paul@320 | 636 | self.stream.write("<div class='assert nowrap'>\n") |
paul@320 | 637 | self._keyword("assert") |
paul@320 | 638 | self.dispatch(node.test) |
paul@320 | 639 | if node.fail: |
paul@320 | 640 | self.stream.write(", ") |
paul@320 | 641 | self.dispatch(node.fail) |
paul@320 | 642 | self.stream.write("</div>\n") |
paul@320 | 643 | |
paul@320 | 644 | def visitAssign(self, node): |
paul@320 | 645 | self.stream.write("<div class='assign nowrap'>\n") |
paul@320 | 646 | for lvalue in node.nodes: |
paul@320 | 647 | self.dispatch(lvalue) |
paul@353 | 648 | self.stream.write(" = ") |
paul@320 | 649 | self.dispatch(node.expr) |
paul@320 | 650 | self.stream.write("</div>\n") |
paul@320 | 651 | |
paul@320 | 652 | def visitAugAssign(self, node): |
paul@320 | 653 | self.stream.write("<div class='augassign nowrap'>\n") |
paul@320 | 654 | self.dispatch(node.node) |
paul@371 | 655 | self._op(node.op, operator_functions[node.op], 1) |
paul@320 | 656 | self.dispatch(node.expr) |
paul@320 | 657 | self.stream.write("</div>\n") |
paul@320 | 658 | |
paul@320 | 659 | def visitBreak(self, node): |
paul@320 | 660 | self.stream.write("<div class='break nowrap'>\n") |
paul@320 | 661 | self._keyword("break") |
paul@320 | 662 | self.stream.write("</div>\n") |
paul@320 | 663 | |
paul@320 | 664 | def visitClass(self, node): |
paul@353 | 665 | if not used_by_unit(node): |
paul@370 | 666 | self._docstring('"Class %s not generated."' % node.name) |
paul@353 | 667 | return |
paul@320 | 668 | |
paul@320 | 669 | # Use inspected details where possible. |
paul@320 | 670 | |
paul@354 | 671 | if hasattr(node, "unit"): |
paul@354 | 672 | cls = node.unit |
paul@320 | 673 | bases = cls.bases |
paul@320 | 674 | self.stream.write("<div class='class nowrap' id='%s'>\n" % cls.full_name()) |
paul@320 | 675 | else: |
paul@507 | 676 | print >>sys.stderr, "Warning: class %s not recognised!" % node.name |
paul@320 | 677 | return |
paul@320 | 678 | |
paul@320 | 679 | # Write the declaration line. |
paul@320 | 680 | |
paul@320 | 681 | self.stream.write("<div>\n") |
paul@320 | 682 | self._keyword("class") |
paul@321 | 683 | self._object_name_def(self.module, cls, "class-name") |
paul@320 | 684 | |
paul@320 | 685 | # Suppress the "object" class appearing alone. |
paul@320 | 686 | |
paul@320 | 687 | if bases and not (len(bases) == 1 and bases[0].name == "object"): |
paul@320 | 688 | self.stream.write("(") |
paul@320 | 689 | first = 1 |
paul@320 | 690 | for base in bases: |
paul@320 | 691 | if not first: |
paul@321 | 692 | self.stream.write(", ") |
paul@320 | 693 | |
paul@358 | 694 | self._object_name_ref(base.module, base) |
paul@320 | 695 | |
paul@320 | 696 | first = 0 |
paul@320 | 697 | self.stream.write(")") |
paul@320 | 698 | |
paul@320 | 699 | self.stream.write(":\n") |
paul@320 | 700 | self.stream.write("</div>\n") |
paul@320 | 701 | |
paul@320 | 702 | # Write the docstring and class body. |
paul@320 | 703 | |
paul@320 | 704 | self.stream.write("<div class='body nowrap'>\n") |
paul@320 | 705 | self._doc(node) |
paul@358 | 706 | |
paul@358 | 707 | # NOTE: Some streams may not support tell. |
paul@358 | 708 | |
paul@358 | 709 | x = self.stream.tell() |
paul@358 | 710 | |
paul@358 | 711 | self.default(node.code) |
paul@358 | 712 | |
paul@358 | 713 | # Check for no output. |
paul@358 | 714 | |
paul@358 | 715 | if x == self.stream.tell(): |
paul@358 | 716 | self.visitPass(None) |
paul@358 | 717 | |
paul@320 | 718 | self.stream.write("</div>\n") |
paul@320 | 719 | self.stream.write("</div>\n") |
paul@320 | 720 | |
paul@320 | 721 | def visitContinue(self, node): |
paul@320 | 722 | self.stream.write("<div class='continue nowrap'>\n") |
paul@320 | 723 | self._keyword("continue") |
paul@320 | 724 | self.stream.write("</div>\n") |
paul@320 | 725 | |
paul@320 | 726 | def visitDiscard(self, node): |
paul@320 | 727 | self.stream.write("<div class='discard nowrap'>\n") |
paul@320 | 728 | self.default(node) |
paul@320 | 729 | self.stream.write("</div>\n") |
paul@320 | 730 | |
paul@320 | 731 | def visitFor(self, node): |
paul@320 | 732 | self.stream.write("<div class='if nowrap'>\n") |
paul@320 | 733 | self.stream.write("<div>\n") |
paul@320 | 734 | self._keyword("for") |
paul@320 | 735 | self.dispatch(node.assign) |
paul@353 | 736 | self._keyword("in", 1) |
paul@320 | 737 | self.dispatch(node.list) |
paul@320 | 738 | self.stream.write(":\n") |
paul@320 | 739 | self.stream.write("</div>\n") |
paul@320 | 740 | self.stream.write("<div class='body nowrap'>\n") |
paul@320 | 741 | self.dispatch(node.body) |
paul@320 | 742 | self.stream.write("</div>\n") |
paul@320 | 743 | if node.else_ is not None: |
paul@320 | 744 | self.stream.write("<div>\n") |
paul@353 | 745 | self._keyword("else", trailing=0) |
paul@320 | 746 | self.stream.write(":\n") |
paul@320 | 747 | self.stream.write("</div>\n") |
paul@320 | 748 | self.stream.write("<div class='body nowrap'>\n") |
paul@320 | 749 | self.dispatch(node.else_) |
paul@320 | 750 | self.stream.write("</div>\n") |
paul@320 | 751 | self.stream.write("</div>\n") |
paul@320 | 752 | |
paul@320 | 753 | def visitFrom(self, node): |
paul@320 | 754 | self.stream.write("<div class='from nowrap'>\n") |
paul@320 | 755 | self._keyword("from") |
paul@589 | 756 | self._module_link(node.modname) |
paul@353 | 757 | self._keyword("import", 1) |
paul@320 | 758 | first = 1 |
paul@363 | 759 | for name, alias in node.names: |
paul@320 | 760 | if not first: |
paul@321 | 761 | self.stream.write(", ") |
paul@589 | 762 | self._name(name) |
paul@320 | 763 | if alias: |
paul@353 | 764 | self._keyword("as", 1) |
paul@589 | 765 | self._name(alias) |
paul@320 | 766 | first = 0 |
paul@320 | 767 | self.stream.write("</div>\n") |
paul@320 | 768 | |
paul@320 | 769 | def visitFunction(self, node): |
paul@353 | 770 | if not used_by_unit(node): |
paul@370 | 771 | self._docstring('"Function %s not generated."' % node.name) |
paul@353 | 772 | return |
paul@353 | 773 | |
paul@354 | 774 | if hasattr(node, "unit"): |
paul@354 | 775 | fn = node.unit |
paul@320 | 776 | self.stream.write("<div class='function nowrap' id='%s'>\n" % fn.full_name()) |
paul@320 | 777 | else: |
paul@507 | 778 | print >>sys.stderr, "Warning: function %s not recognised!" % node.name |
paul@320 | 779 | return |
paul@320 | 780 | |
paul@320 | 781 | # Write the declaration line. |
paul@320 | 782 | |
paul@320 | 783 | self.stream.write("<div>\n") |
paul@320 | 784 | self._keyword("def") |
paul@321 | 785 | self._object_name_def(self.module, fn, "function-name") |
paul@320 | 786 | |
paul@320 | 787 | self.stream.write("(") |
paul@354 | 788 | self._parameters(fn, node) |
paul@320 | 789 | self.stream.write(")") |
paul@320 | 790 | self.stream.write(":\n") |
paul@320 | 791 | self.stream.write("</div>\n") |
paul@320 | 792 | |
paul@320 | 793 | self.stream.write("<div class='body nowrap'>\n") |
paul@320 | 794 | self._doc(node) |
paul@320 | 795 | self.dispatch(node.code) |
paul@320 | 796 | self.stream.write("</div>\n") |
paul@320 | 797 | self.stream.write("</div>\n") |
paul@320 | 798 | |
paul@320 | 799 | def visitGlobal(self, node): |
paul@320 | 800 | self.stream.write("<div class='global nowrap'>\n") |
paul@320 | 801 | self._keyword("global") |
paul@320 | 802 | first = 1 |
paul@320 | 803 | for name in node.names: |
paul@320 | 804 | if not first: |
paul@321 | 805 | self.stream.write(", ") |
paul@320 | 806 | self.stream.write(name) |
paul@320 | 807 | first = 0 |
paul@320 | 808 | self.stream.write("</div>\n") |
paul@320 | 809 | |
paul@320 | 810 | def visitIf(self, node): |
paul@320 | 811 | self.stream.write("<div class='if nowrap'>\n") |
paul@320 | 812 | first = 1 |
paul@320 | 813 | for compare, stmt in node.tests: |
paul@320 | 814 | self.stream.write("<div>\n") |
paul@320 | 815 | if first: |
paul@320 | 816 | self._keyword("if") |
paul@320 | 817 | else: |
paul@320 | 818 | self._keyword("elif") |
paul@320 | 819 | self.dispatch(compare) |
paul@320 | 820 | self.stream.write(":\n") |
paul@320 | 821 | self.stream.write("</div>\n") |
paul@320 | 822 | self.stream.write("<div class='body nowrap'>\n") |
paul@320 | 823 | self.dispatch(stmt) |
paul@320 | 824 | self.stream.write("</div>\n") |
paul@320 | 825 | first = 0 |
paul@320 | 826 | if node.else_ is not None: |
paul@320 | 827 | self.stream.write("<div>\n") |
paul@353 | 828 | self._keyword("else", trailing=0) |
paul@353 | 829 | self.stream.write(":\n") |
paul@353 | 830 | self.stream.write("</div>\n") |
paul@353 | 831 | self.stream.write("<div class='body nowrap'>\n") |
paul@353 | 832 | self.dispatch(node.else_) |
paul@353 | 833 | self.stream.write("</div>\n") |
paul@353 | 834 | self.stream.write("</div>\n") |
paul@353 | 835 | |
paul@353 | 836 | def visitImport(self, node): |
paul@353 | 837 | self.stream.write("<div class='import nowrap'>\n") |
paul@353 | 838 | self._keyword("import") |
paul@353 | 839 | first = 1 |
paul@353 | 840 | for name, alias in node.names: |
paul@353 | 841 | if not first: |
paul@353 | 842 | self.stream.write(",\n") |
paul@589 | 843 | self._module_link(name) |
paul@353 | 844 | if alias: |
paul@353 | 845 | self._keyword("as", 1) |
paul@589 | 846 | self._name(alias) |
paul@353 | 847 | first = 0 |
paul@353 | 848 | self.stream.write("</div>\n") |
paul@353 | 849 | |
paul@353 | 850 | def visitPass(self, node): |
paul@353 | 851 | self.stream.write("<div class='pass nowrap'>\n") |
paul@353 | 852 | self._keyword("pass") |
paul@353 | 853 | self.stream.write("</div>\n") |
paul@353 | 854 | |
paul@353 | 855 | def visitPrint(self, node): |
paul@353 | 856 | self.stream.write("<div class='print nowrap'>\n") |
paul@353 | 857 | self._keyword("print") |
paul@353 | 858 | if node.dest is not None: |
paul@353 | 859 | self.stream.write(">>\n") |
paul@353 | 860 | self.dispatch(node.dest) |
paul@518 | 861 | self.stream.write(",\n") |
paul@353 | 862 | for n in node.nodes: |
paul@353 | 863 | self.dispatch(n) |
paul@353 | 864 | self.stream.write(",\n") |
paul@353 | 865 | self.stream.write("</div>\n") |
paul@353 | 866 | |
paul@353 | 867 | def visitPrintnl(self, node): |
paul@353 | 868 | self.stream.write("<div class='printnl nowrap'>\n") |
paul@353 | 869 | self._keyword("print") |
paul@353 | 870 | if node.dest is not None: |
paul@353 | 871 | self.stream.write(">>\n") |
paul@353 | 872 | self.dispatch(node.dest) |
paul@518 | 873 | first = 0 |
paul@518 | 874 | else: |
paul@518 | 875 | first = 1 |
paul@353 | 876 | for n in node.nodes: |
paul@353 | 877 | if not first: |
paul@353 | 878 | self.stream.write(",\n") |
paul@353 | 879 | self.dispatch(n) |
paul@353 | 880 | first = 0 |
paul@353 | 881 | self.stream.write("</div>\n") |
paul@353 | 882 | |
paul@353 | 883 | def visitRaise(self, node): |
paul@353 | 884 | self.stream.write("<div class='raise nowrap'>\n") |
paul@353 | 885 | self._keyword("raise") |
paul@363 | 886 | if node.expr1 is not None: |
paul@363 | 887 | self.dispatch(node.expr1) |
paul@353 | 888 | if node.expr2 is not None: |
paul@353 | 889 | self.stream.write(",\n") |
paul@353 | 890 | self.dispatch(node.expr2) |
paul@353 | 891 | if node.expr3 is not None: |
paul@353 | 892 | self.stream.write(",\n") |
paul@353 | 893 | self.dispatch(node.expr3) |
paul@353 | 894 | self.stream.write("</div>\n") |
paul@353 | 895 | |
paul@353 | 896 | def visitReturn(self, node): |
paul@353 | 897 | self.stream.write("<div class='return nowrap'>\n") |
paul@353 | 898 | self._keyword("return") |
paul@353 | 899 | self.dispatch(node.value) |
paul@353 | 900 | self.stream.write("</div>\n") |
paul@353 | 901 | |
paul@353 | 902 | def visitStmt(self, node): |
paul@353 | 903 | self.stream.write("<div class='stmt nowrap'>\n") |
paul@353 | 904 | self.default(node) |
paul@353 | 905 | self.stream.write("</div>\n") |
paul@353 | 906 | |
paul@353 | 907 | def visitTryExcept(self, node): |
paul@353 | 908 | self.stream.write("<div class='tryexcept nowrap'>\n") |
paul@353 | 909 | self.stream.write("<div>\n") |
paul@353 | 910 | self._keyword("try", trailing=0) |
paul@353 | 911 | self.stream.write(":\n") |
paul@353 | 912 | self.stream.write("</div>\n") |
paul@353 | 913 | self.stream.write("<div class='body nowrap'>\n") |
paul@353 | 914 | self.dispatch(node.body) |
paul@353 | 915 | self.stream.write("</div>\n") |
paul@353 | 916 | for spec, assign, statement in node.handlers: |
paul@353 | 917 | self.stream.write("<div>\n") |
paul@353 | 918 | self._keyword("except") |
paul@353 | 919 | if spec is not None: |
paul@353 | 920 | self.dispatch(spec) |
paul@353 | 921 | if assign is not None: |
paul@353 | 922 | self.stream.write(",\n") |
paul@353 | 923 | self.dispatch(assign) |
paul@353 | 924 | self.stream.write(":\n") |
paul@353 | 925 | self.stream.write("</div>\n") |
paul@353 | 926 | self.stream.write("<div class='body nowrap'>\n") |
paul@353 | 927 | self.dispatch(statement) |
paul@353 | 928 | self.stream.write("</div>\n") |
paul@353 | 929 | if node.else_ is not None: |
paul@353 | 930 | self.stream.write("<div>\n") |
paul@353 | 931 | self._keyword("else", trailing=0) |
paul@353 | 932 | self.stream.write(":\n") |
paul@353 | 933 | self.stream.write("</div>\n") |
paul@353 | 934 | self.stream.write("<div class='body nowrap'>\n") |
paul@353 | 935 | self.dispatch(node.else_) |
paul@353 | 936 | self.stream.write("</div>\n") |
paul@353 | 937 | self.stream.write("</div>\n") |
paul@353 | 938 | |
paul@353 | 939 | def visitTryFinally(self, node): |
paul@353 | 940 | self.stream.write("<div class='tryfinally nowrap'>\n") |
paul@353 | 941 | self.stream.write("<div>\n") |
paul@353 | 942 | self._keyword("try", trailing=0) |
paul@353 | 943 | self.stream.write(":\n") |
paul@353 | 944 | self.stream.write("</div>\n") |
paul@353 | 945 | self.stream.write("<div class='body nowrap'>\n") |
paul@353 | 946 | self.dispatch(node.body) |
paul@353 | 947 | self.stream.write("</div>\n") |
paul@353 | 948 | self.stream.write("<div>\n") |
paul@353 | 949 | self._keyword("finally", trailing=0) |
paul@353 | 950 | self.stream.write(":\n") |
paul@353 | 951 | self.stream.write("</div>\n") |
paul@353 | 952 | self.stream.write("<div class='body nowrap'>\n") |
paul@353 | 953 | self.dispatch(node.final) |
paul@353 | 954 | self.stream.write("</div>\n") |
paul@353 | 955 | self.stream.write("</div>\n") |
paul@353 | 956 | |
paul@353 | 957 | def visitWhile(self, node): |
paul@353 | 958 | self.stream.write("<div class='while nowrap'>\n") |
paul@353 | 959 | self.stream.write("<div>\n") |
paul@353 | 960 | self._keyword("while") |
paul@353 | 961 | self.dispatch(node.test) |
paul@353 | 962 | self.stream.write(":\n") |
paul@353 | 963 | self.stream.write("</div>\n") |
paul@353 | 964 | self.stream.write("<div class='body nowrap'>\n") |
paul@353 | 965 | self.dispatch(node.body) |
paul@353 | 966 | self.stream.write("</div>\n") |
paul@353 | 967 | if node.else_ is not None: |
paul@353 | 968 | self.stream.write("<div>\n") |
paul@353 | 969 | self._keyword("else", trailing=0) |
paul@320 | 970 | self.stream.write(":\n") |
paul@320 | 971 | self.stream.write("</div>\n") |
paul@320 | 972 | self.stream.write("<div class='body nowrap'>\n") |
paul@320 | 973 | self.dispatch(node.else_) |
paul@320 | 974 | self.stream.write("</div>\n") |
paul@320 | 975 | self.stream.write("</div>\n") |
paul@320 | 976 | |
paul@496 | 977 | def visitYield(self, node): |
paul@496 | 978 | self.stream.write("<div class='yield nowrap'>\n") |
paul@496 | 979 | self._keyword("yield") |
paul@496 | 980 | self.dispatch(node.value) |
paul@496 | 981 | self.stream.write("</div>\n") |
paul@496 | 982 | |
paul@353 | 983 | # Expression-related helper methods. |
paul@353 | 984 | |
paul@588 | 985 | def _visitBitBinary(self, node, symbol): |
paul@588 | 986 | name = operator_functions[node.__class__.__name__] |
paul@355 | 987 | self._span_start(name) |
paul@353 | 988 | first = 1 |
paul@353 | 989 | for node in node.nodes: |
paul@353 | 990 | if not first: |
paul@371 | 991 | self._op(symbol, name, 1) |
paul@353 | 992 | self.dispatch(node) |
paul@353 | 993 | first = 0 |
paul@355 | 994 | self._span_end() |
paul@353 | 995 | |
paul@588 | 996 | def _visitBinary(self, node, symbol): |
paul@588 | 997 | name = operator_functions[node.__class__.__name__] |
paul@355 | 998 | self._span_start(name) |
paul@353 | 999 | self.dispatch(node.left) |
paul@371 | 1000 | self._op(symbol, name, 1) |
paul@353 | 1001 | self.dispatch(node.right) |
paul@355 | 1002 | self._span_end() |
paul@353 | 1003 | |
paul@588 | 1004 | def _visitUnary(self, node, symbol): |
paul@588 | 1005 | name = operator_functions[node.__class__.__name__] |
paul@355 | 1006 | self._span_start(name) |
paul@529 | 1007 | self._op(symbol, name, trailing=0) |
paul@353 | 1008 | self.dispatch(node.expr) |
paul@355 | 1009 | self._span_end() |
paul@353 | 1010 | |
paul@353 | 1011 | # Expressions. |
paul@353 | 1012 | |
paul@353 | 1013 | def visitAdd(self, node): |
paul@588 | 1014 | self._visitBinary(node, "+") |
paul@353 | 1015 | |
paul@353 | 1016 | def visitAnd(self, node): |
paul@355 | 1017 | self._span_start("and") |
paul@353 | 1018 | first = 1 |
paul@353 | 1019 | for n in node.nodes: |
paul@353 | 1020 | if not first: |
paul@353 | 1021 | self._keyword("and", 1) |
paul@353 | 1022 | self.dispatch(n) |
paul@353 | 1023 | first = 0 |
paul@355 | 1024 | self._span_end() |
paul@353 | 1025 | |
paul@353 | 1026 | def visitAssAttr(self, node): |
paul@536 | 1027 | possible_types = self.possible_accessor_types(node, defining_users=0) |
paul@582 | 1028 | target_names = set(["%s%s" % (is_static and "static " or "", target_name) |
paul@582 | 1029 | for target_name, is_static in possible_types]) |
paul@536 | 1030 | attributes = self._get_attributes(possible_types, node.attrname) |
paul@536 | 1031 | |
paul@567 | 1032 | wraps_getattr = isinstance(node.expr, compiler.ast.Getattr) |
paul@567 | 1033 | |
paul@567 | 1034 | if not wraps_getattr: |
paul@567 | 1035 | self._span_start("assattr") |
paul@567 | 1036 | self._accessor_start(target_names) |
paul@353 | 1037 | self.dispatch(node.expr) |
paul@567 | 1038 | if not wraps_getattr: |
paul@567 | 1039 | self._accessor_end(target_names) |
paul@353 | 1040 | self.stream.write(".") |
paul@583 | 1041 | self._attribute_start(node.attrname, self._attributes_to_attribute_names(attributes, node.attrname)) |
paul@523 | 1042 | self._span(node.attrname, "attrname" + (not target_names and " no-targets" or "")) |
paul@536 | 1043 | self._attribute_end(attributes) |
paul@567 | 1044 | if not wraps_getattr: |
paul@567 | 1045 | self._span_end() |
paul@353 | 1046 | |
paul@353 | 1047 | def visitAssList(self, node): |
paul@355 | 1048 | self._span_start("list") |
paul@353 | 1049 | self.stream.write("[") |
paul@353 | 1050 | self._sequence(node) |
paul@353 | 1051 | self.stream.write("]") |
paul@355 | 1052 | self._span_end() |
paul@353 | 1053 | |
paul@353 | 1054 | def visitAssName(self, node): |
paul@354 | 1055 | self._assname(node.name, node) |
paul@353 | 1056 | |
paul@353 | 1057 | def visitAssTuple(self, node): |
paul@355 | 1058 | self._span_start("tuple") |
paul@353 | 1059 | self.stream.write("(") |
paul@353 | 1060 | self._sequence(node) |
paul@353 | 1061 | self.stream.write(")") |
paul@355 | 1062 | self._span_end() |
paul@353 | 1063 | |
paul@353 | 1064 | def visitBitand(self, node): |
paul@588 | 1065 | self._visitBitBinary(node, "&") |
paul@353 | 1066 | |
paul@437 | 1067 | def visitBitor(self, node): |
paul@588 | 1068 | self._visitBitBinary(node, "|") |
paul@437 | 1069 | |
paul@437 | 1070 | def visitBitxor(self, node): |
paul@588 | 1071 | self._visitBitBinary(node, "^") |
paul@437 | 1072 | |
paul@353 | 1073 | def visitCallFunc(self, node): |
paul@355 | 1074 | self._span_start("callfunc") |
paul@353 | 1075 | self.dispatch(node.node) |
paul@355 | 1076 | self._span_start("call") |
paul@353 | 1077 | self.stream.write("(") |
paul@353 | 1078 | first = 1 |
paul@353 | 1079 | for arg in node.args: |
paul@353 | 1080 | if not first: |
paul@353 | 1081 | self.stream.write(", ") |
paul@353 | 1082 | self.dispatch(arg) |
paul@353 | 1083 | first = 0 |
paul@353 | 1084 | if node.star_args is not None: |
paul@353 | 1085 | if not first: |
paul@353 | 1086 | self.stream.write(", *") |
paul@353 | 1087 | self.dispatch(node.star_args) |
paul@353 | 1088 | first = 0 |
paul@353 | 1089 | if node.dstar_args is not None: |
paul@353 | 1090 | if not first: |
paul@353 | 1091 | self.stream.write(", **") |
paul@353 | 1092 | self.dispatch(node.dstar_args) |
paul@353 | 1093 | first = 0 |
paul@353 | 1094 | self.stream.write(")") |
paul@355 | 1095 | self._span_end() |
paul@355 | 1096 | self._span_end() |
paul@353 | 1097 | |
paul@353 | 1098 | def visitCompare(self, node): |
paul@355 | 1099 | self._span_start("compare") |
paul@353 | 1100 | self.dispatch(node.expr) |
paul@353 | 1101 | for op_name, expr in node.ops: |
paul@371 | 1102 | self._op(op_name, operator_functions.get(op_name), 1) |
paul@353 | 1103 | self.dispatch(expr) |
paul@355 | 1104 | self._span_end() |
paul@353 | 1105 | |
paul@353 | 1106 | def visitConst(self, node): |
paul@353 | 1107 | if isinstance(node.value, (str, unicode)): |
paul@355 | 1108 | self._span_start("str") |
paul@353 | 1109 | self.stream.write(self._text(repr(node.value))) |
paul@353 | 1110 | if isinstance(node.value, (str, unicode)): |
paul@355 | 1111 | self._span_end() |
paul@353 | 1112 | |
paul@353 | 1113 | def visitDict(self, node): |
paul@355 | 1114 | self._span_start("dict") |
paul@353 | 1115 | self.stream.write("{") |
paul@353 | 1116 | self._mapping(node) |
paul@353 | 1117 | self.stream.write("}") |
paul@355 | 1118 | self._span_end() |
paul@353 | 1119 | |
paul@353 | 1120 | def visitDiv(self, node): |
paul@588 | 1121 | self._visitBinary(node, "/") |
paul@353 | 1122 | |
paul@353 | 1123 | def visitFloorDiv(self, node): |
paul@588 | 1124 | self._visitBinary(node, "//") |
paul@353 | 1125 | |
paul@353 | 1126 | def visitGetattr(self, node): |
paul@536 | 1127 | possible_types = self.possible_accessor_types(node, defining_users=0) |
paul@582 | 1128 | target_names = set(["%s%s" % (is_static and "static " or "", target_name) |
paul@582 | 1129 | for target_name, is_static in possible_types]) |
paul@536 | 1130 | attributes = self._get_attributes(possible_types, node.attrname) |
paul@536 | 1131 | |
paul@567 | 1132 | wraps_getattr = isinstance(node.expr, compiler.ast.Getattr) |
paul@567 | 1133 | |
paul@567 | 1134 | if not wraps_getattr: |
paul@567 | 1135 | self._span_start("getattr") |
paul@567 | 1136 | self._accessor_start(target_names) |
paul@353 | 1137 | self.dispatch(node.expr) |
paul@567 | 1138 | if not wraps_getattr: |
paul@567 | 1139 | self._accessor_end(target_names) |
paul@353 | 1140 | self.stream.write(".") |
paul@583 | 1141 | self._attribute_start(node.attrname, self._attributes_to_attribute_names(attributes, node.attrname)) |
paul@523 | 1142 | self._span(node.attrname, "attrname" + (not target_names and " no-targets" or "")) |
paul@536 | 1143 | self._attribute_end(attributes) |
paul@567 | 1144 | if not wraps_getattr: |
paul@567 | 1145 | self._span_end() |
paul@353 | 1146 | |
paul@500 | 1147 | def visitGenExpr(self, node): |
paul@500 | 1148 | self._span_start("genexpr") |
paul@500 | 1149 | self.stream.write("(") |
paul@500 | 1150 | self.dispatch(node.code) |
paul@500 | 1151 | self.stream.write(")") |
paul@500 | 1152 | self._span_end() |
paul@500 | 1153 | |
paul@500 | 1154 | def visitGenExprFor(self, node): |
paul@500 | 1155 | self._span_start("genexprfor") |
paul@500 | 1156 | self._keyword("for", 1) |
paul@500 | 1157 | self._span_start("item") |
paul@500 | 1158 | self.dispatch(node.assign) |
paul@500 | 1159 | self._span_end() |
paul@500 | 1160 | self._keyword("in", 1) |
paul@500 | 1161 | self._span_start("collection") |
paul@500 | 1162 | self.dispatch(node.iter) |
paul@500 | 1163 | self._span_end() |
paul@500 | 1164 | for if_ in node.ifs: |
paul@500 | 1165 | self.dispatch(if_) |
paul@500 | 1166 | self._span_end() |
paul@500 | 1167 | |
paul@500 | 1168 | def visitGenExprIf(self, node): |
paul@500 | 1169 | self._span_start("genexprif") |
paul@500 | 1170 | self._span_start("conditional") |
paul@500 | 1171 | self._keyword("if", 1) |
paul@500 | 1172 | self.dispatch(node.test) |
paul@500 | 1173 | self._span_end() |
paul@500 | 1174 | self._span_end() |
paul@500 | 1175 | |
paul@500 | 1176 | def visitGenExprInner(self, node): |
paul@500 | 1177 | self._span_start("genexprinner") |
paul@500 | 1178 | self.dispatch(node.expr) |
paul@500 | 1179 | for qual in node.quals: |
paul@500 | 1180 | self.dispatch(qual) |
paul@500 | 1181 | self._span_end() |
paul@500 | 1182 | |
paul@496 | 1183 | def visitIfExp(self, node): |
paul@496 | 1184 | self._span_start("ifexp") |
paul@496 | 1185 | self.dispatch(node.then) |
paul@512 | 1186 | self._keyword("if", 1) |
paul@496 | 1187 | self.dispatch(node.test) |
paul@512 | 1188 | self._keyword("else", 1) |
paul@496 | 1189 | self.dispatch(node.else_) |
paul@496 | 1190 | self._span_end() |
paul@496 | 1191 | |
paul@513 | 1192 | def visitInvert(self, node): |
paul@588 | 1193 | self._visitUnary(node, "~") |
paul@513 | 1194 | |
paul@353 | 1195 | def visitKeyword(self, node): |
paul@355 | 1196 | self._span_start("keyword-arg") |
paul@353 | 1197 | self.stream.write(node.name) |
paul@353 | 1198 | self.stream.write("=") |
paul@353 | 1199 | self.dispatch(node.expr) |
paul@355 | 1200 | self._span_end() |
paul@353 | 1201 | |
paul@353 | 1202 | def visitLambda(self, node): |
paul@354 | 1203 | if hasattr(node, "unit"): |
paul@354 | 1204 | fn = node.unit |
paul@353 | 1205 | else: |
paul@507 | 1206 | print >>sys.stderr, "Warning: function %s not recognised!" % node.name |
paul@353 | 1207 | return |
paul@353 | 1208 | |
paul@355 | 1209 | self._span_start("lambda") |
paul@353 | 1210 | self._keyword("lambda") |
paul@354 | 1211 | self._parameters(fn, node) |
paul@355 | 1212 | self.stream.write(": ") |
paul@355 | 1213 | self._span_start("code") |
paul@353 | 1214 | self.dispatch(node.code) |
paul@355 | 1215 | self._span_end() |
paul@355 | 1216 | self._span_end() |
paul@353 | 1217 | |
paul@481 | 1218 | def visitLeftShift(self, node): |
paul@588 | 1219 | self._visitBinary(node, "<<") |
paul@481 | 1220 | |
paul@353 | 1221 | visitList = visitAssList |
paul@353 | 1222 | |
paul@353 | 1223 | def visitListComp(self, node): |
paul@355 | 1224 | self._span_start("listcomp") |
paul@353 | 1225 | self.stream.write("[") |
paul@353 | 1226 | self.dispatch(node.expr) |
paul@353 | 1227 | for qual in node.quals: |
paul@353 | 1228 | self.dispatch(qual) |
paul@353 | 1229 | self.stream.write("]") |
paul@355 | 1230 | self._span_end() |
paul@353 | 1231 | |
paul@353 | 1232 | def visitListCompFor(self, node): |
paul@355 | 1233 | self._span_start("listcompfor") |
paul@365 | 1234 | self._keyword("for", 1) |
paul@355 | 1235 | self._span_start("item") |
paul@353 | 1236 | self.dispatch(node.assign) |
paul@355 | 1237 | self._span_end() |
paul@353 | 1238 | self._keyword("in", 1) |
paul@355 | 1239 | self._span_start("collection") |
paul@353 | 1240 | self.dispatch(node.list) |
paul@355 | 1241 | self._span_end() |
paul@353 | 1242 | for if_ in node.ifs: |
paul@353 | 1243 | self.dispatch(if_) |
paul@355 | 1244 | self._span_end() |
paul@353 | 1245 | |
paul@353 | 1246 | def visitListCompIf(self, node): |
paul@355 | 1247 | self._span_start("listcompif") |
paul@355 | 1248 | self._span_start("conditional") |
paul@353 | 1249 | self._keyword("if", 1) |
paul@353 | 1250 | self.dispatch(node.test) |
paul@355 | 1251 | self._span_end() |
paul@355 | 1252 | self._span_end() |
paul@353 | 1253 | |
paul@353 | 1254 | def visitMod(self, node): |
paul@588 | 1255 | self._visitBinary(node, "%") |
paul@353 | 1256 | |
paul@353 | 1257 | def visitMul(self, node): |
paul@588 | 1258 | self._visitBinary(node, "*") |
paul@353 | 1259 | |
paul@353 | 1260 | def visitName(self, node): |
paul@353 | 1261 | if hasattr(node, "_scope"): |
paul@353 | 1262 | scope = node._scope |
paul@353 | 1263 | self._name_start() |
paul@353 | 1264 | self.stream.write(node.name) |
paul@353 | 1265 | self._popup_start() |
paul@583 | 1266 | self._scope(node._scope, node._attr) |
paul@353 | 1267 | self._popup_end() |
paul@353 | 1268 | self._name_end() |
paul@353 | 1269 | else: |
paul@355 | 1270 | self._span(node.name) |
paul@353 | 1271 | |
paul@358 | 1272 | def visitNot(self, node): |
paul@358 | 1273 | self._span_start("not") |
paul@358 | 1274 | self._keyword("not") |
paul@358 | 1275 | self.dispatch(node.expr) |
paul@358 | 1276 | self._span_end() |
paul@358 | 1277 | |
paul@358 | 1278 | def visitOr(self, node): |
paul@358 | 1279 | self._span_start("or") |
paul@358 | 1280 | first = 1 |
paul@358 | 1281 | for n in node.nodes: |
paul@358 | 1282 | if not first: |
paul@358 | 1283 | self._keyword("or", 1) |
paul@358 | 1284 | self.dispatch(n) |
paul@358 | 1285 | first = 0 |
paul@358 | 1286 | self._span_end() |
paul@358 | 1287 | |
paul@358 | 1288 | def visitPower(self, node): |
paul@588 | 1289 | self._visitBinary(node, "**") |
paul@358 | 1290 | |
paul@481 | 1291 | def visitRightShift(self, node): |
paul@588 | 1292 | self._visitBinary(node, ">>") |
paul@481 | 1293 | |
paul@358 | 1294 | def visitSlice(self, node): |
paul@358 | 1295 | self._span_start("slice") |
paul@358 | 1296 | self.dispatch(node.expr) |
paul@358 | 1297 | self.stream.write("[") |
paul@358 | 1298 | if node.lower: |
paul@358 | 1299 | self.dispatch(node.lower) |
paul@358 | 1300 | self.stream.write(":") |
paul@358 | 1301 | if node.upper: |
paul@358 | 1302 | self.dispatch(node.upper) |
paul@358 | 1303 | # NOTE: Step? |
paul@358 | 1304 | self.stream.write("]") |
paul@358 | 1305 | self._span_end() |
paul@358 | 1306 | |
paul@358 | 1307 | def visitSliceobj(self, node): |
paul@358 | 1308 | self._span_start("sliceobj") |
paul@358 | 1309 | first = 1 |
paul@358 | 1310 | for n in node.nodes: |
paul@358 | 1311 | if not first: |
paul@358 | 1312 | self.stream.write(":") |
paul@358 | 1313 | self.dispatch(n) |
paul@358 | 1314 | self._span_end() |
paul@358 | 1315 | |
paul@358 | 1316 | def visitSub(self, node): |
paul@588 | 1317 | self._visitBinary(node, "-") |
paul@358 | 1318 | |
paul@358 | 1319 | def visitSubscript(self, node): |
paul@358 | 1320 | self._span_start("subscript") |
paul@358 | 1321 | self.dispatch(node.expr) |
paul@358 | 1322 | self.stream.write("[") |
paul@358 | 1323 | first = 1 |
paul@358 | 1324 | for sub in node.subs: |
paul@358 | 1325 | if not first: |
paul@358 | 1326 | self.stream.write(", ") |
paul@358 | 1327 | self.dispatch(sub) |
paul@358 | 1328 | first = 0 |
paul@358 | 1329 | self.stream.write("]") |
paul@358 | 1330 | self._span_end() |
paul@358 | 1331 | |
paul@358 | 1332 | visitTuple = visitAssTuple |
paul@358 | 1333 | |
paul@358 | 1334 | def visitUnaryAdd(self, node): |
paul@588 | 1335 | self._visitUnary(node, "+") |
paul@358 | 1336 | |
paul@358 | 1337 | def visitUnarySub(self, node): |
paul@588 | 1338 | self._visitUnary(node, "-") |
paul@358 | 1339 | |
paul@320 | 1340 | # Output preparation methods. |
paul@320 | 1341 | |
paul@320 | 1342 | def _sequence(self, node): |
paul@320 | 1343 | first = 1 |
paul@320 | 1344 | for n in node.nodes: |
paul@320 | 1345 | if not first: |
paul@321 | 1346 | self.stream.write(", ") |
paul@320 | 1347 | self.dispatch(n) |
paul@320 | 1348 | first = 0 |
paul@320 | 1349 | |
paul@320 | 1350 | def _mapping(self, node): |
paul@320 | 1351 | first = 1 |
paul@320 | 1352 | for k, v in node.items: |
paul@320 | 1353 | if not first: |
paul@321 | 1354 | self.stream.write(", ") |
paul@320 | 1355 | self.dispatch(k) |
paul@321 | 1356 | self.stream.write(" : ") |
paul@320 | 1357 | self.dispatch(v) |
paul@320 | 1358 | first = 0 |
paul@320 | 1359 | |
paul@354 | 1360 | def _parameters(self, fn, node): |
paul@320 | 1361 | nparams = len(fn.positional_names) |
paul@320 | 1362 | ndefaults = len(fn.defaults) |
paul@320 | 1363 | first_with_default = nparams - ndefaults |
paul@320 | 1364 | |
paul@321 | 1365 | first = 1 |
paul@320 | 1366 | for n, param in enumerate(fn.positional_names): |
paul@320 | 1367 | if not first: |
paul@321 | 1368 | self.stream.write(", ") |
paul@370 | 1369 | |
paul@370 | 1370 | # Handle tuple parameters. |
paul@370 | 1371 | |
paul@370 | 1372 | if isinstance(param, tuple): |
paul@370 | 1373 | self._tuple_parameter(param, node) |
paul@370 | 1374 | else: |
paul@370 | 1375 | self._assname(param, node) |
paul@370 | 1376 | |
paul@320 | 1377 | n_default = n - first_with_default |
paul@320 | 1378 | if n_default >= 0: |
paul@320 | 1379 | self._default(fn.defaults[n_default]) |
paul@321 | 1380 | first = 0 |
paul@320 | 1381 | |
paul@320 | 1382 | if fn.has_star: |
paul@320 | 1383 | if not first: |
paul@321 | 1384 | self.stream.write(", *") |
paul@320 | 1385 | self._name(fn.star_name) |
paul@320 | 1386 | |
paul@320 | 1387 | if fn.has_dstar: |
paul@320 | 1388 | if not first: |
paul@321 | 1389 | self.stream.write(", **") |
paul@320 | 1390 | self._name(fn.dstar_name) |
paul@320 | 1391 | |
paul@370 | 1392 | def _tuple_parameter(self, parameters, node): |
paul@370 | 1393 | self.stream.write("(") |
paul@370 | 1394 | |
paul@370 | 1395 | first = 1 |
paul@370 | 1396 | for param in parameters: |
paul@370 | 1397 | if not first: |
paul@370 | 1398 | self.stream.write(", ") |
paul@370 | 1399 | |
paul@370 | 1400 | # Handle tuples. |
paul@370 | 1401 | |
paul@370 | 1402 | if isinstance(param, tuple): |
paul@370 | 1403 | self._tuple_parameter(param, node) |
paul@370 | 1404 | else: |
paul@370 | 1405 | self._assname(param, node) |
paul@370 | 1406 | |
paul@370 | 1407 | first = 0 |
paul@370 | 1408 | |
paul@370 | 1409 | self.stream.write(")") |
paul@370 | 1410 | |
paul@320 | 1411 | def _default(self, default): |
paul@321 | 1412 | self.stream.write("=") |
paul@320 | 1413 | self.dispatch(default) |
paul@320 | 1414 | |
paul@318 | 1415 | # Convenience functions. |
paul@318 | 1416 | |
paul@357 | 1417 | def summarise(module, program, filename): |
paul@318 | 1418 | stream = open(filename, "wb") |
paul@318 | 1419 | try: |
paul@357 | 1420 | summary = Summary(module, program) |
paul@320 | 1421 | summary.to_stream(stream) |
paul@320 | 1422 | finally: |
paul@320 | 1423 | stream.close() |
paul@320 | 1424 | |
paul@357 | 1425 | def annotate(module, program, filename): |
paul@320 | 1426 | stream = open(filename, "wb") |
paul@320 | 1427 | try: |
paul@357 | 1428 | source = AnnotatedSource(module, program) |
paul@320 | 1429 | source.to_stream(stream) |
paul@318 | 1430 | finally: |
paul@318 | 1431 | stream.close() |
paul@318 | 1432 | |
paul@480 | 1433 | def interfaces(program, filename): |
paul@480 | 1434 | stream = open(filename, "wb") |
paul@480 | 1435 | try: |
paul@480 | 1436 | source = Interfaces(program) |
paul@480 | 1437 | source.to_stream(stream) |
paul@480 | 1438 | finally: |
paul@480 | 1439 | stream.close() |
paul@480 | 1440 | |
paul@357 | 1441 | def report(program, directory): |
paul@353 | 1442 | if not exists(directory): |
paul@353 | 1443 | os.mkdir(directory) |
paul@353 | 1444 | |
paul@357 | 1445 | for module in program.get_importer().get_modules(): |
paul@357 | 1446 | annotate(module, program, join(directory, "%s%sxhtml" % (module.full_name(), extsep))) |
paul@357 | 1447 | summarise(module, program, join(directory, "%s-summary%sxhtml" % (module.full_name(), extsep))) |
paul@353 | 1448 | |
paul@480 | 1449 | interfaces(program, join(directory, "-interfaces%sxhtml" % extsep)) |
paul@480 | 1450 | |
paul@318 | 1451 | # vim: tabstop=4 expandtab shiftwidth=4 |