All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fonyuy-Asheri Caleb <fonyuy-asheri.caleb@inria.fr>
To: cocci@inria.fr
Subject: [cocci] Creating function definitions from function pointers in a struct with coccinelle
Date: Mon, 10 Feb 2025 12:08:05 +0100 (CET)	[thread overview]
Message-ID: <1579016749.8625707.1739185685318.JavaMail.zimbra@inria.fr> (raw)

[-- 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 --]

             reply	other threads:[~2025-02-10 11:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-10 11:08 Fonyuy-Asheri Caleb [this message]
2025-02-10 11:16 ` [cocci] Creating function definitions from function pointers in a struct with coccinelle 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1579016749.8625707.1739185685318.JavaMail.zimbra@inria.fr \
    --to=fonyuy-asheri.caleb@inria.fr \
    --cc=cocci@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.