cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
From: Valentin Schneider <valentin.schneider@arm.com>
To: cocci@systeme.lip6.fr
Subject: [Cocci] Matching variable declarations
Date: Thu, 5 Sep 2019 12:17:06 +0100	[thread overview]
Message-ID: <d9df847c-199d-e78d-aff2-6f14629d63b5@arm.com> (raw)

Hi,

I'm trying to change the type of variables that match a certain rule.
Abstracting away this specific rule and only looking at coming up with a
rule to match variable declarations, I have a few newbie questions.

Say I want to replace all long declarations into ints, this simple rule
seems to be working fine:

---
@@
identifier var;
type T = long;
expression E;
@@

(
- T var;
+ int var;
|
- T var = E;
+ int var = E;
)
---

I tried to write it as
---
- T
+ int
var
? = E
;
---
but that doesn't seem to be a valid syntax.


Now, I'd like to match declarations of several variables in a single
statement as well.

Say I want to get something like

- long a, b = 2, c, d = 42, e;
+ long a, b = 2, c, e;
+ int d = 42;

 (match on longs initialized to 42)

My current attempt is
---
@@
identifier var;
type T = long;
expression L, R;
@@

T L,
- var = 42
R;
+ int var;
---
But that isn't valid either. How should I go about writing this sort of
rule?

If you're curious, there's more context about what I'm trying to achieve
at:

https://lore.kernel.org/lkml/20190902210558.GA23013@avx2/

Thanks,
Valentin
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

             reply	other threads:[~2019-09-05 11:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-05 11:17 Valentin Schneider [this message]
2019-09-05 12:03 ` [Cocci] Matching variable declarations Julia Lawall
2019-09-05 14:08   ` Valentin Schneider

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=d9df847c-199d-e78d-aff2-6f14629d63b5@arm.com \
    --to=valentin.schneider@arm.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).