sighingnow / libclang

(Unofficial) Release libclang (clang.cindex) on pypi.
https://pypi.org/project/libclang
Other
81 stars 21 forks source link

UNEXPOSED_ATTRIBUTE not having tokens or spelling #52

Closed Victorious3 closed 1 year ago

Victorious3 commented 1 year ago

Say you have a function like this:

__attribute__((always_inline)) void test(int a) {

}

If you use libclang to iterate over the children it becomes an UNEXPOSED_ATTRIBUTE. However, I don't know how to inspect it further because its tokens are empty and spelling is the empty string.

JhnW commented 1 year ago

The best way to handle attribute is use regex near the function. Why? Clang can parse some attributes but not all - it ignores unsupported attributes silently, giving no information about them. I even made a ticket for it once and one of the contributors nicely explained that from their point of view it's not that easy (an unknown attribute would require its own unknown attribute grammar). Although from what I remember your case was possible to handle with the clang parser.

sighingnow commented 1 year ago

Assuming element is your CursorKind.UNEXPOSED_ATTR node, and text is your source code, try:

text[element.extent.start.offset : element.extent.end.offset]

The result should be string always_inline.