From: joe@perches.com (Joe Perches)
To: cocci@systeme.lip6.fr
Subject: [Cocci] cocci script to add static to const declarations ?
Date: Wed, 30 Aug 2017 05:38:27 -0700 [thread overview]
Message-ID: <1504096707.2786.20.camel@perches.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1708301334550.3184@hadrien>
On Wed, 2017-08-30 at 13:41 +0200, Julia Lawall wrote:
> The following seems to work:
>
> @initialize:ocaml@
> @@
>
> let diff(p,i) = not ((List.hd p).current_element = i)
>
> @promising disable optional_storage@
> position p;
> constant c;
> type t;
> identifier i;
> @@
>
> const t i at p[] = { ...,c,... };
>
> @worrisome@
> position promising.p,bad;
> constant c;
> expression e;
> type t;
> identifier i;
> @@
>
> const t i at p[] = { ...,\(c\|e at bad\),... };
>
> @hasexp@
> position promising.p,worrisome.bad;
> expression e;
> type t;
> identifier i;
> @@
>
> const t i at p[] = { ...,e at bad,... };
>
> @depends on !hasexp@
> position promising.p : script:ocaml(promising.i) { diff(p,i) };
> type t;
> identifier i;
> @@
>
> +static
> const t i at p[] = { ... };
>
> ---
>
> The ocaml code checks that the declaration is inside a function, by
> checking that the name of the current top-level element is different than
> the name of the defined object.
>
> The main rule is "worrisome", which will set a position variable if any
> field is not a constant. This considers anything that is in all capital
> letters to be a constant, which is not safe. To forbid all arrays that
> contain any identifier, in capital letters or not, one could convert
>
> \(c\|e at bad\)
>
> to
>
> \(i at bad\|c\|e at bad\)
>
> with i defined as an identifier metavariable.
btw: thanks.
It may be useful to put smoe of these ocaml code snippers
like the above and the space between type and pointer bit
into a cookbook/recipe list somewhere.
cheers, Joe
next prev parent reply other threads:[~2017-08-30 12:38 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-30 10:49 [Cocci] cocci script to add static to const declarations ? Joe Perches
2017-08-30 11:12 ` SF Markus Elfring
2017-08-30 11:41 ` Julia Lawall
2017-08-30 11:55 ` Joe Perches
2017-08-30 20:48 ` Julia Lawall
2017-08-30 21:41 ` Julia Lawall
2017-08-30 22:33 ` Joe Perches
2017-08-31 5:04 ` Julia Lawall
2017-08-31 14:22 ` Julia Lawall
2017-08-31 18:11 ` Joe Perches
2017-08-31 19:25 ` Julia Lawall
2017-08-31 20:06 ` Joe Perches
2017-08-30 12:38 ` Joe Perches [this message]
2017-08-30 13:02 ` Julia Lawall
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=1504096707.2786.20.camel@perches.com \
--to=joe@perches.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 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.