I am working on a criterion for the coverage of multithreaded code, and as part of it I would like to write down calls to variables. For example, in the code below, I would like to write that the variable x was written and y, z, a[i], , and I was read.
x = y * (int)z + a[i]
I looked at this using Clang RecursiveASTVisitor and changing the source to enable recording functions. However, I'm not sure if this is a reasonable approach, as my understanding of how Klang works is very incomplete.
Currently, when I find the instruction, I check if it is BinaryOperator, UnaryOperator, Cast, or DeclRefExpr . (I will expand on what I am capable of as soon as my foundations are based.) If it is a BinaryOperator, UnaryOperator, or Cast , I check the subexpressions of the expression. If it is DeclRefExpr, I can check if the expression is lvalue or rvalue (again, simplifying now), but as soon as I found DeclRefExpr, they are always lvalues. To determine if they were used as lvalues or rvalues , I have to check its parent object, if it was an lvaluetorvalue sheet, it was used as an rvalue.
I really like that I am using this problem incorrectly because I see that it is becoming much more complicated, since I have to consider more complex code.
Would there be a better way to get close to this?
thanks
Edit
I am not going to write this information statically. I intend to find the use of variables and insert code that will record calls to these variables when the code runs.
For example, given the code above ( x = y * (int)z + a[i]; ), I would like to create something like
x = y * (int)z + a[i]; recordAccess(<file>, <line>, "x", &x, WRITE); recordAccess(<file>, <line>, "y", &y, READ); recordAccess(<file>, <line>, "z", &z, READ); recordAccess(<file>, <line>, "a[i]", &a[i], READ); recordAccess(<file>, <line>, "i", &i, READ);