2. I have noticed that the discussed filter pattern needs another extension.
What is the best way to express the other uses besides direct function calls
in
the semantic patch language?
How should function pointers be generally handled here that are used with the
access operators "." or "->"?
I have tried to extend the suggested approach myself.
elfring@Sonne:~/Projekte/Coccinelle/Probe> SRC=f-ptr-test1.c && cat $SRC && echo
'-----' && PAT=../my_pattern2.cocci && cat $PAT && echo '-----' && spatch
-sp_file $PAT $SRC
void my_log(char const * text)
{
/* Write something ... */
}
char const * const my_message(void)
{
return "Surprise!";
}
int my_status(void)
{
return 1;
}
int main(void)
{
struct my_operations
{
void (*log)(char const * t);
char const * const (*get_message)(void);
int (*is_ready)(void);
} mo = {my_log, my_message, my_status}, * mop = &mo;
char const * const x = mo.get_message();
int y = mop->is_ready();
mo.log(mo.get_message());
mo.is_ready();
}
-----
@r@
identifier f;
@@
f(...);
@is_void@
identifier r.f;
@@
void f(...);
@depends on !is_void@
identifier r.f != {strcpy, strcat};
identifier g;
expression a, b;
@@
g(...)
{<+...
(
* f(...);
|
* (a)->f(...);
|
* (b).f(...);
)
...+>}
@is_assigned@
position p;
expression a, b, v, w, x, y;
expression f != {strcpy, strcat, fread, fclose};
statement S1, S2, S3, S4;
type t;
@@
(
y@p = (t) (x)(...)
|
y@p = (t) (a)->(x)(...)
|
y@p = (t) (b).(x)(...)
)
... when != if (<+...y...+>) S1 else S2
when != (f)(...,<+...y...+>,...)
when != (v)->(f)(...,<+...y...+>,...)
when != (w).(f)(...,<+...y...+>,...)
when != for (...;<+...y...+>;...) S3
when != while (<+...y...+>) S4
when != switch (<+...y...+>) { case ... : ... }
when != (<+...y...+>) ? ... : ...
@is_assigned_without_when_filters@
position p != is_assigned.p;
expression a, b, x, y;
type t;
@@
(
*y@p = (t) (x)(...)
|
*y@p = (t) (a)->(x)(...)
|
*y@p = (t) (b).(x)(...)
)
-----
init_defs_builtins: /usr/share/coccinelle/standard.h
420 421
Fatal error: exception Failure("minus: parse error:
= File "../my_pattern2.cocci", line 37, column 16, charpos = 420
around = '(', whole content = y@p = (t) (a)->(x)(...)
")
How do you think about this analysis result?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)