Program refactoring in the presence of preprocessor directives

The C preprocessor is heavily used in C programs because it provides useful and even necessary additions to the C language. Since preprocessor directives are not part of C, they are removed before parsing and program analysis take place, during the phase called preprocessing. In the context of refactoring, it is inappropriate to remove preprocessor directives: if changes are applied on the preprocessed version of a program, it may not be possible to recover the un-preprocessed version. This means that after refactoring, all the source code would be contained in a single unit, targeted to a single configuration and without preprocessor macros. This thesis describes a novel approach to preserve preprocessor directives during parsing and program analysis, and integrate them in the program representations. Furthermore, it illustrates how the program representations are used during refactoring and how transformations preserve preprocessor directives. Additionally, the semantics of the C preprocessor are formally specified, and the results of implementing this approach in a refactoring tool for C, CRefactory, are presented.

[1]  William G. Griswold,et al.  Refactoring Tools , 2007, ECOOP Workshops.

[2]  Jeffrey Overbey,et al.  Refactorings for Fortran and high-performance computing , 2005, SE-HPCS '05.

[3]  Ralph E. Johnson,et al.  The role of refactorings in API evolution , 2005, 21st IEEE International Conference on Software Maintenance (ICSM'05).

[4]  Premkumar T. Devanbu GENOA—a customizable, front-end-retargetable source code analysis framework , 1999, TSEM.

[5]  Alejandra Garrido,et al.  Challenges of refactoring C programs , 2002, IWPSE '02.

[6]  Mel O Cinn eide Automated application of design patterns: a refactoring approach , 2001 .

[7]  Meir M. Lehman,et al.  Laws of Software Evolution Revisited , 1996, EWSPT.

[8]  David Notkin,et al.  A framework for preprocessor-aware C source code analyses , 2000 .

[9]  Stéphane S. Somé,et al.  Parsing minimization when extracting information from code in the presence of conditional compilation , 1998, Proceedings. 6th International Workshop on Program Comprehension. IWPC'98 (Cat. No.98TB100242).

[10]  José Meseguer,et al.  Theoroidal Maps as Algebraic Simulations , 2004, WADT.

[11]  Don S. Batory,et al.  Evolving Object-Oriented Designs with Refactorings , 2004, Automated Software Engineering.

[12]  Marian Vittek Refactoring browser with preprocessor , 2003, Seventh European Conference onSoftware Maintenance and Reengineering, 2003. Proceedings..

[13]  Bjarne Stroustrup,et al.  The Design and Evolution of C , 1994 .

[14]  David W. Binkley,et al.  Interprocedural slicing using dependence graphs , 1988, SIGP.

[15]  Václav Rajlich,et al.  Restructuring legacy C code into C++ , 1999, Proceedings IEEE International Conference on Software Maintenance - 1999 (ICSM'99). 'Software Maintenance for Business Change' (Cat. No.99CB36360).

[16]  Panos E. Livadas,et al.  Understanding code containing preprocessor constructs , 1994, Proceedings 1994 IEEE 3rd Workshop on Program Comprehension- WPC '94.

[17]  C. V. Ramamoorthy,et al.  The C Information Abstraction System , 1990, IEEE Trans. Software Eng..

[18]  William G. Griswold,et al.  Supporting the restructuring of data abstractions through manipulation of a program visualization , 1998, TSEM.

[19]  Lerina Aversano,et al.  Handling preprocessor-conditioned declarations , 2002, Proceedings. Second IEEE International Workshop on Source Code Analysis and Manipulation.

[20]  Meir M. Lehman,et al.  On understanding laws, evolution, and conservation in the large-program life cycle , 1984, J. Syst. Softw..

[21]  Steven S. Muchnick,et al.  Advanced Compiler Design and Implementation , 1997 .

[22]  William F. Opdyke,et al.  Lifecycle and refactoring patterns that support evolution and reuse , 1995 .

[23]  Ralph E. Johnson,et al.  A Refactoring Tool for Smalltalk , 1997, Theory Pract. Object Syst..

[24]  Ralph E. Johnson,et al.  Refactoring C with conditional compilation , 2003, 18th IEEE International Conference on Automated Software Engineering, 2003. Proceedings..

[25]  Ralph Johnson,et al.  design patterns elements of reusable object oriented software , 2019 .

[26]  Václav Rajlich,et al.  Reengineering object-oriented code , 1998, Proceedings. International Conference on Software Maintenance (Cat. No. 98CB36272).

[27]  Markus Mock,et al.  Improving program slicing with dynamic points-to data , 2002, SIGSOFT '02/FSE-10.

[28]  Hausi A. Müller,et al.  Rigi: A Visualization Environment for Reverse Engineering , 1997, Proceedings of the (19th) International Conference on Software Engineering.

[29]  Volker Riediger,et al.  Folding: an approach to enable program understanding of preprocessed languages , 2001, Proceedings Eighth Working Conference on Reverse Engineering.

[30]  William G. Griswold,et al.  Effective whole-program analysis in the presence of pointers , 1998, SIGSOFT '98/FSE-6.

[31]  Peter A. Darnell,et al.  The C Preprocessor , 1991 .

[32]  Guy L. Steele,et al.  C, a reference manual , 1984 .

[33]  Michael D. Ernst,et al.  An Empirical Analysis of C Preprocessor Use , 2002, IEEE Trans. Software Eng..

[34]  Christopher W. Pidgeon,et al.  DMS®: Program Transformations for Practical Scalable Software Evolution , 2002, IWPSE '02.

[35]  Mark Weiser,et al.  Programmers use slices when debugging , 1982, CACM.

[36]  R. S. Arnold,et al.  Software restructuring , 1989, Proc. IEEE.

[37]  William F. Opdyke,et al.  Refactoring object-oriented frameworks , 1992 .

[38]  Malcolm Munro,et al.  Understanding C programs using the Combined C Graph representation , 1994, Proceedings 1994 International Conference on Software Maintenance.

[39]  Charles L. A. Clarke,et al.  Relocating XML elements from preprocessed to unprocessed code , 2002, Proceedings 10th International Workshop on Program Comprehension.

[40]  Mitchell Wand,et al.  Essentials of programming languages , 2008 .

[41]  Ralph E. Johnson,et al.  Analyzing multiple configurations of a C program , 2005, 21st IEEE International Conference on Software Maintenance (ICSM'05).

[42]  Ira D. Baxter,et al.  Preprocessor conditional removal by simple partial evaluation , 2001, Proceedings Eighth Working Conference on Reverse Engineering.

[43]  Richard M. Stallman Free software foundation (FSF) , 2003 .