A meta-programming library for C++

Printer-friendly version
  • An interest in programming languages and reasoning about programs

Meta-programming libraries, in which a program's code is treated as data, are used for a variety of applications: performing searches and transformations in source code, performing program analysis, optimizing programs, computing code metrics, performing refactorings, and so on. Ekeko is such a meta-programming library being developed here at the Software Languages Lab. More specifically, Ekeko is a logic meta-programming library. This means that a program's source code is represented as a database of logic facts. Ekeko also provides a catalogue of relations to reason about these facts. (e.g. to relate an AST node to its children, a variable use to its declaration, a class to its subclasses, ...) Using these relations, Ekeko's database can be searched by writing logic queries. To give a few examples (for querying Java programs) :

(ekeko* [?m] (ast :MethodDeclaration ?m))

Retrieves all method declarations of a program (bound to logic variable ?m).

(ekeko* [?inv]
    (ast :MethodInvocation ?inv)
    (fresh [?exp]
      (has :expression ?inv ?exp)
      (value|null ?exp)))

Retrieve all method invocations with an implicit receiver (i.e. the "expression" child of the MethodInvocation AST node must be null).

Several applications have also been built using the Ekeko library:

  • Ekeko/X is a high-level layer on top of Ekeko where code searches and transformations are specified using code templates. Under the hood, these templates are converted to Ekeko queries, which will perform the desired search/transformation.
  • QwalKeko extends Ekeko such that it becomes possible to reason about the history of projects, by including git revision information in the database, as well as the source code of each commit.
  • Matraca makes use of Ekeko to keep track of traceability links between source code and other resources, such as XML or HTML files.
  • GASR extends Ekeko with support for the AspectJ language, and can automatically verify certain assumptions about the usage of aspects.
Goal & Research Activities: 

The Ekeko library was designed with support for multiple languages in mind; it currently supports Java, AspectJ and PHP. One of the companies within the Cha-Q research project has expressed interest in making use of Ekeko and Ekeko/X to assist with performing refactorings and code transformations. As the company's code base is mainly written in C++, the main goal of this thesis is to extend Ekeko with metaprogramming support for C++. This involves being able to represent C++ programs as logic facts (using Eclipse CDT, as Ekeko is Eclipse-based). The catalogue of relations also needs to be extended with relations between C++ -specific constructs (multiple inheritance, macros, memory management, pointers, ...). To evaluate the usefulness of Ekeko's C++ support, it will be applied in a number of use cases.