We provide two more sections to demonstrate the effectiveness of TransRepair. The first one is the statistics of the repaired results for 74 compilation errors provided by DrRepair and TransRepair on TRACER Testset. The other one is a case study with two examples to intuitively confirm TransRepair's effectiveness.
We provide repair accuracy of DrRepair and TransRepair for each type of compilation errors (74 in total) on TRACER testset, where the column Total denotes the number of samples for current kind of compilation error in TRACER testset. We highlight rows where TransRepair is better than DrRepair in green. When TransRepair is worse than DrRepair, we highlight the row in red.
(a) Syntax-Statement (stmt)
(d) Identifier misuse (im)
(c) Variable declaration (decl)
(e) Type mismatch (tm)
From Table (a) to Table (e), we find that TransRepair is able to fix a higher number of compilation errors in terms of stmt, struct, decl and tm. For the kind of identifier misuse errors, since DrRepair constructs a program feedback graph to capture the usage relations in variables, DeRepair fixes better, but TransRepair still achieves a competitive performance (i.e., only 5 less fixes). Furthermore, we also find that the types of compilation errors that TransRepair can fix are more diverse than DrRepair for example there are 31 kinds of compilation errors that TransRepair can fix (highlighted in green) while DrRepair can only fix 12 (highlighted in red).
To demonstrate the repair capability of TransRepair, we present two examples compared the results with DrRepair for better illustration. The diagnostic feedback contains the error line number and its message provided by GCC compiler, "pred err line#" is the predicted line number and "pred_code_candidate" is generated result by different models. "pred code (edit)" denotes the result that can be accepted by the compiler.
Error code:
0 #include <stdio.h>
1 #include <string.h>
2 void pal ( char c [ ] , int k , int n ) {
3 if ( k == n || n - k == 1 ) {
4 return 1 ; }
5 if ( c [ k ] == c [ n ] ) {
6 return pal ( c , k + 1 , n - 1 ) ; }
7 else {
8 return 0 ; } }
9 int main ( ) {
10 char s [ 100 ] ;
11 int a = getchar ( ) ;
12 int i = 0 ;
13 while ( a != ' \0 ' ) {
14 s [ i ] = a ;
15 i ++ ;
16 a = getchar ( ) ; }
17 if ( pal ( s , 0 , i - 1 ) ) {
18 printf ( " Yes " ) ; }
19 else {
20 printf ( " No " ) ; }
21 return 0 ; }
Diagnostic Feedback:17:void value not ignored as it ought to be
The results generated by DrRepair:
pred err line#: 17
pred_code_candidate: if ( pal ( s , 0 , i - 1 ) ) {
pred_code_candidate: if ( pal ( s , 0 , n - 1 ) ) {
pred_code_candidate: if ( pal ( s , 0 , i - 1 ] ) {
pred_code_candidate: if ( pal ( s , 0 , n , 1 ) ) {
all edit candidates rejected.
The results generated by TransRepair:
pred err line#: 2 √
pred_code_candidate: int pal ( char c [ ] , int k , int n ) {√
pred code (edit): int pal ( char c [ ] , int k , int n ) { √
This example is used for palindrome checking. If the input string is a palindrome, then the program prints "Yes", otherwise prints "No". Line 17 needs a return value for if conditional judgment, however, the function is declared as "void" at line 2. Hence, a correct repaired statement is to fix the function declaration from "void pal (char c[], int k, int n)" to "int pal (char c[], int k, int n)". We can find that the result provided by TransRepair is correct. It not only predicts the position of the "true" error statement but also generates a correct fixing.
Tracer- ID:20287
Error code:
0 #include <stdio.h>
1 #include <stdlib.h>
2 void replace_substring ( char * s , int m , char * t , char * w , int r , int i ) {
3 int j ;
4 for ( j = i ; j < i + m ; j ++ ) {
5 s [ j ] = w [ j - i ] ; }
6 for ( j = i + m ; j < m + r ; j ++ ) {
7 s [ j ] = t [ j ] ; } }
8 int main ( ) {
9 int m , n , r , i , j , c = 0 ;
10 char * s , * t , * w , * p ;
11 scanf ( " %d " , & m ) ;
12 s = ( char * ) malloc ( sizeof ( char ) * ( m + 100 ) ) ;
13 t = ( char * ) malloc ( sizeof ( char ) * ( m + 100 ) ) ; 14 for ( i = 0 ; i < m ; i ++ ) {
15 scanf ( " %c " , & s [ i ] ) ;
16 t [ i ] = s [ i ] ; }
17 scanf ( " %d " , & n ) ;
18 w = ( char * ) malloc ( sizeof ( char ) * n ) ;
19 for ( i = 0 ; i < m ; i ++ ) {
20 scanf ( " %c " , & s [ i ] ) ; }
21 scanf ( " %d " , & r ) ;
22 p = ( char * ) malloc ( sizeof ( char ) * r ) ;
23 for ( i = 0 ; i < m ; i ++ ) {
24 scanf ( " %c " , & s [ i ] ) ; }
25 for ( i = 0 ; i < m ; i ++ ) {
26 if ( s [ i ] == p [ 0 ] ) {
27 for ( j = i ; j < ( i + n ) ; j ++ ) {
28 if ( s [ i ] == p [ j - i ] ) {
29 c ++ ; } }
30 if ( c == n ) {
31 replace_substring ( s , t , w , i ) ;
32 i = i - r ; }
33 c = 0 ; } }
34 printf ( " %s " , s ) ;
35 return 0 ; }
Diagnostic Feedback:31:too few arguments to function ‘replace_substring’
The results generated by DrRepair:
pred err line#: 31 √
pred_code_candidate: replace_substring ( s , t , w , i ) ;
pred_code_candidate: replace_substring ( s , r , w , i ) ;
pred_code_candidate: replace_substring ( s , m , w , i ) ;
pred_code_candidate: replace_substring ( s , r , w , w , i ) ;
pred_code_candidate: replace_substring ( s , t , w , w , w ) ;
all edit candidates rejected.
The results generated by TransRepair:
pred err line#: 31 √
pred_code_candidate: replace_substring ( s , m , t , w , r , i ) ; √
pred code (edit): replace_substring ( s , m , t , w , r , i ) ; √
This example is used to replace a substring. The invoked function replace_substring requires six parameters, however in the main function, only four parameters are given at line 31. Hence, to fix this error, a correct number of parameters should be used. We can see that although the predicted location is correct for both models, the first candidate that TransRepair generates is already correct and pass the compiler check. It demonstrates that TransRepair has more learning capacity thann DrRepair in fixing program errors.