TypeChef

TypeChef is a research project with the goal of analyzing
ifdef variability in C code with the goal of finding
variability-induced bugs in large-scale real-world systems,
such as the Linux kernel with several thousand
features (or configuration options).

Instead of analyzing each variant for each feature
combination in isolation, TypeChef parses the
entire source code containing all variability in a
variability-aware fashion without preprocessing.
The resulting abstract syntax tree contains the
variability in form of choice nodes. Eventually, a
variability-aware type system performs type checking
on these trees, variability-aware data-flow analysis
performs data-flow analysis and so forth.

TypeChef was started with the goal of building a type
system for C code with compile-time configurations.
TypeChef was originally short for
Type Checking Ifdef Variability.
Over time it has grown into an infrastructure of all
kinds of analyses.
In all cases, the goal is to detect errors in all possible
feature combinations, without resorting to a brute-force approach.

Architecture and Subprojects

The TypeChef project contains of four main components
and several helper libraries.

A library for reasoning about feature expressions (subproject FeatureExprLib).
The library allows to easily express and reason about expressions
in propositional logic. It supports also parsing feature expressions
and loading entire feature models (in textual format or a .dimacs file).
For reasoning, internally both BDDs and SAT solvers are used which
allows to scale reasoning even to feature models the size of the Linux kernel.
The library can be (and is) reused in very different contexts also in Java code.

A library of conditional data structures for variational programming
(subproject ConditionalLib) with several useful operations on
conditional structures. Used heavily in all other subprojects.
For a short introduction see VariationalProgramming.md.

A variability-aware lexer (also called partial preprocessor;
subproject PartialPreprocessor) that
reads unpreprocessed code and produces a conditional
token stream. The variability-aware lexer is responsible
for resolving macros and file inclusions and for
normalizing #ifdef conditions

The variability-aware parsers for GNU C and Java
(subprojects CParser and JavaParser) use the parser
framework to build parsers for the corresponding languages.
The parsers read a conditional token stream and
produce abstract syntax trees with corresponding choice nodes.

A variability-aware type system (subproject CTypeChecker)
eventually checks variability in the abstract
syntax tree. This will be supported by variability-aware
linker checks.

A variability-aware control-flow and data-flow analysis
(subproject CRewrite) provides implementations for
successor/predecessor determination of abstract syntax tree
elements in the presence of choice nodes and on top of it
a variable liveness implementation.

Setups for analyzing individual systems together with useful tooling are available as
separate github projects (see section evaluation below).

Due to library dependencies, setting up the TypeChef classpath
can be difficult. There are two convenient mechanisms:
Use sbt assembly to build a single jar file.
Alternatively, call sbt mkrun to create a script
typechef.sh that sets a correct classpath.

Most functionality of TypeChef is accessible through parameters of
the main de.fosd.typechef.Frontend class. Call TypeChef with --help to see a
list of configuration parameters. See also
Parameter.txt.
You will need to set up system include paths with -I and
a header file with the compiler’s macro definitions with -h (generate,
for example, with echo - | gcc -dM - -E -std=gnu99 for gcc).
Have a look at existing projects using TypeChef or contact us in
case of questions.

IntelliJ Idea users should run sbt gen-idea to create
corresponding project and classpath information for the
IDE. Similar sbt plugins for Eclipse are available,
but we have not tried or integrated them yet. In general
avoid to set the classpath in IDEs manually, but let sbt
generate corresponding files for you.