All of lore.kernel.org
 help / color / mirror / Atom feed
From: daniel.lezcano@linaro.org (Daniel Lezcano)
To: cocci@systeme.lip6.fr
Subject: [Cocci] Adding argument to a function
Date: Wed, 2 Nov 2016 22:09:50 +0100	[thread overview]
Message-ID: <20161102210950.GA1770@mai> (raw)

Hi all,

I'm very new to coccinelle, so sorry if the question is irrelevant or was already asked.

I'm trying to add a new argument to a function which has a couple of callbacks.

The original function is:

static inline int cpuhp_setup_state(enum cpuhp_state state,
				    int (*startup)(unsigned int cpu),
				    int (*teardown)(unsigned int cpu));

I would like to pass a private pointer when setting the state and then pass
this pointer to the 'startup' / 'teardown' callbacks where there signature will be
different and all call sites must change their callbacks signature also.

I tried to first add the new argument to the function, in order to have:

static inline int cpuhp_setup_state(enum cpuhp_state state,
				    int (*startup)(unsigned int cpu),
				    int (*teardown)(unsigned int cpu),
				    void *data);

... with the rule:

@rule@
identifier cpuhp_setup_state;
identifier state, name, startup, teardown, data;
@@

static inline int cpuhp_setup_state(enum cpuhp_state state,
                                    const char *name,
                                    int (*startup)(unsigned int cpu),
                                    int (*teardown)(unsigned int cpu),
				    void *data)
{
	...
}

@@
identifier rule.cpuhp_setup_state;
expression E1, E2, E3, E4;
@@

cpuhp_setup_state(E1, E2, E3, E4
+                 , NULL
		 )

But the parsing gives:

...

cpuhp_setup_state(E1, E2, E3, E4
                    >>> , NULL
                  )


grep tokens
cpuhp_state || cpu
No query
warning: line 8: should cpu be a metavariable?
warning: line 9: should cpu be a metavariable?

And I don't have the expected result, well actually I have no output.

Can someone give me some hints or help to implement this change ?

Thanks in advance

  -- Daniel

             reply	other threads:[~2016-11-02 21:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-02 21:09 Daniel Lezcano [this message]
2016-11-02 21:40 ` [Cocci] Adding argument to a function Julia Lawall
2016-11-03  0:56   ` Daniel Lezcano
2016-11-03  6:17     ` Julia Lawall
2016-11-04 17:22       ` Daniel Lezcano
2016-11-04 21:07         ` Julia Lawall
2016-11-04 21:29           ` Daniel Lezcano
2016-11-04 21:32             ` Julia Lawall
2016-11-04 17:26       ` Daniel Lezcano

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=20161102210950.GA1770@mai \
    --to=daniel.lezcano@linaro.org \
    --cc=cocci@systeme.lip6.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.