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

Should headerdoc comments be parsed when ParseComments is false? #58

Closed waldnercharles closed 2 years ago

waldnercharles commented 2 years ago

I've noticed that headerdoc comments, (/*! MyComment */), get parsed even when ParseComments is set to false. Is this expected behavior?

Test case to prove assertion:

ParseAssert(@"// This is a comment is ignored
int f0;

/*! This comment is parsed */
int f1;

/* This comment is ignored */
int f2;",
compilation => { ... },
new CppParserOptions { ParseComments = false });
xoofx commented 2 years ago

Is this expected behavior?

I believe so. ParseComments is translated to -fparse-all-comments so that it will parse non-doxygen comments in addition to doxygen comments.

As explained in the doc: https://clang.llvm.org/docs/UsersManual.html#comment-parsing-options

Clang parses Doxygen and non-Doxygen style documentation comments and attaches them to the appropriate declaration nodes. By default, it only parses Doxygen-style comments and ignores ordinary comments starting with // and /*.

waldnercharles commented 2 years ago

Does it make sense to add support to ignore all comments, including doxygen comments?

xoofx commented 2 years ago

Does it make sense to add support to ignore all comments, including doxygen comments?

I have never had the need for such a feature, because even if it parses the comment and I don't use them, it's not the end of the world. But, if you have a particular use case where it makes sense for it, feel free to make a PR.