<p>Code clone detection has garnered significant attention across various fields, including code refactoring, plagiarism detection, and software maintenance. Numerous methods have been proposed for detecting code clones; however, while text-based and token-based approaches are scalable, they often fail to consider code semantics and are unable to effectively handle semantic code clones. Although tree-based methods perform well in semantic code clone detection, they are limited by the complex structure of trees, making it challenging to apply to large-scale clone detection. Moreover, these methods struggle to achieve fine-grained semantic code clone detection, lacking the ability to pinpoint specific code blocks within semantic clones. In this paper, we propose <i>Rator</i>, a tree-based code clone detector that combines scalability and fine-grained analysis capabilities while effectively detecting semantic clones. Specifically, we design a tree encoding method based on node degrees of freedom, which can transform complex tree structures into simple vector representations while preserving the structural details of the tree. In this way, we can encode all the subtrees of the <i>abstract syntax tree</i> into separate sets of vectors and derive similar features by calculating the similarity between these vectors. The derived similar features serve dual purposes: firstly, they are employed to train a machine learning-based code clone detector, and then, by analyzing the subtree types corresponding to the feature values, specific clone code blocks can be precisely located, thus achieving fine-grained code clone detection. Experimental results show that <i>Rator</i> outperforms nine state-of-the-art code clone detectors with F1 scores of 0.99 and 0.91 on BigCloneBench and Google Code Jam datasets, respectively. As for scalability, <i>Rator</i> is about 93 times faster than <i>ASTNN</i>, another state-of-the-art tree-based semantic clone detector. Regarding fine-grained detection, <i>Rator</i> correctly identifies the concrete clone block with a Top-3 ranked list. Furthermore, the accuracy of fine-grained detection on the Google Code Jam dataset is up to 100% with a Top-2 ranked list.</p>

错误:搜索内容不能为空,请输入英文关键词
错误:关键词超出字数限制,请精简
高级检索

Rator: detecting fine-grained semantic code clones using tree encoding based on node degrees of freedom

  • Yu Zhang,
  • Yutao Hu,
  • Bing Sun,
  • Rui Lou,
  • Huanwei Wang,
  • Weiyu Dong

摘要

Code clone detection has garnered significant attention across various fields, including code refactoring, plagiarism detection, and software maintenance. Numerous methods have been proposed for detecting code clones; however, while text-based and token-based approaches are scalable, they often fail to consider code semantics and are unable to effectively handle semantic code clones. Although tree-based methods perform well in semantic code clone detection, they are limited by the complex structure of trees, making it challenging to apply to large-scale clone detection. Moreover, these methods struggle to achieve fine-grained semantic code clone detection, lacking the ability to pinpoint specific code blocks within semantic clones. In this paper, we propose Rator, a tree-based code clone detector that combines scalability and fine-grained analysis capabilities while effectively detecting semantic clones. Specifically, we design a tree encoding method based on node degrees of freedom, which can transform complex tree structures into simple vector representations while preserving the structural details of the tree. In this way, we can encode all the subtrees of the abstract syntax tree into separate sets of vectors and derive similar features by calculating the similarity between these vectors. The derived similar features serve dual purposes: firstly, they are employed to train a machine learning-based code clone detector, and then, by analyzing the subtree types corresponding to the feature values, specific clone code blocks can be precisely located, thus achieving fine-grained code clone detection. Experimental results show that Rator outperforms nine state-of-the-art code clone detectors with F1 scores of 0.99 and 0.91 on BigCloneBench and Google Code Jam datasets, respectively. As for scalability, Rator is about 93 times faster than ASTNN, another state-of-the-art tree-based semantic clone detector. Regarding fine-grained detection, Rator correctly identifies the concrete clone block with a Top-3 ranked list. Furthermore, the accuracy of fine-grained detection on the Google Code Jam dataset is up to 100% with a Top-2 ranked list.