GenPat 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.[PDF][Tool]
Inferring Stage
Extracting Hypergraphs : parses source code before and after changing into hypergraph representations with a set of predefined attributes and relations in the graph.
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.
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
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.
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.
SimFix is an automatic program repair technique, which leverages exisiting patches from other projects and similar code snippets in the same project to generate patches. The following figure is the workflow of our approach.[PDF][Tool]
Mining Stage
mine repair patterns from existing open-source projects, after which we can obtain a set of frequent repair patterns. Those patterns can be reused for other repairing scenarios as well.
Repairing Stage
Fault Localization : obtain a ranking list of candidate faulty statements and extract corresponding code snippets.
Donor Snippet Identification : identify the similarity between faulty code snippet and each candidate similar code snippet by leveraging three similarity metrics, according to which we obtain a list of candidate similar snippets with decending order of similarity value.
Variable Mapping : establish the mapping relationship between variables in faulty and similar code snippets by leveraging similarity metrics and then obtain a mapping table, based on which the variables in the donor code snippet will be replaced with the corresponding variables.
Modification Extraction and Intersection : extract code modifications to faulty code snippet via AST (Abstract Syntax Tree) matching and differencing against the donor snippet, and then the frequent patterns from the mining stage will be used to take intersection with those modifications to further ruled out invalid ones.
Patch Generation & Validation : generate repair patches by applying extracted code modifications to the faulty code snippet with combining and ranking whose modifications, then using the test suite to validate the correctness of candidate patches until a correct patch found or timeout.