摘要
随着程序规模和复杂性的增加,代码重构在改善软件质量、性能以及提高软件的扩展性和维护性等方面至关重要。目前的Eclipse中,C源代码重构工具的函数提取只能处理一些简单的代码,且处理过程需要人工参与,不能自动化处理。为此,提出一种C源代码级别自动化的函数提取方法(CCodeExtractor),它通过指定提取条件,在保证语义一致的前提下,将符合条件的代码片段自动分离成一个单独的函数,并将其放到新文件中,而原代码片段替换成了一个函数调用。为了验证CCodeExtractor的有效性,结合循环分析和优化在实际应用中的广泛应用,在LLVM上实现了一个提取循环的工具,将程序中满足条件的for循环封装成单独的函数。在实验中,使用该工具对6个不同规模的程序进行了测试并且对比了变换前后程序运行的结果。实验结果表明,CCodeExtractor代码提取方法在保证程序语义不变的前提下,适用于不同规模的程序。
As program complexity increases,code refactoring plays an important role in improving quality and performance of software,and is also essential for improving the maintainability and extensibility of programs.Current code extraction approach for C code in Eclipse,can only deal with some simple code,and cannot refactor the code automatically.In this paper,we proposed a code extraction approach for C code,CCodeExtractor.It can extract the C code fragments that meet the specified conditions into new functions,and replace the fragments with these new functions calls automatically.The refactored code has the same program semantics as the original code.In order to verify the validity of CCodeExtractor,we implemented it in LLVM to extract some for statements in C programs into new functions since loop analysis and optimization has been widely explored in recent years.Our experiments evaluated CCodeExtractor using six actual applications of different size,and compared the outcomes of the original and transformed programs.Experimental results show that CCodeExtractor can provide correct source-level transformation for programs of different size.
出处
《计算机科学》
CSCD
北大核心
2017年第4期16-20,29,共6页
Computer Science
基金
国家863高技术研究发展计划项目基金(2012AA010901)
国家自然科学基金(61170018)资助
关键词
C程序重构
程序变换
程序理解
代码提取
循环分析
LLVM
C program refactoring
Program transformation
Program comprehension
Code extraction
Loop analysis
LLVM