How to match function calls in macros?
Quoted 5 lines
@@
identifier mac,f;
@@*#define mac(...) <+... f(...) ...+>
Does such an analysis approach restrict the source code search really on complete definitions for function-like macros?
Will it become interesting for clarify corresponding special cases?
* How are empty macros treated by the Coccinelle software?
* Is there a connection managed between a macro declaration and subsequent source code?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 8 lines · Markus Elfring
Quoted 5 lines
@@
identifier mac,f;
@@*#define mac(...) <+... f(...) ...+>
Does such an analysis approach restrict the source code search really on complete definitions for function-like macros?
Coccinelle knows where the macro ends. A macro has to be on one line, perhaps extended with a \
julia
Quoted 4 lines
Will it become interesting for clarify corresponding special cases?
Quoted 8 lines
* How are empty macros treated by the Coccinelle software?
* Is there a connection managed between a macro declaration and subsequent source code?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 10 lines
Quoted 8 lines
Quoted 5 lines
@@
identifier mac,f;
@@*#define mac(...) <+... f(...) ...+>
Does such an analysis approach restrict the source code search really on complete definitions for function-like macros?
Coccinelle knows where the macro ends.
This is good to know.
Quoted 1 line
A macro has to be on one line,
This fact is reasonable.
Quoted 1 line
perhaps extended with a \
How would (or should) the Coccinelle software handle the mentioned search pattern if such a line continuation indication was omitted between a macro declaration and subsequent source code?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 16 lines · Markus Elfring
Quoted 10 lines
Quoted 8 lines
Quoted 5 lines
@@
identifier mac,f;
@@*#define mac(...) <+... f(...) ...+>
Does such an analysis approach restrict the source code search really on complete definitions for function-like macros?
Coccinelle knows where the macro ends.
This is good to know.
Quoted 1 line
A macro has to be on one line,
Quoted 8 lines
This fact is reasonable.
Quoted 1 line
perhaps extended with a \
How would (or should) the Coccinelle software handle the mentioned search pattern if such a line continuation indication was omitted between a macro declaration and subsequent source code?
The macro ends at the first line that doesn't end with a \
If the developer forgets the \ there would likely be a parsing problem.
julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 5 lines
Quoted 3 lines
How would (or should) the Coccinelle software handle the mentioned search pattern if such a line continuation indication was omitted between a macro declaration and subsequent source code?
The macro ends at the first line that doesn't end with a \
This is fine.
Quoted 1 line
If the developer forgets the \ there would likely be a parsing problem.
I find it helpful to clarify parsing challenges around such an use case. It might occasionally be relevant if a line continuation indication was accidentally forgotten or was intentionally omitted.
* Source code review should point such questionable places out, shouldn't it?
* How much does this implementation detail matter for the safe application of the semantic patch language?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 11 lines · Markus Elfring
Quoted 5 lines
Quoted 3 lines
How would (or should) the Coccinelle software handle the mentioned search pattern if such a line continuation indication was omitted between a macro declaration and subsequent source code?
The macro ends at the first line that doesn't end with a \
This is fine.
Quoted 1 line
If the developer forgets the \ there would likely be a parsing problem.
Quoted 8 lines
I find it helpful to clarify parsing challenges around such an use case. It might occasionally be relevant if a line continuation indication was accidentally forgotten or was intentionally omitted.
* Source code review should point such questionable places out, shouldn't it?
* How much does this implementation detail matter for the safe application of the semantic patch language?
This is not Coccinelle's problem. A developer can run a compiler to check for parsing errors.
julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
If the developer forgets the \ there would likely be a parsing problem.
I find it helpful to clarify parsing challenges around such an use case. It might occasionally be relevant if a line continuation indication was accidentally forgotten or was intentionally omitted.
Quoted 6 lines
Quoted 4 lines
* Source code review should point such questionable places out, shouldn't it?
* How much does this implementation detail matter for the safe application of the semantic patch language?
This is not Coccinelle's problem.
This software is also involved then.
Quoted 1 line
A developer can run a compiler to check for parsing errors.
I imagine that a missing line continuation can be hard to detect and report as a possible programming error because the corresponding code parts can still be valid on their own according to special circumstances.
Can the semantic patch language help to insist for a search that a bit of source code belongs to the implementation of a function-like macro?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 13 lines · Markus Elfring
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
If the developer forgets the \ there would likely be a parsing problem.
I find it helpful to clarify parsing challenges around such an use case. It might occasionally be relevant if a line continuation indication was accidentally forgotten or was intentionally omitted.
Quoted 6 lines
Quoted 4 lines
* Source code review should point such questionable places out, shouldn't it?
* How much does this implementation detail matter for the safe application of the semantic patch language?
This is not Coccinelle's problem.
Quoted 8 lines
This software is also involved then.
Quoted 1 line
A developer can run a compiler to check for parsing errors.
I imagine that a missing line continuation can be hard to detect and report as a possible programming error because the corresponding code parts can still be valid on their own according to special circumstances.
If they are valid, then what is the problem. Neither a compiler nor Coccinelle can know what the developer intended.
Quoted 2 lines
Can the semantic patch language help to insist for a search that a bit of source code belongs to the implementation of a function-like macro?
That's what the search that was written does. The pattern that comes after #define has to be in the definition of the macro. Coccinelle never matches things in more than one top-level term in the C file.
julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 4 lines
Quoted 2 lines
Can the semantic patch language help to insist for a search that a bit of source code belongs to the implementation of a function-like macro?
That's what the search that was written does.
I interpret the example in another way.
*#define mac(...) <+... f(...) ...+>
Quoted 1 line
The pattern that comes after #define has to be in the definition of the macro.
* Would you find it as acceptable if a function-like macro was implemented in the way that it became empty?
* If find that the specification “<+... f(...) ...+>” does not explicitly express a requirement for a replacement list (despite of being so close).
https://en.cppreference.com/w/c/preprocessor/replace
Quoted 1 line
Coccinelle never matches things in more than one top-level term in the C file.
Which is the corresponding scope for such source code?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 1 line
If the developer forgets the \ there would likely be a parsing problem.
Another information can be helpful then.
elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-c INIT_WORK-Test-20200518.c …
SUSPICIOUS: a \ character appears outside of a #define at INIT_WORK-Test-20200518.c:4
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 5 lines
Quoted 2 lines
Can the semantic patch language help to insist for a search that a bit of source code belongs to the implementation of a function-like macro?
That's what the search that was written does. The pattern that comes after #define has to be in the definition of the macro.
I suggest to consider additional source code variants.
With which SmPL constructs should be ensured that a search pattern like “<+... f(...) ...+>” refers only to content from the same logical source line?
https://en.cppreference.com/w/c/language/translation_phases#Phase_2
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 10 lines · Markus Elfring
Quoted 5 lines
Quoted 2 lines
Can the semantic patch language help to insist for a search that a bit of source code belongs to the implementation of a function-like macro?
That's what the search that was written does. The pattern that comes after #define has to be in the definition of the macro.
I suggest to consider additional source code variants.
With which SmPL constructs should be ensured that a search pattern like “<+... f(...) ...+>” refers only to content from the same logical source line?
https://en.cppreference.com/w/c/language/translation_phases#Phase_2
Please stop asking the same question over and over. In the context of a macro definition, <+... f(...) ...+> will only match what is from the same logical source line. Because that is all that there is in a macro definition. If Coccinelle is working on a macro definition, it works only on that macro definition. If it is working on a function definition, it works only on that function definition.
julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 5 lines
Quoted 3 lines
With which SmPL constructs should be ensured that a search pattern like “<+... f(...) ...+>” refers only to content from the same logical source line?
https://en.cppreference.com/w/c/language/translation_phases#Phase_2Please stop asking the same question over and over.
I hope that the expected and actually supported software functionality will become clearer.
Quoted 2 lines
In the context of a macro definition, <+... f(...) ...+> will only match what is from the same logical source line.
Does the functionality of the SmPL nest construct change according to previous source code?
Are there more aspects to consider for the safe handling of physical source lines?
Quoted 1 line
Because that is all that there is in a macro definition.
We hope so also according to the initial clarification request for this issue.
Quoted 1 line
If Coccinelle is working on a macro definition, it works only on that macro definition.
Such an expectation can eventually be fine.
Did I overlook any information for this detail in the software documentation so far?
https://github.com/coccinelle/coccinelle/blob/7cf2c23e64066d5249a64a316cc5347831f7a63f/docs/manual/cocci_syntax.tex#L1736
Quoted 1 line
If it is working on a function definition, it works only on that function definition.
Does the position of the define directive influence this view?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 28 lines · Markus Elfring
Quoted 5 lines
Quoted 3 lines
With which SmPL constructs should be ensured that a search pattern like “<+... f(...) ...+>” refers only to content from the same logical source line?
https://en.cppreference.com/w/c/language/translation_phases#Phase_2Please stop asking the same question over and over.
I hope that the expected and actually supported software functionality will become clearer.
Quoted 2 lines
In the context of a macro definition, <+... f(...) ...+> will only match what is from the same logical source line.
Does the functionality of the SmPL nest construct change according to previous source code?
Are there more aspects to consider for the safe handling of physical source lines?
Quoted 1 line
Because that is all that there is in a macro definition.
We hope so also according to the initial clarification request for this issue.
Quoted 1 line
If Coccinelle is working on a macro definition, it works only on that macro definition.
Such an expectation can eventually be fine.
Quoted 7 lines
Did I overlook any information for this detail in the software documentation so far?
https://github.com/coccinelle/coccinelle/blob/7cf2c23e64066d5249a64a316cc5347831f7a63f/docs/manual/cocci_syntax.tex#L1736Quoted 1 line
If it is working on a function definition, it works only on that function definition.
Does the position of the define directive influence this view?
I believe that the #defines inside of other top-level definitions are ignored.
julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
If it is working on a function definition, it works only on that function definition.
Does the position of the define directive influence this view?
I believe that the #defines inside of other top-level definitions are ignored.
I find such a feedback surprising.
It seems that the clarification of desired software functionality can become more interesting also with this information.
How will the supported software functionality evolve further besides intra-procedural source code analysis?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci