On Wed, 12 Oct 2011 02:53:55 +0200, Julia Lawall <[email protected]> wrote:
On Wed, 12 Oct 2011, ben wrote:
On Wed, 12 Oct 2011 00:54:07 +0200, Julia Lawall <[email protected]> wrote:
>On Tue, 11 Oct 2011, ben wrote:
>
> >hi
> >
> >I've tried to figure out why there is a strong and unexceptional
scope of
> >coccinelle on semantic patching. Why not metaprogramming, or macro
> >preprocessor on steroids? I would be very interested in this, but
couldn't
> >find anything in the docs. And maybe I'm completely on the wrong
trail
> >here,
> >because one problem I see is extending the syntax would mean to
> >(mis)reinterpret C's syntax since coccinelle 'just' understand C.
> >But as little stupid regex hacker I'm impressed by the possibility
to leave
> >the rather line oriented approach and going deep into a construct and
> >programmatically rearrange evey token I want. And so I'm a little
obsessed
> >by
> >the idea that coccinelle can make data out of c code and give me a
> >powerfull
> >macro system.
>
>Perhaps you could explain a little more concretely what you would like
to
>do?
>
>julia
A poor example: Nested Functions
// The source: not ansi c
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ nested.pseudoc ~~~~~~~~
void foo(void){
void bar(void){
}
}
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// This is a embarrassing non-working attempt
~ ~ ~ ~ ~ ~ ~ ~ ~ poor.cocci ~~~~~~~~~~~~~~~
@@
identifier fnout;
identifier fnin;
@@
fnout(...) {
...
- fnin();
}
+ fnin();
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~
// This should be the end result
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ lamesimulation.c ~~~~~~
void bar(void){
}
void foo(void){
void bar(void);
bar();
}
void bar(void){
}
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Probably you find this stupid on multiple levels.
1. trying to force coccinelle to parse uncorrect c source code
2. trying to poorly simulate constructs from other languages in the
target
code.
3. ...
But still, I'm somehow fascinated by this...
Is this possible, to write such a patch?
Coccinelle tries to parse both the source code and the generated code, so
it makes an effort to prevent what you are trying to do. But it is
possible to do some of these things, eg nested functions, by exploiting
the fact that you can use python or ocaml to create identifiers. You can
see examples of how to do this in the demos directory in the files
pythontococci.cocci and ocamltococci.cocci. Then you can make an
identifier that has an extremely strange name, eg a name that looks just
like a function header or that looks like a close brace. On the other
hand, you have to use this identifier in a legitimate context. It may be
useful to make the identifier end in //. Then you can put the
"statement"
strangeidentifier;
and even the semicolon won't be in the way.
On the other hand, an identifier followed by a semicolon isn't a
legitimate toplevel term, so ths doesn't help for adding a function call
outside any function definition.
julia
Thank you for this explanations. I try to comprehend what you are saying,
I try to read every documentation I can find (wiki still down though). But
I don't get it:
- generated code:
"Coccinelle tries to parse both the source code and the generated code"
What is the generated code? The diff file?
- identifiers:
" by exploiting the fact that you can use python or ocaml to create
identifiers"
I dont get this, identifiers are a core concept of spml - no? Do you mean
identifier metavariables?
- spml identifier vs. source identifier:
"Then you can make an identifier that has an extremely strange name, eg a
name that looks just like a function header or that looks like a close
brace. [...]"
As far as I understand identifiers in spml are abstract from names. Are
you talking about setting a somekind of signal word into the c source code?
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)