Commit 859e52bb authored by Robert Bradshaw's avatar Robert Bradshaw

Annotation work

parent ad3415a3
...@@ -7,6 +7,10 @@ from StringIO import StringIO ...@@ -7,6 +7,10 @@ from StringIO import StringIO
from Code import CCodeWriter from Code import CCodeWriter
# need one-characters subsitutions (for now) so offsets aren't off
special_chars = [('<', '\xF0', '&lt;'),
('>', '\xF1', '&gt;'),
('&', '\xF2', '&amp;')]
class AnnotationCCodeWriter(CCodeWriter): class AnnotationCCodeWriter(CCodeWriter):
...@@ -29,14 +33,13 @@ class AnnotationCCodeWriter(CCodeWriter): ...@@ -29,14 +33,13 @@ class AnnotationCCodeWriter(CCodeWriter):
# if pos is not None: # if pos is not None:
# CCodeWriter.mark_pos(self, pos) # CCodeWriter.mark_pos(self, pos)
# return # return
print "marking", pos
if self.last_pos: if self.last_pos:
try: try:
code = self.code[self.last_pos[1]] code = self.code[self.last_pos[1]]
except KeyError: except KeyError:
code = "" code = ""
self.code[self.last_pos[1]] = code + self.buffer.getvalue() self.code[self.last_pos[1]] = code + self.buffer.getvalue()
self.buffer = StringIO() self.buffer = StringIO()
self.last_pos = pos self.last_pos = pos
def annotate(self, pos, item): def annotate(self, pos, item):
...@@ -47,12 +50,10 @@ class AnnotationCCodeWriter(CCodeWriter): ...@@ -47,12 +50,10 @@ class AnnotationCCodeWriter(CCodeWriter):
f = open(filename) f = open(filename)
lines = f.readlines() lines = f.readlines()
for k in range(len(lines)): for k in range(len(lines)):
# there has to be a better way to do this line = lines[k]
lines[k] = lines[k].replace(' ','\t ') for c, cc, html in special_chars:
lines[k] = lines[k].replace(' ','\t\t') line = line.replace(c, cc)
# TODO: this is incorrect lines[k] = line
lines[k] = lines[k].replace('<', '~')
lines[k] = lines[k].replace('>', '~')
f.close() f.close()
all = [] all = []
for pos, item in self.annotations: for pos, item in self.annotations:
...@@ -86,6 +87,7 @@ body { font-family: courier; font-size: 12; } ...@@ -86,6 +87,7 @@ body { font-family: courier; font-size: 12; }
.py_api { color: red; } .py_api { color: red; }
.pyx_api { color: #FF3000; } .pyx_api { color: #FF3000; }
.py_macro_api { color: #FF8000; } .py_macro_api { color: #FF8000; }
.error_goto { color: #FF8000; }
.tag { } .tag { }
...@@ -97,6 +99,8 @@ body { font-family: courier; font-size: 12; } ...@@ -97,6 +99,8 @@ body { font-family: courier; font-size: 12; }
.py_call { color: #FF0000; font-weight: bold; } .py_call { color: #FF0000; font-weight: bold; }
.c_call { color: #0000FF; } .c_call { color: #0000FF; }
.line { margin: 0em }
</style> </style>
<script> <script>
function toggleDiv(id) { function toggleDiv(id) {
...@@ -113,6 +117,7 @@ function toggleDiv(id) { ...@@ -113,6 +117,7 @@ function toggleDiv(id) {
py_c_api = re.compile('(Py[A-Z][a-z]+_[A-Z][a-z][A-Za-z_]+)') py_c_api = re.compile('(Py[A-Z][a-z]+_[A-Z][a-z][A-Za-z_]+)')
pyx_api = re.compile('(__Pyx[A-Za-z_]+)\(') pyx_api = re.compile('(__Pyx[A-Za-z_]+)\(')
py_marco_api = re.compile('(Py[A-Za-z]*_[A-Z][A-Z_]+)') py_marco_api = re.compile('(Py[A-Za-z]*_[A-Z][A-Z_]+)')
error_goto = re.compile(r'(if .*? \{__pyx_filename = .*goto __pyx_L\w+;\})')
for line in lines: for line in lines:
...@@ -125,16 +130,18 @@ function toggleDiv(id) { ...@@ -125,16 +130,18 @@ function toggleDiv(id) {
code, c_api_calls = py_c_api.subn(r"<span class='py_api'>\1</span>", code) code, c_api_calls = py_c_api.subn(r"<span class='py_api'>\1</span>", code)
code, pyx_api_calls = pyx_api.subn(r"<span class='pyx_api'>\1</span>(", code) code, pyx_api_calls = pyx_api.subn(r"<span class='pyx_api'>\1</span>(", code)
code, macro_api_calls = py_marco_api.subn(r"<span class='py_macro_api'>\1</span>", code) code, macro_api_calls = py_marco_api.subn(r"<span class='py_macro_api'>\1</span>", code)
code, error_goto_calls = error_goto.subn(r"<span class='error_goto'>\1</span>", code)
color = "FFFF%02x" % int(255/(1+(5*c_api_calls+2*pyx_api_calls+macro_api_calls)/10.0)) color = "FFFF%02x" % int(255/(1+(5*c_api_calls+2*pyx_api_calls+macro_api_calls)/10.0))
f.write("<div class='line' style='background-color: #%s' onclick='toggleDiv(\"line%s\")'>" % (color, k)) f.write("<pre class='line' style='background-color: #%s' onclick='toggleDiv(\"line%s\")'>" % (color, k))
f.write(" %d: " % k) f.write(" %d: " % k)
line = line.replace('\t', '&nbsp;') for c, cc, html in special_chars:
f.write(line) line = line.replace(cc, html)
f.write(line.rstrip())
f.write('</div>\n') f.write('</pre>\n')
f.write("<div id='line%s' class='code' style='background-color: #%s'>%s</div>" % (k, color, code.replace('\n', '\n<br>'))) f.write("<pre id='line%s' class='code' style='background-color: #%s'>%s</pre>" % (k, color, code))
f.write('</body></html>\n') f.write('</body></html>\n')
f.close() f.close()
......
...@@ -98,6 +98,8 @@ class CCodeWriter: ...@@ -98,6 +98,8 @@ class CCodeWriter:
return "0x%02X%02X%02X%02X" % (tuple(pyversion) + (0,0,0,0))[:4] return "0x%02X%02X%02X%02X" % (tuple(pyversion) + (0,0,0,0))[:4]
def mark_pos(self, pos): def mark_pos(self, pos):
if pos is None:
return
file, line, col = pos file, line, col = pos
contents = self.file_contents(file) contents = self.file_contents(file)
......
...@@ -217,12 +217,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -217,12 +217,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self.generate_py_string_decls(env, code) self.generate_py_string_decls(env, code)
self.generate_cached_builtins_decls(env, code) self.generate_cached_builtins_decls(env, code)
self.body.generate_function_definitions(env, code) self.body.generate_function_definitions(env, code)
code.mark_pos(None)
self.generate_interned_name_table(env, code) self.generate_interned_name_table(env, code)
self.generate_py_string_table(env, code) self.generate_py_string_table(env, code)
self.generate_typeobj_definitions(env, code) self.generate_typeobj_definitions(env, code)
self.generate_method_table(env, code) self.generate_method_table(env, code)
self.generate_filename_init_prototype(code) self.generate_filename_init_prototype(code)
self.generate_module_init_func(modules[:-1], env, code) self.generate_module_init_func(modules[:-1], env, code)
code.mark_pos(None)
self.generate_module_cleanup_func(env, code) self.generate_module_cleanup_func(env, code)
self.generate_filename_table(code) self.generate_filename_table(code)
self.generate_utility_functions(env, code) self.generate_utility_functions(env, code)
...@@ -1196,6 +1198,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1196,6 +1198,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
"};") "};")
def generate_interned_name_table(self, env, code): def generate_interned_name_table(self, env, code):
code.mark_pos(None)
items = env.intern_map.items() items = env.intern_map.items()
if items: if items:
items.sort() items.sort()
...@@ -1280,6 +1283,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1280,6 +1283,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self.generate_type_import_code_for_module(module, env, code) self.generate_type_import_code_for_module(module, env, code)
code.putln("/*--- Execution code ---*/") code.putln("/*--- Execution code ---*/")
code.mark_pos(None)
self.body.generate_execution_code(code) self.body.generate_execution_code(code)
if Options.generate_cleanup_code: if Options.generate_cleanup_code:
......
...@@ -88,8 +88,6 @@ class Node: ...@@ -88,8 +88,6 @@ class Node:
# mro does the wrong thing # mro does the wrong thing
if isinstance(self, BlockNode): if isinstance(self, BlockNode):
self.body.annotate(code) self.body.annotate(code)
else:
print "skipping", self
class BlockNode: class BlockNode:
......
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