]> granicus.if.org Git - clang/commitdiff
Patch to remove ObjcProtoMethodDecl and use ObjcMethodDecl
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 17 Sep 2007 22:36:42 +0000 (22:36 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 17 Sep 2007 22:36:42 +0000 (22:36 +0000)
instead for @protocol method decls.

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

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

index 8208c020494e45861297a6c5ab3b05e17930b0a9..0cbadbf9692d8a377806e2055f0b26ea81569fae 100644 (file)
@@ -298,12 +298,12 @@ void ObjcProtocolDecl::ObjcAddProtoMethods(ObjcMethodDecl **insMethods,
                                           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*));
   }
 }
index c2cf61d36777744a4e1b8cf1835554ce3c3d37cc..c4a785eed89a6f043117cb7f2a911d49e402b363 100644 (file)
@@ -375,7 +375,7 @@ Parser::DeclTy *Parser::ParseObjCMethodPrototype(DeclTy *IDecl,
   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 @@ Parser::TypeTy *Parser::ParseObjCTypeName() {
 ///   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 @@ Parser::DeclTy *Parser::ParseObjCMethodDecl(DeclTy *IDecl,
     // 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 @@ Parser::DeclTy *Parser::ParseObjCMethodDecl(DeclTy *IDecl,
   if (getLang().ObjC2 && Tok.getKind() == tok::kw___attribute) 
     methodAttrs = ParseAttributes();
 
-  return Actions.ObjcBuildMethodDeclaration(IDecl, pi,
+  return Actions.ObjcBuildMethodDeclaration(pi,
                                             mLoc, mType, ReturnType, 
                                             selIdent, methodAttrs);
 }
index b50993e7e2c6afed4c6643e935bafac90236b683..1b1aa781d1e23e8247d59ff811dfdb9fc9868624 100644 (file)
@@ -368,14 +368,12 @@ public:
 
   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);
index 24b6309b1a6a772b256dbcb26677b02d869ee959..53efacfd0ab6ed6ede7974ba727acd38640cc44d 100644 (file)
@@ -1264,8 +1264,7 @@ void Sema::ObjcAddMethodsToClass(DeclTy *ClassDecl,
   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 @@ Sema::DeclTy *Sema::ObjcBuildMethodDeclaration(DeclTy *IDecl,
     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 @@ Sema::DeclTy *Sema::ObjcBuildMethodDeclaration(DeclTy *IDecl,
   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;
 }
 
index 683e98489fb1c847948c3180a6c7741f25a6830a..6569b0657c2e7a7961616d0756b2c3432c543ddb 100644 (file)
@@ -26,7 +26,6 @@ class FunctionDecl;
 class AttributeList;
 class ObjcIvarDecl;
 class ObjcMethodDecl;
-class ObjcProtoMethodDecl;
 class SelectorInfo;
 
 
@@ -615,6 +614,9 @@ public:
 /// 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 @@ class ObjcMethodDecl : public Decl {
 
   /// 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 @@ public:
 
   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 @@ public:
   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.
index 960e4154fe1f28856d206c344a8c314b44672bc8..50c437dd414d355d94a2dffefa9da361adbeda8f 100644 (file)
@@ -453,15 +453,13 @@ public:
                     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;
index 89fd68eebdb4d7f353e1f5c5ac7ccbb72a570a99..1e51fe7f4b33a33390da57be95f2c8364a5d7b74 100644 (file)
@@ -291,7 +291,7 @@ private:
   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);