计算机科学与探索 ›› 2014, Vol. 8 ›› Issue (4): 446-455.DOI: 10.3778/j.issn.1673-9418.1311015

• 系统软件与软件工程 • 上一篇    下一篇

基于分组的代码克隆增量检测方法

王  海,林  云,彭  鑫+,赵文耘   

  1. 复旦大学 软件学院 软件工程实验室,上海 201203
  • 出版日期:2014-04-01 发布日期:2014-04-03

Grouping-Based Incremental Clone Detection Method

WANG Hai, LIN Yun, PENG Xin+, ZHAO Wenyun   

  1. Laboratory of Software Engineering, Software School, Fudan University, Shanghai 201203, China
  • Online:2014-04-01 Published:2014-04-03

摘要: 代码克隆是指软件程序中一组相同或相近的代码片段,它广泛存在于软件中,因此如何发现代码克隆成为软件维护的一个重要问题。目前已有的克隆检测工具大多针对单一版本进行完整的克隆检测,然而对于大规模、复杂软件系统而言,在软件演化过程中随着代码的改变,不断重新检测代码克隆将花费较高的代价。针对这一问题,提出了一种基于分组的增量克隆检测方法。该方法根据前后两个版本的差异将源代码分为发生变化和未发生变化的两组,通过组内和组间的克隆分析实现增量的克隆检测。基于所提出的方法,在克隆检测工具CCFinderX的基础上实现了一个名为ICDBG(incremental clone detector based on grouping)的原型工具。实验证明,在变更较小时,该方法能够在保证正确性的同时显著减少克隆检测时间。

关键词: 程序分析, 代码克隆, 克隆检测, 增量

Abstract: Code clones are identical or similar code fragments in software systems, and extensively exist in software systems, therefore detecting code clones is deemed as an important issue in software maintenance. The majority of clone detectors detect code clones only in one revision. However, the changes on source codes are on-going as software systems evolve incrementally and iteratively. Thus, re-detecting all the code clones whenever any change happens turns out to be very effort and time consuming. In order to address this issue, this paper proposes an incremental clone detection algorithm, which divides the source codes into two groups, the changed and unchanged codes, in a subject software project. By detecting clones inside as well as between those two groups, this algorithm can incrementally detect code clones without re-detecting the whole project. Based on the proposed algorithm, this paper implements a prototype tool called ICDBG (incremental clone detector based on grouping). The experimental results show that ICDBG decreases the detecting time with good accuracy.

Key words: program analysis, code clone, clone detection, incremental