Abstract
C preprocessor (CPP) is a major cause that makes it much difficult to precisely analyze C source code, which is indispensable to refactoring tools for C programs. To precisely analyze C source code, we need to obtain the mapping information between unpreprocessed C source code and preprocessed one. Previous works obtain the mapping information by extending the existing CPP (e.g., Cpplib), which results in low portability and low maintainability due to the strong dependency on CPP implementation.
To solve this problem, this paper proposes a novel approach based on tracer, which obtains the mapping information by automatically embedding XML-like tracers in source code, running native CPP “as-is”, and finally analyzing the resulting tracers. Thus the tracer method is highly portable and maintainable, while the previous methods are not. We successfully implemented a first prototype of tracer-based CPP analyzer (called TBCppA), and experimentally applied TBCppA to the code of gcc-4.1.1 (consisting of around 630 KLOC). This preliminary result suggests that our tracer approach works fine both in functionality and performance for obtaining the CPP mapping information in a very portable manner.