[cfe-commits] r50662 - in /cfe/trunk: Driver/ASTConsumers.cpp include/clang/AST/DeclObjC.h include/clang/Parse/Action.h lib/AST/DeclObjC.cpp lib/Parse/ParseObjc.cpp lib/Sema/Sema.h lib/Sema/SemaDeclObjC.cpp

Fariborz Jahanian fjahanian at apple.com
Mon May 5 11:51:55 PDT 2008


Author: fjahanian
Date: Mon May  5 13:51:55 2008
New Revision: 50662

URL: http://llvm.org/viewvc/llvm-project?rev=50662&view=rev
Log:
percolate @optional/@required protocols down to ASTs for
properties declared in the protocol.

Modified:
    cfe/trunk/Driver/ASTConsumers.cpp
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/include/clang/Parse/Action.h
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/Parse/ParseObjc.cpp
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp

Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=50662&r1=50661&r2=50662&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Mon May  5 13:51:55 2008
@@ -320,7 +320,11 @@
 /// PrintObjCPropertyDecl - print a property declaration.
 ///
 void DeclPrinter::PrintObjCPropertyDecl(ObjCPropertyDecl *PDecl) {
-    
+  if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Required)
+    Out << "@required\n";
+  else if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Optional)
+    Out << "@optional\n";
+  
   Out << "@property";
   if (PDecl->getPropertyAttributes() != ObjCPropertyDecl::OBJC_PR_noattr) {
     bool first = true;

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Mon May  5 13:51:55 2008
@@ -1066,10 +1066,15 @@
     OBJC_PR_nonatomic = 0x40,
     OBJC_PR_setter    = 0x80
   };
+  
+  enum PropertyControl { None, Required, Optional };
 private:
   QualType DeclType;
   unsigned PropertyAttributes : 8;
   
+  // @required/@optional
+  unsigned PropertyImplementation : 2;
+  
   IdentifierInfo *GetterName;    // getter name of NULL if no getter
   IdentifierInfo *SetterName;    // setter name of NULL if no setter
   
@@ -1078,7 +1083,8 @@
       PropertyAttributes(OBJC_PR_noattr), GetterName(0), SetterName(0) {}
 public:
   static ObjCPropertyDecl *Create(ASTContext &C, SourceLocation L, 
-                                  IdentifierInfo *Id, QualType T);
+                                  IdentifierInfo *Id, QualType T,
+                                  PropertyControl propControl = None);
   QualType getType() const { return DeclType; }
   QualType getCanonicalType() const { return DeclType.getCanonicalType(); }
   
@@ -1095,6 +1101,14 @@
   IdentifierInfo *getSetterName() const { return SetterName; }
   void setSetterName(IdentifierInfo *Id) { SetterName = Id; }
   
+  // Related to @optional/@required declared in @protocol
+  void setPropertyImplementation(PropertyControl pc) {
+    PropertyImplementation = pc;
+  }
+  PropertyControl getPropertyImplementation() const {
+    return PropertyControl(PropertyImplementation);
+  }  
+  
   static bool classof(const Decl *D) {
     return D->getKind() == ObjCProperty;
   }

Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=50662&r1=50661&r2=50662&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Mon May  5 13:51:55 2008
@@ -685,7 +685,8 @@
   }
   // ActOnProperty - called to build one property AST
   virtual DeclTy *ActOnProperty (Scope *S, SourceLocation AtLoc,
-                                 FieldDeclarator &FD, ObjCDeclSpec &ODS) {
+                                 FieldDeclarator &FD, ObjCDeclSpec &ODS,
+                                 tok::ObjCKeywordKind MethodImplKind) {
     return 0;
   }
                                      

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

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Mon May  5 13:51:55 2008
@@ -112,7 +112,8 @@
 ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C,
                                            SourceLocation L,
                                            IdentifierInfo *Id,
-                                           QualType T) {
+                                           QualType T,
+                                           PropertyControl propControl) {
   void *Mem = C.getAllocator().Allocate<ObjCPropertyDecl>();
   return new (Mem) ObjCPropertyDecl(L, Id, T);
 }

Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=50662&r1=50661&r2=50662&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Mon May  5 13:51:55 2008
@@ -271,7 +271,8 @@
           FieldDeclarator &FD = FieldDeclarators[i];
           // Install the property declarator into interfaceDecl.
           DeclTy *Property = Actions.ActOnProperty(CurScope,
-                               DS.getSourceRange().getBegin(), FD, OCDS);
+                               DS.getSourceRange().getBegin(), FD, OCDS,
+                               MethodImplKind);
           allProperties.push_back(Property);
         }
         continue;

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

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Mon May  5 13:51:55 2008
@@ -676,7 +676,9 @@
                       DeclTy **allProperties = 0, unsigned pNum = 0);
   
   virtual DeclTy *ActOnProperty(Scope *S, SourceLocation AtLoc,
-                                FieldDeclarator &FD, ObjCDeclSpec &ODS);
+                                FieldDeclarator &FD, ObjCDeclSpec &ODS,
+                                tok::ObjCKeywordKind MethodImplKind);
+  
   virtual DeclTy *ActOnPropertyImplDecl(SourceLocation AtLoc, 
                                         SourceLocation PropertyLoc,
                                         bool ImplKind, DeclTy *ClassImplDecl,

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Mon May  5 13:51:55 2008
@@ -1022,7 +1022,8 @@
 
 Sema::DeclTy *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, 
                                   FieldDeclarator &FD,
-                                  ObjCDeclSpec &ODS) {
+                                  ObjCDeclSpec &ODS,
+                                  tok::ObjCKeywordKind MethodImplKind) {
   QualType T = GetTypeForDeclarator(FD.D, S);
   ObjCPropertyDecl *PDecl = ObjCPropertyDecl::Create(Context, AtLoc, 
                                                      FD.D.getIdentifier(), T);
@@ -1055,6 +1056,11 @@
   if (ODS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_nonatomic)
     PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_nonatomic);
   
+  if (MethodImplKind == tok::objc_required)
+    PDecl->setPropertyImplementation(ObjCPropertyDecl::Required);
+  else if (MethodImplKind == tok::objc_optional)
+    PDecl->setPropertyImplementation(ObjCPropertyDecl::Optional);
+  
   return PDecl;
 }
 





More information about the cfe-commits mailing list