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
501 stars 66 forks source link

Getting comments from the side of a function #5

Closed chrisdill closed 5 years ago

chrisdill commented 5 years ago

I have been testing this library for my raylib bindings.

I am processing a header and I am not sure how to get the comments that are to the side of a function. I can get them from a struct or enum but I also would like to get the spacing so I can line them up.

RLAPI void InitWindow(int width, int height, const char *title);  // Initialize window and OpenGL context
// Texture2D type
// NOTE: Data stored in GPU memory
typedef struct Texture2D {
    unsigned int id;        // OpenGL texture id
    int width;              // Texture base width
    int height;             // Texture base height
    int mipmaps;            // Mipmap levels, 1 by default
    int format;             // Data format (PixelFormat type)
} Texture2D;

I am not sure the best way to do this. Maybe if there is a way to get the full line from a function as a string then I can access the spacing and split the string to get the comment.

xoofx commented 5 years ago

libclang doesn't report comments for functions on the side while it should work for struct fields.

Apart modifying header files, there is nothing much to do about it. Re-parsing a partial C++ line would be very brittle (but you can try, although that's something that I would never put back into CppAst)