diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2023-02-11 12:38:04 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2023-02-11 12:38:11 +0000 |
commit | e3b557809604d036af6e00c60f012c2025b59a5e (patch) | |
tree | 8a11ba2269a3b669601e2fd41145b174008f4da8 /clang/lib/Tooling/Refactoring | |
parent | 08e8dd7b9db7bb4a9de26d44c1cbfd24e869c014 (diff) |
Diffstat (limited to 'clang/lib/Tooling/Refactoring')
4 files changed, 19 insertions, 14 deletions
diff --git a/clang/lib/Tooling/Refactoring/ASTSelection.cpp b/clang/lib/Tooling/Refactoring/ASTSelection.cpp index 9485c8bc04ad..058574d8ec1a 100644 --- a/clang/lib/Tooling/Refactoring/ASTSelection.cpp +++ b/clang/lib/Tooling/Refactoring/ASTSelection.cpp @@ -10,6 +10,7 @@ #include "clang/AST/LexicallyOrderedRecursiveASTVisitor.h" #include "clang/Lex/Lexer.h" #include "llvm/Support/SaveAndRestore.h" +#include <optional> using namespace clang; using namespace tooling; @@ -50,12 +51,12 @@ public: SourceSelectionKind::None)); } - Optional<SelectedASTNode> getSelectedASTNode() { + std::optional<SelectedASTNode> getSelectedASTNode() { assert(SelectionStack.size() == 1 && "stack was not popped"); SelectedASTNode Result = std::move(SelectionStack.back()); SelectionStack.pop_back(); if (Result.Children.empty()) - return None; + return std::nullopt; return std::move(Result); } @@ -63,14 +64,14 @@ public: // Avoid traversing the semantic expressions. They should be handled by // looking through the appropriate opaque expressions in order to build // a meaningful selection tree. - llvm::SaveAndRestore<bool> LookThrough(LookThroughOpaqueValueExprs, true); + llvm::SaveAndRestore LookThrough(LookThroughOpaqueValueExprs, true); return TraverseStmt(E->getSyntacticForm()); } bool TraverseOpaqueValueExpr(OpaqueValueExpr *E) { if (!LookThroughOpaqueValueExprs) return true; - llvm::SaveAndRestore<bool> LookThrough(LookThroughOpaqueValueExprs, false); + llvm::SaveAndRestore LookThrough(LookThroughOpaqueValueExprs, false); return TraverseStmt(E->getSourceExpr()); } @@ -178,7 +179,7 @@ private: } // end anonymous namespace -Optional<SelectedASTNode> +std::optional<SelectedASTNode> clang::tooling::findSelectedASTNodes(const ASTContext &Context, SourceRange SelectionRange) { assert(SelectionRange.isValid() && @@ -375,22 +376,22 @@ static void findDeepestWithKind( findDeepestWithKind(ASTSelection, MatchingNodes, Kind, ParentStack); } -Optional<CodeRangeASTSelection> +std::optional<CodeRangeASTSelection> CodeRangeASTSelection::create(SourceRange SelectionRange, const SelectedASTNode &ASTSelection) { // Code range is selected when the selection range is not empty. if (SelectionRange.getBegin() == SelectionRange.getEnd()) - return None; + return std::nullopt; llvm::SmallVector<SelectedNodeWithParents, 4> ContainSelection; findDeepestWithKind(ASTSelection, ContainSelection, SourceSelectionKind::ContainsSelection); // We are looking for a selection in one body of code, so let's focus on // one matching result. if (ContainSelection.size() != 1) - return None; + return std::nullopt; SelectedNodeWithParents &Selected = ContainSelection[0]; if (!Selected.Node.get().Node.get<Stmt>()) - return None; + return std::nullopt; const Stmt *CodeRangeStmt = Selected.Node.get().Node.get<Stmt>(); if (!isa<CompoundStmt>(CodeRangeStmt)) { Selected.canonicalize(); diff --git a/clang/lib/Tooling/Refactoring/ASTSelectionRequirements.cpp b/clang/lib/Tooling/Refactoring/ASTSelectionRequirements.cpp index 70a4df07ea67..0e052bb19768 100644 --- a/clang/lib/Tooling/Refactoring/ASTSelectionRequirements.cpp +++ b/clang/lib/Tooling/Refactoring/ASTSelectionRequirements.cpp @@ -8,6 +8,7 @@ #include "clang/Tooling/Refactoring/RefactoringActionRuleRequirements.h" #include "clang/AST/Attr.h" +#include <optional> using namespace clang; using namespace tooling; @@ -20,7 +21,7 @@ ASTSelectionRequirement::evaluate(RefactoringRuleContext &Context) const { if (!Range) return Range.takeError(); - Optional<SelectedASTNode> Selection = + std::optional<SelectedASTNode> Selection = findSelectedASTNodes(Context.getASTContext(), *Range); if (!Selection) return Context.createDiagnosticError( @@ -37,8 +38,9 @@ Expected<CodeRangeASTSelection> CodeRangeASTSelectionRequirement::evaluate( return ASTSelection.takeError(); std::unique_ptr<SelectedASTNode> StoredSelection = std::make_unique<SelectedASTNode>(std::move(*ASTSelection)); - Optional<CodeRangeASTSelection> CodeRange = CodeRangeASTSelection::create( - Context.getSelectionRange(), *StoredSelection); + std::optional<CodeRangeASTSelection> CodeRange = + CodeRangeASTSelection::create(Context.getSelectionRange(), + *StoredSelection); if (!CodeRange) return Context.createDiagnosticError( Context.getSelectionRange().getBegin(), diff --git a/clang/lib/Tooling/Refactoring/Extract/Extract.cpp b/clang/lib/Tooling/Refactoring/Extract/Extract.cpp index 402b56109052..d437f4c21f47 100644 --- a/clang/lib/Tooling/Refactoring/Extract/Extract.cpp +++ b/clang/lib/Tooling/Refactoring/Extract/Extract.cpp @@ -19,6 +19,7 @@ #include "clang/AST/ExprObjC.h" #include "clang/Rewrite/Core/Rewriter.h" #include "clang/Tooling/Refactoring/Extract/SourceExtraction.h" +#include <optional> namespace clang { namespace tooling { @@ -68,7 +69,7 @@ const RefactoringDescriptor &ExtractFunction::describe() { Expected<ExtractFunction> ExtractFunction::initiate(RefactoringRuleContext &Context, CodeRangeASTSelection Code, - Optional<std::string> DeclName) { + std::optional<std::string> DeclName) { // We would like to extract code out of functions/methods/blocks. // Prohibit extraction from things like global variable / field // initializers and other top-level expressions. diff --git a/clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp b/clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp index 5d57ecf90a96..5e69fb805150 100644 --- a/clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp +++ b/clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp @@ -12,6 +12,7 @@ #include "clang/AST/StmtObjC.h" #include "clang/Basic/SourceManager.h" #include "clang/Lex/Lexer.h" +#include <optional> using namespace clang; @@ -100,7 +101,7 @@ ExtractionSemicolonPolicy::compute(const Stmt *S, SourceRange &ExtractedRange, /// Other statements should generally have a trailing ';'. We can try to find /// it and move it together it with the extracted code. - Optional<Token> NextToken = Lexer::findNextToken(End, SM, LangOpts); + std::optional<Token> NextToken = Lexer::findNextToken(End, SM, LangOpts); if (NextToken && NextToken->is(tok::semi) && areOnSameLine(NextToken->getLocation(), End, SM)) { ExtractedRange.setEnd(NextToken->getLocation()); |