Detect functionally equivalent code fragments via k-nearest neighbor algorithm

Dandan Kong, Xiaohong Su, Shitang Wu, Tiantian Wang, Peijun Ma
{"title":"Detect functionally equivalent code fragments via k-nearest neighbor algorithm","authors":"Dandan Kong, Xiaohong Su, Shitang Wu, Tiantian Wang, Peijun Ma","doi":"10.1109/ICACI.2012.6463128","DOIUrl":null,"url":null,"abstract":"It is important for improving program to detect duplicated code (also known as code clone) in the field of software development and maintenance. The existing solutions can not effectively analyze the complex semantics of programs, and so can not effectively detect functionally equivalent code fragments that execute the same operations but with different syntax. This paper proposes a method to detect functionally equivalent code fragments via k-nearest neighbor algorithm. Firstly, the source code is statically analyzed to get the information of control dependency and data flow; then, k-nearest neighbor clustering algorithm is performed to form functionally independent code fragments; next, the input and output variables of the code fragments are identified, and the code fragments are transformed to compilable and executable functions, then the automatic random assignment for the input variables of functions are carried out. At last, the functions are dynamically tested and are classified into different clusters according to the testing outputs. Experimental results show that this method can effectively get functionally equivalent code fragments with a lower time complexity.","PeriodicalId":404759,"journal":{"name":"2012 IEEE Fifth International Conference on Advanced Computational Intelligence (ICACI)","volume":"6 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2012-10-01","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"7","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"2012 IEEE Fifth International Conference on Advanced Computational Intelligence (ICACI)","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1109/ICACI.2012.6463128","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 7

Abstract

It is important for improving program to detect duplicated code (also known as code clone) in the field of software development and maintenance. The existing solutions can not effectively analyze the complex semantics of programs, and so can not effectively detect functionally equivalent code fragments that execute the same operations but with different syntax. This paper proposes a method to detect functionally equivalent code fragments via k-nearest neighbor algorithm. Firstly, the source code is statically analyzed to get the information of control dependency and data flow; then, k-nearest neighbor clustering algorithm is performed to form functionally independent code fragments; next, the input and output variables of the code fragments are identified, and the code fragments are transformed to compilable and executable functions, then the automatic random assignment for the input variables of functions are carried out. At last, the functions are dynamically tested and are classified into different clusters according to the testing outputs. Experimental results show that this method can effectively get functionally equivalent code fragments with a lower time complexity.
通过k近邻算法检测功能等效的代码片段
在软件开发和维护领域,检测重复代码(也称为代码克隆)对于改进程序具有重要意义。现有的解决方案不能有效地分析程序的复杂语义,因此不能有效地检测执行相同操作但语法不同的功能等效代码片段。本文提出了一种基于k近邻算法的功能等效码片段检测方法。首先,对源代码进行静态分析,得到控制依赖关系和数据流信息;然后,采用k近邻聚类算法形成功能独立的代码片段;然后,识别代码片段的输入和输出变量,将代码片段转换为可编译和可执行的函数,然后对函数的输入变量进行自动随机赋值。最后,根据测试结果对函数进行动态测试,并将其分类到不同的聚类中。实验结果表明,该方法可以有效地获得功能等效的代码片段,且时间复杂度较低。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
求助全文
约1分钟内获得全文 求助全文
来源期刊
自引率
0.00%
发文量
0
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
确定
请完成安全验证×
copy
已复制链接
快去分享给好友吧!
我知道了
右上角分享
点击右上角分享
0
联系我们:info@booksci.cn Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。 Copyright © 2023 布克学术 All rights reserved.
京ICP备2023020795号-1
ghs 京公网安备 11010802042870号
Book学术文献互助
Book学术文献互助群
群 号:481959085
Book学术官方微信