changeset 133:5252a8c52011

ast: Added parent pointers to ast nodes via a wrapper of ast. The wrapper should have been called ast, but this gave problems with relative imports. All imports of ast are now pysmcl.ast_wrapper as ast.
author Sigurd Meldgaard <stm@daimi.au.dk>
date Mon, 02 Nov 2009 12:02:08 +0100
parents 4e2a22493116
children 8e496d0ea446
files pysmcl/ast_wrapper.py pysmcl/bad_calls.py pysmcl/compatibility_check.py pysmcl/emacs/info.py pysmcl/flow.py pysmcl/ideal_functionality.py pysmcl/pretty_print.py pysmcl/proof_burden.py pysmcl/range_analysis.py pysmcl/secret_annotator.py pysmcl/secret_ifs.py pysmcl/simpl_print.py pysmcl/test/unit/test_flow.py pysmcl/test/unit/test_rangeanalysis.py pysmcl/test/unit/test_secret_annotator.py pysmcl/test/unit/test_secret_ifs.py
diffstat 16 files changed, 42 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pysmcl/ast_wrapper.py	Mon Nov 02 12:02:08 2009 +0100
@@ -0,0 +1,22 @@
+from ast import *
+import ast 
+"""
+Wrapper of the python ast builtin-module.
+
+Ensures that nodes of parse-trees have parent pointers.
+"""
+
+def parse(f):
+    def make_ast_parents(n):
+        for i in ast.iter_child_nodes(n):
+            i.parent = n
+            make_ast_parents(i)
+
+    m = ast.parse(f)
+    make_ast_parents(m)
+    return m
+
+def get_ancestor(node, type):
+    while not isinstance(node, type):
+        node = node.parent
+    return node
--- a/pysmcl/bad_calls.py	Mon Nov 02 11:33:30 2009 +0100
+++ b/pysmcl/bad_calls.py	Mon Nov 02 12:02:08 2009 +0100
@@ -1,5 +1,5 @@
 import util
-import ast
+import pysmcl.ast_wrapper as ast
 from secret_annotator import expr_secret, non_compromising_functions
 
 
--- a/pysmcl/compatibility_check.py	Mon Nov 02 11:33:30 2009 +0100
+++ b/pysmcl/compatibility_check.py	Mon Nov 02 12:02:08 2009 +0100
@@ -1,4 +1,4 @@
-import ast
+import pysmcl.ast_wrapper as ast
 
 # Import PySMCL packages.
 from pysmcl.util import error
--- a/pysmcl/emacs/info.py	Mon Nov 02 11:33:30 2009 +0100
+++ b/pysmcl/emacs/info.py	Mon Nov 02 12:02:08 2009 +0100
@@ -1,4 +1,4 @@
-import ast
+import pysmcl.ast_wrapper as ast
 import sys
 from pysmcl.secret_annotator import secret_analysis, expr_secret
 from pysmcl.pretty_print import  expr_string
@@ -7,7 +7,7 @@
 
 def main():
     try:
-        prog = ast.parse(file(sys.argv[1]).read())
+        module = ast.parse(file(sys.argv[1]).read())
     except SyntaxError:
         exit(2)  # Exit code signalling syntax error.
     for i in prog.body:
--- a/pysmcl/flow.py	Mon Nov 02 11:33:30 2009 +0100
+++ b/pysmcl/flow.py	Mon Nov 02 12:02:08 2009 +0100
@@ -1,4 +1,4 @@
-import ast
+import pysmcl.ast_wrapper as ast
 import StringIO
 
 # Import PySMCL packages.
--- a/pysmcl/ideal_functionality.py	Mon Nov 02 11:33:30 2009 +0100
+++ b/pysmcl/ideal_functionality.py	Mon Nov 02 12:02:08 2009 +0100
@@ -1,5 +1,5 @@
 import inspect
-import ast
+import pysmcl.ast_wrapper as ast
 from collections import defaultdict
 
 # Import PySMCL packages.
