Avoiding code duplication for SmPL constraints
Hello,
Constraints can be specified for metavariables of the semantic patch language. I noticed that they can trigger software maintenance challenges when bigger specifications are repeated in some SmPL rules.
Now I am looking again for further possibilities to avoid corresponding code duplication.
* Scripted constraints might be a design option.
Unfortunately, I find the documentation for this functionality still incomplete.
* I imagine that it would nice if constraints could be set by programming script rules at a single place.
Regards,
Markus
Quoted 10 lines · SF Markus Elfring
Hello,
Constraints can be specified for metavariables of the semantic patch language. I noticed that they can trigger software maintenance challenges when bigger specifications are repeated in some SmPL rules.
Now I am looking again for further possibilities to avoid corresponding code duplication.* Scripted constraints might be a design option.
Unfortunately, I find the documentation for this functionality still incomplete.
What information do you find to be lacking?
Quoted 2 lines
* I imagine that it would nice if constraints could be set by programming script rules at a single place.
The simplest thing to do is to define a function in the initialize part of the semantic patch, and then call that function in the constraints as needed.
julia
Quoted 11 lines · SF Markus Elfring
Quoted 7 lines
Quoted 5 lines
Now I am looking again for further possibilities to avoid corresponding code duplication.
* Scripted constraints might be a design option.
Unfortunately, I find the documentation for this functionality still incomplete.What information do you find to be lacking?
I would appreciate if the place for the desired predicate will be better explained.
May they refer to a predefined function?
When you write eg
identifier x : script:python(...) { ... };
or
identifier x : script:ocaml(...) { ... };
Between the { ... } you can put any code that you could put in a python or ocaml script, respectively.
julia
[Cocci] Clarification for scripted SmPL constraints
In reply to a message not in the archiveQuoted 8 lines · SF Markus Elfring
Quoted 8 lines
Quoted 3 lines
I would appreciate if the place for the desired predicate will be better explained.
May they refer to a predefined function?
When you write eg
identifier x : script:python(...) { ... };
Quoted 8 lines
Quoted 6 lines
or
identifier x : script:ocaml(...) { ... };
Between the { ... } you can put any code that you could put in a python or ocaml script, respectively.
Which parameters should be passed to the selected function?
You can always pass the declared metavariable. You can put a comma-separated list of inherited metavariables (r.a, r.b, ...) between the parentheses, and then use a, b, etc in the script code. If there are no disjunctions in the rule and if the declared metavariable is no seprated by ... from a metavariable previously declared in the same rule, then the latter variable can be included in the () as well, with no rule name, and then used in the script code.
julia
[Cocci] Clarification for scripted SmPL constraints
Quoted 3 lines
Quoted 1 line
Which parameters should be passed to the selected function?
You can always pass the declared metavariable.
I have got special imaginations for convenient parameter passing in such an use case.
Quoted 1 line
You can put a comma-separated list of inherited metavariables
Do you suggest that a dependency on metavariable inheritance is required?
Quoted 1 line
(r.a, r.b, ...) between the parentheses, and then use a, b, etc in the script code.
I would appreciate if the needed data would be directly available for the predicate function (without repeating variable names).
Quoted 4 lines
If there are no disjunctions in the rule and if the declared metavariable is no seprated by ... from a metavariable previously declared in the same rule, then the latter variable can be included in the () as well, with no rule name, and then used in the script code.
I find this condition hard to understand at the moment.
Regards,
Markus