I'm using following syntax in my code
///Data types #define TYPE_NOT_USED 0 //!< not used #define TYPE_1 1 //!< comment1 #define TYPE_2 2 //!< comment2 #define TYPE_3 3 //!< comment3
If "parse documentation" enabled only first one appeared in list when I type "TYPE_". If I use C-like comment syntax (/!< comment /) CC parse it correctly.
I can confirm this bug.
with doc reading enabled, I see that after SkipComment(), the CurrentChar() is not \n. But with doc reading disabled, the CurrentChar() is \n, which works correctly.
The following patch should read the doc correctly, but note that the Token and the document are not synchronized correctly, because the macro definition token is added after reading the whole comments.
I found that there are some issues when handling comments. Especially that C++ and C comments are handled differently.
When C comment is handled, the stop char is here
When C++ comment is handled, the stop char is "\n"
As a reference, the C comment is prefered if you use them in a big macro definition cross several lines, see: http://complete-concrete-concise.com/programming/c/how-to-add-comments-to-macros
Thanks! Looks like this patch working for me.
I know about using single-line comments in multi-line macro, but here is single-line macroses and all tested compilers handle this syntax ok.
FYI: I commit the fix to partially fix this issue in rev9905.
since the doxygen comment parsing is also part of the CC, another issue still exists, if doxygen comments are to be displayed (CC->Documentation->Parse documentation) , CC will show the line comment for the next define only.
That is, TYPE_NOT_USED shows "comment1",
TYPE_1 shows "comment2",
TYPE_3 doesn't show anything as no other define/comment follows...
Hi, White-Tiger, as I said in previous posts(also in the commit 9905's log message), the token and the comment synchronization issue is not solved yet. I can't find a way to solve this issue, because the comment parsing and token parsing are basically independent, so they don't know much about each other.
well... I've only seen this issue with defines, other types such as enums, variables, function declarations etc., all work fine..
So what's so special about defines? Why are they handled differently?
For example, here are the code:
int a; //<! description of a
Here, the parser first find a Token "int a;", and store it in the TokenTree.
Then it find a comment "description of a", also it detected that "//<!" which means this is a kind of doxygen comment, which should append to the previous variable. In this case those snippet is running (inside the SkipComment())
Note that m_LastTokenIdx points to Token "int a;".
Now, in OP's example:
The macro definition Token "TYPE_NOT_USED" is recorded AFTER reading the "not used" comments. So, that "not used" text is not attached to the Token "TYPE_NOT_USED". Next, when "comment1" is read, the m_LastTokenIdx points to Token "TYPE_NOT_USED"(Token TYPE_1 is not recorded yet), so "comment1" attaches to Token "TYPE_NOT_USED".
The solution could be: stop the parser and record the macro Token if the parser see a C++ kind of comments.
Guys, here is the patch to solve this issue, I just stop the reading of the macro definition when the parser see a C++ style comments.
I put the patch here for several days, so you can test it, if no issues, I will commit it.
Not that happy about that patch.. as it only handles C++ style comments and thus isn't a full solution to the problem. Just a mere "better than nothing"
while I tried to understand what the parser is doing (thanks to your explanation), I've found that there are more cases than just defines... such as:
The 1st and 2nd comment will be added to GotNoDoxygenComments()
and DoxyTestFunc() is missing them...
And I guess the only valid doxygen comment would be "1st"... while I guess it's also ok to do
So it's basically the same issue that exists for defines, you'll try to fully parse the tokens before adding them... which means to also parse the function block after function definition.
from my understanding, the parser should add the token once it hits either ";={", that is a char that ends the definition.
in case of "{", the parser would have to go "backward", ignoring spaces and comments and start parsing comments from there on
For #define this would be anything after the word following "define", so basically on first space hit.
Another solution would be if the parser got something like "TokenFound" so that comments can be processed (
/*** */
onces will be added to the newly found token,/**< */
onces will be added to the previous token, but preferably only if they are on the same line)Hi, thanks for the suggestion.
The 1st and 2nd comment will be added to GotNoDoxygenComments()
and DoxyTestFunc() is missing them...
And I guess the only valid doxygen comment would be "1st"... while I guess it's also ok to do
first, I think people rarely write doxygen text like the above samples. Although it is a valid code. I just read the code about handling Functions, I see that the function body is normally skipped by
But SkipBlock() function will internally call SkipComment(), so doxygen comments is still added, but I see that the function Token is only added after SkipBlock(), which means the collect doxygen document would add to previous function Token(in your case, the GotNoDoxygenComments function Token.
I'm not sure, but for a parser, the "go backward" is quite hard to implement, because we may have "backward buffer replacement" when handling macro replacement, so we lose all the backward code context. Thus this method is hard to implement in current CC's implementation.
You mean that the below code:
The above "append kind comment" to "Token" association should only happens when the previous Token and comment are in the same line?
Thanks.
weird... I wrote "onces" instead of "ones" in my previous reply xD Damn it..
Yes, I've meant that.. but seems like it's not as easy as I thought... The only uses I've seen so far suggest that they only apply to a "token" directly in front of them.. so I assumed a new line wouldn't cut it. Yet those comments can continue on the next line: http://www.stack.nl/~dimitri/doxygen/manual/docblocks.html#memberdoc
So that doesn't really help either..
Yes, I see that the link Doxygen Manual: Documenting the code have some sample code like:
So, it can has two lines after the var definition.
Not sure how Doxygen's parser handle those pattern...
My patch is committed in trunk now(r10321), and I think we can close this ticket. Though in CC there are still many things need to improve.
A related bug report: incorrect defines parsing with doxygen block comment