Existing research suggests that a considerable fraction (5-10%) of the source code of large scale computer programs is duplicate code ("clones"). Detection and removal of such clones promises decreased software maintenance costs of possibly the same magnitude. Previous work was limited to detection of either near misses differing only in single lexems, or near misses only between complete functions. The paper presents simple and practical methods for detecting exact and near miss clones over arbitrary program fragments in program source code by using abstract syntax trees. Previous work also did not suggest practical means for removing detected clones. Since our methods operate in terms of the program structure, clones could be removed by mechanical methods producing in-lined procedures or standard preprocessor macros. A tool using these techniques is applied to a C production software system of some 400 K source lines, and the results confirm detected levels of duplication found by previous work. The tool produces macro bodies needed for clone removal, and macro invocations to replace the clones. The tool uses a variation of the well known compiler method for detecting common sub expressions. This method determines exact tree matches; a number of adjustments are needed to detect equivalent statement sequences, commutative operands, and nearly exact matches. We additionally suggest that clone detection could also be useful in producing more structured code, and in reverse engineering to discover domain concepts and their implementations.
[1]
Brenda S. Baker,et al.
On finding duplication and near-duplication in large software systems
,
1995,
Proceedings of 2nd Working Conference on Reverse Engineering.
[2]
J. Howard Johnson,et al.
Navigating the textual redundancy web in legacy source
,
1996,
CASCON.
[3]
Ettore Merlo,et al.
Assessing the benefits of incorporating function clone detection in a development process
,
1997,
1997 Proceedings International Conference on Software Maintenance.
[4]
Ray J. Frank,et al.
Dynamic competitive learning applied to the clone detection problem
,
1995
.
[5]
J. Howard Johnson,et al.
Substring matching for clone detection and change tracking
,
1994,
Proceedings 1994 International Conference on Software Maintenance.
[6]
Alfred V. Aho,et al.
Compilers: Principles, Techniques, and Tools
,
1986,
Addison-Wesley series in computer science / World student series edition.
[7]
Jean-Marc DeBaud,et al.
DARE: domain-augmented reengineering
,
1997,
Proceedings of the Fourth Working Conference on Reverse Engineering.
[8]
Susan L. Graham,et al.
Incremental analysis of real programming languages
,
1997,
PLDI '97.
[9]
Christopher W. Pidgeon,et al.
Software change through design maintenance
,
1997,
1997 Proceedings International Conference on Software Maintenance.