一句话:提出 FaCoY,通过查询改写静态搜索与输入代码语义相似的代码片段。
代码搜索是软件开发中的常见活动,但现有方法多面向自然语言查询,缺乏对代码到代码搜索的支持。论文提出 FaCoY,一种静态查找与用户输入代码在语义上可能相似的代码片段的方法。FaCoY 采用查询改写策略:不直接将代码查询 token 与搜索空间中的代码匹配,而是先识别可能同样参与实现输入代码功能行为的其他 token。实验表明,FaCoY 比在线代码到代码搜索引擎更有效;在 BigCloneBench 上比现有方法检测出更多语义代码克隆(Type-4);尽管是静态方法,仍能发现运行时执行行为确实相似的代码片段;并可用于代码/补丁推荐。
Code search is an unavoidable activity in software development. Various approaches and techniques have been explored in the literature to support code search tasks. Most of these approaches focus on serving user queries provided as natural language free-form input. However, there exists a wide range of use-case scenarios where a code-to-code approach would be most beneficial. For example, research directions in code transplantation, code diversity, patch recommendation can leverage a code-to-code search engine to find essential ingredients for their techniques. In this paper, we propose FaCoY, a novel approach for statically finding code fragments which may be semantically similar to user input code. FaCoY implements a query alternation strategy: instead of directly matching code query tokens with code in the search space, FaCoY first attempts to identify other tokens which may also be relevant in implementing the functional behavior of the input code. With various experiments, we show that (1) FaCoY is more effective than online code-to-code search engines; (2) FaCoY can detect more semantic code clones (i.e., Type-4) in BigCloneBench than the state-of-the-art; (3) FaCoY, while static, can detect code fragments which are indeed similar with respect to runtime execution behavior; and (4) FaCoY can be useful in code/patch recommendation.
@inproceedings{paperbot4417,
title = {F
<scp>a</scp>
C
<scp>o</scp>
Y},
author = {Kisub Kim and Dongsun Kim and Tegawendé F. Bissyandé and Eunjong Choi and Li Li and Jacques Klein and Yves Le Traon},
booktitle = {ICSE},
year = {2018},
doi = {10.1145/3180155.3180187}
}