高级检索

    基于Petri网可达分析的代码搜索方法

    Code Search Method Based on the Reachability Analysis of Petri Nets

    • 摘要: 复用已有高质量源代码可提高软件开发效率及软件质量.当前,基于用户提供的输入输出对的匹配判断是代码语义搜索的主要方法之一,但该方法难以刻画完整代码行为,且仅能处理单输入类型.提出一种针对多种形式类型匹配的代码语义搜索方法.首先将代码集内各个代码片段中数据对象个数及类型的加工过程转换为Petri网模型;其次根据用户查询中蕴含的数据类型及个数、输出数据类型等约束来构造Petri网初始标识和目标标识;然后在Petri网中通过可达图及诱发网分析判断是否存在相应的可达路径,从而获得代码匹配依据.分析及实验表明,该方法能有效实现多种形式的输入输出类型匹配的代码搜索,且相对于传统类型匹配方法,能明显提高搜索准确度和效率.

       

      Abstract: Reusing existing high-quality source codes can improve efficiency of software development and quality of software. At present, code search based on inputoutput queries provided by users is one of the main approaches in the field of code semantic search, but existing approaches are difficult to describe the complete behavior of codes and can only handle a single input type. This paper proposes a code semantic search approach based on the reachability analysis of Petri Nets for matching multiple forms of type. First, the semantic processes of code snippets consisting of the number of data objects and types of data objects in the code corpus are converted into improved Petri Net models. Second, the initial marking and target marking of Petri Net models are constructed according to the number of data objects and types of data objects contained in users’ queries. Matching code snippets is obtained by the analysis of reachable paths in reachability graphs and induced networks of Petri Nets. Analysis and experimental results show that this approach contributes to seeking out desired code snippets by queries that possess multiple forms of inputoutput types provided by users, and compared with traditional approaches, it can significantly improve accuracy and efficiency of code search.

       

    /

    返回文章
    返回