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

Fariborz Jahanian fjahanian at apple.com
Mon Apr 14 16:36:37 PDT 2008


Author: fjahanian
Date: Mon Apr 14 18:36:35 2008
New Revision: 49699

URL: http://llvm.org/viewvc/llvm-project?rev=49699&view=rev
Log:
New AST representation for each objc2's property declaration.


Modified:
    cfe/trunk/Driver/ASTConsumers.cpp
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/include/clang/Parse/Action.h
    cfe/trunk/include/clang/Parse/Parser.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=49699&r1=49698&r2=49699&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Mon Apr 14 18:36:35 2008
@@ -316,16 +316,9 @@
         }
         Out << " )";
       }
-      
-      ObjCPropertyDecl::propdecl_iterator
-        I = PDecl->propdecl_begin(), E = PDecl->propdecl_end();
-      
       Out << ' ' << PDecl->getType().getAsString()
-          << ' ' << (*I)->getName();
-    
-      for (++I; I != E; ++I)
-        Out << ", " << (*I)->getName();
-
+          << ' ' << PDecl->getName();
+      
       Out << ";\n";
     }
   }

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Mon Apr 14 18:36:35 2008
@@ -27,7 +27,6 @@
 class ObjCProtocolDecl;
 class ObjCCategoryDecl;
 class ObjCPropertyDecl;
-class FieldDeclarator;
 
 /// ObjCMethodDecl - Represents an instance or class method declaration.
 /// ObjC methods can be declared within 4 contexts: class interfaces,
@@ -940,8 +939,12 @@
   static bool classof(const ObjCCompatibleAliasDecl *D) { return true; }
   
 };
-  
-class ObjCPropertyDecl : public Decl {
+
+/// ObjCPropertyDecl - Represents one property declaration in an interface.
+/// For example:
+/// @property (assign, readwrite) int MyProperty;
+///
+class ObjCPropertyDecl : public NamedDecl {
 public:
   enum PropertyAttributeKind {
     OBJC_PR_noattr    = 0x00, 
@@ -956,31 +959,18 @@
   };
 private:
   QualType DeclType;
-  // List of property name declarations
-  NamedDecl **PropertyDecls;
-  unsigned NumPropertyDecls;
   unsigned PropertyAttributes : 8;
   
   IdentifierInfo *GetterName;    // getter name of NULL if no getter
   IdentifierInfo *SetterName;    // setter name of NULL if no setter
   
-  ObjCPropertyDecl(SourceLocation L, QualType T)
-    : Decl(ObjCProperty, L), DeclType(T),
-      PropertyDecls(0), NumPropertyDecls(0),
+  ObjCPropertyDecl(SourceLocation L, IdentifierInfo *Id, QualType T)
+    : NamedDecl(ObjCProperty, L, Id), DeclType(T),
       PropertyAttributes(OBJC_PR_noattr), GetterName(0), SetterName(0) {}
 public:
-  static ObjCPropertyDecl *Create(ASTContext &C, SourceLocation L, QualType T);
+  static ObjCPropertyDecl *Create(ASTContext &C, SourceLocation L, 
+                                  IdentifierInfo *Id, QualType T);
   QualType getType() const { return DeclType; }
-  typedef NamedDecl * const *propdecl_iterator;
-  propdecl_iterator propdecl_begin() const { return PropertyDecls; }
-  propdecl_iterator propdecl_end() const {
-    return PropertyDecls+NumPropertyDecls; 
-  }
-  unsigned propdecl_size() const { return NumPropertyDecls; }
-  bool propdecl_empty() const { return NumPropertyDecls == 0; }
-  NamedDecl **getPropertyDecls() { return PropertyDecls; }
-  void setNumPropertyDecls(unsigned num) { NumPropertyDecls = num; }
-  void setPropertyDecls(NamedDecl **Nd) { PropertyDecls = Nd; }
   PropertyAttributeKind getPropertyAttributes() const {
     return PropertyAttributeKind(PropertyAttributes);
   }

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

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Mon Apr 14 18:36:35 2008
@@ -657,10 +657,9 @@
     unsigned pNum = 0) {
     return;
   }
-  // ActOnAddObjCProperties - called to build one property AST
-  virtual DeclTy *ActOnAddObjCProperties (Scope *S, SourceLocation AtLoc,
-    FieldDeclarator *PropertyDeclarators, unsigned NumPropertyDeclarators, 
-    ObjCDeclSpec &ODS) {
+  // ActOnProperty - called to build one property AST
+  virtual DeclTy *ActOnProperty (Scope *S, SourceLocation AtLoc,
+                                 FieldDeclarator &FD, ObjCDeclSpec &ODS) {
     return 0;
   }
                                      

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

==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Mon Apr 14 18:36:35 2008
@@ -323,7 +323,6 @@
                               DeclTy *classDecl,
             tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword);
   void ParseObjCPropertyAttribute(ObjCDeclSpec &DS);
-  DeclTy *ParseObjCPropertyDecl(DeclTy *interfaceDecl, SourceLocation AtLoc);
   
   DeclTy *ParseObjCMethodDefinition();
   

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

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Mon Apr 14 18:36:35 2008
@@ -111,9 +111,10 @@
 
 ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C,
                                            SourceLocation L,
+                                           IdentifierInfo *Id,
                                            QualType T) {
   void *Mem = C.getAllocator().Allocate<ObjCPropertyDecl>();
-  return new (Mem) ObjCPropertyDecl(L, T);
+  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=49699&r1=49698&r2=49699&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Mon Apr 14 18:36:35 2008
@@ -248,7 +248,32 @@
         if (contextKey != tok::objc_protocol)
           Diag(AtLoc, diag::err_objc_protocol_optional);
       } else if (ocKind == tok::objc_property) {
-        allProperties.push_back(ParseObjCPropertyDecl(interfaceDecl, AtLoc));
+        ObjCDeclSpec OCDS;
+        ConsumeToken(); // the "property" identifier
+        // Parse property attribute list, if any. 
+        if (Tok.is(tok::l_paren)) {
+          // property has attribute list.
+          ParseObjCPropertyAttribute(OCDS);
+        }
+        // Parse all the comma separated declarators.
+        DeclSpec DS;
+        llvm::SmallVector<FieldDeclarator, 8> FieldDeclarators;
+        ParseStructDeclaration(DS, FieldDeclarators);
+        
+        if (Tok.is(tok::semi)) 
+          ConsumeToken();
+        else {
+          Diag(Tok, diag::err_expected_semi_decl_list);
+          SkipUntil(tok::r_brace, true, true);
+        }
+        // Convert them all to property declarations.
+        for (unsigned i = 0, e = FieldDeclarators.size(); i != e; ++i) {
+          FieldDeclarator &FD = FieldDeclarators[i];
+          // Install the property declarator into interfaceDecl.
+          DeclTy *Property = Actions.ActOnProperty(CurScope,
+                               DS.getSourceRange().getBegin(), FD, OCDS);
+          allProperties.push_back(Property);
+        }
         continue;
       } else {
         Diag(Tok, diag::err_objc_illegal_interface_qual);
@@ -370,39 +395,6 @@
   }
 }
 
