llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.07k stars 11.99k forks source link

Replace /* ... */ single-line comments with // ... comments #24841

Open LegalizeAdulthood opened 9 years ago

LegalizeAdulthood commented 9 years ago
Bugzilla Link 24467
Version unspecified
OS Windows NT

Extended Description

Detect when C-style /.../ block comments are used to create a single-line comment. Replace those block-style comments with // style comments.

Possible false positives:

/* ....\ */

comments could result in a // comment like this:

// ...\

which would escape the newline and be a problem.

LegalizeAdulthood commented 8 years ago

Proposed check name: modernize-use-single-line-comments

llvmbot commented 1 year ago

Hi!

This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:

1) Assign the issue to you. 2) Fix the issue locally. 3) Run the test suite locally. 3.1) Remember that the subdirectories under test/ create fine-grained testing targets, so you can e.g. use make check-clang-ast to only run Clang's AST tests. 4) Create a git commit 5) Run git clang-format HEAD~1 to format your changes. 6) Submit the patch to Phabricator. 6.1) Detailed instructions can be found here

For more instructions on how to submit a patch to LLVM, see our documentation.

If you have any further questions about this issue, don't hesitate to ask via a comment on this Github issue.

@llvm/issue-subscribers-good-first-issue

Endilll commented 1 year ago

@PiotrZSL can you provide some analysis and points of entry into codebase?

PiotrZSL commented 1 year ago

Create new check, call it modernize-use-double-slash-comments, modernize-use-cpp-comment-style or something else.

  1. Register new comment handler in registerPPCallbacks with: PP->addCommentHandler
  2. Implement clang::CommentHandler interface
  3. Read current comment by using StringRef CommentText = Lexer::getSourceText(CharSourceRange::getCharRange(CommentRange), PP.getSourceManager(), PP.getLangOpts());
  4. Verify if its block comment for example matching against regexp: "^[ \t]*/\\*+[ \t\n]*(.*[ \t\n]*)*[ \t\n]*\\*+/[ \t\n]*$" (or implement this in other way)
  5. Add support to exclude some comments that are for example Doxygen comment (regexp) ?
  6. Add option to detect / remove frames (those ***** or #######)
  7. Generate fixes that would replace current comment with new one.
akshaykumars614 commented 1 year ago

I would like to take up the issue if nobody is working as this would be a good start for me to begin llvm. So, please correct me if I am wrong. We have to implement a check that converts /* styled comment that is used for single line to // style. While doing that we have to take care of the like Doxygen comment (as @PiotrZSL mentioned) in clang-tidy.

I am new to this project please help me out.