Skip to contentSkip to conversation

Extending handling of position information for SmPL

cocci Markus Elfring 2 participants 13 messages Feb 10, 2024 – Feb 11, 2024

lore
Share & tools
lore
#0 lore raw

Hello,

Source code positions can be determined also by the means of the semantic patch language. I would occasionally like to benefit a bit more from this functionality.

The SmPL manual provides the following information so far:
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/4965f42eb94d2d67f7375c66b268997457cbcefb/docs/manual/cocci_syntax.tex#L411
“…
A position metavariable is used by attaching it using @ to any token, including another metavariable.
…”

Such a description is fine for the initial determination.
But I suggest to reconsider data processing consequences after a corresponding variable assignment was performed.
Addiional data became available. Thus I imagine that it would be more succinct to use these data at subsequent places in SmPL code by the following features:

1. Another character could indicate the direct reuse of a position metavariable so that the identifier for a companion position metavariable does not need to be repeated any more.

2. Another metavariable type (like “positioned”?) could indicate that known data should be applied once more.

How do you think about to extend the Coccinelle software here?

Regards,
Markus

#1 lore raw
Quoted 22 lines · Markus Elfring

Hello,

Source code positions can be determined also by the means of the semantic patch language. I would occasionally like to benefit a bit more from this functionality.

The SmPL manual provides the following information so far:
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/4965f42eb94d2d67f7375c66b268997457cbcefb/docs/manual/cocci_syntax.tex#L411
“…
A position metavariable is used by attaching it using @ to any token, including another metavariable.
…”

Such a description is fine for the initial determination.
But I suggest to reconsider data processing consequences after a corresponding variable assignment was performed.
Addiional data became available. Thus I imagine that it would be more succinct to use these data at subsequent places in SmPL code by the following features:

1. Another character could indicate the direct reuse of a position metavariable so that the identifier for a companion position metavariable does not need to be repeated any more.

Quoted 5 lines

2. Another metavariable type (like “positioned”?) could indicate that known data should be applied once more.

How do you think about to extend the Coccinelle software here?

I can never really understand what you are asking for. Please include a concrete example. A priori, I don't see any need for changing the way in which matching of metavariables is expressed.

julia

#2 lore raw
Quoted 1 line

I can never really understand what you are asking for.

I find such communication difficulties interesting somehow.

Quoted 1 line

Please include a concrete example.

Can the presented idea be clarified also without extra SmPL code (at the moment)?

Quoted 2 lines

A priori, I don't see any need for changing the way in which matching of metavariables is expressed.

An improved software documentation can probably help also with a better understanding.

* Do we distinguish anyhow if a (position) metavariable was initialised by a script?

* May further uses be considered (besides variable inheritance) in SmPL code?

* Can a position metavariable be reused in the same SmPL rule?

Regards,
Markus

#3 lore raw
Quoted 9 lines · Markus Elfring
Quoted 1 line

I can never really understand what you are asking for.

I find such communication difficulties interesting somehow.

Quoted 1 line

Please include a concrete example.

Can the presented idea be clarified also without extra SmPL code (at the moment)?

No. If you want some feature, a bare minimum is that you can illustrate some use case for it.

Quoted 10 lines
Quoted 4 lines

A priori, I don't see any need for changing the way in which matching of metavariables is expressed.

An improved software documentation can probably help also with a better understanding.

* Do we distinguish anyhow if a (position) metavariable was initialised by a script?

No.

Quoted 2 lines

* May further uses be considered (besides variable inheritance) in SmPL code?

No idea what this means.

Quoted 2 lines

* Can a position metavariable be reused in the same SmPL rule?

Yes.

julia

Quoted 5 lines

Regards,
Markus

#4 lore raw
Quoted 3 lines
Quoted 1 line

* Can a position metavariable be reused in the same SmPL rule?

Yes.

Such a variable was assigned (or do you prefer the wording “was bound”?) somewhere in a SmPL rule.
How would later SmPL code refer to the previous variable name without repeating a companion metavariable identifier?

Regards,
Markus

