Skip to content

[Clang] Fix LibTooling doc #90441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2024
Merged

Conversation

maxmosk
Copy link
Contributor

@maxmosk maxmosk commented Apr 29, 2024

Replace CommonOptionsParser ctor by factory method ::create.

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

Copy link

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 llvmbot added the clang Clang issues not falling into any other category label Apr 29, 2024
@llvmbot
Copy link
Member

llvmbot commented Apr 29, 2024

@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 --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<clang::SyntaxOnlyAction>().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<SyntaxOnlyAction>().get());
 /// }
 /// \endcode

Copy link
Member

@Sirraide Sirraide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for improving our documentation!

There’s some error handling missing here. The CommonOptionsParser constructor would previously just exit, but that is no longer the case here, so we actually need to handle errors now.

@Sirraide
Copy link
Member

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

@maxmosk
Copy link
Contributor Author

maxmosk commented Apr 29, 2024

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
Copy link
Member

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 maxmosk force-pushed the moskalets/libtooling/fix-doc branch from ed05f89 to a09f0c8 Compare April 30, 2024 09:57
@maxmosk
Copy link
Contributor Author

maxmosk commented Apr 30, 2024

@Sirraide updated with header doc fix, please review

Copy link
Member

@Sirraide Sirraide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM seeing as this matches what’s already in the documentation.

Copy link

github-actions bot commented Apr 30, 2024

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

@Sirraide
Copy link
Member

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.

Synchronize the example in LibTooling documentation and header CommonOptionsParser.h
@maxmosk maxmosk force-pushed the moskalets/libtooling/fix-doc branch from a09f0c8 to 723b4be Compare April 30, 2024 12:59
@Sirraide Sirraide merged commit 1c17252 into llvm:main Apr 30, 2024
Copy link

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants