python语言控制流解析器。作为codimension项目的一部分编写的这个解析器旨在提取所有必要的数据来构建控制流图。

cdmcfparser的Python项目详细描述


CDM流分析器

cdm-flowparser project是一条Python 3(python 2支持有限)扩展模块。提供的模块 函数可以获取带有python代码或字符缓冲区的文件, 解析它并在 碎片的术语。每个片段描述输入的一部分: 起点(直线、列和绝对位置)加上终点 (直线、柱和绝对位置)。

注释也被保留。

模块在Codimension Python IDE中用于生成类似流程图的图表 对于用户键入的任意python代码。基本上是IDE 检测键入时的暂停并重新生成关系图。

python 3安装和构建

master branch 包含Python3的代码(包括3.5/3.6/3.7语法)。

可以使用pip安装模块:

pip install cdmcfparser

您还可以检索完整的源代码 公用事业。为此,您可以执行以下步骤:

git clone https://github.com/SergeySatskiy/cdm-flowparser.git
cd cdm-flowparser
make
make check
make localinstall

python 3:可视化分析的数据

假设存在具有以下内容的~/my-file.py文件:

#!/bin/env pythonimportsys# I like commentsa=154forxinrange(a):print("x = "+str(x))sys.exit(0)

然后您可以运行一个测试实用程序(如果您有一个本地 repository克隆:

~/cdm-flowparser/utils/run.py ~/my-file.py

输出如下:

Running control flow parser version: trunk
Module location: /home/swift/cdm-flowparser/cdmcfparser.cpython-35m-x86_64-linux-gnu.so
<ControlFlow [0:113] (1,1) (9,11)
 Body: [18:113] (2,1) (9,11)
 LeadingComment: None
 SideComment: None
 LeadingCMLComments: n/a
 SideCMLComments: n/a
 isOK: true
 Errors: n/a
 Warnings: n/a
 BangLine: [0:16] (1,1) (1,17)
 EncodingLine: None
 Docstring: None
 Suite: <Import [18:27] (2,1) (2,10)
         Body: [18:27] (2,1) (2,10)
         LeadingComment: None
         SideComment: None
         LeadingCMLComments: n/a
         SideCMLComments: n/a
         FromPart: None
         WhatPart: [25:27] (2,8) (2,10)
        >
        <CodeBlock [30:54] (4,1) (5,7)
         Body: [48:54] (5,1) (5,7)
         LeadingComment: <Comment [30:46] (4,1) (4,17)
                          Parts: <Fragment [30:46] (4,1) (4,17)
                                 >
                         >
         SideComment: None
         LeadingCMLComments: n/a
         SideCMLComments: n/a
        >
        <For [56:100] (6,1) (7,26)
         Body: [56:73] (6,1) (6,18)
         LeadingComment: None
         SideComment: None
         LeadingCMLComments: n/a
         SideCMLComments: n/a
         Async: None
         For: [56:58] (6,1) (6,3)
         Iteration: [60:72] (6,5) (6,17)
         Suite: <CodeBlock [79:100] (7,5) (7,26)
                 Body: [79:100] (7,5) (7,26)
                 LeadingComment: None
                 SideComment: None
                 LeadingCMLComments: n/a
                 SideCMLComments: n/a
                >
         ElsePart: None
        >
        <CodeBlock [103:113] (9,1) (9,11)
         Body: [103:113] (9,1) (9,11)
         LeadingComment: None
         SideComment: None
         LeadingCMLComments: n/a
         SideCMLComments: n/a
        >
>

python 2安装和构建

注意:不再支持python 2版本。会有的 不再发布Python2。

最新的Python2版本是1.0.1。预建模块和源代码 在github的releases区域中可以找到代码:latest Python 2 release 1.0.1

要从源代码构建Python2模块,请执行以下步骤:

cd
wget https://github.com/SergeySatskiy/cdm-flowparser/archive/v1.0.1.tar.gz
gunzip v1.0.1.tar.gz
tar -xf v1.0.1.tar
cd cdm-flowparser-1.0.1/
make
make localinstall
make check

python 2:可视化分析的数据

假设有如下文件~/my-file.py 内容:

#!/usr/bin/pythonimportsys# I like commentsa=154forxinxrange(a):print"x = "+str(x)sys.exit(0)

然后您可以运行测试实用程序:

~/cdm-flowparser/utils/run.py ~/my-file.py

输出如下:

Running control flow parser version: trunk
<ControlFlow [0:119] (1,1) (9,13)
 isOK: true
 Errors: n/a
 Warnings: n/a
 BangLine: [0:16] (1,1) (1,17)
 EncodingLine: None
 Docstring: None
 Suite: <Import [18:27] (2,1) (2,10)
         Body: [18:27] (2,1) (2,10)
         LeadingComment: None
         SideComment: None
         LeadingCMLComments: n/a
         SideCMLComments: n/a
         FromPart: None
         WhatPart: [25:27] (2,8) (2,10)
        >
        <CodeBlock [30:54] (4,1) (5,7)
         Body: [48:54] (5,1) (5,7)
         LeadingComment: <Comment [30:46] (4,1) (4,17)
                          Parts: <Fragment [30:46] (4,1) (4,17)
                                 >
                         >
         SideComment: None
         LeadingCMLComments: n/a
         SideCMLComments: n/a
        >
        <For [56:104] (6,1) (7,27)
         Body: [56:76] (6,1) (6,21)
         LeadingComment: None
         SideComment: None
         LeadingCMLComments: n/a
         SideCMLComments: n/a
         Iteration: [60:75] (6,5) (6,20)
         Suite: <CodeBlock [82:104] (7,5) (7,27)
                 Body: [82:104] (7,5) (7,27)
                 LeadingComment: None
                 SideComment: None
                 LeadingCMLComments: n/a
                 SideCMLComments: n/a
                >
         ElsePart: None
        >
        <SysExit [107:119] (9,1) (9,13)
         Body: [107:119] (9,1) (9,13)
         LeadingComment: None
         SideComment: None
         LeadingCMLComments: n/a
         SideCMLComments: n/a
         Argument: [117:117] (9,11) (9,11)
        >
>

发动机罩下

基本上,“run.py”实用程序具有以下基本行 以上示例:

fromcdmcfparserimportgetControlFlowFromFilecontrolFlow=getControlFlowFromFile("my-file.py")# Serializes nicely the controlFlow object# See the run.py for the details of how it is done

run.py在位于的本地克隆中可用 ~/cdm flowparser/utils/run.py或者您可以看到源代码 online

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java搜索具有外键的JPA实体的约定是什么?   java事务没有使用事务和嵌套方法的2个实例回滚   SpringBootJavaMessageFormat。使用umlauts格式(ä/ö/ü)   java如何通过字符串在sqlite中搜索列   JAVAlang.ClassNotFoundException:org。冬眠Hibernate4的例外情况   java消息正文在Gmail中被弄乱了   java Apache Ignite未使用空值更新缓存   Java正则表达式未捕获组   java onBackPressed();除非我叫super否则不行。onBackPressed();两次密码   java CustomAlertDialog在删除数据库记录后未完成其进程   C++中的迭代器(Stl)与java,是否存在概念上的区别?   Java在不知道字符编码的情况下将字节[]转换为字符串   来自本地WSDL文件的java Web服务客户端   java工具可用于在一个位置聚合所有项目相关信息   java在Netbeans中的maven项目中设置依赖项