From: Steve Naroff Date: Mon, 1 Oct 2007 19:00:59 +0000 (+0000) Subject: Move ObjC decls to DeclObjC.h, a new AST header. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=980e508ca70d6de75d2abfd96b4681fc98bb2698;p=clang Move ObjC decls to DeclObjC.h, a new AST header. Update clients and add to project file. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42494 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/AST/ASTContext.cpp b/AST/ASTContext.cpp index cb5588b4b7..6039131899 100644 --- a/AST/ASTContext.cpp +++ b/AST/ASTContext.cpp @@ -13,6 +13,7 @@ #include "clang/AST/ASTContext.h" #include "clang/AST/Decl.h" +#include "clang/AST/DeclObjC.h" #include "clang/Lex/Preprocessor.h" #include "clang/Basic/TargetInfo.h" #include "llvm/ADT/SmallVector.h" diff --git a/AST/Decl.cpp b/AST/Decl.cpp index b8c9275a26..ddf4187a0e 100644 --- a/AST/Decl.cpp +++ b/AST/Decl.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "clang/AST/Decl.h" +#include "clang/AST/DeclObjC.h" #include "clang/Lex/IdentifierTable.h" using namespace clang; diff --git a/AST/Type.cpp b/AST/Type.cpp index f7779bc3c6..39646b7529 100644 --- a/AST/Type.cpp +++ b/AST/Type.cpp @@ -14,6 +14,7 @@ #include "clang/Lex/IdentifierTable.h" #include "clang/AST/Type.h" #include "clang/AST/Decl.h" +#include "clang/AST/DeclObjC.h" #include "clang/AST/Expr.h" #include "clang/Basic/TargetInfo.h" #include "llvm/Support/Streams.h" diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index 7cf76f5975..20226cb9b4 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -15,6 +15,7 @@ #include "clang/AST/ASTContext.h" #include "clang/AST/Builtins.h" #include "clang/AST/Decl.h" +#include "clang/AST/DeclObjC.h" #include "clang/AST/Expr.h" #include "clang/AST/Type.h" #include "clang/Parse/DeclSpec.h" diff --git a/Sema/SemaType.cpp b/Sema/SemaType.cpp index 5340928a19..1b61faa53e 100644 --- a/Sema/SemaType.cpp +++ b/Sema/SemaType.cpp @@ -14,6 +14,7 @@ #include "Sema.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Decl.h" +#include "clang/AST/DeclObjC.h" #include "clang/Parse/DeclSpec.h" #include "clang/Lex/IdentifierTable.h" #include "clang/Basic/LangOptions.h" diff --git a/clang.xcodeproj/project.pbxproj b/clang.xcodeproj/project.pbxproj index fca0464b47..314ed3ea3c 100644 --- a/clang.xcodeproj/project.pbxproj +++ b/clang.xcodeproj/project.pbxproj @@ -17,6 +17,7 @@ 355CF6840C90A8D400A08AA3 /* DeadStores.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 355CF6830C90A8D400A08AA3 /* DeadStores.cpp */; }; 356EF9B50C8F7DDF006650F5 /* LiveVariables.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 356EF9B40C8F7DDF006650F5 /* LiveVariables.cpp */; }; 35CFFE000CA1CBCB00E6F2BE /* StmtViz.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 35CFFDFF0CA1CBCB00E6F2BE /* StmtViz.cpp */; }; + 84AF36A10CB17A3B00C820A5 /* DeclObjC.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 84AF36A00CB17A3B00C820A5 /* DeclObjC.h */; }; 84D9A8880C1A57E100AC7ABC /* AttributeList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84D9A8870C1A57E100AC7ABC /* AttributeList.cpp */; }; 84D9A88C0C1A581300AC7ABC /* AttributeList.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 84D9A88B0C1A581300AC7ABC /* AttributeList.h */; }; DE01DA490B12ADA300AC22CE /* PPCallbacks.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE01DA480B12ADA300AC22CE /* PPCallbacks.h */; }; @@ -202,6 +203,7 @@ DEF2E95F0C5FBD74000C4259 /* InternalsManual.html in CopyFiles */, DEC63B1C0C7B940600DBF169 /* CFG.h in CopyFiles */, DEF7D9F70C9C8B1A0001F598 /* Rewriter.h in CopyFiles */, + 84AF36A10CB17A3B00C820A5 /* DeclObjC.h in CopyFiles */, ); runOnlyForDeploymentPostprocessing = 1; }; @@ -231,6 +233,7 @@ 35CFFE010CA1CBDD00E6F2BE /* StmtGraphTraits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StmtGraphTraits.h; path = clang/AST/StmtGraphTraits.h; sourceTree = ""; }; 35D1DDD10CA9C6D50096E967 /* DataflowSolver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DataflowSolver.h; path = clang/Analysis/FlowSensitive/DataflowSolver.h; sourceTree = ""; }; 35D1DDD20CA9C6D50096E967 /* DataflowValues.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DataflowValues.h; path = clang/Analysis/FlowSensitive/DataflowValues.h; sourceTree = ""; }; + 84AF36A00CB17A3B00C820A5 /* DeclObjC.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = DeclObjC.h; path = clang/AST/DeclObjC.h; sourceTree = ""; }; 84D9A8870C1A57E100AC7ABC /* AttributeList.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = AttributeList.cpp; path = Parse/AttributeList.cpp; sourceTree = ""; }; 84D9A88B0C1A581300AC7ABC /* AttributeList.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = AttributeList.h; path = clang/Parse/AttributeList.h; sourceTree = ""; }; 8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = clang; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -570,6 +573,7 @@ DEC8D98B0A9433BC00353FCA /* AST */ = { isa = PBXGroup; children = ( + 84AF36A00CB17A3B00C820A5 /* DeclObjC.h */, 35BFBD2B0C9EDE1E006CB644 /* ASTConsumer.h */, DEC8D9A30A94346E00353FCA /* AST.h */, DE75ED280B044DC90020CF81 /* ASTContext.h */, @@ -733,7 +737,6 @@ 08FB7793FE84155DC02AAC07 /* Project object */ = { isa = PBXProject; buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */; - compatibilityVersion = "Xcode 2.4"; hasScannedForEncodings = 1; mainGroup = 08FB7794FE84155DC02AAC07 /* clang */; projectDirPath = ""; diff --git a/include/clang/AST/AST.h b/include/clang/AST/AST.h index a185692985..b527f90a88 100644 --- a/include/clang/AST/AST.h +++ b/include/clang/AST/AST.h @@ -17,6 +17,7 @@ // This header exports all AST interfaces. #include "clang/AST/ASTContext.h" #include "clang/AST/Decl.h" +#include "clang/AST/DeclObjC.h" #include "clang/AST/Expr.h" #include "clang/AST/Type.h" #include "clang/AST/StmtVisitor.h" diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index 0258f98f43..83065e7a82 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -26,7 +26,8 @@ namespace clang { class TargetInfo; - + class ObjcImplementationDecl; + /// ASTContext - This class holds long-lived AST nodes (such as types and /// decls) that can be referred to throughout the semantic analysis of a file. class ASTContext { diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 5a8cd1acc4..5102a99d25 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -24,10 +24,6 @@ class Expr; class Stmt; class FunctionDecl; class AttributeList; -class ObjcIvarDecl; -class ObjcMethodDecl; -class ObjcProtocolDecl; -class ObjcCategoryDecl; /// Decl - This represents one declaration (or definition), e.g. a variable, /// typedef, function, struct, etc. @@ -550,402 +546,5 @@ public: static bool classof(const RecordDecl *D) { return true; } }; -class ObjcInterfaceDecl : public TypeDecl { - - /// Class's super class. - ObjcInterfaceDecl *SuperClass; - - /// Protocols referenced in interface header declaration - 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 class has no ivars - int NumIvars; // -1 if class has no ivars - - /// instance methods - ObjcMethodDecl **InsMethods; // Null if class has no instance methods - int NumInsMethods; // -1 if class has no instance methods - - /// class methods - 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; - - bool isForwardDecl; // declared with @class. -public: - ObjcInterfaceDecl(SourceLocation L, unsigned numRefProtos, - IdentifierInfo *Id, bool FD = false) - : TypeDecl(ObjcInterface, L, Id, 0), - SuperClass(0), - IntfRefProtocols(0), NumIntfRefProtocols(-1), - Ivars(0), NumIvars(-1), - InsMethods(0), NumInsMethods(-1), ClsMethods(0), NumClsMethods(-1), - ListCategories(0), - isForwardDecl(FD) { - AllocIntfRefProtocols(numRefProtos); - } - - void AllocIntfRefProtocols(unsigned numRefProtos) { - if (numRefProtos) { - IntfRefProtocols = new ObjcProtocolDecl*[numRefProtos]; - memset(IntfRefProtocols, '\0', - numRefProtos*sizeof(ObjcProtocolDecl*)); - NumIntfRefProtocols = numRefProtos; - } - } - - ObjcProtocolDecl **getIntfRefProtocols() const { return IntfRefProtocols; } - int getNumIntfRefProtocols() const { return NumIntfRefProtocols; } - - ObjcIvarDecl **getIntfDeclIvars() const { return Ivars; } - int getIntfDeclNumIvars() const { return NumIvars; } - - ObjcMethodDecl** getInsMethods() const { return InsMethods; } - int getNumInsMethods() const { return NumInsMethods; } - - ObjcMethodDecl** getClsMethods() const { return ClsMethods; } - int getNumClsMethods() const { return NumClsMethods; } - - void ObjcAddInstanceVariablesToClass(ObjcIvarDecl **ivars, - unsigned numIvars); - - void ObjcAddMethods(ObjcMethodDecl **insMethods, unsigned numInsMembers, - ObjcMethodDecl **clsMethods, unsigned numClsMembers); - - bool getIsForwardDecl() const { return isForwardDecl; } - void setIsForwardDecl(bool val) { isForwardDecl = val; } - - void setIntfRefProtocols(int idx, ObjcProtocolDecl *OID) { - assert((idx < NumIntfRefProtocols) && "index out of range"); - IntfRefProtocols[idx] = OID; - } - - ObjcInterfaceDecl *getSuperClass() const { return SuperClass; } - void setSuperClass(ObjcInterfaceDecl * superCls) { SuperClass = superCls; } - - ObjcCategoryDecl* getListCategories() const { return ListCategories; } - void setListCategories(ObjcCategoryDecl *category) { - ListCategories = category; - } - - static bool classof(const Decl *D) { - return D->getKind() == ObjcInterface; - } - static bool classof(const ObjcInterfaceDecl *D) { return true; } -}; - -class ObjcIvarDecl : public FieldDecl { -public: - ObjcIvarDecl(SourceLocation L, IdentifierInfo *Id, QualType T) - : FieldDecl(ObjcIvar, L, Id, T) {} - - enum AccessControl { - None, Private, Protected, Public, Package - }; - void setAccessControl(AccessControl ac) { DeclAccess = ac; } - AccessControl getAccessControl() const { return DeclAccess; } - - // Implement isa/cast/dyncast/etc. - static bool classof(const Decl *D) { return D->getKind() == ObjcIvar; } - static bool classof(const ObjcIvarDecl *D) { return true; } -private: - AccessControl DeclAccess : 3; -}; - -class ObjcClassDecl : public TypeDecl { - ObjcInterfaceDecl **ForwardDecls; // Null if not defined. - int NumForwardDecls; // -1 if not defined. -public: - ObjcClassDecl(SourceLocation L, unsigned nElts) - : TypeDecl(ObjcClass, L, 0, 0) { - if (nElts) { - ForwardDecls = new ObjcInterfaceDecl*[nElts]; - memset(ForwardDecls, '\0', nElts*sizeof(ObjcInterfaceDecl*)); - } - NumForwardDecls = nElts; - } - void setInterfaceDecl(int idx, ObjcInterfaceDecl *OID) { - assert((idx < NumForwardDecls) && "index out of range"); - ForwardDecls[idx] = OID; - } - static bool classof(const Decl *D) { - return D->getKind() == ObjcClass; - } - static bool classof(const ObjcClassDecl *D) { return true; } -}; - -/// 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: - /// Bitfields must be first fields in this class so they pack with those - /// declared in class Decl. - /// instance (true) or class (false) method. - bool IsInstance : 1; - /// @required/@optional - ImplementationControl DeclImplementation : 2; - - // A unigue name for this method. - Selector SelName; - - // Type of this method. - QualType MethodDeclType; - /// ParamInfo - new[]'d array of pointers to VarDecls for the formal - /// parameters of this Method. This is null if there are no formals. - ParmVarDecl **ParamInfo; - int NumMethodParams; // -1 if no parameters - - /// List of attributes for this method declaration. - AttributeList *MethodAttrs; - - /// Loc - location of this declaration. - SourceLocation Loc; - -public: - ObjcMethodDecl(SourceLocation L, Selector SelInfo, QualType T, - ParmVarDecl **paramInfo = 0, int numParams=-1, - AttributeList *M = 0, bool isInstance = true, - ImplementationControl impControl = None, - Decl *PrevDecl = 0) - : Decl(ObjcMethod), - IsInstance(isInstance), DeclImplementation(impControl), - SelName(SelInfo), MethodDeclType(T), - ParamInfo(paramInfo), NumMethodParams(numParams), - MethodAttrs(M), Loc(L) {} -#if 0 - ObjcMethodDecl(Kind DK, SourceLocation L, IdentifierInfo &SelId, QualType T, - ParmVarDecl **paramInfo = 0, int numParams=-1, - AttributeList *M = 0, bool isInstance = true, - Decl *PrevDecl = 0) - : Decl(DK), Selector(SelId), MethodDeclType(T), - ParamInfo(paramInfo), NumMethodParams(numParams), - MethodAttrs(M), IsInstance(isInstance) {} -#endif - virtual ~ObjcMethodDecl(); - bool isInstance() const { return IsInstance; } - ImplementationControl getImplementationControl() const { - return DeclImplementation; - } - - Selector getSelector() const { return SelName; } - QualType getMethodType() const { return MethodDeclType; } - unsigned getNumMethodParams() const { return NumMethodParams; } - ParmVarDecl *getMethodParamDecl(unsigned i) { - assert(i < getNumMethodParams() && "Illegal param #"); - return ParamInfo[i]; - } - void setMethodParams(ParmVarDecl **NewParamInfo, unsigned NumParams); - - AttributeList *getMethodAttrs() const {return MethodAttrs;} - SourceLocation getLocation() const { return Loc; } - - // Implement isa/cast/dyncast/etc. - static bool classof(const Decl *D) { - return D->getKind() == ObjcMethod; - } - static bool classof(const ObjcMethodDecl *D) { return true; } -}; - -class ObjcProtocolDecl : public TypeDecl { - /// referenced protocols - ObjcProtocolDecl **ReferencedProtocols; // Null if none - int NumReferencedProtocols; // -1 if none - - /// protocol instance methods - ObjcMethodDecl **ProtoInsMethods; // Null if not defined - int NumProtoInsMethods; // -1 if not defined - - /// protocol class methods - ObjcMethodDecl **ProtoClsMethods; // Null if not defined - int NumProtoClsMethods; // -1 if not defined - - bool isForwardProtoDecl; // declared with @protocol. -public: - ObjcProtocolDecl(SourceLocation L, unsigned numRefProtos, - IdentifierInfo *Id, bool FD = false) - : TypeDecl(ObjcProtocol, L, Id, 0), - ReferencedProtocols(0), NumReferencedProtocols(-1), - ProtoInsMethods(0), NumProtoInsMethods(-1), - ProtoClsMethods(0), NumProtoClsMethods(-1), - isForwardProtoDecl(FD) { - AllocReferencedProtocols(numRefProtos); - } - void AllocReferencedProtocols(unsigned numRefProtos) { - if (numRefProtos) { - ReferencedProtocols = new ObjcProtocolDecl*[numRefProtos]; - memset(ReferencedProtocols, '\0', - numRefProtos*sizeof(ObjcProtocolDecl*)); - NumReferencedProtocols = numRefProtos; - } - } - void ObjcAddProtoMethods(ObjcMethodDecl **insMethods, unsigned numInsMembers, - ObjcMethodDecl **clsMethods, unsigned numClsMembers); - - void setReferencedProtocols(int idx, ObjcProtocolDecl *OID) { - assert((idx < NumReferencedProtocols) && "index out of range"); - ReferencedProtocols[idx] = OID; - } - - ObjcProtocolDecl** getReferencedProtocols() const { - return ReferencedProtocols; - } - int getNumReferencedProtocols() const { return NumReferencedProtocols; } - - ObjcMethodDecl** getInsMethods() const { return ProtoInsMethods; } - int getNumInsMethods() const { return NumProtoInsMethods; } - - ObjcMethodDecl** getClsMethods() const { return ProtoClsMethods; } - int getNumClsMethods() const { return NumProtoClsMethods; } - - bool getIsForwardProtoDecl() const { return isForwardProtoDecl; } - void setIsForwardProtoDecl(bool val) { isForwardProtoDecl = val; } - - static bool classof(const Decl *D) { - return D->getKind() == ObjcProtocol; - } - static bool classof(const ObjcProtocolDecl *D) { return true; } -}; - -class ObjcForwardProtocolDecl : public TypeDecl { - ObjcProtocolDecl **ForwardProtocolDecls; // Null if not defined. - int NumForwardProtocolDecls; // -1 if not defined. - public: - ObjcForwardProtocolDecl(SourceLocation L, unsigned nElts) - : TypeDecl(ObjcForwardProtocol, L, 0, 0) { - if (nElts) { - ForwardProtocolDecls = new ObjcProtocolDecl*[nElts]; - memset(ForwardProtocolDecls, '\0', nElts*sizeof(ObjcProtocolDecl*)); - NumForwardProtocolDecls = nElts; - } - } - void setForwardProtocolDecl(int idx, ObjcProtocolDecl *OID) { - assert((idx < NumForwardProtocolDecls) && "index out of range"); - ForwardProtocolDecls[idx] = OID; - } - static bool classof(const Decl *D) { - return D->getKind() == ObjcForwardProtocol; - } - static bool classof(const ObjcForwardProtocolDecl *D) { return true; } -}; - -class ObjcCategoryDecl : public ScopedDecl { - /// Interface belonging to this category - ObjcInterfaceDecl *ClassInterface; - - /// Category name - IdentifierInfo *ObjcCatName; - - /// referenced protocols in this category - ObjcProtocolDecl **CatReferencedProtocols; // Null if none - int NumCatReferencedProtocols; // -1 if none - - /// category instance methods - ObjcMethodDecl **CatInsMethods; // Null if not defined - int NumCatInsMethods; // -1 if not defined - - /// category class methods - ObjcMethodDecl **CatClsMethods; // Null if not defined - int NumCatClsMethods; // -1 if not defined - - /// Next category belonging to this class - ObjcCategoryDecl *NextClassCategory; - -public: - ObjcCategoryDecl(SourceLocation L, unsigned numRefProtocol, - IdentifierInfo *Id) - : ScopedDecl(ObjcCategory, L, Id, 0), - ClassInterface(0), ObjcCatName(0), - CatReferencedProtocols(0), NumCatReferencedProtocols(-1), - CatInsMethods(0), NumCatInsMethods(-1), - CatClsMethods(0), NumCatClsMethods(-1), - NextClassCategory(0) { - if (numRefProtocol) { - CatReferencedProtocols = new ObjcProtocolDecl*[numRefProtocol]; - memset(CatReferencedProtocols, '\0', - numRefProtocol*sizeof(ObjcProtocolDecl*)); - NumCatReferencedProtocols = numRefProtocol; - } - } - - ObjcInterfaceDecl *getClassInterface() const { return ClassInterface; } - void setClassInterface(ObjcInterfaceDecl *IDecl) { ClassInterface = IDecl; } - - void setCatReferencedProtocols(int idx, ObjcProtocolDecl *OID) { - assert((idx < NumCatReferencedProtocols) && "index out of range"); - CatReferencedProtocols[idx] = OID; - } - - void ObjcAddCatMethods(ObjcMethodDecl **insMethods, unsigned numInsMembers, - ObjcMethodDecl **clsMethods, unsigned numClsMembers); - - IdentifierInfo *getCatName() const { return ObjcCatName; } - void setCatName(IdentifierInfo *catName) { ObjcCatName = catName; } - - ObjcCategoryDecl *getNextClassCategory() const { return NextClassCategory; } - void insertNextClassCategory() { - NextClassCategory = ClassInterface->getListCategories(); - ClassInterface->setListCategories(this); - } - - static bool classof(const Decl *D) { - return D->getKind() == ObjcCategory; - } - static bool classof(const ObjcCategoryDecl *D) { return true; } -}; - -class ObjcImplementationDecl : public TypeDecl { - - /// Implementation Class's super class. - ObjcInterfaceDecl *SuperClass; - - /// Optional Ivars/NumIvars - This is a new[]'d array of pointers to Decls. - ObjcIvarDecl **Ivars; // Null if not specified - int NumIvars; // -1 if not defined. - - /// implemented instance methods - ObjcMethodDecl **InsMethods; // Null if not defined - int NumInsMethods; // -1 if not defined - - /// implemented class methods - ObjcMethodDecl **ClsMethods; // Null if not defined - int NumClsMethods; // -1 if not defined - - public: - ObjcImplementationDecl(SourceLocation L, IdentifierInfo *Id, - ObjcInterfaceDecl* superDecl) - : TypeDecl(ObjcImplementation, L, Id, 0), - SuperClass(superDecl), - Ivars(0), NumIvars(-1), - InsMethods(0), NumInsMethods(-1), ClsMethods(0), NumClsMethods(-1) {} - - void ObjcAddInstanceVariablesToClassImpl(ObjcIvarDecl **ivars, - unsigned numIvars); - - void ObjcAddImplMethods(ObjcMethodDecl **insMethods, unsigned numInsMembers, - ObjcMethodDecl **clsMethods, unsigned numClsMembers); - - ObjcInterfaceDecl *getImplSuperClass() const { return SuperClass; } - - void setImplSuperClass(ObjcInterfaceDecl * superCls) - { SuperClass = superCls; } - - ObjcMethodDecl **getInsMethods() const { return InsMethods; } - int getNumInsMethods() const { return NumInsMethods; } - - ObjcMethodDecl **getClsMethods() const { return ClsMethods; } - int getNumClsMethods() const { return NumClsMethods; } - - static bool classof(const Decl *D) { - return D->getKind() == ObjcImplementation; - } - static bool classof(const ObjcImplementationDecl *D) { return true; } -}; - - } // end namespace clang #endif diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h new file mode 100644 index 0000000000..8d74036923 --- /dev/null +++ b/include/clang/AST/DeclObjC.h @@ -0,0 +1,428 @@ +//===--- DeclObjC.h - Classes for representing declarations -----*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Steve Naroff and is distributed under +// the University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the DeclObjC interface and subclasses. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_AST_DECLOBJC_H +#define LLVM_CLANG_AST_DECLOBJC_H + +#include "clang/AST/Decl.h" + +namespace clang { +class Expr; +class Stmt; +class FunctionDecl; +class AttributeList; +class ObjcIvarDecl; +class ObjcMethodDecl; +class ObjcProtocolDecl; +class ObjcCategoryDecl; + +class ObjcInterfaceDecl : public TypeDecl { + + /// Class's super class. + ObjcInterfaceDecl *SuperClass; + + /// Protocols referenced in interface header declaration + ObjcProtocolDecl **IntfRefProtocols; // Null if none + int NumIntfRefProtocols; // -1 if none + + /// Ivars/NumIvars - This is a new[]'d array of pointers to Decls. + ObjcIvarDecl **Ivars; // Null if not defined. + int NumIvars; // -1 if not defined. + + /// instance methods + ObjcMethodDecl **InsMethods; // Null if not defined + int NumInsMethods; // -1 if not defined + + /// class methods + ObjcMethodDecl **ClsMethods; // Null if not defined + int NumClsMethods; // -1 if not defined + + /// List of categories defined for this class. + ObjcCategoryDecl *ListCategories; + + bool isForwardDecl; // declared with @class. +public: + ObjcInterfaceDecl(SourceLocation L, unsigned numRefProtos, + IdentifierInfo *Id, bool FD = false) + : TypeDecl(ObjcInterface, L, Id, 0), + SuperClass(0), + IntfRefProtocols(0), NumIntfRefProtocols(-1), + Ivars(0), NumIvars(-1), + InsMethods(0), NumInsMethods(-1), ClsMethods(0), NumClsMethods(-1), + ListCategories(0), + isForwardDecl(FD) { + AllocIntfRefProtocols(numRefProtos); + } + + void AllocIntfRefProtocols(unsigned numRefProtos) { + if (numRefProtos) { + IntfRefProtocols = new ObjcProtocolDecl*[numRefProtos]; + memset(IntfRefProtocols, '\0', + numRefProtos*sizeof(ObjcProtocolDecl*)); + NumIntfRefProtocols = numRefProtos; + } + } + + ObjcProtocolDecl **getIntfRefProtocols() const { return IntfRefProtocols; } + int getNumIntfRefProtocols() const { return NumIntfRefProtocols; } + + ObjcIvarDecl **getIntfDeclIvars() const { return Ivars; } + int getIntfDeclNumIvars() const { return NumIvars; } + + ObjcMethodDecl** getInsMethods() const { return InsMethods; } + int getNumInsMethods() const { return NumInsMethods; } + + ObjcMethodDecl** getClsMethods() const { return ClsMethods; } + int getNumClsMethods() const { return NumClsMethods; } + + void ObjcAddInstanceVariablesToClass(ObjcIvarDecl **ivars, + unsigned numIvars); + + void ObjcAddMethods(ObjcMethodDecl **insMethods, unsigned numInsMembers, + ObjcMethodDecl **clsMethods, unsigned numClsMembers); + + bool getIsForwardDecl() const { return isForwardDecl; } + void setIsForwardDecl(bool val) { isForwardDecl = val; } + + void setIntfRefProtocols(int idx, ObjcProtocolDecl *OID) { + assert((idx < NumIntfRefProtocols) && "index out of range"); + IntfRefProtocols[idx] = OID; + } + + ObjcInterfaceDecl *getSuperClass() const { return SuperClass; } + void setSuperClass(ObjcInterfaceDecl * superCls) { SuperClass = superCls; } + + ObjcCategoryDecl* getListCategories() const { return ListCategories; } + void setListCategories(ObjcCategoryDecl *category) { + ListCategories = category; + } + + static bool classof(const Decl *D) { + return D->getKind() == ObjcInterface; + } + static bool classof(const ObjcInterfaceDecl *D) { return true; } +}; + +class ObjcIvarDecl : public FieldDecl { +public: + ObjcIvarDecl(SourceLocation L, IdentifierInfo *Id, QualType T) + : FieldDecl(ObjcIvar, L, Id, T) {} + + enum AccessControl { + None, Private, Protected, Public, Package + }; + void setAccessControl(AccessControl ac) { DeclAccess = ac; } + AccessControl getAccessControl() const { return DeclAccess; } + + // Implement isa/cast/dyncast/etc. + static bool classof(const Decl *D) { return D->getKind() == ObjcIvar; } + static bool classof(const ObjcIvarDecl *D) { return true; } +private: + AccessControl DeclAccess : 3; +}; + +class ObjcClassDecl : public TypeDecl { + ObjcInterfaceDecl **ForwardDecls; // Null if not defined. + int NumForwardDecls; // -1 if not defined. +public: + ObjcClassDecl(SourceLocation L, unsigned nElts) + : TypeDecl(ObjcClass, L, 0, 0) { + if (nElts) { + ForwardDecls = new ObjcInterfaceDecl*[nElts]; + memset(ForwardDecls, '\0', nElts*sizeof(ObjcInterfaceDecl*)); + } + NumForwardDecls = nElts; + } + void setInterfaceDecl(int idx, ObjcInterfaceDecl *OID) { + assert((idx < NumForwardDecls) && "index out of range"); + ForwardDecls[idx] = OID; + } + static bool classof(const Decl *D) { + return D->getKind() == ObjcClass; + } + static bool classof(const ObjcClassDecl *D) { return true; } +}; + +/// 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: + /// Bitfields must be first fields in this class so they pack with those + /// declared in class Decl. + /// instance (true) or class (false) method. + bool IsInstance : 1; + /// @required/@optional + ImplementationControl DeclImplementation : 2; + + // A unigue name for this method. + Selector SelName; + + // Type of this method. + QualType MethodDeclType; + /// ParamInfo - new[]'d array of pointers to VarDecls for the formal + /// parameters of this Method. This is null if there are no formals. + ParmVarDecl **ParamInfo; + int NumMethodParams; // -1 if no parameters + + /// List of attributes for this method declaration. + AttributeList *MethodAttrs; + + /// Loc - location of this declaration. + SourceLocation Loc; + +public: + ObjcMethodDecl(SourceLocation L, Selector SelInfo, QualType T, + ParmVarDecl **paramInfo = 0, int numParams=-1, + AttributeList *M = 0, bool isInstance = true, + ImplementationControl impControl = None, + Decl *PrevDecl = 0) + : Decl(ObjcMethod), + IsInstance(isInstance), DeclImplementation(impControl), + SelName(SelInfo), MethodDeclType(T), + ParamInfo(paramInfo), NumMethodParams(numParams), + MethodAttrs(M), Loc(L) {} +#if 0 + ObjcMethodDecl(Kind DK, SourceLocation L, IdentifierInfo &SelId, QualType T, + ParmVarDecl **paramInfo = 0, int numParams=-1, + AttributeList *M = 0, bool isInstance = true, + Decl *PrevDecl = 0) + : Decl(DK), Selector(SelId), MethodDeclType(T), + ParamInfo(paramInfo), NumMethodParams(numParams), + MethodAttrs(M), IsInstance(isInstance) {} +#endif + virtual ~ObjcMethodDecl(); + Selector getSelector() const { return SelName; } + QualType getMethodType() const { return MethodDeclType; } + unsigned getNumMethodParams() const { return NumMethodParams; } + ParmVarDecl *getMethodParamDecl(unsigned i) { + assert(i < getNumMethodParams() && "Illegal param #"); + return ParamInfo[i]; + } + void setMethodParams(ParmVarDecl **NewParamInfo, unsigned NumParams); + + 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; + } + static bool classof(const ObjcMethodDecl *D) { return true; } +}; + +class ObjcProtocolDecl : public TypeDecl { + /// referenced protocols + ObjcProtocolDecl **ReferencedProtocols; // Null if none + int NumReferencedProtocols; // -1 if none + + /// protocol instance methods + ObjcMethodDecl **ProtoInsMethods; // Null if not defined + int NumProtoInsMethods; // -1 if not defined + + /// protocol class methods + ObjcMethodDecl **ProtoClsMethods; // Null if not defined + int NumProtoClsMethods; // -1 if not defined + + bool isForwardProtoDecl; // declared with @protocol. +public: + ObjcProtocolDecl(SourceLocation L, unsigned numRefProtos, + IdentifierInfo *Id, bool FD = false) + : TypeDecl(ObjcProtocol, L, Id, 0), + ReferencedProtocols(0), NumReferencedProtocols(-1), + ProtoInsMethods(0), NumProtoInsMethods(-1), + ProtoClsMethods(0), NumProtoClsMethods(-1), + isForwardProtoDecl(FD) { + AllocReferencedProtocols(numRefProtos); + } + void AllocReferencedProtocols(unsigned numRefProtos) { + if (numRefProtos) { + ReferencedProtocols = new ObjcProtocolDecl*[numRefProtos]; + memset(ReferencedProtocols, '\0', + numRefProtos*sizeof(ObjcProtocolDecl*)); + NumReferencedProtocols = numRefProtos; + } + } + void ObjcAddProtoMethods(ObjcMethodDecl **insMethods, unsigned numInsMembers, + ObjcMethodDecl **clsMethods, unsigned numClsMembers); + + void setReferencedProtocols(int idx, ObjcProtocolDecl *OID) { + assert((idx < NumReferencedProtocols) && "index out of range"); + ReferencedProtocols[idx] = OID; + } + + ObjcProtocolDecl** getReferencedProtocols() const { + return ReferencedProtocols; + } + int getNumReferencedProtocols() const { return NumReferencedProtocols; } + + ObjcMethodDecl** getInsMethods() const { return ProtoInsMethods; } + int getNumInsMethods() const { return NumProtoInsMethods; } + + ObjcMethodDecl** getClsMethods() const { return ProtoClsMethods; } + int getNumClsMethods() const { return NumProtoClsMethods; } + + bool getIsForwardProtoDecl() const { return isForwardProtoDecl; } + void setIsForwardProtoDecl(bool val) { isForwardProtoDecl = val; } + + static bool classof(const Decl *D) { + return D->getKind() == ObjcProtocol; + } + static bool classof(const ObjcProtocolDecl *D) { return true; } +}; + +class ObjcForwardProtocolDecl : public TypeDecl { + ObjcProtocolDecl **ForwardProtocolDecls; // Null if not defined. + int NumForwardProtocolDecls; // -1 if not defined. + public: + ObjcForwardProtocolDecl(SourceLocation L, unsigned nElts) + : TypeDecl(ObjcForwardProtocol, L, 0, 0) { + if (nElts) { + ForwardProtocolDecls = new ObjcProtocolDecl*[nElts]; + memset(ForwardProtocolDecls, '\0', nElts*sizeof(ObjcProtocolDecl*)); + NumForwardProtocolDecls = nElts; + } + } + void setForwardProtocolDecl(int idx, ObjcProtocolDecl *OID) { + assert((idx < NumForwardProtocolDecls) && "index out of range"); + ForwardProtocolDecls[idx] = OID; + } + static bool classof(const Decl *D) { + return D->getKind() == ObjcForwardProtocol; + } + static bool classof(const ObjcForwardProtocolDecl *D) { return true; } +}; + +class ObjcCategoryDecl : public ScopedDecl { + /// Interface belonging to this category + ObjcInterfaceDecl *ClassInterface; + + /// Category name + IdentifierInfo *ObjcCatName; + + /// referenced protocols in this category + ObjcProtocolDecl **CatReferencedProtocols; // Null if none + int NumCatReferencedProtocols; // -1 if none + + /// category instance methods + ObjcMethodDecl **CatInsMethods; // Null if not defined + int NumCatInsMethods; // -1 if not defined + + /// category class methods + ObjcMethodDecl **CatClsMethods; // Null if not defined + int NumCatClsMethods; // -1 if not defined + + /// Next category belonging to this class + ObjcCategoryDecl *NextClassCategory; + +public: + ObjcCategoryDecl(SourceLocation L, unsigned numRefProtocol, + IdentifierInfo *Id) + : ScopedDecl(ObjcCategory, L, Id, 0), + ClassInterface(0), ObjcCatName(0), + CatReferencedProtocols(0), NumCatReferencedProtocols(-1), + CatInsMethods(0), NumCatInsMethods(-1), + CatClsMethods(0), NumCatClsMethods(-1), + NextClassCategory(0) { + if (numRefProtocol) { + CatReferencedProtocols = new ObjcProtocolDecl*[numRefProtocol]; + memset(CatReferencedProtocols, '\0', + numRefProtocol*sizeof(ObjcProtocolDecl*)); + NumCatReferencedProtocols = numRefProtocol; + } + } + + ObjcInterfaceDecl *getClassInterface() const { return ClassInterface; } + void setClassInterface(ObjcInterfaceDecl *IDecl) { ClassInterface = IDecl; } + + void setCatReferencedProtocols(int idx, ObjcProtocolDecl *OID) { + assert((idx < NumCatReferencedProtocols) && "index out of range"); + CatReferencedProtocols[idx] = OID; + } + + void ObjcAddCatMethods(ObjcMethodDecl **insMethods, unsigned numInsMembers, + ObjcMethodDecl **clsMethods, unsigned numClsMembers); + + IdentifierInfo *getCatName() const { return ObjcCatName; } + void setCatName(IdentifierInfo *catName) { ObjcCatName = catName; } + + ObjcCategoryDecl *getNextClassCategory() const { return NextClassCategory; } + void insertNextClassCategory() { + NextClassCategory = ClassInterface->getListCategories(); + ClassInterface->setListCategories(this); + } + + static bool classof(const Decl *D) { + return D->getKind() == ObjcCategory; + } + static bool classof(const ObjcCategoryDecl *D) { return true; } +}; + +class ObjcImplementationDecl : public TypeDecl { + + /// Implementation Class's super class. + ObjcInterfaceDecl *SuperClass; + + /// Optional Ivars/NumIvars - This is a new[]'d array of pointers to Decls. + ObjcIvarDecl **Ivars; // Null if not specified + int NumIvars; // -1 if not defined. + + /// implemented instance methods + ObjcMethodDecl **InsMethods; // Null if not defined + int NumInsMethods; // -1 if not defined + + /// implemented class methods + ObjcMethodDecl **ClsMethods; // Null if not defined + int NumClsMethods; // -1 if not defined + + public: + ObjcImplementationDecl(SourceLocation L, IdentifierInfo *Id, + ObjcInterfaceDecl* superDecl) + : TypeDecl(ObjcImplementation, L, Id, 0), + SuperClass(superDecl), + Ivars(0), NumIvars(-1), + InsMethods(0), NumInsMethods(-1), ClsMethods(0), NumClsMethods(-1) {} + + void ObjcAddInstanceVariablesToClassImpl(ObjcIvarDecl **ivars, + unsigned numIvars); + + void ObjcAddImplMethods(ObjcMethodDecl **insMethods, unsigned numInsMembers, + ObjcMethodDecl **clsMethods, unsigned numClsMembers); + + ObjcInterfaceDecl *getImplSuperClass() const { return SuperClass; } + + void setImplSuperClass(ObjcInterfaceDecl * superCls) + { SuperClass = superCls; } + + ObjcMethodDecl **getInsMethods() const { return InsMethods; } + int getNumInsMethods() const { return NumInsMethods; } + + ObjcMethodDecl **getClsMethods() const { return ClsMethods; } + int getNumClsMethods() const { return NumClsMethods; } + + static bool classof(const Decl *D) { + return D->getKind() == ObjcImplementation; + } + static bool classof(const ObjcImplementationDecl *D) { return true; } +}; + + +} // end namespace clang +#endif diff --git a/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h b/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h index e8f74c0a7b..a2f2fa72e4 100644 --- a/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h +++ b/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h @@ -19,6 +19,7 @@ #include "clang/Analysis/Visitors/CFGRecStmtVisitor.h" #include "clang/AST/Decl.h" +#include "clang/AST/DeclObjC.h" #define DISPATCH_CASE(CASE,CLASS) \ case Decl::CASE: \