kirancodes.me
To Proof Maintenance & Beyond!

A foundation for refactoring C with macros

Jeffrey L. Overbey, Farnaz Behrang, Munawar Hafiz

Abstract

This paper establishes the concept of "preprocessor dependences" as a foundation for building automated refactoring tools that transform source code containing lexical macros and conditional compilation directives, such as those provided by the C preprocessor. We define a preprocessor dependence graph (PPDG) that models the relationships among macro definitions, macro invocations, and conditional compilation directives in a file--the relationships that must be maintained for the semantics of the C preprocessor to be preserved. For many refactorings, a tool can construct a PPDG from the code before and after it is transformed, then perform a linear-time comparison of the two graphs to determine whether the refactoring will operate correctly in the presence of macros and conditional compilation directives. The proposed technique was implemented in OpenRefactory/C and tested by applying refactorings to GNU Coreutils version 8.21. Empirical results indicate that the technique is effective; it successfully handled refactoring scenarios in which Eclipse CDT, Visual Assist X, and XRefactory all refactored code incorrectly.

BibTeX
@inproceedings{Overbey-al:FSE14,
  author    = {Jeffrey L. Overbey and
               Farnaz Behrang and
               Munawar Hafiz},
  title     = {A foundation for refactoring C with macros},
  booktitle = {FSE},
  pages     = {75--85},
  publisher = {{ACM}},
  year      = {2014},
}

Related papers