More precise distinction of types for source code searches?
Hello,
The semantic patch language supports metavariables.
It can occur then that a source code search should be performed for items which should be different while they belong still to the same data type. (If these items would be identical, the software situation would provide opportunities to simplify corresponding source code.)
The expected difference can trigger the need to express this detail by the usage of two identifiers based on the same metavariable type.
SmPL script example:
@display@
constant c1, c2;
identifier x;
@@
x =
* c1
;
x =
* c2
;
Source file example:
int main(void)
{
int x;
x = 1;
x = 0;
return x;
}
The used constants are integers and additional properties can be expressed for such numbers. These properties can eventually handled with scripted SmPL constraints.
But I have got the impression that other metavariable types provide even more software development challenges for safe distinction of relevant items.
I would like to point the detail out once more that also these metavariables can be of the same kind then with the consequence that it is not guaranteed that such metavariables will only match different source code. The support for the introduction of additional subtypes on demand might be too limited by the evolving software.
How do you think about this use case?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 2 lines
The expected difference can trigger the need to express this detail by the usage of two identifiers based on the same metavariable type.
I guess that this wording should be clarified a bit more according to the current software development status around the semantic patch language. A selection of different metavariable types is supported already.
https://github.com/coccinelle/coccinelle/blob/c6d7554edf7c4654aeae4d33c3f040e300682f23/docs/manual/cocci_syntax.tex#L199
So it seems to be occasionally appropriate to use metavariables with the same type while different names are chosen then for the corresponding variable declaration.
Another SmPL script example:
@test@
constant c1, c2;
@@
x =
* c1
;
x =
* c2
;
Such a source code search specification is too generic so far when you would really like to determine if these assignments (or its elements) are equivalent or even identical (or not).
I am looking again for possibilities to improve language distinctions here.
* How can a single metavariable remember a mapping to a previous instance from its type?
* How will it become possible to match only a subset of a known base type?
* How often do you want to exclude something because of a previous match with a similar type?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 13 lines · Markus Elfring
Quoted 2 lines
The expected difference can trigger the need to express this detail by the usage of two identifiers based on the same metavariable type.
I guess that this wording should be clarified a bit more according to the current software development status around the semantic patch language. A selection of different metavariable types is supported already.
https://github.com/coccinelle/coccinelle/blob/c6d7554edf7c4654aeae4d33c3f040e300682f23/docs/manual/cocci_syntax.tex#L199So it seems to be occasionally appropriate to use metavariables with the same type while different names are chosen then for the corresponding variable declaration.
Quoted 10 lines
Another SmPL script example:
@test@
constant c1, c2;
@@
x =
* c1
;
x =
* c2
;
@@
expression x;
constant c1,c2;
@@
x = c1;
(
x = c1;
|
*x = c2;
)
julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 11 lines
@@
expression x;
constant c1,c2;
@@x = c1;
(
x = c1;
|
*x = c2;
)
Thanks for your suggestion of the possible usage of a SmPL disjunction.
* Does it indicate a search attempt to match the first assignment statement twice (for the implementation of exclusion of duplicate source code)?
* How many implementation details will become relevant for the corresponding documentation of the Coccinelle software?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 6 lines
@@
expression x;
constant c1,c2;
@@x = c1;
The SmPL manual contains the promising wording “As metavariables are bound and inherited across rules, …”.
https://github.com/coccinelle/coccinelle/blob/c6d7554edf7c4654aeae4d33c3f040e300682f23/docs/manual/cocci_syntax.tex#L179
The mentioned binding and inheritance can still become clearer.
I guess that the Coccinelle software constructs corresponding internal data structures. The application experience shows that specific matched values can be directly reused in subsequent SmPL rules already.
Quoted 2 lines
(
x = c1;
Can it make sense then to support the direct access to a matched item also as a constraint within the same SmPL rule?
How do you think about to work with backreferences to known data for further checking (or exclusion) of such source code?
Quoted 3 lines
|
*x = c2;
)
Will any SmPL constraint extensions result in the consequence to construct a special metavariable type?
Will the software situation evolve further around the usage of such SmPL disjunctions?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci