arXiv:2508.03379cs.AIcs.SE2025-08

用增强版时序图+数据依赖分析,让代码生成更准确

Data Dependency-Aware Code Generation from Enhanced UML Sequence Diagrams

  • 用扩展时序图显式表达服务间逻辑与接口
  • 先构建数据依赖图再生成代码,避免遗漏
  • 适合需要精准控制流程的系统开发

大型语言模型(LLMs)在自然语言到代码生成方面表现优异,但纯文本描述存在固有歧义,难以捕捉复杂系统行为、条件逻辑和架构约束;服务架构中的隐含数据依赖也难被正确推断。为此,我们提出名为UML2Dep的分步代码生成框架,利用复杂需求的无歧义形式化规范来弥合差距。首先,设计一种面向服务架构的增强型统一建模语言(UML)时序图,通过集成决策表和API规范,显式形式化服务交互中的结构关系与业务逻辑流,彻底消除语言模糊性。其次,引入专门的数据依赖推理(DDI)任务,系统性地在代码合成前构建显式数据依赖图。为确保可靠性,将DDI形式化为带约束的数学推理任务,并采用新颖提示策略,发挥LLM在数学推理方面的优势。额外的静态解析与依赖剪枝进一步降低上下文复杂度和认知负荷,提升推理准确率与效率。

原文摘要 · Abstract (English)

Large language models (LLMs) excel at generating code from natural language (NL) descriptions. However, the plain textual descriptions are inherently ambiguous and often fail to capture complex requirements like intricate system behaviors, conditional logic, and architectural constraints; implicit data dependencies in service-oriented architectures are difficult to infer and handle correctly. To bridge this gap, we propose a novel step-by-step code generation framework named UML2Dep by leveraging unambiguous formal specifications of complex requirements. First, we introduce an enhanced Unified Modeling Language (UML) sequence diagram tailored for service-oriented architectures. This diagram extends traditional visual syntax by integrating decision tables and API specifications, explicitly formalizing structural relationships and business logic flows in service interactions to rigorously eliminate linguistic ambiguity. Second, recognizing the critical role of data flow, we introduce a dedicated data dependency inference (DDI) task. DDI systematically constructs an explicit data dependency graph prior to actual code synthesis. To ensure reliability, we formalize DDI as a constrained mathematical reasoning task through novel prompting strategies, aligning with LLMs' excellent mathematical strengths. Additional static parsing and dependency pruning further reduce context complexity and cognitive load associated with intricate specifications, thereby enhancing reasoning accuracy and efficiency.

代码生成UML数据依赖LLM

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。