Skip to contentSkip to conversation

Moving a function body to an other source code place with SmPL

Cocci SF Markus Elfring 2 participants 8 messages May 14, 2018 – May 15, 2018 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

Hello,

I am curious on how good the Coccinelle software can support a specific source code transformation:
It would be occasionally nice if an implementation of a function could be completely stored into a metavariable.
Is a statement list variable appropriate for this use case?

Can these data be moved to an other function (or macro definition)?

Regards,
Markus

#1 lore raw
Quoted 7 lines · SF Markus Elfring

Hello,

I am curious on how good the Coccinelle software can support a specific source code transformation:
It would be occasionally nice if an implementation of a function could be completely stored into a metavariable.
Is a statement list variable appropriate for this use case?

Yes.

@@
identifier f;
statement list SS;
@@

f() {
SS
}

A statement list metavariable should only be used as the body of a block {}. If it is not working at the top of a function, it should be possible to fix that.

Quoted 1 line

Can these data be moved to an other function (or macro definition)?

Yes. A statement list variable can be added anywhere a list of statements is allowed, ie not necessarily as the complete body of a block.

julia

Quoted 8 lines

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

#2 lore raw
Quoted 5 lines
Quoted 3 lines

It would be occasionally nice if an implementation of a function could be completely stored into a metavariable.
Is a statement list variable appropriate for this use case?

Yes.

Thanks for your acknowledgement that it should usually work.

I have noticed a moment ago that a blank line is not marked by the SmPL asterisk operator (for a small source code example) so far.

Can such whitespace characters be also preserved there anyhow?

Quoted 4 lines
Quoted 1 line

Can these data be moved to an other function (or macro definition)?

Yes. A statement list variable can be added anywhere a list of statements is allowed, ie not necessarily as the complete body of a block.

How will the software behaviour evolve if I stumble on the message ?Fatal error: exception Coccinelle_modules.Common.Timeout? after passing the parameter ?--timeout 123? for a change attempt with a C++ source file? (Am I too impatient here?)

Regards,
Markus

#3 lore raw
Quoted 6 lines · SF Markus Elfring
Quoted 5 lines
Quoted 3 lines

It would be occasionally nice if an implementation of a function could be completely stored into a metavariable.
Is a statement list variable appropriate for this use case?

Yes.

Quoted 7 lines

Thanks for your acknowledgement that it should usually work.

I have noticed a moment ago that a blank line is not marked by the SmPL asterisk operator (for a small source code example) so far.

Can such whitespace characters be also preserved there anyhow?

No. Whitespace is never preserved in metavariables.

Quoted 11 lines
Quoted 6 lines
Quoted 3 lines

Can these data be moved to an other function (or macro definition)?

Yes. A statement list variable can be added anywhere a list of statements is allowed, ie not necessarily as the complete body of a block.

How will the software behaviour evolve if I stumble on the message ?Fatal error: exception Coccinelle_modules.Common.Timeout? after passing the parameter ?--timeout 123? for a change attempt with a C++ source file? (Am I too impatient here?)

No evolution is planned. I see no reason why matching the body of a function should intrinsically cause a timeout.

julia

#4 lore raw
Quoted 6 lines
Quoted 4 lines

I have noticed a moment ago that a blank line is not marked by the SmPL asterisk operator (for a small source code example) so far.

Can such whitespace characters be also preserved there anyhow?

No. Whitespace is never preserved in metavariables.

I guess that this aspect will trigger further software development consequences.

How should a function body be converted into a part of a macro then?

Quoted 7 lines
Quoted 4 lines

How will the software behaviour evolve if I stumble on the message ?Fatal error: exception Coccinelle_modules.Common.Timeout? after passing the parameter ?--timeout 123? for a change attempt with a C++ source file? (Am I too impatient here?)

No evolution is planned. I see no reason why matching the body of a function should intrinsically cause a timeout.

I am also unsure if the Coccinelle software can cope in an other time frame with another example file I am experimenting a bit.

Regards,
Markus

#5 lore raw
Quoted 10 lines · SF Markus Elfring
Quoted 6 lines
Quoted 4 lines

I have noticed a moment ago that a blank line is not marked by the SmPL asterisk operator (for a small source code example) so far.

Can such whitespace characters be also preserved there anyhow?

No. Whitespace is never preserved in metavariables.

I guess that this aspect will trigger further software development consequences.

How should a function body be converted into a part of a macro then?

If you want to do this, you might need to add \ at the ends of lines. You can do that in python or ocaml, treating the result as an identifier.

julia

Quoted 16 lines
Quoted 9 lines
Quoted 6 lines

How will the software behaviour evolve if I stumble on the message ?Fatal error: exception Coccinelle_modules.Common.Timeout? after passing the parameter ?--timeout 123? for a change attempt with a C++ source file? (Am I too impatient here?)

No evolution is planned. I see no reason why matching the body of a function should intrinsically cause a timeout.

I am also unsure if the Coccinelle software can cope in an other time frame with another example file I am experimenting a bit.

Regards,
Markus

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw

[Cocci] Checking the support for source code transformations with special characters

Quoted 11 lines · SF Markus Elfring
Quoted 6 lines
Quoted 4 lines

I have noticed a moment ago that a blank line is not marked by the SmPL asterisk operator (for a small source code example) so far.

Can such whitespace characters be also preserved there anyhow?

No. Whitespace is never preserved in metavariables.

How does such information fit to the following wording in the documentation?
https://github.com/coccinelle/coccinelle/blob/848f85e256516330c06f5fd8dc782b854ed9aa03/docs/manual/introduction.tex#L4

?? automate repetitive source-to-source style-preserving program transformations ??

When Coccinelle adds code, it makes an effort to conform to the indentation of the context in which the code is placed, not the context from which the code was removed. The goal is to preserve the stule of the code as a whole.

julia

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw

[Cocci] Checking data processing for statement lists

Quoted 16 lines · SF Markus Elfring
Quoted 6 lines
Quoted 4 lines

How will the software behaviour evolve if I stumble on the message ?Fatal error: exception Coccinelle_modules.Common.Timeout? after passing the parameter ?--timeout 123? for a change attempt with a C++ source file? (Am I too impatient here?)

No evolution is planned.

I suggest to reconsider such a view.

It is possible to perform some data processing with the help of the semantic patch language also on C++ source files in an acceptable time frame.

Example:
https://trac.cppcheck.net/ticket/8571

Quoted 6 lines
Quoted 2 lines

I see no reason why matching the body of a function should intrinsically cause a timeout.

I accidentally observed that the software situation can be changed in a dramatic way if a metavariable of the type ?statement list? is involved. Can the run time characteristics be considerably improved?

I don't have either semantic patch or the test data. Perhaps you sent them but without mentioning it in the message, so I didn't see it.

There is nothing about the processing of C++ that should be particularly time consuming.

julia