Find all variables/parameters of a given type.
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?
Quoted 12 lines · Eliseo Mart?nez
Hi,
I?m trying to write a semantic patch to be able to find all
longvariables/function parameters in my code. I?ve tried a lot of variations, the last of them being:```
@@ identifier i; @@* long i;
@@ identifier i, f; @@
Quoted 9 lines
(
* 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
Quoted 9 lines
```
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
Quoted 1 line
But I get parse errors no matter what I try.
I guess that I can not really help with parsing difficulties in your case.
Quoted 1 line
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
Quoted 21 lines · SF Markus Elfring
Quoted 1 line
But I get parse errors no matter what I try.
I guess that I can not really help with parsing difficulties in your case.
Quoted 1 line
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,
Quoted 7 lines
...); | 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
[Cocci] Support for function definitions within SmPL disjunctions?
Quoted 1 line
You cannot put a function definition in a disjunction.
Would anybody like to change this software limitation?
Regards,
Markus
Quoted 2 lines
I?m trying to write a semantic patch to be able to find all
longvariables/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
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?
Quoted 38 lines · SF Markus Elfring
Quoted 3 lines
I?m trying to write a semantic patch to be able to find all
longvariables/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
Quoted 1 line
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,
...)
{ ... }
Quoted 1 line
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
Quoted 5 lines · SF Markus Elfring
Quoted 1 line
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?
Quoted 8 lines
@find_integer_within_function_declaration@
identifier func, var;
typereturn_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.
Quoted 11 lines
)
@find_integer_from_function_definition@
identifier func, var;
typereturn_type;
@@
return_type
func(...,
* long var,...){ ... }
The return type is not needed in this case.
julia
Quoted 3 lines
The return type is indeed needed in this case; otherwise the parser will think it is a function call.
Ok. Thanks!
Quoted 5 lines · Eliseo Mart?nez
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.
Quoted 1 line
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