Commit 408fc116 authored by Stefan Behnel's avatar Stefan Behnel

modernise code, make attribute name less ambiguous

parent c4c2e3d8
...@@ -8,6 +8,8 @@ import re ...@@ -8,6 +8,8 @@ import re
import codecs import codecs
import textwrap import textwrap
from datetime import datetime from datetime import datetime
from functools import partial
from collections import defaultdict
from xml.sax.saxutils import escape as html_escape from xml.sax.saxutils import escape as html_escape
from StringIO import StringIO from StringIO import StringIO
...@@ -23,14 +25,14 @@ class AnnotationCCodeWriter(CCodeWriter): ...@@ -23,14 +25,14 @@ class AnnotationCCodeWriter(CCodeWriter):
if create_from is None: if create_from is None:
self.annotation_buffer = StringIO() self.annotation_buffer = StringIO()
self.annotations = [] self.annotations = []
self.last_pos = None self.last_annotated_pos = None
self.code = {} self.code = defaultdict(partial(defaultdict, str))
else: else:
# When creating an insertion point, keep references to the same database # When creating an insertion point, keep references to the same database
self.annotation_buffer = create_from.annotation_buffer self.annotation_buffer = create_from.annotation_buffer
self.annotations = create_from.annotations self.annotations = create_from.annotations
self.code = create_from.code self.code = create_from.code
self.last_pos = create_from.last_pos self.last_annotated_pos = create_from.last_annotated_pos
def create_new(self, create_from, buffer, copy_formatting): def create_new(self, create_from, buffer, copy_formatting):
return AnnotationCCodeWriter(create_from, buffer, copy_formatting) return AnnotationCCodeWriter(create_from, buffer, copy_formatting)
...@@ -42,12 +44,12 @@ class AnnotationCCodeWriter(CCodeWriter): ...@@ -42,12 +44,12 @@ class AnnotationCCodeWriter(CCodeWriter):
def mark_pos(self, pos): def mark_pos(self, pos):
if pos is not None: if pos is not None:
CCodeWriter.mark_pos(self, pos) CCodeWriter.mark_pos(self, pos)
if self.last_pos: if self.last_annotated_pos:
pos_code = self.code.setdefault(self.last_pos[0].filename, {}) source_desc, line, _ = self.last_annotated_pos
code = pos_code.get(self.last_pos[1], "") pos_code = self.code[source_desc.filename]
pos_code[self.last_pos[1]] = code + self.annotation_buffer.getvalue() pos_code[line] += self.annotation_buffer.getvalue()
self.annotation_buffer = StringIO() self.annotation_buffer = StringIO()
self.last_pos = pos self.last_annotated_pos = pos
def annotate(self, pos, item): def annotate(self, pos, item):
self.annotations.append((pos, item)) self.annotations.append((pos, item))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment