All of lore.kernel.org
 help / color / mirror / Atom feed
* [cocci] Space-delimted string literals
@ 2022-04-01 20:12 Eric Wheeler
  2022-04-02  8:42 ` [cocci] Checking the handling of “space-delimited” string literals by SmPL Markus Elfring
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Wheeler @ 2022-04-01 20:12 UTC (permalink / raw)
  To: cocci

I think this is a known issue, but thought I would share in case it is 
useful.  This function:

	void print_bug(char *s)               
	{                                     
	    printf(__FILE__ ": BUG: %s\n", s);
	}                                     

is not matched by this SmPL:

	@ p @               
	expression list EL; 
	constant C =~ "BUG";
	@@                  
	-printf(C, EL);     
	+BUG(C, EL);        

but without __FILE__ it matches:

	void print_bug(char *s)               
	{                                     
	    printf(": BUG: %s\n", s);
	}                                     

I've tried to do something like this, but it is invalid SmPL:

	@ p @               
	expression list EL; 
	constant FOO, C =~ "BUG";
	@@                  
	-printf(FOO C, EL);     
	+BUG(C, EL);        

and produces this error:
	minus: parse error: 
	  File "cocci/constant-issue", line 5, column 12, charpos = 68
	  around = 'C',
	  whole content = -printf(FOO C, EL);

This isn't a critical issue in my case, only a few replacements, but 
string literal handling in SmPL might benefit other users.

Consider a grammar like this:

	literal := literal | literal literal

Maybe the definition is a but too recursive, but you can see what I'm 
trying to express.  Maybe keep it as a "constant" or perhaps introduce a 
new SmPL metavar type called "literal" or "string".

Considerations if "a" "b" "c" were being matched:

1. Specify A B C metavars and get the string in each as you would expect.
2. Specify just A and get all of them in A
3. Specify A B and A gets the first and B gets the tail as "b" "c".

Just ideas, I'm open to whatever you think is best for the project.

--
Eric Wheeler

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

* Re: [cocci] Checking the handling of “space-delimited” string literals by SmPL
  2022-04-01 20:12 [cocci] Space-delimted string literals Eric Wheeler
@ 2022-04-02  8:42 ` Markus Elfring
  2022-04-03  0:25   ` Eric Wheeler
  0 siblings, 1 reply; 4+ messages in thread
From: Markus Elfring @ 2022-04-02  8:42 UTC (permalink / raw)
  To: Eric Wheeler; +Cc: cocci

> I've tried to do something like this, but it is invalid SmPL:
>
> 	@ p @
> 	expression list EL;
> 	constant FOO, C =~ "BUG";
> 	@@
> 	-printf(FOO C, EL);
> 	+BUG(C, EL);


Thanks for your interest in software adjustments also for this area.



> Just ideas, I'm open to whatever you think is best for the project.


How do you think about to influence the evolution any further
also according to information from discussions around a topic like
“Adding metavariable types for the handling of string literals?”?
https://lore.kernel.org/cocci/alpine.DEB.2.22.394.2203271450370.3119@hadrien/
https://sympa.inria.fr/sympa/arc/cocci/2022-03/msg00140.html

Regards,
Markus


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

* Re: [cocci] Checking the handling of “space-delimited” string literals by SmPL
  2022-04-02  8:42 ` [cocci] Checking the handling of “space-delimited” string literals by SmPL Markus Elfring
@ 2022-04-03  0:25   ` Eric Wheeler
  2022-04-03  8:04     ` Julia Lawall
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Wheeler @ 2022-04-03  0:25 UTC (permalink / raw)
  To: Markus Elfring; +Cc: cocci

[-- Attachment #1: Type: text/plain, Size: 962 bytes --]

On Sat, 2 Apr 2022, Markus Elfring wrote:
> > I've tried to do something like this, but it is invalid SmPL:
> >
> > 	@ p @
> > 	expression list EL;
> > 	constant FOO, C =~ "BUG";
> > 	@@
> > 	-printf(FOO C, EL);
> > 	+BUG(C, EL);
> 
> 
> Thanks for your interest in software adjustments also for this area.
> 
> 
> 
> > Just ideas, I'm open to whatever you think is best for the project.
> 
> 
> How do you think about to influence the evolution any further
> also according to information from discussions around a topic like
> “Adding metavariable types for the handling of string literals?”?
> https://lore.kernel.org/cocci/alpine.DEB.2.22.394.2203271450370.3119@hadrien/
> https://sympa.inria.fr/sympa/arc/cocci/2022-03/msg00140.html

+1 for matching (and inserting/appending to) a series of quoted literals.  
I could have used that a few times recently and I don't know how to use 
cocci+python (yet!).



--
Eric Wheeler


> 
> Regards,
> Markus
> 
> 

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

* Re: [cocci] Checking the handling of “space-delimited” string literals by SmPL
  2022-04-03  0:25   ` Eric Wheeler
@ 2022-04-03  8:04     ` Julia Lawall
  0 siblings, 0 replies; 4+ messages in thread
From: Julia Lawall @ 2022-04-03  8:04 UTC (permalink / raw)
  To: Eric Wheeler; +Cc: Markus Elfring, cocci

[-- Attachment #1: Type: text/plain, Size: 1174 bytes --]



On Sat, 2 Apr 2022, Eric Wheeler wrote:

> On Sat, 2 Apr 2022, Markus Elfring wrote:
> > > I've tried to do something like this, but it is invalid SmPL:
> > >
> > > 	@ p @
> > > 	expression list EL;
> > > 	constant FOO, C =~ "BUG";
> > > 	@@
> > > 	-printf(FOO C, EL);
> > > 	+BUG(C, EL);
> >
> >
> > Thanks for your interest in software adjustments also for this area.
> >
> >
> >
> > > Just ideas, I'm open to whatever you think is best for the project.
> >
> >
> > How do you think about to influence the evolution any further
> > also according to information from discussions around a topic like
> > “Adding metavariable types for the handling of string literals?”?
> > https://lore.kernel.org/cocci/alpine.DEB.2.22.394.2203271450370.3119@hadrien/
> > https://sympa.inria.fr/sympa/arc/cocci/2022-03/msg00140.html
>
> +1 for matching (and inserting/appending to) a series of quoted literals.
> I could have used that a few times recently and I don't know how to use
> cocci+python (yet!).

While such strings are surely useful, learning how to use python will be
even more useful to you in the short term.  Just look at the demos that
contain script:python.

julia

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

end of thread, other threads:[~2022-04-03  8:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-01 20:12 [cocci] Space-delimted string literals Eric Wheeler
2022-04-02  8:42 ` [cocci] Checking the handling of “space-delimited” string literals by SmPL Markus Elfring
2022-04-03  0:25   ` Eric Wheeler
2022-04-03  8:04     ` Julia Lawall

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.