This is an archive of the discontinued LLVM Phabricator instance.

This change-list changes clang to attach the ordinary comments if an option is specified
ClosedPublic

Authored by amshali on Apr 2 2013, 2:00 PM.

Details

Summary

Not all people use doxygen style comments as doc-comments. They just use ordinary comments in place of doxygen style comments. We would like to know which nodes are associated with those comments.

Diff Detail

Event Timeline

gribozavr added a subscriber: Unknown Object (MLST).Apr 3 2013, 6:07 AM

I think a name like "parse all comments" would better reflect the intent of this feature.

include/clang/AST/RawCommentList.h
13–15

Please sort includes.

92

It would be better to change isOrdinary instead:

return (Kind == RCK_OrdinaryBCPL) || (Kind == RCK_OrdinaryC) || TreatOrdinaryCommentAsDocComment;
144

Only "//"? It would be better to rename it to "parse all comments". Is this OK with you?

145

Three slashes, please.

145

And please spell 'documentation comments' completely.

146

Please pack this at the end of the bitfield above (after IsTrailingComment, IsAlmostTrailingComment).

lib/AST/RawCommentList.cpp
258

I don't think the last 'true' is necessary here. Why do you think it is?

unittests/Frontend/FrontendActionTest.cpp
103–104 ↗(On Diff #1486)

Star goes to the right. Member names should start with a capital letter and should not have an underscore.

108–109 ↗(On Diff #1486)

Why is this test so complicated, going through constructing half of Clang?

You can add a very simple test, based on c-index-test, see test/Index/annotate-comments.cpp.

112–113 ↗(On Diff #1486)

Please add tests for /* ... */ comments.

amshali updated this revision to Unknown Object (????).Apr 3 2013, 3:55 PM

Changes in this revision:

  • Applied reviewer's comments.
  • Renamed the option to ParseAllComments.
  • Fixed the code appropriately.
  • Removed the test from unittests/Frontend/FrontendActionTest.cpp. * Added two tests, one for making sure we are passing the argument to clang and one for making sure we are attaching ordinary comments.
  • Changed Tools.cpp to pass the option to cc1.
  • Changed the option definition in Options.td.

Please have a look. I added some new tests and applied most of your comments.

include/clang/AST/RawCommentList.h
13–15

Done.

92

Wait, you mean:

return (Kind == RCK_OrdinaryBCPL) || (Kind == RCK_OrdinaryC) || !ParseAllComments;

But then it skips doxygen style comments when ParseAllComments is false.
Besides I think it should be in isDocumentation because otherwise it will fail to return the comment for a declaration because of the check at line 191 file: ASTContext.cpp.

144

Sure. Done.

145

Done.

145

Done.

146

Done.

lib/AST/RawCommentList.cpp
258

'true' is not necessary, you are right. But 'false' is not correct either. I changed it so that it gets the correct value from RC. I think that should be correct. What do you think?

unittests/Frontend/FrontendActionTest.cpp
103–104 ↗(On Diff #1486)

Done.

108–109 ↗(On Diff #1486)

didn't know about that. Thanks.

amshali added inline comments.Apr 3 2013, 4:03 PM
test/Index/parse-all-comments.c
36

For some reason the out.c-index-pch does not have the I expected.
Running the follwing check fails after this RUN:
// RUN: c-index-test -test-load-tu %t/out.pch all > %t/out.c-index-pch

Can you help me with that? Is it necessary to run the check on out.c-index-pch or out.c-index-direct good enough?

Hi
No rush, but I was wondering if you or someone could take another look at this. Thank you.

Please also mention this new command line option in the documentation. http://clang.llvm.org/docs/UsersManual.html should be a good place. Add a new section about documentation comments if this does not fall naturally into existing sections.

include/clang/AST/RawCommentList.h
92

Yes, that line is incorrect. The correct should be:

return ((Kind == RCK_OrdinaryBCPL) || (Kind == RCK_OrdinaryC)) && !ParseAllComments;

Does this fix the issue in ASTContext?

144

Also mention /* ... */ comments.

include/clang/Basic/CommentOptions.h
31–32

Serialization/deserialization code is missing. Grep for BlockCommandNames to find the relevant places.

lib/AST/RawCommentList.cpp
232

Why this change? isOrdinary() should be the exact opposite of isDocumentation() (modulo invalid cases).

test/Index/parse-all-comments.c
7–8

Please add a test that consecutive '//' comments are merged. See isdoxy20 in the original test for an idea.

36

Yes, pch usecase is important. This error is caused by missing serialization/deserialization code in lib/Serialization/ASTReader.cpp and lib/Serialization/ASTWriter.cpp.

amshali updated this revision to Unknown Object (????).Apr 9 2013, 11:30 AM

Applied comments. Fixed isOrdinary and isDocumentation comments with the right logic for parsing all comments. Reverted the change in RawCommentList.cpp regarding isOrdinary. Added some new tests. Added the pch tests. Updated user manual with a section for comment processing options. Fixed up the serialization code for comment options.

Thank you for comments and help. Updated UsersManual.rst with a new section for comment processing options. Please take a look.

include/clang/AST/RawCommentList.h
92

Since isDocumentation is the opposite of isOrdinary, I need to change both for whole thing to work fine.

144

Done.

include/clang/Basic/CommentOptions.h
31–32

Done. Thanks.

lib/AST/RawCommentList.cpp
232

Reverted. Fixed isOrdinary and isDocumentation. PTAL.

test/Index/parse-all-comments.c
7–8

Added.

36

Thanks. Done.

This patch looks good, I have just a few style remarks.

docs/UsersManual.rst
1318

Please spell Doxygen with a capital 'D'.

1325–1326

Maybe:

Clang will parse all comments as documentation comments (including ordinary comments starting with `//` and `/*`).
include/clang/AST/RawCommentList.h
44–45

I think these default arguments are unused now. If they are, please remove them.

87–88

LLVM and Clang style is to leave '&&' on the previous line.

145–147

Please put two slashes on the second line (to turn this into a documentation comment). Also put a blank line before this comment.

include/clang/Basic/CommentOptions.h
31–32

Please spell 'documentation comments' completely.

amshali updated this revision to Unknown Object (????).Apr 9 2013, 1:33 PM

Removed default parameter from RawComment constructor. Fixed users manual text. Fixed comments. Fixed the if condition style.

Thanks. Applied your comments. Let me know what should I do next.

docs/UsersManual.rst
1318

Done.

1325–1326

Done.

include/clang/AST/RawCommentList.h
44–45

Done.

87–88

Done.

145–147

Done.

include/clang/Basic/CommentOptions.h
31–32

Done.

gribozavr accepted this revision.Apr 10 2013, 8:37 AM

Committed r179180, thank you!

Eugene.Zelenko closed this revision.Oct 5 2016, 1:44 PM