Developers introduce code clones to improve programming productivity. Many existing studies have achieved impressive performance in monolingual code clone detection. However, during software development, more and more developers write semantically equivalent programs with different languages to support different platforms and help developers translate projects from one language to another. Considering that collecting cross-language parallel data, especially for low-resource languages, is expensive and time-consuming, how designing an effective cross-language model that does not rely on any parallel data is a significant problem. In this paper, we propose a novel method named ZC3 for Zero-shot Cross-language Code Clone detection. ZC3 designs the contrastive snippet prediction to form an isomorphic representation space among different programming languages. Based on this, ZC3 exploits domain-aware learning and cycle consistency learning to further constrain the model to generate representations that are aligned among different languages meanwhile are diacritical for different types of clones. To evaluate our approach, we conduct extensive experiments on four representative cross-language clone detection datasets. Experimental results show that ZC3 outperforms the state-of-the-art baselines by 67.12%, 51.39%, 14.85%, and 53.01% on the MAP score, respectively. We further investigate the representational distribution of different languages and discuss the effectiveness of our method.
成功的跨语言克隆检测可以使研究人员和开发人员创建强大的语言迁移工具,一旦掌握了一种程序设计语言,就可以方便地学习其他语言,并促进代码片段在更广泛的代码库中的重用。然而,识别跨语言克隆提出了特殊的挑战,克隆检测问题。任意语言之间缺乏公共的底层表示意味着检测克隆需要以下解决方案之一:1)跨每个目标语言复制的静态分析框架,其注释匹配所有语言的语言特征,或者2)基于运行时行为检测克隆的动态分析框架。在这项工作中,我们证明了后者的解决方案,一个动态分析方法称为SLACC跨语言克隆检测的可行性。与之前的克隆检测技术一样,我们使用输入/输出行为来匹配克隆,尽管我们通过放大输入的数量和覆盖更多的数据类型来克服之前工作的局限性;因此,实现了比之前尝试更好的聚类。由于聚类是基于输入/输出行为生成的,因此SLACC支持跨语言克隆检测。作为一个额外的挑战,我们的目标是静态类型语言Java和动态类型语言Python。与最近的Java克隆检测工具HitoshiIO相比,SLACC检索的集群数量是HitoshiIO的6倍,并且精度更高(86.7% vs. 30.7%)。这是第一个对动态类型语言执行克隆检测的工作(精度= 87.3%),也是第一个对缺乏公共底层表示的语言执行克隆检测的工作(精度= 94.1%)。它为实现可伸缩语言迁移工具的更大目标迈出了第一步。
AST-Enhanced or AST-Overloaded? The Surprising Impact of Hybrid Graph Representations on Code Clone Detection
University of Galway(Galway大学);CRT-AI, Irish National Centre for Research Training in Artificial Intelligence(CRT-AI,爱尔兰人工智能研究培训国家中心);Lero, the Research Ireland Centre for Software(Lero,爱尔兰软件研究中心)