All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] Avoiding code duplication for SmPL constraints
@ 2018-02-17 13:34 SF Markus Elfring
  2018-02-17 13:39 ` Julia Lawall
  0 siblings, 1 reply; 5+ messages in thread
From: SF Markus Elfring @ 2018-02-17 13:34 UTC (permalink / raw)
  To: cocci

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Cocci] Avoiding code duplication for SmPL constraints
  2018-02-17 13:34 [Cocci] Avoiding code duplication for SmPL constraints SF Markus Elfring
@ 2018-02-17 13:39 ` Julia Lawall
       [not found]   ` <388d5af8-d3e4-ee18-7481-3675e2b52024@users.sourceforge.net>
  0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2018-02-17 13:39 UTC (permalink / raw)
  To: cocci



On Sat, 17 Feb 2018, SF Markus Elfring wrote:

> 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?

> * 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Cocci] Avoiding code duplication for SmPL constraints
       [not found]   ` <388d5af8-d3e4-ee18-7481-3675e2b52024@users.sourceforge.net>
@ 2018-02-17 14:11     ` Julia Lawall
       [not found]       ` <9d550db4-cad4-f625-32da-173078fdde54@users.sourceforge.net>
  0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2018-02-17 14:11 UTC (permalink / raw)
  To: cocci



On Sat, 17 Feb 2018, SF Markus Elfring wrote:

> >> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Cocci] Clarification for scripted SmPL constraints
       [not found]       ` <9d550db4-cad4-f625-32da-173078fdde54@users.sourceforge.net>
@ 2018-02-17 14:34         ` Julia Lawall
  2018-02-17 14:54           ` SF Markus Elfring
  0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2018-02-17 14:34 UTC (permalink / raw)
  To: cocci



On Sat, 17 Feb 2018, SF Markus Elfring wrote:

> >> 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.
>
> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Cocci] Clarification for scripted SmPL constraints
  2018-02-17 14:34         ` [Cocci] Clarification for scripted " Julia Lawall
@ 2018-02-17 14:54           ` SF Markus Elfring
  0 siblings, 0 replies; 5+ messages in thread
From: SF Markus Elfring @ 2018-02-17 14:54 UTC (permalink / raw)
  To: cocci

>> 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.


> You can put a comma-separated list of inherited metavariables

Do you suggest that a dependency on metavariable inheritance is required?


> (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).


> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-02-17 14:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-17 13:34 [Cocci] Avoiding code duplication for SmPL constraints SF Markus Elfring
2018-02-17 13:39 ` Julia Lawall
     [not found]   ` <388d5af8-d3e4-ee18-7481-3675e2b52024@users.sourceforge.net>
2018-02-17 14:11     ` Julia Lawall
     [not found]       ` <9d550db4-cad4-f625-32da-173078fdde54@users.sourceforge.net>
2018-02-17 14:34         ` [Cocci] Clarification for scripted " Julia Lawall
2018-02-17 14:54           ` SF Markus Elfring

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.