-
Notifications
You must be signed in to change notification settings - Fork 14.2k
[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
[Clang] Fix LibTooling doc #90441
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be 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 If you have received no comments on your PR for a week, you can request a review 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. |
@llvm/pr-subscribers-clang Author: Maxim Moskalets (maxmosk) ChangesReplace 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:
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
|
There was a problem hiding this 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.
I also just noticed that there already is a pr for this: #70427. |
This PR wasn't approved and doc is still not fixed :( |
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 |
ed05f89
to
a09f0c8
Compare
@Sirraide updated with header doc fix, please review |
There was a problem hiding this 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.
✅ With the latest revision this PR passed the C/C++ code formatter. |
Right, what |
Synchronize the example in LibTooling documentation and header CommonOptionsParser.h
a09f0c8
to
723b4be
Compare
@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 Please check whether problems have been caused by your change specifically, as 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. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
Replace CommonOptionsParser ctor by factory method ::create.
Found on page https://clang.llvm.org/docs/LibTooling.html