From 3a63da7053b07583fe3881388ef35181b2d34d3e Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Sat, 29 Sep 2007 18:24:58 +0000 Subject: [PATCH] This patch fixes all issues mentioned in clattner's feedback of September 28, 2007 4:39:24 PM PDT Please let me know if I missed anything. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42473 91177308-0d34-0410-b5e6-96231b3b80d8 --- Parse/ParseObjc.cpp | 1 - Sema/SemaDecl.cpp | 9 +++--- include/clang/AST/Decl.h | 61 ++++++++++++++++++++++------------------ 3 files changed, 38 insertions(+), 33 deletions(-) diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp index e367834f70..859776f6a0 100644 --- a/Parse/ParseObjc.cpp +++ b/Parse/ParseObjc.cpp @@ -270,7 +270,6 @@ void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl, /// Insert collected methods declarations into the @interface object. Actions.ObjcAddMethodsToClass(CurScope, interfaceDecl,&allMethods[0],allMethods.size()); - return; } /// Parse property attribute declarations. diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index c6c1b1ecc0..ac2be7faeb 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -1678,12 +1678,11 @@ Sema::DeclTy *Sema::ObjcBuildMethodDeclaration(SourceLocation MethodLoc, QualType resultDeclType = QualType::getFromOpaquePtr(ReturnType); ObjcMethodDecl* ObjcMethod = new ObjcMethodDecl(MethodLoc, Sel, resultDeclType, 0, -1, AttrList, - MethodType == tok::minus); + MethodType == tok::minus, + MethodDeclKind == tok::objc_optional ? + ObjcMethodDecl::Optional : + ObjcMethodDecl::Required); ObjcMethod->setMethodParams(&Params[0], Sel.getNumArgs()); - if (MethodDeclKind == tok::objc_optional) - ObjcMethod->setDeclImplementation(ObjcMethodDecl::Optional); - else - ObjcMethod->setDeclImplementation(ObjcMethodDecl::Required); return ObjcMethod; } diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 98a34406d3..865bf6fd9e 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -56,6 +56,9 @@ public: IDNS_Protocol, IDNS_Ordinary }; + + enum ImplementationControl { None, Required, Optional }; + private: /// DeclKind - This indicates which class this is. Kind DeclKind : 8; @@ -63,10 +66,22 @@ private: /// InvalidDecl - This indicates a semantic error occurred. unsigned int InvalidDecl : 1; + /// instance (true) or class (false) method. + bool IsInstance : 1; + /// @required/@optional + ImplementationControl DeclImplementation : 2; + protected: - Decl(Kind DK) : DeclKind(DK), InvalidDecl(0) { + Decl(Kind DK) : DeclKind(DK), InvalidDecl(0), + IsInstance(false), DeclImplementation(None) { if (Decl::CollectingStats()) addDeclKind(DK); } + + Decl(Kind DK, bool isInstance, ImplementationControl implControl) + : DeclKind(DK), InvalidDecl(0), + IsInstance(isInstance), DeclImplementation(implControl) { + if (Decl::CollectingStats()) addDeclKind(DK); + } virtual ~Decl(); public: @@ -78,7 +93,10 @@ public: /// allows for graceful error recovery. void setInvalidDecl() { InvalidDecl = 1; } int isInvalidDecl() const { return InvalidDecl; } - + bool isInstance() const { return IsInstance; } + ImplementationControl getImplementationControl() const + { return DeclImplementation; } + IdentifierNamespace getIdentifierNamespace() const { switch (DeclKind) { default: assert(0 && "Unknown decl kind!"); @@ -551,20 +569,20 @@ class ObjcInterfaceDecl : public TypeDecl { ObjcInterfaceDecl *SuperClass; /// Protocols referenced in interface header declaration - ObjcProtocolDecl **IntfRefProtocols; // Null if none - int NumIntfRefProtocols; // -1 if none + ObjcProtocolDecl **IntfRefProtocols; // Null if no referenced protocols + int NumIntfRefProtocols; // -1 if no referenced protocols /// Ivars/NumIvars - This is a new[]'d array of pointers to Decls. - ObjcIvarDecl **Ivars; // Null if not defined. - int NumIvars; // -1 if not defined. + ObjcIvarDecl **Ivars; // Null if class has no ivars + int NumIvars; // -1 if class has no ivars /// instance methods - ObjcMethodDecl **InsMethods; // Null if not defined - int NumInsMethods; // -1 if not defined + ObjcMethodDecl **InsMethods; // Null if class has no instance methods + int NumInsMethods; // -1 if class has no instance methods /// class methods - ObjcMethodDecl **ClsMethods; // Null if not defined - int NumClsMethods; // -1 if not defined + ObjcMethodDecl **ClsMethods; // Null if class has no class methods + int NumClsMethods; // -1 if class has no class methods /// List of categories defined for this class. ObjcCategoryDecl *ListCategories; @@ -675,8 +693,6 @@ 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. Selector SelName; @@ -694,19 +710,16 @@ private: /// Loc - location of this declaration. SourceLocation Loc; - /// instance (true) or class (false) method. - bool IsInstance : 1; - /// @required/@optional - ImplementationControl DeclImplementation : 2; - public: ObjcMethodDecl(SourceLocation L, Selector SelInfo, QualType T, ParmVarDecl **paramInfo = 0, int numParams=-1, - AttributeList *M = 0, bool isInstance = true, + AttributeList *M = 0, bool isInstance = true, + ImplementationControl impControl = None, Decl *PrevDecl = 0) - : Decl(ObjcMethod), SelName(SelInfo), MethodDeclType(T), + : Decl(ObjcMethod, isInstance, impControl), + SelName(SelInfo), MethodDeclType(T), ParamInfo(paramInfo), NumMethodParams(numParams), - MethodAttrs(M), Loc(L), IsInstance(isInstance) {} + MethodAttrs(M), Loc(L) {} #if 0 ObjcMethodDecl(Kind DK, SourceLocation L, IdentifierInfo &SelId, QualType T, ParmVarDecl **paramInfo = 0, int numParams=-1, @@ -728,13 +741,7 @@ public: AttributeList *getMethodAttrs() const {return MethodAttrs;} SourceLocation getLocation() const { return Loc; } - 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) { return D->getKind() == ObjcMethod -- 2.40.0