[cfe-commits] r71908 - /cfe/trunk/lib/Sema/SemaDeclAttr.cpp

Fariborz Jahanian fjahanian at apple.com
Fri May 15 16:15:04 PDT 2009


Author: fjahanian
Date: Fri May 15 18:15:03 2009
New Revision: 71908

URL: http://llvm.org/viewvc/llvm-project?rev=71908&view=rev
Log:
Early support for __format__attribute on blocks.
Work in progress...

Modified:
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=71908&r1=71907&r2=71908&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri May 15 18:15:03 2009
@@ -37,6 +37,8 @@
   
   if (Ty->isFunctionPointerType())
     Ty = Ty->getAsPointerType()->getPointeeType();
+  else if (Ty->isBlockPointerType())
+    Ty = Ty->getAsBlockPointerType()->getPointeeType();
 
   return Ty->getAsFunctionType();
 }
@@ -51,13 +53,27 @@
   return getFunctionType(d) || isa<ObjCMethodDecl>(d);
 }
 
+/// isFunctionOrMethodOrBlock - Return true if the given decl has function
+/// type (function or function-typed variable) or an Objective-C
+/// method or a block.
+static bool isFunctionOrMethodOrBlock(Decl *d) {
+  if (isFunctionOrMethod(d))
+    return true;
+  // check for block is more involved.
+  if (const VarDecl *V = dyn_cast<VarDecl>(d)) {
+    QualType Ty = V->getType();
+    return Ty->isBlockPointerType();
+  }
+  return false;
+}
+
 /// hasFunctionProto - Return true if the given decl has a argument
 /// information. This decl should have already passed
-/// isFunctionOrMethod.
+/// isFunctionOrMethod or isFunctionOrMethodOrBlock.
 static bool hasFunctionProto(Decl *d) {
-  if (const FunctionType *FnTy = getFunctionType(d)) {
+  if (const FunctionType *FnTy = getFunctionType(d))
     return isa<FunctionProtoType>(FnTy);
-  } else {
+  else {
     assert(isa<ObjCMethodDecl>(d));
     return true;
   }
@@ -69,6 +85,17 @@
 static unsigned getFunctionOrMethodNumArgs(Decl *d) {
   if (const FunctionType *FnTy = getFunctionType(d))
     return cast<FunctionProtoType>(FnTy)->getNumArgs();
+  else if (VarDecl *V = dyn_cast<VarDecl>(d)) {
+    QualType Ty = V->getType(); 
+    if (Ty->isBlockPointerType()) {
+      const FunctionType *FT = 
+        Ty->getAsBlockPointerType()->getPointeeType()->getAsFunctionType();
+      if (const FunctionProtoType *Proto = dyn_cast<FunctionProtoType>(FT))
+        return Proto->getNumArgs();
+      
+    }
+    assert(false && "getFunctionOrMethodNumArgs - caused by block mishap");
+  }
   return cast<ObjCMethodDecl>(d)->param_size();
 }
 
@@ -76,6 +103,7 @@
   if (const FunctionType *FnTy = getFunctionType(d))
     return cast<FunctionProtoType>(FnTy)->getArgType(Idx);
   
+  
   return cast<ObjCMethodDecl>(d)->param_begin()[Idx]->getType();
 }
 
@@ -1062,7 +1090,7 @@
     return;
   }
 
-  if (!isFunctionOrMethod(d) || !hasFunctionProto(d)) {
+  if (!isFunctionOrMethodOrBlock(d) || !hasFunctionProto(d)) {
     S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
       << Attr.getName() << 0 /*function*/;
     return;





More information about the cfe-commits mailing list