Skip to contentSkip to conversation

Searching for functions with non-internal linkage

Cocci Markus Elfring 2 participants 10 messages Sep 21, 2020 – Sep 22, 2020 8 messages not in the archive

lore
Share & tools
lore
#0 lore raw

Hello,

I have tried another tiny script variant out for the semantic patch language (according to the software combination “Coccinelle 1.0.8-00177-g28737419”).

@find@
identifier i;
type t;
@@
t i(...)
{ ... }

@find_static@
identifier find.i;
type find.t;
@@
static t i(...)
{ ... }

@display depends on !find_static@
identifier find.i;
type find.t;
@@
*t i(...)
{ ... }

This source code analysis approach is generally working in the way it is designed.
Can the same data processing results be achieved also with a single SmPL rule?

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#1 lore raw
Quoted 27 lines · Markus Elfring

Hello,

I have tried another tiny script variant out for the semantic patch language (according to the software combination “Coccinelle 1.0.8-00177-g28737419”).

@find@
identifier i;
type t;
@@
t i(...)
{ ... }

@find_static@
identifier find.i;
type find.t;
@@
static t i(...)
{ ... }

@display depends on !find_static@
identifier find.i;
type find.t;
@@
*t i(...)
{ ... }

Quoted 3 lines

This source code analysis approach is generally working in the way it is designed.
Can the same data processing results be achieved also with a single SmPL rule?

There is an isomorphism related to static. Maybe optional_qualifier. That is, in the third rule, if you remove the depends on and add disable optional_qualifier, then it would not match a static function.

julia

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#3 lore raw
In reply to a message not in the archive
Quoted 9 lines · Markus Elfring
Quoted 3 lines
Quoted 1 line

Can the same data processing results be achieved also with a single SmPL rule?

There is an isomorphism related to static. Maybe optional_qualifier.

I interpret the available information in the way that the isomorphism “optional_storage” affects the handling of visibility for identifiers like function names.
https://github.com/coccinelle/coccinelle/blob/730dbb034559b3e549ec0b2973cd0400a3fa072f/docs/manual/cocci_syntax.tex#L125

Quoted 5 lines
Quoted 2 lines

That is, in the third rule, if you remove the depends on and add disable optional_qualifier, then it would not match a static function.

Would such a setting be better than the dependency check according to the SmPL rule “find_static”?

Optional_storage is indeed probably the right one.

julia

Quoted 7 lines

How are the chances to determine functions which are not marked as “static” by one SmPL rule directly?

Regards,
Markus

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#5 lore raw
In reply to a message not in the archive
Quoted 25 lines · Markus Elfring
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

That is, in the third rule, if you remove the depends on and add disable optional_qualifier, then it would not match a static function.

Would such a setting be better than the dependency check according to the SmPL rule “find_static”?

Optional_storage is indeed probably the right one.

The following SmPL script variant seems to work as expected then.

@find disable optional_storage@
identifier i;
type t;
@@
(
*t i(...)
{ ... }
|
*extern t i(...)
{ ... }
)

Can another SmPL script variant become similarly useful?

Quoted 11 lines

@find2 disable optional_storage@
identifier i;
type t;
@@
(
*t
|
*extern t
)
*i(...)
{ ... }

I doubt that this parses. I don't think extern t is considered to be a type.

julia

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#7 lore raw
In reply to a message not in the archive
Quoted 14 lines · Markus Elfring
Quoted 14 lines
Quoted 13 lines

Can another SmPL script variant become similarly useful?

@find2 disable optional_storage@
identifier i;
type t;
@@
(
*t
|
*extern t
)
*i(...)
{ ... }

Quoted 8 lines
Quoted 1 line

I doubt that this parses.

I hope to achieve further improvements also for this application area.

Quoted 1 line

I don't think extern t is considered to be a type.

Which entity should take care of this key word (in SmPL disjunctions)?

I don't know if a disjunction is allowed at this level. But if it is allowed, then it would be with extern and maybe inline, etc.

julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#9 lore raw

Re: [Cocci] Searching for functions with linkage specifications

In reply to a message not in the archive
Quoted 5 lines · Markus Elfring
Quoted 1 line

I doubt that this parses.

Can another report for a parsing error be reconsidered also for the following SmPL script variant?

Quoted 11 lines

@display disable optional_storage@
identifier i;
type t;
@@
(
*extern
|
*static
)
*t i(...)
{ ... }

When you use a yacc generated parser, you don't have any control over where it decides to report an error.

julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#11 lore raw

Re: [Cocci] Searching for functions with linkage specifications

In reply to a message not in the archive
Quoted 15 lines · Markus Elfring
Quoted 15 lines
Quoted 14 lines

Can another report for a parsing error be reconsidered also for the following SmPL script variant?

@display disable optional_storage@
identifier i;
type t;
@@
(
*extern
|
*static
)
*t i(...)
{ ... }

Quoted 4 lines
Quoted 2 lines

When you use a yacc generated parser, you don't have any control over where it decides to report an error.

How do you think about to choose an alternative parsing approach?

This question is completely absurd. Have you ever actually written a parser?

Quoted 2 lines

Would you find the shown case distinction useful?

Disjunctions could be added for extern and static. Feel free to propose a patch.

julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#13 lore raw

Re: [Cocci] Searching for functions with linkage specifications

In reply to a message not in the archive
Quoted 19 lines · Markus Elfring
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

When you use a yacc generated parser, you don't have any control over where it decides to report an error.

How do you think about to choose an alternative parsing approach?

This question is completely absurd.

It is known that YACC-like parsing has got limitations. Thus I am curious under which circumstances possible alternatives can become more attractive.

Quoted 1 line

Have you ever actually written a parser?

I came also along special parsing needs for specific data structures.

Quoted 2 lines
Quoted 1 line

Would you find the shown case distinction useful?

Quoted 8 lines
Quoted 1 line

Disjunctions could be added for extern and static.

Thanks for this kind of feedback.

Quoted 1 line

Feel free to propose a patch.

Can any clarification help to make such a contribution easier?

I think you can follow the model of other kinds of disjunctions.

julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#15 lore raw

Re: [Cocci] Searching for functions with linkage specifications

In reply to a message not in the archive
Quoted 3 lines · Markus Elfring
Quoted 1 line

I think you can follow the model of other kinds of disjunctions.

Which (OCaml) modules do take care of the corresponding data processing?

Probably all files in parsing_cocci and cocci_vs_c.ml

julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#17 lore raw

Re: [Cocci] Searching for functions with linkage specifications

In reply to a message not in the archive
Quoted 8 lines · Markus Elfring
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

I think you can follow the model of other kinds of disjunctions.

Which (OCaml) modules do take care of the corresponding data processing?

Probably all files in parsing_cocci and cocci_vs_c.ml

Can the dependencies become clearer for the evaluation of SmPL disjunctions by such software components?

Just grep for Disj. You will find all of the relevant files.

julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci