OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

get all calling function inside a function

  • Thread starter Thread starter d_k
  • Start date Start date
D

d_k

Guest
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:

Code:
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.

Code:
**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):


  1. using re module
    re.findall(r'.*?(?=\s?\().*?(?=\))', body_content) re.findall(r'.*?(?=\s?\()', body_content)


  2. using regex regex.search(r'.*?(\((.*?:[()]|[^()]|(?R))*+\))', body_content )

Expectation: get all the functions with name. i.e. func1, func2, func3, func4, func5, func6

Is there any way to recursively call regex?
<p>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).</p>
<p>for ex:</p>
<pre><code>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)
}
}
</code></pre>
<p>I'm parsing the above content(only body) as a single line.</p>
<pre><code>**body_content **= "int a = {0}; func1(arg1, arg11); if(var1 == data1 && func2(arg2)) { var2 = func3(arg3, func4(arg4)) func5(var5) } else { (void)func6(arg6) }"
</code></pre>
<p><strong>Tried</strong> (in <strong>Python 3.12.3</strong>):</p>
<ol>
<li><p>using re module<br />
<code>re.findall(r'.*?(?=\s?\().*?(?=\))', body_content)</code>
<code>re.findall(r'.*?(?=\s?\()', body_content)</code></p>
</li>
<li><p>using regex
<code>regex.search(r'.*?(\((.*?:[()]|[^()]|(?R))*+\))', body_content )</code></p>
</li>
</ol>
<p><strong>Expectation</strong>:
get all the functions with name.
i.e. <strong>func1</strong>, <strong>func2</strong>, <strong>func3</strong>, <strong>func4</strong>, <strong>func5</strong>, <strong>func6</strong></p>
<p>Is there any way to recursively call regex?</p>
 

Online statistics

Members online
0
Guests online
4
Total visitors
4
Top