Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend support for handling of optional source code parts #53

Open
elfring opened this issue Dec 21, 2015 · 0 comments
Open

Extend support for handling of optional source code parts #53

elfring opened this issue Dec 21, 2015 · 0 comments

Comments

@elfring
Copy link
Contributor

elfring commented Dec 21, 2015

The Coccinelle software provides the search operator "question mark". If I try a small script for the semantic patch language out on a source file like the following, I get an incomplete analysis result.

show_variable_definitions1.cocci:

@variable_definition@
expression value;
identifier var;
type data_type;
@@
*data_type var
?= value
 ;

optional_initialisation1.c:

#include <stdio.h>

int main(void)
{
 char const message[] = "Test example\n";
 int result;

 result = puts(message);
 return result;
}

Output:

elfring@Sonne:~/Projekte/Coccinelle/janitor> spatch.opt -sp-file show_variable_definitions1.cocci ../Probe/optional_initialisation1.c
init_defs_builtins: /usr/local/lib64/coccinelle/standard.h
HANDLING: ../Probe/optional_initialisation1.c
diff = 
warning: incompatible arity found on line 7
warning: incompatible arity found on line 6
warning: incompatible arity found on line 6
--- ../Probe/optional_initialisation1.c
+++ /tmp/cocci-output-30894-5c6d7c-optional_initialisation1.c
@@ -2,7 +2,6 @@

 int main(void)
 {
- char const message[] = "Test example\n";
  int result;

  result = puts(message);

I hope that the mentioned arity can become compatible. It seems that SmPL disjunctions need to be used instead for a while.

show_variable_definitions2.cocci:

@variable_definition@
expression value;
identifier var;
type data_type;
@@
(
*data_type var;
|
*data_type var = value;
)

Output:

elfring@Sonne:~/Projekte/Coccinelle/janitor> spatch.opt -sp-file show_variable_definitions2.cocci ../Probe/optional_initialisation1.c
init_defs_builtins: /usr/local/lib64/coccinelle/standard.h
HANDLING: ../Probe/optional_initialisation1.c
diff = 
--- ../Probe/optional_initialisation1.c
+++ /tmp/cocci-output-32184-d244bd-optional_initialisation1.c
@@ -2,8 +2,6 @@

 int main(void)
 {
- char const message[] = "Test example\n";
- int result;

  result = puts(message);
  return result;

I hope that the software implementation can also be improved around the operator "question mark" so that search element duplication can be avoided in more use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant