Refactoring has become a well-known technique for transforming code in a way that preserves behavior. Refactorings may be applied manually, although manual code manipulation is error prone and cumbersome, so maintainers need tools to make automatic refactorings. There is currently extensive literature on refactoring object-oriented programs and some very good tools for refactoring Smalltalk and Java code. Although there is more code written in C or C++ than in any other language, refactoring tools for C with full support for preprocessor directives have not yet appeared.The C programming language, especially the preprocessor directives that coexist with it, complicates refactorings in different ways as directives are not legal C code and may violate otherwise correct refactorings.Refactoring C poses two major research challenges. On the one hand, as preprocessor directives may violate correctness, new precondition and execution rules must be defined for existing refactorings to preserve behavior. On the other hand, the automated execution of refactorings requires specialized program analysis tools to represent and manipulate preprocessor directives. After studying the area we have found some results to overcome these challenges and make a correct tool for the C language attainable.This paper first discusses the difficulties in refactoring C code with preprocessor directives. It then defines preconditions and execution rules to maintain correctness of refactoring in the presence of macros and conditional directives. Moreover, new refactorings are proposed for macro definitions and conditionals. Lastly, the paper suggests enhancements to program analysis and program representation tools to correctly manipulate preprocessor directives.
[1]
William F. Opdyke,et al.
Lifecycle and refactoring patterns that support evolution and reuse
,
1995
.
[2]
Don S. Batory,et al.
Evolving Object-Oriented Designs with Refactorings
,
2004,
Automated Software Engineering.
[3]
Bjarne Stroustrup,et al.
The Design and Evolution of C
,
1994
.
[4]
Ralph E. Johnson,et al.
A Refactoring Tool for Smalltalk
,
1997,
Theory Pract. Object Syst..
[5]
William G. Griswold,et al.
Tool support for planning the restructuring of data abstractions in large systems
,
1996,
SIGSOFT '96.
[6]
Martin Fowler. Refactoring.
Improving the Design of Existing Code
,
1999
.
[7]
Michael D. Ernst,et al.
An Empirical Analysis of C Preprocessor Use
,
2002,
IEEE Trans. Software Eng..
[8]
Mel O Cinn eide.
Automated application of design patterns: a refactoring approach
,
2001
.
[9]
William G. Griswold,et al.
Supporting the restructuring of data abstractions through manipulation of a program visualization
,
1998,
TSEM.
[10]
Bjarne Stroustrup,et al.
C++ Programming Language
,
1986,
IEEE Softw..
[11]
William F. Opdyke,et al.
Refactoring object-oriented frameworks
,
1992
.
[12]
Martin Fowler,et al.
Refactoring - Improving the Design of Existing Code
,
1999,
Addison Wesley object technology series.
[13]
Don S. Batory,et al.
Evolving object-oriented designs with refactorings
,
1999,
14th IEEE International Conference on Automated Software Engineering.