DeclTemplate.h revision 833ca991c1bfc967f0995974ca86f66ba1f666b5
1aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor//===-- DeclTemplate.h - Classes for representing C++ templates -*- C++ -*-===// 2aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor// 3aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor// The LLVM Compiler Infrastructure 4aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor// 5aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor// This file is distributed under the University of Illinois Open Source 6aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor// License. See LICENSE.TXT for details. 7aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor// 8aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor//===----------------------------------------------------------------------===// 9aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor// 10aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor// This file defines the C++ template declaration subclasses. 11aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor// 12aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor//===----------------------------------------------------------------------===// 13aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 14aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#ifndef LLVM_CLANG_AST_DECLTEMPLATE_H 15aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#define LLVM_CLANG_AST_DECLTEMPLATE_H 16aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 1755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor#include "clang/AST/DeclCXX.h" 18275c10a8a4a43219f67d8d2c912ec6294d9d9af2John McCall#include "clang/AST/TemplateBase.h" 19f67875d5addf36b951ad37fb04509ab2b572c88aDouglas Gregor#include "llvm/ADT/PointerUnion.h" 203f3ce82674b44a58a2af7d90feb55acd906dd762Anders Carlsson#include <limits> 2155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 22aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregornamespace clang { 23aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 24aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregorclass TemplateParameterList; 25aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregorclass TemplateDecl; 26aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregorclass FunctionTemplateDecl; 27aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregorclass ClassTemplateDecl; 28c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregorclass ClassTemplatePartialSpecializationDecl; 29aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregorclass TemplateTypeParmDecl; 30aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregorclass NonTypeTemplateParmDecl; 31aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregorclass TemplateTemplateParmDecl; 32aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 33f67875d5addf36b951ad37fb04509ab2b572c88aDouglas Gregor/// \brief Stores a template parameter of any kind. 34f67875d5addf36b951ad37fb04509ab2b572c88aDouglas Gregortypedef llvm::PointerUnion3<TemplateTypeParmDecl*, NonTypeTemplateParmDecl*, 35f67875d5addf36b951ad37fb04509ab2b572c88aDouglas Gregor TemplateTemplateParmDecl*> TemplateParameter; 36f67875d5addf36b951ad37fb04509ab2b572c88aDouglas Gregor 37aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor/// TemplateParameterList - Stores a list of template parameters for a 38aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor/// TemplateDecl and its derived classes. 39aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregorclass TemplateParameterList { 40ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor /// The location of the 'template' keyword. 41ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor SourceLocation TemplateLoc; 42ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor 43ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor /// The locations of the '<' and '>' angle brackets. 44ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor SourceLocation LAngleLoc, RAngleLoc; 45ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor 46ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor /// The number of template parameters in this template 47aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor /// parameter list. 48aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor unsigned NumParams; 49aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 50ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor TemplateParameterList(SourceLocation TemplateLoc, SourceLocation LAngleLoc, 51bf4ea56cdc376cef5a12abf6bf18dc34805c2226Douglas Gregor NamedDecl **Params, unsigned NumParams, 52ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor SourceLocation RAngleLoc); 53aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 54aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregorpublic: 551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static TemplateParameterList *Create(ASTContext &C, 56ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor SourceLocation TemplateLoc, 57ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor SourceLocation LAngleLoc, 58bf4ea56cdc376cef5a12abf6bf18dc34805c2226Douglas Gregor NamedDecl **Params, 59ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor unsigned NumParams, 60ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor SourceLocation RAngleLoc); 61aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 62aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor /// iterator - Iterates through the template parameters in this list. 63bf4ea56cdc376cef5a12abf6bf18dc34805c2226Douglas Gregor typedef NamedDecl** iterator; 64aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 65aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor /// const_iterator - Iterates through the template parameters in this list. 66bf4ea56cdc376cef5a12abf6bf18dc34805c2226Douglas Gregor typedef NamedDecl* const* const_iterator; 67aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 68bf4ea56cdc376cef5a12abf6bf18dc34805c2226Douglas Gregor iterator begin() { return reinterpret_cast<NamedDecl **>(this + 1); } 69aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor const_iterator begin() const { 70bf4ea56cdc376cef5a12abf6bf18dc34805c2226Douglas Gregor return reinterpret_cast<NamedDecl * const *>(this + 1); 71aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor } 72aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor iterator end() { return begin() + NumParams; } 73aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor const_iterator end() const { return begin() + NumParams; } 74aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 75aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor unsigned size() const { return NumParams; } 76ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor 77bf4ea56cdc376cef5a12abf6bf18dc34805c2226Douglas Gregor NamedDecl* getParam(unsigned Idx) { 78f67875d5addf36b951ad37fb04509ab2b572c88aDouglas Gregor assert(Idx < size() && "Template parameter index out-of-range"); 79f67875d5addf36b951ad37fb04509ab2b572c88aDouglas Gregor return begin()[Idx]; 80f67875d5addf36b951ad37fb04509ab2b572c88aDouglas Gregor } 81f67875d5addf36b951ad37fb04509ab2b572c88aDouglas Gregor 82bf4ea56cdc376cef5a12abf6bf18dc34805c2226Douglas Gregor const NamedDecl* getParam(unsigned Idx) const { 8340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor assert(Idx < size() && "Template parameter index out-of-range"); 8440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor return begin()[Idx]; 8540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor } 8640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 8762cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor /// \btief Returns the minimum number of arguments needed to form a 8862cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor /// template specialization. This may be fewer than the number of 8962cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor /// template parameters, if some of the parameters have default 900ceffb51b28b09db67404058c642dcb1f877f6e8Anders Carlsson /// arguments or if there is a parameter pack. 9162cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor unsigned getMinRequiredArguments() const; 9262cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor 93ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \brief Get the depth of this template parameter list in the set of 94ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// template parameter lists. 95ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// 96ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// The first template parameter list in a declaration will have depth 0, 97ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// the second template parameter list will have depth 1, etc. 98ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor unsigned getDepth() const; 99ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor 100ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor SourceLocation getTemplateLoc() const { return TemplateLoc; } 101ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor SourceLocation getLAngleLoc() const { return LAngleLoc; } 102ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor SourceLocation getRAngleLoc() const { return RAngleLoc; } 10362cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor 10462cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor SourceRange getSourceRange() const { 10562cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor return SourceRange(TemplateLoc, RAngleLoc); 10662cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor } 107aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor}; 108aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 109127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// \brief A helper class for making template argument lists. 110127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorclass TemplateArgumentListBuilder { 111127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateArgument *StructuredArgs; 112127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned MaxStructuredArgs; 113127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned NumStructuredArgs; 1141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 115127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateArgument *FlatArgs; 116127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned MaxFlatArgs; 117127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned NumFlatArgs; 1181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 119127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor bool AddingToPack; 120127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned PackBeginIndex; 1211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 122aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregorpublic: 123127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateArgumentListBuilder(const TemplateParameterList *Parameters, 124127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned NumTemplateArgs) 1251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : StructuredArgs(0), MaxStructuredArgs(Parameters->size()), 1261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NumStructuredArgs(0), FlatArgs(0), 127127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor MaxFlatArgs(std::max(MaxStructuredArgs, NumTemplateArgs)), NumFlatArgs(0), 128127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor AddingToPack(false), PackBeginIndex(0) { } 1291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 130127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor void Append(const TemplateArgument& Arg); 131127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor void BeginPack(); 132127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor void EndPack(); 1331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 134127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor void ReleaseArgs(); 1351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned flatSize() const { 137127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor return NumFlatArgs; 138127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor } 139127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor const TemplateArgument *getFlatArguments() const { 140127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor return FlatArgs; 141127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor } 1421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 143127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned structuredSize() const { 144127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // If we don't have any structured args, just reuse the flat size. 145127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor if (!StructuredArgs) 146127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor return flatSize(); 1471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 148127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor return NumStructuredArgs; 149d684b0027e16163c4bdba3e2f8bfadda7d62a0d3Douglas Gregor } 150127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor const TemplateArgument *getStructuredArguments() const { 151127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // If we don't have any structured args, just reuse the flat args. 152127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor if (!StructuredArgs) 153127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor return getFlatArguments(); 1541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 155127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor return StructuredArgs; 156aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor } 157aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor}; 158aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 159127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// \brief A template argument list. 160127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// 161127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// FIXME: In the future, this class will be extended to support 162127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// variadic templates and member templates, which will make some of 163127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// the function names below make more sense. 164127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorclass TemplateArgumentList { 165127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief The template argument list. 166127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// 167127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// The integer value will be non-zero to indicate that this 168127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// template argument list does not own the pointer. 169127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor llvm::PointerIntPair<const TemplateArgument *, 1> FlatArguments; 1701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 171127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief The number of template arguments in this template 172127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// argument list. 173127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned NumFlatArguments; 1741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 175127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor llvm::PointerIntPair<const TemplateArgument *, 1> StructuredArguments; 176127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned NumStructuredArguments; 1771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 178aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregorpublic: 179127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateArgumentList(ASTContext &Context, 180127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateArgumentListBuilder &Builder, 181127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor bool TakeArgs); 1821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 183b9aa6b214c8fbc3e081dde575eef1f0913d48bdcDouglas Gregor /// \brief Produces a shallow copy of the given template argument list 184b9aa6b214c8fbc3e081dde575eef1f0913d48bdcDouglas Gregor TemplateArgumentList(const TemplateArgumentList &Other); 185b9aa6b214c8fbc3e081dde575eef1f0913d48bdcDouglas Gregor 186127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor ~TemplateArgumentList(); 1871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 188127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Retrieve the template argument at a given index. 1891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const TemplateArgument &get(unsigned Idx) const { 190127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor assert(Idx < NumFlatArguments && "Invalid template argument index"); 191127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor return getFlatArgumentList()[Idx]; 192127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor } 1931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 194127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Retrieve the template argument at a given index. 195127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor const TemplateArgument &operator[](unsigned Idx) const { return get(Idx); } 1961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 197127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Retrieve the number of template arguments in this 198127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// template argument list. 199127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned size() const { return NumFlatArguments; } 2001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 201127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Retrieve the number of template arguments in the 202127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// flattened template argument list. 203127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned flat_size() const { return NumFlatArguments; } 2041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 205127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Retrieve the flattened template argument list. 2061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const TemplateArgument *getFlatArgumentList() const { 207127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor return FlatArguments.getPointer(); 208127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor } 209127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor}; 2101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 211127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor//===----------------------------------------------------------------------===// 212127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor// Kinds of Templates 213127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor//===----------------------------------------------------------------------===// 214aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 215127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// TemplateDecl - The base class of all kinds of template declarations (e.g., 216127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// class, function, etc.). The TemplateDecl class stores the list of template 217127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// parameters and a reference to the templated scoped declaration: the 218127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// underlying AST node. 219127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorclass TemplateDecl : public NamedDecl { 220127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorprotected: 221127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // This is probably never used. 222127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L, 223127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor DeclarationName Name) 2241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : NamedDecl(DK, DC, L, Name), TemplatedDecl(0), TemplateParams(0) { } 225d684b0027e16163c4bdba3e2f8bfadda7d62a0d3Douglas Gregor 226127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // Construct a template decl with the given name and parameters. 227127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // Used when there is not templated element (tt-params, alias?). 228127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L, 229127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor DeclarationName Name, TemplateParameterList *Params) 2301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : NamedDecl(DK, DC, L, Name), TemplatedDecl(0), TemplateParams(Params) { } 231d684b0027e16163c4bdba3e2f8bfadda7d62a0d3Douglas Gregor 232127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // Construct a template decl with name, parameters, and templated element. 233127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L, 234127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor DeclarationName Name, TemplateParameterList *Params, 235127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor NamedDecl *Decl) 236127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor : NamedDecl(DK, DC, L, Name), TemplatedDecl(Decl), 237127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateParams(Params) { } 238127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorpublic: 239127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor ~TemplateDecl(); 240d684b0027e16163c4bdba3e2f8bfadda7d62a0d3Douglas Gregor 241127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// Get the list of template parameters 242127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateParameterList *getTemplateParameters() const { 243127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor return TemplateParams; 244d684b0027e16163c4bdba3e2f8bfadda7d62a0d3Douglas Gregor } 245d684b0027e16163c4bdba3e2f8bfadda7d62a0d3Douglas Gregor 246127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// Get the underlying, templated declaration. 247127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor NamedDecl *getTemplatedDecl() const { return TemplatedDecl; } 248127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor 249aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor // Implement isa/cast/dyncast/etc. 250aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor static bool classof(const Decl *D) { 251127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor return D->getKind() >= TemplateFirst && D->getKind() <= TemplateLast; 252aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor } 253127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor static bool classof(const TemplateDecl *D) { return true; } 254127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor static bool classof(const FunctionTemplateDecl *D) { return true; } 255127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor static bool classof(const ClassTemplateDecl *D) { return true; } 256aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor static bool classof(const TemplateTemplateParmDecl *D) { return true; } 257aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 258127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorprotected: 259127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor NamedDecl *TemplatedDecl; 260127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateParameterList* TemplateParams; 261127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor}; 2621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// \brief Provides information about a function template specialization, 264127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// which is a FunctionDecl that has been explicitly specialization or 265127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// instantiated from a function template. 266127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorclass FunctionTemplateSpecializationInfo : public llvm::FoldingSetNode { 267127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorpublic: 2681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief The function template specialization that this structure 269127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// describes. 270127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor FunctionDecl *Function; 2711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief The function template from which this function template 273127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// specialization was generated. 2741fd2dd145d9bcdf0b8d60a88e1795b6ae83656f5Douglas Gregor /// 275d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor /// The two bits are contain the top 4 values of TemplateSpecializationKind. 276d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor llvm::PointerIntPair<FunctionTemplateDecl *, 2> Template; 2771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 278127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief The template arguments used to produce the function template 279127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// specialization from the function template. 280127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor const TemplateArgumentList *TemplateArguments; 2811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 282b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// \brief The point at which this function template specialization was 283b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// first instantiated. 284b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor SourceLocation PointOfInstantiation; 285b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor 2861fd2dd145d9bcdf0b8d60a88e1795b6ae83656f5Douglas Gregor /// \brief Retrieve the template from which this function was specialized. 2871fd2dd145d9bcdf0b8d60a88e1795b6ae83656f5Douglas Gregor FunctionTemplateDecl *getTemplate() const { return Template.getPointer(); } 288d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor 289d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor /// \brief Determine what kind of template specialization this is. 290d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor TemplateSpecializationKind getTemplateSpecializationKind() const { 291d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor return (TemplateSpecializationKind)(Template.getInt() + 1); 292d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor } 293d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor 294d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor /// \brief Set the template specialization kind. 295d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor void setTemplateSpecializationKind(TemplateSpecializationKind TSK) { 2961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(TSK != TSK_Undeclared && 297d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor "Cannot encode TSK_Undeclared for a function template specialization"); 298d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor Template.setInt(TSK - 1); 2991fd2dd145d9bcdf0b8d60a88e1795b6ae83656f5Douglas Gregor } 3001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 301b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// \brief Retrieve the first point of instantiation of this function 302b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// template specialization. 303b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// 304b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// The point of instantiation may be an invalid source location if this 305b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// function has yet to be instantiated. 306b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor SourceLocation getPointOfInstantiation() const { 307b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor return PointOfInstantiation; 308b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor } 309b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor 310b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// \brief Set the (first) point of instantiation of this function template 311b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// specialization. 312b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor void setPointOfInstantiation(SourceLocation POI) { 313b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor PointOfInstantiation = POI; 314b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor } 315b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor 316127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 3171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Profile(ID, TemplateArguments->getFlatArgumentList(), 318828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor TemplateArguments->flat_size(), 3191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Function->getASTContext()); 320127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor } 3211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void 3231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Profile(llvm::FoldingSetNodeID &ID, const TemplateArgument *TemplateArgs, 324828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor unsigned NumTemplateArgs, ASTContext &Context) { 325127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor ID.AddInteger(NumTemplateArgs); 326127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor for (unsigned Arg = 0; Arg != NumTemplateArgs; ++Arg) 327828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor TemplateArgs[Arg].Profile(ID, Context); 3281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 329127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor}; 3301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3312db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor/// \brief Provides information a specialization of a member of a class 3322db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor/// template, which may be a member function, static data member, or 3332db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor/// member class. 3342db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregorclass MemberSpecializationInfo { 33544e368b6a85c42d681148ccd5e0052418ff9751eDouglas Gregor // The member declaration from which this member was instantiated, and the 33644e368b6a85c42d681148ccd5e0052418ff9751eDouglas Gregor // manner in which the instantiation occurred (in the lower two bits). 33744e368b6a85c42d681148ccd5e0052418ff9751eDouglas Gregor llvm::PointerIntPair<NamedDecl *, 2> MemberAndTSK; 3382db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor 339b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor // The point at which this member was first instantiated. 340b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor SourceLocation PointOfInstantiation; 341b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor 3422db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregorpublic: 3432db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor explicit 3442db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor MemberSpecializationInfo(NamedDecl *IF, TemplateSpecializationKind TSK) 345b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor : MemberAndTSK(IF, TSK - 1), PointOfInstantiation() { 34644e368b6a85c42d681148ccd5e0052418ff9751eDouglas Gregor assert(TSK != TSK_Undeclared && 34744e368b6a85c42d681148ccd5e0052418ff9751eDouglas Gregor "Cannot encode undeclared template specializations for members"); 34844e368b6a85c42d681148ccd5e0052418ff9751eDouglas Gregor } 3492db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor 3502db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor /// \brief Retrieve the member declaration from which this member was 3512db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor /// instantiated. 35244e368b6a85c42d681148ccd5e0052418ff9751eDouglas Gregor NamedDecl *getInstantiatedFrom() const { return MemberAndTSK.getPointer(); } 3532db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor 3542db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor /// \brief Determine what kind of template specialization this is. 3552db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor TemplateSpecializationKind getTemplateSpecializationKind() const { 35644e368b6a85c42d681148ccd5e0052418ff9751eDouglas Gregor return (TemplateSpecializationKind)(MemberAndTSK.getInt() + 1); 3572db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor } 3582db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor 3592db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor /// \brief Set the template specialization kind. 3602db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor void setTemplateSpecializationKind(TemplateSpecializationKind TSK) { 36144e368b6a85c42d681148ccd5e0052418ff9751eDouglas Gregor assert(TSK != TSK_Undeclared && 36244e368b6a85c42d681148ccd5e0052418ff9751eDouglas Gregor "Cannot encode undeclared template specializations for members"); 36344e368b6a85c42d681148ccd5e0052418ff9751eDouglas Gregor MemberAndTSK.setInt(TSK - 1); 3642db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor } 365b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor 366b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// \brief Retrieve the first point of instantiation of this member. 367b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// If the point of instantiation is an invalid location, then this member 368b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// has not yet been instantiated. 369b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor SourceLocation getPointOfInstantiation() const { 370b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor return PointOfInstantiation; 371b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor } 372b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor 373b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// \brief Set the first point of instantiation. 374b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor void setPointOfInstantiation(SourceLocation POI) { 375b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor PointOfInstantiation = POI; 376b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor } 3772db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor}; 3782db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor 379127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// Declaration of a template function. 3801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass FunctionTemplateDecl : public TemplateDecl { 381127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorprotected: 382127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Data that is common to all of the declarations of a given 383127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// function template. 384127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor struct Common { 385fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor Common() : InstantiatedFromMember(0, false) { } 3861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 387127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief The function template specializations for this function 388127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// template, including explicit specializations and instantiations. 389127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor llvm::FoldingSet<FunctionTemplateSpecializationInfo> Specializations; 3901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 391d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// \brief The member function template from which this was most 392d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// directly instantiated (or null). 393fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// 394fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// The boolean value indicates whether this member function template 395fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// was explicitly specialized. 396fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor llvm::PointerIntPair<FunctionTemplateDecl*, 1, bool> InstantiatedFromMember; 3973e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor }; 3981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 399127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief A pointer to the previous declaration (if this is a redeclaration) 400127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// or to the data that is common to all declarations of this function 401127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// template. 402127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor llvm::PointerUnion<Common*, FunctionTemplateDecl*> CommonOrPrev; 4031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieves the "common" pointer shared by all 405127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// (re-)declarations of the same function template. Calling this routine 406127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// may implicitly allocate memory for the common pointer. 407127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor Common *getCommonPtr(); 4081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 409127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor FunctionTemplateDecl(DeclContext *DC, SourceLocation L, DeclarationName Name, 410127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateParameterList *Params, NamedDecl *Decl) 411127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor : TemplateDecl(FunctionTemplate, DC, L, Name, Params, Decl), 412127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor CommonOrPrev((Common*)0) { } 4131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4143e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregorpublic: 415127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor void Destroy(ASTContext &C); 4161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 417127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// Get the underlying function declaration of the template. 418127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor FunctionDecl *getTemplatedDecl() const { 419127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor return static_cast<FunctionDecl*>(TemplatedDecl); 4203e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor } 4213e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 422127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Retrieve the set of function template specializations of this 423127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// function template. 424127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor llvm::FoldingSet<FunctionTemplateSpecializationInfo> &getSpecializations() { 425127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor return getCommonPtr()->Specializations; 4263e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor } 4271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 428127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Retrieve the previous declaration of this function template, or 429127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// NULL if no such declaration exists. 430127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor const FunctionTemplateDecl *getPreviousDeclaration() const { 431127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor return CommonOrPrev.dyn_cast<FunctionTemplateDecl*>(); 4323e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor } 4333e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 434127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Retrieve the previous declaration of this function template, or 435127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// NULL if no such declaration exists. 436127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor FunctionTemplateDecl *getPreviousDeclaration() { 437127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor return CommonOrPrev.dyn_cast<FunctionTemplateDecl*>(); 4383e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor } 4391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 440127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Set the previous declaration of this function template. 441127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor void setPreviousDeclaration(FunctionTemplateDecl *Prev) { 442127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor if (Prev) 443127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor CommonOrPrev = Prev; 444127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor } 4451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 446b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios Kyrtzidis virtual FunctionTemplateDecl *getCanonicalDecl(); 4471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the member function template that this function template 449d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// was instantiated from. 450d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// 451d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// This routine will return non-NULL for member function templates of 452d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// class templates. For example, given: 453d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// 454d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// \code 455d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// template <typename T> 456d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// struct X { 457d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// template <typename U> void f(); 458d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// }; 459d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// \endcode 460d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// 461d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// X<int>::A<float> is a CXXMethodDecl (whose parent is X<int>, a 4621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// ClassTemplateSpecializationDecl) for which getPrimaryTemplate() will 463d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// return X<int>::f, a FunctionTemplateDecl (whose parent is again 464d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// X<int>) for which getInstantiatedFromMemberTemplate() will return 4651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// X<T>::f, a FunctionTemplateDecl (whose parent is X<T>, a 466d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// ClassTemplateDecl). 467d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// 4681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \returns NULL if this is not an instantiation of a member function 469d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// template. 470d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor FunctionTemplateDecl *getInstantiatedFromMemberTemplate() { 471fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor return getCommonPtr()->InstantiatedFromMember.getPointer(); 472d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor } 4731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 474d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor void setInstantiatedFromMemberTemplate(FunctionTemplateDecl *FTD) { 475fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor assert(!getCommonPtr()->InstantiatedFromMember.getPointer()); 476fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor getCommonPtr()->InstantiatedFromMember.setPointer(FTD); 477d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor } 4781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 479fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// \brief Determines whether this template was a specialization of a 480fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// member template. 481fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// 482fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// In the following example, the function template \c X<int>::f is a 483fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// member specialization. 484fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// 485fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// \code 486fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// template<typename T> 487fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// struct X { 488fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// template<typename U> void f(T, U); 489fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// }; 490fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// 491fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// template<> template<typename T> 492fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// void X<int>::f(int, T); 493fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// \endcode 494fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor bool isMemberSpecialization() { 495fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor return getCommonPtr()->InstantiatedFromMember.getInt(); 496fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor } 497fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor 498fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// \brief Note that this member template is a specialization. 499fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor void setMemberSpecialization() { 500fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor assert(getCommonPtr()->InstantiatedFromMember.getPointer() && 501fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor "Only member templates can be member template specializations"); 502fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor getCommonPtr()->InstantiatedFromMember.setInt(true); 503fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor } 504fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor 505127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// Create a template function node. 506127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor static FunctionTemplateDecl *Create(ASTContext &C, DeclContext *DC, 507127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor SourceLocation L, 508127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor DeclarationName Name, 509127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateParameterList *Params, 510127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor NamedDecl *Decl); 5113e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 512127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // Implement isa/cast/dyncast support 513127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor static bool classof(const Decl *D) 514127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor { return D->getKind() == FunctionTemplate; } 515127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor static bool classof(const FunctionTemplateDecl *D) 516127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor { return true; } 517127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor}; 518d01b1da213aeb71fd40ff7fb78a194613cc1ece7Anders Carlsson 519127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor//===----------------------------------------------------------------------===// 520127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor// Kinds of Template Parameters 521127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor//===----------------------------------------------------------------------===// 52240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 523127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// The TemplateParmPosition class defines the position of a template parameter 524127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// within a template parameter list. Because template parameter can be listed 525127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// sequentially for out-of-line template members, each template parameter is 526127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// given a Depth - the nesting of template parameter scopes - and a Position - 527127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// the occurrence within the parameter list. 528127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// This class is inheritedly privately by different kinds of template 529127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// parameters and is not part of the Decl hierarchy. Just a facility. 5301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass TemplateParmPosition { 531127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorprotected: 532127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // FIXME: This should probably never be called, but it's here as 533127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateParmPosition() 534127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor : Depth(0), Position(0) 535127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor { /* assert(0 && "Cannot create positionless template parameter"); */ } 5363e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 537127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateParmPosition(unsigned D, unsigned P) 538127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor : Depth(D), Position(P) 539127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor { } 5403e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 541127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // FIXME: These probably don't need to be ints. int:5 for depth, int:8 for 542127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // position? Maybe? 543127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned Depth; 544127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned Position; 5453e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 546127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorpublic: 547127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// Get the nesting depth of the template parameter. 548127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned getDepth() const { return Depth; } 5493e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 550127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// Get the position of the template parameter within its parameter list. 551127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned getPosition() const { return Position; } 5521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 553127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// Get the index of the template parameter within its parameter list. 554127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned getIndex() const { return Position; } 555127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor}; 5563e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 557127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// TemplateTypeParmDecl - Declaration of a template type parameter, 558127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// e.g., "T" in 559127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// @code 560127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// template<typename T> class vector; 561127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// @endcode 562127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorclass TemplateTypeParmDecl : public TypeDecl { 563127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Whether this template type parameter was declaration with 564127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// the 'typename' keyword. If false, it was declared with the 565127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// 'class' keyword. 566127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor bool Typename : 1; 5673e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 568127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Whether this template type parameter inherited its 569127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// default argument. 570127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor bool InheritedDefault : 1; 5713e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 572127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Whether this is a parameter pack. 573127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor bool ParameterPack : 1; 574127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor 575127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief The default template argument, if any. 576833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall DeclaratorInfo *DefaultArgument; 577127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor 5781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateTypeParmDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, 579127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor bool Typename, QualType Type, bool ParameterPack) 580127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor : TypeDecl(TemplateTypeParm, DC, L, Id), Typename(Typename), 5811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump InheritedDefault(false), ParameterPack(ParameterPack), DefaultArgument() { 582127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TypeForDecl = Type.getTypePtr(); 5833e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor } 5843e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 585127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorpublic: 586127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor static TemplateTypeParmDecl *Create(ASTContext &C, DeclContext *DC, 587127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor SourceLocation L, unsigned D, unsigned P, 588127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor IdentifierInfo *Id, bool Typename, 589127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor bool ParameterPack); 590c971f8694661776ecdec2ccc33fbe0333eeaf191Douglas Gregor 591127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Whether this template type parameter was declared with 592127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// the 'typename' keyword. If not, it was declared with the 'class' 593127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// keyword. 594127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor bool wasDeclaredWithTypename() const { return Typename; } 595c971f8694661776ecdec2ccc33fbe0333eeaf191Douglas Gregor 596127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Determine whether this template parameter has a default 597127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// argument. 598833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall bool hasDefaultArgument() const { return DefaultArgument != 0; } 599199d99192fbcca9f043596c40ead4afab4999dbaDouglas Gregor 600127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Retrieve the default argument, if any. 601833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall QualType getDefaultArgument() const { return DefaultArgument->getType(); } 60240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 603833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// \brief Retrieves the default argument's source information, if any. 604833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall DeclaratorInfo *getDefaultArgumentInfo() const { return DefaultArgument; } 605833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 606833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// \brief Retrieves the location of the default argument declaration. 607833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation getDefaultArgumentLoc() const; 60840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 609127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Determines whether the default argument was inherited 610127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// from a previous declaration of this template. 611127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor bool defaultArgumentWasInherited() const { return InheritedDefault; } 612f670c8cfa58b4c224eb8fb566130dc47844dd3deDouglas Gregor 613127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Set the default argument for this template parameter, and 614127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// whether that default argument was inherited from another 615127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// declaration. 616833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall void setDefaultArgument(DeclaratorInfo *DefArg, bool Inherited) { 617127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor DefaultArgument = DefArg; 618127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor InheritedDefault = Inherited; 619f670c8cfa58b4c224eb8fb566130dc47844dd3deDouglas Gregor } 62040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 621833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// \brief Removes the default argument of this template parameter. 622833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall void removeDefaultArgument() { 623833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall DefaultArgument = 0; 624833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall InheritedDefault = false; 625833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 626833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 627ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \brief Retrieve the depth of the template parameter. 628ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor unsigned getDepth() const; 629ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor 630ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \brief Retrieve the index of the template parameter. 631ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor unsigned getIndex() const; 632ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor 633127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Returns whether this is a parameter pack. 634127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor bool isParameterPack() const { return ParameterPack; } 635fb25052736439d72a557cddd41dfb927bcb3d3e5Anders Carlsson 636127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // Implement isa/cast/dyncast/etc. 637127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor static bool classof(const Decl *D) { 638127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor return D->getKind() == TemplateTypeParm; 6393e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor } 640127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor static bool classof(const TemplateTypeParmDecl *D) { return true; } 6413e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor}; 6423e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 643127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// NonTypeTemplateParmDecl - Declares a non-type template parameter, 644127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// e.g., "Size" in 645127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// @code 646127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// template<int Size> class array { }; 647127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// @endcode 648127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorclass NonTypeTemplateParmDecl 649127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor : public VarDecl, protected TemplateParmPosition { 650127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief The default template argument, if any. 651127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor Expr *DefaultArgument; 652127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor 653127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor NonTypeTemplateParmDecl(DeclContext *DC, SourceLocation L, unsigned D, 654127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned P, IdentifierInfo *Id, QualType T, 655a5d82000f7b173a0a5ce34dc8c09a03f98d9e439Argyrios Kyrtzidis DeclaratorInfo *DInfo) 656a5d82000f7b173a0a5ce34dc8c09a03f98d9e439Argyrios Kyrtzidis : VarDecl(NonTypeTemplateParm, DC, L, Id, T, DInfo, VarDecl::None), 6571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateParmPosition(D, P), DefaultArgument(0) 658127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor { } 659127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor 6601c5976e5e933c0d74f7e04e8f907a93f5edbfec1Anders Carlssonpublic: 661127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor static NonTypeTemplateParmDecl * 662127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor Create(ASTContext &C, DeclContext *DC, SourceLocation L, unsigned D, 663a5d82000f7b173a0a5ce34dc8c09a03f98d9e439Argyrios Kyrtzidis unsigned P, IdentifierInfo *Id, QualType T, DeclaratorInfo *DInfo); 6649ba41645892da0000fe8a7832b80208f44dafedaAnders Carlsson 665127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor using TemplateParmPosition::getDepth; 666127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor using TemplateParmPosition::getPosition; 667127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor using TemplateParmPosition::getIndex; 6681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 669127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Determine whether this template parameter has a default 670127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// argument. 671127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor bool hasDefaultArgument() const { return DefaultArgument; } 672fb25052736439d72a557cddd41dfb927bcb3d3e5Anders Carlsson 673127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Retrieve the default argument, if any. 674127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor Expr *getDefaultArgument() const { return DefaultArgument; } 675127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor 676127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Retrieve the location of the default argument, if any. 677127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor SourceLocation getDefaultArgumentLoc() const; 678127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor 679127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Set the default argument for this template parameter. 680127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor void setDefaultArgument(Expr *DefArg) { 681127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor DefaultArgument = DefArg; 6823b36b66a00b7d5bab71b486a54694f0ae397bddbAnders Carlsson } 683127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor 684127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // Implement isa/cast/dyncast/etc. 685127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor static bool classof(const Decl *D) { 686127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor return D->getKind() == NonTypeTemplateParm; 6873b36b66a00b7d5bab71b486a54694f0ae397bddbAnders Carlsson } 688127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor static bool classof(const NonTypeTemplateParmDecl *D) { return true; } 6891c5976e5e933c0d74f7e04e8f907a93f5edbfec1Anders Carlsson}; 6901c5976e5e933c0d74f7e04e8f907a93f5edbfec1Anders Carlsson 691127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// TemplateTemplateParmDecl - Declares a template template parameter, 692127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// e.g., "T" in 693127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// @code 694127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// template <template <typename> class T> class container { }; 695127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// @endcode 696127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// A template template parameter is a TemplateDecl because it defines the 697127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// name of a template and the template parameters allowable for substitution. 698127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorclass TemplateTemplateParmDecl 699127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor : public TemplateDecl, protected TemplateParmPosition { 7007e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor 701127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief The default template argument, if any. 702127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor Expr *DefaultArgument; 7037e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor 704127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateTemplateParmDecl(DeclContext *DC, SourceLocation L, 705127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned D, unsigned P, 706127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor IdentifierInfo *Id, TemplateParameterList *Params) 707127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor : TemplateDecl(TemplateTemplateParm, DC, L, Id, Params), 708127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateParmPosition(D, P), DefaultArgument(0) 709127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor { } 7107e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor 711127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorpublic: 712127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor static TemplateTemplateParmDecl *Create(ASTContext &C, DeclContext *DC, 713127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor SourceLocation L, unsigned D, 714127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned P, IdentifierInfo *Id, 715127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateParameterList *Params); 7167e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor 717127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor using TemplateParmPosition::getDepth; 718127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor using TemplateParmPosition::getPosition; 719127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor using TemplateParmPosition::getIndex; 7201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 721127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Determine whether this template parameter has a default 722127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// argument. 723127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor bool hasDefaultArgument() const { return DefaultArgument; } 7247e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor 725127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Retrieve the default argument, if any. 726127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor Expr *getDefaultArgument() const { return DefaultArgument; } 7277e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor 728127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Retrieve the location of the default argument, if any. 729127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor SourceLocation getDefaultArgumentLoc() const; 7307e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor 731127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Set the default argument for this template parameter. 732127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor void setDefaultArgument(Expr *DefArg) { 733127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor DefaultArgument = DefArg; 734127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor } 7357e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor 736127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // Implement isa/cast/dyncast/etc. 737127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor static bool classof(const Decl *D) { 738127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor return D->getKind() == TemplateTemplateParm; 7397e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor } 740127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor static bool classof(const TemplateTemplateParmDecl *D) { return true; } 7417e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor}; 7427e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor 7433e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor/// \brief Represents a class template specialization, which refers to 7443e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor/// a class template with a given set of template arguments. 7453e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor/// 7463e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor/// Class template specializations represent both explicit 7473e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor/// specialization of class templates, as in the example below, and 7483e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor/// implicit instantiations of class templates. 7493e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor/// 7503e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor/// \code 7513e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor/// template<typename T> class array; 7521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 7531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<> 7543e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor/// class array<bool> { }; // class template specialization array<bool> 7553e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor/// \endcode 7561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ClassTemplateSpecializationDecl 7573e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor : public CXXRecordDecl, public llvm::FoldingSetNode { 7581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Structure that stores information about a class template 76037d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// specialization that was instantiated from a class template partial 76137d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// specialization. 76237d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor struct SpecializedPartialSpecialization { 76337d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// \brief The class template partial specialization from which this 76437d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// class template specialization was instantiated. 76537d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor ClassTemplatePartialSpecializationDecl *PartialSpecialization; 7661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 76737d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// \brief The template argument list deduced for the class template 76837d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// partial specialization itself. 76937d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor TemplateArgumentList *TemplateArgs; 77037d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor }; 7711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7723e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor /// \brief The template that this specialization specializes 77337d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor llvm::PointerUnion<ClassTemplateDecl *, SpecializedPartialSpecialization *> 77437d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor SpecializedTemplate; 7753e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 7767e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor /// \brief The template arguments used to describe this specialization. 7777e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor TemplateArgumentList TemplateArgs; 778cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 7799cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall /// \brief The point where this template was instantiated (if any) 7809cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall SourceLocation PointOfInstantiation; 7819cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall 782cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor /// \brief The kind of specialization this declaration refers to. 783cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor /// Really a value of type TemplateSpecializationKind. 784d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor unsigned SpecializationKind : 3; 785cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 786c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregorprotected: 787c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, 7887e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor DeclContext *DC, SourceLocation L, 7893e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor ClassTemplateDecl *SpecializedTemplate, 7908e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor TemplateArgumentListBuilder &Builder, 7918e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor ClassTemplateSpecializationDecl *PrevDecl); 7921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7933e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregorpublic: 7943e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor static ClassTemplateSpecializationDecl * 7953e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor Create(ASTContext &Context, DeclContext *DC, SourceLocation L, 7963e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor ClassTemplateDecl *SpecializedTemplate, 79791fdf6f576b91f023c3bebb0d3786aab555cb3c5Anders Carlsson TemplateArgumentListBuilder &Builder, 798cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor ClassTemplateSpecializationDecl *PrevDecl); 7993e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 80037d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor virtual void Destroy(ASTContext& C); 80137d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor 802136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall virtual void getNameForDiagnostic(std::string &S, 803136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall const PrintingPolicy &Policy, 804136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall bool Qualified) const; 805136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall 8063e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor /// \brief Retrieve the template that this specialization specializes. 80737d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor ClassTemplateDecl *getSpecializedTemplate() const; 8083e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 8091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the template arguments of the class template 81037d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// specialization. 8111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const TemplateArgumentList &getTemplateArgs() const { 8127e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor return TemplateArgs; 8133e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor } 8143e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 815cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor /// \brief Determine the kind of specialization that this 816cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor /// declaration represents. 817cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor TemplateSpecializationKind getSpecializationKind() const { 818cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor return static_cast<TemplateSpecializationKind>(SpecializationKind); 819cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor } 820cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 821cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor void setSpecializationKind(TemplateSpecializationKind TSK) { 822cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor SpecializationKind = TSK; 823cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor } 824cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 8259cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall /// \brief Get the point of instantiation (if any), or null if none. 8269cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall SourceLocation getPointOfInstantiation() const { 8279cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall return PointOfInstantiation; 8289cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall } 8299cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall 8309cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall void setPointOfInstantiation(SourceLocation Loc) { 8319cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall assert(Loc.isValid() && "point of instantiation must be valid!"); 8329cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall PointOfInstantiation = Loc; 8339cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall } 8349cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall 83537d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// \brief If this class template specialization is an instantiation of 83637d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// a template (rather than an explicit specialization), return the 83737d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// class template or class template partial specialization from which it 83837d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// was instantiated. 8391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump llvm::PointerUnion<ClassTemplateDecl *, 84037d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor ClassTemplatePartialSpecializationDecl *> 84137d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor getInstantiatedFrom() const { 84237d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor if (getSpecializationKind() != TSK_ImplicitInstantiation && 843d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor getSpecializationKind() != TSK_ExplicitInstantiationDefinition && 844d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor getSpecializationKind() != TSK_ExplicitInstantiationDeclaration) 84537d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor return (ClassTemplateDecl*)0; 8461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (SpecializedPartialSpecialization *PartialSpec 84837d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>()) 84937d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor return PartialSpec->PartialSpecialization; 8501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 85137d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor return const_cast<ClassTemplateDecl*>( 85237d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor SpecializedTemplate.get<ClassTemplateDecl*>()); 85337d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor } 8541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 85537d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// \brief Retrieve the set of template arguments that should be used 85637d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// to instantiate members of the class template or class template partial 85737d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// specialization from which this class template specialization was 85837d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// instantiated. 85937d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// 86037d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// \returns For a class template specialization instantiated from the primary 86137d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// template, this function will return the same template arguments as 86237d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// getTemplateArgs(). For a class template specialization instantiated from 86337d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// a class template partial specialization, this function will return the 86437d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// deduced template arguments for the class template partial specialization 86537d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// itself. 86637d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor const TemplateArgumentList &getTemplateInstantiationArgs() const { 8671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (SpecializedPartialSpecialization *PartialSpec 86837d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>()) 86937d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor return *PartialSpec->TemplateArgs; 8701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 87137d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor return getTemplateArgs(); 87237d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor } 8731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 87437d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// \brief Note that this class template specialization is actually an 87537d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// instantiation of the given class template partial specialization whose 87637d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// template arguments have been deduced. 87737d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, 87837d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor TemplateArgumentList *TemplateArgs) { 8791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SpecializedPartialSpecialization *PS 88037d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor = new (getASTContext()) SpecializedPartialSpecialization(); 88137d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor PS->PartialSpecialization = PartialSpec; 88237d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor PS->TemplateArgs = TemplateArgs; 88337d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor SpecializedTemplate = PS; 88437d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor } 8851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 886fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor /// \brief Sets the type of this specialization as it was written by 887fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor /// the user. This will be a class template specialization type. 888fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor void setTypeAsWritten(QualType T) { 889fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor TypeForDecl = T.getTypePtr(); 890fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor } 891fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor 892c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) const { 893828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor Profile(ID, TemplateArgs.getFlatArgumentList(), TemplateArgs.flat_size(), 894828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor getASTContext()); 895c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor } 896c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor 8971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void 8981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Profile(llvm::FoldingSetNodeID &ID, const TemplateArgument *TemplateArgs, 899828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor unsigned NumTemplateArgs, ASTContext &Context) { 9000ceffb51b28b09db67404058c642dcb1f877f6e8Anders Carlsson ID.AddInteger(NumTemplateArgs); 9013e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor for (unsigned Arg = 0; Arg != NumTemplateArgs; ++Arg) 902828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor TemplateArgs[Arg].Profile(ID, Context); 9033e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor } 9043e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 9051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Decl *D) { 906c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor return D->getKind() == ClassTemplateSpecialization || 907c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor D->getKind() == ClassTemplatePartialSpecialization; 9083e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor } 9093e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 9103e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor static bool classof(const ClassTemplateSpecializationDecl *) { 9113e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor return true; 9123e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor } 913c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor 914c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor static bool classof(const ClassTemplatePartialSpecializationDecl *) { 915c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor return true; 916c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor } 917c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor}; 918c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor 9191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ClassTemplatePartialSpecializationDecl 9201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : public ClassTemplateSpecializationDecl { 9211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief The list of template parameters 922c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor TemplateParameterList* TemplateParams; 923c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor 924833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// \brief The source info for the template arguments as written. 925833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc *ArgsAsWritten; 926833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall unsigned NumArgsAsWritten; 927833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 928ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \brief The class template partial specialization from which this 929ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// class template partial specialization was instantiated. 930ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// 931ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// The boolean value will be true to indicate that this class template 932ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// partial specialization was specialized at this level. 933ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor llvm::PointerIntPair<ClassTemplatePartialSpecializationDecl *, 1, bool> 934ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor InstantiatedFromMember; 935ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor 936c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor ClassTemplatePartialSpecializationDecl(ASTContext &Context, 937c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor DeclContext *DC, SourceLocation L, 938c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor TemplateParameterList *Params, 939c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor ClassTemplateDecl *SpecializedTemplate, 9408e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor TemplateArgumentListBuilder &Builder, 941833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc *ArgInfos, 942833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall unsigned NumArgInfos, 9438e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor ClassTemplatePartialSpecializationDecl *PrevDecl) 9441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : ClassTemplateSpecializationDecl(Context, 9458e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor ClassTemplatePartialSpecialization, 9468e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor DC, L, SpecializedTemplate, Builder, 9478e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor PrevDecl), 948833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateParams(Params), ArgsAsWritten(ArgInfos), 949833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NumArgsAsWritten(NumArgInfos), InstantiatedFromMember(0, false) { } 950c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor 951c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregorpublic: 952c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor static ClassTemplatePartialSpecializationDecl * 953c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor Create(ASTContext &Context, DeclContext *DC, SourceLocation L, 954c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor TemplateParameterList *Params, 955c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor ClassTemplateDecl *SpecializedTemplate, 95691fdf6f576b91f023c3bebb0d3786aab555cb3c5Anders Carlsson TemplateArgumentListBuilder &Builder, 957833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc *ArgInfos, 958833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall unsigned NumArgInfos, 959c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor ClassTemplatePartialSpecializationDecl *PrevDecl); 960c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor 961c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor /// Get the list of template parameters 962c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor TemplateParameterList *getTemplateParameters() const { 963c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor return TemplateParams; 964c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor } 965c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor 966833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// Get the template arguments as written. 967833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc *getTemplateArgsAsWritten() const { 968833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return ArgsAsWritten; 969833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 970833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 971833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// Get the number of template arguments as written. 972833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall unsigned getNumTemplateArgsAsWritten() const { 973833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return NumArgsAsWritten; 974833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 975833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 976ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \brief Retrieve the member class template partial specialization from 977ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// which this particular class template partial specialization was 978ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// instantiated. 979ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// 980ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \code 981ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// template<typename T> 982ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// struct Outer { 983ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// template<typename U> struct Inner; 984ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// template<typename U> struct Inner<U*> { }; // #1 985ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// }; 986ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// 987ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// Outer<float>::Inner<int*> ii; 988ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \endcode 989ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// 990ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// In this example, the instantiation of \c Outer<float>::Inner<int*> will 991ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// end up instantiating the partial specialization 992ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \c Outer<float>::Inner<U*>, which itself was instantiated from the class 993ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// template partial specialization \c Outer<T>::Inner<U*>. Given 994ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \c Outer<float>::Inner<U*>, this function would return 995ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \c Outer<T>::Inner<U*>. 996ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor ClassTemplatePartialSpecializationDecl *getInstantiatedFromMember() { 997ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor ClassTemplatePartialSpecializationDecl *First 998ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor = cast<ClassTemplatePartialSpecializationDecl>(getFirstDeclaration()); 999ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor return First->InstantiatedFromMember.getPointer(); 1000ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor } 1001ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor 1002ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor void setInstantiatedFromMember( 1003ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor ClassTemplatePartialSpecializationDecl *PartialSpec) { 1004ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor ClassTemplatePartialSpecializationDecl *First 1005ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor = cast<ClassTemplatePartialSpecializationDecl>(getFirstDeclaration()); 1006ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor First->InstantiatedFromMember.setPointer(PartialSpec); 1007ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor } 1008ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor 1009ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \brief Determines whether this class template partial specialization 1010ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// template was a specialization of a member partial specialization. 1011ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// 1012ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// In the following example, the member template partial specialization 1013ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \c X<int>::Inner<T*> is a member specialization. 1014ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// 1015ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \code 1016ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// template<typename T> 1017ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// struct X { 1018ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// template<typename U> struct Inner; 1019ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// template<typename U> struct Inner<U*>; 1020ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// }; 1021ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// 1022ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// template<> template<typename T> 1023ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// struct X<int>::Inner<T*> { /* ... */ }; 1024ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \endcode 1025ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor bool isMemberSpecialization() { 1026ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor ClassTemplatePartialSpecializationDecl *First 1027ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor = cast<ClassTemplatePartialSpecializationDecl>(getFirstDeclaration()); 1028ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor return First->InstantiatedFromMember.getInt(); 1029ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor } 1030ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor 1031ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \brief Note that this member template is a specialization. 1032ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor void setMemberSpecialization() { 1033ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor ClassTemplatePartialSpecializationDecl *First 1034ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor = cast<ClassTemplatePartialSpecializationDecl>(getFirstDeclaration()); 1035ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor assert(First->InstantiatedFromMember.getPointer() && 1036ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor "Only member templates can be member template specializations"); 1037ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor return First->InstantiatedFromMember.setInt(true); 1038ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor } 1039ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor 1040c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor // FIXME: Add Profile support! 1041c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor 10421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Decl *D) { 1043c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor return D->getKind() == ClassTemplatePartialSpecialization; 1044c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor } 1045c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor 1046c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor static bool classof(const ClassTemplatePartialSpecializationDecl *) { 1047c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor return true; 1048c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor } 10493e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor}; 10503e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 10513e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor/// Declaration of a class template. 10523e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregorclass ClassTemplateDecl : public TemplateDecl { 10533e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregorprotected: 10545953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor /// \brief Data that is common to all of the declarations of a given 10555953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor /// class template. 10565953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor struct Common { 1057fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor Common() : InstantiatedFromMember(0, 0) {} 1058e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall 10595953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor /// \brief The class template specializations for this class 10605953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor /// template, including explicit specializations and instantiations. 10615953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor llvm::FoldingSet<ClassTemplateSpecializationDecl> Specializations; 10627da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor 1063c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor /// \brief The class template partial specializations for this class 1064c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor /// template. 10651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump llvm::FoldingSet<ClassTemplatePartialSpecializationDecl> 1066c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor PartialSpecializations; 1067c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor 10687da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// \brief The injected-class-name type for this class template. 10697da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor QualType InjectedClassNameType; 1070e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall 1071e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall /// \brief The templated member class from which this was most 1072e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall /// directly instantiated (or null). 1073fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// 1074fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// The boolean value indicates whether this member class template 1075fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// was explicitly specialized. 1076fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor llvm::PointerIntPair<ClassTemplateDecl *, 1, bool> InstantiatedFromMember; 10775953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor }; 10785953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor 1079fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor // FIXME: Combine PreviousDeclaration with CommonPtr, as in 1080fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor // FunctionTemplateDecl. 1081fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor 10827532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor /// \brief Previous declaration of this class template. 10835953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor ClassTemplateDecl *PreviousDeclaration; 10845953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor 10855953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor /// \brief Pointer to the data that is common to all of the 10865953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor /// declarations of this class template. 10871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 10885953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor /// The first declaration of a class template (e.g., the declaration 10895953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor /// with no "previous declaration") owns this pointer. 10905953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor Common *CommonPtr; 10911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10923e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor ClassTemplateDecl(DeclContext *DC, SourceLocation L, DeclarationName Name, 10935953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor TemplateParameterList *Params, NamedDecl *Decl, 10945953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor ClassTemplateDecl *PrevDecl, Common *CommonPtr) 10955953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor : TemplateDecl(ClassTemplate, DC, L, Name, Params, Decl), 10965953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor PreviousDeclaration(PrevDecl), CommonPtr(CommonPtr) { } 10973e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 10985953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor ~ClassTemplateDecl(); 10993e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 11003e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregorpublic: 11013e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor /// Get the underlying class declarations of the template. 11023e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor CXXRecordDecl *getTemplatedDecl() const { 11033e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor return static_cast<CXXRecordDecl *>(TemplatedDecl); 11043e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor } 11053e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 11067da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// \brief Retrieve the previous declaration of this template. 11077da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor ClassTemplateDecl *getPreviousDeclaration() const { 11087da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor return PreviousDeclaration; 11097da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor } 11101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1111b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios Kyrtzidis virtual ClassTemplateDecl *getCanonicalDecl(); 11127da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor 11135953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor /// Create a class template node. 11143e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor static ClassTemplateDecl *Create(ASTContext &C, DeclContext *DC, 11153e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor SourceLocation L, 11163e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor DeclarationName Name, 11173e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor TemplateParameterList *Params, 11185953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor NamedDecl *Decl, 11195953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor ClassTemplateDecl *PrevDecl); 11203e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 11213e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor /// \brief Retrieve the set of specializations of this class template. 11223e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor llvm::FoldingSet<ClassTemplateSpecializationDecl> &getSpecializations() { 11235953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor return CommonPtr->Specializations; 11243e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor } 11253e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 1126c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor /// \brief Retrieve the set of partial specializations of this class 1127c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor /// template. 1128c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor llvm::FoldingSet<ClassTemplatePartialSpecializationDecl> & 1129c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor getPartialSpecializations() { 1130c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor return CommonPtr->PartialSpecializations; 1131c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor } 1132c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor 1133b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor /// \brief Find a class template partial specialization with the given 1134b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor /// type T. 1135b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor /// 1136b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor /// \brief A dependent type that names a specialization of this class 1137b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor /// template. 1138b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor /// 1139b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor /// \returns the class template partial specialization that exactly matches 1140b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor /// the type \p T, or NULL if no such partial specialization exists. 1141b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor ClassTemplatePartialSpecializationDecl *findPartialSpecialization(QualType T); 11421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11437da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// \brief Retrieve the type of the injected-class-name for this 11447da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// class template. 11457da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// 11467da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// The injected-class-name for a class template \c X is \c 11477da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// X<template-args>, where \c template-args is formed from the 11487da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// template arguments that correspond to the template parameters of 11497da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// \c X. For example: 11507da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// 11517da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// \code 11527da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// template<typename T, int N> 11537da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// struct array { 11547da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// typedef array this_type; // "array" is equivalent to "array<T, N>" 11557da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// }; 11567da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// \endcode 11577da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor QualType getInjectedClassNameType(ASTContext &Context); 11587da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor 1159e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall /// \brief Retrieve the member class template that this class template was 1160e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall /// derived from. 1161e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall /// 1162e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall /// This routine will return non-NULL for templated member classes of 1163e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall /// class templates. For example, given: 1164e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall /// 1165e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall /// \code 1166e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall /// template <typename T> 1167e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall /// struct X { 1168e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall /// template <typename U> struct A {}; 1169e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall /// }; 1170e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall /// \endcode 1171e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall /// 1172e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall /// X<int>::A<float> is a ClassTemplateSpecializationDecl (whose parent 1173e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall /// is X<int>, also a CTSD) for which getSpecializedTemplate() will 1174e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall /// return X<int>::A<U>, a TemplateClassDecl (whose parent is again 1175e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall /// X<int>) for which getInstantiatedFromMemberTemplate() will return 1176e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall /// X<T>::A<U>, a TemplateClassDecl (whose parent is X<T>, also a TCD). 1177e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall /// 1178e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall /// \returns null if this is not an instantiation of a member class template. 1179e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall ClassTemplateDecl *getInstantiatedFromMemberTemplate() const { 1180fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor return CommonPtr->InstantiatedFromMember.getPointer(); 1181e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall } 1182e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall 1183e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall void setInstantiatedFromMemberTemplate(ClassTemplateDecl *CTD) { 1184fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor assert(!CommonPtr->InstantiatedFromMember.getPointer()); 1185fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor CommonPtr->InstantiatedFromMember.setPointer(CTD); 1186e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall } 1187e29ba20148e9b7835ad463b39cd4ee9223eafbbfJohn McCall 1188fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// \brief Determines whether this template was a specialization of a 1189fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// member template. 1190fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// 1191fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// In the following example, the member template \c X<int>::Inner is a 1192fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// member specialization. 1193fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// 1194fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// \code 1195fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// template<typename T> 1196fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// struct X { 1197fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// template<typename U> struct Inner; 1198fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// }; 1199fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// 1200fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// template<> template<typename T> 1201fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// struct X<int>::Inner { /* ... */ }; 1202fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// \endcode 1203fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor bool isMemberSpecialization() { 1204fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor return CommonPtr->InstantiatedFromMember.getInt(); 1205fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor } 1206fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor 1207fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// \brief Note that this member template is a specialization. 1208fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor void setMemberSpecialization() { 1209fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor assert(CommonPtr->InstantiatedFromMember.getPointer() && 1210fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor "Only member templates can be member template specializations"); 1211fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor CommonPtr->InstantiatedFromMember.setInt(true); 1212fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor } 1213fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor 12143e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor // Implement isa/cast/dyncast support 12153e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor static bool classof(const Decl *D) 12163e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor { return D->getKind() == ClassTemplate; } 12173e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor static bool classof(const ClassTemplateDecl *D) 12183e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor { return true; } 12195953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor 12205953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor virtual void Destroy(ASTContext& C); 12213e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor}; 12223e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 1223dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall/// Declaration of a friend template. For example: 1224dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall/// 1225dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall/// template <typename T> class A { 1226dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall/// friend class MyVector<T>; // not a friend template 1227dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall/// template <typename U> friend class B; // friend template 1228dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall/// template <typename U> friend class Foo<T>::Nested; // friend template 1229dd4a3b0065b9a7e7b00073df415a798886c090f3John McCallclass FriendTemplateDecl : public Decl { 1230dd4a3b0065b9a7e7b00073df415a798886c090f3John McCallpublic: 1231dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall typedef llvm::PointerUnion<NamedDecl*,Type*> FriendUnion; 1232dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1233dd4a3b0065b9a7e7b00073df415a798886c090f3John McCallprivate: 1234dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall // The number of template parameters; always non-zero. 1235dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall unsigned NumParams; 1236dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1237dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall // The parameter list. 1238dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall TemplateParameterList **Params; 1239dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1240dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall // The declaration that's a friend of this class. 1241dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall FriendUnion Friend; 1242dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1243dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall // Location of the 'friend' specifier. 1244dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall SourceLocation FriendLoc; 1245dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1246dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1247dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall FriendTemplateDecl(DeclContext *DC, SourceLocation Loc, 1248dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall unsigned NParams, 1249dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall TemplateParameterList **Params, 1250dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall FriendUnion Friend, 1251dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall SourceLocation FriendLoc) 1252dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall : Decl(Decl::FriendTemplate, DC, Loc), 1253dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall NumParams(NParams), 1254dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall Params(Params), 1255dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall Friend(Friend), 1256dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall FriendLoc(FriendLoc) 1257dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall {} 1258dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1259dd4a3b0065b9a7e7b00073df415a798886c090f3John McCallpublic: 1260dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall static FriendTemplateDecl *Create(ASTContext &Context, 1261dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall DeclContext *DC, SourceLocation Loc, 1262dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall unsigned NParams, 1263dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall TemplateParameterList **Params, 1264dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall FriendUnion Friend, 1265dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall SourceLocation FriendLoc); 1266dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1267dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall /// If this friend declaration names a templated type (or 1268dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall /// a dependent member type of a templated type), return that 1269dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall /// type; otherwise return null. 1270dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall Type *getFriendType() const { 1271dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall return Friend.dyn_cast<Type*>(); 1272dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall } 1273dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1274dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall /// If this friend declaration names a templated function (or 1275dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall /// a member function of a templated type), return that type; 1276dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall /// otherwise return null. 1277dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall NamedDecl *getFriendDecl() const { 1278dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall return Friend.dyn_cast<NamedDecl*>(); 1279dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall } 1280dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1281dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall /// Retrieves the location of the 'friend' keyword. 1282dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall SourceLocation getFriendLoc() const { 1283dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall return FriendLoc; 1284dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall } 1285dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1286dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall TemplateParameterList *getTemplateParameterList(unsigned i) const { 1287dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall assert(i <= NumParams); 1288dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall return Params[i]; 1289dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall } 1290dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1291dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall unsigned getNumTemplateParameters() const { 1292dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall return NumParams; 1293dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall } 1294dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1295dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall // Implement isa/cast/dyncast/etc. 1296dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall static bool classof(const Decl *D) { 1297dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall return D->getKind() == Decl::FriendTemplate; 1298dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall } 1299dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall static bool classof(const FriendTemplateDecl *D) { return true; } 1300dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall}; 1301dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1302e53060fa78ad7e98352049f72787bdb7543e2a48Douglas Gregor/// Implementation of inline functions that require the template declarations 13031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpinline AnyFunctionDecl::AnyFunctionDecl(FunctionTemplateDecl *FTD) 1304e53060fa78ad7e98352049f72787bdb7543e2a48Douglas Gregor : Function(FTD) { } 1305e53060fa78ad7e98352049f72787bdb7543e2a48Douglas Gregor 1306aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor} /* end of namespace clang */ 1307aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 1308aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#endif 1309