一句话:提出 HFDecomposer,用两阶段分组与去幻觉增强 LLM,实现大型头文件的准确可靠分解。
巨型头文件被大量源文件包含,给代码理解与维护带来挑战。现有方法依赖代码相似度度量分解头文件,却难以准确捕捉代码的功能本质;直接用 LLM 又受长文件 token 约束、幻觉导致的不完整或虚假输出,以及违反架构原则、引发编译失败的循环依赖所限。本文提出 HFDecomposer:采用两阶段分组,先用传统相似度度量把强相关代码实体分组,再将组摘要交给 LLM 做高层语义聚合;并通过静态分析抽取事实知识增强提示,检测输出错误,重分配遗漏实体、消解循环依赖以去幻觉。在真实头文件分解重构上评估,该方法克服了纯 LLM 方法的局限,比传统最先进方法提升 11%,结果更准确可靠。
God Header Files, large header files included by numerous other code files, present significant challenges for code comprehension and maintenance. Existing approaches leverage various code similarity metrics to decompose them, but these metrics do not always capture the code’s functional essence accurately. Large Language Models (LLMs), with their advanced capabilities in code understanding and generation, offer a promising alternative for producing more effective refactorings. However, LLMs face three critical limitations that hinder practical application: they struggle with lengthy header files due to token constraints, suffer from hallucination by generating incomplete or spurious results, and produce cyclic dependencies that violate architectural principles and cause compilation failures. To address these challenges, we propose HFDecomposer, a hybrid approach that enhances LLMs with staged grouping and dehallucination techniques to effectively decompose header files. Our approach introduces a two-stage grouping framework for lengthy header files: it first groups strongly related code entities using traditional similarity metrics, then feeds group summaries to the LLM for higher-level semantic aggregation. To mitigate LLM hallucinations, we enhance prompts with factual knowledge extracted from static analysis, detect errors in LLM output, and make necessary corrections by reassigning missing entities and resolving cyclic dependencies. Our evaluation on real-world header file decomposition refactorings demonstrates that our method effectively overcomes the limitations of purely LLM-based techniques and outperforms the traditional state-of-the-art approach by 11%, delivering more accurate and reliable decomposition results. Our approach enables LLMs to handle lengthy header files efficiently, significantly reduces hallucinations, and ensures the reliability and practicality of the final decomposition.
DOI 原文 ·
@inproceedings{paperbot9541,
title = {Enhancing LLMs with Staged Grouping and Dehallucination for Header File Decomposition},
author = {Yue Wang and Jiaxuan Sun and Yanzhen Zou and Bing Xie},
booktitle = {ASE},
year = {2025},
doi = {10.1109/ase63991.2025.00037}
}