[cfe-commits] r42070 - in /cfe/trunk: AST/Decl.cpp Parse/ParseObjc.cpp Sema/Sema.h Sema/SemaDecl.cpp include/clang/AST/Decl.h include/clang/Parse/Action.h include/clang/Parse/Parser.h

Fariborz Jahanian fjahanian at apple.com
Mon Sep 17 15:36:43 PDT 2007


Author: fjahanian
Date: Mon Sep 17 17:36:42 2007
New Revision: 42070

URL: http://llvm.org/viewvc/llvm-project?rev=42070&view=rev
Log:
Patch to remove ObjcProtoMethodDecl and use ObjcMethodDecl
instead for @protocol method decls.

Modified:
    cfe/trunk/AST/Decl.cpp
    cfe/trunk/Parse/ParseObjc.cpp
    cfe/trunk/Sema/Sema.h
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/Parse/Action.h
    cfe/trunk/include/clang/Parse/Parser.h

Modified: cfe/trunk/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Decl.cpp?rev=42070&r1=42069&r2=42070&view=diff

==============================================================================
--- cfe/trunk/AST/Decl.cpp (original)
+++ cfe/trunk/AST/Decl.cpp Mon Sep 17 17:36:42 2007
@@ -298,12 +298,12 @@
 					   unsigned numClsMembers) {
   NumProtoInsMethods = numInsMembers;
   if (numInsMembers) {
-    ProtoInsMethods = new ObjcProtoMethodDecl*[numInsMembers];
+    ProtoInsMethods = new ObjcMethodDecl*[numInsMembers];
     memcpy(ProtoInsMethods, insMethods, numInsMembers*sizeof(ObjcMethodDecl*));
   }
   NumProtoClsMethods = numClsMembers;
   if (numClsMembers) {
-    ProtoClsMethods = new ObjcProtoMethodDecl*[numClsMembers];
+    ProtoClsMethods = new ObjcMethodDecl*[numClsMembers];
     memcpy(ProtoClsMethods, clsMethods, numClsMembers*sizeof(ObjcMethodDecl*));
   }
 }

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

==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Mon Sep 17 17:36:42 2007
@@ -375,7 +375,7 @@
   tok::TokenKind methodType = Tok.getKind();  
   SourceLocation methodLoc = ConsumeToken();
   
-  DeclTy *MDecl = ParseObjCMethodDecl(IDecl, pi, methodType, methodLoc);
+  DeclTy *MDecl = ParseObjCMethodDecl(pi, methodType, methodLoc);
   // Since this rule is used for both method declarations and definitions,
   // the caller is (optionally) responsible for consuming the ';'.
   return MDecl;
@@ -484,8 +484,7 @@
 ///   objc-keyword-attributes:         [OBJC2]
 ///     __attribute__((unused))
 ///
