一句话:将 code2vec 的 AST 路径扩展为融合 AST、CFG 与 PDG 路径的源码表示,在方法命名任务上显著提升 F1。
源代码表示对代码分类、克隆检测等任务至关重要,但现有方法多仅用 AST,未充分利用 CFG、PDG 等语义图。本文提出将基于路径的 code2vec 扩展到融合 AST、CFG 与 PDG 路径的“Mocktail”表示,用注意力神经网络学习代码嵌入。作者在从 GitHub 收集的 730K C 方法数据集上评估 METHODNAMING:相比只使用 AST 的 code2vec,完整数据集 F1 提升 11%,单个项目最高提升 100%。结果表明 CFG/PDG 语义路径能大幅改善软件工程任务,并倡导重新审视源码表示组合。
Efficient representation of source code is essential for various software engineering tasks such as code classification and code clone detection. Most recent approaches for representing source code still use AST and do not leverage semantic graphs such as CFG and PDG. One effective technique for representing source code involves extracting paths from the AST and using a learning model to capture program properties. Code2vec is one such path-based approach that uses an attention-based neural network to learn code embeddings which can then be used for various downstream tasks. However, this approach uses only AST and does not leverage CFG and PDG. Even though an integrated graph approach (Code Property Graph) exists for representing source code, it has only been explored in the domain of software security. Moreover, it does not leverage the paths from the individual graphs. Our idea is to extend the path-based approach code2vec to include the semantic graphs CFG and PDG with AST, which is largely unexplored in software engineering. We evaluate our approach on the task of METHODNAMING using a C dataset of 730K methods collected from GitHub. In comparison to code2vec, our approach improves the F1 score by 11% on the full dataset and up to 100% with individual projects. We show that semantic features from the CFG and PDG paths drastically improve the performance of the software engineering tasks. We envision that looking at a mocktail of source code representations for various software engineering tasks can lay the foundation for a new line of research and a re-haul of existing research.