Skip to content

Commit 6fa59e4

Browse files
committed
Fix failing tests in clang/test/Refactor
The tests started failing after the following PR was merged: llvm#147835 rdar://159140646
1 parent 99bff65 commit 6fa59e4

File tree

4 files changed

+35
-33
lines changed

4 files changed

+35
-33
lines changed

clang/lib/Tooling/Refactor/FillInEnumSwitchCases.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,12 @@ clang::tooling::initiateFillInEnumSwitchCasesOperation(
8080

8181
if (!ED)
8282
return RefactoringOperationResult("The switch doesn't operate on an enum");
83-
if (!ED->isCompleteDefinition())
84-
return RefactoringOperationResult("The enum type is incomplete");
83+
84+
if (!ED->isCompleteDefinition()) {
85+
ED = ED->getDefinition();
86+
if (!ED)
87+
return RefactoringOperationResult("The enum type is incomplete");
88+
}
8589

8690
if (Switch->isAllEnumCasesCovered())
8791
return RefactoringOperationResult("All enum cases are already covered");

clang/lib/Tooling/Refactor/ImplementDeclaredMethods.cpp

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -262,35 +262,42 @@ ImplementDeclaredCXXMethodsOperation::runInImplementationAST(
262262
std::string MethodString;
263263
llvm::raw_string_ostream OS(MethodString);
264264

265+
PrintingPolicy PP = Context.getPrintingPolicy();
266+
PP.PolishForDeclaration = true;
267+
PP.SupressStorageClassSpecifiers = true;
268+
PP.SuppressStrongLifetime = true;
269+
PP.SuppressLifetimeQualifiers = true;
270+
PP.SuppressUnwrittenScope = true;
271+
272+
// Callback class for skipping namespaces.
273+
class Callbacks final : public PrintingCallbacks {
274+
public:
275+
bool isScopeVisible(const DeclContext *DC) const override {
276+
return DC->getDeclKind() == Decl::Namespace;
277+
}
278+
} CB;
279+
265280
// Pick a good insertion location.
266281
SourceLocation InsertionLoc;
267282
const CXXMethodDecl *InsertAfterMethod = nullptr;
268-
std::optional<NestedNameSpecifier> NamePrefix = std::nullopt;
269283
if (DefinedOutOfLineMethods.empty()) {
284+
PP.Callbacks = &CB;
270285
const RecordDecl *OutermostRecord = findOutermostRecord(Class);
271286
InsertionLoc = SM.getExpansionRange(OutermostRecord->getEndLoc()).getEnd();
272287
if (SM.getFileID(InsertionLoc) == File) {
273-
// We can insert right after the class. Compute the appropriate
274-
// qualification.
275-
NamePrefix = NestedNameSpecifier::getRequiredQualification(
276-
Context, OutermostRecord->getLexicalDeclContext(),
277-
Class->getLexicalDeclContext());
288+
// We can insert right after the class.
278289
} else {
279290
// We can't insert after the end of the class, since the indexer told us
280291
// that some file should have the implementation of it, even when there
281292
// are no methods here. We should try to insert at the end of the file.
282293
InsertionLoc = SM.getLocForEndOfFile(File);
283-
NamePrefix = NestedNameSpecifier::getRequiredQualification(
284-
Context, Context.getTranslationUnitDecl(),
285-
Class->getLexicalDeclContext());
286294
llvm::SmallVector<const NamespaceDecl *, 4> Namespaces;
287-
std::optional<NestedNameSpecifier> Qualifier = NamePrefix;
288-
while (Qualifier) {
289-
auto [ND, Prefix] = Qualifier->getAsNamespaceAndPrefix();
290-
if (ND)
291-
Namespaces.push_back(ND->getNamespace());
292-
Qualifier = Prefix;
293-
}
295+
296+
for (const DeclContext *DC = OutermostRecord->getLexicalDeclContext(); DC;
297+
DC = DC->getLookupParent())
298+
if (auto *ND = dyn_cast<NamespaceDecl>(DC))
299+
Namespaces.push_back(ND);
300+
294301
// When the class is in a namespace, add a 'using' declaration if it's
295302
// needed and adjust the out-of-line qualification.
296303
if (!Namespaces.empty()) {
@@ -305,9 +312,6 @@ ImplementDeclaredCXXMethodsOperation::runInImplementationAST(
305312
}
306313
OS << "\nusing namespace " << NamespaceOS.str() << ";";
307314
}
308-
// Re-compute the name qualifier without the namespace.
309-
NamePrefix = NestedNameSpecifier::getRequiredQualification(
310-
Context, InnermostNamespace, Class->getLexicalDeclContext());
311315
}
312316
}
313317
} else {
@@ -324,12 +328,6 @@ ImplementDeclaredCXXMethodsOperation::runInImplementationAST(
324328
InsertionLoc = getLastLineLocationUnlessItHasOtherTokens(
325329
InsertionLoc, SM, Context.getLangOpts());
326330

327-
PrintingPolicy PP = Context.getPrintingPolicy();
328-
PP.PolishForDeclaration = true;
329-
PP.SupressStorageClassSpecifiers = true;
330-
PP.SuppressStrongLifetime = true;
331-
PP.SuppressLifetimeQualifiers = true;
332-
PP.SuppressUnwrittenScope = true;
333331
OS << "\n";
334332
for (const auto &I : SelectedMethods) {
335333
const CXXMethodDecl *MD = I.Decl;

clang/lib/Tooling/Refactor/SymbolOccurrenceFinder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,9 @@ class SymbolOccurrenceFinderASTVisitor
278278
checkDecl(TND, TTL.getNameLoc());
279279
return true;
280280
}
281-
TypeSpecTypeLoc TSTL = Loc.getAs<TypeSpecTypeLoc>();
282-
if (TSTL) {
283-
checkDecl(Loc.getType()->getAsTagDecl(), TSTL.getNameLoc());
281+
TagTypeLoc TagTL = Loc.getAs<TagTypeLoc>();
282+
if (TagTL) {
283+
checkDecl(Loc.getType()->getAsTagDecl(), TagTL.getNameLoc());
284284
}
285285
if (const auto *TemplateTypeParm =
286286
dyn_cast<TemplateTypeParmType>(Loc.getType())) {

clang/lib/Tooling/Refactor/USRFinder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,9 @@ class NamedDeclFindingASTVisitor
317317
}
318318
return checkOccurrence(TND, TTL.getNameLoc());
319319
}
320-
TypeSpecTypeLoc TSTL = Loc.getAs<TypeSpecTypeLoc>();
321-
if (TSTL) {
322-
return checkOccurrence(Loc.getType()->getAsTagDecl(), TSTL.getNameLoc());
320+
TagTypeLoc TagTL = Loc.getAs<TagTypeLoc>();
321+
if (TagTL) {
322+
return checkOccurrence(Loc.getType()->getAsTagDecl(), TagTL.getNameLoc());
323323
}
324324
return true;
325325
}

0 commit comments

Comments
 (0)