Proceedings of ISP RAS


Automatic clone detection for refactoring.

N.G. Zetser.

Abstract

Software clones are repeating fragments of source code. Clones are considered harmful for many reasons and should be eliminated from the program. In this paper we study the possibility to combine automatic refactoring with the detection of repeating fragments in C/C++ source code. Classification of software clones is proposed in terms of their further use during automatic refactoring. Three types of clones are defined depending on the level of rigor: exact clones, clones withing the accuracy of concrete arithmetical expressions and clones of the third type – advanced version of the second type. For each clone type the method for detection is described. Proposed clone detection algorithm is based on program's abstract syntax tree (AST) analysis and, thus, it is accurate and does not have false positives. Existing clone detection tools are reviewed, their shortcomings are pointed out and it is shown that proposed method works correctly in considered situations. The approach described in this article has been implemented in the Klocwork inSight tool in refactorings “Extract method” and “Introduce variable”. Finally, idea on improvement of the proposed approach are given: using of data flow analysis.

Keywords

refactoring, clone detection

Edition

Proceedings of the Institute for System Programming, vol. 25, 2013, pp. 39-50.

ISSN 2220-6426 (Online), ISSN 2079-8156 (Print).

DOI: 10.15514/ISPRAS-2013-25-3

Full text of the paper in pdf (in Russian) Back to the contents of the volume