public inbox for cocci@systeme.lip6.fr
 help / color / mirror / Atom feed
From: julia.lawall@lip6.fr (Julia Lawall)
To: cocci@systeme.lip6.fr
Subject: [Cocci] Adding names to arguments in function prototypes
Date: Wed, 5 Dec 2012 10:28:24 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.02.1212051027460.2115@hadrien> (raw)
In-Reply-To: <CAACXqO_0dmB+CvJA+DgtnNcOpc2NKHdj9YK-+0uz2ur8q9Gg_A@mail.gmail.com>

Looking quickly, I think you need to inherit the parameter list length n
from one rule to the next.  In the rules after the first one, put rule1.n,
not just n.

julia

On Wed, 5 Dec 2012, H?kon L?vdal wrote:

> Hi. I want to add names to arguments in function prototypes where
> only the type is specified, e.g. adding 'i' below:
>
> -int foo(int);
> +int foo(int i);
>
>
> I have gotten it almost working like I want, but got some problem beyond
> running on the most basic input code. The following works fine:
>
> ---START---
>
> $?more abc.* parameter_wo_name.cocci
> ::::::::::::::
> abc.c
> ::::::::::::::
>
> #include "abc.h"
>
> int foo(int i)
> {
>         return i;
> }
>
> int bar(int i)
> {
>         return i;
> }
>
> int abc(int a, int b, int c)
> {
>         return a + b + c;
> }
>
> ::::::::::::::
> abc.h
> ::::::::::::::
>
> int foo(int);
> int bar(int i);
> int abc(int, int, int);
>
> ::::::::::::::
> parameter_wo_name.cocci
> ::::::::::::::
>
> /* Match function prototypes without parameter names */
> @rule1@
> identifier f;
> type T1, T2;
> parameter list[n] ps;
> position p1;
> @@
>
> T1 f at p1(ps, T2, ...);
>
> /* Match the corresponding function declaration */
> @rule2@
> type rule1.T1;
> type rule1.T2;
> identifier rule1.f;
> parameter list[n] rule1.ps;
> identifier id;
> @@
>
> T1 f(ps, T2 id, ...) {...}
>
> /* Combine information from the above two rules to add the parameter
> name to the function prototype */
> @rule3@
> type rule1.T1;
> type rule1.T2;
> identifier rule1.f;
> parameter list[n] rule1.ps;
> position rule1.p1;
> identifier rule2.id;
> @@
>
> T1 f at p1(ps, T2
> +id
> , ...);
>
> $?spatch --sp-file parameter_wo_name.cocci --recursive-includes -I
> /usr/include abc.c
> init_defs_builtins: /usr/share/coccinelle/standard.h
> HANDLING: abc.c
> a header file was modified: abc.h
> diff =
> --- ./abc.h
> +++ /tmp/cocci-output-27689-53d466-abc.h
> @@ -1,5 +1,5 @@
>
> -int foo(int);
> +int foo(int i);
>  int bar(int i);
> -int abc(int, int, int);
> +int abc(int a, int, int);
>
> $
>
> ---END---
>
>
> As can be seen only the first parameter in abc is named, but this is
> just a matter of running the script multiple times, so this is not a
> big problem (although if anyone have a solution to have it done in one
> operation, feel free to provide a solution).
>
> However, if I start using other types than int I get in trouble:
>
>
> $?more xyz.*
> ::::::::::::::
> xyz.c
> ::::::::::::::
>
> #include "xyz.h"
>
> int xyz(int x, uint8_t y, int z)
> {
>         return x + y + z;
> }
>
> ::::::::::::::
> xyz.h
> ::::::::::::::
> #include <stdint.h>
>
> int xyz(int, uint8_t, int);
>
> $?spatch --sp-file parameter_wo_name.cocci --recursive-includes -I
> /usr/include xyz.c
> init_defs_builtins: /usr/share/coccinelle/standard.h
> HANDLING: xyz.c
> (ONCE) TYPE: header gnu/stubs-32.h not found
> Fatal error: exception Failure("empty list, max_min_ii_by_pos")
> $?mkdir gnu
> $?touch gnu/stubs-32.h
> $?spatch --sp-file parameter_wo_name.cocci --recursive-includes -I
> /usr/include -I . xyz.c
> init_defs_builtins: /usr/share/coccinelle/standard.h
> HANDLING: xyz.c
> Fatal error: exception Failure("empty list, max_min_ii_by_pos")
> $
>
>
>
> Why is coccinelle failing here and how do I solve this?
>
> BR H?kon L?vdal
> _______________________________________________
> Cocci mailing list
> Cocci at systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>

  reply	other threads:[~2012-12-05  9:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-05  9:25 [Cocci] Adding names to arguments in function prototypes Håkon Løvdal
2012-12-05  9:28 ` Julia Lawall [this message]
2012-12-05  9:31   ` Håkon Løvdal
2012-12-05  9:36     ` Julia Lawall
2012-12-06 17:24       ` Christian Clausen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.02.1212051027460.2115@hadrien \
    --to=julia.lawall@lip6.fr \
    --cc=cocci@systeme.lip6.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox