Patch to remove ObjcProtoMethodDecl and use ObjcMethodDecl
instead for @protocol method decls.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42070 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/AST/Decl.cpp b/AST/Decl.cpp
index 8208c02..0cbadbf 100644
--- a/AST/Decl.cpp
+++ b/AST/Decl.cpp
@@ -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*));
}
}
diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp
index c2cf61d..c4a785e 100644
--- a/Parse/ParseObjc.cpp
+++ b/Parse/ParseObjc.cpp
@@ -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);
}
diff --git a/Sema/Sema.h b/Sema/Sema.h
index b50993e..1b1aa78 100644
--- a/Sema/Sema.h
+++ b/Sema/Sema.h
@@ -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);
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index 24b6309..53efacf 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -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;
}
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h
index 683e984..6569b06 100644
--- a/include/clang/AST/Decl.h
+++ b/include/clang/AST/Decl.h
@@ -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.
diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h
index 960e415..50c437d 100644
--- a/include/clang/Parse/Action.h
+++ b/include/clang/Parse/Action.h
@@ -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;
diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h
index 89fd68e..1e51fe7 100644
--- a/include/clang/Parse/Parser.h
+++ b/include/clang/Parse/Parser.h
@@ -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);