-///   Main routine to parse property declaration.
-///
-///   @property property-attr-decl[opt] property-component-decl ';'
-///
-Parser::DeclTy *Parser::ParseObjCPropertyDecl(DeclTy *interfaceDecl, 
-                                              SourceLocation AtLoc) {
-  assert(Tok.isObjCAtKeyword(tok::objc_property) &&
-         "ParseObjCPropertyDecl(): Expected @property");
-  ObjCDeclSpec OCDS;
-  ConsumeToken(); // the "property" identifier
-  // Parse property attribute list, if any. 
-  if (Tok.is(tok::l_paren)) {
-    // property has attribute list.
-    ParseObjCPropertyAttribute(OCDS);
-  }
-  // Parse declaration portion of @property.
-  llvm::SmallVector<DeclTy*, 8> PropertyDecls;
-  
-  // Parse all the comma separated declarators.
-  DeclSpec DS;
-  llvm::SmallVector<FieldDeclarator, 8> FieldDeclarators;
-  ParseStructDeclaration(DS, FieldDeclarators);
-    
-  if (Tok.is(tok::semi)) 
-    ConsumeToken();
-  else {
-    Diag(Tok, diag::err_expected_semi_decl_list);
-    SkipUntil(tok::r_brace, true, true);
-  }
-  return Actions.ActOnAddObjCProperties(CurScope, AtLoc, &FieldDeclarators[0],
-                                        FieldDeclarators.size(), OCDS);
-}
-
 ///   objc-method-proto:
 ///     objc-instance-method objc-method-decl objc-method-attributes[opt] 
 ///     objc-class-method objc-method-decl objc-method-attributes[opt]

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

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Mon Apr 14 18:36:35 2008
@@ -655,10 +655,8 @@
                       DeclTy **allMethods = 0, unsigned allNum = 0,
                       DeclTy **allProperties = 0, unsigned pNum = 0);
   
-  virtual DeclTy *ActOnAddObjCProperties(Scope *S, SourceLocation AtLoc, 
-                                         FieldDeclarator *allProperties,
-                                         unsigned NumProperties,
-                                         ObjCDeclSpec &ODS);  
+  virtual DeclTy *ActOnProperty(Scope *S, SourceLocation AtLoc,
+                                FieldDeclarator &FD, ObjCDeclSpec &ODS);  
   virtual DeclTy *ActOnMethodDeclaration(
     SourceLocation BeginLoc, // location of the + or -.
     SourceLocation EndLoc,   // location of the ; or {.

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Mon Apr 14 18:36:35 2008
@@ -886,13 +886,12 @@
   return ObjCMethod;
 }
 
-Sema::DeclTy *Sema::ActOnAddObjCProperties(Scope *S, SourceLocation AtLoc, 
-                                           FieldDeclarator *propertyDeclarators,
-                                           unsigned NumPropertyDeclarators, 
-                                           ObjCDeclSpec &ODS) {
-  FieldDeclarator &FD = propertyDeclarators[0];
+Sema::DeclTy *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, 
+                                  FieldDeclarator &FD,
+                                  ObjCDeclSpec &ODS) {
   QualType T = GetTypeForDeclarator(FD.D, S);
-  ObjCPropertyDecl *PDecl = ObjCPropertyDecl::Create(Context, AtLoc, T);
+  ObjCPropertyDecl *PDecl = ObjCPropertyDecl::Create(Context, AtLoc, 
+                                                     FD.D.getIdentifier(), T);
   
   if (ODS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_readonly)
     PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readonly);
@@ -922,16 +921,6 @@
   if (ODS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_nonatomic)
     PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_nonatomic);
   
-  if (NumPropertyDeclarators != 0) {
-    NamedDecl **propertyName = new NamedDecl*[NumPropertyDeclarators];
-    PDecl->setPropertyDecls(propertyName);
-    PDecl->setNumPropertyDecls(NumPropertyDeclarators);
-    for (unsigned i = 0; i < NumPropertyDeclarators; i++) {
-      Declarator &D = propertyDeclarators[i].D;
-      propertyName[i] = new NamedDecl(Decl::ObjCProperty, 
-                                      D.getIdentifierLoc(), D.getIdentifier());
-    }
-  }
   return PDecl;
 }
 





More information about the cfe-commits mailing list