aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/Tooling/Refactoring
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/clang/lib/Tooling/Refactoring')
-rw-r--r--contrib/llvm-project/clang/lib/Tooling/Refactoring/ASTSelection.cpp19
-rw-r--r--contrib/llvm-project/clang/lib/Tooling/Refactoring/ASTSelectionRequirements.cpp8
-rw-r--r--contrib/llvm-project/clang/lib/Tooling/Refactoring/AtomicChange.cpp6
-rw-r--r--contrib/llvm-project/clang/lib/Tooling/Refactoring/Extract/Extract.cpp3
-rw-r--r--contrib/llvm-project/clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp3
-rw-r--r--contrib/llvm-project/clang/lib/Tooling/Refactoring/Lookup.cpp16
-rw-r--r--contrib/llvm-project/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp9
-rw-r--r--contrib/llvm-project/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp27
8 files changed, 57 insertions, 34 deletions
diff --git a/contrib/llvm-project/clang/lib/Tooling/Refactoring/ASTSelection.cpp b/contrib/llvm-project/clang/lib/Tooling/Refactoring/ASTSelection.cpp
index 9485c8bc04ad..058574d8ec1a 100644
--- a/contrib/llvm-project/clang/lib/Tooling/Refactoring/ASTSelection.cpp
+++ b/contrib/llvm-project/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/contrib/llvm-project/clang/lib/Tooling/Refactoring/ASTSelectionRequirements.cpp b/contrib/llvm-project/clang/lib/Tooling/Refactoring/ASTSelectionRequirements.cpp
index 70a4df07ea67..0e052bb19768 100644
--- a/contrib/llvm-project/clang/lib/Tooling/Refactoring/ASTSelectionRequirements.cpp
+++ b/contrib/llvm-project/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/contrib/llvm-project/clang/lib/Tooling/Refactoring/AtomicChange.cpp b/contrib/llvm-project/clang/lib/Tooling/Refactoring/AtomicChange.cpp
index 069e9c1eb36e..dfc98355c664 100644
--- a/contrib/llvm-project/clang/lib/Tooling/Refactoring/AtomicChange.cpp
+++ b/contrib/llvm-project/clang/lib/Tooling/Refactoring/AtomicChange.cpp
@@ -1,4 +1,4 @@
-//===--- AtomicChange.cpp - AtomicChange implementation -----------------*- C++ -*-===//
+//===--- AtomicChange.cpp - AtomicChange implementation ---------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -150,7 +150,7 @@ createReplacementsForHeaders(llvm::StringRef FilePath, llvm::StringRef Code,
for (const auto &Change : Changes) {
for (llvm::StringRef Header : Change.getInsertedHeaders()) {
std::string EscapedHeader =
- Header.startswith("<") || Header.startswith("\"")
+ Header.starts_with("<") || Header.starts_with("\"")
? Header.str()
: ("\"" + Header + "\"").str();
std::string ReplacementText = "#include " + EscapedHeader;
@@ -198,7 +198,7 @@ AtomicChange::AtomicChange(const SourceManager &SM,
const FullSourceLoc FullKeyPosition(KeyPosition, SM);
std::pair<FileID, unsigned> FileIDAndOffset =
FullKeyPosition.getSpellingLoc().getDecomposedLoc();
- const FileEntry *FE = SM.getFileEntryForID(FileIDAndOffset.first);
+ OptionalFileEntryRef FE = SM.getFileEntryRefForID(FileIDAndOffset.first);
assert(FE && "Cannot create AtomicChange with invalid location.");
FilePath = std::string(FE->getName());
Key = FilePath + ":" + std::to_string(FileIDAndOffset.second);
diff --git a/contrib/llvm-project/clang/lib/Tooling/Refactoring/Extract/Extract.cpp b/contrib/llvm-project/clang/lib/Tooling/Refactoring/Extract/Extract.cpp
index 402b56109052..d437f4c21f47 100644
--- a/contrib/llvm-project/clang/lib/Tooling/Refactoring/Extract/Extract.cpp
+++ b/contrib/llvm-project/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/contrib/llvm-project/clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp b/contrib/llvm-project/clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
index 5d57ecf90a96..5e69fb805150 100644
--- a/contrib/llvm-project/clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
+++ b/contrib/llvm-project/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());
diff --git a/contrib/llvm-project/clang/lib/Tooling/Refactoring/Lookup.cpp b/contrib/llvm-project/clang/lib/Tooling/Refactoring/Lookup.cpp
index 9468d4d032a7..757fba0404e6 100644
--- a/contrib/llvm-project/clang/lib/Tooling/Refactoring/Lookup.cpp
+++ b/contrib/llvm-project/clang/lib/Tooling/Refactoring/Lookup.cpp
@@ -98,8 +98,8 @@ static StringRef getBestNamespaceSubstr(const DeclContext *DeclA,
// from NewName if it has an identical prefix.
std::string NS =
"::" + cast<NamespaceDecl>(DeclA)->getQualifiedNameAsString() + "::";
- if (NewName.startswith(NS))
- return NewName.substr(NS.size());
+ if (NewName.consume_front(NS))
+ return NewName;
// No match yet. Strip of a namespace from the end of the chain and try
// again. This allows to get optimal qualifications even if the old and new
@@ -128,9 +128,9 @@ static std::string disambiguateSpellingInScope(StringRef Spelling,
StringRef QName,
const DeclContext &UseContext,
SourceLocation UseLoc) {
- assert(QName.startswith("::"));
- assert(QName.endswith(Spelling));
- if (Spelling.startswith("::"))
+ assert(QName.starts_with("::"));
+ assert(QName.ends_with(Spelling));
+ if (Spelling.starts_with("::"))
return std::string(Spelling);
auto UnspelledSpecifier = QName.drop_back(Spelling.size());
@@ -146,7 +146,7 @@ static std::string disambiguateSpellingInScope(StringRef Spelling,
UseLoc = SM.getSpellingLoc(UseLoc);
auto IsAmbiguousSpelling = [&](const llvm::StringRef CurSpelling) {
- if (CurSpelling.startswith("::"))
+ if (CurSpelling.starts_with("::"))
return false;
// Lookup the first component of Spelling in all enclosing namespaces
// and check if there is any existing symbols with the same name but in
@@ -160,7 +160,7 @@ static std::string disambiguateSpellingInScope(StringRef Spelling,
// ambiguous. For example, a reference in a header file should not be
// affected by a potentially ambiguous name in some file that includes
// the header.
- if (!TrimmedQName.startswith(Res->getQualifiedNameAsString()) &&
+ if (!TrimmedQName.starts_with(Res->getQualifiedNameAsString()) &&
SM.isBeforeInTranslationUnit(
SM.getSpellingLoc(Res->getLocation()), UseLoc))
return true;
@@ -187,7 +187,7 @@ std::string tooling::replaceNestedName(const NestedNameSpecifier *Use,
const DeclContext *UseContext,
const NamedDecl *FromDecl,
StringRef ReplacementString) {
- assert(ReplacementString.startswith("::") &&
+ assert(ReplacementString.starts_with("::") &&
"Expected fully-qualified name!");
// We can do a raw name replacement when we are not inside the namespace for
diff --git a/contrib/llvm-project/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp b/contrib/llvm-project/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
index a69b76a3c971..7708fea53d01 100644
--- a/contrib/llvm-project/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
+++ b/contrib/llvm-project/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
@@ -145,14 +145,12 @@ private:
void handleVarTemplateDecl(const VarTemplateDecl *VTD) {
USRSet.insert(getUSRForDecl(VTD));
USRSet.insert(getUSRForDecl(VTD->getTemplatedDecl()));
- llvm::for_each(VTD->specializations(), [&](const auto *Spec) {
+ for (const auto *Spec : VTD->specializations())
USRSet.insert(getUSRForDecl(Spec));
- });
SmallVector<VarTemplatePartialSpecializationDecl *, 4> PartialSpecs;
VTD->getPartialSpecializations(PartialSpecs);
- llvm::for_each(PartialSpecs, [&](const auto *Spec) {
+ for (const auto *Spec : PartialSpecs)
USRSet.insert(getUSRForDecl(Spec));
- });
}
void addUSRsOfCtorDtors(const CXXRecordDecl *RD) {
@@ -245,7 +243,8 @@ private:
DiagnosticsEngine::Error,
"SourceLocation in file %0 at offset %1 is invalid");
Engine.Report(SourceLocation(), InvalidOffset)
- << SourceMgr.getFileEntryForID(MainFileID)->getName() << SymbolOffset;
+ << SourceMgr.getFileEntryRefForID(MainFileID)->getName()
+ << SymbolOffset;
return false;
}
diff --git a/contrib/llvm-project/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp b/contrib/llvm-project/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
index 6a08c7fd5247..c18f9290471f 100644
--- a/contrib/llvm-project/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
+++ b/contrib/llvm-project/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
@@ -226,6 +226,25 @@ public:
return true;
}
+ bool VisitDesignatedInitExpr(const DesignatedInitExpr *E) {
+ for (const DesignatedInitExpr::Designator &D : E->designators()) {
+ if (D.isFieldDesignator()) {
+ if (const FieldDecl *Decl = D.getFieldDecl()) {
+ if (isInUSRSet(Decl)) {
+ auto StartLoc = D.getFieldLoc();
+ auto EndLoc = D.getFieldLoc();
+ RenameInfos.push_back({StartLoc, EndLoc,
+ /*FromDecl=*/nullptr,
+ /*Context=*/nullptr,
+ /*Specifier=*/nullptr,
+ /*IgnorePrefixQualifiers=*/true});
+ }
+ }
+ }
+ }
+ return true;
+ }
+
bool VisitCXXConstructorDecl(const CXXConstructorDecl *CD) {
// Fix the constructor initializer when renaming class members.
for (const auto *Initializer : CD->inits()) {
@@ -543,8 +562,8 @@ createRenameAtomicChanges(llvm::ArrayRef<std::string> USRs,
ReplacedName = tooling::replaceNestedName(
RenameInfo.Specifier, RenameInfo.Begin,
RenameInfo.Context->getDeclContext(), RenameInfo.FromDecl,
- NewName.startswith("::") ? NewName.str()
- : ("::" + NewName).str());
+ NewName.starts_with("::") ? NewName.str()
+ : ("::" + NewName).str());
} else {
// This fixes the case where type `T` is a parameter inside a function
// type (e.g. `std::function<void(T)>`) and the DeclContext of `T`
@@ -559,13 +578,13 @@ createRenameAtomicChanges(llvm::ArrayRef<std::string> USRs,
SM, TranslationUnitDecl->getASTContext().getLangOpts());
// Add the leading "::" back if the name written in the code contains
// it.
- if (ActualName.startswith("::") && !NewName.startswith("::")) {
+ if (ActualName.starts_with("::") && !NewName.starts_with("::")) {
ReplacedName = "::" + NewName.str();
}
}
}
// If the NewName contains leading "::", add it back.
- if (NewName.startswith("::") && NewName.substr(2) == ReplacedName)
+ if (NewName.starts_with("::") && NewName.substr(2) == ReplacedName)
ReplacedName = NewName.str();
}
Replace(RenameInfo.Begin, RenameInfo.End, ReplacedName);