Please make a smaller example. In your example try to delete everything that you can without changing what you consider to be the undesirableness of the result. For example, I don't see what is the purpose, with respect to illutrating the bug, of the my_operations definition, the python code, or more of the function bodies.

In the current case, I can't see what you expect to be the third function.

julia

On Mon, 26 Dec 2011, SF Markus Elfring wrote:

{here f is a non-void function}

I have tried out another approach for a source code analysis with the Coccinelle software 1.0.0-rc7 on my openSUSE 12.1 system.

It corresponds also to my feature request "Support for alternative display format of selection results".
https://github.com/coccinelle/coccinelle/issues/6


elfring@Sonne:~/Projekte/Coccinelle/lokal/demos/return_values> SRC=../../../Probe/f-ptr-test1b.c && cat $SRC && LINE='-----' && echo $LINE && PAT=select_non_void_functions.cocci && cat $PAT && echo $LINE && spatch -sp_file $PAT $SRC
int my_safe_log(char const * text);
 int my_status(void);

void my_log(char const * text)
{
 /* Write something ... */
}

int my_safe_log(char const * text)
{
 if (!text)
   return 1;

 my_log(text);
 return 0;
}

char const * const my_message(void)
{
 return "Surprise!";
}

int my_status(void)
{
 return 1;
}

   int my_addition(char a, char b);

int my_addition(char a, char b)
{
 return a + b;
}

int main(void)
{
 struct my_operations
 {
   void (*log)(char const * t);
   int (*safe_log)(char const * t);
   char const * const (*get_message)(void);
   int (*is_ready)(void);
   int (*add)(char a, char b);
} mo = {my_log, my_safe_log, my_message, my_status, my_addition}, * mop = &mo;

 char const * const x = mo.get_message();
 int y = mop->is_ready();
 y = mop->add(1, 2);
 y = mo.add(3, 4);
 mo.log(mo.get_message());
 mo.is_ready();
 my_safe_log(0);
 mo.safe_log(0);
 mop->safe_log(0);
}
-----
@initialize:python@
result = []
delimiter = '|'

@function_declaration@
identifier f;
position p;
@@
f@p(...);

@is_void@
identifier function_declaration.f;
@@
void f(...);

@script:python collection depends on !is_void@
fun << function_declaration.f;
places << function_declaration.p;
@@
for place in places:
   fields = []
   fields.append(fun.ident)
   fields.append("declaration")
   fields.append(place.file)
   fields.append(place.line)
   fields.append(place.column)
   result.append(delimiter.join(fields))

@finalize:python@
if result:
result.insert(0, delimiter.join(["function", "action", "source file", "line", "column"]))
  print("\r\n".join(result))
else:
  print("No result for this analysis!")
-----
init_defs_builtins: /usr/share/coccinelle/standard.h
HANDLING: ../../../Probe/f-ptr-test1b.c
function|action|source file|line|column
my_log|declaration|../../../Probe/f-ptr-test1b.c|14|2
my_safe_log|declaration|../../../Probe/f-ptr-test1b.c|52|2


I do not like this test result because there should be found three different function names from my example. Do I make another mistake here in the application of the semantic patch language?

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to