It looks like this broke self-host with an assertion, so I've reverted it in r106100.
- Doug On Jun 16, 2010, at 7:59 AM, Abramo Bagnara wrote: > Author: abramo > Date: Wed Jun 16 09:59:30 2010 > New Revision: 106099 > > URL: http://llvm.org/viewvc/llvm-project?rev=106099&view=rev > Log: > Added TemplateTypeParmType::getDecl(). > > Modified: > cfe/trunk/include/clang/AST/ASTContext.h > cfe/trunk/include/clang/AST/CanonicalType.h > cfe/trunk/include/clang/AST/DeclTemplate.h > cfe/trunk/include/clang/AST/Type.h > cfe/trunk/lib/AST/ASTContext.cpp > cfe/trunk/lib/AST/DeclPrinter.cpp > cfe/trunk/lib/AST/DeclTemplate.cpp > cfe/trunk/lib/AST/TypePrinter.cpp > cfe/trunk/lib/Sema/SemaTemplate.cpp > cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp > cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp > > Modified: cfe/trunk/include/clang/AST/ASTContext.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=106099&r1=106098&r2=106099&view=diff > ============================================================================== > --- cfe/trunk/include/clang/AST/ASTContext.h (original) > +++ cfe/trunk/include/clang/AST/ASTContext.h Wed Jun 16 09:59:30 2010 > @@ -601,7 +601,7 @@ > > QualType getTemplateTypeParmType(unsigned Depth, unsigned Index, > bool ParameterPack, > - IdentifierInfo *Name = 0); > + TemplateTypeParmDecl *ParmDecl = 0); > > QualType getTemplateSpecializationType(TemplateName T, > const TemplateArgument *Args, > > Modified: cfe/trunk/include/clang/AST/CanonicalType.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CanonicalType.h?rev=106099&r1=106098&r2=106099&view=diff > ============================================================================== > --- cfe/trunk/include/clang/AST/CanonicalType.h (original) > +++ cfe/trunk/include/clang/AST/CanonicalType.h Wed Jun 16 09:59:30 2010 > @@ -640,7 +640,6 @@ > LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getDepth) > LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(unsigned, getIndex) > LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isParameterPack) > - LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(IdentifierInfo *, getName) > }; > > template<> > > Modified: cfe/trunk/include/clang/AST/DeclTemplate.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclTemplate.h?rev=106099&r1=106098&r2=106099&view=diff > ============================================================================== > --- cfe/trunk/include/clang/AST/DeclTemplate.h (original) > +++ cfe/trunk/include/clang/AST/DeclTemplate.h Wed Jun 16 09:59:30 2010 > @@ -662,18 +662,13 @@ > /// default argument. > bool InheritedDefault : 1; > > - /// \brief Whether this is a parameter pack. > - bool ParameterPack : 1; > - > /// \brief The default template argument, if any. > TypeSourceInfo *DefaultArgument; > > TemplateTypeParmDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, > - bool Typename, QualType Type, bool ParameterPack) > + bool Typename) > : TypeDecl(TemplateTypeParm, DC, L, Id), Typename(Typename), > - InheritedDefault(false), ParameterPack(ParameterPack), > DefaultArgument() { > - TypeForDecl = Type.getTypePtr(); > - } > + InheritedDefault(false), DefaultArgument() { } > > public: > static TemplateTypeParmDecl *Create(ASTContext &C, DeclContext *DC, > @@ -724,7 +719,7 @@ > unsigned getIndex() const; > > /// \brief Returns whether this is a parameter pack. > - bool isParameterPack() const { return ParameterPack; } > + bool isParameterPack() const; > > // Implement isa/cast/dyncast/etc. > static bool classof(const Decl *D) { return classofKind(D->getKind()); } > > Modified: cfe/trunk/include/clang/AST/Type.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=106099&r1=106098&r2=106099&view=diff > ============================================================================== > --- cfe/trunk/include/clang/AST/Type.h (original) > +++ cfe/trunk/include/clang/AST/Type.h Wed Jun 16 09:59:30 2010 > @@ -2311,42 +2311,63 @@ > }; > > class TemplateTypeParmType : public Type, public llvm::FoldingSetNode { > - unsigned Depth : 15; > - unsigned Index : 16; > - unsigned ParameterPack : 1; > - IdentifierInfo *Name; > + // Helper data collector for canonical types. > + struct CanonicalTTPTInfo { > + unsigned Depth : 15; > + unsigned Index : 16; > + unsigned ParameterPack : 1; > + }; > + > + union { > + // Info for the canonical type. > + CanonicalTTPTInfo CanTTPTInfo; > + // Info for the non-canonical type. > + TemplateTypeParmDecl *TTPDecl; > + }; > > - TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N, > - QualType Canon) > + /// Build a non-canonical type. > + TemplateTypeParmType(TemplateTypeParmDecl *TTPDecl, QualType Canon) > : Type(TemplateTypeParm, Canon, /*Dependent=*/true), > - Depth(D), Index(I), ParameterPack(PP), Name(N) { } > + TTPDecl(TTPDecl) { } > > + /// Build the canonical type. > TemplateTypeParmType(unsigned D, unsigned I, bool PP) > - : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true), > - Depth(D), Index(I), ParameterPack(PP), Name(0) { } > + : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true) { > + CanTTPTInfo.Depth = D; > + CanTTPTInfo.Index = I; > + CanTTPTInfo.ParameterPack = PP; > + } > > friend class ASTContext; // ASTContext creates these > > + const CanonicalTTPTInfo& getCanTTPTInfo() const { > + QualType Can = getCanonicalTypeInternal(); > + return Can->getAs<TemplateTypeParmType>()->CanTTPTInfo; > + } > + > public: > - unsigned getDepth() const { return Depth; } > - unsigned getIndex() const { return Index; } > - bool isParameterPack() const { return ParameterPack; } > - IdentifierInfo *getName() const { return Name; } > + unsigned getDepth() const { return getCanTTPTInfo().Depth; } > + unsigned getIndex() const { return getCanTTPTInfo().Index; } > + bool isParameterPack() const { return getCanTTPTInfo().ParameterPack; } > + > + TemplateTypeParmDecl *getDecl() const { > + return isCanonicalUnqualified() ? 0 : TTPDecl; > + } > > bool isSugared() const { return false; } > QualType desugar() const { return QualType(this, 0); } > > void Profile(llvm::FoldingSetNodeID &ID) { > - Profile(ID, Depth, Index, ParameterPack, Name); > + Profile(ID, getDepth(), getIndex(), isParameterPack(), getDecl()); > } > > static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, > unsigned Index, bool ParameterPack, > - IdentifierInfo *Name) { > + TemplateTypeParmDecl *TTPDecl) { > ID.AddInteger(Depth); > ID.AddInteger(Index); > ID.AddBoolean(ParameterPack); > - ID.AddPointer(Name); > + ID.AddPointer(TTPDecl); > } > > static bool classof(const Type *T) { > @@ -2373,8 +2394,6 @@ > friend class ASTContext; > > public: > - IdentifierInfo *getName() const { return Replaced->getName(); } > - > /// Gets the template parameter that was substituted for. > const TemplateTypeParmType *getReplacedParameter() const { > return Replaced; > > Modified: cfe/trunk/lib/AST/ASTContext.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=106099&r1=106098&r2=106099&view=diff > ============================================================================== > --- cfe/trunk/lib/AST/ASTContext.cpp (original) > +++ cfe/trunk/lib/AST/ASTContext.cpp Wed Jun 16 09:59:30 2010 > @@ -1728,9 +1728,9 @@ > /// name. > QualType ASTContext::getTemplateTypeParmType(unsigned Depth, unsigned Index, > bool ParameterPack, > - IdentifierInfo *Name) { > + TemplateTypeParmDecl *TTPDecl) { > llvm::FoldingSetNodeID ID; > - TemplateTypeParmType::Profile(ID, Depth, Index, ParameterPack, Name); > + TemplateTypeParmType::Profile(ID, Depth, Index, ParameterPack, TTPDecl); > void *InsertPos = 0; > TemplateTypeParmType *TypeParm > = TemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos); > @@ -1738,10 +1738,9 @@ > if (TypeParm) > return QualType(TypeParm, 0); > > - if (Name) { > + if (TTPDecl) { > QualType Canon = getTemplateTypeParmType(Depth, Index, ParameterPack); > - TypeParm = new (*this, TypeAlignment) > - TemplateTypeParmType(Depth, Index, ParameterPack, Name, Canon); > + TypeParm = new (*this, TypeAlignment) TemplateTypeParmType(TTPDecl, > Canon); > > TemplateTypeParmType *TypeCheck > = TemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos); > > Modified: cfe/trunk/lib/AST/DeclPrinter.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=106099&r1=106098&r2=106099&view=diff > ============================================================================== > --- cfe/trunk/lib/AST/DeclPrinter.cpp (original) > +++ cfe/trunk/lib/AST/DeclPrinter.cpp Wed Jun 16 09:59:30 2010 > @@ -623,7 +623,7 @@ > if (TTP->isParameterPack()) > Out << "... "; > > - Out << ParamType.getAsString(Policy); > + Out << TTP->getNameAsString(); > > if (TTP->hasDefaultArgument()) { > Out << " = "; > > Modified: cfe/trunk/lib/AST/DeclTemplate.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclTemplate.cpp?rev=106099&r1=106098&r2=106099&view=diff > ============================================================================== > --- cfe/trunk/lib/AST/DeclTemplate.cpp (original) > +++ cfe/trunk/lib/AST/DeclTemplate.cpp Wed Jun 16 09:59:30 2010 > @@ -265,8 +265,11 @@ > SourceLocation L, unsigned D, unsigned P, > IdentifierInfo *Id, bool Typename, > bool ParameterPack) { > - QualType Type = C.getTemplateTypeParmType(D, P, ParameterPack, Id); > - return new (C) TemplateTypeParmDecl(DC, L, Id, Typename, Type, > ParameterPack); > + TemplateTypeParmDecl *TTPDecl > + = new (C) TemplateTypeParmDecl(DC, L, Id, Typename); > + QualType TTPType = C.getTemplateTypeParmType(D, P, ParameterPack, TTPDecl); > + TTPDecl->TypeForDecl = TTPType.getTypePtr(); > + return TTPDecl; > } > > SourceLocation TemplateTypeParmDecl::getDefaultArgumentLoc() const { > @@ -281,6 +284,10 @@ > return TypeForDecl->getAs<TemplateTypeParmType>()->getIndex(); > } > > +bool TemplateTypeParmDecl::isParameterPack() const { > + return TypeForDecl->getAs<TemplateTypeParmType>()->isParameterPack(); > +} > + > //===----------------------------------------------------------------------===// > // NonTypeTemplateParmDecl Method Implementations > //===----------------------------------------------------------------------===// > > Modified: cfe/trunk/lib/AST/TypePrinter.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=106099&r1=106098&r2=106099&view=diff > ============================================================================== > --- cfe/trunk/lib/AST/TypePrinter.cpp (original) > +++ cfe/trunk/lib/AST/TypePrinter.cpp Wed Jun 16 09:59:30 2010 > @@ -506,12 +506,12 @@ > std::string &S) { > if (!S.empty()) // Prefix the basic type, e.g. 'parmname X'. > S = ' ' + S; > - > - if (!T->getName()) > + > + if (IdentifierInfo *Id = T->getDecl() ? T->getDecl()->getIdentifier() : 0) > + S = Id->getName().str() + S; > + else > S = "type-parameter-" + llvm::utostr_32(T->getDepth()) + '-' + > llvm::utostr_32(T->getIndex()) + S; > - else > - S = T->getName()->getName().str() + S; > } > > void TypePrinter::PrintSubstTemplateTypeParm(const SubstTemplateTypeParmType > *T, > > Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=106099&r1=106098&r2=106099&view=diff > ============================================================================== > --- cfe/trunk/lib/Sema/SemaTemplate.cpp (original) > +++ cfe/trunk/lib/Sema/SemaTemplate.cpp Wed Jun 16 09:59:30 2010 > @@ -450,7 +450,7 @@ > /// (otherwise, "class" was used), and KeyLoc is the location of the > /// "class" or "typename" keyword. ParamName is the name of the > /// parameter (NULL indicates an unnamed template parameter) and > -/// ParamName is the location of the parameter name (if any). > +/// ParamNameLoc is the location of the parameter name (if any). > /// If the type parameter has a default argument, it will be added > /// later via ActOnTypeParameterDefault. > Sema::DeclPtrTy Sema::ActOnTypeParameter(Scope *S, bool Typename, bool > Ellipsis, > > Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=106099&r1=106098&r2=106099&view=diff > ============================================================================== > --- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original) > +++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Wed Jun 16 09:59:30 2010 > @@ -896,12 +896,17 @@ > // the template parameter list of a member template inside the > // template we are instantiating). Create a new template type > // parameter with the template "level" reduced by one. > + TemplateTypeParmDecl *NewTTPDecl = 0; > + if (TemplateTypeParmDecl *OldTTPDecl = T->getDecl()) > + NewTTPDecl = cast_or_null<TemplateTypeParmDecl>( > + TransformDecl(TL.getNameLoc(), > OldTTPDecl)); > + > QualType Result > = getSema().Context.getTemplateTypeParmType(T->getDepth() > - > TemplateArgs.getNumLevels(), > T->getIndex(), > T->isParameterPack(), > - T->getName()); > + NewTTPDecl); > TemplateTypeParmTypeLoc NewTL = TLB.push<TemplateTypeParmTypeLoc>(Result); > NewTL.setNameLoc(TL.getNameLoc()); > return Result; > > Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=106099&r1=106098&r2=106099&view=diff > ============================================================================== > --- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original) > +++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Wed Jun 16 09:59:30 > 2010 > @@ -1442,14 +1442,12 @@ > Decl *TemplateDeclInstantiator::VisitTemplateTypeParmDecl( > TemplateTypeParmDecl *D) { > // TODO: don't always clone when decls are refcounted. > - const Type* T = D->getTypeForDecl(); > - assert(T->isTemplateTypeParmType()); > - const TemplateTypeParmType *TTPT = T->getAs<TemplateTypeParmType>(); > + assert(D->getTypeForDecl()->isTemplateTypeParmType()); > > TemplateTypeParmDecl *Inst = > TemplateTypeParmDecl::Create(SemaRef.Context, Owner, D->getLocation(), > - TTPT->getDepth() - 1, TTPT->getIndex(), > - TTPT->getName(), > + D->getDepth() - 1, D->getIndex(), > + D->getIdentifier(), > D->wasDeclaredWithTypename(), > D->isParameterPack()); > > > > _______________________________________________ > cfe-commits mailing list > cfe-commits@cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits _______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits