计算机科学 ›› 2017, Vol. 44 ›› Issue (4): 16-20.doi: 10.11896/j.issn.1002-137X.2017.04.004
张其良,张昱,周坤
ZHANG Qi-liang, ZHANG Yu and ZHOU Kun
摘要: 随着程序规模和复杂性的增加,代码重构在改善软件质量、性能以及提高软件的扩展性和维护性等方面至关重要。目前的Eclipse中,C源代码重构工具的函数提取只能处理一些简单的代码,且处理过程需要人工参与,不能自动化处理。为此,提出一种C源代码级别自动化的函数提取方法(CCodeExtractor),它通过指定提取条件,在保证语义一致的前提下,将符合条件的代码片段自动分离成一个单独的函数,并将其放到新文件中,而原代码片段替换成了一个函数调用。为了验证CCodeExtractor的有效性,结合循环分析和优化在实际应用中的广泛应用,在LLVM上实现了一个提取循环的工具,将程序中满足条件的for循环封装成单独的函数。在实验中,使用该工具对6个不同规模的程序进行了测试并且对比了变换前后程序运行的结果。实验结果表明,CCodeExtractor代码提取方法在保证程序语义不变的前提下,适用于不同规模的程序。
[1] FOWLER M.Refactoring:improving the design of existing code[M].Pearson Education India,1999. [2] Code refactoring.http://en.wikipedia.org/wiki/Code_re-factoring. [3] HAFIZ M,OVERBEY J.OpenRefactory/C:An infrastructurefor developing program transformations for C programs[C]∥Proceedings of the 3rd annual conference on Systems,programming,and applications:software for humanity.ACM,2012:27-28. [4] HAFIZ M,OVERBEY J,BEHRANG F,et al.OpenRefactory/C:An infrastructure for building correct and complex C transformations[C]∥Proceedings of the 2013 ACM Workshop on Refactoring Tools.ACM,2013:1-4. [5] Microsoft Visual Studio.http://www.wholetomato.com/features/ feature-refactoring.asp#extract. [6] Extract method In Eclipse.https://sourcemaking.com/re-factoring/ extract-method. [7] JEFFREY L.Overbey,Farnaz Behrang,and Munawar Hafiz.A foundation for refactoring C with macros[C]∥22nd ACM SIGSOFT International Symposium on Foundations of Software Engineering (FSE).New York,NY,USA,2014:75-85. [8] LATTNER C,ADVE V.LLVM:A compilation framework for lifelong program analysis & transformation[C]∥ International Symposium on Code Generation and Optimization,2004(CGO 2004).IEEE,2004:75-86. [9] LATTNER C.LLVM and Clang:Next generation compiler tech-nology[C]∥The BSD Conference.2008:1-2. [10] LLVM extractCode.http://llvm.org/docs/doxygen/html/CodeExtractor 8cpp _source.html. [11] PROKAJ J.C code for SIFT feature point extraction.http://www.pudn.com/downloads93/sourcecode/graph/texture_mapping/detail365370.html. |
No related articles found! |
|