Skip to contentSkip to conversation

Converting variable initialisations to later assignments

Cocci Markus Elfring 2 participants 9 messages May 24, 2020 – May 25, 2020

lore
Share & tools
lore
#0 lore raw
Quoted 2 lines
Quoted 2 lines

I am trying to move local variable initialization of some variable to first statement. …

I find such a source code transformation task also interesting.
But it points some software development challenges out also for the safe application of the semantic patch language for this use case.

Quoted 1 line

put \(<+...a...+>\&E\) in place of E

How do you think about the following SmPL script variant?

@movement@
expression E;
identifier V1, V2, Vx;
statement S;
type T1, T2;
@@
T1 V1;
... when any
T2 V2
- = \( <+... Vx ...+> \& E \)
;
... when any

     when != S

++ V2 = E;

elfring@Sonne:~/Projekte/Coccinelle/janitor> spatch --parse-cocci convert_variable_initialisation_to_assignment.cocci …
plus: parse error:
File "convert_variable_initialisation_to_assignment.cocci", line 10, column 9, charpos = 117 around = '\(',
whole content = - = \( <+... Vx ...+> \& E \)

I have tried another SmPL code variation out then.

-T2 V2 = \( <+... Vx ...+> \& E \)
+T2 V2
;

elfring@Sonne:~/Projekte/Coccinelle/janitor> spatch --parse-cocci convert_variable_initialisation_to_assignment2.cocci …
14: no available token to attach to

How will the software evolution be continued here?

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#1 lore raw
Quoted 12 lines · Markus Elfring
Quoted 2 lines
Quoted 2 lines

I am trying to move local variable initialization of some variable to first statement. …

I find such a source code transformation task also interesting.
But it points some software development challenges out also for the safe application of the semantic patch language for this use case.

Quoted 1 line

put \(<+...a...+>\&E\) in place of E

How do you think about the following SmPL script variant?

Quoted 10 lines

@movement@
expression E;
identifier V1, V2, Vx;
statement S;
type T1, T2;
@@
T1 V1;
... when any
T2 V2
- = \( <+... Vx ...+> \& E \)

What is Vx for? He wants an expression that involves a.

Quoted 4 lines

;
... when any

     when != S

++ V2 = E;

What do you expect this code to be added on to?

julia

Quoted 20 lines

elfring@Sonne:~/Projekte/Coccinelle/janitor> spatch --parse-cocci convert_variable_initialisation_to_assignment.cocci …
plus: parse error:
File "convert_variable_initialisation_to_assignment.cocci", line 10, column 9, charpos = 117 around = '\(',
whole content = - = \( <+... Vx ...+> \& E \)

I have tried another SmPL code variation out then.

(quoted diff) +1 -1
-T2 V2 = \( <+... Vx ...+> \& E \)
+T2 V2
 ;

elfring@Sonne:~/Projekte/Coccinelle/janitor> spatch --parse-cocci convert_variable_initialisation_to_assignment2.cocci …
14: no available token to attach to

Quoted 5 lines

How will the software evolution be continued here?

Regards,
Markus

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#2 lore raw
Quoted 11 lines
Quoted 10 lines

@movement@
expression E;
identifier V1, V2, Vx;
statement S;
type T1, T2;
@@
T1 V1;
... when any
T2 V2
- = \( <+... Vx ...+> \& E \)

Quoted 1 line

What is Vx for? He wants an expression that involves a.

I chose a slightly more unique metavariable identifier for the desired clarification of this use case.

a ⇔ Vx
(Or should the identifier “V1” be used instead?)

Quoted 6 lines
Quoted 4 lines

;
... when any

     when != S

++ V2 = E;

What do you expect this code to be added on to?

I imagine that we would like to determine the end of the code block for variable declarations somehow.

Quoted 10 lines
Quoted 10 lines

elfring@Sonne:~/Projekte/Coccinelle/janitor> spatch --parse-cocci convert_variable_initialisation_to_assignment.cocci …
plus: parse error:
File "convert_variable_initialisation_to_assignment.cocci", line 10, column 9, charpos = 117 around = '\(',
whole content = - = \( <+... Vx ...+> \& E \)

I have tried another SmPL code variation out then.

Quoted 7 lines
Quoted 7 lines
(quoted diff) +1 -1
-T2 V2 = \( <+... Vx ...+> \& E \)
+T2 V2
 ;

elfring@Sonne:~/Projekte/Coccinelle/janitor> spatch --parse-cocci convert_variable_initialisation_to_assignment2.cocci …
14: no available token to attach to

Will the mentioned error messages get any more attention?

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#3 lore raw
Quoted 11 lines · Markus Elfring
Quoted 11 lines
Quoted 10 lines

