changeset 143:f13a89c1a888

Updates for editor_info
author Sigurd Meldgaard <stm@daimi.au.dk>
date Mon, 23 Nov 2009 10:58:49 +0100
parents 4e35d7cf4fe8
children a95fc481028c
files pysmcl/editor_info.py
diffstat 1 files changed, 24 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/pysmcl/editor_info.py	Mon Nov 09 10:49:45 2009 +0100
+++ b/pysmcl/editor_info.py	Mon Nov 23 10:58:49 2009 +0100
@@ -1,29 +1,39 @@
 import pysmcl.ast_wrapper as ast
 import sys
+from pysmcl.flow import Flow
+from pysmcl.graph import Graph
 from pysmcl.secret_annotator import secret_analysis, expr_secret
-from pysmcl.pretty_print import  expr_string
-import StringIO
+from pysmcl.pretty_print import  expr_string, pprint
+from pysmcl.range_analysis import RangeAnalysis
 
+def is_ideal_functionality(function_def):
+    return any([decorator.id == 'ideal_functionality' for decorator in function_def.decorator_list])
 
 def main():
     try:
-        module = ast.parse(file(sys.argv[1]).read())
+        prog = ast.parse(file(sys.argv[1]).read())
     except SyntaxError:
         exit(2)  # Exit code signalling syntax error.
     for i in prog.body:
         if isinstance(i, ast.FunctionDef):
             secret_analysis(i)
-    for i in prog.body:
-        if(isinstance(i, ast.FunctionDef) and
-           any([decorator.id == 'ideal_functionality' for decorator in i.decorator_list])):
-            for j in ast.walk(i):
-                if isinstance(j, ast.stmt):
-                    e = j.out_values["secret"]
-                if isinstance(j, ast.expr):
-                    if expr_secret(j, e):
-                        output = StringIO.StringIO()
-                        print "%d %d %d" % (j.lineno, j.col_offset,
-                                              len(expr_string(j)))
+    # Graph(Flow().to_dot(prog.body[1])).to_dot()
+    for top_level_statement in prog.body:
+        if(isinstance(top_level_statement, ast.FunctionDef) and
+           is_ideal_functionality(top_level_statement)):
+            RangeAnalysis(13).apply(top_level_statement)
+            for statement in top_level_statement.body:
+                for j in ast.walk(statement):
+                    if isinstance(j, ast.stmt):
+                        e = j.out_values["secret"]
+                        r = j.out_values["range"]
+                    if isinstance(j, ast.expr):
+                        if expr_secret(j, e):
+                            print "%d %d %d" % (j.lineno, j.col_offset,
+                                                len(expr_string(j)))
+                    if isinstance(j, ast.Name) and not isinstance(j.parent, ast.Call):
+                        pass#                        print "%s has values in %s" % (j.id, str(r[j.id]))
+
 
 if __name__ == "__main__":
     main()