Share on Facebook Tweet on Twitter Share on LinkedIn Share by email
A language to script refactoring transformations

Mathieu Verbaere


Refactorings are behaviour-preserving program transformations, typically for improving the structure of existing code. A few of these transformations have been mechanised in interactive development environments. Many more refactorings have been proposed, and it would be desirable for programmers to script their own refactorings. Implementing such source-to-source transformations, however, is quite complex: even the most sophisticated development environments contain significant bugs in their refactoring tools.

We introduce a domain-specific language to script refactoring transformations. The language, named JunGL, is a hybrid of a functional language in the style of ML and a logic query language. It allows the computation of static-semantic information, such as name binding and control flow, and the expression of refactoring preconditions as queries on a graph representation of the program. Borrowing from earlier work on the specification of compiler optimisations, JunGL notably uses path queries to express dataflow properties.

We have been careful to keep the semantics of all logical features very declarative to provide a sound basis for rigorous reasoning on the transformations. All constructs translate to a novel variant of Datalog, a query language originally put forward in the theory of databases. This variant works on duplicate-free sequences rather than sets, with the rationale to present logical matches in a meaningful deterministic order. We call it Ordered Datalog.

Ordered Datalog programs, like Datalog programs, can be classified depending on how nonmonotonic constructs such as negation are used. We identify the new class of partially stratified programs as sufficiently expressive for our application, and highlight an evaluation strategy following the Query-Subquery approach. Finally, we describe the current implementation of JunGL, and validate the whole design of the language via a number of complex refactoring transformations.


Publication typePhdThesis
InstitutionUniversity of Oxford
> Publications > A language to script refactoring transformations