@movement@
expression E;
identifier V1, V2, Vx;
statement S;
type T1, T2;
@@
T1 V1;
... when any
T2 V2
- = \( <+... Vx ...+> \& E \)

Quoted 7 lines
Quoted 1 line

What is Vx for? He wants an expression that involves a.

I chose a slightly more unique metavariable identifier for the desired clarification of this use case.

a ⇔ Vx
(Or should the identifier “V1” be used instead?)

Vx is not bound to anything. It will match any identifier.

Quoted 27 lines
Quoted 8 lines
Quoted 6 lines

;
... when any

     when != S

++ V2 = E;

What do you expect this code to be added on to?

I imagine that we would like to determine the end of the code block for variable declarations somehow.

Quoted 14 lines
Quoted 14 lines

elfring@Sonne:~/Projekte/Coccinelle/janitor> spatch --parse-cocci convert_variable_initialisation_to_assignment.cocci …
plus: parse error:
File "convert_variable_initialisation_to_assignment.cocci", line 10, column 9, charpos = 117 around = '\(',
whole content = - = \( <+... Vx ...+> \& E \)

I have tried another SmPL code variation out then.

(quoted diff) +1 -1
-T2 V2 = \( <+... Vx ...+> \& E \)
+T2 V2
 ;
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines

elfring@Sonne:~/Projekte/Coccinelle/janitor> spatch --parse-cocci convert_variable_initialisation_to_assignment2.cocci …
14: no available token to attach to

Will the mentioned error messages get any more attention?

I already asked above what you expected the ++ code to be attached to. All added code has to be attached to something.

julia

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#4 lore raw
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 10 lines

@movement@
expression E;
identifier V1, V2, Vx;
statement S;
type T1, T2;
@@
T1 V1;
... when any
T2 V2
- = \( <+... Vx ...+> \& E \)

What is Vx for? He wants an expression that involves a.

Quoted 7 lines
Quoted 5 lines

I chose a slightly more unique metavariable identifier for the desired clarification of this use case.

a ⇔ Vx
(Or should the identifier “V1” be used instead?)

Vx is not bound to anything.

This interpretation might be appropriate.

Quoted 1 line

It will match any identifier.

Should the desired “binding” work with the variable name “V1” (or “a”) finally?

Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

;
... when any

     when != S

++ V2 = E;

What do you expect this code to be added on to?

I imagine that we would like to determine the end of the code block for variable declarations somehow.

…

Quoted 2 lines

I already asked above what you expected the ++ code to be attached to. All added code has to be attached to something.

The shown simple SmPL exclusion specification for statements can be replaced also with a better source code search approach.

Would you recommend to exclude declarations (and/or definitions) of C variables by any other means?
(Is more SmPL code needed for this purpose?)

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#5 lore raw
In reply to Julia Lawall
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

;
... when any

     when != S

++ V2 = E;

…

Quoted 2 lines

I already asked above what you expected the ++ code to be attached to. All added code has to be attached to something.

Can the connection to the desired source code position be achieved also by the application of the SmPL ellipsis together with code exclusions?

Does the Coccinelle software expect a more explicit place selection so far?

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

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

;
... when any

     when != S

++ V2 = E;

…

Quoted 2 lines

I already asked above what you expected the ++ code to be attached to. All added code has to be attached to something.

Can the connection to the desired source code position be achieved also by the application of the SmPL ellipsis together with code exclusions?

No.

Quoted 2 lines

Does the Coccinelle software expect a more explicit place selection so far?

Yes.

julia

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#7 lore raw
Quoted 11 lines
Quoted 10 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

;
... when any

     when != S

++ V2 = E;

…

Quoted 2 lines

I already asked above what you expected the ++ code to be attached to. All added code has to be attached to something.

Can the connection to the desired source code position be achieved also by the application of the SmPL ellipsis together with code exclusions?

Quoted 6 lines

No.

Quoted 2 lines

Does the Coccinelle software expect a more explicit place selection so far?

Yes.

Can the chances grow to adjust such a software limitation anyhow?

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#8 lore raw
In reply to Julia Lawall
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

I already asked above what you expected the ++ code to be attached to. All added code has to be attached to something.

Can the connection to the desired source code position be achieved also by the application of the SmPL ellipsis together with code exclusions?

No.

Do you find that the following SmPL script variant can generate usable patches according to the discussed source code transformation approach?

@find@
identifier V1;
position P;
statement S1, S2;
type T1;
@@
T1 V1;
... when any

     when != S1

S2@P

@movement@
expression E;
identifier find.V1, V2;
position find.P;
statement S, find.S2;
type find.T1, T2;
@@
T1 V1;
... when any
-T2 V2 = \( <+... V1 ...+> \& E \)
+T2 V2
;
... when any

     when != S

++ V2 = E;
S2@P

Would you like to achieve any related software improvements?

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci