cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] Searching for constants between shift operators with SmPL
@ 2018-06-17 17:09 SF Markus Elfring
  2018-06-17 17:51 ` Julia Lawall
  0 siblings, 1 reply; 7+ messages in thread
From: SF Markus Elfring @ 2018-06-17 17:09 UTC (permalink / raw)
  To: cocci

Hello,

The following script for the semantic patch language can mark a bit of source
code also in a corresponding example.


@display@
constant C;
expression A, B;
identifier X;
type T;
@@
 T X = A
 <<
*C
 <<
 B;


int main(void)
{
unsigned int a = 2, b = 4;
unsigned long c = a << 2 << b;
}


1. I get the error message ?minus: parse error? after the addition of
   a SmPL ellipsis behind the metavariable ?B?.

2. I have observed that no source code is found if I omit the metavariables ?T?
   and ?X? (omission of the assignment target) in a SmPL script variant.


How do you think about to clarify these software situations any more?

Regards,
Markus

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

* [Cocci] Searching for constants between shift operators with SmPL
  2018-06-17 17:09 [Cocci] Searching for constants between shift operators with SmPL SF Markus Elfring
@ 2018-06-17 17:51 ` Julia Lawall
       [not found]   ` <ae26a5be-ba96-cf08-c3cb-cced3c04f44d@users.sourceforge.net>
  0 siblings, 1 reply; 7+ messages in thread
From: Julia Lawall @ 2018-06-17 17:51 UTC (permalink / raw)
  To: cocci



On Sun, 17 Jun 2018, SF Markus Elfring wrote:

> Hello,
>
> The following script for the semantic patch language can mark a bit of source
> code also in a corresponding example.
>
>
> @display@
> constant C;
> expression A, B;
> identifier X;
> type T;
> @@
>  T X = A
>  <<
> *C
>  <<
>  B;
>
>
> int main(void)
> {
> unsigned int a = 2, b = 4;
> unsigned long c = a << 2 << b;
> }
>
>
> 1. I get the error message ?minus: parse error? after the addition of
>    a SmPL ellipsis behind the metavariable ?B?.

You can't just put ... at random places.  If you are in an expression, ...
must replace a single expression.

> 2. I have observed that no source code is found if I omit the metavariables ?T?
>    and ?X? (omission of the assignment target) in a SmPL script variant.

Since I don't know anythign about the code you are applying it to, and I
don't know the exact definition of the semantic patch, I can't answer the
question.

julia

>
> How do you think about to clarify these software situations any more?
>
> Regards,
> Markus
> _______________________________________________
> Cocci mailing list
> Cocci at systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>

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

* [Cocci] Searching for constants between shift operators with SmPL
       [not found]   ` <ae26a5be-ba96-cf08-c3cb-cced3c04f44d@users.sourceforge.net>
@ 2018-06-17 18:40     ` Julia Lawall
       [not found]       ` <4179275b-eafb-7622-2f92-06a4b0b1b39e@users.sourceforge.net>
  0 siblings, 1 reply; 7+ messages in thread
From: Julia Lawall @ 2018-06-17 18:40 UTC (permalink / raw)
  To: cocci



On Sun, 17 Jun 2018, SF Markus Elfring wrote:

> > You can't just put ... at random places.
>
> I hope that this software aspect can be adjusted somehow.

No.

>
> > If you are in an expression, ... must replace a single expression.
>
> Can it be optional at the end?

I don't know what "it" refers to, but the answer is surely no.

>
> >> 2. I have observed that no source code is found if I omit the metavariables ?T?
> >>    and ?X? (omission of the assignment target) in a SmPL script variant.
> >
> > Since I don't know anythign about the code you are applying it to,
>
> Please look once more at the constructed example.
>
> int main(void)
> {
> unsigned int a = 2, b = 4;
> unsigned long c = a << 2 << b;
> }
>
>
> > and I don't know the exact definition of the semantic patch,
>
> Can the following SmPL search approach trigger further software development considerations?
>
> @display@
> constant C;
> expression A, B;
> @@
>  A
>  <<
> *C
>  <<
>  B ...;
>
>
> This SmPL script variant does not present the error message ?minus:
> parse error?.

That's true.  You have an expression followed by ... followed by an empty
statement.  It will match things like:

foo = x << 12 << b;
test();
test();
;

It doesn't match your sample program.

julia

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

* [Cocci] Searching for constants between shift operators with SmPL
       [not found]       ` <4179275b-eafb-7622-2f92-06a4b0b1b39e@users.sourceforge.net>
@ 2018-06-17 19:10         ` Julia Lawall
       [not found]           ` <a2f0f632-d84d-379c-8386-0acbace4eae0@users.sourceforge.net>
  0 siblings, 1 reply; 7+ messages in thread
From: Julia Lawall @ 2018-06-17 19:10 UTC (permalink / raw)
  To: cocci

> The following file combination produces another usable search result.
>
> @display@
> constant C;
> expression A, B;
> identifier X;
> type T;
> @@
>  T X = A
>  <<
> *C
>  <<
>  B + ...;

Yes, because now ... is replacing an expression.

> Should anything be found in the following source code variant then?
>
> int main(void)
> {
> unsigned int a = 2, b = 4;
> unsigned long c = a << 2 << b;
> return c;
> }

No, because there is no empty statement to match the final ;.  The ...
matches a complete statement (in general, 0 or more complete statements).
It doesn't match return c

julia

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

* [Cocci] Searching for constants between shift operators with SmPL
       [not found]           ` <a2f0f632-d84d-379c-8386-0acbace4eae0@users.sourceforge.net>
