On Sun, 13 Mar 2011 22:34:39 +0100 (CET)
Julia Lawall <[email protected]> wrote:

> > One more question, can I tell spatch to always expand certain macros? Or 
> > teach it any other way
> > that 
> >  CAMLlocal1(v);
> > is equivalent to
> >  value v;
> > cause otherwise it sometimes assumes (I guess) that v is a global variable 
> > and wrecks havoc when it matches
> > the name of local variable in another function.. I tried specifying it via 
> > Declaration or Statement isomorphism
> > but failed.
> 
> Create a file called macros.h and put in it
> 
> #define CAMLlocal1(v) value v

Sorry, but this doesn't seem to work. As you said in previous mail :

> The problem is that (to the 
> best of my knowledge) coccinelle only uses the definitions of macros if it 
> can't parse the code otherwise, and in your case it has no problem parsing 
> the code.

and experiment confirms this :

$ cat test.c
int main()
{
  local(v);
  v = 2;
  size_t x;
  x = 3;
}

$ cat macro.h 
#define local(z) size_t z

$ cat test.cocci
@@ idexpression size_t X; expression E; @@
 <...
- X = E;
+ X = E + 1;
 ...>

$ spatch -macro_file macro.h -sp_file test.cocci test.c
init_defs_builtins: /usr/share/coccinelle/standard.h
init_defs: macro.h
HANDLING: test.c
diff = 
--- test.c      2011-03-15 23:10:21.550112816 +0200
+++ /tmp/cocci-output-31750-9aaf83-test.c       2011-03-15 23:11:47.198114542 
+0200
@@ -3,5 +3,5 @@ int main()
   local(v);
   v = 2;
   size_t x;
-  x = 3;
+  x = 3 + 1;
 }

My understanding is that local(v) is parsed successfully as function call and 
hence macro.h is
not consulted at all. Hence my seeking to "force" coccinelle expand the macro 
before the first
parse pass..

-- 
 ygrek
 http://ygrek.org.ua/
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to