Skip to contentSkip to conversation

Does SmPL for functions with prototype disjunctions need to be complete?

cocci Eric Wheeler 3 participants 7 messages Mar 7, 2022 – Mar 8, 2022

lore
Share & tools
lore
#0 lore raw

This seems to work when the body of the funciton is defined in each disjunction:

	@ prefix_nec_arg @
	type T;
	identifier F, j;
	typedef nec_t;
	parameter list PL;
	@@
	( 
	T F(
	-void
	+nec_t *nec
	 )
	{
	... when exists
	    when any
	nec->j
	... when exists
	    when any
	}
	| 
	T F(
	+nec_t *nec
	 )
	{
	... when exists
	    when any
	nec->j
	... when exists
	    when any
	} 
	| 
	T F(
	+nec_t *nec,
	PL
	 )
	{
	... when exists
	    when any
	nec->j
	... when exists
	    when any
	}
	)

But placing the function body after the disjunction block did not, even though it is easier to read and does not duplicate content:

	@ prefix_nec_arg @
	type T;
	identifier F, j;
	typedef nec_t;
	parameter list PL;
	@@
	( 
	T F(
	-void
	+nec_t *nec
	 )
	| 
	T F(
	+nec_t *nec
	 )
	| 
	T F(
	+nec_t *nec,
	PL
	 )
	)
	{
	... when exists
	    when any
	nec->j
	... when exists
	    when any
	}

Is that expected?

It means there must be a longer SmPL, which is ok, but for my own
curiosity: is there a shorter form?

--
Eric Wheeler

#1 lore raw
Quoted 77 lines · Eric Wheeler

This seems to work when the body of the funciton is defined in each disjunction:

	@ prefix_nec_arg @
	type T;
	identifier F, j;
	typedef nec_t;
	parameter list PL;
	@@
	(
	T F(
	-void
	+nec_t *nec
	 )
	{
	... when exists
	    when any
	nec->j
	... when exists
	    when any
	}
	|
	T F(
	+nec_t *nec
	 )
	{
	... when exists
	    when any
	nec->j
	... when exists
	    when any
	}
	|
	T F(
	+nec_t *nec,
	PL
	 )
	{
	... when exists
	    when any
	nec->j
	... when exists
	    when any
	}
	)

But placing the function body after the disjunction block did not, even though it is easier to read and does not duplicate content:

	@ prefix_nec_arg @
	type T;
	identifier F, j;
	typedef nec_t;
	parameter list PL;
	@@
	(
	T F(
	-void
	+nec_t *nec
	 )
	|
	T F(
	+nec_t *nec
	 )
	|
	T F(
	+nec_t *nec,
	PL
	 )
	)
	{
	... when exists
	    when any
	nec->j
	... when exists
	    when any
	}
Quoted 4 lines

Is that expected?

It means there must be a longer SmPL, which is ok, but for my own
curiosity: is there a shorter form?

It might be possible to put a disjunction around only the parameter list, ie inside the parentheses.

julia

#2 lore raw
Quoted 5 lines
Quoted 3 lines

It means there must be a longer SmPL, which is ok, but for my own
curiosity: is there a shorter form?

It might be possible to put a disjunction around only the parameter list, ie inside the parentheses.

How useful would such an SmPL code variant be here actually?

Regards,
Markus

#3 lore raw
Quoted 6 lines · Markus Elfring
Quoted 6 lines
Quoted 3 lines

It means there must be a longer SmPL, which is ok, but for my own
curiosity: is there a shorter form?

It might be possible to put a disjunction around only the parameter list, ie inside the parentheses.

Thanks Julia, that is a great hint!

Quoted 1 line

How useful would such an SmPL code variant be here actually?

It just makes it more readable. I always try to avoid duplicate code no matter what language I'm writing for.

--
Eric Wheeler

Quoted 6 lines

Regards,
Markus

#4 lore raw
Quoted 9 lines · Eric Wheeler
Quoted 6 lines · Markus Elfring
Quoted 6 lines
Quoted 3 lines

It means there must be a longer SmPL, which is ok, but for my own
curiosity: is there a shorter form?

It might be possible to put a disjunction around only the parameter list, ie inside the parentheses.

Quoted 6 lines

Thanks Julia, that is a great hint!

Quoted 1 line

How useful would such an SmPL code variant be here actually?

It just makes it more readable. I always try to avoid duplicate code no matter what language I'm writing for.

There is some value to rules that are readable, rather than minimal.

julia

#5 lore raw
In reply to Eric Wheeler
Quoted 3 lines

It just makes it more readable. I always try to avoid duplicate code no matter what language I'm writing for.

How do you think about “code” which you would not need to specify at all?

Regards,
Markus

#6 lore raw
Quoted 5 lines · Markus Elfring
Quoted 2 lines

It just makes it more readable. I always try to avoid duplicate code no matter what language I'm writing for.

How do you think about “code” which you would not need to specify at all?

At the moment my needs are met, but if you think an SmPL notation for this would benefit others then of course that would be great.

--
Eric Wheeler

Quoted 6 lines

Regards,
Markus