From: Chris Lattner Date: Sun, 6 Apr 2008 04:47:34 +0000 (+0000) Subject: This patch contains these changes: X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b048c9835969c4f7fe06264748be18ed4b442116;p=clang This patch contains these changes: -Renamed ContextDecl -> DeclContext -Removed DeclContext pointer from FieldDecl -EnumDecl inherits from DeclContext, instead of TagDecl Patch by Argiris Kirtzidis! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49261 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp index 26bfa01b26..7be16993ec 100644 --- a/Driver/RewriteTest.cpp +++ b/Driver/RewriteTest.cpp @@ -1839,8 +1839,7 @@ QualType RewriteTest::getSuperStructType() { FieldDecl *FieldDecls[2]; for (unsigned i = 0; i < 2; ++i) - FieldDecls[i] = FieldDecl::Create(*Context, SuperStructDecl, - SourceLocation(), 0, + FieldDecls[i] = FieldDecl::Create(*Context, SourceLocation(), 0, FieldTypes[i]); SuperStructDecl->defineBody(FieldDecls, 4); @@ -1867,8 +1866,7 @@ QualType RewriteTest::getConstantStringStructType() { FieldDecl *FieldDecls[4]; for (unsigned i = 0; i < 4; ++i) - FieldDecls[i] = FieldDecl::Create(*Context, ConstantStringDecl, - SourceLocation(), 0, + FieldDecls[i] = FieldDecl::Create(*Context, SourceLocation(), 0, FieldTypes[i]); ConstantStringDecl->defineBody(FieldDecls, 4); diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index d0cd999f9a..c6c77b43e6 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -58,15 +58,15 @@ class ScopedDecl : public NamedDecl { /// ScopedDecl *Next; - ContextDecl *CtxDecl; + DeclContext *CtxDecl; protected: - ScopedDecl(Kind DK, ContextDecl *CD, SourceLocation L, + ScopedDecl(Kind DK, DeclContext *CD, SourceLocation L, IdentifierInfo *Id, ScopedDecl *PrevDecl) : NamedDecl(DK, L, Id), NextDeclarator(PrevDecl), Next(0), CtxDecl(CD) {} public: - ContextDecl *getContextDecl() const { return CtxDecl; } + DeclContext *getDeclContext() const { return CtxDecl; } ScopedDecl *getNext() const { return Next; } void setNext(ScopedDecl *N) { Next = N; } @@ -83,8 +83,8 @@ public: // roughly global variables and functions, but also handles enums (which could // be defined inside or outside a function etc). bool isDefinedOutsideFunctionOrMethod() const { - if (getContextDecl()) - return !getContextDecl()->isFunctionOrMethod(); + if (getDeclContext()) + return !getDeclContext()->isFunctionOrMethod(); else return true; } @@ -110,7 +110,7 @@ class ValueDecl : public ScopedDecl { QualType DeclType; protected: - ValueDecl(Kind DK, ContextDecl *CD, SourceLocation L, + ValueDecl(Kind DK, DeclContext *CD, SourceLocation L, IdentifierInfo *Id, QualType T, ScopedDecl *PrevDecl) : ScopedDecl(DK, CD, L, Id, PrevDecl), DeclType(T) {} public: @@ -143,7 +143,7 @@ private: friend class StmtIteratorBase; protected: - VarDecl(Kind DK, ContextDecl *CD, SourceLocation L, IdentifierInfo *Id, QualType T, + VarDecl(Kind DK, DeclContext *CD, SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass SC, ScopedDecl *PrevDecl) : ValueDecl(DK, CD, L, Id, T, PrevDecl), Init(0) { SClass = SC; } public: @@ -196,12 +196,12 @@ protected: /// void foo() { int x; static int y; extern int z; } /// class BlockVarDecl : public VarDecl { - BlockVarDecl(ContextDecl *CD, SourceLocation L, + BlockVarDecl(DeclContext *CD, SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S, ScopedDecl *PrevDecl) : VarDecl(BlockVar, CD, L, Id, T, S, PrevDecl) {} public: - static BlockVarDecl *Create(ASTContext &C, ContextDecl *CD, SourceLocation L, + static BlockVarDecl *Create(ASTContext &C, DeclContext *CD, SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S, ScopedDecl *PrevDecl); // Implement isa/cast/dyncast/etc. @@ -220,12 +220,12 @@ protected: /// definitions (C99 6.9.2p2) using our type system (without storing a /// pointer to the decl's scope, which is transient). class FileVarDecl : public VarDecl { - FileVarDecl(ContextDecl *CD, SourceLocation L, + FileVarDecl(DeclContext *CD, SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S, ScopedDecl *PrevDecl) : VarDecl(FileVar, CD, L, Id, T, S, PrevDecl) {} public: - static FileVarDecl *Create(ASTContext &C, ContextDecl *CD, + static FileVarDecl *Create(ASTContext &C, DeclContext *CD, SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S, ScopedDecl *PrevDecl); @@ -247,13 +247,13 @@ class ParmVarDecl : public VarDecl { /// in, inout, etc. unsigned objcDeclQualifier : 6; - ParmVarDecl(ContextDecl *CD, SourceLocation L, + ParmVarDecl(DeclContext *CD, SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S, ScopedDecl *PrevDecl) : VarDecl(ParmVar, CD, L, Id, T, S, PrevDecl), objcDeclQualifier(OBJC_TQ_None) {} public: - static ParmVarDecl *Create(ASTContext &C, ContextDecl *CD, + static ParmVarDecl *Create(ASTContext &C, DeclContext *CD, SourceLocation L,IdentifierInfo *Id, QualType T, StorageClass S, ScopedDecl *PrevDecl); @@ -279,7 +279,7 @@ protected: /// FunctionDecl - An instance of this class is created to represent a function /// declaration or definition. -class FunctionDecl : public ValueDecl, public ContextDecl { +class FunctionDecl : public ValueDecl, public DeclContext { public: enum StorageClass { None, Extern, Static, PrivateExtern @@ -302,16 +302,16 @@ private: bool IsInline : 1; bool IsImplicit : 1; - FunctionDecl(ContextDecl *CD, SourceLocation L, + FunctionDecl(DeclContext *CD, SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S, bool isInline, ScopedDecl *PrevDecl) : ValueDecl(Function, CD, L, Id, T, PrevDecl), - ContextDecl(Function), + DeclContext(Function), ParamInfo(0), Body(0), DeclChain(0), SClass(S), IsInline(isInline), IsImplicit(0) {} virtual ~FunctionDecl(); public: - static FunctionDecl *Create(ASTContext &C, ContextDecl *CD, SourceLocation L, + static FunctionDecl *Create(ASTContext &C, DeclContext *CD, SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S = None, bool isInline = false, ScopedDecl *PrevDecl = 0); @@ -371,18 +371,14 @@ protected: class FieldDecl : public NamedDecl { QualType DeclType; Expr *BitWidth; - ContextDecl *CtxDecl; protected: - FieldDecl(Kind DK, ContextDecl *CD, - SourceLocation L, IdentifierInfo *Id, QualType T, + FieldDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, QualType T, Expr *BW = NULL) - : NamedDecl(DK, L, Id), DeclType(T), BitWidth(BW), CtxDecl(CD) {} - FieldDecl(RecordDecl *CD, SourceLocation L, - IdentifierInfo *Id, QualType T, Expr *BW) + : NamedDecl(DK, L, Id), DeclType(T), BitWidth(BW) {} + FieldDecl(SourceLocation L, IdentifierInfo *Id, QualType T, Expr *BW) : NamedDecl(Field, L, Id), DeclType(T), BitWidth(BW) {} public: - static FieldDecl *Create(ASTContext &C, RecordDecl *CD, - SourceLocation L, IdentifierInfo *Id, + static FieldDecl *Create(ASTContext &C, SourceLocation L, IdentifierInfo *Id, QualType T, Expr *BW = NULL); QualType getType() const { return DeclType; } @@ -390,7 +386,6 @@ public: bool isBitField() const { return BitWidth != NULL; } Expr *getBitWidth() const { return BitWidth; } - ContextDecl *getContextDecl() const { return CtxDecl; } // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return D->getKind() >= FieldFirst && D->getKind() <= FieldLast; @@ -415,7 +410,7 @@ class EnumConstantDecl : public ValueDecl { Expr *Init; // an integer constant expression llvm::APSInt Val; // The value. protected: - EnumConstantDecl(ContextDecl *CD, SourceLocation L, + EnumConstantDecl(DeclContext *CD, SourceLocation L, IdentifierInfo *Id, QualType T, Expr *E, const llvm::APSInt &V, ScopedDecl *PrevDecl) : ValueDecl(EnumConstant, CD, L, Id, T, PrevDecl), Init(E), Val(V) {} @@ -460,7 +455,7 @@ class TypeDecl : public ScopedDecl { Type *TypeForDecl; friend class ASTContext; protected: - TypeDecl(Kind DK, ContextDecl *CD, SourceLocation L, + TypeDecl(Kind DK, DeclContext *CD, SourceLocation L, IdentifierInfo *Id, ScopedDecl *PrevDecl) : ScopedDecl(DK, CD, L, Id, PrevDecl), TypeForDecl(0) {} public: @@ -475,13 +470,13 @@ public: class TypedefDecl : public TypeDecl { /// UnderlyingType - This is the type the typedef is set to. QualType UnderlyingType; - TypedefDecl(ContextDecl *CD, SourceLocation L, + TypedefDecl(DeclContext *CD, SourceLocation L, IdentifierInfo *Id, QualType T, ScopedDecl *PD) : TypeDecl(Typedef, CD, L, Id, PD), UnderlyingType(T) {} ~TypedefDecl() {} public: - static TypedefDecl *Create(ASTContext &C, ContextDecl *CD, + static TypedefDecl *Create(ASTContext &C, DeclContext *CD, SourceLocation L,IdentifierInfo *Id, QualType T, ScopedDecl *PD); @@ -504,14 +499,14 @@ protected: /// TagDecl - Represents the declaration of a struct/union/class/enum. -class TagDecl : public TypeDecl, public ContextDecl { +class TagDecl : public TypeDecl { /// IsDefinition - True if this is a definition ("struct foo {};"), false if /// it is a declaration ("struct foo;"). bool IsDefinition : 1; protected: - TagDecl(Kind DK, ContextDecl *CD, SourceLocation L, + TagDecl(Kind DK, DeclContext *CD, SourceLocation L, IdentifierInfo *Id, ScopedDecl *PrevDecl) - : TypeDecl(DK, CD, L, Id, PrevDecl), ContextDecl(DK) { + : TypeDecl(DK, CD, L, Id, PrevDecl) { IsDefinition = false; } public: @@ -542,7 +537,7 @@ protected: /// EnumDecl - Represents an enum. As an extension, we allow forward-declared /// enums. -class EnumDecl : public TagDecl { +class EnumDecl : public TagDecl, public DeclContext { /// ElementList - this is a linked list of EnumConstantDecl's which are linked /// together through their getNextDeclarator pointers. EnumConstantDecl *ElementList; @@ -552,14 +547,14 @@ class EnumDecl : public TagDecl { /// have a different type than this does. QualType IntegerType; - EnumDecl(ContextDecl *CD, SourceLocation L, + EnumDecl(DeclContext *CD, SourceLocation L, IdentifierInfo *Id, ScopedDecl *PrevDecl) - : TagDecl(Enum, CD, L, Id, PrevDecl) { + : TagDecl(Enum, CD, L, Id, PrevDecl), DeclContext(Enum) { ElementList = 0; IntegerType = QualType(); } public: - static EnumDecl *Create(ASTContext &C, ContextDecl *CD, + static EnumDecl *Create(ASTContext &C, DeclContext *CD, SourceLocation L, IdentifierInfo *Id, ScopedDecl *PrevDecl); @@ -612,7 +607,7 @@ class RecordDecl : public TagDecl { FieldDecl **Members; // Null if not defined. int NumMembers; // -1 if not defined. - RecordDecl(Kind DK, ContextDecl *CD, SourceLocation L, IdentifierInfo *Id, + RecordDecl(Kind DK, DeclContext *CD, SourceLocation L, IdentifierInfo *Id, ScopedDecl *PrevDecl) : TagDecl(DK, CD, L, Id, PrevDecl) { HasFlexibleArrayMember = false; assert(classof(static_cast(this)) && "Invalid Kind!"); @@ -621,7 +616,7 @@ class RecordDecl : public TagDecl { } public: - static RecordDecl *Create(ASTContext &C, Kind DK, ContextDecl *CD, + static RecordDecl *Create(ASTContext &C, Kind DK, DeclContext *CD, SourceLocation L, IdentifierInfo *Id, ScopedDecl *PrevDecl); diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h index ae8fdc7d9b..4f9cc0cb66 100644 --- a/include/clang/AST/DeclBase.h +++ b/include/clang/AST/DeclBase.h @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// // -// This file defines the Decl and ContextDecl interfaces. +// This file defines the Decl and DeclContext interfaces. // //===----------------------------------------------------------------------===// @@ -21,7 +21,7 @@ namespace clang { class FunctionDecl; class ObjCMethodDecl; -class TagDecl; +class EnumDecl; class ObjCInterfaceDecl; /// Decl - This represents one declaration (or definition), e.g. a variable, @@ -191,20 +191,20 @@ protected: void ReadInRec(llvm::Deserializer& D); }; -/// ContextDecl - This is used only as base class of specific decl types that +/// DeclContext - This is used only as base class of specific decl types that /// can act as declaration contexts. These decls are: /// /// FunctionDecl /// ObjCMethodDecl -/// TagDecl +/// EnumDecl /// ObjCInterfaceDecl /// -class ContextDecl { +class DeclContext { /// DeclKind - This indicates which class this is. Decl::Kind DeclKind : 8; // Used in the CastTo template to get the DeclKind - // from a Decl or a ContextDecl. ContextDecl doesn't have a getKind() method + // from a Decl or a DeclContext. DeclContext doesn't have a getKind() method // to avoid 'ambiguous access' compiler errors. template struct KindTrait { static Decl::Kind getKind(const T *D) { return D->getKind(); } @@ -221,23 +221,21 @@ class ContextDecl { return static_cast(const_cast(D)); case Decl::ObjCInterface: return static_cast(const_cast(D)); + case Decl::Enum: + return static_cast(const_cast(D)); default: - // check for TagDecl - if (DK >= Decl::TagFirst && DK <= Decl::TagLast) - return static_cast(const_cast(D)); - - assert(false && "a decl that inherits ContextDecl isn't handled"); + assert(false && "a decl that inherits DeclContext isn't handled"); return 0; } } protected: - ContextDecl(Decl::Kind K) : DeclKind(K) {} + DeclContext(Decl::Kind K) : DeclKind(K) {} public: - /// getParent - Returns the containing ContextDecl if this is a ScopedDecl, + /// getParent - Returns the containing DeclContext if this is a ScopedDecl, /// else returns NULL. - ContextDecl *getParent() const; + DeclContext *getParent() const; bool isFunctionOrMethod() const { switch (DeclKind) { @@ -249,80 +247,79 @@ public: } } - /// ToDecl and FromDecl make Decl <-> ContextDecl castings. + /// ToDecl and FromDecl make Decl <-> DeclContext castings. /// They are intended to be used by the simplify_type and cast_convert_val /// templates. - static Decl *ToDecl (const ContextDecl *D); - static ContextDecl *FromDecl (const Decl *D); + static Decl *ToDecl (const DeclContext *D); + static DeclContext *FromDecl (const Decl *D); static bool classof(const Decl *D) { switch (D->getKind()) { case Decl::Function: case Decl::ObjCMethod: case Decl::ObjCInterface: + case Decl::Enum: return true; default: - // check for TagDecl - return D->getKind() >= Decl::TagFirst && - D->getKind() <= Decl::TagLast; + return false; } } - static bool classof(const ContextDecl *D) { return true; } + static bool classof(const DeclContext *D) { return true; } static bool classof(const FunctionDecl *D) { return true; } static bool classof(const ObjCMethodDecl *D) { return true; } - static bool classof(const TagDecl *D) { return true; } + static bool classof(const EnumDecl *D) { return true; } static bool classof(const ObjCInterfaceDecl *D) { return true; } }; -template<> struct ContextDecl::KindTrait { - static Decl::Kind getKind(const ContextDecl *D) { return D->DeclKind; } +template<> struct DeclContext::KindTrait { + static Decl::Kind getKind(const DeclContext *D) { return D->DeclKind; } }; } // end clang. namespace llvm { -/// Implement simplify_type for ContextDecl, so that we can dyn_cast from -/// ContextDecl to a specific Decl class. - template<> struct simplify_type { +/// Implement simplify_type for DeclContext, so that we can dyn_cast from +/// DeclContext to a specific Decl class. + template<> struct simplify_type { typedef ::clang::Decl* SimpleType; - static SimpleType getSimplifiedValue(const ::clang::ContextDecl *Val) { - return ::clang::ContextDecl::ToDecl(Val); + static SimpleType getSimplifiedValue(const ::clang::DeclContext *Val) { + return ::clang::DeclContext::ToDecl(Val); } }; -template<> struct simplify_type< ::clang::ContextDecl*> - : public simplify_type {}; +template<> struct simplify_type< ::clang::DeclContext*> + : public simplify_type {}; -template<> struct simplify_type { +template<> struct simplify_type { typedef ::clang::Decl SimpleType; - static SimpleType &getSimplifiedValue(const ::clang::ContextDecl &Val) { - return *::clang::ContextDecl::ToDecl(&Val); + static SimpleType &getSimplifiedValue(const ::clang::DeclContext &Val) { + return *::clang::DeclContext::ToDecl(&Val); } }; -template<> struct simplify_type< ::clang::ContextDecl> - : public simplify_type {}; +template<> struct simplify_type< ::clang::DeclContext> + : public simplify_type {}; -/// Implement cast_convert_val for ContextDecl, so that we can dyn_cast from -/// a Decl class to ContextDecl. +/// Implement cast_convert_val for DeclContext, so that we can dyn_cast from +/// a Decl class to DeclContext. template -struct cast_convert_val< ::clang::ContextDecl,const FromTy,const FromTy> { - static ::clang::ContextDecl &doit(const FromTy &Val) { - return *::clang::ContextDecl::FromDecl(&Val); +struct cast_convert_val< ::clang::DeclContext,const FromTy,const FromTy> { + static ::clang::DeclContext &doit(const FromTy &Val) { + return *::clang::DeclContext::FromDecl(&Val); } }; template -struct cast_convert_val< ::clang::ContextDecl,FromTy,FromTy> - : public cast_convert_val< ::clang::ContextDecl,const FromTy,const FromTy> +struct cast_convert_val< ::clang::DeclContext,FromTy,FromTy> + : public cast_convert_val< ::clang::DeclContext,const FromTy,const FromTy> {}; template -struct cast_convert_val< ::clang::ContextDecl,const FromTy*,const FromTy*> { - static ::clang::ContextDecl *doit(const FromTy *Val) { - return ::clang::ContextDecl::FromDecl(Val); +struct cast_convert_val< ::clang::DeclContext,const FromTy*,const FromTy*> { + static ::clang::DeclContext *doit(const FromTy *Val) { + return ::clang::DeclContext::FromDecl(Val); } }; template -struct cast_convert_val< ::clang::ContextDecl,FromTy*,FromTy*> - : public cast_convert_val< ::clang::ContextDecl,const FromTy*,const FromTy*> +struct cast_convert_val< ::clang::DeclContext,FromTy*,FromTy*> + : public cast_convert_val< ::clang::DeclContext,const FromTy*,const FromTy*> {}; } // end namespace llvm diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index 9930f1cc3b..640dd37750 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -48,7 +48,7 @@ class ObjCPropertyDecl; /// A selector represents a unique name for a method. The selector names for /// the above methods are setMenu:, menu, replaceSubview:with:, and defaultMenu. /// -class ObjCMethodDecl : public Decl, public ContextDecl { +class ObjCMethodDecl : public Decl, public DeclContext { public: enum ImplementationControl { None, Required, Optional }; private: @@ -96,7 +96,7 @@ private: bool isVariadic = false, ImplementationControl impControl = None) : Decl(ObjCMethod, beginLoc), - ContextDecl(ObjCMethod), + DeclContext(ObjCMethod), IsInstance(isInstance), IsVariadic(isVariadic), DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None), MethodContext(static_cast(contextDecl)), @@ -198,7 +198,7 @@ public: /// Unlike C++, ObjC is a single-rooted class model. In Cocoa, classes /// typically inherit from NSObject (an exception is NSProxy). /// -class ObjCInterfaceDecl : public NamedDecl, public ContextDecl { +class ObjCInterfaceDecl : public NamedDecl, public DeclContext { /// TypeForDecl - This indicates the Type object that represents this /// TypeDecl. It is a cache maintained by ASTContext::getObjCInterfaceType Type *TypeForDecl; @@ -239,7 +239,7 @@ class ObjCInterfaceDecl : public NamedDecl, public ContextDecl { ObjCInterfaceDecl(SourceLocation atLoc, unsigned numRefProtos, IdentifierInfo *Id, bool FD, bool isInternal) - : NamedDecl(ObjCInterface, atLoc, Id), ContextDecl(ObjCInterface), + : NamedDecl(ObjCInterface, atLoc, Id), DeclContext(ObjCInterface), TypeForDecl(0), SuperClass(0), ReferencedProtocols(0), NumReferencedProtocols(0), Ivars(0), NumIvars(0), @@ -381,12 +381,10 @@ public: /// } /// class ObjCIvarDecl : public FieldDecl { - ObjCIvarDecl(ContextDecl *CD, SourceLocation L, - IdentifierInfo *Id, QualType T) - : FieldDecl(ObjCIvar, CD, L, Id, T) {} + ObjCIvarDecl(SourceLocation L, IdentifierInfo *Id, QualType T) + : FieldDecl(ObjCIvar, L, Id, T) {} public: - static ObjCIvarDecl *Create(ASTContext &C, ObjCInterfaceDecl *CD, - SourceLocation L, + static ObjCIvarDecl *Create(ASTContext &C, SourceLocation L, IdentifierInfo *Id, QualType T); enum AccessControl { diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 9e51b292fb..0708c704c5 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -1131,8 +1131,7 @@ QualType ASTContext::getCFConstantStringType() { FieldDecl *FieldDecls[4]; for (unsigned i = 0; i < 4; ++i) - FieldDecls[i] = FieldDecl::Create(*this, CFConstantStringTypeDecl, - SourceLocation(), 0, + FieldDecls[i] = FieldDecl::Create(*this, SourceLocation(), 0, FieldTypes[i]); CFConstantStringTypeDecl->defineBody(FieldDecls, 4); diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index b1a2499949..d97e0b33e5 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -204,7 +204,7 @@ void Decl::addDeclKind(Kind k) { // Decl Allocation/Deallocation Method Implementations //===----------------------------------------------------------------------===// -BlockVarDecl *BlockVarDecl::Create(ASTContext &C, ContextDecl *CD, +BlockVarDecl *BlockVarDecl::Create(ASTContext &C, DeclContext *CD, SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S, ScopedDecl *PrevDecl) { @@ -213,7 +213,7 @@ BlockVarDecl *BlockVarDecl::Create(ASTContext &C, ContextDecl *CD, } -FileVarDecl *FileVarDecl::Create(ASTContext &C, ContextDecl *CD, +FileVarDecl *FileVarDecl::Create(ASTContext &C, DeclContext *CD, SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S, ScopedDecl *PrevDecl) { @@ -221,7 +221,7 @@ FileVarDecl *FileVarDecl::Create(ASTContext &C, ContextDecl *CD, return new (Mem) FileVarDecl(CD, L, Id, T, S, PrevDecl); } -ParmVarDecl *ParmVarDecl::Create(ASTContext &C, ContextDecl *CD, +ParmVarDecl *ParmVarDecl::Create(ASTContext &C, DeclContext *CD, SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S, ScopedDecl *PrevDecl) { @@ -229,7 +229,7 @@ ParmVarDecl *ParmVarDecl::Create(ASTContext &C, ContextDecl *CD, return new (Mem) ParmVarDecl(CD, L, Id, T, S, PrevDecl); } -FunctionDecl *FunctionDecl::Create(ASTContext &C, ContextDecl *CD, +FunctionDecl *FunctionDecl::Create(ASTContext &C, DeclContext *CD, SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S, bool isInline, @@ -238,10 +238,10 @@ FunctionDecl *FunctionDecl::Create(ASTContext &C, ContextDecl *CD, return new (Mem) FunctionDecl(CD, L, Id, T, S, isInline, PrevDecl); } -FieldDecl *FieldDecl::Create(ASTContext &C, RecordDecl *CD, SourceLocation L, +FieldDecl *FieldDecl::Create(ASTContext &C, SourceLocation L, IdentifierInfo *Id, QualType T, Expr *BW) { void *Mem = C.getAllocator().Allocate(); - return new (Mem) FieldDecl(CD, L, Id, T, BW); + return new (Mem) FieldDecl(L, Id, T, BW); } @@ -254,7 +254,7 @@ EnumConstantDecl *EnumConstantDecl::Create(ASTContext &C, EnumDecl *CD, return new (Mem) EnumConstantDecl(CD, L, Id, T, E, V, PrevDecl); } -TypedefDecl *TypedefDecl::Create(ASTContext &C, ContextDecl *CD, +TypedefDecl *TypedefDecl::Create(ASTContext &C, DeclContext *CD, SourceLocation L, IdentifierInfo *Id, QualType T, ScopedDecl *PD) { @@ -262,14 +262,14 @@ TypedefDecl *TypedefDecl::Create(ASTContext &C, ContextDecl *CD, return new (Mem) TypedefDecl(CD, L, Id, T, PD); } -EnumDecl *EnumDecl::Create(ASTContext &C, ContextDecl *CD, SourceLocation L, +EnumDecl *EnumDecl::Create(ASTContext &C, DeclContext *CD, SourceLocation L, IdentifierInfo *Id, ScopedDecl *PrevDecl) { void *Mem = C.getAllocator().Allocate(); return new (Mem) EnumDecl(CD, L, Id, PrevDecl); } -RecordDecl *RecordDecl::Create(ASTContext &C, Kind DK, ContextDecl *CD, +RecordDecl *RecordDecl::Create(ASTContext &C, Kind DK, DeclContext *CD, SourceLocation L, IdentifierInfo *Id, ScopedDecl *PrevDecl) { void *Mem = C.getAllocator().Allocate(); @@ -330,22 +330,22 @@ const Attr *Decl::getAttrs() const { } //===----------------------------------------------------------------------===// -// ContextDecl Implementation +// DeclContext Implementation //===----------------------------------------------------------------------===// -ContextDecl *ContextDecl::getParent() const { +DeclContext *DeclContext::getParent() const { if (ScopedDecl *SD = dyn_cast(this)) - return SD->getContextDecl(); + return SD->getDeclContext(); else return NULL; } -Decl *ContextDecl::ToDecl (const ContextDecl *D) { +Decl *DeclContext::ToDecl (const DeclContext *D) { return CastTo(D); } -ContextDecl *ContextDecl::FromDecl (const Decl *D) { - return CastTo(D); +DeclContext *DeclContext::FromDecl (const Decl *D) { + return CastTo(D); } //===----------------------------------------------------------------------===// diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 5671dbe9b9..a8ef5aa473 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -45,11 +45,10 @@ ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C, isInternal); } -ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, ObjCInterfaceDecl *CD, - SourceLocation L, +ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, SourceLocation L, IdentifierInfo *Id, QualType T) { void *Mem = C.getAllocator().Allocate(); - return new (Mem) ObjCIvarDecl(CD, L, Id, T); + return new (Mem) ObjCIvarDecl(L, Id, T); } ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, diff --git a/lib/AST/DeclSerialization.cpp b/lib/AST/DeclSerialization.cpp index e6b3f93096..a2e9ce1b12 100644 --- a/lib/AST/DeclSerialization.cpp +++ b/lib/AST/DeclSerialization.cpp @@ -106,7 +106,7 @@ void NamedDecl::ReadInRec(Deserializer& D) { void ScopedDecl::EmitInRec(Serializer& S) const { NamedDecl::EmitInRec(S); S.EmitPtr(getNext()); // From ScopedDecl. - S.EmitPtr(cast_or_null(getContextDecl())); // From ScopedDecl. + S.EmitPtr(cast_or_null(getDeclContext())); // From ScopedDecl. } void ScopedDecl::ReadInRec(Deserializer& D) { @@ -114,7 +114,7 @@ void ScopedDecl::ReadInRec(Deserializer& D) { D.ReadPtr(Next); // From ScopedDecl. Decl *TmpD; D.ReadPtr(TmpD); // From ScopedDecl. - CtxDecl = cast_or_null(TmpD); + CtxDecl = cast_or_null(TmpD); } //===------------------------------------------------------------===// @@ -306,7 +306,7 @@ void FieldDecl::EmitImpl(Serializer& S) const { } FieldDecl* FieldDecl::CreateImpl(Deserializer& D) { - FieldDecl* decl = new FieldDecl(0, SourceLocation(), NULL, QualType(), 0); + FieldDecl* decl = new FieldDecl(SourceLocation(), NULL, QualType(), 0); decl->DeclType.ReadBackpatch(D); decl->ReadInRec(D); decl->BitWidth = D.ReadOwnedPtr(); diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 9e379e4be7..8c9bceae21 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -120,8 +120,7 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer) RecordDecl::Create(Context, Decl::Struct, NULL, SourceLocation(), &IT.get("objc_object"), 0); - FieldDecl *IsaDecl = FieldDecl::Create(Context, ObjectTag, - SourceLocation(), 0, + FieldDecl *IsaDecl = FieldDecl::Create(Context, SourceLocation(), 0, Context.getObjCClassType()); ObjectTag->defineBody(&IsaDecl, 1); QualType ObjT = Context.getPointerType(Context.getTagDeclType(ObjectTag)); diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index b1d0499d13..98ecf87ce6 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -32,7 +32,7 @@ namespace clang { class ASTConsumer; class Preprocessor; class Decl; - class ContextDecl; + class DeclContext; class NamedDecl; class ScopedDecl; class Expr; @@ -75,7 +75,7 @@ class Sema : public Action { /// the method decl for the method being parsed. ObjCMethodDecl *CurMethodDecl; - ContextDecl *CurContext; + DeclContext *CurContext; /// LabelMap - This is a mapping from label identifiers to the LabelStmt for /// it (which acts like the label decl in some ways). Forward referenced @@ -250,8 +250,8 @@ private: DeclTy **Elements, unsigned NumElements); private: /// Set the current declaration context until it gets popped. - void PushContextDecl(ContextDecl *CD); - void PopContextDecl(); + void PushDeclContext(DeclContext *CD); + void PopDeclContext(); /// Subroutines of ActOnDeclarator(). TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T, diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 882ec0e1a4..150478c1e7 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -40,14 +40,14 @@ Sema::DeclTy *Sema::isTypeName(const IdentifierInfo &II, Scope *S) { return 0; } -void Sema::PushContextDecl(ContextDecl *CD) { +void Sema::PushDeclContext(DeclContext *CD) { assert(CD->getParent() == CurContext && - "The next ContextDecl should be directly contained in the current one."); + "The next DeclContext should be directly contained in the current one."); CurContext = CD; } -void Sema::PopContextDecl() { - assert(CurContext && "ContextDecl imbalance!"); +void Sema::PopDeclContext() { + assert(CurContext && "DeclContext imbalance!"); CurContext = CurContext->getParent(); } @@ -1081,7 +1081,7 @@ Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) { Decl *decl = static_cast(ActOnDeclarator(GlobalScope, D, 0)); FunctionDecl *FD = cast(decl); CurFunctionDecl = FD; - PushContextDecl(FD); + PushDeclContext(FD); // Create Decl objects for each parameter, adding them to the FunctionDecl. llvm::SmallVector Params; @@ -1126,7 +1126,7 @@ Sema::DeclTy *Sema::ActOnFinishFunctionBody(DeclTy *D, StmtTy *Body) { MD->setBody((Stmt*)Body); CurMethodDecl = 0; } - PopContextDecl(); + PopDeclContext(); // Verify and clean out per-function state. // Check goto/label use. @@ -1353,8 +1353,8 @@ Sema::DeclTy *Sema::ActOnField(Scope *S, DeclTy *tagDecl, // FIXME: Chain fielddecls together. FieldDecl *NewFD; - if (RecordDecl *RD = dyn_cast(TagDecl)) - NewFD = FieldDecl::Create(Context, RD, Loc, II, T, BitWidth); + if (isa(TagDecl)) + NewFD = FieldDecl::Create(Context, Loc, II, T, BitWidth); else if (isa(TagDecl) || isa(TagDecl) || isa(TagDecl) || @@ -1362,7 +1362,7 @@ Sema::DeclTy *Sema::ActOnField(Scope *S, DeclTy *tagDecl, // properties can appear within a protocol. // See corresponding FIXME in DeclObjC.h:ObjCPropertyDecl. isa(TagDecl)) - NewFD = ObjCIvarDecl::Create(Context, dyn_cast(TagDecl), Loc, II, T); + NewFD = ObjCIvarDecl::Create(Context, Loc, II, T); else assert(0 && "Sema::ActOnField(): Unknown TagDecl"); diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 6b9b9e2d43..9cf1b3c425 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -33,7 +33,7 @@ void Sema::ObjCActOnStartOfMethodDef(Scope *FnBodyScope, DeclTy *D) { // Allow all of Sema to see that we are entering a method definition. CurMethodDecl = MDecl; - PushContextDecl(MDecl); + PushDeclContext(MDecl); // Create Decl objects for each parameter, entrring them in the scope for // binding to their use.