cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] Capturing comments / whitespace with statement list?
@ 2019-02-20 19:46 Michael Stefaniuc
  2019-02-20 19:54 ` Julia Lawall
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Stefaniuc @ 2019-02-20 19:46 UTC (permalink / raw)
  To: Coccinelle

[-- Attachment #1: Type: text/plain, Size: 550 bytes --]

Hello,

is there a way to capture in a statement list the comments and empty
lines between statements?

I've got asked for scripting help to merge a ton of helper functions
into their only caller.

Of course it is trivial to do with coccinelle. But the comments and
empty lines get lost in the process:

  spatch merge.cocci -D func=foo_base merge.c > merge.diff


It is not a big issue, only about 55 functions to merge. So I can either
use the above script and add the comments and newlines back. Or copy the
stuff manually.

thanks
bye
	michael



[-- Attachment #2: merge.cocci --]
[-- Type: text/plain, Size: 173 bytes --]

@base@
identifier virtual.func;
statement list body;
type T;
@@
- T func(...) { body }


@@
identifier virtual.func;
statement list base.body;
@@
- return func(...);
+ body

[-- Attachment #3: merge.c --]
[-- Type: text/x-csrc, Size: 152 bytes --]

int foo_base(int i, int j)
{
    i++;
    /* Now increment j too */
    j++;

    return i + j;
}

int foo(int i, int j)
{
    return foo_base(i, j);
}

[-- Attachment #4: merge.diff --]
[-- Type: text/x-patch, Size: 281 bytes --]

--- /tmp/merge.c
+++ /tmp/cocci-output-18706-5610a6-merge.c
@@ -1,13 +1,8 @@
-int foo_base(int i, int j)
-{
-    i++;
-    /* Now increment j too */
-    j++;
 
-    return i + j;
-}
 
 int foo(int i, int j)
 {
-    return foo_base(i, j);
+    i++;
+    j++;
+    return i + j;
 }

[-- Attachment #5: Type: text/plain, Size: 136 bytes --]

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Cocci] Capturing comments / whitespace with statement list?
  2019-02-20 19:46 [Cocci] Capturing comments / whitespace with statement list? Michael Stefaniuc
@ 2019-02-20 19:54 ` Julia Lawall
  2019-02-20 20:04   ` Michael Stefaniuc
  2019-02-21 15:56   ` Markus Elfring
  0 siblings, 2 replies; 4+ messages in thread
From: Julia Lawall @ 2019-02-20 19:54 UTC (permalink / raw)
  To: Michael Stefaniuc; +Cc: Coccinelle



On Wed, 20 Feb 2019, Michael Stefaniuc wrote:

> Hello,
>
> is there a way to capture in a statement list the comments and empty
> lines between statements?
>
> I've got asked for scripting help to merge a ton of helper functions
> into their only caller.
>
> Of course it is trivial to do with coccinelle. But the comments and
> empty lines get lost in the process:
>
>   spatch merge.cocci -D func=foo_base merge.c > merge.diff
>
>
> It is not a big issue, only about 55 functions to merge. So I can either
> use the above script and add the comments and newlines back. Or copy the
> stuff manually.

Metavariables lose all of their whitespace and comments, so that that they
can be unified against other instances that have different whitespace and
comments.  Perhaps dropping the information could be delayed until the
metavariable needs to be compared against another one, but that doesn't
seem to be what is done at the moment.

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Cocci] Capturing comments / whitespace with statement list?
  2019-02-20 19:54 ` Julia Lawall
@ 2019-02-20 20:04   ` Michael Stefaniuc
  2019-02-21 15:56   ` Markus Elfring
  1 sibling, 0 replies; 4+ messages in thread
From: Michael Stefaniuc @ 2019-02-20 20:04 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Coccinelle

On 2/20/19 8:54 PM, Julia Lawall wrote:
> 
> 
> On Wed, 20 Feb 2019, Michael Stefaniuc wrote:
> 
>> Hello,
>>
>> is there a way to capture in a statement list the comments and empty
>> lines between statements?
>>
>> I've got asked for scripting help to merge a ton of helper functions
>> into their only caller.
>>
>> Of course it is trivial to do with coccinelle. But the comments and
>> empty lines get lost in the process:
>>
>>   spatch merge.cocci -D func=foo_base merge.c > merge.diff
>>
>>
>> It is not a big issue, only about 55 functions to merge. So I can either
>> use the above script and add the comments and newlines back. Or copy the
>> stuff manually.
> 
> Metavariables lose all of their whitespace and comments, so that that they
> can be unified against other instances that have different whitespace and
> comments.  Perhaps dropping the information could be delayed until the
> metavariable needs to be compared against another one, but that doesn't
> seem to be what is done at the moment.
Yeah, assumed there is a technical reason for this.
Not a problem as manually moving the code isn't the hard part / tedious
part. There are more transformations to be done on the moved code but
that is standard coccinelle work.

Thanks anyway
bye
	michael
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Cocci] Capturing comments / whitespace with statement list?
  2019-02-20 19:54 ` Julia Lawall
  2019-02-20 20:04   ` Michael Stefaniuc
@ 2019-02-21 15:56   ` Markus Elfring
  1 sibling, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2019-02-21 15:56 UTC (permalink / raw)
  To: cocci

> Metavariables lose all of their whitespace and comments,

Would you like to reconsider such details because of information from
the documentation?

“Coccinelle is a tool to help automate repetitive source-to-source
style-preserving program transformations on C source code, like for instance
to perform some refactorings.”
https://github.com/coccinelle/coccinelle/blob/848f85e256516330c06f5fd8dc782b854ed9aa03/docs/manual/introduction.tex#L4


> so that they can be unified against other instances that have different
> whitespace and comments.

The involved abstraction levels influence the software situation considerably.


> Perhaps dropping the information could be delayed until the metavariable
> needs to be compared against another one, but that doesn't seem to be
> what is done at the moment.

I am curious on how the motivation will evolve for corresponding imaginations
and change possibilities.
Would you like to take another look at a feature request like “Add a metavariable
for the handling of source code”?
https://github.com/coccinelle/coccinelle/issues/140

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-02-21 15:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-20 19:46 [Cocci] Capturing comments / whitespace with statement list? Michael Stefaniuc
2019-02-20 19:54 ` Julia Lawall
2019-02-20 20:04   ` Michael Stefaniuc
2019-02-21 15:56   ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).