[clang] [Clang] Fix LibTooling doc (PR #90441)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 29 01:44:19 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Maxim Moskalets (maxmosk)
<details>
<summary>Changes</summary>
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<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
``````````
</details>
https://github.com/llvm/llvm-project/pull/90441
More information about the cfe-commits
mailing list