[clang] 7a11eb9 - [clang] NFC: NNS getLocalSourceRange user cleanup (#163206)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 13 09:16:29 PDT 2025
Author: Matheus Izvekov
Date: 2025-10-13T13:16:25-03:00
New Revision: 7a11eb96d591e980f347c01b8a559da441164bf8
URL: https://github.com/llvm/llvm-project/commit/7a11eb96d591e980f347c01b8a559da441164bf8
DIFF: https://github.com/llvm/llvm-project/commit/7a11eb96d591e980f347c01b8a559da441164bf8.diff
LOG: [clang] NFC: NNS getLocalSourceRange user cleanup (#163206)
This adds a note to the documentation of getLocalSourceRange, and cleans
up one of the users of this function which was changed in
https://github.com/llvm/llvm-project/pull/147835
This also removes `TypeLoc::getNonPrefixBeginLoc`, which was recently
introduced in the above patch, as that became unused.
Added:
Modified:
clang-tools-extra/clangd/FindTarget.cpp
clang/include/clang/AST/NestedNameSpecifierBase.h
clang/include/clang/AST/TypeLoc.h
clang/lib/AST/TypeLoc.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp
index 8aae41420b83e..799c64b8dab4d 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -1040,16 +1040,11 @@ class ExplicitReferenceCollector
if (auto *S = N.get<Stmt>())
return refInStmt(S, Resolver);
if (auto *NNSL = N.get<NestedNameSpecifierLoc>()) {
+ if (auto TL = NNSL->getAsTypeLoc())
+ return refInTypeLoc(NNSL->getAsTypeLoc(), Resolver);
// (!) 'DeclRelation::Alias' ensures we do not lose namespace aliases.
- NestedNameSpecifierLoc Qualifier;
- SourceLocation NameLoc;
- if (auto TL = NNSL->getAsTypeLoc()) {
- Qualifier = TL.getPrefix();
- NameLoc = TL.getNonPrefixBeginLoc();
- } else {
- Qualifier = NNSL->getAsNamespaceAndPrefix().Prefix;
- NameLoc = NNSL->getLocalBeginLoc();
- }
+ NestedNameSpecifierLoc Qualifier = NNSL->getAsNamespaceAndPrefix().Prefix;
+ SourceLocation NameLoc = NNSL->getLocalBeginLoc();
return {
ReferenceLoc{Qualifier, NameLoc, false,
explicitReferenceTargets(
diff --git a/clang/include/clang/AST/NestedNameSpecifierBase.h b/clang/include/clang/AST/NestedNameSpecifierBase.h
index 73c60ba695419..8f4bbe97f6e9a 100644
--- a/clang/include/clang/AST/NestedNameSpecifierBase.h
+++ b/clang/include/clang/AST/NestedNameSpecifierBase.h
@@ -361,6 +361,9 @@ class NestedNameSpecifierLoc {
/// Retrieve the source range covering just the last part of
/// this nested-name-specifier, not including the prefix.
///
+ /// Note that this is the source range of this NestedNameSpecifier chunk,
+ /// and for a type this includes the prefix of that type.
+ ///
/// For example, if this instance refers to a nested-name-specifier
/// \c \::std::vector<int>::, the returned source range would cover
/// from "vector" to the last '::'.
diff --git a/clang/include/clang/AST/TypeLoc.h b/clang/include/clang/AST/TypeLoc.h
index 38e8fba569396..3f14ee86d55b1 100644
--- a/clang/include/clang/AST/TypeLoc.h
+++ b/clang/include/clang/AST/TypeLoc.h
@@ -198,11 +198,6 @@ class TypeLoc {
/// "foo::bar". Returns null if this type represents an unqualified-id.
NestedNameSpecifierLoc getPrefix() const;
- /// This returns the position of the type after any elaboration, such as the
- /// 'struct' keyword, and name qualifiers. This will the 'template' keyword if
- /// present, or the name location otherwise.
- SourceLocation getNonPrefixBeginLoc() const;
-
/// This returns the position of the type after any elaboration, such as the
/// 'struct' keyword. This may be the position of the name qualifiers,
/// 'template' keyword, or the name location otherwise.
diff --git a/clang/lib/AST/TypeLoc.cpp b/clang/lib/AST/TypeLoc.cpp
index 55476e2175a1f..e952e82031976 100644
--- a/clang/lib/AST/TypeLoc.cpp
+++ b/clang/lib/AST/TypeLoc.cpp
@@ -494,39 +494,6 @@ NestedNameSpecifierLoc TypeLoc::getPrefix() const {
}
}
-SourceLocation TypeLoc::getNonPrefixBeginLoc() const {
- switch (getTypeLocClass()) {
- case TypeLoc::TemplateSpecialization: {
- auto TL = castAs<TemplateSpecializationTypeLoc>();
- SourceLocation Loc = TL.getTemplateKeywordLoc();
- if (!Loc.isValid())
- Loc = TL.getTemplateNameLoc();
- return Loc;
- }
- case TypeLoc::DeducedTemplateSpecialization: {
- auto TL = castAs<DeducedTemplateSpecializationTypeLoc>();
- SourceLocation Loc = TL.getTemplateKeywordLoc();
- if (!Loc.isValid())
- Loc = TL.getTemplateNameLoc();
- return Loc;
- }
- case TypeLoc::DependentName:
- return castAs<DependentNameTypeLoc>().getNameLoc();
- case TypeLoc::Enum:
- case TypeLoc::Record:
- case TypeLoc::InjectedClassName:
- return castAs<TagTypeLoc>().getNameLoc();
- case TypeLoc::Typedef:
- return castAs<TypedefTypeLoc>().getNameLoc();
- case TypeLoc::UnresolvedUsing:
- return castAs<UnresolvedUsingTypeLoc>().getNameLoc();
- case TypeLoc::Using:
- return castAs<UsingTypeLoc>().getNameLoc();
- default:
- return getBeginLoc();
- }
-}
-
SourceLocation TypeLoc::getNonElaboratedBeginLoc() const {
// For elaborated types (e.g. `struct a::A`) we want the portion after the
// `struct` but including the namespace qualifier, `a::`.
More information about the cfe-commits
mailing list