llvm / llvm-project

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

[Clang] Fix LibTooling doc #90441

Closed maxmosk closed 2 weeks ago

maxmosk commented 2 weeks ago

Replace CommonOptionsParser ctor by factory method ::create.

Found on page https://clang.llvm.org/docs/LibTooling.html

github-actions[bot] commented 2 weeks ago

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

llvmbot commented 2 weeks ago

@llvm/pr-subscribers-clang

Author: Maxim Moskalets (maxmosk)

Changes Replace CommonOptionsParser ctor by factory method ::create. Found on page https://clang.llvm.org/docs/LibTooling.html --- Full diff: https://github.com/llvm/llvm-project/pull/90441.diff 2 Files Affected: - (modified) clang/docs/LibTooling.rst (+6-6) - (modified) clang/include/clang/Tooling/CommonOptionsParser.h (+3-3) ``````````diff diff --git a/clang/docs/LibTooling.rst b/clang/docs/LibTooling.rst index df50dcebf9b83c..d6fd1d99a5c845 100644 --- a/clang/docs/LibTooling.rst +++ b/clang/docs/LibTooling.rst @@ -71,9 +71,9 @@ and automatic location of the compilation database using source files paths. int main(int argc, const char **argv) { // CommonOptionsParser constructor will parse arguments and create a // CompilationDatabase. In case of error it will terminate the program. - CommonOptionsParser OptionsParser(argc, argv, MyToolCategory); + auto OptionsParser = CommonOptionsParser::create(argc, argv, MyToolCategory); - // Use OptionsParser.getCompilations() and OptionsParser.getSourcePathList() + // Use OptionsParser->getCompilations() and OptionsParser->getSourcePathList() // to retrieve CompilationDatabase and the list of input file paths. } @@ -93,7 +93,7 @@ our ``FrontendAction`` over some code. For example, to run the // We hand the CompilationDatabase we created and the sources to run over into // the tool constructor. - ClangTool Tool(OptionsParser.getCompilations(), Sources); + ClangTool Tool(OptionsParser->getCompilations(), Sources); // The ClangTool needs a new FrontendAction for each translation unit we run // on. Thus, it takes a FrontendActionFactory as parameter. To create a @@ -133,9 +133,9 @@ version of this example tool is also checked into the clang tree at static cl::extrahelp MoreHelp("\nMore help text...\n"); int main(int argc, const char **argv) { - CommonOptionsParser OptionsParser(argc, argv, MyToolCategory); - ClangTool Tool(OptionsParser.getCompilations(), - OptionsParser.getSourcePathList()); + auto OptionsParser = CommonOptionsParser::create(argc, argv, MyToolCategory); + ClangTool Tool(OptionsParser->getCompilations(), + OptionsParser->getSourcePathList()); return Tool.run(newFrontendActionFactory().get()); } diff --git a/clang/include/clang/Tooling/CommonOptionsParser.h b/clang/include/clang/Tooling/CommonOptionsParser.h index 3c0480af377943..857dcd23331f87 100644 --- a/clang/include/clang/Tooling/CommonOptionsParser.h +++ b/clang/include/clang/Tooling/CommonOptionsParser.h @@ -56,9 +56,9 @@ namespace tooling { /// ... /// /// int main(int argc, const char **argv) { -/// CommonOptionsParser OptionsParser(argc, argv, MyToolCategory); -/// ClangTool Tool(OptionsParser.getCompilations(), -/// OptionsParser.getSourcePathList()); +/// auto OptionsParser = CommonOptionsParser::create(argc, argv, MyToolCategory); +/// ClangTool Tool(OptionsParser->getCompilations(), +/// OptionsParser->getSourcePathList()); /// return Tool.run(newFrontendActionFactory().get()); /// } /// \endcode ``````````
Sirraide commented 2 weeks ago

I also just noticed that there already is a pr for this: #70427.

maxmosk commented 2 weeks ago

I also just noticed that there already is a pr for this: #70427.

This PR wasn't approved and doc is still not fixed :( What to do with this PR?

Sirraide commented 2 weeks ago

This PR wasn't approved and doc is still not fixed :( What to do with this PR?

It somehow just went unnoticed all this time, unfortunately. I’ll approve the other pr since it seems to do the same thing that we’re also doing somewhere else in our documentation, and it’s pretty much what I suggested here anyway.

The comment in clang/Tooling/CommonOptionsParser.h still needs to be updated, which the other pr doesn’t do; you can still do that if you’d like. Sorry about the entire confusion here; this is something that shouldn’t normally happen...

maxmosk commented 2 weeks ago

@Sirraide updated with header doc fix, please review

github-actions[bot] commented 2 weeks ago

:white_check_mark: With the latest revision this PR passed the C/C++ code formatter.

Sirraide commented 2 weeks ago

Right, what clang-format is suggesting here is a bit bizzare; please reformat the comment manually so every line fits within the 80 column limit.

github-actions[bot] commented 2 weeks ago

@maxmosk Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!