A control flow generator for Python that is able to generate control flow graphs and corresponding flows. The motivation behind this project is to generate flows suitable for data flow analysis for Python. In my plan, an instance of a dynamic monotone framework is going to be implemented upon it.
I'm doing my master's thesis now. In order to save some time, now the latest py2flows code lies in dmf. You can find it in module dmf.flows.
After I finish my thesis, I will update this project.
- Python 3.7
- [] Python 3.8(Untested)
- [] Python 3.9(Untested)
- [] Python 3.10(Untested)
- ast.Module
- ast.FunctionDef
- ast.AsyncFunctionDef(Poor support for now)
- ast.ClassDef
- ast.Return
- ast.Delete
- ast.Assign
- ast.AugAssign
- ast.AnnAssign
- ast.For
- ast.AsyncFor(Poor support for now)
- ast.While
- ast.If
- ast.With(Poor support for now)
- ast.AsyncWith(Poor support for now)
- ast.Raise(Poor support for now)
- ast.Try(Relatively poor support for now)
- ast.Assert
- ast.Import
- ast.ImportFrom
- ast.Global
- ast.Nonlocal
- ast.Expr
- ast.Pass
- ast.Break
- ast.Continue
- ast.BoolOp
- ast.BinOp
- ast.UnaryOp
- ast.Lambda
- ast.IfExp
- ast.Dict
- ast.Set
- ast.ListComp
- ast.SetComp
- ast.DictComp
- ast.GeneratorExp
- ast.Await
- ast.Yield
- ast.YieldFrom
- ast.Compare
- ast.Call
- ast.Num
- ast.Str
- ast.FormattedValue
- ast.JoinedStr
- ast.Bytes
- ast.NameConstant
- ast.Ellipsis
- ast.Constant
- ast.Attribute
- ast.Subscript
- ast.Starred
- ast.Name
- ast.List
- ast.Tuple
Support for other statements and expressions will be added gradually.
- Removal of comments and docstrings
- Decomposition of complex statements
- Isolated entries and exits
- [] Support for Modules and packages. Motivation: a project may contain multiple packages and modules. So we would like to maintain a data structure to represent this relationship. It would be helpful for static analysis.
- Refactor exception handling
- [] Count characteristics of each file. Motivation: Emm. It is related to my thesis topic. I wanna count the tendency of each source file. I bet this feature would be implemented in 2 weeks.
- Prune temporal variables
- Use two labels to denote call and return of each function call
- Understandable CFGs generated
- Use one return to denote all returns in functions
- [] The data structure representing classes. Motivation: As we know, classes consist of fields and methods. So it's better to have a good data structure to store and retrieve fields and methods elegantly. I think it also holds for functions(In modern languages, functions can be shadowed).
- Install all dependencies listed in requirements.txt
- Open a terminal and run
python setup.py install
- If step 2 succeeds, an executable file py2flows will be available.
py2flows --help
# 12_listcomp.py
z = [[1, 2, 3], [4, 5, 6]]
a = [x for x in [y for y in z]]
b = [2 * x for y in z if len(y) > 1 for x in y if x > 2 if x < 4]
def test():
while i <= n:
sum = sum + i
i = i + 1
print("no isolated entries and exits")
No isolated entries and exits
Isolated entries and exits