[cfe-commits] r64954 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp lib/CodeGen/CGExpr.cpp

Fariborz Jahanian fjahanian at apple.com
Wed Feb 18 13:49:28 PST 2009


Author: fjahanian
Date: Wed Feb 18 15:49:28 2009
New Revision: 64954

URL: http://llvm.org/viewvc/llvm-project?rev=64954&view=rev
Log:
Some refactoring and simplificaiotn of objc's gc
ir gen.

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

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

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Wed Feb 18 15:49:28 2009
@@ -395,6 +395,11 @@
   /// to struct), Interface* (pointer to ObjCInterfaceType) and id<P> (qualified
   /// ID type).
   bool isObjCObjectPointerType(QualType Ty) const;
+
+  /// getObjCGCAttr - Returns one of GCNone, Weak or Strong objc's
+  /// garbage collection attribute.
+  ///
+  QualType::GCAttrTypes getObjCGCAttrKind(const QualType &Ty) const;
   
   /// isObjCNSObjectType - Return true if this is an NSObject object with
   /// its NSObject attribute set.

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

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Feb 18 15:49:28 2009
@@ -2390,6 +2390,22 @@
   return isObjCNSObjectType(Ty);
 }
 
+/// getObjCGCAttr - Returns one of GCNone, Weak or Strong objc's
+/// garbage collection attribute.
+///
+QualType::GCAttrTypes ASTContext::getObjCGCAttrKind(const QualType &Ty) const {
+  QualType::GCAttrTypes attr = QualType::GCNone;
+  if (getLangOptions().ObjC1 &&
+      getLangOptions().getGCMode() != LangOptions::NonGC) {
+    attr = Ty.getObjCGCAttr();
+    // Default behavious under objective-c's gc is for objective-c pointers
+    // be treated as though they were declared as __strong.
+    if (attr == QualType::GCNone && isObjCObjectPointerType(Ty))
+      attr = QualType::Strong;
+  }
+  return attr;
+}
+
 //===----------------------------------------------------------------------===//
 //                        Type Compatibility Testing
 //===----------------------------------------------------------------------===//

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Wed Feb 18 15:49:28 2009
@@ -604,22 +604,15 @@
   Builder.CreateStore(Vec, Dst.getExtVectorAddr(), Dst.isVolatileQualified());
 }
 
-/// SetVarDeclObjCAttribute - Set __weak/__strong attributes into the LValue
+/// SetDeclObjCGCAttrInLvalue - Set __weak/__strong attributes into the LValue
 /// object.
-static void SetVarDeclObjCAttribute(ASTContext &Ctx, const Decl *VD, 
-                                    const QualType &Ty, LValue &LV)
+static void SetDeclObjCGCAttrInLvalue(ASTContext &Ctx, const QualType &Ty, 
+                                      LValue &LV)
 {
-  if (Ctx.getLangOptions().ObjC1 &&
-      Ctx.getLangOptions().getGCMode() != LangOptions::NonGC) {
-    QualType::GCAttrTypes attr = Ty.getObjCGCAttr();
-    if (attr != QualType::GCNone)
-      LValue::SetObjCType(attr == QualType::Weak, 
-                          attr == QualType::Strong, LV);
-    // Default behavious under objective-c's gc is for objective-c pointers
-    // be treated as though they were declared as __strong.
-    else if (Ctx.isObjCObjectPointerType(Ty))
-      LValue::SetObjCType(false, true, LV);
-  }
+  QualType::GCAttrTypes attr = Ctx.getObjCGCAttrKind(Ty);
+  if (attr != QualType::GCNone)
+    LValue::SetObjCType(attr == QualType::Weak, 
+                        attr == QualType::Strong, LV);
 }
 
 LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
@@ -640,12 +633,12 @@
     if (VD->isBlockVarDecl() && 
         (VD->getStorageClass() == VarDecl::Static || 
          VD->getStorageClass() == VarDecl::Extern))
-      SetVarDeclObjCAttribute(getContext(), VD, E->getType(), LV);
+      SetDeclObjCGCAttrInLvalue(getContext(), E->getType(), LV);
     return LV;
   } else if (VD && VD->isFileVarDecl()) {
     LValue LV = LValue::MakeAddr(CGM.GetAddrOfGlobalVar(VD),
                                  E->getType().getCVRQualifiers());
-    SetVarDeclObjCAttribute(getContext(), VD, E->getType(), LV);
+    SetDeclObjCGCAttrInLvalue(getContext(), E->getType(), LV);
     return LV;
   } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(E->getDecl())) {
     return LValue::MakeAddr(CGM.GetAddrOfFunction(FD),
@@ -1054,7 +1047,7 @@
                                                         ObjectTy,
                                                         BaseValue, Ivar, Field,
                                                         CVRQualifiers);
-  SetVarDeclObjCAttribute(getContext(), Ivar, Ivar->getType(), LV);
+  SetDeclObjCGCAttrInLvalue(getContext(), Ivar->getType(), LV);
   return LV;
 }
 





More information about the cfe-commits mailing list