A framework for preprocessor-aware C source code analyses

Analyses of C source code usually ignore the C preprocessor because of its complexity. Instead, these analyses either define their own approximate parser (or scanner) or else they require that their input already be preprocessed. Neither approach is entirely satisfactory: the first gives up accuracy (or incurs large implementation costs), while the second loses the preprocessor-based abstractions. We describe a framework that permits analyses to be expressed in terms of both preprocessing and parsing actions, allowing the implementer to focus on the analysis. We discuss an implementation of such a framework that embeds a C preprocessor, a parser, and a Perl interpreter for the action “hooks.” Many common software engineering analyses can be written surprisingly easily using our implementation, replacing numerous ad-hoc tools. The framework’s integration of the preprocessor and the parser further enables some analyses that otherwise would be especially difficult.

[1]  Gregor Snelting,et al.  On the inference of configuration structures from source code , 1994, Proceedings of 16th International Conference on Software Engineering.

[2]  Bjarne Stroustrup,et al.  The Design and Evolution of C , 1994 .

[3]  David Notkin,et al.  Lightweight lexical source model extraction , 1996, TSEM.

[4]  John K. Ousterhout,et al.  Scripting: Higher-Level Programming for the 21st Century , 1998, Computer.

[5]  Yih-Farn Robin Chen,et al.  The C++ Information Abstractor , 1990, C++ Conference.

[6]  David Notkin,et al.  An empirical study of static call graph extractors , 1998, TSEM.

[7]  Guy L. Steele,et al.  C, a reference manual , 1984 .

[8]  Steven P. Reiss The Field Programming Environment: A Friendly Integrated Environment for Learning and Development , 1994 .

[9]  Brian W. Kernighan,et al.  The C Programming Language , 1978 .

[10]  Thomas W. Reps,et al.  Program generalization for software reuse: from C to C++ , 1996, SIGSOFT '96.

[11]  William G. Griswold,et al.  Fast, flexible syntactic pattern matching and processing , 1996, WPC '96. 4th Workshop on Program Comprehension.

[12]  William G. Griswold,et al.  The design of whole-program analysis tools , 1996, Proceedings of IEEE 18th International Conference on Software Engineering.

[13]  Tony Mason,et al.  Lex & Yacc , 1992 .