-Parser::DeclTy *Parser::ParseObjCMethodDecl(DeclTy *IDecl,
-                          tok::ObjCKeywordKind& pi, 
+Parser::DeclTy *Parser::ParseObjCMethodDecl(tok::ObjCKeywordKind& pi, 
 			  tok::TokenKind mType, SourceLocation mLoc) {
 
   TypeTy *ReturnType = 0;
@@ -552,7 +551,7 @@
     // If attributes exist after the method, parse them.
     if (getLang().ObjC2 && Tok.getKind() == tok::kw___attribute) 
       methodAttrs = ParseAttributes();
-    return Actions.ObjcBuildMethodDeclaration(IDecl, pi, mLoc, mType, 
+    return Actions.ObjcBuildMethodDeclaration(pi, mLoc, mType, 
                                               ReturnType, 
                                               &KeyInfo[0], KeyInfo.size(), 
 					      methodAttrs);
@@ -563,7 +562,7 @@
   if (getLang().ObjC2 && Tok.getKind() == tok::kw___attribute) 
     methodAttrs = ParseAttributes();
 
-  return Actions.ObjcBuildMethodDeclaration(IDecl, pi,
+  return Actions.ObjcBuildMethodDeclaration(pi,
                                             mLoc, mType, ReturnType, 
                                             selIdent, methodAttrs);
 }

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

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Mon Sep 17 17:36:42 2007
@@ -368,14 +368,12 @@
 
   virtual void ObjcAddMethodsToClass(DeclTy *ClassDecl, 
 				     DeclTy **allMethods, unsigned allNum);
-  virtual DeclTy *ObjcBuildMethodDeclaration(DeclTy *InterfaceDecl,
-                    tok::ObjCKeywordKind& pi, 
+  virtual DeclTy *ObjcBuildMethodDeclaration(tok::ObjCKeywordKind& pi, 
 		    SourceLocation MethodLoc, 
 	            tok::TokenKind MethodType, TypeTy *ReturnType,
      		    ObjcKeywordDecl *Keywords, unsigned NumKeywords, 
      		    AttributeList *AttrList);
-  virtual DeclTy *ObjcBuildMethodDeclaration(DeclTy *InterfaceDecl,
-                    tok::ObjCKeywordKind& pi, 
+  virtual DeclTy *ObjcBuildMethodDeclaration(tok::ObjCKeywordKind& pi, 
 		    SourceLocation MethodLoc, 
  	     	    tok::TokenKind MethodType, TypeTy *ReturnType,
      		    IdentifierInfo *SelectorName, AttributeList *AttrList);

Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=42070&r1=42069&r2=42070&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Mon Sep 17 17:36:42 2007
@@ -1264,8 +1264,7 @@
   return;
 }
 
-Sema::DeclTy *Sema::ObjcBuildMethodDeclaration(DeclTy *IDecl,
-		      tok::ObjCKeywordKind& pi,
+Sema::DeclTy *Sema::ObjcBuildMethodDeclaration(tok::ObjCKeywordKind& pi,
 		      SourceLocation MethodLoc, 
                       tok::TokenKind MethodType, TypeTy *ReturnType,
                       ObjcKeywordDecl *Keywords, unsigned NumKeywords,
@@ -1303,31 +1302,18 @@
     Params.push_back(Param);
   }
   QualType resultDeclType = QualType::getFromOpaquePtr(ReturnType);
-  ObjcMethodDecl* ObjcMethod;
-// FIXME: Added !IDecl for now to handle @implementation
-  if (!IDecl || isa<ObjcInterfaceDecl>(static_cast<Decl *>(IDecl))) {
-    ObjcMethod =  new ObjcMethodDecl(MethodLoc, SelName, resultDeclType,
-                        0, -1, AttrList, MethodType == tok::minus);
-    ObjcMethod->setMethodParams(&Params[0], NumKeywords);
-  }
-  else if (isa<ObjcProtocolDecl>(static_cast<Decl *>(IDecl))) {
-    ObjcMethod =  new ObjcProtoMethodDecl(MethodLoc, SelName, resultDeclType,
-                        0, -1, AttrList, MethodType == tok::minus);
-    ObjcMethod->setMethodParams(&Params[0], NumKeywords);
-    if (pi == tok::objc_optional)
-      dyn_cast<ObjcProtoMethodDecl>(ObjcMethod)->
-                 setDeclImplementation(ObjcProtoMethodDecl::Optional);
-    else
-      dyn_cast<ObjcProtoMethodDecl>(ObjcMethod)->
-                 setDeclImplementation(ObjcProtoMethodDecl::Required);
-  }
+  ObjcMethodDecl* ObjcMethod =  new ObjcMethodDecl(MethodLoc, 
+				      SelName, resultDeclType,
+		      		      0, -1, AttrList, MethodType == tok::minus);
+  ObjcMethod->setMethodParams(&Params[0], NumKeywords);
+  if (pi == tok::objc_optional)
+      ObjcMethod->setDeclImplementation(ObjcMethodDecl::Optional);
   else
-    assert(0 && "Sema::ObjcBuildMethodDeclaration(): Unknown DeclTy");
+       ObjcMethod->setDeclImplementation(ObjcMethodDecl::Required);
   return ObjcMethod;
 }
 
-Sema::DeclTy *Sema::ObjcBuildMethodDeclaration(DeclTy *IDecl,
-		      tok::ObjCKeywordKind& pi,
+Sema::DeclTy *Sema::ObjcBuildMethodDeclaration(tok::ObjCKeywordKind& pi,
 		      SourceLocation MethodLoc,  
                       tok::TokenKind MethodType, TypeTy *ReturnType,
                       IdentifierInfo *SelectorName, AttributeList *AttrList) {
@@ -1335,25 +1321,13 @@
   SelectorInfo &SelName = Context.getSelectorInfo(methodName, 
                                                   methodName+strlen(methodName));
   QualType resultDeclType = QualType::getFromOpaquePtr(ReturnType);
-  ObjcMethodDecl* ObjcMethod;
-// FIXME: Remove after IDecl is always non-null
-  if (!IDecl || isa<ObjcInterfaceDecl>(static_cast<Decl *>(IDecl))) {
-    ObjcMethod = new ObjcMethodDecl(MethodLoc, SelName, resultDeclType, 0, -1,
-                                    AttrList, MethodType == tok::minus);
-  }
-  else if (isa<ObjcProtocolDecl>(static_cast<Decl *>(IDecl))) {
-    ObjcMethod = new ObjcProtoMethodDecl(MethodLoc, SelName, resultDeclType,
-                                         0, -1,
-                                         AttrList, MethodType == tok::minus);
-    if (pi == tok::objc_optional)
-      dyn_cast<ObjcProtoMethodDecl>(ObjcMethod)->
-                 setDeclImplementation(ObjcProtoMethodDecl::Optional);
-    else
-      dyn_cast<ObjcProtoMethodDecl>(ObjcMethod)->
-                 setDeclImplementation(ObjcProtoMethodDecl::Required);
-  }
+  ObjcMethodDecl* ObjcMethod = new ObjcMethodDecl(MethodLoc, 
+			             SelName, resultDeclType, 0, -1,
+                                     AttrList, MethodType == tok::minus);
+  if (pi == tok::objc_optional)
+      ObjcMethod->setDeclImplementation(ObjcMethodDecl::Optional);
   else
-    assert(0 && "Sema::ObjcBuildMethodDeclaration(): Unknown DeclTy");
+       ObjcMethod->setDeclImplementation(ObjcMethodDecl::Required);
   return ObjcMethod;
 }
 

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

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Mon Sep 17 17:36:42 2007
@@ -26,7 +26,6 @@
 class AttributeList;
 class ObjcIvarDecl;
 class ObjcMethodDecl;
-class ObjcProtoMethodDecl;
 class SelectorInfo;
 
 
@@ -615,6 +614,9 @@
 /// ObjcMethodDecl - An instance of this class is created to represent an instance
 /// or class method declaration.
 class ObjcMethodDecl : public Decl {
+public:
+  enum ImplementationControl { None, Required, Optional };
+private:
   // A unigue name for this method.
   SelectorInfo &Selector;
   
@@ -630,6 +632,9 @@
 
   /// instance (true) or class (false) method.
   bool IsInstance : 1;
+  /// @required/@optional
+  ImplementationControl DeclImplementation : 2;
+
 public:
   ObjcMethodDecl(SourceLocation L, SelectorInfo &SelId, QualType T,
 		 ParmVarDecl **paramInfo = 0, int numParams=-1,
@@ -658,6 +663,11 @@
 
   AttributeList *getMethodAttrs() const {return MethodAttrs;}
   bool isInstance() const { return IsInstance; }
+  // Related to protocols declared in  @protocol
+  void setDeclImplementation(ImplementationControl ic)
+         { DeclImplementation = ic; }
+  ImplementationControl  getImplementationControl() const
+                           { return DeclImplementation; }
   
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { 
@@ -667,39 +677,13 @@
   static bool classof(const ObjcMethodDecl *D) { return true; }
 };
 
-/// ObjcProtoMethodDecl - Each instance represents a method declared
-/// in a protocol. 
-///
-class ObjcProtoMethodDecl : public ObjcMethodDecl {
-public:
-  ObjcProtoMethodDecl(SourceLocation L, SelectorInfo &Id, QualType T,
-                      ParmVarDecl **paramInfo = 0, int numParams=-1,
-                      AttributeList *M = 0, bool isInstance = true,
-                      Decl *PrevDecl = 0) :
-  ObjcMethodDecl(ObjcProtoMethod, L, Id, T, paramInfo, numParams, 
-		 M, isInstance, PrevDecl) {}
-
-  enum ImplementationControl { None, Required, Optional };
-
-  void setDeclImplementation(ImplementationControl ic) 
-         { DeclImplementation = ic; }
-  ImplementationControl  getImplementationControl() const 
-			   { return DeclImplementation; }
-  // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) { return D->getKind() == ObjcProtoMethod; }
-  static bool classof(const ObjcMethodDecl *D) { return true; }
-
-private:
-  ImplementationControl DeclImplementation : 2;
-};
-
 class ObjcProtocolDecl : public TypeDecl {
   /// protocol instance methods
-  ObjcProtoMethodDecl **ProtoInsMethods;  // Null if not defined
+  ObjcMethodDecl **ProtoInsMethods;  // Null if not defined
   int NumProtoInsMethods;  // -1 if not defined
 
   /// protocol class methods
-  ObjcProtoMethodDecl **ProtoClsMethods;  // Null if not defined
+  ObjcMethodDecl **ProtoClsMethods;  // Null if not defined
   int NumProtoClsMethods;  // -1 if not defined
 
   bool isForwardProtoDecl; // declared with @protocol.

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

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Mon Sep 17 17:36:42 2007
@@ -453,15 +453,13 @@
                     IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs) {
     return 0;
   }
-  virtual DeclTy *ObjcBuildMethodDeclaration(DeclTy *IDecl,
-    tok::ObjCKeywordKind& pi, 
+  virtual DeclTy *ObjcBuildMethodDeclaration(tok::ObjCKeywordKind& pi, 
     SourceLocation MethodLoc, tok::TokenKind MethodType, TypeTy *ReturnType,
     ObjcKeywordDecl *Keywords, unsigned NumKeywords, 
     AttributeList *AttrList) {
     return 0;
   }
-  virtual DeclTy *ObjcBuildMethodDeclaration(DeclTy *IDecl,
-    tok::ObjCKeywordKind& pi, 
+  virtual DeclTy *ObjcBuildMethodDeclaration(tok::ObjCKeywordKind& pi, 
     SourceLocation MethodLoc, tok::TokenKind MethodType, TypeTy *ReturnType,
     IdentifierInfo *SelectorName, AttributeList *AttrList) {
     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=42070&r1=42069&r2=42070&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Mon Sep 17 17:36:42 2007
@@ -291,7 +291,7 @@
   void ParseObjCMethodRequirement();
   DeclTy *ParseObjCMethodPrototype(DeclTy *classOrCat,
 				   tok::ObjCKeywordKind& pi);
-  DeclTy *ParseObjCMethodDecl(DeclTy *CDecl, tok::ObjCKeywordKind& pi,
+  DeclTy *ParseObjCMethodDecl(tok::ObjCKeywordKind& pi,
 			      tok::TokenKind mType, 
 			      SourceLocation mLoc);
   void ParseObjCPropertyAttribute(DeclTy *interfaceDecl);





More information about the cfe-commits mailing list