Using the following C++ struct as an example:
__attribute__((annotate("MyAttribute")))
struct TestComponent
{
__attribute__((annotate("MyAttribute")))
int32_t testInt;
__attribute__((annotate("MyAttribute")))
bool testBool;
__attribute__((annotate("MyAttribute")))
char testChar;
};
Given a node (cursor) from clang using (clang module's cindex) while parsing the AST, using the following I can get the annotations on the class members when node is pointing to TestComponent and has a kind equal to CursorKind.STRUCT_DECL:
def get_annotations(node):
annotations = [c.displayname for c in node.get_children()
if c.kind == clang.cindex.CursorKind.ANNOTATE_ATTR]
return annotations
But class/struct annotations never show up as children of a struct/class. Is there a way to get to those? Even in the C bindings - I can try Monkeypatching it, but couldn't find anything.
tl;dr: attribute should be placed between
structandTestComponentIf you print
tu.diagnostics,clangdoes issue a-Wignored-attributeswarning:Once fixed,
ANNOTATE_ATTRis visible in AST:My test code for reference: