* [cocci] How can I find all static variable declarations?
@ 2022-03-02 3:17 Eric Wheeler
2022-03-02 7:21 ` Julia Lawall
0 siblings, 1 reply; 3+ messages in thread
From: Eric Wheeler @ 2022-03-02 3:17 UTC (permalink / raw)
To: cocci
Hello,
I'm trying to find all static variable declarations (either global or
within a function:
static int global_x, y, z;
void foo()
{
static int a, b, c;
}
with a patch like this:
@ rule1 @
identifier I;
type T;
@@
static T I;
+ // static ^^
It gets single variable declarations:
static gint iv[4];
+ // static ^^
but not multiple variable declarations like the foo() example above
because 'I' only matches a single variable in the rule.
It also matches functions, but I really only want variables (if possible):
static void subph( int nx, int ny );
+// static ^^
I tried an identfier list:
@ rule1 @
identifier list IL;
type T;
@@
static T IL;
+ // static ^^
but gives the error:
init_defs_builtins: /usr/lib64/coccinelle/standard.h
minus: parse error:
File "nec-static.cocci", line 5, column 9, charpos = 50
around = 'IL',
whole content = static T IL;
What is the right way to do this?
I'm just printing the diffs so I can inspect the code, sort of using
`spatch` like a semantic grep. Is there an official way to do "semantic
greps"?
--
Eric Wheeler
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [cocci] How can I find all static variable declarations?
2022-03-02 3:17 [cocci] How can I find all static variable declarations? Eric Wheeler
@ 2022-03-02 7:21 ` Julia Lawall
2022-03-03 3:26 ` Eric Wheeler
0 siblings, 1 reply; 3+ messages in thread
From: Julia Lawall @ 2022-03-02 7:21 UTC (permalink / raw)
To: Eric Wheeler; +Cc: cocci
On Tue, 1 Mar 2022, Eric Wheeler wrote:
> Hello,
>
> I'm trying to find all static variable declarations (either global or
> within a function:
>
> static int global_x, y, z;
>
> void foo()
> {
> static int a, b, c;
> }
>
> with a patch like this:
>
> @ rule1 @
> identifier I;
> type T;
> @@
> static T I;
> + // static ^^
>
> It gets single variable declarations:
> static gint iv[4];
> + // static ^^
>
> but not multiple variable declarations like the foo() example above
> because 'I' only matches a single variable in the rule.
>
> It also matches functions, but I really only want variables (if possible):
> static void subph( int nx, int ny );
> +// static ^^
>
> I tried an identfier list:
> @ rule1 @
> identifier list IL;
> type T;
> @@
> static T IL;
> + // static ^^
>
> but gives the error:
>
> init_defs_builtins: /usr/lib64/coccinelle/standard.h
> minus: parse error:
> File "nec-static.cocci", line 5, column 9, charpos = 50
> around = 'IL',
> whole content = static T IL;
>
> What is the right way to do this?
What you tried should have worked. And it should not have matched
function definitions. I will check on it.
>
> I'm just printing the diffs so I can inspect the code, sort of using
> `spatch` like a semantic grep. Is there an official way to do "semantic
> greps"?
Use * instead of - or + for the things you are interested in. You will
still get a diff, but the - lines are the ones that match what you wanted
to see.
julia
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [cocci] How can I find all static variable declarations?
2022-03-02 7:21 ` Julia Lawall
@ 2022-03-03 3:26 ` Eric Wheeler
0 siblings, 0 replies; 3+ messages in thread
From: Eric Wheeler @ 2022-03-03 3:26 UTC (permalink / raw)
To: Julia Lawall; +Cc: cocci
On Wed, 2 Mar 2022, Julia Lawall wrote:
> On Tue, 1 Mar 2022, Eric Wheeler wrote:
> > Hello,
> >
> > I'm trying to find all static variable declarations (either global or
> > within a function:
> >
> > static int global_x, y, z;
> >
> > void foo()
> > {
> > static int a, b, c;
> > }
> >
> > with a patch like this:
> >
> > @ rule1 @
> > identifier I;
> > type T;
> > @@
> > static T I;
> > + // static ^^
> >
> > It gets single variable declarations:
> > static gint iv[4];
> > + // static ^^
> >
> > but not multiple variable declarations like the foo() example above
> > because 'I' only matches a single variable in the rule.
> >
> > It also matches functions, but I really only want variables (if possible):
> > static void subph( int nx, int ny );
> > +// static ^^
> >
> > I tried an identfier list:
> > @ rule1 @
> > identifier list IL;
> > type T;
> > @@
> > static T IL;
> > + // static ^^
> >
> > but gives the error:
> >
> > init_defs_builtins: /usr/lib64/coccinelle/standard.h
> > minus: parse error:
> > File "nec-static.cocci", line 5, column 9, charpos = 50
> > around = 'IL',
> > whole content = static T IL;
> >
> > What is the right way to do this?
>
> What you tried should have worked. And it should not have matched
> function definitions. I will check on it.
Thanks for checking!
FYI:
]# spatch --version
spatch version 1.1.1-00044-gb2a4b9b compiled with OCaml version 4.05.0
Flags passed to the configure script: --prefix=/usr/local/coccinelle-git
OCaml scripting support: yes
Python scripting support: yes
Syntax of regular expressions: PCRE
Let me know if there if you have a patch or git update and I'll try it out.
>
> >
> > I'm just printing the diffs so I can inspect the code, sort of using
> > `spatch` like a semantic grep. Is there an official way to do "semantic
> > greps"?
>
> Use * instead of - or + for the things you are interested in. You will
> still get a diff, but the - lines are the ones that match what you wanted
> to see.
Neat! I'll give it a try.
--
Eric Wheeler
>
> julia
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-03-03 3:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-02 3:17 [cocci] How can I find all static variable declarations? Eric Wheeler
2022-03-02 7:21 ` Julia Lawall
2022-03-03 3:26 ` Eric Wheeler
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.