xoofx / CppAst.NET

CppAst is a .NET library providing a C/C++ parser for header files powered by Clang/libclang with access to the full AST, comments and macros
BSD 2-Clause "Simplified" License
482 stars 63 forks source link

Attributes on line preceding the function are not parsed #53

Open javster101 opened 2 years ago

javster101 commented 2 years ago

I'm working with custom attributes for a serializer, and for readability purposes I'd like to have attributes on the line before the function the attribute is for, eg:

[[test::attr]]
void myFunc();

Unfortunately, CppAst cannot correctly identify the attribute in that case.

However, if I put the attribute on the same line:

[[test::attr]] void myFunc();

it works fine. As far as I know, the standard does allow the attributes to be before as per the former example. I'm not sure if this is an issue with CppAst or with libclang itself, but it would be great if attributes could be on the line before the function.

xoofx commented 2 years ago

Definitely possible, as attributes have to be parsed manually, so there might be some bugs.

fangfang1984 commented 1 year ago

Definitely possible, as attributes have to be parsed manually, so there might be some bugs.

Yes, it seems custom attribute is act as a ignore cursor here, but in now version of ClangSharp, it has no feature to query custom attribute here. I'm try to do it by manual use SourceLocation and offset. The on the line feature is important for not let code easy to read. Our project is try to use annoute with custom string to do this, but it will need many macros, and it is not controllable. It used looks like struct RCLASS(Ignore=true, DisplayName="abc") MyClass, where RCLASS is a macro at last will replace to a annotate attribute here.