All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] Find all variables/parameters of a given type.
@ 2015-01-16 12:42 Eliseo Martínez
  2015-01-16 17:51 ` Julia Lawall
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Eliseo Martínez @ 2015-01-16 12:42 UTC (permalink / raw)
  To: cocci

Hi, 

I?m trying to write a semantic patch to be able to find all `long` variables/function parameters in my code.
I?ve tried a lot of variations, the last of them being:

```
@@ identifier i; @@

* long i;

@@ identifier i, f; @@

(
* f(long i) { ... }
|
* f(long i, ...) { ... }
|
* f(..., long i, ...) { ... }
|
* f(..., long i) { ... }
)
```

But I get parse errors no matter what I try.
Where?s my error? 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Cocci] Find all variables/parameters of a given type.
  2015-01-16 12:42 [Cocci] Find all variables/parameters of a given type Eliseo Martínez
@ 2015-01-16 17:51 ` Julia Lawall
  2015-01-16 17:55 ` SF Markus Elfring
  2015-01-16 18:36 ` [Cocci] Find all variables/parameters of a given type SF Markus Elfring
  2 siblings, 0 replies; 11+ messages in thread
From: Julia Lawall @ 2015-01-16 17:51 UTC (permalink / raw)
  To: cocci

On Fri, 16 Jan 2015, Eliseo Mart?nez wrote:

> Hi,
>
> I?m trying to write a semantic patch to be able to find all `long` variables/function parameters in my code.
> I?ve tried a lot of variations, the last of them being:
>
> ```
> @@ identifier i; @@
>
> * long i;
>
> @@ identifier i, f; @@
>
> (
> * f(long i) { ... }
> |
> * f(long i, ...) { ... }
> |
> * f(..., long i, ...) { ... }
> |
> * f(..., long i) { ... }
> )

You can't put function definitions in a disjunction.  But you don't need
to either.  The third case will take care of everything.

julia

> ```
>
> But I get parse errors no matter what I try.
> Where?s my error?
> _______________________________________________
> Cocci mailing list
> Cocci at systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Cocci] Find all variables/parameters of a given type.
  2015-01-16 12:42 [Cocci] Find all variables/parameters of a given type Eliseo Martínez
  2015-01-16 17:51 ` Julia Lawall
@ 2015-01-16 17:55 ` SF Markus Elfring
  2015-01-16 18:10   ` Julia Lawall
  2015-01-16 18:36 ` [Cocci] Find all variables/parameters of a given type SF Markus Elfring
  2 siblings, 1 reply; 11+ messages in thread
From: SF Markus Elfring @ 2015-01-16 17:55 UTC (permalink / raw)
  To: cocci

> But I get parse errors no matter what I try.

I guess that I can not really help with parsing difficulties
in your case.


> Where?s my error?

I find that your SmPL disjunction can also be written in
a slightly different way.
Would you like to try out the following semantic filter approach?

@find_big_integers@
identifier func, var;
@@
(
*long var
 ... ;
|
 func(...,
*     long var,
      ...);
|
 func(...,
*     long var,
      ...)
 { ... }
)

Regards,
Markus

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Cocci] Find all variables/parameters of a given type.
  2015-01-16 17:55 ` SF Markus Elfring
@ 2015-01-16 18:10   ` Julia Lawall
  2015-01-16 18:21     ` [Cocci] Support for function definitions within SmPL disjunctions? SF Markus Elfring
  0 siblings, 1 reply; 11+ messages in thread
From: Julia Lawall @ 2015-01-16 18:10 UTC (permalink / raw)
  To: cocci



On Fri, 16 Jan 2015, SF Markus Elfring wrote:

> > But I get parse errors no matter what I try.
>
> I guess that I can not really help with parsing difficulties
> in your case.
>
>
> > Where?s my error?
>
> I find that your SmPL disjunction can also be written in
> a slightly different way.
> Would you like to try out the following semantic filter approach?
>
> @find_big_integers@
> identifier func, var;
> @@
> (
> *long var
>  ... ;
> |
>  func(...,
> *     long var,
>       ...);
> |
>  func(...,
> *     long var,
>       ...)
>  { ... }
> )

This does not work either, for the same reason previously mentioned.  You
cannot put a function definition in a disjunction.

Including function prototypes seems redundant, but may be useful if the
function definition has a parsing problem, but the prototype does not.

julia

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Cocci] Support for function definitions within SmPL disjunctions?
  2015-01-16 18:10   ` Julia Lawall
