]> granicus.if.org Git - clang/commitdiff
Refactor HandleObjCOwnershipRetainAttr and HandleObjCOwnershipCFRetainAttr into
authorTed Kremenek <kremenek@apple.com>
Mon, 27 Apr 2009 18:41:18 +0000 (18:41 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 27 Apr 2009 18:41:18 +0000 (18:41 +0000)
HandleObjCOwnershipParmAttr. No functionality change (hopefully).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70224 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclAttr.cpp

index 7bbfb2695413f468f59e0bdcdb0c56c74e7865ad..cf722e511d32745afbf94c4ad62e15cf61f11ce8 100644 (file)
@@ -1533,28 +1533,36 @@ static void HandleObjCOwnershipReturnsAttr(Decl *d, const AttributeList &Attr,
   d->addAttr(::new (S.Context) ObjCOwnershipReturnsAttr());
 }
 
-static void HandleObjCOwnershipRetainAttr(Decl *d, const AttributeList &Attr,
-                                           Sema &S) {
+static void HandleObjCOwnershipParmAttr(Decl *d, const AttributeList &Attr,
+                                        Sema &S) {
   
   if (!isa<ParmVarDecl>(d)) {
-    S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type) <<
-    "objc_ownership_retain" << 4 /* parameter */;
-    return;
-  }
-  
-  d->addAttr(::new (S.Context) ObjCOwnershipRetainAttr());
-}
+    const char *name;
+    
+    switch (Attr.getKind()) {
+      default:
+        assert(0 && "invalid ownership attribute");
+        return;
+      case AttributeList::AT_objc_ownership_retain:
+        name = "objc_ownership_retain"; break;
+      case AttributeList::AT_objc_ownership_cfretain:
+        name = "objc_ownership_cfretain"; break;
+    };
 
-static void HandleObjCOwnershipCFRetainAttr(Decl *d, const AttributeList &Attr,
-                                            Sema &S) {
-  
-  if (!isa<ParmVarDecl>(d)) {
-    S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type) <<
-    "objc_ownership_cfretain" << 4 /* parameter */;
+    S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type) << name
+          << 4 /* parameter */;
     return;
   }
   
-  d->addAttr(::new (S.Context) ObjCOwnershipCFRetainAttr());
+  switch (Attr.getKind()) {
+    default:
+      assert(0 && "invalid ownership attribute");
+      return;
+    case AttributeList::AT_objc_ownership_retain:
+      d->addAttr(::new (S.Context) ObjCOwnershipRetainAttr());   return;
+    case AttributeList::AT_objc_ownership_cfretain:
+      d->addAttr(::new (S.Context) ObjCOwnershipCFRetainAttr()); return;
+  }
 }
 
 //===----------------------------------------------------------------------===//
@@ -1596,11 +1604,10 @@ static void ProcessDeclAttribute(Decl *D, const AttributeList &Attr, Sema &S) {
 
   // Checker-specific.
   case AttributeList::AT_objc_ownership_retain:
-    HandleObjCOwnershipRetainAttr(D, Attr, S); break;
+  case AttributeList::AT_objc_ownership_cfretain:
+    HandleObjCOwnershipParmAttr(D, Attr, S); break;
   case AttributeList::AT_objc_ownership_returns:
     HandleObjCOwnershipReturnsAttr(D, Attr, S); break;
-  case AttributeList::AT_objc_ownership_cfretain:
-    HandleObjCOwnershipCFRetainAttr(D, Attr, S); break;
 
   case AttributeList::AT_packed:      HandlePackedAttr    (D, Attr, S); break;
   case AttributeList::AT_section:     HandleSectionAttr   (D, Attr, S); break;