#5 lore raw
Quoted 8 lines · Markus Elfring
Quoted 3 lines
Quoted 1 line

* Can a position metavariable be reused in the same SmPL rule?

Yes.

Such a variable was assigned (or do you prefer the wording “was bound”?) somewhere in a SmPL rule.
How would later SmPL code refer to the previous variable name without repeating a companion metavariable identifier?

I don't understand how you plan to use something without referring to it.

julia

#6 lore raw
Quoted 4 lines
Quoted 2 lines

How would later SmPL code refer to the previous variable name without repeating a companion metavariable identifier?

I don't understand how you plan to use something without referring to it.

It is described in the SmPL manual that the character “@” can connect a metavariable with a new source code position, isn't?

If you would like to support references for already assigned/bound position metavariables, you probably need an alternative notation for the specification of corresponding identifiers.

Regards,
Markus

#7 lore raw
Quoted 10 lines · Markus Elfring
Quoted 4 lines
Quoted 2 lines

How would later SmPL code refer to the previous variable name without repeating a companion metavariable identifier?

I don't understand how you plan to use something without referring to it.

It is described in the SmPL manual that the character “@” can connect a metavariable with a new source code position, isn't?

If you would like to support references for already assigned/bound position metavariables, you probably need an alternative notation for the specification of corresponding identifiers.

It's already supported and there is no need for a different notation.

Just like for any other metavariables. For example, if x is a metavariable, you can say f(x,x) with no special notation for either of them.

julia

#8 lore raw
Quoted 7 lines
Quoted 2 lines

If you would like to support references for already assigned/bound position metavariables, you probably need an alternative notation for the specification of corresponding identifiers.

It's already supported and there is no need for a different notation.

Just like for any other metavariables. For example, if x is a metavariable, you can say f(x,x) with no special notation for either of them.

Are there further constraints to consider if they would refer to source code positions next to each other?

Regards,
Markus

#9 lore raw
In reply to Julia Lawall
Quoted 2 lines

Just like for any other metavariables. For example, if x is a metavariable, you can say f(x,x) with no special notation for either of them.

How do you think about to extend corresponding advices?

@rename@
identifier f;
position x;
@@
-f
+g
(x,x)

Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> spatch --parse-cocci test1-position-20240210.cocci …
minus: parse error:
File "test1-position-20240210.cocci", line 7, column 3, charpos = 47
around = 'x',
whole content = (x,x)

Regards,
Markus

#10 lore raw
Quoted 15 lines · Markus Elfring
Quoted 2 lines

Just like for any other metavariables. For example, if x is a metavariable, you can say f(x,x) with no special notation for either of them.

How do you think about to extend corresponding advices?

@rename@
identifier f;
position x;
@@

(quoted diff) +1 -1
-f
+g
  (x,x)
Quoted 6 lines

Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> spatch --parse-cocci test1-position-20240210.cocci …
minus: parse error:
File "test1-position-20240210.cocci", line 7, column 3, charpos = 47
around = 'x',
whole content = (x,x)

I didn't mean if x was a position. For f(x,x), x should be an expression or an identifier. A position variable has to be attached to something. And anyway, there is no hope that the two arguments of a function will be in the same position.

julia

#11 lore raw

…

Quoted 7 lines
Quoted 7 lines

@rename@
identifier f;
position x;
@@

(quoted diff) +1 -1
-f
+g
  (x,x)

…

Quoted 3 lines

A position variable has to be attached to something.
And anyway, there is no hope that the two arguments of a function will be in the same position.

Would you like to offer clearer error messages for such special cases?

Regards,
Markus

#12 lore raw
Quoted 9 lines · Markus Elfring

…

Quoted 7 lines
Quoted 7 lines

@rename@
identifier f;
position x;
@@

(quoted diff) +1 -1
-f
+g
  (x,x)

…

Quoted 5 lines
Quoted 3 lines

A position variable has to be attached to something.
And anyway, there is no hope that the two arguments of a function will be in the same position.

Would you like to offer clearer error messages for such special cases?

OK