[clang] [Clang] Fix LibTooling doc (PR #90441)
Maxim Moskalets via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 29 01:43:34 PDT 2024
https://github.com/maxmosk created https://github.com/llvm/llvm-project/pull/90441
Replace CommonOptionsParser ctor by factory method ::create.
Found on page https://clang.llvm.org/docs/LibTooling.html
>From ed05f896b39f4bd6feb6fa01375d3971064b15fb Mon Sep 17 00:00:00 2001
From: Maxim Moskalets <Maxim.Moskalets at kaspersky.com>
Date: Mon, 29 Apr 2024 11:39:10 +0300
Subject: [PATCH] [Clang] Fix LibTooling doc
Replace CommonOptionsParser ctor by factory method ::create.
---
clang/docs/LibTooling.rst | 12 ++++++------
clang/include/clang/Tooling/CommonOptionsParser.h | 6 +++---
2 files changed, 9 insertions(+), 9 deletions(-)
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
More information about the cfe-commits
mailing list