[cfe-commits] r77411 - in /cfe/trunk: include/clang/AST/Type.h lib/AST/Type.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CGExprScalar.cpp

Fariborz Jahanian fjahanian at apple.com
Tue Jul 28 17:44:13 PDT 2009


Author: fjahanian
Date: Tue Jul 28 19:44:13 2009
New Revision: 77411

URL: http://llvm.org/viewvc/llvm-project?rev=77411&view=rev
Log:
Code refactoring to define getCXXRecordDeclForPointerType
and use it in several places.

Modified:
    cfe/trunk/include/clang/AST/Type.h
    cfe/trunk/lib/AST/Type.cpp
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp

Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=77411&r1=77410&r2=77411&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Tue Jul 28 19:44:13 2009
@@ -464,7 +464,8 @@
   const ObjCInterfaceType *getAsObjCInterfaceType() const;
   const ObjCInterfaceType *getAsObjCQualifiedInterfaceType() const;
   const TemplateTypeParmType *getAsTemplateTypeParmType() const;
-
+  const CXXRecordDecl *getCXXRecordDeclForPointerType() const;
+  
   // Member-template getAs<specific type>'.  This scheme will eventually
   // replace the specific getAsXXXX methods above.
   template <typename T> const T *getAs() const;

Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=77411&r1=77410&r2=77411&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Tue Jul 28 19:44:13 2009
@@ -523,6 +523,13 @@
   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 *
 Type::getAsTemplateSpecializationType() const {
   // There is no sugar for class template specialization types, so

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=77411&r1=77410&r2=77411&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue Jul 28 19:44:13 2009
@@ -993,12 +993,10 @@
     if (PTy->getPointeeType()->isUnionType())
       isUnion = true;
     CVRQualifiers = PTy->getPointeeType().getCVRQualifiers();
-    QualType ClassTy = BaseExpr->getType();
-    ClassTy = ClassTy->getPointeeType();
-    if (CXXRecordDecl *ClassDecl =
-        dyn_cast<CXXRecordDecl>(ClassTy->getAsRecordType()->getDecl())) {
+    if (const CXXRecordDecl *ClassDecl = 
+          BaseExpr->getType()->getCXXRecordDeclForPointerType()) {
       FieldDecl *Field = dyn_cast<FieldDecl>(E->getMemberDecl());
-      if (CXXRecordDecl *BaseClassDecl = 
+      if (const CXXRecordDecl *BaseClassDecl = 
           dyn_cast<CXXRecordDecl>(Field->getDeclContext()))
         BaseValue = AddressCXXOfBaseClass(BaseValue, ClassDecl, BaseClassDecl);
     }
@@ -1017,14 +1015,15 @@
       isNonGC = true;
     // FIXME: this isn't right for bitfields.
     BaseValue = BaseLV.getAddress();
-    if (BaseExpr->getType()->isUnionType())
+    QualType BaseTy = BaseExpr->getType();
+    if (BaseTy->isUnionType())
       isUnion = true;
-    CVRQualifiers = BaseExpr->getType().getCVRQualifiers();
-    if (CXXRecordDecl *ClassDecl =
+    CVRQualifiers = BaseTy.getCVRQualifiers();
+    if (const CXXRecordDecl *ClassDecl =
           dyn_cast<CXXRecordDecl>(
-                        BaseExpr->getType()->getAsRecordType()->getDecl())) {
+                        BaseTy->getAsRecordType()->getDecl())) {
         FieldDecl *Field = dyn_cast<FieldDecl>(E->getMemberDecl());
-        if (CXXRecordDecl *BaseClassDecl = 
+        if (const CXXRecordDecl *BaseClassDecl = 
             dyn_cast<CXXRecordDecl>(Field->getDeclContext()))
             BaseValue = 
               AddressCXXOfBaseClass(BaseValue, ClassDecl, BaseClassDecl);

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=77411&r1=77410&r2=77411&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Tue Jul 28 19:44:13 2009
@@ -442,18 +442,11 @@
     // The source value may be an integer, or a pointer.
     if (isa<llvm::PointerType>(Src->getType())) {
       // Some heavy lifting for derived to base conversion.
-      if (const PointerType *PT = SrcType->getAsPointerType()) {
-        QualType SrcClassTy = PT->getPointeeType();
-        if (const RecordType *RT = SrcClassTy->getAsRecordType())
-          if (CXXRecordDecl *ClassDecl =
-              dyn_cast<CXXRecordDecl>(RT->getDecl())) {
-            QualType DstClassType = DstType->getPointeeType();
-            if (const RecordType *DRT = DstClassType->getAsRecordType())
-              if (CXXRecordDecl *BaseClassDecl = 
-                    dyn_cast<CXXRecordDecl>(DRT->getDecl()))
-                Src = CGF.AddressCXXOfBaseClass(Src, ClassDecl, BaseClassDecl);
-          }
-      }
+      if (const CXXRecordDecl *ClassDecl = 
+            SrcType->getCXXRecordDeclForPointerType())
+        if (const CXXRecordDecl *BaseClassDecl = 
+              DstType->getCXXRecordDeclForPointerType())
+          Src = CGF.AddressCXXOfBaseClass(Src, ClassDecl, BaseClassDecl);
       return Builder.CreateBitCast(Src, DstTy, "conv");
     }
     assert(SrcType->isIntegerType() && "Not ptr->ptr or int->ptr conversion?");





More information about the cfe-commits mailing list