@ 2015-01-16 18:21     ` SF Markus Elfring
  0 siblings, 0 replies; 11+ messages in thread
From: SF Markus Elfring @ 2015-01-16 18:21 UTC (permalink / raw)
  To: cocci

> You cannot put a function definition in a disjunction.

Would anybody like to change this software limitation?

Regards,
Markus

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Cocci] Find all variables/parameters of a given type.
  2015-01-16 12:42 [Cocci] Find all variables/parameters of a given type Eliseo Martínez
  2015-01-16 17:51 ` Julia Lawall
  2015-01-16 17:55 ` SF Markus Elfring
@ 2015-01-16 18:36 ` SF Markus Elfring
  2015-01-16 19:18   ` Eliseo Martínez
  2 siblings, 1 reply; 11+ messages in thread
From: SF Markus Elfring @ 2015-01-16 18:36 UTC (permalink / raw)
  To: cocci

> I?m trying to write a semantic patch to be able to find
> all `long` variables/function parameters in my code.

Can the desired semantic filter approach be also written
without a SmPL disjunction?

Would you like to try the following variant out?

@find_integer_variable@
identifier var;
@@
*long var
 ... ;
)

@find_integer_within_function_declaration@
identifier func, var;
@@
 func(...,
*     long var,
      ...);
)

@find_integer_from_function_definition@
identifier func, var;
@@
 func(...,
*     long var,
      ...)
 { ... }


Are you looking for more special cases in your source code?

Regards,
Markus

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Cocci] Find all variables/parameters of a given type.
  2015-01-16 18:36 ` [Cocci] Find all variables/parameters of a given type SF Markus Elfring
@ 2015-01-16 19:18   ` Eliseo Martínez
  2015-01-16 20:05     ` SF Markus Elfring
  2015-01-16 20:11     ` Julia Lawall
  0 siblings, 2 replies; 11+ messages in thread
From: Eliseo Martínez @ 2015-01-16 19:18 UTC (permalink / raw)
  To: cocci

Ok. Rule for function definition works. Rule for function declaration doesn?t (gives parse error too).
To my particular problem at hand, I don?t need to locate declarations, so that solves my problem.
But just out of curiosity, why rule for function declaration is incorrect?

Thanks!

BTW, every time I post a message to this list, I get a message back saying my message has to be moderated since I?m not a member of the list. Can I be added to such list, or is it somehow restricted?


> On 16 Jan 2015, at 19:36, SF Markus Elfring <elfring@users.sourceforge.net> wrote:
> 
>> I?m trying to write a semantic patch to be able to find
>> all `long` variables/function parameters in my code.
> 
> Can the desired semantic filter approach be also written
> without a SmPL disjunction?
> 
> Would you like to try the following variant out?
> 
> @find_integer_variable@
> identifier var;
> @@
> *long var
> ... ;
> )
> 
> @find_integer_within_function_declaration@
> identifier func, var;
> @@
> func(...,
> *     long var,
>      ...);
> )
> 
> @find_integer_from_function_definition@
> identifier func, var;
> @@
> func(...,
> *     long var,
>      ...)
> { ... }
> 
> 
> Are you looking for more special cases in your source code?
> 
> Regards,
> Markus

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Cocci] Find all variables/parameters of a given type.
  2015-01-16 19:18   ` Eliseo Martínez
