language: en

PCp 3 : A C Front End for Preprocessor Analysis and Transformation

Greg J. Badros *
gjb@cs.washington.edu 16 October 1997

Abstract Though the C preprocessor provides necessary language features, it does so in an unstructured way. The lexical nature of cpp creates numerous problems for software engineers and their tools, all stemming from the chasm between the engineer's view of the source code and the compiler's view. The simplest way to reduce this problem is to minimize use of the preprocessor. In light of the data collected in a prior empirical analysis, this paper describes a tool to aid the software engineer in analyses targeted at replacing preprocessor constructs with language features. Existing tools for analyzing C source in the context of the preprocessor are unsuitable for such transformations. This work introduces a new approach: tightly integrating the preprocessor with a C language parser, permitting the code to be analyzed at both the preprocessor and syntactic levels simultaneously. The front-end framework, called PCp 3 , combines a preprocessor, a parser, and arbitrary Perl subroutine "hooks" invoked upon various preprocessor and parser events. PCp 3 's strengths and weaknesses are discussed in the context of several program understanding and transformation tools, including a conservative analysis to support replacing cpp's #define directives with C++ language features.

1 Introduction