[cfe-commits] r123425 - in /cfe/trunk: include/clang/AST/ include/clang/Serialization/ lib/AST/ lib/Sema/ lib/Serialization/ test/CXX/temp/temp.decls/temp.variadic/
Douglas Gregor
dgregor at apple.com
Thu Jan 13 20:59:44 PST 2011
On Jan 13, 2011, at 8:19 PM, Matt Beaumont-Gay wrote:
> On Thu, Jan 13, 2011 at 18:55, Douglas Gregor <dgregor at apple.com> wrote:
>> Author: dgregor
>> Date: Thu Jan 13 20:55:32 2011
>> New Revision: 123425
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=123425&view=rev
>> Log:
>> Start implementing support for substitution into pack expansions that
>> involve template parameter packs at multiple template levels that
>> occur within the signatures members of class templates (and partial
>> specializations thereof). This is a work-in-progress that is deficient
>> in several ways, notably:
>> - It only works for template type parameter packs, but we need to
>> also support non-type template parameter packs and template template
>> parameter packs.
>> - It doesn't keep track of the lengths of the substituted argument
>> packs in the expansion, so it can't properly diagnose length
>> mismatches.
>>
>> However, this is a concrete step in the right direction.
>>
>> Modified:
>> cfe/trunk/include/clang/AST/ASTContext.h
>> cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
>> cfe/trunk/include/clang/AST/Type.h
>> cfe/trunk/include/clang/AST/TypeLoc.h
>> cfe/trunk/include/clang/AST/TypeNodes.def
>> cfe/trunk/include/clang/Serialization/ASTBitCodes.h
>> cfe/trunk/lib/AST/ASTContext.cpp
>> cfe/trunk/lib/AST/ItaniumMangle.cpp
>> cfe/trunk/lib/AST/MicrosoftMangle.cpp
>> cfe/trunk/lib/AST/Type.cpp
>> cfe/trunk/lib/AST/TypePrinter.cpp
>> cfe/trunk/lib/Sema/SemaTemplate.cpp
>> cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
>> cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
>> cfe/trunk/lib/Sema/TreeTransform.h
>> cfe/trunk/lib/Serialization/ASTReader.cpp
>> cfe/trunk/lib/Serialization/ASTWriter.cpp
>> cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/multi-level-substitution.cpp
>>
>> Modified: cfe/trunk/include/clang/AST/ASTContext.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=123425&r1=123424&r2=123425&view=diff
>> ==============================================================================
>> --- cfe/trunk/include/clang/AST/ASTContext.h (original)
>> +++ cfe/trunk/include/clang/AST/ASTContext.h Thu Jan 13 20:55:32 2011
>> @@ -102,6 +102,8 @@
>> mutable llvm::FoldingSet<TemplateTypeParmType> TemplateTypeParmTypes;
>> mutable llvm::FoldingSet<SubstTemplateTypeParmType>
>> SubstTemplateTypeParmTypes;
>> + mutable llvm::FoldingSet<SubstTemplateTypeParmPackType>
>> + SubstTemplateTypeParmPackTypes;
>> mutable llvm::ContextualFoldingSet<TemplateSpecializationType, ASTContext&>
>> TemplateSpecializationTypes;
>> mutable llvm::FoldingSet<ParenType> ParenTypes;
>> @@ -664,6 +666,9 @@
>>
>> QualType getSubstTemplateTypeParmType(const TemplateTypeParmType *Replaced,
>> QualType Replacement) const;
>> + QualType getSubstTemplateTypeParmPackType(
>> + const TemplateTypeParmType *Replaced,
>> + const TemplateArgument &ArgPack);
>>
>> QualType getTemplateTypeParmType(unsigned Depth, unsigned Index,
>> bool ParameterPack,
>>
>> Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=123425&r1=123424&r2=123425&view=diff
>> ==============================================================================
>> --- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
>> +++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Thu Jan 13 20:55:32 2011
>> @@ -718,6 +718,7 @@
>> DEF_TRAVERSE_TYPE(EnumType, { })
>> DEF_TRAVERSE_TYPE(TemplateTypeParmType, { })
>> DEF_TRAVERSE_TYPE(SubstTemplateTypeParmType, { })
>> +DEF_TRAVERSE_TYPE(SubstTemplateTypeParmPackType, { })
>>
>> DEF_TRAVERSE_TYPE(TemplateSpecializationType, {
>> TRY_TO(TraverseTemplateName(T->getTemplateName()));
>> @@ -925,6 +926,7 @@
>> DEF_TRAVERSE_TYPELOC(EnumType, { })
>> DEF_TRAVERSE_TYPELOC(TemplateTypeParmType, { })
>> DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmType, { })
>> +DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmPackType, { })
>>
>> // FIXME: use the loc for the template name?
>> DEF_TRAVERSE_TYPELOC(TemplateSpecializationType, {
>>
>> Modified: cfe/trunk/include/clang/AST/Type.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=123425&r1=123424&r2=123425&view=diff
>> ==============================================================================
>> --- cfe/trunk/include/clang/AST/Type.h (original)
>> +++ cfe/trunk/include/clang/AST/Type.h Thu Jan 13 20:55:32 2011
>> @@ -2860,6 +2860,59 @@
>> static bool classof(const SubstTemplateTypeParmType *T) { return true; }
>> };
>>
>> +/// \brief Represents the result of substituting a set of types for a template
>> +/// type parameter pack.
>> +///
>> +/// When a pack expansion in the source code contains multiple parameter packs
>> +/// and those parameter packs correspond to different levels of template
>> +/// parameter lists, this type node is used to represent a template type
>> +/// parameter pack from an outer level, which has already had its argument pack
>> +/// substituted but that still lives within a pack expansion that itself
>> +/// could not be instantiated. When actually performing a substitution into
>> +/// that pack expansion (e.g., when all template parameters have corresponding
>> +/// arguments), this type will be replaced with the \c SubstTemplateTypeParmType
>> +/// at the current pack substitution index.
>> +class SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode {
>> + /// \brief The original type parameter.
>> + const TemplateTypeParmType *Replaced;
>> +
>> + /// \brief A pointer to the set of template arguments that this
>> + /// parameter pack is instantiated with.
>> + const TemplateArgument *Arguments;
>> +
>> + /// \brief The number of template arguments in \c Arguments.
>> + unsigned NumArguments;
>> +
>> + SubstTemplateTypeParmPackType(const TemplateTypeParmType *Param,
>> + QualType Canon,
>> + const TemplateArgument &ArgPack);
>> +
>> + friend class ASTContext;
>> +
>> +public:
>> + IdentifierInfo *getName() const { return Replaced->getName(); }
>> +
>> + /// Gets the template parameter that was substituted for.
>> + const TemplateTypeParmType *getReplacedParameter() const {
>> + return Replaced;
>> + }
>> +
>> + bool isSugared() const { return false; }
>> + QualType desugar() const { return QualType(this, 0); }
>> +
>> + TemplateArgument getArgumentPack() const;
>> +
>> + void Profile(llvm::FoldingSetNodeID &ID);
>> + static void Profile(llvm::FoldingSetNodeID &ID,
>> + const TemplateTypeParmType *Replaced,
>> + const TemplateArgument &ArgPack);
>> +
>> + static bool classof(const Type *T) {
>> + return T->getTypeClass() == SubstTemplateTypeParmPack;
>> + }
>> + static bool classof(const SubstTemplateTypeParmPackType *T) { return true; }
>> +};
>> +
>> /// \brief Represents the type of a template specialization as written
>> /// in the source code.
>> ///
>>
>> Modified: cfe/trunk/include/clang/AST/TypeLoc.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLoc.h?rev=123425&r1=123424&r2=123425&view=diff
>> ==============================================================================
>> --- cfe/trunk/include/clang/AST/TypeLoc.h (original)
>> +++ cfe/trunk/include/clang/AST/TypeLoc.h Thu Jan 13 20:55:32 2011
>> @@ -592,6 +592,13 @@
>> SubstTemplateTypeParmType> {
>> };
>>
>> + /// \brief Wrapper for substituted template type parameters.
>> +class SubstTemplateTypeParmPackTypeLoc :
>> + public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
>> + SubstTemplateTypeParmPackTypeLoc,
>> + SubstTemplateTypeParmPackType> {
>> +};
>> +
>> struct AttributedLocInfo {
>> union {
>> Expr *ExprOperand;
>>
>> Modified: cfe/trunk/include/clang/AST/TypeNodes.def
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeNodes.def?rev=123425&r1=123424&r2=123425&view=diff
>> ==============================================================================
>> --- cfe/trunk/include/clang/AST/TypeNodes.def (original)
>> +++ cfe/trunk/include/clang/AST/TypeNodes.def Thu Jan 13 20:55:32 2011
>> @@ -91,6 +91,7 @@
>> NON_CANONICAL_TYPE(Attributed, Type)
>> DEPENDENT_TYPE(TemplateTypeParm, Type)
>> NON_CANONICAL_TYPE(SubstTemplateTypeParm, Type)
>> +DEPENDENT_TYPE(SubstTemplateTypeParmPack, Type)
>
> A couple of switch statements need cases for SubstTemplateTypeParmPack:
>
> tools/clang/lib/AST/ASTImporter.cpp:379:11: error: enumeration value
> 'SubstTemplateTypeParmPack' not handled in switch [-Wswitch-enum]
> switch (TC) {
> ^
>
> tools/clang/lib/Sema/SemaTemplateDeduction.cpp:3448:12: error:
> enumeration value 'SubstTemplateTypeParmPack' not handled in switch
> [-Wswitch-enum]
> switch (T->getTypeClass()) {
> ^
>
> Want me to just add "default: assert(0 && ...)" for now?
Please don't; I'll implement these pieces now. I forgot to do a check for warnings as I was running out the door :(
- Doug
More information about the cfe-commits
mailing list