@ 2015-01-16 20:05     ` SF Markus Elfring
  2015-01-16 20:22       ` Julia Lawall
  2015-01-16 20:11     ` Julia Lawall
  1 sibling, 1 reply; 11+ messages in thread
From: SF Markus Elfring @ 2015-01-16 20:05 UTC (permalink / raw)
  To: cocci

> Rule for function declaration doesn?t (gives parse error too).

Will the semantic filter approach work better if you specify
a return type for the searched functions explicitly?

@find_integer_within_function_declaration@
identifier func, var;
type return_type;
@@
 return_type
 func(...,
*     long var,
      ...);
)

@find_integer_from_function_definition@
identifier func, var;
type return_type;
@@
 return_type
 func(...,
*     long var,
      ...)
 { ... }



> Can I be added to such list, or is it somehow restricted?

Would you like to subscribe to this mailing list?
http://coccinelle.lip6.fr/contact.php

Regards,
Markus

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Cocci] Find all variables/parameters of a given type.
  2015-01-16 19:18   ` Eliseo Martínez
  2015-01-16 20:05     ` SF Markus Elfring
@ 2015-01-16 20:11     ` Julia Lawall
  1 sibling, 0 replies; 11+ messages in thread
From: Julia Lawall @ 2015-01-16 20:11 UTC (permalink / raw)
  To: cocci

On Fri, 16 Jan 2015, Eliseo Mart?nez wrote:

> Ok. Rule for function definition works. Rule for function declaration doesn?t (gives parse error too).
> To my particular problem at hand, I don?t need to locate declarations, so that solves my problem.
> But just out of curiosity, why rule for function declaration is incorrect?
> 
> Thanks!

I don't know any more what exactly is your rule for function declarations.  

> BTW, every time I post a message to this list, I get a message back saying my message has to be moderated since I?m not a member of the list. Can I be added to such list, or is it somehow restricted?

If you would like to join the mailing list, send an empty e-mail to 
cocci-subscribe at systeme.lip6.fr.

julia

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Cocci] Find all variables/parameters of a given type.
  2015-01-16 20:05     ` SF Markus Elfring
@ 2015-01-16 20:22       ` Julia Lawall
  2015-01-16 21:25         ` Eliseo Martínez
  0 siblings, 1 reply; 11+ messages in thread
From: Julia Lawall @ 2015-01-16 20:22 UTC (permalink / raw)
  To: cocci

On Fri, 16 Jan 2015, SF Markus Elfring wrote:

> > Rule for function declaration doesn?t (gives parse error too).
> 
> Will the semantic filter approach work better if you specify
> a return type for the searched functions explicitly?
> 
> @find_integer_within_function_declaration@
> identifier func, var;
> type return_type;
> @@
>  return_type
>  func(...,
> *     long var,
>       ...);

The return type is indeed needed in this case; otherwise the parser will 
think it is a function call.

> )
> 
> @find_integer_from_function_definition@
> identifier func, var;
> type return_type;
> @@
>  return_type
>  func(...,
> *     long var,
>       ...)
>  { ... }

The return type is not needed in this case.

julia

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Cocci] Find all variables/parameters of a given type.
  2015-01-16 20:22       ` Julia Lawall
@ 2015-01-16 21:25         ` Eliseo Martínez
  0 siblings, 0 replies; 11+ messages in thread
From: Eliseo Martínez @ 2015-01-16 21:25 UTC (permalink / raw)
  To: cocci


> The return type is indeed needed in this case; otherwise the parser will 
> think it is a function call.

Ok. Thanks!

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-01-16 21:25 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-16 12:42 [Cocci] Find all variables/parameters of a given type Eliseo Martínez
2015-01-16 17:51 ` Julia Lawall
2015-01-16 17:55 ` SF Markus Elfring
2015-01-16 18:10   ` Julia Lawall
2015-01-16 18:21     ` [Cocci] Support for function definitions within SmPL disjunctions? SF Markus Elfring
2015-01-16 18:36 ` [Cocci] Find all variables/parameters of a given type SF Markus Elfring
2015-01-16 19:18   ` Eliseo Martínez
2015-01-16 20:05     ` SF Markus Elfring
2015-01-16 20:22       ` Julia Lawall
2015-01-16 21:25         ` Eliseo Martínez
2015-01-16 20:11     ` Julia Lawall

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.