What are the two places you want to change?
It is never useful to put <+... ...+> around an entire rule. That is what
the semantics of rule application already does naturally.
If you want to add at declaration at the very top of a function, make a
rule that looks like the function definition and put the declaration
there. Eg:
@@
identifier f;
@@
f(...) {
+ int x;
...
}
Unfortunately, I'm not on line very much today.
julia
On Sun, 15 May 2011, Jim Cromie wrote:
> @ rcr_md @
> expression major, minor;
> expression ct, name;
> position fnc_expr;
> statement S1,S2,S3;
> @@
>
> <+...
> S1
> + devt = MKDEV(major,minor);
> S2
>
> // <+...
> //- MKDEV(major,minor)
> //+ devt
> // ...+>
> // S3
> ...
> - register_chrdev_region
> + register_chrdev_ids
> (
> - MKDEV(major,minor),
> + &devt,
> ct, name)
> @fnc_expr // at end of fn-call expr
> ...+>
>
>
> the above rule works on ./drivers/tty/tty_io.c as follows
>
> diff =
> --- ./drivers/tty/tty_io.c 2011-05-14 12:46:02.282840998 -0600
> +++ /tmp/cocci-output-28931-46cda0-tty_io.c 2011-05-15 01:36:23.969325500
> -0600
> @@ -3294,14 +3294,17 @@ void console_sysfs_notify(void)
> int __init tty_init(void)
> {
> cdev_init(&tty_cdev, &tty_fops);
> + devt = MKDEV(TTYAUX_MAJOR, 1);
> if (cdev_add(&tty_cdev, MKDEV(TTYAUX_MAJOR, 0), 1) ||
> register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0)
> panic("Couldn't register /dev/tty driver\n");
> + devt = MKDEV(TTYAUX_MAJOR, 1);
> device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 0), NULL, "tty");
> + devt = MKDEV(TTYAUX_MAJOR, 1);
>
> cdev_init(&console_cdev, &console_fops);
> if (cdev_add(&console_cdev, MKDEV(TTYAUX_MAJOR, 1), 1) ||
> - register_chrdev_region(MKDEV(TTYAUX_MAJOR, 1), 1, "/dev/console") <
> 0)
> + register_chrdev_ids(&devt, 1, "/dev/console") < 0)
> panic("Couldn't register /dev/console driver\n");
> consdev = device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 1), NULL,
> "console");
> Note: processing took 24.0s: ./drivers/tty/tty_io.c
>
> its managing to insert the devt=... code,
> but its doing so 3 times, not 2, and not where Id really like it.
> code looks legal, as S1, S2 seem to force statement boundaries.
>
> If I remove S2, which seems to force inserted initializer above where
> Id like it,
> I get more profound problem:
>
> previous modification:
> CONTEXT
> >>> devt = MKDEV(rcr_md:major, rcr_md:minor);
>
> According to environment 2:
> rcr_md.minor -> 1
> rcr_md.major -> TTYAUX_MAJOR
>
> current modification:
> CONTEXT
> >>> devt = MKDEV(rcr_md:major, rcr_md:minor);
>
> According to environment 2:
> rcr_md.minor -> 0
> rcr_md.major -> TTYAUX_MAJOR
>
> Fatal error: exception Failure("rcr_md: already tagged token:
> C code context
> File "./drivers/tty/tty_io.c", line 3296, column 32, charpos = 82361
> around = ';', whole content = cdev_init(&tty_cdev, &tty_fops);")
>
>
> Theres also that commented out block with S3.
> If uncommented, match-&-transform fails.
> Id like it to pick up the MKDEV uses in the cdev_add() calls.
>
> Also, I cant make decl-insert at top-of-scope work.
> _______________________________________________
> Cocci mailing list
> [email protected]
> http://lists.diku.dk/mailman/listinfo/cocci
> (Web access from inside DIKUs LAN only)
>
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)