I'm parsing a GLSL source code and I need to replace global variable name with a new name. The problem is how to take care of shadow variable? For example, in the following source code, I would like to replace lines a = 1
and a = 3
but not a = 2
because of the local declaration.
int a; // To be replaced
void some_function(void)
{
a = 1; // To be replaced
{
int a;
a = 2; // To be kept
}
a = 3; // To be replaced
}
I'm using pyparsing but I did not find a solution (apart using nestedExpr
and re-parsing each block).