aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/AST/CXXInheritance.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/clang/lib/AST/CXXInheritance.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/AST/CXXInheritance.cpp150
1 files changed, 35 insertions, 115 deletions
diff --git a/contrib/llvm-project/clang/lib/AST/CXXInheritance.cpp b/contrib/llvm-project/clang/lib/AST/CXXInheritance.cpp
index 8af97119e3cf..c87bcf31d120 100644
--- a/contrib/llvm-project/clang/lib/AST/CXXInheritance.cpp
+++ b/contrib/llvm-project/clang/lib/AST/CXXInheritance.cpp
@@ -33,29 +33,6 @@
using namespace clang;
-/// Computes the set of declarations referenced by these base
-/// paths.
-void CXXBasePaths::ComputeDeclsFound() {
- assert(NumDeclsFound == 0 && !DeclsFound &&
- "Already computed the set of declarations");
-
- llvm::SmallSetVector<NamedDecl *, 8> Decls;
- for (paths_iterator Path = begin(), PathEnd = end(); Path != PathEnd; ++Path)
- Decls.insert(Path->Decls.front());
-
- NumDeclsFound = Decls.size();
- DeclsFound = std::make_unique<NamedDecl *[]>(NumDeclsFound);
- std::copy(Decls.begin(), Decls.end(), DeclsFound.get());
-}
-
-CXXBasePaths::decl_range CXXBasePaths::found_decls() {
- if (NumDeclsFound == 0)
- ComputeDeclsFound();
-
- return decl_range(decl_iterator(DeclsFound.get()),
- decl_iterator(DeclsFound.get() + NumDeclsFound));
-}
-
/// isAmbiguous - Determines whether the set of paths provided is
/// ambiguous, i.e., there are two or more paths that refer to
/// different base class subobjects of the same type. BaseType must be
@@ -402,54 +379,45 @@ bool CXXRecordDecl::FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
->getCanonicalDecl() == BaseRecord;
}
-bool CXXRecordDecl::FindTagMember(const CXXBaseSpecifier *Specifier,
- CXXBasePath &Path,
- DeclarationName Name) {
- RecordDecl *BaseRecord =
- Specifier->getType()->castAs<RecordType>()->getDecl();
-
- for (Path.Decls = BaseRecord->lookup(Name);
- !Path.Decls.empty();
- Path.Decls = Path.Decls.slice(1)) {
- if (Path.Decls.front()->isInIdentifierNamespace(IDNS_Tag))
- return true;
- }
-
- return false;
+static bool isOrdinaryMember(const NamedDecl *ND) {
+ return ND->isInIdentifierNamespace(Decl::IDNS_Ordinary | Decl::IDNS_Tag |
+ Decl::IDNS_Member);
}
-static bool findOrdinaryMember(RecordDecl *BaseRecord, CXXBasePath &Path,
+static bool findOrdinaryMember(const CXXRecordDecl *RD, CXXBasePath &Path,
DeclarationName Name) {
- const unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_Tag |
- Decl::IDNS_Member;
- for (Path.Decls = BaseRecord->lookup(Name);
- !Path.Decls.empty();
- Path.Decls = Path.Decls.slice(1)) {
- if (Path.Decls.front()->isInIdentifierNamespace(IDNS))
+ Path.Decls = RD->lookup(Name);
+ for (NamedDecl *ND : Path.Decls)
+ if (isOrdinaryMember(ND))
return true;
- }
return false;
}
-bool CXXRecordDecl::FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
- CXXBasePath &Path,
- DeclarationName Name) {
- RecordDecl *BaseRecord =
- Specifier->getType()->castAs<RecordType>()->getDecl();
- return findOrdinaryMember(BaseRecord, Path, Name);
+bool CXXRecordDecl::hasMemberName(DeclarationName Name) const {
+ CXXBasePath P;
+ if (findOrdinaryMember(this, P, Name))
+ return true;
+
+ CXXBasePaths Paths(false, false, false);
+ return lookupInBases(
+ [Name](const CXXBaseSpecifier *Specifier, CXXBasePath &Path) {
+ return findOrdinaryMember(Specifier->getType()->getAsCXXRecordDecl(),
+ Path, Name);
+ },
+ Paths);
}
-bool CXXRecordDecl::FindOrdinaryMemberInDependentClasses(
- const CXXBaseSpecifier *Specifier, CXXBasePath &Path,
- DeclarationName Name) {
+static bool
+findOrdinaryMemberInDependentClasses(const CXXBaseSpecifier *Specifier,
+ CXXBasePath &Path, DeclarationName Name) {
const TemplateSpecializationType *TST =
Specifier->getType()->getAs<TemplateSpecializationType>();
if (!TST) {
auto *RT = Specifier->getType()->getAs<RecordType>();
if (!RT)
return false;
- return findOrdinaryMember(RT->getDecl(), Path, Name);
+ return findOrdinaryMember(cast<CXXRecordDecl>(RT->getDecl()), Path, Name);
}
TemplateName TN = TST->getTemplateName();
const auto *TD = dyn_cast_or_null<ClassTemplateDecl>(TN.getAsTemplateDecl());
@@ -461,80 +429,32 @@ bool CXXRecordDecl::FindOrdinaryMemberInDependentClasses(
return findOrdinaryMember(RD, Path, Name);
}
-bool CXXRecordDecl::FindOMPReductionMember(const CXXBaseSpecifier *Specifier,
- CXXBasePath &Path,
- DeclarationName Name) {
- RecordDecl *BaseRecord =
- Specifier->getType()->castAs<RecordType>()->getDecl();
-
- for (Path.Decls = BaseRecord->lookup(Name); !Path.Decls.empty();
- Path.Decls = Path.Decls.slice(1)) {
- if (Path.Decls.front()->isInIdentifierNamespace(IDNS_OMPReduction))
- return true;
- }
-
- return false;
-}
-
-bool CXXRecordDecl::FindOMPMapperMember(const CXXBaseSpecifier *Specifier,
- CXXBasePath &Path,
- DeclarationName Name) {
- RecordDecl *BaseRecord =
- Specifier->getType()->castAs<RecordType>()->getDecl();
-
- for (Path.Decls = BaseRecord->lookup(Name); !Path.Decls.empty();
- Path.Decls = Path.Decls.slice(1)) {
- if (Path.Decls.front()->isInIdentifierNamespace(IDNS_OMPMapper))
- return true;
- }
-
- return false;
-}
-
-bool CXXRecordDecl::
-FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier,
- CXXBasePath &Path,
- DeclarationName Name) {
- RecordDecl *BaseRecord =
- Specifier->getType()->castAs<RecordType>()->getDecl();
-
- for (Path.Decls = BaseRecord->lookup(Name);
- !Path.Decls.empty();
- Path.Decls = Path.Decls.slice(1)) {
- // FIXME: Refactor the "is it a nested-name-specifier?" check
- if (isa<TypedefNameDecl>(Path.Decls.front()) ||
- Path.Decls.front()->isInIdentifierNamespace(IDNS_Tag))
- return true;
- }
-
- return false;
-}
-
std::vector<const NamedDecl *> CXXRecordDecl::lookupDependentName(
- const DeclarationName &Name,
+ DeclarationName Name,
llvm::function_ref<bool(const NamedDecl *ND)> Filter) {
std::vector<const NamedDecl *> Results;
// Lookup in the class.
- DeclContext::lookup_result DirectResult = lookup(Name);
- if (!DirectResult.empty()) {
- for (const NamedDecl *ND : DirectResult) {
- if (Filter(ND))
- Results.push_back(ND);
- }
- return Results;
+ bool AnyOrdinaryMembers = false;
+ for (const NamedDecl *ND : lookup(Name)) {
+ if (isOrdinaryMember(ND))
+ AnyOrdinaryMembers = true;
+ if (Filter(ND))
+ Results.push_back(ND);
}
+ if (AnyOrdinaryMembers)
+ return Results;
+
// Perform lookup into our base classes.
CXXBasePaths Paths;
Paths.setOrigin(this);
if (!lookupInBases(
[&](const CXXBaseSpecifier *Specifier, CXXBasePath &Path) {
- return CXXRecordDecl::FindOrdinaryMemberInDependentClasses(
- Specifier, Path, Name);
+ return findOrdinaryMemberInDependentClasses(Specifier, Path, Name);
},
Paths, /*LookupInDependent=*/true))
return Results;
for (const NamedDecl *ND : Paths.front().Decls) {
- if (Filter(ND))
+ if (isOrdinaryMember(ND) && Filter(ND))
Results.push_back(ND);
}
return Results;