cnife logo

cnife: a tool for the transformation of #ifdefs into feature-modules



Overview

The preprocessor cpp has a long history in software development for the implementation of variable source code. By means of preprocessor directives (e.g., #if, #ifdef, and #ifndef) a programmer annotates variable parts of the source code. The implementation of variable source code is also a major aim of feature-oriented programming. In feature-oriented programming variable source code is represented by feature-modules. a feature-module is a folder that contains all source code (e.g., new classes or class refinements) that a feature adds to the existing code base. Although, #ifdef-annotated source code and feature modules share the same goal of implementing variable source code, the transformation of one in another is complicated. This project deals with the transformation of #ifdef-annotated source code in feature-modules.

cnife is an extensible Java library for the (semi)automatic transformation of #ifdef annotated source code in C++ programs into FeatureC++ feature-modules (see FeatureC++ project website for more information). cnife recognizes a set of patterns automatically (#ifdef usage in software systems) and tries to transform the annotated code into feature-modules.

Background

#ifdef annotation vs. feature-module

/* Config.cpp */
#define NOSORT 0
#define INSERTIONSORT 1
#define BUBBLESORT 2
#define DLINKED 1
#define SORTALGO INSERTIONSORT
#if SORTALGO != NOSORT
#define UPWARD 0
#define DOWNWARD 1
#define SORTORDER DOWNWARD
#endif

/* Node.cpp */
class Node {
public:
  int data;
  Node *next;
#if DLINKED
  Node *prev;
#endif
};

/* List.cpp */
LinkedList::LinkedList() {
  first = NULL;
#if DLINKED
  last = NULL;
#endif
  return;
}
void LinkedList::insert( int newData ) {
  Node *n = new Node();
  n->data = newData;
#if SORTALGO == BUBBLESORT || SORTALGO == INSERTIONSORT
  Node *a = NULL;
  Node *b = NULL;
#endif
#if SORTALGO == BUBBLESORT
  Node *c = NULL;
  Node *e = NULL;
  Node *tmp = NULL;
#endif

  if (NULL == first) {
    first = n;
  } else {
...

Technically, the composition of features and refinement of classes are implemented via superimposition. For more details, we refer the interested reader to the FeatureHouse website.

HowTo

The cnife library is deployed in the form of a Jar archive, which can be used for testing purposes. As command line arguments, it expects a project directory containing another directory named 'Base'. This directory should contain some source files prepared with the latest build of src2srcml. In order to get started, we recommend to download and unzip the binary, then unzip the list example in the same folder. Open up a terminal, cd to the folder and type this in a terminal:
java -jar cnife.jar --inputfolder ./test/list


Notes on this prototype release:
The binary transforms all so-called disciplined annotations with limitations regarding some special cases (annotated #define-directives, gotos, cases in switch blocks, ...). Therefore it will apply hooks, wherever it could, moves whole functions to FeatureC++ feature-modules and so on.

Downloads

Contact

cnife has been developed at the University of Passau, Germany. For more information please contact the developers: