# GenPat

Published:

## I. Introduction

GenPath is an automatic program transformation inferring framework, which infers general (reusable) transformations from singular examples. In this process, it leverages a big code corpus to guide the inference process. The following figure is the workflow of our approach.

#### Inferring Stage

1. Extracting Hypergraphs : parses source code before and after changing into hypergraph representations with a set of predefined attributes and relations in the graph.
2. Extracting Modifications : performs hypergraph differencing and extracts modifications related to corresponding nodes in the graph. Specifically, tree-based differencing, e.g., GumTree, can be used to perfrom the differencing as this hypergraph is a super graph with the original AST as backbone.
3. Inferring Transformations : based on the previous process, we know which nodes are modified. This step first selects a set of node according to the expansion starting from the changed nodes, which will constitute the context of the transformation. Next, a big code corpus will be utilized to select the attributes of those context nodes, i.e., frequently appeared attributes cross projects will be keeped in the transformation pattern, while others discarded.

As a result, the final transformation pattern contains a subset of the nodes in the hypergraph, some attributes of which are discarded.

#### Applying Stage

1. Matching Hypergraph : when given a transformation pattern and an examplar code snippet, it first extracts a hypergraph from the code and tries to match it with the given pattern, where all nodes and attributes in the pattern should be matched with some one in the hypergraph of the examplar code.
2. Migrating Modifications : after matching the hypergraph with the pattern, a sequnence of mappings can be obtained, which record the matching result of the hypergraphs. According to the mappings, modifications related to corresponding nodes can be transfered to the target hypergraph with replacing mapped variables and expressions.

If you want to use this project, please cite our technical paper published on ASE’19.

@inproceedings{GenPat:2019,
author   = {Jiang, Jiajun and Ren, Luyao and Xiong, Yingfei and Zhang, Lingming},
title    = {Inferring Program Transformations From Singular Examples via Big Code},
series   = {ASE},
year     = {2019},
location = {San Diego, California, U.S.},
}


View More Details on Github