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@591 | 338 | first = True |
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@591 | 343 | first = False |
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@591 | 353 | return False |
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@591 | 362 | return True |
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@592 | 390 | have_instances = False |
paul@583 | 391 | values = [] |
paul@583 | 392 | for v in attr.get_values(): |
paul@585 | 393 | if isinstance(v, Const): |
paul@586 | 394 | values.append((repr(v.get_value()), v)) |
paul@585 | 395 | elif not isinstance(v, Instance): |
paul@583 | 396 | values.append((v.full_name(), v)) |
paul@592 | 397 | else: |
paul@592 | 398 | have_instances = True |
paul@592 | 399 | |
paul@592 | 400 | if have_instances: |
paul@592 | 401 | values.append(("...", None)) |
paul@583 | 402 | |
paul@583 | 403 | values.sort() |
paul@583 | 404 | return values |
paul@583 | 405 | |
paul@583 | 406 | def _attributes_to_attribute_names(self, attributes, attrname): |
paul@583 | 407 | |
paul@583 | 408 | "Get the output form of the 'attributes'." |
paul@583 | 409 | |
paul@583 | 410 | output = [] |
paul@583 | 411 | for value, target, target_name in attributes: |
paul@583 | 412 | if value and not isinstance(value, Instance): |
paul@583 | 413 | fullname = value.full_name() |
paul@583 | 414 | else: |
paul@583 | 415 | fullname = target_name + "." + attrname |
paul@583 | 416 | output.append((fullname, value)) |
paul@583 | 417 | |
paul@583 | 418 | output.sort() |
paul@583 | 419 | return output |
paul@583 | 420 | |
paul@536 | 421 | def _attribute_start(self, attrname, attributes): |
paul@536 | 422 | if attributes: |
paul@536 | 423 | self._span_start("attr") |
paul@536 | 424 | self._popup_start("attributes-popup") |
paul@536 | 425 | self._names_list_start("attributes", "attrnames") |
paul@583 | 426 | self._attribute_list(attributes) |
paul@536 | 427 | self._names_list_end() |
paul@536 | 428 | self._popup_end() |
paul@536 | 429 | |
paul@583 | 430 | def _attribute_list(self, attributes): |
paul@583 | 431 | |
paul@583 | 432 | # Mix links to attributes with labels indicating undetermined |
paul@583 | 433 | # attributes. |
paul@583 | 434 | |
paul@583 | 435 | last = None |
paul@583 | 436 | for fullname, value in attributes: |
paul@583 | 437 | if fullname != last: |
paul@583 | 438 | if last is not None: |
paul@583 | 439 | self.stream.write("<br />") |
paul@583 | 440 | if value is not None and not isinstance(value, Instance): |
paul@583 | 441 | self._object_name_ref(value.module, value, fullname, classes="attribute-name") |
paul@583 | 442 | else: |
paul@586 | 443 | self.stream.write(self._text(fullname)) |
paul@583 | 444 | last = fullname |
paul@583 | 445 | |
paul@536 | 446 | def _attribute_end(self, attributes): |
paul@536 | 447 | if attributes: |
paul@536 | 448 | self._span_end() |
paul@536 | 449 | |
paul@536 | 450 | def _get_attributes(self, possible_types, attrname): |
paul@536 | 451 | objtable = self.program.get_object_table() |
paul@536 | 452 | attributes = [] |
paul@536 | 453 | for target_name, is_static in possible_types: |
paul@536 | 454 | target = objtable.get_object(target_name) |
paul@536 | 455 | try: |
paul@536 | 456 | attr = objtable.access(target_name, attrname) |
paul@536 | 457 | except TableError: |
paul@536 | 458 | continue |
paul@536 | 459 | if attr.is_static_attribute(): |
paul@536 | 460 | for v in attr.get_values(): |
paul@536 | 461 | attributes.append((v, target, target_name)) |
paul@536 | 462 | else: |
paul@536 | 463 | attributes.append((None, target, target_name)) |
paul@536 | 464 | |
paul@536 | 465 | return attributes |
paul@536 | 466 | |
paul@318 | 467 | # Summary classes. |
paul@318 | 468 | |
paul@320 | 469 | class Summary(Writer): |
paul@318 | 470 | |
paul@319 | 471 | "Summarise classes and attributes in modules." |
paul@319 | 472 | |
paul@357 | 473 | def __init__(self, module, program): |
paul@319 | 474 | self.module = module |
paul@357 | 475 | self.program = program |
paul@318 | 476 | |
paul@319 | 477 | def to_stream(self, stream): |
paul@319 | 478 | |
paul@319 | 479 | "Write the summary to the given 'stream'." |
paul@319 | 480 | |
paul@319 | 481 | self.stream = stream |
paul@480 | 482 | self.stream.write(html_header % { |
paul@480 | 483 | "title" : "Module: %s" % self.module.full_name() |
paul@480 | 484 | }) |
paul@319 | 485 | self._write_classes(self.module) |
paul@318 | 486 | self.stream.write(html_footer) |
paul@318 | 487 | |
paul@318 | 488 | def _write_classes(self, module): |
paul@318 | 489 | |
paul@318 | 490 | all_classes = {} |
paul@318 | 491 | |
paul@318 | 492 | for obj in self.module.all_objects: |
paul@318 | 493 | if isinstance(obj, Class): |
paul@318 | 494 | all_classes[obj.name] = obj |
paul@318 | 495 | |
paul@361 | 496 | if all_classes: |
paul@361 | 497 | |
paul@361 | 498 | all_class_names = all_classes.keys() |
paul@361 | 499 | all_class_names.sort() |
paul@318 | 500 | |
paul@361 | 501 | self.stream.write("<table cellspacing='5' cellpadding='5'>\n") |
paul@361 | 502 | self.stream.write("<thead>\n") |
paul@361 | 503 | self.stream.write("<tr>\n") |
paul@361 | 504 | self.stream.write("<th>Classes</th><th>Attributes</th>\n") |
paul@361 | 505 | self.stream.write("</tr>\n") |
paul@361 | 506 | self.stream.write("</thead>\n") |
paul@318 | 507 | |
paul@361 | 508 | for name in all_class_names: |
paul@361 | 509 | self._write_class(all_classes[name]) |
paul@361 | 510 | |
paul@361 | 511 | self.stream.write("</table>\n") |
paul@318 | 512 | |
paul@318 | 513 | def _write_class(self, obj): |
paul@318 | 514 | |
paul@318 | 515 | # Write the class... |
paul@318 | 516 | |
paul@318 | 517 | self.stream.write("<tbody class='class'>\n") |
paul@318 | 518 | self.stream.write("<tr>\n") |
paul@361 | 519 | self.stream.write("<th class='summary-class' id='%s' rowspan='2'>" % self._attr(obj.full_name())) |
paul@361 | 520 | self._object_name_ref(self.module, obj, classes="class-name") |
paul@318 | 521 | self.stream.write("</th>\n") |
paul@318 | 522 | |
paul@361 | 523 | # ...and instance attribute names in order... |
paul@318 | 524 | |
paul@358 | 525 | attrs = obj.instance_attributes().values() |
paul@358 | 526 | attrs.sort(cmp=lambda x, y: cmp(x.position, y.position)) |
paul@318 | 527 | |
paul@361 | 528 | if attrs: |
paul@361 | 529 | for attr in attrs: |
paul@361 | 530 | self.stream.write("<td class='summary-attr'>%s</td>\n" % self._text(attr.name)) |
paul@361 | 531 | else: |
paul@361 | 532 | self.stream.write("<td class='summary-attr-absent'>None</td>\n") |
paul@361 | 533 | |
paul@361 | 534 | self.stream.write("</tr>\n") |
paul@361 | 535 | self.stream.write("<tr>\n") |
paul@361 | 536 | |
paul@361 | 537 | # ...and class attribute names in order. |
paul@361 | 538 | |
paul@361 | 539 | attrs = obj.class_attributes().values() |
paul@361 | 540 | attrs.sort(cmp=lambda x, y: cmp(x.position, y.position)) |
paul@361 | 541 | |
paul@361 | 542 | if attrs: |
paul@361 | 543 | for attr in attrs: |
paul@363 | 544 | if attr.is_strict_constant(): |
paul@363 | 545 | value = attr.get_value() |
paul@473 | 546 | if not isinstance(value, Const): |
paul@473 | 547 | self.stream.write("<td class='summary-class-attr' id='%s'>" % self._attr(value.full_name())) |
paul@473 | 548 | self._object_name_ref(self.module, value, attr.name, classes="summary-ref") |
paul@473 | 549 | self.stream.write("</td>\n") |
paul@473 | 550 | else: |
paul@473 | 551 | self.stream.write("<td class='summary-class-attr'>%s</td>\n" % self._text(attr.name)) |
paul@361 | 552 | else: |
paul@361 | 553 | self.stream.write("<td class='summary-class-attr'>%s</td>\n" % self._text(attr.name)) |
paul@361 | 554 | else: |
paul@361 | 555 | self.stream.write("<td class='summary-class-attr-absent'>None</td>\n") |
paul@358 | 556 | |
paul@318 | 557 | self.stream.write("</tr>\n") |
paul@318 | 558 | self.stream.write("</tbody>\n") |
paul@318 | 559 | |
paul@480 | 560 | class Interfaces(Writer): |
paul@480 | 561 | |
paul@480 | 562 | "Summarise the interfaces used by reading the object table cache." |
paul@480 | 563 | |
paul@480 | 564 | def __init__(self, program): |
paul@480 | 565 | self.program = program |
paul@480 | 566 | |
paul@480 | 567 | def to_stream(self, stream): |
paul@480 | 568 | |
paul@480 | 569 | "Write the summary to the given 'stream'." |
paul@480 | 570 | |
paul@480 | 571 | self.stream = stream |
paul@480 | 572 | self.stream.write(html_header % { |
paul@480 | 573 | "title" : "Interfaces" |
paul@480 | 574 | }) |
paul@480 | 575 | self._write_interfaces() |
paul@480 | 576 | self.stream.write(html_footer) |
paul@480 | 577 | |
paul@480 | 578 | def _write_interfaces(self): |
paul@480 | 579 | objtable = self.program.get_object_table() |
paul@480 | 580 | all_interfaces = objtable.all_cache.items() |
paul@480 | 581 | any_interfaces = objtable.any_cache.items() |
paul@480 | 582 | all_interfaces.sort() |
paul@480 | 583 | any_interfaces.sort() |
paul@480 | 584 | |
paul@480 | 585 | self.stream.write("<table cellspacing='5' cellpadding='5'>\n") |
paul@480 | 586 | self.stream.write("<thead>\n") |
paul@480 | 587 | self.stream.write("<tr>\n") |
paul@480 | 588 | self.stream.write("<th>Complete 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(all_interfaces, "complete") |
paul@480 | 592 | self.stream.write("<thead>\n") |
paul@480 | 593 | self.stream.write("<tr>\n") |
paul@480 | 594 | self.stream.write("<th>Partial Interfaces</th>\n") |
paul@480 | 595 | self.stream.write("</tr>\n") |
paul@480 | 596 | self.stream.write("</thead>\n") |
paul@480 | 597 | self._write_interface_type(any_interfaces, "partial") |
paul@480 | 598 | self.stream.write("</table>\n") |
paul@480 | 599 | |
paul@480 | 600 | def _write_interface_type(self, interfaces, classes=""): |
paul@480 | 601 | self.stream.write("<tbody>\n") |
paul@480 | 602 | |
paul@480 | 603 | for names, objects in interfaces: |
paul@480 | 604 | if names: |
paul@481 | 605 | names = list(names) |
paul@480 | 606 | names.sort() |
paul@480 | 607 | self.stream.write("<tr>\n") |
paul@480 | 608 | self.stream.write("<td class='summary-interface %s'>%s</td>" % (classes, ", ".join(names))) |
paul@480 | 609 | self.stream.write("</tr>\n") |
paul@480 | 610 | |
paul@480 | 611 | self.stream.write("</tbody>\n") |
paul@480 | 612 | |
paul@320 | 613 | # Source code classes. |
paul@320 | 614 | |
paul@320 | 615 | class AnnotatedSource(ASTVisitor, Writer): |
paul@320 | 616 | |
paul@320 | 617 | "A module source code browser." |
paul@320 | 618 | |
paul@357 | 619 | def __init__(self, module, program): |
paul@320 | 620 | self.visitor = self |
paul@320 | 621 | self.module = module |
paul@357 | 622 | self.program = program |
paul@320 | 623 | |
paul@320 | 624 | def to_stream(self, stream): |
paul@320 | 625 | |
paul@320 | 626 | "Write the annotated code to the given 'stream'." |
paul@320 | 627 | |
paul@320 | 628 | self.stream = stream |
paul@480 | 629 | self.stream.write(html_header % { |
paul@480 | 630 | "title" : "Module: %s" % self.module.full_name() |
paul@480 | 631 | }) |
paul@353 | 632 | self.dispatch(self.module.astnode) |
paul@320 | 633 | self.stream.write(html_footer) |
paul@320 | 634 | |
paul@320 | 635 | def visitModule(self, node): |
paul@585 | 636 | self._doc(node, "module") |
paul@320 | 637 | self.default(node) |
paul@320 | 638 | |
paul@320 | 639 | # Statements. |
paul@320 | 640 | |
paul@320 | 641 | def visitAssert(self, node): |
paul@320 | 642 | self.stream.write("<div class='assert nowrap'>\n") |
paul@320 | 643 | self._keyword("assert") |
paul@320 | 644 | self.dispatch(node.test) |
paul@320 | 645 | if node.fail: |
paul@320 | 646 | self.stream.write(", ") |
paul@320 | 647 | self.dispatch(node.fail) |
paul@320 | 648 | self.stream.write("</div>\n") |
paul@320 | 649 | |
paul@320 | 650 | def visitAssign(self, node): |
paul@320 | 651 | self.stream.write("<div class='assign nowrap'>\n") |
paul@320 | 652 | for lvalue in node.nodes: |
paul@320 | 653 | self.dispatch(lvalue) |
paul@353 | 654 | self.stream.write(" = ") |
paul@320 | 655 | self.dispatch(node.expr) |
paul@320 | 656 | self.stream.write("</div>\n") |
paul@320 | 657 | |
paul@320 | 658 | def visitAugAssign(self, node): |
paul@320 | 659 | self.stream.write("<div class='augassign nowrap'>\n") |
paul@320 | 660 | self.dispatch(node.node) |
paul@371 | 661 | self._op(node.op, operator_functions[node.op], 1) |
paul@320 | 662 | self.dispatch(node.expr) |
paul@320 | 663 | self.stream.write("</div>\n") |
paul@320 | 664 | |
paul@320 | 665 | def visitBreak(self, node): |
paul@320 | 666 | self.stream.write("<div class='break nowrap'>\n") |
paul@320 | 667 | self._keyword("break") |
paul@320 | 668 | self.stream.write("</div>\n") |
paul@320 | 669 | |
paul@320 | 670 | def visitClass(self, node): |
paul@353 | 671 | if not used_by_unit(node): |
paul@370 | 672 | self._docstring('"Class %s not generated."' % node.name) |
paul@353 | 673 | return |
paul@320 | 674 | |
paul@320 | 675 | # Use inspected details where possible. |
paul@320 | 676 | |
paul@354 | 677 | if hasattr(node, "unit"): |
paul@354 | 678 | cls = node.unit |
paul@320 | 679 | bases = cls.bases |
paul@320 | 680 | self.stream.write("<div class='class nowrap' id='%s'>\n" % cls.full_name()) |
paul@320 | 681 | else: |
paul@507 | 682 | print >>sys.stderr, "Warning: class %s not recognised!" % node.name |
paul@320 | 683 | return |
paul@320 | 684 | |
paul@320 | 685 | # Write the declaration line. |
paul@320 | 686 | |
paul@320 | 687 | self.stream.write("<div>\n") |
paul@320 | 688 | self._keyword("class") |
paul@321 | 689 | self._object_name_def(self.module, cls, "class-name") |
paul@320 | 690 | |
paul@320 | 691 | # Suppress the "object" class appearing alone. |
paul@320 | 692 | |
paul@320 | 693 | if bases and not (len(bases) == 1 and bases[0].name == "object"): |
paul@320 | 694 | self.stream.write("(") |
paul@591 | 695 | first = True |
paul@320 | 696 | for base in bases: |
paul@320 | 697 | if not first: |
paul@321 | 698 | self.stream.write(", ") |
paul@320 | 699 | |
paul@358 | 700 | self._object_name_ref(base.module, base) |
paul@320 | 701 | |
paul@591 | 702 | first = False |
paul@320 | 703 | self.stream.write(")") |
paul@320 | 704 | |
paul@320 | 705 | self.stream.write(":\n") |
paul@320 | 706 | self.stream.write("</div>\n") |
paul@320 | 707 | |
paul@320 | 708 | # Write the docstring and class body. |
paul@320 | 709 | |
paul@320 | 710 | self.stream.write("<div class='body nowrap'>\n") |
paul@320 | 711 | self._doc(node) |
paul@358 | 712 | |
paul@358 | 713 | # NOTE: Some streams may not support tell. |
paul@358 | 714 | |
paul@358 | 715 | x = self.stream.tell() |
paul@358 | 716 | |
paul@358 | 717 | self.default(node.code) |
paul@358 | 718 | |
paul@358 | 719 | # Check for no output. |
paul@358 | 720 | |
paul@358 | 721 | if x == self.stream.tell(): |
paul@358 | 722 | self.visitPass(None) |
paul@358 | 723 | |
paul@320 | 724 | self.stream.write("</div>\n") |
paul@320 | 725 | self.stream.write("</div>\n") |
paul@320 | 726 | |
paul@320 | 727 | def visitContinue(self, node): |
paul@320 | 728 | self.stream.write("<div class='continue nowrap'>\n") |
paul@320 | 729 | self._keyword("continue") |
paul@320 | 730 | self.stream.write("</div>\n") |
paul@320 | 731 | |
paul@320 | 732 | def visitDiscard(self, node): |
paul@320 | 733 | self.stream.write("<div class='discard nowrap'>\n") |
paul@320 | 734 | self.default(node) |
paul@320 | 735 | self.stream.write("</div>\n") |
paul@320 | 736 | |
paul@320 | 737 | def visitFor(self, node): |
paul@320 | 738 | self.stream.write("<div class='if nowrap'>\n") |
paul@320 | 739 | self.stream.write("<div>\n") |
paul@320 | 740 | self._keyword("for") |
paul@320 | 741 | self.dispatch(node.assign) |
paul@353 | 742 | self._keyword("in", 1) |
paul@320 | 743 | self.dispatch(node.list) |
paul@320 | 744 | self.stream.write(":\n") |
paul@320 | 745 | self.stream.write("</div>\n") |
paul@320 | 746 | self.stream.write("<div class='body nowrap'>\n") |
paul@320 | 747 | self.dispatch(node.body) |
paul@320 | 748 | self.stream.write("</div>\n") |
paul@320 | 749 | if node.else_ is not None: |
paul@320 | 750 | self.stream.write("<div>\n") |
paul@353 | 751 | self._keyword("else", trailing=0) |
paul@320 | 752 | self.stream.write(":\n") |
paul@320 | 753 | self.stream.write("</div>\n") |
paul@320 | 754 | self.stream.write("<div class='body nowrap'>\n") |
paul@320 | 755 | self.dispatch(node.else_) |
paul@320 | 756 | self.stream.write("</div>\n") |
paul@320 | 757 | self.stream.write("</div>\n") |
paul@320 | 758 | |
paul@320 | 759 | def visitFrom(self, node): |
paul@320 | 760 | self.stream.write("<div class='from nowrap'>\n") |
paul@320 | 761 | self._keyword("from") |
paul@589 | 762 | self._module_link(node.modname) |
paul@353 | 763 | self._keyword("import", 1) |
paul@591 | 764 | first = True |
paul@363 | 765 | for name, alias in node.names: |
paul@320 | 766 | if not first: |
paul@321 | 767 | self.stream.write(", ") |
paul@589 | 768 | self._name(name) |
paul@320 | 769 | if alias: |
paul@353 | 770 | self._keyword("as", 1) |
paul@589 | 771 | self._name(alias) |
paul@591 | 772 | first = False |
paul@320 | 773 | self.stream.write("</div>\n") |
paul@320 | 774 | |
paul@320 | 775 | def visitFunction(self, node): |
paul@353 | 776 | if not used_by_unit(node): |
paul@370 | 777 | self._docstring('"Function %s not generated."' % node.name) |
paul@353 | 778 | return |
paul@353 | 779 | |
paul@354 | 780 | if hasattr(node, "unit"): |
paul@354 | 781 | fn = node.unit |
paul@320 | 782 | self.stream.write("<div class='function nowrap' id='%s'>\n" % fn.full_name()) |
paul@320 | 783 | else: |
paul@507 | 784 | print >>sys.stderr, "Warning: function %s not recognised!" % node.name |
paul@320 | 785 | return |
paul@320 | 786 | |
paul@320 | 787 | # Write the declaration line. |
paul@320 | 788 | |
paul@320 | 789 | self.stream.write("<div>\n") |
paul@320 | 790 | self._keyword("def") |
paul@321 | 791 | self._object_name_def(self.module, fn, "function-name") |
paul@320 | 792 | |
paul@320 | 793 | self.stream.write("(") |
paul@354 | 794 | self._parameters(fn, node) |
paul@320 | 795 | self.stream.write(")") |
paul@320 | 796 | self.stream.write(":\n") |
paul@320 | 797 | self.stream.write("</div>\n") |
paul@320 | 798 | |
paul@320 | 799 | self.stream.write("<div class='body nowrap'>\n") |
paul@320 | 800 | self._doc(node) |
paul@320 | 801 | self.dispatch(node.code) |
paul@320 | 802 | self.stream.write("</div>\n") |
paul@320 | 803 | self.stream.write("</div>\n") |
paul@320 | 804 | |
paul@320 | 805 | def visitGlobal(self, node): |
paul@320 | 806 | self.stream.write("<div class='global nowrap'>\n") |
paul@320 | 807 | self._keyword("global") |
paul@591 | 808 | first = True |
paul@320 | 809 | for name in node.names: |
paul@320 | 810 | if not first: |
paul@321 | 811 | self.stream.write(", ") |
paul@320 | 812 | self.stream.write(name) |
paul@591 | 813 | first = False |
paul@320 | 814 | self.stream.write("</div>\n") |
paul@320 | 815 | |
paul@320 | 816 | def visitIf(self, node): |
paul@320 | 817 | self.stream.write("<div class='if nowrap'>\n") |
paul@591 | 818 | first = True |
paul@320 | 819 | for compare, stmt in node.tests: |
paul@320 | 820 | self.stream.write("<div>\n") |
paul@320 | 821 | if first: |
paul@320 | 822 | self._keyword("if") |
paul@320 | 823 | else: |
paul@320 | 824 | self._keyword("elif") |
paul@320 | 825 | self.dispatch(compare) |
paul@320 | 826 | self.stream.write(":\n") |
paul@320 | 827 | self.stream.write("</div>\n") |
paul@320 | 828 | self.stream.write("<div class='body nowrap'>\n") |
paul@320 | 829 | self.dispatch(stmt) |
paul@320 | 830 | self.stream.write("</div>\n") |
paul@591 | 831 | first = False |
paul@320 | 832 | if node.else_ is not None: |
paul@320 | 833 | self.stream.write("<div>\n") |
paul@353 | 834 | self._keyword("else", trailing=0) |
paul@353 | 835 | self.stream.write(":\n") |
paul@353 | 836 | self.stream.write("</div>\n") |
paul@353 | 837 | self.stream.write("<div class='body nowrap'>\n") |
paul@353 | 838 | self.dispatch(node.else_) |
paul@353 | 839 | self.stream.write("</div>\n") |
paul@353 | 840 | self.stream.write("</div>\n") |
paul@353 | 841 | |
paul@353 | 842 | def visitImport(self, node): |
paul@353 | 843 | self.stream.write("<div class='import nowrap'>\n") |
paul@353 | 844 | self._keyword("import") |
paul@591 | 845 | first = True |
paul@353 | 846 | for name, alias in node.names: |
paul@353 | 847 | if not first: |
paul@353 | 848 | self.stream.write(",\n") |
paul@589 | 849 | self._module_link(name) |
paul@353 | 850 | if alias: |
paul@353 | 851 | self._keyword("as", 1) |
paul@589 | 852 | self._name(alias) |
paul@591 | 853 | first = False |
paul@353 | 854 | self.stream.write("</div>\n") |
paul@353 | 855 | |
paul@353 | 856 | def visitPass(self, node): |
paul@353 | 857 | self.stream.write("<div class='pass nowrap'>\n") |
paul@353 | 858 | self._keyword("pass") |
paul@353 | 859 | self.stream.write("</div>\n") |
paul@353 | 860 | |
paul@353 | 861 | def visitPrint(self, node): |
paul@353 | 862 | self.stream.write("<div class='print nowrap'>\n") |
paul@353 | 863 | self._keyword("print") |
paul@353 | 864 | if node.dest is not None: |
paul@353 | 865 | self.stream.write(">>\n") |
paul@353 | 866 | self.dispatch(node.dest) |
paul@518 | 867 | self.stream.write(",\n") |
paul@353 | 868 | for n in node.nodes: |
paul@353 | 869 | self.dispatch(n) |
paul@353 | 870 | self.stream.write(",\n") |
paul@353 | 871 | self.stream.write("</div>\n") |
paul@353 | 872 | |
paul@353 | 873 | def visitPrintnl(self, node): |
paul@353 | 874 | self.stream.write("<div class='printnl nowrap'>\n") |
paul@353 | 875 | self._keyword("print") |
paul@353 | 876 | if node.dest is not None: |
paul@353 | 877 | self.stream.write(">>\n") |
paul@353 | 878 | self.dispatch(node.dest) |
paul@591 | 879 | first = False |
paul@518 | 880 | else: |
paul@591 | 881 | first = True |
paul@353 | 882 | for n in node.nodes: |
paul@353 | 883 | if not first: |
paul@353 | 884 | self.stream.write(",\n") |
paul@353 | 885 | self.dispatch(n) |
paul@591 | 886 | first = False |
paul@353 | 887 | self.stream.write("</div>\n") |
paul@353 | 888 | |
paul@353 | 889 | def visitRaise(self, node): |
paul@353 | 890 | self.stream.write("<div class='raise nowrap'>\n") |
paul@353 | 891 | self._keyword("raise") |
paul@363 | 892 | if node.expr1 is not None: |
paul@363 | 893 | self.dispatch(node.expr1) |
paul@353 | 894 | if node.expr2 is not None: |
paul@353 | 895 | self.stream.write(",\n") |
paul@353 | 896 | self.dispatch(node.expr2) |
paul@353 | 897 | if node.expr3 is not None: |
paul@353 | 898 | self.stream.write(",\n") |
paul@353 | 899 | self.dispatch(node.expr3) |
paul@353 | 900 | self.stream.write("</div>\n") |
paul@353 | 901 | |
paul@353 | 902 | def visitReturn(self, node): |
paul@353 | 903 | self.stream.write("<div class='return nowrap'>\n") |
paul@353 | 904 | self._keyword("return") |
paul@353 | 905 | self.dispatch(node.value) |
paul@353 | 906 | self.stream.write("</div>\n") |
paul@353 | 907 | |
paul@353 | 908 | def visitStmt(self, node): |
paul@353 | 909 | self.stream.write("<div class='stmt nowrap'>\n") |
paul@353 | 910 | self.default(node) |
paul@353 | 911 | self.stream.write("</div>\n") |
paul@353 | 912 | |
paul@353 | 913 | def visitTryExcept(self, node): |
paul@353 | 914 | self.stream.write("<div class='tryexcept nowrap'>\n") |
paul@353 | 915 | self.stream.write("<div>\n") |
paul@353 | 916 | self._keyword("try", trailing=0) |
paul@353 | 917 | self.stream.write(":\n") |
paul@353 | 918 | self.stream.write("</div>\n") |
paul@353 | 919 | self.stream.write("<div class='body nowrap'>\n") |
paul@353 | 920 | self.dispatch(node.body) |
paul@353 | 921 | self.stream.write("</div>\n") |
paul@353 | 922 | for spec, assign, statement in node.handlers: |
paul@353 | 923 | self.stream.write("<div>\n") |
paul@353 | 924 | self._keyword("except") |
paul@353 | 925 | if spec is not None: |
paul@353 | 926 | self.dispatch(spec) |
paul@353 | 927 | if assign is not None: |
paul@353 | 928 | self.stream.write(",\n") |
paul@353 | 929 | self.dispatch(assign) |
paul@353 | 930 | self.stream.write(":\n") |
paul@353 | 931 | self.stream.write("</div>\n") |
paul@353 | 932 | self.stream.write("<div class='body nowrap'>\n") |
paul@353 | 933 | self.dispatch(statement) |
paul@353 | 934 | self.stream.write("</div>\n") |
paul@353 | 935 | if node.else_ is not None: |
paul@353 | 936 | self.stream.write("<div>\n") |
paul@353 | 937 | self._keyword("else", trailing=0) |
paul@353 | 938 | self.stream.write(":\n") |
paul@353 | 939 | self.stream.write("</div>\n") |
paul@353 | 940 | self.stream.write("<div class='body nowrap'>\n") |
paul@353 | 941 | self.dispatch(node.else_) |
paul@353 | 942 | self.stream.write("</div>\n") |
paul@353 | 943 | self.stream.write("</div>\n") |
paul@353 | 944 | |
paul@353 | 945 | def visitTryFinally(self, node): |
paul@353 | 946 | self.stream.write("<div class='tryfinally nowrap'>\n") |
paul@353 | 947 | self.stream.write("<div>\n") |
paul@353 | 948 | self._keyword("try", trailing=0) |
paul@353 | 949 | self.stream.write(":\n") |
paul@353 | 950 | self.stream.write("</div>\n") |
paul@353 | 951 | self.stream.write("<div class='body nowrap'>\n") |
paul@353 | 952 | self.dispatch(node.body) |
paul@353 | 953 | self.stream.write("</div>\n") |
paul@353 | 954 | self.stream.write("<div>\n") |
paul@353 | 955 | self._keyword("finally", trailing=0) |
paul@353 | 956 | self.stream.write(":\n") |
paul@353 | 957 | self.stream.write("</div>\n") |
paul@353 | 958 | self.stream.write("<div class='body nowrap'>\n") |
paul@353 | 959 | self.dispatch(node.final) |
paul@353 | 960 | self.stream.write("</div>\n") |
paul@353 | 961 | self.stream.write("</div>\n") |
paul@353 | 962 | |
paul@353 | 963 | def visitWhile(self, node): |
paul@353 | 964 | self.stream.write("<div class='while nowrap'>\n") |
paul@353 | 965 | self.stream.write("<div>\n") |
paul@353 | 966 | self._keyword("while") |
paul@353 | 967 | self.dispatch(node.test) |
paul@353 | 968 | self.stream.write(":\n") |
paul@353 | 969 | self.stream.write("</div>\n") |
paul@353 | 970 | self.stream.write("<div class='body nowrap'>\n") |
paul@353 | 971 | self.dispatch(node.body) |
paul@353 | 972 | self.stream.write("</div>\n") |
paul@353 | 973 | if node.else_ is not None: |
paul@353 | 974 | self.stream.write("<div>\n") |
paul@353 | 975 | self._keyword("else", trailing=0) |
paul@320 | 976 | self.stream.write(":\n") |
paul@320 | 977 | self.stream.write("</div>\n") |
paul@320 | 978 | self.stream.write("<div class='body nowrap'>\n") |
paul@320 | 979 | self.dispatch(node.else_) |
paul@320 | 980 | self.stream.write("</div>\n") |
paul@320 | 981 | self.stream.write("</div>\n") |
paul@320 | 982 | |
paul@496 | 983 | def visitYield(self, node): |
paul@496 | 984 | self.stream.write("<div class='yield nowrap'>\n") |
paul@496 | 985 | self._keyword("yield") |
paul@496 | 986 | self.dispatch(node.value) |
paul@496 | 987 | self.stream.write("</div>\n") |
paul@496 | 988 | |
paul@353 | 989 | # Expression-related helper methods. |
paul@353 | 990 | |
paul@588 | 991 | def _visitBitBinary(self, node, symbol): |
paul@588 | 992 | name = operator_functions[node.__class__.__name__] |
paul@355 | 993 | self._span_start(name) |
paul@591 | 994 | first = True |
paul@353 | 995 | for node in node.nodes: |
paul@353 | 996 | if not first: |
paul@371 | 997 | self._op(symbol, name, 1) |
paul@353 | 998 | self.dispatch(node) |
paul@591 | 999 | first = False |
paul@355 | 1000 | self._span_end() |
paul@353 | 1001 | |
paul@588 | 1002 | def _visitBinary(self, node, symbol): |
paul@588 | 1003 | name = operator_functions[node.__class__.__name__] |
paul@355 | 1004 | self._span_start(name) |
paul@353 | 1005 | self.dispatch(node.left) |
paul@371 | 1006 | self._op(symbol, name, 1) |
paul@353 | 1007 | self.dispatch(node.right) |
paul@355 | 1008 | self._span_end() |
paul@353 | 1009 | |
paul@588 | 1010 | def _visitUnary(self, node, symbol): |
paul@588 | 1011 | name = operator_functions[node.__class__.__name__] |
paul@355 | 1012 | self._span_start(name) |
paul@529 | 1013 | self._op(symbol, name, trailing=0) |
paul@353 | 1014 | self.dispatch(node.expr) |
paul@355 | 1015 | self._span_end() |
paul@353 | 1016 | |
paul@353 | 1017 | # Expressions. |
paul@353 | 1018 | |
paul@353 | 1019 | def visitAdd(self, node): |
paul@588 | 1020 | self._visitBinary(node, "+") |
paul@353 | 1021 | |
paul@353 | 1022 | def visitAnd(self, node): |
paul@355 | 1023 | self._span_start("and") |
paul@591 | 1024 | first = True |
paul@353 | 1025 | for n in node.nodes: |
paul@353 | 1026 | if not first: |
paul@353 | 1027 | self._keyword("and", 1) |
paul@353 | 1028 | self.dispatch(n) |
paul@591 | 1029 | first = False |
paul@355 | 1030 | self._span_end() |
paul@353 | 1031 | |
paul@353 | 1032 | def visitAssAttr(self, node): |
paul@536 | 1033 | possible_types = self.possible_accessor_types(node, defining_users=0) |
paul@582 | 1034 | target_names = set(["%s%s" % (is_static and "static " or "", target_name) |
paul@582 | 1035 | for target_name, is_static in possible_types]) |
paul@536 | 1036 | attributes = self._get_attributes(possible_types, node.attrname) |
paul@536 | 1037 | |
paul@567 | 1038 | wraps_getattr = isinstance(node.expr, compiler.ast.Getattr) |
paul@567 | 1039 | |
paul@567 | 1040 | if not wraps_getattr: |
paul@567 | 1041 | self._span_start("assattr") |
paul@567 | 1042 | self._accessor_start(target_names) |
paul@353 | 1043 | self.dispatch(node.expr) |
paul@567 | 1044 | if not wraps_getattr: |
paul@567 | 1045 | self._accessor_end(target_names) |
paul@353 | 1046 | self.stream.write(".") |
paul@583 | 1047 | self._attribute_start(node.attrname, self._attributes_to_attribute_names(attributes, node.attrname)) |
paul@523 | 1048 | self._span(node.attrname, "attrname" + (not target_names and " no-targets" or "")) |
paul@536 | 1049 | self._attribute_end(attributes) |
paul@567 | 1050 | if not wraps_getattr: |
paul@567 | 1051 | self._span_end() |
paul@353 | 1052 | |
paul@353 | 1053 | def visitAssList(self, node): |
paul@355 | 1054 | self._span_start("list") |
paul@353 | 1055 | self.stream.write("[") |
paul@353 | 1056 | self._sequence(node) |
paul@353 | 1057 | self.stream.write("]") |
paul@355 | 1058 | self._span_end() |
paul@353 | 1059 | |
paul@353 | 1060 | def visitAssName(self, node): |
paul@354 | 1061 | self._assname(node.name, node) |
paul@353 | 1062 | |
paul@353 | 1063 | def visitAssTuple(self, node): |
paul@355 | 1064 | self._span_start("tuple") |
paul@353 | 1065 | self.stream.write("(") |
paul@353 | 1066 | self._sequence(node) |
paul@353 | 1067 | self.stream.write(")") |
paul@355 | 1068 | self._span_end() |
paul@353 | 1069 | |
paul@353 | 1070 | def visitBitand(self, node): |
paul@588 | 1071 | self._visitBitBinary(node, "&") |
paul@353 | 1072 | |
paul@437 | 1073 | def visitBitor(self, node): |
paul@588 | 1074 | self._visitBitBinary(node, "|") |
paul@437 | 1075 | |
paul@437 | 1076 | def visitBitxor(self, node): |
paul@588 | 1077 | self._visitBitBinary(node, "^") |
paul@437 | 1078 | |
paul@353 | 1079 | def visitCallFunc(self, node): |
paul@355 | 1080 | self._span_start("callfunc") |
paul@353 | 1081 | self.dispatch(node.node) |
paul@355 | 1082 | self._span_start("call") |
paul@353 | 1083 | self.stream.write("(") |
paul@591 | 1084 | first = True |
paul@353 | 1085 | for arg in node.args: |
paul@353 | 1086 | if not first: |
paul@353 | 1087 | self.stream.write(", ") |
paul@353 | 1088 | self.dispatch(arg) |
paul@591 | 1089 | first = False |
paul@353 | 1090 | if node.star_args is not None: |
paul@353 | 1091 | if not first: |
paul@353 | 1092 | self.stream.write(", *") |
paul@353 | 1093 | self.dispatch(node.star_args) |
paul@591 | 1094 | first = False |
paul@353 | 1095 | if node.dstar_args is not None: |
paul@353 | 1096 | if not first: |
paul@353 | 1097 | self.stream.write(", **") |
paul@353 | 1098 | self.dispatch(node.dstar_args) |
paul@591 | 1099 | first = False |
paul@353 | 1100 | self.stream.write(")") |
paul@355 | 1101 | self._span_end() |
paul@355 | 1102 | self._span_end() |
paul@353 | 1103 | |
paul@353 | 1104 | def visitCompare(self, node): |
paul@355 | 1105 | self._span_start("compare") |
paul@353 | 1106 | self.dispatch(node.expr) |
paul@353 | 1107 | for op_name, expr in node.ops: |
paul@371 | 1108 | self._op(op_name, operator_functions.get(op_name), 1) |
paul@353 | 1109 | self.dispatch(expr) |
paul@355 | 1110 | self._span_end() |
paul@353 | 1111 | |
paul@353 | 1112 | def visitConst(self, node): |
paul@353 | 1113 | if isinstance(node.value, (str, unicode)): |
paul@355 | 1114 | self._span_start("str") |
paul@353 | 1115 | self.stream.write(self._text(repr(node.value))) |
paul@353 | 1116 | if isinstance(node.value, (str, unicode)): |
paul@355 | 1117 | self._span_end() |
paul@353 | 1118 | |
paul@353 | 1119 | def visitDict(self, node): |
paul@355 | 1120 | self._span_start("dict") |
paul@353 | 1121 | self.stream.write("{") |
paul@353 | 1122 | self._mapping(node) |
paul@353 | 1123 | self.stream.write("}") |
paul@355 | 1124 | self._span_end() |
paul@353 | 1125 | |
paul@353 | 1126 | def visitDiv(self, node): |
paul@588 | 1127 | self._visitBinary(node, "/") |
paul@353 | 1128 | |
paul@353 | 1129 | def visitFloorDiv(self, node): |
paul@588 | 1130 | self._visitBinary(node, "//") |
paul@353 | 1131 | |
paul@353 | 1132 | def visitGetattr(self, node): |
paul@536 | 1133 | possible_types = self.possible_accessor_types(node, defining_users=0) |
paul@582 | 1134 | target_names = set(["%s%s" % (is_static and "static " or "", target_name) |
paul@582 | 1135 | for target_name, is_static in possible_types]) |
paul@536 | 1136 | attributes = self._get_attributes(possible_types, node.attrname) |
paul@536 | 1137 | |
paul@567 | 1138 | wraps_getattr = isinstance(node.expr, compiler.ast.Getattr) |
paul@567 | 1139 | |
paul@567 | 1140 | if not wraps_getattr: |
paul@567 | 1141 | self._span_start("getattr") |
paul@567 | 1142 | self._accessor_start(target_names) |
paul@353 | 1143 | self.dispatch(node.expr) |
paul@567 | 1144 | if not wraps_getattr: |
paul@567 | 1145 | self._accessor_end(target_names) |
paul@353 | 1146 | self.stream.write(".") |
paul@583 | 1147 | self._attribute_start(node.attrname, self._attributes_to_attribute_names(attributes, node.attrname)) |
paul@523 | 1148 | self._span(node.attrname, "attrname" + (not target_names and " no-targets" or "")) |
paul@536 | 1149 | self._attribute_end(attributes) |
paul@567 | 1150 | if not wraps_getattr: |
paul@567 | 1151 | self._span_end() |
paul@353 | 1152 | |
paul@500 | 1153 | def visitGenExpr(self, node): |
paul@500 | 1154 | self._span_start("genexpr") |
paul@500 | 1155 | self.stream.write("(") |
paul@500 | 1156 | self.dispatch(node.code) |
paul@500 | 1157 | self.stream.write(")") |
paul@500 | 1158 | self._span_end() |
paul@500 | 1159 | |
paul@500 | 1160 | def visitGenExprFor(self, node): |
paul@500 | 1161 | self._span_start("genexprfor") |
paul@500 | 1162 | self._keyword("for", 1) |
paul@500 | 1163 | self._span_start("item") |
paul@500 | 1164 | self.dispatch(node.assign) |
paul@500 | 1165 | self._span_end() |
paul@500 | 1166 | self._keyword("in", 1) |
paul@500 | 1167 | self._span_start("collection") |
paul@500 | 1168 | self.dispatch(node.iter) |
paul@500 | 1169 | self._span_end() |
paul@500 | 1170 | for if_ in node.ifs: |
paul@500 | 1171 | self.dispatch(if_) |
paul@500 | 1172 | self._span_end() |
paul@500 | 1173 | |
paul@500 | 1174 | def visitGenExprIf(self, node): |
paul@500 | 1175 | self._span_start("genexprif") |
paul@500 | 1176 | self._span_start("conditional") |
paul@500 | 1177 | self._keyword("if", 1) |
paul@500 | 1178 | self.dispatch(node.test) |
paul@500 | 1179 | self._span_end() |
paul@500 | 1180 | self._span_end() |
paul@500 | 1181 | |
paul@500 | 1182 | def visitGenExprInner(self, node): |
paul@500 | 1183 | self._span_start("genexprinner") |
paul@500 | 1184 | self.dispatch(node.expr) |
paul@500 | 1185 | for qual in node.quals: |
paul@500 | 1186 | self.dispatch(qual) |
paul@500 | 1187 | self._span_end() |
paul@500 | 1188 | |
paul@496 | 1189 | def visitIfExp(self, node): |
paul@496 | 1190 | self._span_start("ifexp") |
paul@496 | 1191 | self.dispatch(node.then) |
paul@512 | 1192 | self._keyword("if", 1) |
paul@496 | 1193 | self.dispatch(node.test) |
paul@512 | 1194 | self._keyword("else", 1) |
paul@496 | 1195 | self.dispatch(node.else_) |
paul@496 | 1196 | self._span_end() |
paul@496 | 1197 | |
paul@513 | 1198 | def visitInvert(self, node): |
paul@588 | 1199 | self._visitUnary(node, "~") |
paul@513 | 1200 | |
paul@353 | 1201 | def visitKeyword(self, node): |
paul@355 | 1202 | self._span_start("keyword-arg") |
paul@353 | 1203 | self.stream.write(node.name) |
paul@353 | 1204 | self.stream.write("=") |
paul@353 | 1205 | self.dispatch(node.expr) |
paul@355 | 1206 | self._span_end() |
paul@353 | 1207 | |
paul@353 | 1208 | def visitLambda(self, node): |
paul@354 | 1209 | if hasattr(node, "unit"): |
paul@354 | 1210 | fn = node.unit |
paul@353 | 1211 | else: |
paul@507 | 1212 | print >>sys.stderr, "Warning: function %s not recognised!" % node.name |
paul@353 | 1213 | return |
paul@353 | 1214 | |
paul@355 | 1215 | self._span_start("lambda") |
paul@353 | 1216 | self._keyword("lambda") |
paul@354 | 1217 | self._parameters(fn, node) |
paul@355 | 1218 | self.stream.write(": ") |
paul@355 | 1219 | self._span_start("code") |
paul@353 | 1220 | self.dispatch(node.code) |
paul@355 | 1221 | self._span_end() |
paul@355 | 1222 | self._span_end() |
paul@353 | 1223 | |
paul@481 | 1224 | def visitLeftShift(self, node): |
paul@588 | 1225 | self._visitBinary(node, "<<") |
paul@481 | 1226 | |
paul@353 | 1227 | visitList = visitAssList |
paul@353 | 1228 | |
paul@353 | 1229 | def visitListComp(self, node): |
paul@355 | 1230 | self._span_start("listcomp") |
paul@353 | 1231 | self.stream.write("[") |
paul@353 | 1232 | self.dispatch(node.expr) |
paul@353 | 1233 | for qual in node.quals: |
paul@353 | 1234 | self.dispatch(qual) |
paul@353 | 1235 | self.stream.write("]") |
paul@355 | 1236 | self._span_end() |
paul@353 | 1237 | |
paul@353 | 1238 | def visitListCompFor(self, node): |
paul@355 | 1239 | self._span_start("listcompfor") |
paul@365 | 1240 | self._keyword("for", 1) |
paul@355 | 1241 | self._span_start("item") |
paul@353 | 1242 | self.dispatch(node.assign) |
paul@355 | 1243 | self._span_end() |
paul@353 | 1244 | self._keyword("in", 1) |
paul@355 | 1245 | self._span_start("collection") |
paul@353 | 1246 | self.dispatch(node.list) |
paul@355 | 1247 | self._span_end() |
paul@353 | 1248 | for if_ in node.ifs: |
paul@353 | 1249 | self.dispatch(if_) |
paul@355 | 1250 | self._span_end() |
paul@353 | 1251 | |
paul@353 | 1252 | def visitListCompIf(self, node): |
paul@355 | 1253 | self._span_start("listcompif") |
paul@355 | 1254 | self._span_start("conditional") |
paul@353 | 1255 | self._keyword("if", 1) |
paul@353 | 1256 | self.dispatch(node.test) |
paul@355 | 1257 | self._span_end() |
paul@355 | 1258 | self._span_end() |
paul@353 | 1259 | |
paul@353 | 1260 | def visitMod(self, node): |
paul@588 | 1261 | self._visitBinary(node, "%") |
paul@353 | 1262 | |
paul@353 | 1263 | def visitMul(self, node): |
paul@588 | 1264 | self._visitBinary(node, "*") |
paul@353 | 1265 | |
paul@353 | 1266 | def visitName(self, node): |
paul@353 | 1267 | if hasattr(node, "_scope"): |
paul@353 | 1268 | scope = node._scope |
paul@353 | 1269 | self._name_start() |
paul@353 | 1270 | self.stream.write(node.name) |
paul@353 | 1271 | self._popup_start() |
paul@583 | 1272 | self._scope(node._scope, node._attr) |
paul@353 | 1273 | self._popup_end() |
paul@353 | 1274 | self._name_end() |
paul@353 | 1275 | else: |
paul@355 | 1276 | self._span(node.name) |
paul@353 | 1277 | |
paul@358 | 1278 | def visitNot(self, node): |
paul@358 | 1279 | self._span_start("not") |
paul@358 | 1280 | self._keyword("not") |
paul@358 | 1281 | self.dispatch(node.expr) |
paul@358 | 1282 | self._span_end() |
paul@358 | 1283 | |
paul@358 | 1284 | def visitOr(self, node): |
paul@358 | 1285 | self._span_start("or") |
paul@591 | 1286 | first = True |
paul@358 | 1287 | for n in node.nodes: |
paul@358 | 1288 | if not first: |
paul@358 | 1289 | self._keyword("or", 1) |
paul@358 | 1290 | self.dispatch(n) |
paul@591 | 1291 | first = False |
paul@358 | 1292 | self._span_end() |
paul@358 | 1293 | |
paul@358 | 1294 | def visitPower(self, node): |
paul@588 | 1295 | self._visitBinary(node, "**") |
paul@358 | 1296 | |
paul@481 | 1297 | def visitRightShift(self, node): |
paul@588 | 1298 | self._visitBinary(node, ">>") |
paul@481 | 1299 | |
paul@358 | 1300 | def visitSlice(self, node): |
paul@358 | 1301 | self._span_start("slice") |
paul@358 | 1302 | self.dispatch(node.expr) |
paul@358 | 1303 | self.stream.write("[") |
paul@358 | 1304 | if node.lower: |
paul@358 | 1305 | self.dispatch(node.lower) |
paul@358 | 1306 | self.stream.write(":") |
paul@358 | 1307 | if node.upper: |
paul@358 | 1308 | self.dispatch(node.upper) |
paul@358 | 1309 | # NOTE: Step? |
paul@358 | 1310 | self.stream.write("]") |
paul@358 | 1311 | self._span_end() |
paul@358 | 1312 | |
paul@358 | 1313 | def visitSliceobj(self, node): |
paul@358 | 1314 | self._span_start("sliceobj") |
paul@591 | 1315 | first = True |
paul@358 | 1316 | for n in node.nodes: |
paul@358 | 1317 | if not first: |
paul@358 | 1318 | self.stream.write(":") |
paul@358 | 1319 | self.dispatch(n) |
paul@358 | 1320 | self._span_end() |
paul@358 | 1321 | |
paul@358 | 1322 | def visitSub(self, node): |
paul@588 | 1323 | self._visitBinary(node, "-") |
paul@358 | 1324 | |
paul@358 | 1325 | def visitSubscript(self, node): |
paul@358 | 1326 | self._span_start("subscript") |
paul@358 | 1327 | self.dispatch(node.expr) |
paul@358 | 1328 | self.stream.write("[") |
paul@591 | 1329 | first = True |
paul@358 | 1330 | for sub in node.subs: |
paul@358 | 1331 | if not first: |
paul@358 | 1332 | self.stream.write(", ") |
paul@358 | 1333 | self.dispatch(sub) |
paul@591 | 1334 | first = False |
paul@358 | 1335 | self.stream.write("]") |
paul@358 | 1336 | self._span_end() |
paul@358 | 1337 | |
paul@358 | 1338 | visitTuple = visitAssTuple |
paul@358 | 1339 | |
paul@358 | 1340 | def visitUnaryAdd(self, node): |
paul@588 | 1341 | self._visitUnary(node, "+") |
paul@358 | 1342 | |
paul@358 | 1343 | def visitUnarySub(self, node): |
paul@588 | 1344 | self._visitUnary(node, "-") |
paul@358 | 1345 | |
paul@320 | 1346 | # Output preparation methods. |
paul@320 | 1347 | |
paul@320 | 1348 | def _sequence(self, node): |
paul@591 | 1349 | first = True |
paul@320 | 1350 | for n in node.nodes: |
paul@320 | 1351 | if not first: |
paul@321 | 1352 | self.stream.write(", ") |
paul@320 | 1353 | self.dispatch(n) |
paul@591 | 1354 | first = False |
paul@320 | 1355 | |
paul@320 | 1356 | def _mapping(self, node): |
paul@591 | 1357 | first = True |
paul@320 | 1358 | for k, v in node.items: |
paul@320 | 1359 | if not first: |
paul@321 | 1360 | self.stream.write(", ") |
paul@320 | 1361 | self.dispatch(k) |
paul@321 | 1362 | self.stream.write(" : ") |
paul@320 | 1363 | self.dispatch(v) |
paul@591 | 1364 | first = False |
paul@320 | 1365 | |
paul@354 | 1366 | def _parameters(self, fn, node): |
paul@320 | 1367 | nparams = len(fn.positional_names) |
paul@320 | 1368 | ndefaults = len(fn.defaults) |
paul@320 | 1369 | first_with_default = nparams - ndefaults |
paul@320 | 1370 | |
paul@591 | 1371 | first = True |
paul@320 | 1372 | for n, param in enumerate(fn.positional_names): |
paul@320 | 1373 | if not first: |
paul@321 | 1374 | self.stream.write(", ") |
paul@370 | 1375 | |
paul@370 | 1376 | # Handle tuple parameters. |
paul@370 | 1377 | |
paul@370 | 1378 | if isinstance(param, tuple): |
paul@370 | 1379 | self._tuple_parameter(param, node) |
paul@370 | 1380 | else: |
paul@370 | 1381 | self._assname(param, node) |
paul@370 | 1382 | |
paul@320 | 1383 | n_default = n - first_with_default |
paul@320 | 1384 | if n_default >= 0: |
paul@320 | 1385 | self._default(fn.defaults[n_default]) |
paul@591 | 1386 | first = False |
paul@320 | 1387 | |
paul@320 | 1388 | if fn.has_star: |
paul@320 | 1389 | if not first: |
paul@321 | 1390 | self.stream.write(", *") |
paul@320 | 1391 | self._name(fn.star_name) |
paul@320 | 1392 | |
paul@320 | 1393 | if fn.has_dstar: |
paul@320 | 1394 | if not first: |
paul@321 | 1395 | self.stream.write(", **") |
paul@320 | 1396 | self._name(fn.dstar_name) |
paul@320 | 1397 | |
paul@370 | 1398 | def _tuple_parameter(self, parameters, node): |
paul@370 | 1399 | self.stream.write("(") |
paul@370 | 1400 | |
paul@591 | 1401 | first = True |
paul@370 | 1402 | for param in parameters: |
paul@370 | 1403 | if not first: |
paul@370 | 1404 | self.stream.write(", ") |
paul@370 | 1405 | |
paul@370 | 1406 | # Handle tuples. |
paul@370 | 1407 | |
paul@370 | 1408 | if isinstance(param, tuple): |
paul@370 | 1409 | self._tuple_parameter(param, node) |
paul@370 | 1410 | else: |
paul@370 | 1411 | self._assname(param, node) |
paul@370 | 1412 | |
paul@591 | 1413 | first = False |
paul@370 | 1414 | |
paul@370 | 1415 | self.stream.write(")") |
paul@370 | 1416 | |
paul@320 | 1417 | def _default(self, default): |
paul@321 | 1418 | self.stream.write("=") |
paul@320 | 1419 | self.dispatch(default) |
paul@320 | 1420 | |
paul@318 | 1421 | # Convenience functions. |
paul@318 | 1422 | |
paul@357 | 1423 | def summarise(module, program, filename): |
paul@318 | 1424 | stream = open(filename, "wb") |
paul@318 | 1425 | try: |
paul@357 | 1426 | summary = Summary(module, program) |
paul@320 | 1427 | summary.to_stream(stream) |
paul@320 | 1428 | finally: |
paul@320 | 1429 | stream.close() |
paul@320 | 1430 | |
paul@357 | 1431 | def annotate(module, program, filename): |
paul@320 | 1432 | stream = open(filename, "wb") |
paul@320 | 1433 | try: |
paul@357 | 1434 | source = AnnotatedSource(module, program) |
paul@320 | 1435 | source.to_stream(stream) |
paul@318 | 1436 | finally: |
paul@318 | 1437 | stream.close() |
paul@318 | 1438 | |
paul@480 | 1439 | def interfaces(program, filename): |
paul@480 | 1440 | stream = open(filename, "wb") |
paul@480 | 1441 | try: |
paul@480 | 1442 | source = Interfaces(program) |
paul@480 | 1443 | source.to_stream(stream) |
paul@480 | 1444 | finally: |
paul@480 | 1445 | stream.close() |
paul@480 | 1446 | |
paul@357 | 1447 | def report(program, directory): |
paul@353 | 1448 | if not exists(directory): |
paul@353 | 1449 | os.mkdir(directory) |
paul@353 | 1450 | |
paul@357 | 1451 | for module in program.get_importer().get_modules(): |
paul@357 | 1452 | annotate(module, program, join(directory, "%s%sxhtml" % (module.full_name(), extsep))) |
paul@357 | 1453 | summarise(module, program, join(directory, "%s-summary%sxhtml" % (module.full_name(), extsep))) |
paul@353 | 1454 | |
paul@480 | 1455 | interfaces(program, join(directory, "-interfaces%sxhtml" % extsep)) |
paul@480 | 1456 | |
paul@318 | 1457 | # vim: tabstop=4 expandtab shiftwidth=4 |