Refactor CXXRecordDecl::lookupInBases() to push the recursion down a
level. No functionality change, and it obeys access control this time. llvm-svn: 97634
This commit is contained in:
parent
db42f3ef2b
commit
0555f7eefa
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#include "clang/AST/DeclarationName.h"
|
#include "clang/AST/DeclarationName.h"
|
||||||
#include "clang/AST/DeclBase.h"
|
#include "clang/AST/DeclBase.h"
|
||||||
|
#include "clang/AST/DeclCXX.h"
|
||||||
#include "clang/AST/Type.h"
|
#include "clang/AST/Type.h"
|
||||||
#include "clang/AST/TypeOrdering.h"
|
#include "clang/AST/TypeOrdering.h"
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
|
@ -159,7 +160,11 @@ class CXXBasePaths {
|
||||||
friend class CXXRecordDecl;
|
friend class CXXRecordDecl;
|
||||||
|
|
||||||
void ComputeDeclsFound();
|
void ComputeDeclsFound();
|
||||||
|
|
||||||
|
bool lookupInBases(ASTContext &Context,
|
||||||
|
const CXXRecordDecl *Record,
|
||||||
|
CXXRecordDecl::BaseMatchesCallback *BaseMatches,
|
||||||
|
void *UserData);
|
||||||
public:
|
public:
|
||||||
typedef std::list<CXXBasePath>::iterator paths_iterator;
|
typedef std::list<CXXBasePath>::iterator paths_iterator;
|
||||||
typedef std::list<CXXBasePath>::const_iterator const_paths_iterator;
|
typedef std::list<CXXBasePath>::const_iterator const_paths_iterator;
|
||||||
|
|
|
@ -140,18 +140,20 @@ bool CXXRecordDecl::forallBases(ForallBasesCallback *BaseMatches,
|
||||||
return AllMatches;
|
return AllMatches;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXXRecordDecl::lookupInBases(BaseMatchesCallback *BaseMatches,
|
bool CXXBasePaths::lookupInBases(ASTContext &Context,
|
||||||
void *UserData,
|
const CXXRecordDecl *Record,
|
||||||
CXXBasePaths &Paths) const {
|
CXXRecordDecl::BaseMatchesCallback *BaseMatches,
|
||||||
|
void *UserData) {
|
||||||
bool FoundPath = false;
|
bool FoundPath = false;
|
||||||
|
|
||||||
// The access of the path down to this record.
|
// The access of the path down to this record.
|
||||||
AccessSpecifier AccessToHere = Paths.ScratchPath.Access;
|
AccessSpecifier AccessToHere = ScratchPath.Access;
|
||||||
bool IsFirstStep = Paths.ScratchPath.empty();
|
bool IsFirstStep = ScratchPath.empty();
|
||||||
|
|
||||||
ASTContext &Context = getASTContext();
|
for (CXXRecordDecl::base_class_const_iterator BaseSpec = Record->bases_begin(),
|
||||||
for (base_class_const_iterator BaseSpec = bases_begin(),
|
BaseSpecEnd = Record->bases_end();
|
||||||
BaseSpecEnd = bases_end(); BaseSpec != BaseSpecEnd; ++BaseSpec) {
|
BaseSpec != BaseSpecEnd;
|
||||||
|
++BaseSpec) {
|
||||||
// Find the record of the base class subobjects for this type.
|
// Find the record of the base class subobjects for this type.
|
||||||
QualType BaseType = Context.getCanonicalType(BaseSpec->getType())
|
QualType BaseType = Context.getCanonicalType(BaseSpec->getType())
|
||||||
.getUnqualifiedType();
|
.getUnqualifiedType();
|
||||||
|
@ -167,31 +169,31 @@ bool CXXRecordDecl::lookupInBases(BaseMatchesCallback *BaseMatches,
|
||||||
|
|
||||||
// Determine whether we need to visit this base class at all,
|
// Determine whether we need to visit this base class at all,
|
||||||
// updating the count of subobjects appropriately.
|
// updating the count of subobjects appropriately.
|
||||||
std::pair<bool, unsigned>& Subobjects = Paths.ClassSubobjects[BaseType];
|
std::pair<bool, unsigned>& Subobjects = ClassSubobjects[BaseType];
|
||||||
bool VisitBase = true;
|
bool VisitBase = true;
|
||||||
bool SetVirtual = false;
|
bool SetVirtual = false;
|
||||||
if (BaseSpec->isVirtual()) {
|
if (BaseSpec->isVirtual()) {
|
||||||
VisitBase = !Subobjects.first;
|
VisitBase = !Subobjects.first;
|
||||||
Subobjects.first = true;
|
Subobjects.first = true;
|
||||||
if (Paths.isDetectingVirtual() && Paths.DetectedVirtual == 0) {
|
if (isDetectingVirtual() && DetectedVirtual == 0) {
|
||||||
// If this is the first virtual we find, remember it. If it turns out
|
// If this is the first virtual we find, remember it. If it turns out
|
||||||
// there is no base path here, we'll reset it later.
|
// there is no base path here, we'll reset it later.
|
||||||
Paths.DetectedVirtual = BaseType->getAs<RecordType>();
|
DetectedVirtual = BaseType->getAs<RecordType>();
|
||||||
SetVirtual = true;
|
SetVirtual = true;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
++Subobjects.second;
|
++Subobjects.second;
|
||||||
|
|
||||||
if (Paths.isRecordingPaths()) {
|
if (isRecordingPaths()) {
|
||||||
// Add this base specifier to the current path.
|
// Add this base specifier to the current path.
|
||||||
CXXBasePathElement Element;
|
CXXBasePathElement Element;
|
||||||
Element.Base = &*BaseSpec;
|
Element.Base = &*BaseSpec;
|
||||||
Element.Class = this;
|
Element.Class = Record;
|
||||||
if (BaseSpec->isVirtual())
|
if (BaseSpec->isVirtual())
|
||||||
Element.SubobjectNumber = 0;
|
Element.SubobjectNumber = 0;
|
||||||
else
|
else
|
||||||
Element.SubobjectNumber = Subobjects.second;
|
Element.SubobjectNumber = Subobjects.second;
|
||||||
Paths.ScratchPath.push_back(Element);
|
ScratchPath.push_back(Element);
|
||||||
|
|
||||||
// Calculate the "top-down" access to this base class.
|
// Calculate the "top-down" access to this base class.
|
||||||
// The spec actually describes this bottom-up, but top-down is
|
// The spec actually describes this bottom-up, but top-down is
|
||||||
|
@ -209,22 +211,22 @@ bool CXXRecordDecl::lookupInBases(BaseMatchesCallback *BaseMatches,
|
||||||
// 3. Otherwise, overall access is determined by the most restrictive
|
// 3. Otherwise, overall access is determined by the most restrictive
|
||||||
// access in the sequence.
|
// access in the sequence.
|
||||||
if (IsFirstStep)
|
if (IsFirstStep)
|
||||||
Paths.ScratchPath.Access = BaseSpec->getAccessSpecifier();
|
ScratchPath.Access = BaseSpec->getAccessSpecifier();
|
||||||
else
|
else
|
||||||
Paths.ScratchPath.Access
|
ScratchPath.Access = CXXRecordDecl::MergeAccess(AccessToHere,
|
||||||
= MergeAccess(AccessToHere, BaseSpec->getAccessSpecifier());
|
BaseSpec->getAccessSpecifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Track whether there's a path involving this specific base.
|
// Track whether there's a path involving this specific base.
|
||||||
bool FoundPathThroughBase = false;
|
bool FoundPathThroughBase = false;
|
||||||
|
|
||||||
if (BaseMatches(BaseSpec, Paths.ScratchPath, UserData)) {
|
if (BaseMatches(BaseSpec, ScratchPath, UserData)) {
|
||||||
// We've found a path that terminates at this base.
|
// We've found a path that terminates at this base.
|
||||||
FoundPath = FoundPathThroughBase = true;
|
FoundPath = FoundPathThroughBase = true;
|
||||||
if (Paths.isRecordingPaths()) {
|
if (isRecordingPaths()) {
|
||||||
// We have a path. Make a copy of it before moving on.
|
// We have a path. Make a copy of it before moving on.
|
||||||
Paths.Paths.push_back(Paths.ScratchPath);
|
Paths.push_back(ScratchPath);
|
||||||
} else if (!Paths.isFindingAmbiguities()) {
|
} else if (!isFindingAmbiguities()) {
|
||||||
// We found a path and we don't care about ambiguities;
|
// We found a path and we don't care about ambiguities;
|
||||||
// return immediately.
|
// return immediately.
|
||||||
return FoundPath;
|
return FoundPath;
|
||||||
|
@ -233,7 +235,7 @@ bool CXXRecordDecl::lookupInBases(BaseMatchesCallback *BaseMatches,
|
||||||
CXXRecordDecl *BaseRecord
|
CXXRecordDecl *BaseRecord
|
||||||
= cast<CXXRecordDecl>(BaseSpec->getType()->getAs<RecordType>()
|
= cast<CXXRecordDecl>(BaseSpec->getType()->getAs<RecordType>()
|
||||||
->getDecl());
|
->getDecl());
|
||||||
if (BaseRecord->lookupInBases(BaseMatches, UserData, Paths)) {
|
if (lookupInBases(Context, BaseRecord, BaseMatches, UserData)) {
|
||||||
// C++ [class.member.lookup]p2:
|
// C++ [class.member.lookup]p2:
|
||||||
// A member name f in one sub-object B hides a member name f in
|
// A member name f in one sub-object B hides a member name f in
|
||||||
// a sub-object A if A is a base class sub-object of B. Any
|
// a sub-object A if A is a base class sub-object of B. Any
|
||||||
|
@ -243,29 +245,35 @@ bool CXXRecordDecl::lookupInBases(BaseMatchesCallback *BaseMatches,
|
||||||
// There is a path to a base class that meets the criteria. If we're
|
// There is a path to a base class that meets the criteria. If we're
|
||||||
// not collecting paths or finding ambiguities, we're done.
|
// not collecting paths or finding ambiguities, we're done.
|
||||||
FoundPath = FoundPathThroughBase = true;
|
FoundPath = FoundPathThroughBase = true;
|
||||||
if (!Paths.isFindingAmbiguities())
|
if (!isFindingAmbiguities())
|
||||||
return FoundPath;
|
return FoundPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pop this base specifier off the current path (if we're
|
// Pop this base specifier off the current path (if we're
|
||||||
// collecting paths).
|
// collecting paths).
|
||||||
if (Paths.isRecordingPaths()) {
|
if (isRecordingPaths()) {
|
||||||
Paths.ScratchPath.pop_back();
|
ScratchPath.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we set a virtual earlier, and this isn't a path, forget it again.
|
// If we set a virtual earlier, and this isn't a path, forget it again.
|
||||||
if (SetVirtual && !FoundPathThroughBase) {
|
if (SetVirtual && !FoundPathThroughBase) {
|
||||||
Paths.DetectedVirtual = 0;
|
DetectedVirtual = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the scratch path access.
|
// Reset the scratch path access.
|
||||||
Paths.ScratchPath.Access = AccessToHere;
|
ScratchPath.Access = AccessToHere;
|
||||||
|
|
||||||
return FoundPath;
|
return FoundPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CXXRecordDecl::lookupInBases(BaseMatchesCallback *BaseMatches,
|
||||||
|
void *UserData,
|
||||||
|
CXXBasePaths &Paths) const {
|
||||||
|
return Paths.lookupInBases(getASTContext(), this, BaseMatches, UserData);
|
||||||
|
}
|
||||||
|
|
||||||
bool CXXRecordDecl::FindBaseClass(const CXXBaseSpecifier *Specifier,
|
bool CXXRecordDecl::FindBaseClass(const CXXBaseSpecifier *Specifier,
|
||||||
CXXBasePath &Path,
|
CXXBasePath &Path,
|
||||||
void *BaseRecord) {
|
void *BaseRecord) {
|
||||||
|
|
Loading…
Reference in New Issue