Partial Preprocessing C Code for Variability Analysis

kaestner@cs.cmu.edu (C. Kästner, P. Giarrusso, K. Ostermann)
Fri, 10 Jan 2025 13:48:21 GMT

Christian Kästner, Paolo G. Giarrusso, and Klaus Ostermann. Partial Preprocessing C Code for Variability Analysis. In Proceedings of the 5th Int'l Workshop on Variability Modelling of Software-Intensive Systems (VaMoS), ISBN 978-1-4503-0570-9, pages 137--140, New York, NY: ACM Press, January 2011.

The C preprocessor is commonly used to implement variability. Given a feature selection, code fragments can be excluded from compilation with #ifdef and similar directives. However, the token-based nature of the C preprocessor makes variability implementation difficult and errorprone. Additionally, variability mechanisms are intertwined with macro definitions, macro expansion, and file inclusion. To determine whether a code fragment is compiled, the entire file must be preprocessed. We present a partial preprocessor that preprocesses file inclusion and macro expansion, but retains variability information for further analysis. We describe the mechanisms of the partial preprocessor, provide a full implementation, and present some initial experimental results. The partial preprocessor is part of a larger endeavor in the TypeChef project to check variability implementations (syntactic correctness, type correctness) in C projects such as the Linux kernel.