Options
CppSig : extracting type information for C-preprocessor macro expansions
Publikationstyp
Conference Paper
Date Issued
2021-10-25
Sprache
English
Author(s)
Institut
Start Page
62
End Page
68
Citation
Workshop on Programming Languages and Operating Systems (PLOS 2021)
Contribution to Conference
Publisher DOI
Scopus ID
Publisher
Association for Computing Machinery
Peer Reviewed
true
For decades, the C programming language proved to be a cornerstone of system-software ecosystems, leaving us with billion lines of existing source code. From today’s perspective of object-oriented and functional languages, C itself seems rather limited in its expressiveness and abstractive power. However, with the C preprocessor (CPP) as its companion, macros, which operate on the raw token stream, allow for abstractions that are impossible to achieve within the language itself. While its flexibility and its ease of use make CPP attractive for programmers, its potential undisciplined usage makes it problematic for static source-code analysis and can slow down the on-boarding of new developers.
In this paper, we focus on a disciplined subclass of CPP macros: the statement-like and expression-like macros, which mimic regular C functions, with well-type C expressions as arguments and, incase, a return value. We show how to spot such macros and their arguments in the compiler’s abstract syntax tree, whereby it becomes possible to deduct type signatures for individual macro expansions. With our CppSig prototype, implemented as a Clang plugin, we extract macro-type information from Linux 5.12, whereby it becomes easier to understand even deep macro-expansion
nests. In the future, these expansion signatures could be used to statically enforce gradually-typed CPP macro definitions.
In this paper, we focus on a disciplined subclass of CPP macros: the statement-like and expression-like macros, which mimic regular C functions, with well-type C expressions as arguments and, incase, a return value. We show how to spot such macros and their arguments in the compiler’s abstract syntax tree, whereby it becomes possible to deduct type signatures for individual macro expansions. With our CppSig prototype, implemented as a Clang plugin, we extract macro-type information from Linux 5.12, whereby it becomes easier to understand even deep macro-expansion
nests. In the future, these expansion signatures could be used to statically enforce gradually-typed CPP macro definitions.
DDC Class
004: Informatik