Add support for C/C++ attribute annotate #552
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds support to emit information about
__attribute__((annotate("ANNOTATION")))
in the generated Code and XML.The GNU attribute
annotate
or its clang equivalent can appear and might convey interesting information that may be useful in the generated bindings. ClangSharpPInvokeGenerator today has only very limited support for a very few attributes, but thisannotate
attribute can be a simple catch-all allowing developers to at least have some mechanism of transferring information from the C/C++ header to the generated code.In my particular scenario I need to do post-processing on the generated bindings and the annotation attribute seemed like a good way to transfer knowledge from the C++ header to the generated XML. I simply overrode a macro that includes the attribute in a struct type declaration, and using the changes made in this PR I could now see the emitted attribute in my C# source and as an
<attribute>
element in the generated XML. In my example I use it as a marker to change the generated struct into a ref struct, because that's what I needed in that particular case.Similarly to
NativeTypeNameAttribute
the generator will emit a synthetically generated attributeNativeAnnotation
if at least oneannotate
attribute was encountered. Otherwise, this new attribute is emitted under the same conditions under whichNativeTypeNameAttribute
is emitted.In C/C++ the
annotate
attribute has one mandatory string literal argument. That literal is emitted as theAnnotation
property on theNativeAnnotation
attribute in C#.libClangSharp
already supports theannotate
attribute, so this PR simply changes the P/Invoke generator to actually do something when anannotate
attribute is reported by Clang.