-
Notifications
You must be signed in to change notification settings - Fork 16
Description
Hi,
Thanks for your awesome tool.
I currently want to extract variables in if-conditions efficiently and tried to use srcslice to get the result of the define-use relations of a variable in the first step. However, I can not get the expected results on a tiny program.
Here is the program (test.c) I used
int g_a = 0;
int foo_1(int a){
g_a = 100;
if (a > 0)
;
else if (a == 0)
;
else
;
if (g_a == 0) {
g_a ++;
}
return 0;
}
int main(){
foo_1(g_a);
return 0;
}
I used the produce-dict.sh to process it, where two lines are in the script
srcml test.c --position -o test.xml
srcslice test.xml
After I execute produce-dict.sh, I got the following
==========================================================================
Name: a
Dvars: {}
Aliases: {}
Use: {}
Def: {2,}
Edges: {}
==========================================================================
==========================================================================
Name: g_a
Dvars: {g_a,}
Aliases: {}
Use: {11,16,}
Def: {1,2,3,}
Edges: {(1, 3),(3, 11),(11, 16),}
==========================================================================
I guess the use field of a is incorrect (the uses in if-conditions are missing) and g_a's result also gets some issues (e.g., the use of if-condition in function foo_1 is missing).
The srcslice version is the master branch at commit e0283e8
The srcml version is
$srcml --version
srcml 1.0.0
libsrcml 1.0.0
libarchive 3.2.2
I also investigated more on other versions of srcSlice, I downloaded the pre-build binary srcslice-ubuntu-14 to replace the srcSlice in the produce-dict.sh script and got the following results:
Time is: 0.000751
test.c,foo_1,g_a,def{3},use{10,11},dvars{},pointers{},cfuncs{}
test.c,foo_1,a,def{2},use{4,6},dvars{},pointers{},cfuncs{}
From the results, the uses of variable a seem correct but the defs of g_a seem incorrect again. Did I miss anything to get the correct results? I will try to modify srcSlice to get more detailed results so I hope the master version srcSlice can work for identifying all the uses of a variable in the program.
Could you please give any hints on how to do it? Thank you so much.
Best regards.
Haoxin