xlab / c-for-go

Automatic C-Go Bindings Generator for Go Programming Language
https://c.for-go.com
MIT License
1.5k stars 119 forks source link

Extracting SAL annotations from declarations #155

Closed ayoubfaouzi closed 1 year ago

ayoubfaouzi commented 1 year ago

Hello @xlab

I understand that the request I am asking is not directly related to what c-for-go aims for, so please feel free to close the issue if you deem it necessary.

I am using cc + c-for-go to parse Windows SDK headers as c-for-go translates the AST to a nice objects I can walk through.

Windows API's prototypes have SAL annotations on them, and for my proposes I need to extract those as well.

For example:

   _Out_writes_bytes_all_(count) void *dest,
   _In_reads_bytes_(count) const void *src,
   size_t count
);

I need to grab the string Out_writes_bytes_all_(count) for the first parameter.

What part of the ast_walker.go I need to change to get these results.

xlab commented 1 year ago

Hi! I worked on earlier versions of cc (~ v1) that didn't have such things supported, so I had to define those macros as empty. I think the current version that we use (CC v4) is able to parse it, but I am not sure how to traverse that info :) Can't help you there..

You can try to work directly with CZnic (@cznic ?)

ayoubfaouzi commented 1 year ago

That's right ! I opened an issue in cc, thanks a lot for your feedback !