Code Clone Detection Method Based on the Combination of Tree-Based and Token-Based Methods
- 1 Graduate School of Science and Engineering, Doshisha University, Kyoto, Japan
- 2 Graduate School of Science and Engineering, Doshisha University, Kyoto, Japan
Abstract
This article proposes the high-speed and high-accuracy code clone detection method based on the combination of tree-based and token-based methods. Existence of duplicated program codes, called code clone, is one of the main factors that reduces the quality and maintainability of software. If one code fragment contains faults (bugs) and they are copied and modified to other locations, it is necessary to correct all of them. But it is not easy to find all code clones in large and complex software. Much research efforts have been done for code clone detection. There are mainly two methods for code clone detection. One is token-based and the other is tree-based method. Token-based method is fast and requires less resources. However it cannot detect all kinds of code clones. Tree-based method can detect all kinds of code clones, but it is slow and requires much computing resources. In this paper combination of these two methods was proposed to improve the efficiency and accuracy of detecting code clones. Firstly some candidates of code clones will be extracted by token-based method that is fast and lightweight. Then selected candidates will be checked more precisely by using tree-based method that can find all kinds of code clones. The prototype system was developed. This system accepts source code and tokenizes it in the first step. Then token-based method is applied to this token sequence to find candidates of code clones. After extracting several candidates, selected source codes will be converted into abstract syntax tree (AST) for applying tree-based method. Some sample source codes were used to evaluate the proposed method. This evaluation proved the improvement of efficiency and precision of code clones detecting.
- Rattan, D., Bhatia, R. and Singh, M. (2013) Software Clone Detection: A Systematic Review. Information and Software Technology, 55, 1165-1199. https://doi.org/10.1016/j.infsof.2013.01.008
- Baker, B. (1995) On Finding Duplication and Near-Duplication in Large Software Systems. Proceedings of the 2nd Working Conference on Reverse Engineering (WCRE 1995), 86-95. https://doi.org/10.1109/WCRE.1995.514697
- Roy, C.K. and Cordy, J.R. (1995) An Empirical Study of Function Clones in Open Source Software Systems. Proceedings of the 15th Working Conference on Reverse Engineering (WCRE 2008), 81-90.
- Bellon, S., Koschke, R., Antoniol, G., Krinke, J. and Merlo, E. (2007) Comparison and Evaluation of Clone Detection Tools. IEEE Transactions on Software Engineering, SE-33, 577-591. https://doi.org/10.1109/TSE.2007.70725
- Kamiya, T., Kusumoto, S. and Inoue, K. (2002) CCFinder: A Multilinguistic Token-Based Code Clone Detection System for Large Scale Source Code. IEEE Transactions on Software Engineering, SE-28, 654-670. https://doi.org/10.1109/TSE.2002.1019480
- Li, Z., Lu, S., Myagmar, S. and Zhou, Y. (2006) CP-Miner: Finding Copy-Paste and Related Bugs in Large-Scale Software Code. IEEE Transactions on Software Engineering, SE-32, 176-192. https://doi.org/10.1109/TSE.2006.28
- Baxter, I.D., Yahin, A., Moura, L., Sant’Anna, M. and Bier, L. (1998) Clone Detection Using Abstract Syntax Trees. IEEE International Conference on Software Maintenance (ICSM 1998), 368-377. https://doi.org/10.1109/ICSM.1998.738528
- Yang, W. (1991) Identifying Syntactic Differences between Two Programs. Software Practice and Experience, 21, 739-755. https://doi.org/10.1002/spe.4380210706
- Anil Kumar, G., Reddy, C.R.K. and Govardhan, A. (2014) Software Code Clone Detection Using AST. International Journal of P2P Network Trends and Technology, 9, 33-39.
- Baker, B. (1992) A Program for Identifying Duplicated Code. Computing Science and Statistics, 24, 49-57.
- Krinke, J. (2001) Identifying Similar Code with Program Dependence Graphs. Proceedings of the 8th Working Conference on Reverse Engineering, 303-309.
- Bille, P. (2005) A Survey on Tree Edit Distance and Related Problems. Theoretical Computer Science, 337, 217-239. https://doi.org/10.1016/j.tcs.2004.12.030
- Demaine, E.D., Mozes S., Rossman, B. and Weimann, O. (2009) An Optimal Decomposition Algorithm for Tree edit Distance. ACM Transactions on Algorithms, 6, 2:1-2:19.