I’m trying to find a way which can fetch all the function which is being called inside the body of a function (i.e. main_func).
for ex:
void main_func (){
int a = {0};
func1(arg1, arg11);
if ( var1 == data1 && func2(arg2))
{
var2 = func3(arg3, func4(arg4))
func5(var5)
}
else
{
(void)func6(arg6)
}
}
I’m parsing the above content(only body) as a single line.
**body_content **= “int a = {0}; func1(arg1, arg11); if(var1 == data1 && func2(arg2)) { var2 = func3(arg3, func4(arg4)) func5(var5) } else { (void)func6(arg6) }”
Tried (in Python 3.12.3):
-
using re module
re.findall(r'.*?(?=s?().*?(?=))', body_content)
re.findall(r'.*?(?=s?()', body_content)
-
using regex
regex.search(r'.*?(((.*?:[()]|[^()]|(?R))*+))', body_content )
Expectation:
get all the functions with name.
i.e. func1, func2, func3, func4, func5, func6
Pls help me to resolve this. Is there any way to recursively call regex.