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