Tool Demonstration: Finding Duplicated Code Using Program Dependences
The results of several studies [1,7,8] indicate that 7-23% of the source code for large programs is duplicated code. Duplication makes programs harder to maintain because when enhancements or bug fixes are made in one instance of the duplicated code, it is necessary to search for the other instances in order to perform the corresponding modification.
A tool that finds clones (instances of duplicated code) can help to alleviate this problem. When code is modified, the tool can be used to find the other copies that also need modification. Alternatively, the clones identified by the tool can be extracted into a new procedure, and the clones themselves replaced by calls to that procedure. In that case, there is only one copy to maintain (the new procedure), and the fact that the procedure can be reused may cut down on future duplication.
We have designed and implemented a tool for C programs that finds clones and displays them to the programmer. To find clones in a program, we represent each procedure using its program dependence graph (PDG) . In the PDG, nodes represent program statements and predicates, and edges represent data and control dependences. To find a pair of clones we use a variation on backward slicing [11,10].
KeywordsIsomorphic Subgraph Ideal Clone Clone Group Control Dependence Clone Detection
- 1.B. Baker. On finding duplication and near-duplication in large software systems. In Proc. IEEE Working Conf. on Reverse Eng., pages 86–95, July 1995.Google Scholar
- 3.I. Baxter, A. Yahin, L. Moura, M. Sant’Anna, and L. Bier. Clone detection using abstract syntax trees. In Int. Conf. on Software Maint., pages 368–378, 1998.Google Scholar
- 4.N. Davey, P. Barson, S. Field, R. Frank, and D. Tansley. The development of a software clone detector. Int. Jrnl. of Applied Software Tech., 1(3-4):219–36, 1995.Google Scholar
- 8.B. Lague, D. Proulx, J. Mayrand, E. Merlo, and J. Hudepohl. Assessing the benefits of incorporating function clone detection in a development process. In Int. Conf. on Software Maint., pages 314–321, 1997.Google Scholar
- 9.J. Mayrand, C. Leblanc, and E. Merlo. Experiment on the automatic detection of function clones in a software system using metrics. In Proc. of the Int. Conf. on Software Maint., pages 244–254, 1996.Google Scholar
- 10.K. Ottenstein and L. Ottenstein. The program dependence graph in a software development environment. In Proc. ACM SIGSOFT/SIGPLAN Software Eng. Symp. on Practical Software Development Environments, pages 177–184, 1984.Google Scholar