changeset 97:2ac1028c5c1a

First steps towards an emacs mode
author Sigurd Meldgaard <stm@daimi.au.dk>
date Mon, 08 Jun 2009 15:39:32 +0200
parents 2bbef4d20678
children 856feae68946
files pysmcl/emacs/__init__.py pysmcl/emacs/colorize.el pysmcl/emacs/info.py
diffstat 2 files changed, 63 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pysmcl/emacs/colorize.el	Mon Jun 08 15:39:32 2009 +0200
@@ -0,0 +1,33 @@
+(defun pos-from-line-col (line col)
+  (save-excursion
+    (goto-line line)
+    (beginning-of-line)
+    (forward-char col)
+    (point)))
+
+(defun markup-secret ()
+  (interactive)
+  (b)
+  (let ((l (read (shell-command-to-string (concat
+                            "cd /users/stm/pysmcl_work ; python -m pysmcl/emacs/info "
+                            (buffer-file-name)
+                            " "
+                            (format "%d" (line-number-at-pos) ))))))
+    (message (format "%s" l))
+    (setq overlays (mapcar (lambda (x)
+              (let* ((pos (pos-from-line-col (car x) (cadr x)))
+                     (end-pos (+ pos (caddr x))))
+                (let ((overlay (make-overlay pos end-pos)))
+                  (overlay-put overlay 'face 'underline)
+                  overlay)))
+            l) )))
+
+(defun b ()
+  (interactive)
+   (mapcar (lambda (overlay) (delete-overlay overlay)) overlays))
+
+;                (delete-overlay foo)
+
+                (message l)))))
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pysmcl/emacs/info.py	Mon Jun 08 15:39:32 2009 +0200
@@ -0,0 +1,30 @@
+import ast
+import sys
+from pysmcl.secret_annotator import secret_analysis, expr_secret
+from pysmcl.pretty_print import  expr_string
+import StringIO
+
+
+def main():
+    prog = ast.parse(file(sys.argv[1]).read())
+    linenr = int(sys.argv[2]) if len(sys.argv) > 2 else 0
+    print "("
+    for i in prog.body:
+        if isinstance(i, ast.FunctionDef):
+            secret_analysis(i)
+    for i in prog.body:
+        if isinstance(i, ast.FunctionDef):
+            for j in ast.walk(i):
+                if isinstance(j, ast.stmt):
+                    e = j.out_values["secret"]
+                if isinstance(j, ast.expr):
+                    try:
+                        if expr_secret(j, e):
+                            output = StringIO.StringIO()
+                            print "(%d %d %d)" % (j.lineno, j.col_offset,
+                                                  len(expr_string(j)))
+                    except:
+                        pass
+    print ")"
+if __name__ == "__main__":
+    main()