All of lore.kernel.org
 help / color / mirror / Atom feed
* [cocci] Creating function definitions from function pointers in a struct with coccinelle
@ 2025-02-10 11:08 Fonyuy-Asheri Caleb
  2025-02-10 11:16 ` Julia Lawall
  0 siblings, 1 reply; 11+ messages in thread
From: Fonyuy-Asheri Caleb @ 2025-02-10 11:08 UTC (permalink / raw)
  To: cocci

[-- Attachment #1: Type: text/plain, Size: 1073 bytes --]

Hello, 

I am new to coccinelle and am interested in creating a patch which can define functions based on the function pointers 
available in a struct declaration. Since the names of the pointers don't exactly match the 
function definitions I want, I used a python script to modify the names. Below is my script: 

@m_rule@ 
field list f_list; 
identifier I; 
@@ 
struct I { 
f_list 
}; 

@script:python p_rule@ 
nf << m_rule.f_list; 
n_list; 
@@ 
new_nf = [] 
for f in nf: 
parts = f.split("(") 
r_type = parts[0] 
if '*' in r_type: 
r_type=r_type.strip() 
else: 
r_type = r_type.lstrip() 
f_name = parts[1].split(")")[0].replace("*", "").strip() 
params = parts[2].split(")")[0] 
new_nf.append(r_type + "pv_" + f_name + "(" + params + ")") 
new_nf.append(r_type + "hvm_" + f_name + "(" + params + ")") 


Please how can I write a new rule that defines several lines of function definitions from 
the p_rule new_nf list available in my python structure? 

I tried adding the list in a plus(+) entry but that does not work. 


Thank you in advance for your help. 

Caleb 

[-- Attachment #2: Type: text/html, Size: 2018 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-02-10 15:54 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-10 11:08 [cocci] Creating function definitions from function pointers in a struct with coccinelle Fonyuy-Asheri Caleb
2025-02-10 11:16 ` Julia Lawall
2025-02-10 11:23   ` Fonyuy-Asheri Caleb
2025-02-10 11:32     ` Julia Lawall
2025-02-10 11:42       ` Fonyuy-Asheri Caleb
2025-02-10 11:56         ` Julia Lawall
2025-02-10 14:48           ` Fonyuy-Asheri Caleb
2025-02-10 14:52             ` Julia Lawall
2025-02-10 14:54               ` Fonyuy-Asheri Caleb
2025-02-10 15:00                 ` Julia Lawall
2025-02-10 15:54                 ` Markus Elfring

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.