arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2106.09173cs.SE
收藏

基于静态和动态分析的跨语言代码搜索

Cross-Language Code Search using Static and Dynamic Analyses

George Mathew, Kathryn T. Stolee

摘要:

随着代码搜索渗透到软件开发中的大多数活动中,代码到代码搜索已经出现,以支持使用代码作为查询并在搜索结果中检索相似的代码。应用程序包括用于重构的重复代码检测、用于程序修复的补丁识别和语言翻译。现有的代码到代码搜索工具依赖于静态相似性方法,例如比较标记和抽象语法树(AST)来近似动态行为,导致精度低。大多数工具不支持跨语言代码到代码搜索,而那些支持的工具依赖于需要标记训练数据的机器学习模型。我们提出了跨语言的代码到代码搜索(COSAL),一种跨语言技术,使用静态和动态分析来识别相似的代码,不需要机器学习模型。基于代码标记相似性、结构相似性和行为相似性,使用非支配排序对代码片段进行排名。我们在43,146个Java和Python文件和55,499个Java文件的两个数据集上对COSAL进行了经验评估,发现1)与单一或加权度量相比,基于静态和动态相似性度量的非支配排名的代码搜索更有效; 2)与最先进的语言内和跨语言代码到代码搜索工具相比,COSAL具有更好的精确度和召回率。我们探讨了在大型开源存储库上使用COSAL的潜力,并讨论了更多语言和相似性度量的可扩展性,为实用的多语言代码到代码搜索提供了一个网关。

英文摘要:

As code search permeates most activities in software development,code-to-code search has emerged to support using code as a query and retrieving similar code in the search results. Applications include duplicate code detection for refactoring, patch identification for program repair, and language translation. Existing code-to-code search tools rely on static similarity approaches such as the comparison of tokens and abstract syntax trees (AST) to approximate dynamic behavior, leading to low precision. Most tools do not support cross-language code-to-code search, and those that do, rely on machine learning models that require labeled training data. We present Code-to-Code Search Across Languages (COSAL), a cross-language technique that uses both static and dynamic analyses to identify similar code and does not require a machine learning model. Code snippets are ranked using non-dominated sorting based on code token similarity, structural similarity, and behavioral similarity. We empirically evaluate COSAL on two datasets of 43,146Java and Python files and 55,499 Java files and find that 1) code search based on non-dominated ranking of static and dynamic similarity measures is more effective compared to single or weighted measures; and 2) COSAL has better precision and recall compared to state-of-the-art within-language and cross-language code-to-code search tools. We explore the potential for using COSAL on large open-source repositories and discuss scalability to more languages and similarity metrics, providing a gateway for practical,multi-language code-to-code search.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