Re: [Cocci] Adjusting macros with SmPL?

2019-10-15 Thread Markus Elfring
> Macros are supposed to be written on one line.

I guess that you refer to a logical source line.
https://en.cppreference.com/w/c/language/translation_phases#Phase_2

I am looking for better support around changing contents from physical text 
lines
also by the means of the semantic patch language.


> Anyway, to my understanding the goal was not to modify the #define part,
> but rather only the code part.

The following transformation approach can produce an usable result
together with another small source file example.

@replacement@
expression buffer, x;
identifier macro;
@@
-#define macro(name) snprintf(buffer, PAGE_SIZE, "%u\n", (x)->name)
+#define macro(name) spgprintf_d(buffer, (x)->name)


Regards,
Markus
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] Adjusting macros with SmPL?

2019-10-14 Thread Markus Elfring
>> I imagine that context-dependent data processing will be needed here
>> to distinguish if preprocessor code should be adjusted (or not).
>> How much will this technical aspect matter?
>
> Macros are supposed to be written on one line.

I suggest to reconsider also this view.
Would you like to take line continuations (or the escaping of line breaks)
into account?


> Anyway, to my understanding the goal was not to modify the #define part,
> but rather only the code part.

The shown transformation approach can probably be interpreted in two ways.

1. A source code modification should be performed behind a macro
   which can be empty.

2. Something should be generally adjusted. It would not matter then
   if the change is relevant (only) for preprocessor code (or not).


Regards,
Markus
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] Adjusting macros with SmPL?

2019-10-14 Thread Julia Lawall


On Mon, 14 Oct 2019, Markus Elfring wrote:

> > Changes within #define code should be supported if Coccinelle is able
> > to parse the code independently of its usage context.
>
> I suggest to take a closer look at the current software situation.
>
> @replacement@
> expression x;
> identifier macro;
> @@
>  #define macro(name)
> -snprintf
> +spgprintf_d
>  (...,
> -PAGE_SIZE, "%d\n",
>  (x)->name)
>
>
> elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-cocci 
> use_spgprintf2.cocci
> …
> minus: parse error:
>   File "use_spgprintf2.cocci", line 11, column 0, charpos = 132
>   around = '',
>   whole content =
>
>
> Can such an error message be explained better?
>
>
> I imagine that context-dependent data processing will be needed here
> to distinguish if preprocessor code should be adjusted (or not).
> How much will this technical aspect matter?

Macros are supposed to be written on one line.

Anyway, to my understanding the goal was not to modify the #define part,
but rather only the code part.

julia___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] Adjusting macros with SmPL?

2019-10-14 Thread Markus Elfring
> Changes within #define code should be supported if Coccinelle is able
> to parse the code independently of its usage context.

I suggest to take a closer look at the current software situation.

@replacement@
expression x;
identifier macro;
@@
 #define macro(name)
-snprintf
+spgprintf_d
 (...,
-PAGE_SIZE, "%d\n",
 (x)->name)


elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-cocci 
use_spgprintf2.cocci
…
minus: parse error:
  File "use_spgprintf2.cocci", line 11, column 0, charpos = 132
  around = '',
  whole content =


Can such an error message be explained better?


I imagine that context-dependent data processing will be needed here
to distinguish if preprocessor code should be adjusted (or not).
How much will this technical aspect matter?

Regards,
Markus
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] Adjusting macros with SmPL?

2019-10-13 Thread Markus Elfring
>> https://github.com/coccinelle/coccinelle/commit/5e3f73c732075f7afadf383d088f3b6d0e1345b1
>
> This seems completely irrelevant.

I got an other view also for this software area.
How many items can be assumed behind the word “etc.” in the section 
“upcoming/planned/todo”?


> The question was about #define, not about #ifdef.

Can we clarify the corresponding details better then?


> Changes within #define code should be supported if Coccinelle is able to parse
> the code independently of its usage context.

Would you like to say that the desired software support is complete here?

Regards,
Markus
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] Adjusting macros with SmPL?

2019-10-13 Thread Julia Lawall



On Sun, 13 Oct 2019, Markus Elfring wrote:

> >> Does the semantic patch language (Coccinelle software) support
> >> the adjustment of preprocessor definitions as in the shown
> >> source code example?
> >
> > Can't you find the answer to this question by yourself by trying it?
>
> My test did not show an useful patch result for the shown SmPL transformation 
> variant.
>
>
> I probably know another answer already if no other news will be contributed.
> Would you like to take another look at your commit from 2011-01-10?
> https://github.com/coccinelle/coccinelle/commit/5e3f73c732075f7afadf383d088f3b6d0e1345b1

This seems completely irrelevant.  The question was about #define, not
about #ifdef.  Changes within #define code should be supported if
Coccinelle is able to parse the code independently of its usage context.

julia
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] Adjusting macros with SmPL?

2019-10-13 Thread Markus Elfring
>> Does the semantic patch language (Coccinelle software) support
>> the adjustment of preprocessor definitions as in the shown
>> source code example?
>
> Can't you find the answer to this question by yourself by trying it?

My test did not show an useful patch result for the shown SmPL transformation 
variant.


I probably know another answer already if no other news will be contributed.
Would you like to take another look at your commit from 2011-01-10?
https://github.com/coccinelle/coccinelle/commit/5e3f73c732075f7afadf383d088f3b6d0e1345b1

Regards,
Markus
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci