forked from OSchip/llvm-project
Code refactoring to define getCXXRecordDeclForPointerType
and use it in several places. llvm-svn: 77411
This commit is contained in:
parent
be62697e6b
commit
82e2874270
|
@ -464,7 +464,8 @@ public:
|
||||||
const ObjCInterfaceType *getAsObjCInterfaceType() const;
|
const ObjCInterfaceType *getAsObjCInterfaceType() const;
|
||||||
const ObjCInterfaceType *getAsObjCQualifiedInterfaceType() const;
|
const ObjCInterfaceType *getAsObjCQualifiedInterfaceType() const;
|
||||||
const TemplateTypeParmType *getAsTemplateTypeParmType() const;
|
const TemplateTypeParmType *getAsTemplateTypeParmType() const;
|
||||||
|
const CXXRecordDecl *getCXXRecordDeclForPointerType() const;
|
||||||
|
|
||||||
// Member-template getAs<specific type>'. This scheme will eventually
|
// Member-template getAs<specific type>'. This scheme will eventually
|
||||||
// replace the specific getAsXXXX methods above.
|
// replace the specific getAsXXXX methods above.
|
||||||
template <typename T> const T *getAs() const;
|
template <typename T> const T *getAs() const;
|
||||||
|
|
|
@ -523,6 +523,13 @@ const TemplateTypeParmType *Type::getAsTemplateTypeParmType() const {
|
||||||
return dyn_cast<TemplateTypeParmType>(CanonicalType);
|
return dyn_cast<TemplateTypeParmType>(CanonicalType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CXXRecordDecl *Type::getCXXRecordDeclForPointerType() const {
|
||||||
|
if (const PointerType *PT = getAsPointerType())
|
||||||
|
if (const RecordType *RT = PT->getPointeeType()->getAsRecordType())
|
||||||
|
return dyn_cast<CXXRecordDecl>(RT->getDecl());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const TemplateSpecializationType *
|
const TemplateSpecializationType *
|
||||||
Type::getAsTemplateSpecializationType() const {
|
Type::getAsTemplateSpecializationType() const {
|
||||||
// There is no sugar for class template specialization types, so
|
// There is no sugar for class template specialization types, so
|
||||||
|
|
|
@ -993,12 +993,10 @@ LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) {
|
||||||
if (PTy->getPointeeType()->isUnionType())
|
if (PTy->getPointeeType()->isUnionType())
|
||||||
isUnion = true;
|
isUnion = true;
|
||||||
CVRQualifiers = PTy->getPointeeType().getCVRQualifiers();
|
CVRQualifiers = PTy->getPointeeType().getCVRQualifiers();
|
||||||
QualType ClassTy = BaseExpr->getType();
|
if (const CXXRecordDecl *ClassDecl =
|
||||||
ClassTy = ClassTy->getPointeeType();
|
BaseExpr->getType()->getCXXRecordDeclForPointerType()) {
|
||||||
if (CXXRecordDecl *ClassDecl =
|
|
||||||
dyn_cast<CXXRecordDecl>(ClassTy->getAsRecordType()->getDecl())) {
|
|
||||||
FieldDecl *Field = dyn_cast<FieldDecl>(E->getMemberDecl());
|
FieldDecl *Field = dyn_cast<FieldDecl>(E->getMemberDecl());
|
||||||
if (CXXRecordDecl *BaseClassDecl =
|
if (const CXXRecordDecl *BaseClassDecl =
|
||||||
dyn_cast<CXXRecordDecl>(Field->getDeclContext()))
|
dyn_cast<CXXRecordDecl>(Field->getDeclContext()))
|
||||||
BaseValue = AddressCXXOfBaseClass(BaseValue, ClassDecl, BaseClassDecl);
|
BaseValue = AddressCXXOfBaseClass(BaseValue, ClassDecl, BaseClassDecl);
|
||||||
}
|
}
|
||||||
|
@ -1017,14 +1015,15 @@ LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) {
|
||||||
isNonGC = true;
|
isNonGC = true;
|
||||||
// FIXME: this isn't right for bitfields.
|
// FIXME: this isn't right for bitfields.
|
||||||
BaseValue = BaseLV.getAddress();
|
BaseValue = BaseLV.getAddress();
|
||||||
if (BaseExpr->getType()->isUnionType())
|
QualType BaseTy = BaseExpr->getType();
|
||||||
|
if (BaseTy->isUnionType())
|
||||||
isUnion = true;
|
isUnion = true;
|
||||||
CVRQualifiers = BaseExpr->getType().getCVRQualifiers();
|
CVRQualifiers = BaseTy.getCVRQualifiers();
|
||||||
if (CXXRecordDecl *ClassDecl =
|
if (const CXXRecordDecl *ClassDecl =
|
||||||
dyn_cast<CXXRecordDecl>(
|
dyn_cast<CXXRecordDecl>(
|
||||||
BaseExpr->getType()->getAsRecordType()->getDecl())) {
|
BaseTy->getAsRecordType()->getDecl())) {
|
||||||
FieldDecl *Field = dyn_cast<FieldDecl>(E->getMemberDecl());
|
FieldDecl *Field = dyn_cast<FieldDecl>(E->getMemberDecl());
|
||||||
if (CXXRecordDecl *BaseClassDecl =
|
if (const CXXRecordDecl *BaseClassDecl =
|
||||||
dyn_cast<CXXRecordDecl>(Field->getDeclContext()))
|
dyn_cast<CXXRecordDecl>(Field->getDeclContext()))
|
||||||
BaseValue =
|
BaseValue =
|
||||||
AddressCXXOfBaseClass(BaseValue, ClassDecl, BaseClassDecl);
|
AddressCXXOfBaseClass(BaseValue, ClassDecl, BaseClassDecl);
|
||||||
|
|
|
@ -442,18 +442,11 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType,
|
||||||
// The source value may be an integer, or a pointer.
|
// The source value may be an integer, or a pointer.
|
||||||
if (isa<llvm::PointerType>(Src->getType())) {
|
if (isa<llvm::PointerType>(Src->getType())) {
|
||||||
// Some heavy lifting for derived to base conversion.
|
// Some heavy lifting for derived to base conversion.
|
||||||
if (const PointerType *PT = SrcType->getAsPointerType()) {
|
if (const CXXRecordDecl *ClassDecl =
|
||||||
QualType SrcClassTy = PT->getPointeeType();
|
SrcType->getCXXRecordDeclForPointerType())
|
||||||
if (const RecordType *RT = SrcClassTy->getAsRecordType())
|
if (const CXXRecordDecl *BaseClassDecl =
|
||||||
if (CXXRecordDecl *ClassDecl =
|
DstType->getCXXRecordDeclForPointerType())
|
||||||
dyn_cast<CXXRecordDecl>(RT->getDecl())) {
|
Src = CGF.AddressCXXOfBaseClass(Src, ClassDecl, BaseClassDecl);
|
||||||
QualType DstClassType = DstType->getPointeeType();
|
|
||||||
if (const RecordType *DRT = DstClassType->getAsRecordType())
|
|
||||||
if (CXXRecordDecl *BaseClassDecl =
|
|
||||||
dyn_cast<CXXRecordDecl>(DRT->getDecl()))
|
|
||||||
Src = CGF.AddressCXXOfBaseClass(Src, ClassDecl, BaseClassDecl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Builder.CreateBitCast(Src, DstTy, "conv");
|
return Builder.CreateBitCast(Src, DstTy, "conv");
|
||||||
}
|
}
|
||||||
assert(SrcType->isIntegerType() && "Not ptr->ptr or int->ptr conversion?");
|
assert(SrcType->isIntegerType() && "Not ptr->ptr or int->ptr conversion?");
|
||||||
|
|
Loading…
Reference in New Issue