[cfe-commits] r71683 - in /cfe/trunk: include/clang/AST/Attr.h lib/Frontend/PCHReaderDecl.cpp lib/Frontend/PCHWriter.cpp lib/Sema/Sema.h lib/Sema/SemaExpr.cpp lib/Sema/SemaExprObjC.cpp

Fariborz Jahanian fjahanian at apple.com
Wed May 13 11:09:43 PDT 2009


Author: fjahanian
Date: Wed May 13 13:09:35 2009
New Revision: 71683

URL: http://llvm.org/viewvc/llvm-project?rev=71683&view=rev
Log:
Some early declarations to support sentinel attribute on
message dispatches (and function calls later). No change in
functionality.

Modified:
    cfe/trunk/include/clang/AST/Attr.h
    cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
    cfe/trunk/lib/Frontend/PCHWriter.cpp
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaExprObjC.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Wed May 13 13:09:35 2009
@@ -66,6 +66,7 @@
     Pure,
     Regparm,
     Section,
+    Sentinel,
     StdCall,
     TransparentUnion,
     Unavailable,
@@ -359,6 +360,23 @@
   static bool classof(const FormatAttr *A) { return true; }
 };
 
+class SentinelAttr : public Attr {
+  int sentinel, NullPos;
+public:
+  SentinelAttr(int sentinel_val, int nullPos) : Attr(Sentinel),
+               sentinel(sentinel_val), NullPos(nullPos) {}
+  int getSentinel() const { return sentinel; }
+  int getNullPos() const { return NullPos; }
+
+  virtual Attr *clone(ASTContext &C) const {
+    return ::new (C) SentinelAttr(sentinel, NullPos);
+  }
+
+  // Implement isa/cast/dyncast/etc.
+  static bool classof(const Attr *A) { return A->getKind() == Sentinel; }
+  static bool classof(const SentinelAttr *A) { return true; }
+};
+
 class VisibilityAttr : public Attr {
 public:
   /// @brief An enumeration for the kinds of visibility of symbols.

Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=71683&r1=71682&r2=71683&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Wed May 13 13:09:35 2009
@@ -452,6 +452,13 @@
       New = ::new (*Context) FormatAttr(Type, FormatIdx, FirstArg);
       break;
     }
+        
+    case Attr::Sentinel: {
+      int sentinel = Record[Idx++];
+      int nullPos = Record[Idx++];
+      New = ::new (*Context) SentinelAttr(sentinel, nullPos);
+      break;
+    }
 
     SIMPLE_ATTR(GNUInline);
     

Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=71683&r1=71682&r2=71683&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Wed May 13 13:09:35 2009
@@ -1556,6 +1556,13 @@
       break;
     }
 
+    case Attr::Sentinel : {
+      const SentinelAttr *Sentinel = cast<SentinelAttr>(Attr);
+      Record.push_back(Sentinel->getSentinel());
+      Record.push_back(Sentinel->getNullPos());
+      break;
+    }
+        
     case Attr::GNUInline:
     case Attr::IBOutletKind:
     case Attr::NoReturn:

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=71683&r1=71682&r2=71683&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Wed May 13 13:09:35 2009
@@ -1274,6 +1274,8 @@
   bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, 
                                         ObjCMethodDecl *Getter,
                                         SourceLocation Loc);
+  void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
+                             Expr **Args, unsigned NumArgs);
 
   // Primary Expressions.
   virtual SourceRange getExprRange(ExprTy *E) const;

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed May 13 13:09:35 2009
@@ -88,6 +88,15 @@
   return false;
 }
 
+/// DiagnoseSentinelCalls - This routine checks on method dispatch calls
+/// (and other functions in future), which have been declared with sentinel 
+/// attribute. It warns if call does not have the sentinel argument.
+///
+void Sema::DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
+                                 Expr **Args, unsigned NumArgs)
+{
+}
+
 SourceRange Sema::getExprRange(ExprTy *E) const {
   Expr *Ex = (Expr *)E;
   return Ex? Ex->getSourceRange() : SourceRange();

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Wed May 13 13:09:35 2009
@@ -626,6 +626,8 @@
     return true;
   }
   
+  if (Method)
+    DiagnoseSentinelCalls(Method, receiverLoc, ArgExprs, NumArgs);
   if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false,
                                 lbrac, rbrac, returnType))
     return true;





More information about the cfe-commits mailing list