CloneGen / CLONEGEN

12 stars 5 forks source link

What is the role of parseCode.py in mutation.sh ? #2

Open ives-nx opened 2 years ago

ives-nx commented 2 years ago

Hello,When I use the code transformation script to process real world source code, I get a pycparser error: File "/usr/anaconda3/lib/python3.8/site-packages/pycparser/plyparser.py", line 67, in _parse_error raise ParseError("%s: %s" % (coord, msg)) pycparser.plyparser.ParseError: :1:25: before: *

the source code is: int ff_h264_check_intra4x4_pred_mode(H264Context *h){

Then I looked at the source code of mutation.sh and found that it called parserCode.py. I want to know what role parserCode.py plays in the code transformation, I found that when I comment out this line of code, the transformation can also be completed.

    txl   -q -s 128 temp1.c $TXLCODEPATH"RemoveNullStatements.Txl" > temp3.c &&
    txl   -q -s 128 temp3.c $TXLCODEPATH"PrettyPrint.Txl" > temp4.c &&
    txl   -q -s 128 temp4.c $TXLCODEPATH"RemoveNullStatements.Txl" > temp.c &&  
    python ParseCode.py temp.c &&
    cp  temp.c Mutated.c   
    # cat Mutated.c
    echo "result reserved in Mutated.c"
    rm  -rf temp* 
from pycparser import c_parser        
import argparse  
parser = argparse.ArgumentParser(description="Choose a dataset:[c|java]")
parser.add_argument("filename")
args = parser.parse_args()  
with open(args.filename ,'r') as f:
    line=f.read()
    parser = c_parser.CParser()
    # parser.parse(line)

It looks like the results of parserCode.py are not used by subsequent operations of mutation.sh, but I'm not sure if commenting out parser.parse(line) will have any effect on other programs?

yqtianust commented 2 years ago

I am not one of the authors of this work. Here is my guess.

&& in bash means that the 2nd command will be executed only if the 1st command successfully runs. In other words, if the parseCode fails, mutation.sh will not copy the temp.c to Mutated.c.

Therefore, I think parseCode.py just checks whether the code in temp.c can be parsed by the c parser. If not, it implies that the code in temp.c is not a valid C code (and thus it should be discarded, instead of being copied to Mutated.C).

ives-nx commented 2 years ago

I think you are right! Thanks.

CloneGen commented 2 years ago

you're right.  If you comments parse code.py can't guarantee the grammarly correctness.  Commenting out this line of code supports handling C++.

---Original--- From: @.> Date: Fri, Nov 4, 2022 14:45 PM To: @.>; Cc: @.***>; Subject: Re: [CloneGen/CLONEGEN] What is the role of parseCode.py in mutation.sh ? (Issue #2)

I think you are right! Thanks.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

ives-nx commented 2 years ago

Hello author, I would like to do code transformation for a certain line or lines of the source code file. Does TXL support it? My idea is to be able to get the transformation rules that each line of code in the source code can take based on the 15 code rules you developed, and then select some of them for code transformation.

CloneGen commented 2 years ago

My transformation rules are all transformed at the granularity of a specific syntactic structure for a function. If you want to transform at line granularity you may need to write another code.

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2022年11月5日(星期六) 中午11:25 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [CloneGen/CLONEGEN] What is the role of parseCode.py in mutation.sh ? (Issue #2)

Hello author, I would like to do code transformation for a certain line or lines of the source code file. Does TXL support it? My idea is to be able to get the transformation rules that each line of code in the source code can take based on the 15 code rules you developed, and then select some of them for code transformation.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>