]> granicus.if.org Git - clang/commitdiff
percolate @optional/@required protocols down to ASTs for
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 5 May 2008 18:51:55 +0000 (18:51 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 5 May 2008 18:51:55 +0000 (18:51 +0000)
properties declared in the protocol.

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

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

index 684b11eaedb282eee15d1cae33459a27fd883ed3..20d4ce2a886a24d242bd1e3b5a95ee5c91b18906 100644 (file)
@@ -320,7 +320,11 @@ void DeclPrinter::PrintObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID) {
 /// 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;
index 5e92708962182f9c4d54467e0b89da70cb0f7213..7947b3dc38a719bf8b0e54504fb2cd5693ab9155 100644 (file)
@@ -1066,10 +1066,15 @@ public:
     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 @@ private:
       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 @@ public:
   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;
   }
index f0d515829747d56075cd8afb73c673a11b5e56cd..5d094ae8926d7f2748ef356a95cd9c5e27bffa3c 100644 (file)
@@ -685,7 +685,8 @@ public:
   }
   // 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;
   }
                                      
index 89f6d2c50195ecc5306a597ec106e7d7bb56e87b..0cb777d8debf369d052e7d128ab1356412bfe398 100644 (file)
@@ -112,7 +112,8 @@ ObjCCompatibleAliasDecl::Create(ASTContext &C,
 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);
 }
index d1b1c25c5a716e61c8a508186c68ddea8e987bed..8d404a9aafcd2bbe48b2d6f3c9f86c6145918b12 100644 (file)
@@ -271,7 +271,8 @@ void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl,
           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;
index 68a834c6b4cbc3223c508cff90203a5e88d87f8b..6375fad0869a4b3d403f829a7be8df73a7a3c9bf 100644 (file)
@@ -676,7 +676,9 @@ public:
                       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,
index afac82ca76f505c43795d884e1b762d0e689fc4d..3b488108961fba2fe31ac08a00da8eca7fb11777 100644 (file)
@@ -1022,7 +1022,8 @@ Sema::DeclTy *Sema::ActOnMethodDeclaration(
 
 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 @@ Sema::DeclTy *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc,
   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;
 }