@ 2018-06-17 19:24             ` Julia Lawall
       [not found]               ` <7d9d3e4f-c789-538e-f4eb-beb1462d8ba0@users.sourceforge.net>
  0 siblings, 1 reply; 7+ messages in thread
From: Julia Lawall @ 2018-06-17 19:24 UTC (permalink / raw)
  To: cocci



On Sun, 17 Jun 2018, SF Markus Elfring wrote:

> >> Should anything be found in the following source code variant then?
> >>
> >> int main(void)
> >> {
> >> unsigned int a = 2, b = 4;
> >> unsigned long c = a << 2 << b;
> >> return c;
> >> }
> >
> > No, because there is no empty statement to match the final ;.
>
> Where do you expect that such an empty statement would occur here?

Because your rule contained ...; which is a ... followed by an empty
statement.

> > The ... matches a complete statement (in general, 0 or more complete statements).
> > It doesn't match return c
>
> Is this line also a complete statement?

No.  return c is not a complete statement.  return c; is, but then there
is nothing to match the ;

>
> I am struggling still with the presented interpretations if the SmPL ellipsis
> should match an expression or/and statements.

If it is in the middle of an expression, it matches a single expression.
If it is elsewhere it matches a sequence of 0 or more statements.  It can
also match eg a sequence of 0 or more field declarations in a structure
declaration or 0 or more parameters in a function header.

julia

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

* [Cocci] Searching for constants between shift operators with SmPL
       [not found]               ` <7d9d3e4f-c789-538e-f4eb-beb1462d8ba0@users.sourceforge.net>
@ 2018-06-17 19:53                 ` Julia Lawall
       [not found]                   ` <fb10378d-dccb-73ed-ddf0-e62d1c181794@users.sourceforge.net>
  0 siblings, 1 reply; 7+ messages in thread
From: Julia Lawall @ 2018-06-17 19:53 UTC (permalink / raw)
  To: cocci



On Sun, 17 Jun 2018, SF Markus Elfring wrote:

> >> Where do you expect that such an empty statement would occur here?
> >
> > Because your rule contained ...;
>
> Yes.
>
>
> > which is a ... followed by an empty statement.
>
> I hoped that a semicolon could be interpreted as the closing delimiter
> for an assignment statement.

No.  That would make the parse amiguous.  While a ... can match a single
expression, to avoid ambiguity, such a ... cannot appear at the beginning
of the expression.  A way around this is to put (...);  That could match
an assignment statement, due to the paren isomorphism.  But that won#t
match return c; because return c is not an expression either.  It's simply
not a complete term.

> > return c; is,
>
> My source code example contained this line.

Yes, but you have to get the ... to match something and the ; to match
something.  If the ; matches the ; at the end of the return, then what
does the ... match?

julia

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

* [Cocci] Searching for constants between shift operators with SmPL
       [not found]                   ` <fb10378d-dccb-73ed-ddf0-e62d1c181794@users.sourceforge.net>
@ 2018-06-17 20:25                     ` Julia Lawall
  0 siblings, 0 replies; 7+ messages in thread
From: Julia Lawall @ 2018-06-17 20:25 UTC (permalink / raw)
  To: cocci



On Sun, 17 Jun 2018, SF Markus Elfring wrote:

> >> I hoped that a semicolon could be interpreted as the closing delimiter
> >> for an assignment statement.
> >
> > No.  That would make the parse amiguous.
>
> I am curious on the clarification of related ambiguity concerns.

...; could match a sequence of statements followed by an empty statement
or a single statement consisting of an expression followed by a ;.  The
parser favors the former.  The former may seem less useful than the
latter, but the constraints of a yacc like parser mean that the former has
to be the one that is chosen.

> > While a ... can match a single expression,
>
> I hoped that the SmPL ellipsis could handle also an optional continuation
> for a computation so that I do not need to express a subsequent operator.

It can't.  This is not going to change.

julia

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

end of thread, other threads:[~2018-06-17 20:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-17 17:09 [Cocci] Searching for constants between shift operators with SmPL SF Markus Elfring
2018-06-17 17:51 ` Julia Lawall
     [not found]   ` <ae26a5be-ba96-cf08-c3cb-cced3c04f44d@users.sourceforge.net>
2018-06-17 18:40     ` Julia Lawall
     [not found]       ` <4179275b-eafb-7622-2f92-06a4b0b1b39e@users.sourceforge.net>
2018-06-17 19:10         ` Julia Lawall
     [not found]           ` <a2f0f632-d84d-379c-8386-0acbace4eae0@users.sourceforge.net>
2018-06-17 19:24             ` Julia Lawall
     [not found]               ` <7d9d3e4f-c789-538e-f4eb-beb1462d8ba0@users.sourceforge.net>
2018-06-17 19:53                 ` Julia Lawall
     [not found]                   ` <fb10378d-dccb-73ed-ddf0-e62d1c181794@users.sourceforge.net>
2018-06-17 20:25                     ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).