--- a/pysmcl/pretty_print.py	Mon Nov 02 11:33:30 2009 +0100
+++ b/pysmcl/pretty_print.py	Mon Nov 02 12:02:08 2009 +0100
@@ -5,7 +5,8 @@
 program parsed into the ast.
 """
 
-import ast, sys
+import pysmcl.ast_wrapper as ast
+import sys
 
 
 def arguments_string(arguments):
--- a/pysmcl/proof_burden.py	Mon Nov 02 11:33:30 2009 +0100
+++ b/pysmcl/proof_burden.py	Mon Nov 02 12:02:08 2009 +0100
@@ -1,4 +1,4 @@
-import ast
+import pysmcl.ast_wrapper as ast
 import inspect
 
 # Import PySMCL packages.
--- a/pysmcl/range_analysis.py	Mon Nov 02 11:33:30 2009 +0100
+++ b/pysmcl/range_analysis.py	Mon Nov 02 12:02:08 2009 +0100
@@ -12,7 +12,7 @@
 """
 
 # Import system packages.
-import ast
+import pysmcl.ast_wrapper as ast
 
 # Import PySMCL packages.
 from pysmcl import flow
@@ -222,6 +222,9 @@
         raise Exception("NYI, subscript targets")
 
     def visit_Name(self, id):
+        if isinstance(id.parent, ast.Call) and id is id.parent.func:
+            # function names are not considered.
+            return
         if id in self.env.keys():
             self.env[id.id] = combine_range(self.env[id.id], self.range)
         else:
--- a/pysmcl/secret_annotator.py	Mon Nov 02 11:33:30 2009 +0100
+++ b/pysmcl/secret_annotator.py	Mon Nov 02 12:02:08 2009 +0100
@@ -1,5 +1,5 @@
 import util
-import ast
+import pysmcl.ast_wrapper as ast
 import pretty_print
 
 # Import PySMCL packages.
--- a/pysmcl/secret_ifs.py	Mon Nov 02 11:33:30 2009 +0100
+++ b/pysmcl/secret_ifs.py	Mon Nov 02 12:02:08 2009 +0100
@@ -4,7 +4,7 @@
 assignments
 """
 
-import ast
+import pysmcl.ast_wrapper as ast
 
 # Import PySMCL packages.
 from pysmcl.util import error
--- a/pysmcl/simpl_print.py	Mon Nov 02 11:33:30 2009 +0100
+++ b/pysmcl/simpl_print.py	Mon Nov 02 12:02:08 2009 +0100
@@ -6,7 +6,7 @@
 program parsed into the ast.
 """
 
-import ast
+import pysmcl.ast_wrapper as ast
 import sys
 
 
--- a/pysmcl/test/unit/test_flow.py	Mon Nov 02 11:33:30 2009 +0100
+++ b/pysmcl/test/unit/test_flow.py	Mon Nov 02 12:02:08 2009 +0100
@@ -3,7 +3,7 @@
 import unittest
 import StringIO
 
-from ast import *
+from pysmcl.ast_wrapper import *
 from pysmcl.range_analysis import RangeAnalysis, Bottom
 
 from pysmcl.graph import Graph
--- a/pysmcl/test/unit/test_rangeanalysis.py	Mon Nov 02 11:33:30 2009 +0100
+++ b/pysmcl/test/unit/test_rangeanalysis.py	Mon Nov 02 12:02:08 2009 +0100
@@ -1,6 +1,6 @@
 import unittest
 
-from ast import *
+from pysmcl.ast_wrapper import *
 from pysmcl.range_analysis import RangeAnalysis, Bottom, full_range
 
 
--- a/pysmcl/test/unit/test_secret_annotator.py	Mon Nov 02 11:33:30 2009 +0100
+++ b/pysmcl/test/unit/test_secret_annotator.py	Mon Nov 02 12:02:08 2009 +0100
@@ -2,7 +2,7 @@
 
 import unittest
 
-from ast import *
+from pysmcl.ast_wrapper import *
 
 from pysmcl.pretty_print import *
 from pysmcl.secret_ifs import TransformIfs
--- a/pysmcl/test/unit/test_secret_ifs.py	Mon Nov 02 11:33:30 2009 +0100
+++ b/pysmcl/test/unit/test_secret_ifs.py	Mon Nov 02 12:02:08 2009 +0100
@@ -1,6 +1,6 @@
 import unittest
 import StringIO
-from ast import parse
+from pysmcl.ast_wrapper import parse
 from pysmcl.pretty_print import pprint
 from pysmcl.secret_ifs import TransformIfs
 from pysmcl.secret_annotator import secret_analysis