From 19c8576b7328f4dc2d07682f5da552875c1912ef Mon Sep 17 00:00:00 2001 From: John McCall Date: Tue, 16 Feb 2010 03:57:14 +0000 Subject: [PATCH] Make the various type-decl Types (and their associated ASTContext routines) accept const decls. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96325 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/ASTContext.h | 4 ++-- include/clang/AST/Type.h | 22 ++++++++++++---------- lib/AST/ASTContext.cpp | 15 ++++++++------- lib/AST/Type.cpp | 5 +++-- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index b1842c9d42..2ed9fd7080 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -537,11 +537,11 @@ public: /// getTypeDeclType - Return the unique reference to the type for /// the specified type declaration. - QualType getTypeDeclType(TypeDecl *Decl, TypeDecl* PrevDecl=0); + QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl* PrevDecl=0); /// getTypedefType - Return the unique reference to the type for the /// specified typename decl. - QualType getTypedefType(TypedefDecl *Decl); + QualType getTypedefType(const TypedefDecl *Decl); QualType getSubstTemplateTypeParmType(const TemplateTypeParmType *Replaced, QualType Replacement); diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index 2fe041f5e7..40e50988e6 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -1922,8 +1922,9 @@ public: class UnresolvedUsingType : public Type { UnresolvedUsingTypenameDecl *Decl; - UnresolvedUsingType(UnresolvedUsingTypenameDecl *D) - : Type(UnresolvedUsing, QualType(), true), Decl(D) {} + UnresolvedUsingType(const UnresolvedUsingTypenameDecl *D) + : Type(UnresolvedUsing, QualType(), true), + Decl(const_cast(D)) {} friend class ASTContext; // ASTContext creates these. public: @@ -1950,8 +1951,9 @@ public: class TypedefType : public Type { TypedefDecl *Decl; protected: - TypedefType(TypeClass tc, TypedefDecl *D, QualType can) - : Type(tc, can, can->isDependentType()), Decl(D) { + TypedefType(TypeClass tc, const TypedefDecl *D, QualType can) + : Type(tc, can, can->isDependentType()), + Decl(const_cast(D)) { assert(!isa(can) && "Invalid canonical type"); } friend class ASTContext; // ASTContext creates these. @@ -2100,7 +2102,7 @@ class TagType : public Type { friend class TagDecl; protected: - TagType(TypeClass TC, TagDecl *D, QualType can); + TagType(TypeClass TC, const TagDecl *D, QualType can); public: TagDecl *getDecl() const { return decl.getPointer(); } @@ -2124,10 +2126,10 @@ public: /// to detect TagType objects of structs/unions/classes. class RecordType : public TagType { protected: - explicit RecordType(RecordDecl *D) - : TagType(Record, reinterpret_cast(D), QualType()) { } + explicit RecordType(const RecordDecl *D) + : TagType(Record, reinterpret_cast(D), QualType()) { } explicit RecordType(TypeClass TC, RecordDecl *D) - : TagType(TC, reinterpret_cast(D), QualType()) { } + : TagType(TC, reinterpret_cast(D), QualType()) { } friend class ASTContext; // ASTContext creates these. public: @@ -2157,8 +2159,8 @@ public: /// EnumType - This is a helper class that allows the use of isa/cast/dyncast /// to detect TagType objects of enums. class EnumType : public TagType { - explicit EnumType(EnumDecl *D) - : TagType(Enum, reinterpret_cast(D), QualType()) { } + explicit EnumType(const EnumDecl *D) + : TagType(Enum, reinterpret_cast(D), QualType()) { } friend class ASTContext; // ASTContext creates these. public: diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 06a40728da..c23babb9a4 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -1817,29 +1817,30 @@ QualType ASTContext::getFunctionType(QualType ResultTy,const QualType *ArgArray, /// getTypeDeclType - Return the unique reference to the type for the /// specified type declaration. -QualType ASTContext::getTypeDeclType(TypeDecl *Decl, TypeDecl* PrevDecl) { +QualType ASTContext::getTypeDeclType(const TypeDecl *Decl, + const TypeDecl* PrevDecl) { assert(Decl && "Passed null for Decl param"); if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); - if (TypedefDecl *Typedef = dyn_cast(Decl)) + if (const TypedefDecl *Typedef = dyn_cast(Decl)) return getTypedefType(Typedef); else if (isa(Decl)) { assert(false && "Template type parameter types are always available."); - } else if (ObjCInterfaceDecl *ObjCInterface + } else if (const ObjCInterfaceDecl *ObjCInterface = dyn_cast(Decl)) return getObjCInterfaceType(ObjCInterface); - if (RecordDecl *Record = dyn_cast(Decl)) { + if (const RecordDecl *Record = dyn_cast(Decl)) { if (PrevDecl) Decl->TypeForDecl = PrevDecl->TypeForDecl; else Decl->TypeForDecl = new (*this, TypeAlignment) RecordType(Record); - } else if (EnumDecl *Enum = dyn_cast(Decl)) { + } else if (const EnumDecl *Enum = dyn_cast(Decl)) { if (PrevDecl) Decl->TypeForDecl = PrevDecl->TypeForDecl; else Decl->TypeForDecl = new (*this, TypeAlignment) EnumType(Enum); - } else if (UnresolvedUsingTypenameDecl *Using = + } else if (const UnresolvedUsingTypenameDecl *Using = dyn_cast(Decl)) { Decl->TypeForDecl = new (*this, TypeAlignment) UnresolvedUsingType(Using); } else @@ -1851,7 +1852,7 @@ QualType ASTContext::getTypeDeclType(TypeDecl *Decl, TypeDecl* PrevDecl) { /// getTypedefType - Return the unique reference to the type for the /// specified typename decl. -QualType ASTContext::getTypedefType(TypedefDecl *Decl) { +QualType ASTContext::getTypedefType(const TypedefDecl *Decl) { if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); QualType Canonical = getCanonicalType(Decl->getUnderlyingType()); diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 52d734ca7e..76cc382920 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -912,8 +912,9 @@ void DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID, E->Profile(ID, Context, true); } -TagType::TagType(TypeClass TC, TagDecl *D, QualType can) - : Type(TC, can, D->isDependentType()), decl(D, 0) {} +TagType::TagType(TypeClass TC, const TagDecl *D, QualType can) + : Type(TC, can, D->isDependentType()), + decl(const_cast(D), 0) {} bool RecordType::classof(const TagType *TT) { return isa(TT->getDecl()); -- 2.40.0