DeclTemplate.h revision fe72e9ceeae6cc8669cd8bb722425300190638ea
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; 269eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourneclass RedeclarableTemplateDecl; 27aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregorclass FunctionTemplateDecl; 28aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregorclass ClassTemplateDecl; 29c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregorclass ClassTemplatePartialSpecializationDecl; 30aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregorclass TemplateTypeParmDecl; 31aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregorclass NonTypeTemplateParmDecl; 32aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregorclass TemplateTemplateParmDecl; 33aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 34f67875d5addf36b951ad37fb04509ab2b572c88aDouglas Gregor/// \brief Stores a template parameter of any kind. 35f67875d5addf36b951ad37fb04509ab2b572c88aDouglas Gregortypedef llvm::PointerUnion3<TemplateTypeParmDecl*, NonTypeTemplateParmDecl*, 36f67875d5addf36b951ad37fb04509ab2b572c88aDouglas Gregor TemplateTemplateParmDecl*> TemplateParameter; 37f67875d5addf36b951ad37fb04509ab2b572c88aDouglas Gregor 38aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor/// TemplateParameterList - Stores a list of template parameters for a 39aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor/// TemplateDecl and its derived classes. 40aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregorclass TemplateParameterList { 41ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor /// The location of the 'template' keyword. 42ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor SourceLocation TemplateLoc; 43ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor 44ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor /// The locations of the '<' and '>' angle brackets. 45ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor SourceLocation LAngleLoc, RAngleLoc; 46ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor 47ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor /// The number of template parameters in this template 48aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor /// parameter list. 49aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor unsigned NumParams; 50aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 51ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor TemplateParameterList(SourceLocation TemplateLoc, SourceLocation LAngleLoc, 52bf4ea56cdc376cef5a12abf6bf18dc34805c2226Douglas Gregor NamedDecl **Params, unsigned NumParams, 53ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor SourceLocation RAngleLoc); 54aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 55aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregorpublic: 561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static TemplateParameterList *Create(ASTContext &C, 57ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor SourceLocation TemplateLoc, 58ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor SourceLocation LAngleLoc, 59bf4ea56cdc376cef5a12abf6bf18dc34805c2226Douglas Gregor NamedDecl **Params, 60ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor unsigned NumParams, 61ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor SourceLocation RAngleLoc); 62aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 63aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor /// iterator - Iterates through the template parameters in this list. 64bf4ea56cdc376cef5a12abf6bf18dc34805c2226Douglas Gregor typedef NamedDecl** iterator; 65aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 66aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor /// const_iterator - Iterates through the template parameters in this list. 67bf4ea56cdc376cef5a12abf6bf18dc34805c2226Douglas Gregor typedef NamedDecl* const* const_iterator; 68aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 69bf4ea56cdc376cef5a12abf6bf18dc34805c2226Douglas Gregor iterator begin() { return reinterpret_cast<NamedDecl **>(this + 1); } 70aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor const_iterator begin() const { 71bf4ea56cdc376cef5a12abf6bf18dc34805c2226Douglas Gregor return reinterpret_cast<NamedDecl * const *>(this + 1); 72aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor } 73aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor iterator end() { return begin() + NumParams; } 74aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor const_iterator end() const { return begin() + NumParams; } 75aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 76aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor unsigned size() const { return NumParams; } 77ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor 78bf4ea56cdc376cef5a12abf6bf18dc34805c2226Douglas Gregor NamedDecl* getParam(unsigned Idx) { 79f67875d5addf36b951ad37fb04509ab2b572c88aDouglas Gregor assert(Idx < size() && "Template parameter index out-of-range"); 80f67875d5addf36b951ad37fb04509ab2b572c88aDouglas Gregor return begin()[Idx]; 81f67875d5addf36b951ad37fb04509ab2b572c88aDouglas Gregor } 82f67875d5addf36b951ad37fb04509ab2b572c88aDouglas Gregor 83bf4ea56cdc376cef5a12abf6bf18dc34805c2226Douglas Gregor const NamedDecl* getParam(unsigned Idx) const { 8440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor assert(Idx < size() && "Template parameter index out-of-range"); 8540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor return begin()[Idx]; 8640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor } 8740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 8862cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor /// \btief Returns the minimum number of arguments needed to form a 8962cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor /// template specialization. This may be fewer than the number of 9062cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor /// template parameters, if some of the parameters have default 910ceffb51b28b09db67404058c642dcb1f877f6e8Anders Carlsson /// arguments or if there is a parameter pack. 9262cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor unsigned getMinRequiredArguments() const; 9362cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor 94ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \brief Get the depth of this template parameter list in the set of 95ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// template parameter lists. 96ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// 97ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// The first template parameter list in a declaration will have depth 0, 98ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// the second template parameter list will have depth 1, etc. 99ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor unsigned getDepth() const; 100ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor 101ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor SourceLocation getTemplateLoc() const { return TemplateLoc; } 102ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor SourceLocation getLAngleLoc() const { return LAngleLoc; } 103ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor SourceLocation getRAngleLoc() const { return RAngleLoc; } 10462cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor 10562cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor SourceRange getSourceRange() const { 10662cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor return SourceRange(TemplateLoc, RAngleLoc); 10762cb18dd11472965e03374d40bc27d650bc331b6Douglas Gregor } 108aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor}; 109aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 110127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// \brief A helper class for making template argument lists. 111127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorclass TemplateArgumentListBuilder { 112127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateArgument *StructuredArgs; 113127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned MaxStructuredArgs; 114127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned NumStructuredArgs; 1151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11698d279ba8092186f606abaa8298f13a0816b9cf2Chris Lattner llvm::SmallVector<TemplateArgument, 4> FlatArgs; 117127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned MaxFlatArgs; 118127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned NumFlatArgs; 1191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 120127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor bool AddingToPack; 121127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned PackBeginIndex; 1221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 123aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregorpublic: 124127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateArgumentListBuilder(const TemplateParameterList *Parameters, 125127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned NumTemplateArgs) 1261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : StructuredArgs(0), MaxStructuredArgs(Parameters->size()), 1271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NumStructuredArgs(0), FlatArgs(0), 128127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor MaxFlatArgs(std::max(MaxStructuredArgs, NumTemplateArgs)), NumFlatArgs(0), 129127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor AddingToPack(false), PackBeginIndex(0) { } 1301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13198d279ba8092186f606abaa8298f13a0816b9cf2Chris Lattner void Append(const TemplateArgument &Arg); 132127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor void BeginPack(); 133127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor void EndPack(); 1341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13598d279ba8092186f606abaa8298f13a0816b9cf2Chris Lattner unsigned flatSize() const { return FlatArgs.size(); } 13698d279ba8092186f606abaa8298f13a0816b9cf2Chris Lattner const TemplateArgument *getFlatArguments() const { return FlatArgs.data(); } 1371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 138127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned structuredSize() const { 139127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // If we don't have any structured args, just reuse the flat size. 140127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor if (!StructuredArgs) 141127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor return flatSize(); 1421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 143127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor return NumStructuredArgs; 144d684b0027e16163c4bdba3e2f8bfadda7d62a0d3Douglas Gregor } 145127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor const TemplateArgument *getStructuredArguments() const { 146127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // If we don't have any structured args, just reuse the flat args. 147127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor if (!StructuredArgs) 148127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor return getFlatArguments(); 1491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 150127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor return StructuredArgs; 151aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor } 152aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor}; 153aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 154127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// \brief A template argument list. 155127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// 156127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// FIXME: In the future, this class will be extended to support 157127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// variadic templates and member templates, which will make some of 158127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// the function names below make more sense. 159127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorclass TemplateArgumentList { 160127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief The template argument list. 161127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// 162127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// The integer value will be non-zero to indicate that this 16356ef550c5eeea0714c635782776389df2a177584Chris Lattner /// template argument list does own the pointer. 164127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor llvm::PointerIntPair<const TemplateArgument *, 1> FlatArguments; 1651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 166127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief The number of template arguments in this template 167127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// argument list. 168127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned NumFlatArguments; 1691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 170127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor llvm::PointerIntPair<const TemplateArgument *, 1> StructuredArguments; 171127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned NumStructuredArguments; 1721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 173885989109ade7cb4dc493e25da41456c64b3cf6aChris Lattner TemplateArgumentList(const TemplateArgumentList &Other); // DO NOT IMPL 174885989109ade7cb4dc493e25da41456c64b3cf6aChris Lattner void operator=(const TemplateArgumentList &Other); // DO NOT IMPL 175aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregorpublic: 17656ef550c5eeea0714c635782776389df2a177584Chris Lattner /// TemplateArgumentList - If this constructor is passed "true" for 'TakeArgs' 17756ef550c5eeea0714c635782776389df2a177584Chris Lattner /// it copies them into a locally new[]'d array. If passed "false", then it 17856ef550c5eeea0714c635782776389df2a177584Chris Lattner /// just references the array passed in. This is only safe if the builder 17956ef550c5eeea0714c635782776389df2a177584Chris Lattner /// outlives it, but saves a copy. 180127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateArgumentList(ASTContext &Context, 181127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateArgumentListBuilder &Builder, 182127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor bool TakeArgs); 1831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 184d0913557c800c8a712fb554032a833619f23bc56Argyrios Kyrtzidis /// TemplateArgumentList - It copies the template arguments into a locally 185d0913557c800c8a712fb554032a833619f23bc56Argyrios Kyrtzidis /// new[]'d array. 186d0913557c800c8a712fb554032a833619f23bc56Argyrios Kyrtzidis TemplateArgumentList(ASTContext &Context, 18794d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis const TemplateArgument *Args, unsigned NumArgs); 188d0913557c800c8a712fb554032a833619f23bc56Argyrios Kyrtzidis 189885989109ade7cb4dc493e25da41456c64b3cf6aChris Lattner /// Produces a shallow copy of the given template argument list. This 190885989109ade7cb4dc493e25da41456c64b3cf6aChris Lattner /// assumes that the input argument list outlives it. This takes the list as 191885989109ade7cb4dc493e25da41456c64b3cf6aChris Lattner /// a pointer to avoid looking like a copy constructor, since this really 192885989109ade7cb4dc493e25da41456c64b3cf6aChris Lattner /// really isn't safe to use that way. 193885989109ade7cb4dc493e25da41456c64b3cf6aChris Lattner explicit TemplateArgumentList(const TemplateArgumentList *Other); 19494d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis 19594d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis TemplateArgumentList() : NumFlatArguments(0), NumStructuredArguments(0) { } 19694d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis 19794d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis /// \brief Copies the template arguments into a locally new[]'d array. 19894d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis void init(ASTContext &Context, 19994d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis const TemplateArgument *Args, unsigned NumArgs); 2001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 201127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Retrieve the template argument at a given index. 2021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const TemplateArgument &get(unsigned Idx) const { 203127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor assert(Idx < NumFlatArguments && "Invalid template argument index"); 204127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor return getFlatArgumentList()[Idx]; 205127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor } 2061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 207127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Retrieve the template argument at a given index. 208127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor const TemplateArgument &operator[](unsigned Idx) const { return get(Idx); } 2091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 210127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Retrieve the number of template arguments in this 211127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// template argument list. 212127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned size() const { return NumFlatArguments; } 2131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 214127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Retrieve the number of template arguments in the 215127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// flattened template argument list. 216127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned flat_size() const { return NumFlatArguments; } 2171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 218127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Retrieve the flattened template argument list. 2191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const TemplateArgument *getFlatArgumentList() const { 220127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor return FlatArguments.getPointer(); 221127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor } 222127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor}; 2231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 224127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor//===----------------------------------------------------------------------===// 225127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor// Kinds of Templates 226127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor//===----------------------------------------------------------------------===// 227aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 228127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// TemplateDecl - The base class of all kinds of template declarations (e.g., 229127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// class, function, etc.). The TemplateDecl class stores the list of template 230127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// parameters and a reference to the templated scoped declaration: the 231127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// underlying AST node. 232127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorclass TemplateDecl : public NamedDecl { 233127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorprotected: 234127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // This is probably never used. 235127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L, 236127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor DeclarationName Name) 2371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : NamedDecl(DK, DC, L, Name), TemplatedDecl(0), TemplateParams(0) { } 238d684b0027e16163c4bdba3e2f8bfadda7d62a0d3Douglas Gregor 239127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // Construct a template decl with the given name and parameters. 240127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // Used when there is not templated element (tt-params, alias?). 241127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L, 242127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor DeclarationName Name, TemplateParameterList *Params) 2431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : NamedDecl(DK, DC, L, Name), TemplatedDecl(0), TemplateParams(Params) { } 244d684b0027e16163c4bdba3e2f8bfadda7d62a0d3Douglas Gregor 245127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // Construct a template decl with name, parameters, and templated element. 246127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L, 247127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor DeclarationName Name, TemplateParameterList *Params, 248127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor NamedDecl *Decl) 249127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor : NamedDecl(DK, DC, L, Name), TemplatedDecl(Decl), 250127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateParams(Params) { } 251127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorpublic: 252127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// Get the list of template parameters 253127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateParameterList *getTemplateParameters() const { 254127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor return TemplateParams; 255d684b0027e16163c4bdba3e2f8bfadda7d62a0d3Douglas Gregor } 256d684b0027e16163c4bdba3e2f8bfadda7d62a0d3Douglas Gregor 257127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// Get the underlying, templated declaration. 258127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor NamedDecl *getTemplatedDecl() const { return TemplatedDecl; } 259127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor 260aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor // Implement isa/cast/dyncast/etc. 26180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 262127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor static bool classof(const TemplateDecl *D) { return true; } 2639eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne static bool classof(const RedeclarableTemplateDecl *D) { return true; } 264127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor static bool classof(const FunctionTemplateDecl *D) { return true; } 265127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor static bool classof(const ClassTemplateDecl *D) { return true; } 266aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor static bool classof(const TemplateTemplateParmDecl *D) { return true; } 26780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { 2689a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt return K >= firstTemplate && K <= lastTemplate; 26980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 270aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 27180484d0de0dccee66d9f1760127c3e6e218987daDouglas Gregor SourceRange getSourceRange() const { 27280484d0de0dccee66d9f1760127c3e6e218987daDouglas Gregor return SourceRange(TemplateParams->getTemplateLoc(), 27380484d0de0dccee66d9f1760127c3e6e218987daDouglas Gregor TemplatedDecl->getSourceRange().getEnd()); 27480484d0de0dccee66d9f1760127c3e6e218987daDouglas Gregor } 27580484d0de0dccee66d9f1760127c3e6e218987daDouglas Gregor 276127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorprotected: 277127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor NamedDecl *TemplatedDecl; 278127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateParameterList* TemplateParams; 2798731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis 2808731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidispublic: 2818731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis /// \brief Initialize the underlying templated declaration and 2828731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis /// template parameters. 2838731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis void init(NamedDecl *templatedDecl, TemplateParameterList* templateParams) { 2848731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis assert(TemplatedDecl == 0 && "TemplatedDecl already set!"); 2858731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis assert(TemplateParams == 0 && "TemplateParams already set!"); 2868731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis TemplatedDecl = templatedDecl; 2878731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis TemplateParams = templateParams; 2888731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis } 289127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor}; 2901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// \brief Provides information about a function template specialization, 292127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// which is a FunctionDecl that has been explicitly specialization or 293127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// instantiated from a function template. 294127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorclass FunctionTemplateSpecializationInfo : public llvm::FoldingSetNode { 295127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorpublic: 2961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief The function template specialization that this structure 297127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// describes. 298127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor FunctionDecl *Function; 2991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief The function template from which this function template 301127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// specialization was generated. 3021fd2dd145d9bcdf0b8d60a88e1795b6ae83656f5Douglas Gregor /// 303d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor /// The two bits are contain the top 4 values of TemplateSpecializationKind. 304d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor llvm::PointerIntPair<FunctionTemplateDecl *, 2> Template; 3051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 306127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief The template arguments used to produce the function template 307127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// specialization from the function template. 308127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor const TemplateArgumentList *TemplateArguments; 3091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 310e03db98d67111ebf7622d9086951aacc24406b66Abramo Bagnara /// \brief The template arguments as written in the sources, if provided. 311e03db98d67111ebf7622d9086951aacc24406b66Abramo Bagnara const TemplateArgumentListInfo *TemplateArgumentsAsWritten; 312e03db98d67111ebf7622d9086951aacc24406b66Abramo Bagnara 313b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// \brief The point at which this function template specialization was 314b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// first instantiated. 315b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor SourceLocation PointOfInstantiation; 316b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor 3171fd2dd145d9bcdf0b8d60a88e1795b6ae83656f5Douglas Gregor /// \brief Retrieve the template from which this function was specialized. 3181fd2dd145d9bcdf0b8d60a88e1795b6ae83656f5Douglas Gregor FunctionTemplateDecl *getTemplate() const { return Template.getPointer(); } 319d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor 320d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor /// \brief Determine what kind of template specialization this is. 321d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor TemplateSpecializationKind getTemplateSpecializationKind() const { 322d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor return (TemplateSpecializationKind)(Template.getInt() + 1); 323d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor } 324d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor 325d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor /// \brief Set the template specialization kind. 326d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor void setTemplateSpecializationKind(TemplateSpecializationKind TSK) { 3271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(TSK != TSK_Undeclared && 328d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor "Cannot encode TSK_Undeclared for a function template specialization"); 329d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor Template.setInt(TSK - 1); 3301fd2dd145d9bcdf0b8d60a88e1795b6ae83656f5Douglas Gregor } 3311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 332b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// \brief Retrieve the first point of instantiation of this function 333b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// template specialization. 334b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// 335b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// The point of instantiation may be an invalid source location if this 336b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// function has yet to be instantiated. 337b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor SourceLocation getPointOfInstantiation() const { 338b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor return PointOfInstantiation; 339b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor } 340b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor 341b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// \brief Set the (first) point of instantiation of this function template 342b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// specialization. 343b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor void setPointOfInstantiation(SourceLocation POI) { 344b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor PointOfInstantiation = POI; 345b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor } 346b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor 347127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 3481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Profile(ID, TemplateArguments->getFlatArgumentList(), 349828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor TemplateArguments->flat_size(), 3501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Function->getASTContext()); 351127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor } 3521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void 3541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Profile(llvm::FoldingSetNodeID &ID, const TemplateArgument *TemplateArgs, 355828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor unsigned NumTemplateArgs, ASTContext &Context) { 356127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor ID.AddInteger(NumTemplateArgs); 357127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor for (unsigned Arg = 0; Arg != NumTemplateArgs; ++Arg) 358828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor TemplateArgs[Arg].Profile(ID, Context); 3591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 360127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor}; 3611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3622db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor/// \brief Provides information a specialization of a member of a class 3632db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor/// template, which may be a member function, static data member, or 3642db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor/// member class. 3652db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregorclass MemberSpecializationInfo { 36644e368b6a85c42d681148ccd5e0052418ff9751eDouglas Gregor // The member declaration from which this member was instantiated, and the 36744e368b6a85c42d681148ccd5e0052418ff9751eDouglas Gregor // manner in which the instantiation occurred (in the lower two bits). 36844e368b6a85c42d681148ccd5e0052418ff9751eDouglas Gregor llvm::PointerIntPair<NamedDecl *, 2> MemberAndTSK; 3692db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor 370b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor // The point at which this member was first instantiated. 371b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor SourceLocation PointOfInstantiation; 372b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor 3732db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregorpublic: 3742db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor explicit 3759421adc43891e272156fab640e5d5ee5054b779cArgyrios Kyrtzidis MemberSpecializationInfo(NamedDecl *IF, TemplateSpecializationKind TSK, 3769421adc43891e272156fab640e5d5ee5054b779cArgyrios Kyrtzidis SourceLocation POI = SourceLocation()) 3779421adc43891e272156fab640e5d5ee5054b779cArgyrios Kyrtzidis : MemberAndTSK(IF, TSK - 1), PointOfInstantiation(POI) { 37844e368b6a85c42d681148ccd5e0052418ff9751eDouglas Gregor assert(TSK != TSK_Undeclared && 37944e368b6a85c42d681148ccd5e0052418ff9751eDouglas Gregor "Cannot encode undeclared template specializations for members"); 38044e368b6a85c42d681148ccd5e0052418ff9751eDouglas Gregor } 3812db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor 3822db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor /// \brief Retrieve the member declaration from which this member was 3832db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor /// instantiated. 38444e368b6a85c42d681148ccd5e0052418ff9751eDouglas Gregor NamedDecl *getInstantiatedFrom() const { return MemberAndTSK.getPointer(); } 3852db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor 3862db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor /// \brief Determine what kind of template specialization this is. 3872db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor TemplateSpecializationKind getTemplateSpecializationKind() const { 38844e368b6a85c42d681148ccd5e0052418ff9751eDouglas Gregor return (TemplateSpecializationKind)(MemberAndTSK.getInt() + 1); 3892db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor } 3902db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor 3912db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor /// \brief Set the template specialization kind. 3922db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor void setTemplateSpecializationKind(TemplateSpecializationKind TSK) { 39344e368b6a85c42d681148ccd5e0052418ff9751eDouglas Gregor assert(TSK != TSK_Undeclared && 39444e368b6a85c42d681148ccd5e0052418ff9751eDouglas Gregor "Cannot encode undeclared template specializations for members"); 39544e368b6a85c42d681148ccd5e0052418ff9751eDouglas Gregor MemberAndTSK.setInt(TSK - 1); 3962db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor } 397b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor 398b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// \brief Retrieve the first point of instantiation of this member. 399b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// If the point of instantiation is an invalid location, then this member 400b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// has not yet been instantiated. 401b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor SourceLocation getPointOfInstantiation() const { 402b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor return PointOfInstantiation; 403b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor } 404b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor 405b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor /// \brief Set the first point of instantiation. 406b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor void setPointOfInstantiation(SourceLocation POI) { 407b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor PointOfInstantiation = POI; 408b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor } 4092db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor}; 410af2094e7cecadf36667deb61a83587ffdd979bd3John McCall 411af2094e7cecadf36667deb61a83587ffdd979bd3John McCall/// \brief Provides information about a dependent function-template 412af2094e7cecadf36667deb61a83587ffdd979bd3John McCall/// specialization declaration. Since explicit function template 413af2094e7cecadf36667deb61a83587ffdd979bd3John McCall/// specialization and instantiation declarations can only appear in 414af2094e7cecadf36667deb61a83587ffdd979bd3John McCall/// namespace scope, and you can only specialize a member of a 415af2094e7cecadf36667deb61a83587ffdd979bd3John McCall/// fully-specialized class, the only way to get one of these is in 416af2094e7cecadf36667deb61a83587ffdd979bd3John McCall/// a friend declaration like the following: 417af2094e7cecadf36667deb61a83587ffdd979bd3John McCall/// 418af2094e7cecadf36667deb61a83587ffdd979bd3John McCall/// template <class T> void foo(T); 419af2094e7cecadf36667deb61a83587ffdd979bd3John McCall/// template <class T> class A { 420af2094e7cecadf36667deb61a83587ffdd979bd3John McCall/// friend void foo<>(T); 421af2094e7cecadf36667deb61a83587ffdd979bd3John McCall/// }; 422af2094e7cecadf36667deb61a83587ffdd979bd3John McCallclass DependentFunctionTemplateSpecializationInfo { 423af2094e7cecadf36667deb61a83587ffdd979bd3John McCall union { 424af2094e7cecadf36667deb61a83587ffdd979bd3John McCall // Force sizeof to be a multiple of sizeof(void*) so that the 425af2094e7cecadf36667deb61a83587ffdd979bd3John McCall // trailing data is aligned. 426af2094e7cecadf36667deb61a83587ffdd979bd3John McCall void *Aligner; 427af2094e7cecadf36667deb61a83587ffdd979bd3John McCall 428af2094e7cecadf36667deb61a83587ffdd979bd3John McCall struct { 429af2094e7cecadf36667deb61a83587ffdd979bd3John McCall /// The number of potential template candidates. 430af2094e7cecadf36667deb61a83587ffdd979bd3John McCall unsigned NumTemplates; 431af2094e7cecadf36667deb61a83587ffdd979bd3John McCall 432af2094e7cecadf36667deb61a83587ffdd979bd3John McCall /// The number of template arguments. 433af2094e7cecadf36667deb61a83587ffdd979bd3John McCall unsigned NumArgs; 434af2094e7cecadf36667deb61a83587ffdd979bd3John McCall } d; 435af2094e7cecadf36667deb61a83587ffdd979bd3John McCall }; 436af2094e7cecadf36667deb61a83587ffdd979bd3John McCall 437af2094e7cecadf36667deb61a83587ffdd979bd3John McCall /// The locations of the left and right angle brackets. 438af2094e7cecadf36667deb61a83587ffdd979bd3John McCall SourceRange AngleLocs; 439af2094e7cecadf36667deb61a83587ffdd979bd3John McCall 440af2094e7cecadf36667deb61a83587ffdd979bd3John McCall FunctionTemplateDecl * const *getTemplates() const { 441af2094e7cecadf36667deb61a83587ffdd979bd3John McCall return reinterpret_cast<FunctionTemplateDecl*const*>(this+1); 442af2094e7cecadf36667deb61a83587ffdd979bd3John McCall } 443af2094e7cecadf36667deb61a83587ffdd979bd3John McCall 444af2094e7cecadf36667deb61a83587ffdd979bd3John McCall const TemplateArgumentLoc *getTemplateArgs() const { 445af2094e7cecadf36667deb61a83587ffdd979bd3John McCall return reinterpret_cast<const TemplateArgumentLoc*>( 44633cab704d9b3b5b0218d578a20593bdfb0b1eb23John McCall &getTemplates()[getNumTemplates()]); 447af2094e7cecadf36667deb61a83587ffdd979bd3John McCall } 448af2094e7cecadf36667deb61a83587ffdd979bd3John McCall 449af2094e7cecadf36667deb61a83587ffdd979bd3John McCallpublic: 450af2094e7cecadf36667deb61a83587ffdd979bd3John McCall DependentFunctionTemplateSpecializationInfo( 451af2094e7cecadf36667deb61a83587ffdd979bd3John McCall const UnresolvedSetImpl &Templates, 452af2094e7cecadf36667deb61a83587ffdd979bd3John McCall const TemplateArgumentListInfo &TemplateArgs); 453af2094e7cecadf36667deb61a83587ffdd979bd3John McCall 454af2094e7cecadf36667deb61a83587ffdd979bd3John McCall /// \brief Returns the number of function templates that this might 455af2094e7cecadf36667deb61a83587ffdd979bd3John McCall /// be a specialization of. 456af2094e7cecadf36667deb61a83587ffdd979bd3John McCall unsigned getNumTemplates() const { 457af2094e7cecadf36667deb61a83587ffdd979bd3John McCall return d.NumTemplates; 458af2094e7cecadf36667deb61a83587ffdd979bd3John McCall } 459af2094e7cecadf36667deb61a83587ffdd979bd3John McCall 460af2094e7cecadf36667deb61a83587ffdd979bd3John McCall /// \brief Returns the i'th template candidate. 461af2094e7cecadf36667deb61a83587ffdd979bd3John McCall FunctionTemplateDecl *getTemplate(unsigned I) const { 462af2094e7cecadf36667deb61a83587ffdd979bd3John McCall assert(I < getNumTemplates() && "template index out of range"); 463af2094e7cecadf36667deb61a83587ffdd979bd3John McCall return getTemplates()[I]; 464af2094e7cecadf36667deb61a83587ffdd979bd3John McCall } 465af2094e7cecadf36667deb61a83587ffdd979bd3John McCall 466af2094e7cecadf36667deb61a83587ffdd979bd3John McCall /// \brief Returns the number of explicit template arguments that were given. 467af2094e7cecadf36667deb61a83587ffdd979bd3John McCall unsigned getNumTemplateArgs() const { 468af2094e7cecadf36667deb61a83587ffdd979bd3John McCall return d.NumArgs; 469af2094e7cecadf36667deb61a83587ffdd979bd3John McCall } 470af2094e7cecadf36667deb61a83587ffdd979bd3John McCall 471af2094e7cecadf36667deb61a83587ffdd979bd3John McCall /// \brief Returns the nth template argument. 472af2094e7cecadf36667deb61a83587ffdd979bd3John McCall const TemplateArgumentLoc &getTemplateArg(unsigned I) const { 473af2094e7cecadf36667deb61a83587ffdd979bd3John McCall assert(I < getNumTemplateArgs() && "template arg index out of range"); 474af2094e7cecadf36667deb61a83587ffdd979bd3John McCall return getTemplateArgs()[I]; 475af2094e7cecadf36667deb61a83587ffdd979bd3John McCall } 476af2094e7cecadf36667deb61a83587ffdd979bd3John McCall 477af2094e7cecadf36667deb61a83587ffdd979bd3John McCall SourceLocation getLAngleLoc() const { 478af2094e7cecadf36667deb61a83587ffdd979bd3John McCall return AngleLocs.getBegin(); 479af2094e7cecadf36667deb61a83587ffdd979bd3John McCall } 480af2094e7cecadf36667deb61a83587ffdd979bd3John McCall 481af2094e7cecadf36667deb61a83587ffdd979bd3John McCall SourceLocation getRAngleLoc() const { 482af2094e7cecadf36667deb61a83587ffdd979bd3John McCall return AngleLocs.getEnd(); 483af2094e7cecadf36667deb61a83587ffdd979bd3John McCall } 484af2094e7cecadf36667deb61a83587ffdd979bd3John McCall}; 4852db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor 4869eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne/// Declaration of a redeclarable template. 4879eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourneclass RedeclarableTemplateDecl : public TemplateDecl { 4881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4899eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne RedeclarableTemplateDecl *getPreviousDeclarationImpl() { 4909eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return CommonOrPrev.dyn_cast<RedeclarableTemplateDecl*>(); 4919eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne } 4929eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 4939eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne RedeclarableTemplateDecl *getCanonicalDeclImpl(); 4949eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 4958a798a7f7d88dc9865fad7da648e5cef8580c65aPeter Collingbourne void setPreviousDeclarationImpl(RedeclarableTemplateDecl *Prev); 4969eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 4979eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne RedeclarableTemplateDecl *getInstantiatedFromMemberTemplateImpl() { 4989eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return getCommonPtr()->InstantiatedFromMember.getPointer(); 4999eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne } 5009eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 5019eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne void setInstantiatedFromMemberTemplateImpl(RedeclarableTemplateDecl *TD) { 5029eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne assert(!getCommonPtr()->InstantiatedFromMember.getPointer()); 5039eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne getCommonPtr()->InstantiatedFromMember.setPointer(TD); 5049eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne } 5051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5069eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourneprotected: 50744dd0b440efdb37ff4c6e49f243faa3b0580b120Peter Collingbourne template <typename EntryType> struct SpecEntryTraits { 50844dd0b440efdb37ff4c6e49f243faa3b0580b120Peter Collingbourne typedef EntryType DeclType; 50944dd0b440efdb37ff4c6e49f243faa3b0580b120Peter Collingbourne 51044dd0b440efdb37ff4c6e49f243faa3b0580b120Peter Collingbourne static DeclType *getMostRecentDeclaration(EntryType *D) { 51144dd0b440efdb37ff4c6e49f243faa3b0580b120Peter Collingbourne return D->getMostRecentDeclaration(); 51244dd0b440efdb37ff4c6e49f243faa3b0580b120Peter Collingbourne } 51344dd0b440efdb37ff4c6e49f243faa3b0580b120Peter Collingbourne }; 51444dd0b440efdb37ff4c6e49f243faa3b0580b120Peter Collingbourne 5159f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne template <typename EntryType, 5169f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne typename _SETraits = SpecEntryTraits<EntryType>, 5179f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne typename _DeclType = typename _SETraits::DeclType> 5189f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne class SpecIterator : public std::iterator<std::forward_iterator_tag, 5199f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne _DeclType*, ptrdiff_t, 5209f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne _DeclType*, _DeclType*> { 5219f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne typedef _SETraits SETraits; 5229f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne typedef _DeclType DeclType; 5239f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne 5249f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne typedef typename llvm::FoldingSet<EntryType>::iterator SetIteratorType; 5259f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne 5269f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne SetIteratorType SetIter; 5279f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne 5289f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne public: 5299f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne SpecIterator() : SetIter() {} 5309f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne SpecIterator(SetIteratorType SetIter) : SetIter(SetIter) {} 5319f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne 5329f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne DeclType *operator*() const { 5339f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne return SETraits::getMostRecentDeclaration(&*SetIter); 5349f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne } 5359f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne DeclType *operator->() const { return **this; } 5369f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne 5379f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne SpecIterator &operator++() { ++SetIter; return *this; } 5389f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne SpecIterator operator++(int) { 5399f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne SpecIterator tmp(*this); 5409f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne ++(*this); 5419f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne return tmp; 5429f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne } 5439f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne 5449f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne bool operator==(SpecIterator Other) const { 5459f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne return SetIter == Other.SetIter; 5469f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne } 5479f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne bool operator!=(SpecIterator Other) const { 5489f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne return SetIter != Other.SetIter; 5499f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne } 5509f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne }; 5519f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne 5529f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne template <typename EntryType> 5539f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne SpecIterator<EntryType> makeSpecIterator(llvm::FoldingSet<EntryType> &Specs, 5549f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne bool isEnd) { 5559f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne return SpecIterator<EntryType>(isEnd ? Specs.end() : Specs.begin()); 5569f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne } 5579f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne 5584048590d5774fd4b08661b5cf59b6f90b62f283aPeter Collingbourne template <class EntryType> typename SpecEntryTraits<EntryType>::DeclType* 5594048590d5774fd4b08661b5cf59b6f90b62f283aPeter Collingbourne findSpecializationImpl(llvm::FoldingSet<EntryType> &Specs, 5604048590d5774fd4b08661b5cf59b6f90b62f283aPeter Collingbourne const TemplateArgument *Args, unsigned NumArgs, 5614048590d5774fd4b08661b5cf59b6f90b62f283aPeter Collingbourne void *&InsertPos); 5624048590d5774fd4b08661b5cf59b6f90b62f283aPeter Collingbourne 5639eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne struct CommonBase { 5649eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne CommonBase() : InstantiatedFromMember(0, false) { } 5659eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 5669eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// \brief The template from which this was most 567d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// directly instantiated (or null). 568fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// 5699eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// The boolean value indicates whether this template 570fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor /// was explicitly specialized. 5719eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne llvm::PointerIntPair<RedeclarableTemplateDecl*, 1, bool> 5729eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne InstantiatedFromMember; 5738a798a7f7d88dc9865fad7da648e5cef8580c65aPeter Collingbourne 5748a798a7f7d88dc9865fad7da648e5cef8580c65aPeter Collingbourne /// \brief The latest declaration of this template. 5758a798a7f7d88dc9865fad7da648e5cef8580c65aPeter Collingbourne RedeclarableTemplateDecl *Latest; 5763e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor }; 5771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 578127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief A pointer to the previous declaration (if this is a redeclaration) 5799eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// or to the data that is common to all declarations of this template. 5809eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne llvm::PointerUnion<CommonBase*, RedeclarableTemplateDecl*> CommonOrPrev; 5811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5829eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// \brief Retrieves the "common" pointer shared by all (re-)declarations of 5839eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// the same template. Calling this routine may implicitly allocate memory 5849eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// for the common pointer. 5859eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne CommonBase *getCommonPtr(); 5861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5879eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne virtual CommonBase *newCommon() = 0; 5882c853e401ca406d417eb916e867226050e7be06bArgyrios Kyrtzidis 5899eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne // Construct a template decl with name, parameters, and templated element. 5909eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne RedeclarableTemplateDecl(Kind DK, DeclContext *DC, SourceLocation L, 5919eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne DeclarationName Name, TemplateParameterList *Params, 5929eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne NamedDecl *Decl) 5939eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne : TemplateDecl(DK, DC, L, Name, Params, Decl), 5949eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne CommonOrPrev((CommonBase*)0) { } 5951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5963e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregorpublic: 5979eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne template <class decl_type> friend class RedeclarableTemplate; 5989eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 5999eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne RedeclarableTemplateDecl *getCanonicalDecl() { 6009eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return getCanonicalDeclImpl(); 6013e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor } 6023e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 6039eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// \brief Retrieve the previous declaration of this template, or 6049eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// NULL if no such declaration exists. 6059eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne RedeclarableTemplateDecl *getPreviousDeclaration() { 6069eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return getPreviousDeclarationImpl(); 6079eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne } 6081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6099eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// \brief Retrieve the previous declaration of this template, or 6109eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// NULL if no such declaration exists. 6119eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne const RedeclarableTemplateDecl *getPreviousDeclaration() const { 6129eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return 6139eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne const_cast<RedeclarableTemplateDecl*>(this)->getPreviousDeclaration(); 6149eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne } 6159eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 616ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis /// \brief Retrieve the first declaration of this template, or itself 617ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis /// if this the first one. 618ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis RedeclarableTemplateDecl *getFirstDeclaration() { 619ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis return getCanonicalDecl(); 620ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis } 621ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis 622ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis /// \brief Retrieve the first declaration of this template, or itself 623ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis /// if this the first one. 624ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis const RedeclarableTemplateDecl *getFirstDeclaration() const { 625ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis return 626ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis const_cast<RedeclarableTemplateDecl*>(this)->getFirstDeclaration(); 627ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis } 628ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis 629ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis /// \brief Retrieve the most recent declaration of this template, or itself 630ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis /// if this the most recent one. 631ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis RedeclarableTemplateDecl *getMostRecentDeclaration() { 632ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis return getCommonPtr()->Latest; 633ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis } 634ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis 635ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis /// \brief Retrieve the most recent declaration of this template, or itself 636ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis /// if this the most recent one. 637ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis const RedeclarableTemplateDecl *getMostRecentDeclaration() const { 638ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis return 639ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis const_cast<RedeclarableTemplateDecl*>(this)->getMostRecentDeclaration(); 640ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis } 641ba5ff8ccf3f2a4d8fa3e91b58733707fb1caed6bArgyrios Kyrtzidis 6429eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// \brief Determines whether this template was a specialization of a 6439eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// member template. 6449eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// 6459eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// In the following example, the function template \c X<int>::f and the 6469eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// member template \c X<int>::Inner are member specializations. 6479eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// 6489eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// \code 6499eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// template<typename T> 6509eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// struct X { 6519eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// template<typename U> void f(T, U); 6529eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// template<typename U> struct Inner; 6539eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// }; 6549eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// 6559eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// template<> template<typename T> 6569eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// void X<int>::f(int, T); 6579eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// template<> template<typename T> 6589eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// struct X<int>::Inner { /* ... */ }; 6599eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// \endcode 6609eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne bool isMemberSpecialization() { 6619eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return getCommonPtr()->InstantiatedFromMember.getInt(); 6629eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne } 6639eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 6649eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// \brief Note that this member template is a specialization. 6659eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne void setMemberSpecialization() { 6669eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne assert(getCommonPtr()->InstantiatedFromMember.getPointer() && 6679eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne "Only member templates can be member template specializations"); 6689eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne getCommonPtr()->InstantiatedFromMember.setInt(true); 6699eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne } 6709eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 6719eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// \brief Retrieve the previous declaration of this template, or 6729eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// NULL if no such declaration exists. 6739eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne RedeclarableTemplateDecl *getInstantiatedFromMemberTemplate() { 6749eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return getInstantiatedFromMemberTemplateImpl(); 6759eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne } 6769eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 677f88718ea0ca0d64b7fd31d109f1d9ec769a9c45fPeter Collingbourne virtual RedeclarableTemplateDecl *getNextRedeclaration(); 678f88718ea0ca0d64b7fd31d109f1d9ec769a9c45fPeter Collingbourne 6799eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne // Implement isa/cast/dyncast/etc. 6809eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne static bool classof(const Decl *D) { return classofKind(D->getKind()); } 6819eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne static bool classof(const RedeclarableTemplateDecl *D) { return true; } 6829eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne static bool classof(const FunctionTemplateDecl *D) { return true; } 6839eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne static bool classof(const ClassTemplateDecl *D) { return true; } 6849eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne static bool classofKind(Kind K) { 6859eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return K >= firstRedeclarableTemplate && K <= lastRedeclarableTemplate; 6869eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne } 6879eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 688d527cc06d78fe5afa5f20105b51697637eb02c56Sebastian Redl friend class ASTDeclReader; 6893397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTDeclWriter; 6909eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne}; 6919eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 6929eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbournetemplate <class decl_type> 6939eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourneclass RedeclarableTemplate { 6949eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne RedeclarableTemplateDecl *thisDecl() { 6959eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return static_cast<decl_type*>(this); 6969eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne } 6979eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 6989eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbournepublic: 699127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Retrieve the previous declaration of this function template, or 700127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// NULL if no such declaration exists. 7019eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne decl_type *getPreviousDeclaration() { 7029eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return static_cast<decl_type*>(thisDecl()->getPreviousDeclarationImpl()); 7033e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor } 7043e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 705127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Retrieve the previous declaration of this function template, or 706127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// NULL if no such declaration exists. 7079eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne const decl_type *getPreviousDeclaration() const { 7089eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return const_cast<RedeclarableTemplate*>(this)->getPreviousDeclaration(); 7093e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor } 7101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 711127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Set the previous declaration of this function template. 7129eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne void setPreviousDeclaration(decl_type *Prev) { 7139eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne thisDecl()->setPreviousDeclarationImpl(Prev); 7149eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne } 7159eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 7169eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne decl_type *getCanonicalDecl() { 7179eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return static_cast<decl_type*>(thisDecl()->getCanonicalDeclImpl()); 718127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor } 7191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7209eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne const decl_type *getCanonicalDecl() const { 7219eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return const_cast<RedeclarableTemplate*>(this)->getCanonicalDecl(); 7229eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne } 7231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7249eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// \brief Retrieve the member template that this template was instantiated 7259eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// from. 726d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// 7279eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// This routine will return non-NULL for member templates of 728d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// class templates. For example, given: 729d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// 730d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// \code 731d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// template <typename T> 732d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// struct X { 733d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// template <typename U> void f(); 7349eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// template <typename U> struct A {}; 735d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// }; 736d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// \endcode 737d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// 7389eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// X<int>::f<float> is a CXXMethodDecl (whose parent is X<int>, a 7391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// ClassTemplateSpecializationDecl) for which getPrimaryTemplate() will 740d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// return X<int>::f, a FunctionTemplateDecl (whose parent is again 741d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// X<int>) for which getInstantiatedFromMemberTemplate() will return 7421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// X<T>::f, a FunctionTemplateDecl (whose parent is X<T>, a 743d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// ClassTemplateDecl). 744d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor /// 7459eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// X<int>::A<float> is a ClassTemplateSpecializationDecl (whose parent 7469eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// is X<int>, also a CTSD) for which getSpecializedTemplate() will 7479eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// return X<int>::A<U>, a ClassTemplateDecl (whose parent is again 7489eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// X<int>) for which getInstantiatedFromMemberTemplate() will return 7499eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// X<T>::A<U>, a ClassTemplateDecl (whose parent is X<T>, also a CTD). 7509eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// 7519eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// \returns NULL if this is not an instantiation of a member template. 7529eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne decl_type *getInstantiatedFromMemberTemplate() { 7539eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return static_cast<decl_type*>( 7549eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne thisDecl()->getInstantiatedFromMemberTemplateImpl()); 755d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor } 7561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7579eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne void setInstantiatedFromMemberTemplate(decl_type *TD) { 7589eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne thisDecl()->setInstantiatedFromMemberTemplateImpl(TD); 759d60e105e6d1624da647ef7dd35a9cf6fad1b763eDouglas Gregor } 7609eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne}; 7611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 76244dd0b440efdb37ff4c6e49f243faa3b0580b120Peter Collingbournetemplate <> struct RedeclarableTemplateDecl:: 76344dd0b440efdb37ff4c6e49f243faa3b0580b120Peter CollingbourneSpecEntryTraits<FunctionTemplateSpecializationInfo> { 76444dd0b440efdb37ff4c6e49f243faa3b0580b120Peter Collingbourne typedef FunctionDecl DeclType; 76544dd0b440efdb37ff4c6e49f243faa3b0580b120Peter Collingbourne 76644dd0b440efdb37ff4c6e49f243faa3b0580b120Peter Collingbourne static DeclType * 76744dd0b440efdb37ff4c6e49f243faa3b0580b120Peter Collingbourne getMostRecentDeclaration(FunctionTemplateSpecializationInfo *I) { 76844dd0b440efdb37ff4c6e49f243faa3b0580b120Peter Collingbourne return I->Function->getMostRecentDeclaration(); 76944dd0b440efdb37ff4c6e49f243faa3b0580b120Peter Collingbourne } 77044dd0b440efdb37ff4c6e49f243faa3b0580b120Peter Collingbourne}; 77144dd0b440efdb37ff4c6e49f243faa3b0580b120Peter Collingbourne 7729eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne/// Declaration of a template function. 7739eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourneclass FunctionTemplateDecl : public RedeclarableTemplateDecl, 7749eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne public RedeclarableTemplate<FunctionTemplateDecl> { 7759eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne static void DeallocateCommon(void *Ptr); 7769eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 7779eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourneprotected: 7789eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne typedef RedeclarableTemplate<FunctionTemplateDecl> redeclarable_base; 7799eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 7809eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// \brief Data that is common to all of the declarations of a given 7819eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// function template. 7829eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne struct Common : CommonBase { 7839eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// \brief The function template specializations for this function 7849eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// template, including explicit specializations and instantiations. 7859eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne llvm::FoldingSet<FunctionTemplateSpecializationInfo> Specializations; 7869eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne }; 7879eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 7889eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne FunctionTemplateDecl(DeclContext *DC, SourceLocation L, DeclarationName Name, 7899eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne TemplateParameterList *Params, NamedDecl *Decl) 7909eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne : RedeclarableTemplateDecl(FunctionTemplate, DC, L, Name, Params, Decl) { } 7919eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 7929eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne CommonBase *newCommon(); 7939eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 7949eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne Common *getCommonPtr() { 7959eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr()); 796fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor } 7979eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 7989eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne friend void FunctionDecl::setFunctionTemplateSpecialization( 7999eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne FunctionTemplateDecl *Template, 8009eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne const TemplateArgumentList *TemplateArgs, 8019eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne void *InsertPos, 8029eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne TemplateSpecializationKind TSK, 8039eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne const TemplateArgumentListInfo *TemplateArgsAsWritten, 8049eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne SourceLocation PointOfInstantiation); 8059eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 8069eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// \brief Retrieve the set of function template specializations of this 8079eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// function template. 8089eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne llvm::FoldingSet<FunctionTemplateSpecializationInfo> &getSpecializations() { 8099eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return getCommonPtr()->Specializations; 810fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor } 811fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor 8129eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbournepublic: 8139eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// Get the underlying function declaration of the template. 8149eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne FunctionDecl *getTemplatedDecl() const { 8159eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return static_cast<FunctionDecl*>(TemplatedDecl); 8169eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne } 8179eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 8189eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// \brief Return the specialization with the provided arguments if it exists, 8199eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// otherwise return the insertion point. 8209eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne FunctionDecl *findSpecialization(const TemplateArgument *Args, 8219eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne unsigned NumArgs, void *&InsertPos); 8229eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 8239eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne FunctionTemplateDecl *getCanonicalDecl() { 8249eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return redeclarable_base::getCanonicalDecl(); 8259eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne } 8269eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne const FunctionTemplateDecl *getCanonicalDecl() const { 8279eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return redeclarable_base::getCanonicalDecl(); 8289eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne } 8299eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 8309eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// \brief Retrieve the previous declaration of this function template, or 8319eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// NULL if no such declaration exists. 8329eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne FunctionTemplateDecl *getPreviousDeclaration() { 8339eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return redeclarable_base::getPreviousDeclaration(); 8349eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne } 8359eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 8369eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// \brief Retrieve the previous declaration of this function template, or 8379eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// NULL if no such declaration exists. 8389eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne const FunctionTemplateDecl *getPreviousDeclaration() const { 8399eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return redeclarable_base::getPreviousDeclaration(); 8409eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne } 8419eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 8429eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne FunctionTemplateDecl *getInstantiatedFromMemberTemplate() { 8439eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return redeclarable_base::getInstantiatedFromMemberTemplate(); 8449eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne } 8459eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 8469f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne typedef SpecIterator<FunctionTemplateSpecializationInfo> spec_iterator; 8479f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne 8489f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne spec_iterator spec_begin() { 8499f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne return makeSpecIterator(getSpecializations(), false); 8509f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne } 8519f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne 8529f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne spec_iterator spec_end() { 8539f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne return makeSpecIterator(getSpecializations(), true); 8549f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne } 8559f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne 856127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// Create a template function node. 857127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor static FunctionTemplateDecl *Create(ASTContext &C, DeclContext *DC, 858127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor SourceLocation L, 859127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor DeclarationName Name, 860127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateParameterList *Params, 861127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor NamedDecl *Decl); 8623e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 863127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // Implement isa/cast/dyncast support 86480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 86580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const FunctionTemplateDecl *D) { return true; } 86680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == FunctionTemplate; } 867c8f9af2943699ff623ca08f2e5ed4d72e0351189Argyrios Kyrtzidis 868d527cc06d78fe5afa5f20105b51697637eb02c56Sebastian Redl friend class ASTDeclReader; 8693397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTDeclWriter; 870127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor}; 871d01b1da213aeb71fd40ff7fb78a194613cc1ece7Anders Carlsson 872127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor//===----------------------------------------------------------------------===// 873127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor// Kinds of Template Parameters 874127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor//===----------------------------------------------------------------------===// 87540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 876127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// The TemplateParmPosition class defines the position of a template parameter 877127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// within a template parameter list. Because template parameter can be listed 878127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// sequentially for out-of-line template members, each template parameter is 879127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// given a Depth - the nesting of template parameter scopes - and a Position - 880127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// the occurrence within the parameter list. 881127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// This class is inheritedly privately by different kinds of template 882127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// parameters and is not part of the Decl hierarchy. Just a facility. 8831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass TemplateParmPosition { 884127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorprotected: 885127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // FIXME: This should probably never be called, but it's here as 886127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateParmPosition() 887127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor : Depth(0), Position(0) 888127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor { /* assert(0 && "Cannot create positionless template parameter"); */ } 8893e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 890127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateParmPosition(unsigned D, unsigned P) 891127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor : Depth(D), Position(P) 892127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor { } 8933e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 894127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // FIXME: These probably don't need to be ints. int:5 for depth, int:8 for 895127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // position? Maybe? 896127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned Depth; 897127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned Position; 8983e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 899127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorpublic: 900127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// Get the nesting depth of the template parameter. 901127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned getDepth() const { return Depth; } 902b24e199fbd17af780ab000c5862d191e4daffc0fArgyrios Kyrtzidis void setDepth(unsigned D) { Depth = D; } 9033e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 904127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// Get the position of the template parameter within its parameter list. 905127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned getPosition() const { return Position; } 906b24e199fbd17af780ab000c5862d191e4daffc0fArgyrios Kyrtzidis void setPosition(unsigned P) { Position = P; } 9071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 908127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// Get the index of the template parameter within its parameter list. 909127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned getIndex() const { return Position; } 910127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor}; 9113e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 912127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// TemplateTypeParmDecl - Declaration of a template type parameter, 913127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// e.g., "T" in 914127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// @code 915127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// template<typename T> class vector; 916127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// @endcode 917127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorclass TemplateTypeParmDecl : public TypeDecl { 918127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Whether this template type parameter was declaration with 919127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// the 'typename' keyword. If false, it was declared with the 920127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// 'class' keyword. 921127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor bool Typename : 1; 9223e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 923127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Whether this template type parameter inherited its 924127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// default argument. 925127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor bool InheritedDefault : 1; 9263e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 927efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor /// \brief Whether this is a parameter pack. 928efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor bool ParameterPack : 1; 929efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor 930127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief The default template argument, if any. 931a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *DefaultArgument; 932127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor 9331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateTypeParmDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, 934efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor bool Typename, QualType Type, bool ParameterPack) 935127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor : TypeDecl(TemplateTypeParm, DC, L, Id), Typename(Typename), 936efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor InheritedDefault(false), ParameterPack(ParameterPack), DefaultArgument() { 937efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor TypeForDecl = Type.getTypePtr(); 938efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor } 9393e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 940127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorpublic: 941127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor static TemplateTypeParmDecl *Create(ASTContext &C, DeclContext *DC, 942127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor SourceLocation L, unsigned D, unsigned P, 943127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor IdentifierInfo *Id, bool Typename, 944127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor bool ParameterPack); 945b8b03e6df1cc89e701a809c6a47c41f31b7a9e50Argyrios Kyrtzidis static TemplateTypeParmDecl *Create(ASTContext &C, EmptyShell Empty); 946c971f8694661776ecdec2ccc33fbe0333eeaf191Douglas Gregor 947127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Whether this template type parameter was declared with 948127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// the 'typename' keyword. If not, it was declared with the 'class' 949127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// keyword. 950127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor bool wasDeclaredWithTypename() const { return Typename; } 951c971f8694661776ecdec2ccc33fbe0333eeaf191Douglas Gregor 952127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Determine whether this template parameter has a default 953127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// argument. 954833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall bool hasDefaultArgument() const { return DefaultArgument != 0; } 955199d99192fbcca9f043596c40ead4afab4999dbaDouglas Gregor 956127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Retrieve the default argument, if any. 957833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall QualType getDefaultArgument() const { return DefaultArgument->getType(); } 95840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 959833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// \brief Retrieves the default argument's source information, if any. 960a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *getDefaultArgumentInfo() const { return DefaultArgument; } 961833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 962833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// \brief Retrieves the location of the default argument declaration. 963833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation getDefaultArgumentLoc() const; 96440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 965127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Determines whether the default argument was inherited 966127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// from a previous declaration of this template. 967127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor bool defaultArgumentWasInherited() const { return InheritedDefault; } 968f670c8cfa58b4c224eb8fb566130dc47844dd3deDouglas Gregor 969127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Set the default argument for this template parameter, and 970127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// whether that default argument was inherited from another 971127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// declaration. 972a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall void setDefaultArgument(TypeSourceInfo *DefArg, bool Inherited) { 973127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor DefaultArgument = DefArg; 974127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor InheritedDefault = Inherited; 975f670c8cfa58b4c224eb8fb566130dc47844dd3deDouglas Gregor } 97640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 977833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// \brief Removes the default argument of this template parameter. 978833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall void removeDefaultArgument() { 979833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall DefaultArgument = 0; 980833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall InheritedDefault = false; 981833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 9828731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis 9838731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis /// \brief Set whether this template type parameter was declared with 9848731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis /// the 'typename' or 'class' keyword. 9858731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis void setDeclaredWithTypename(bool withTypename) { Typename = withTypename; } 9868731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis 9878731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis /// \brief Set whether this is a parameter pack. 9888731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis void setParameterPack(bool isParamPack) { ParameterPack = isParamPack; } 989833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 990ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \brief Retrieve the depth of the template parameter. 991ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor unsigned getDepth() const; 992ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor 993ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \brief Retrieve the index of the template parameter. 994ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor unsigned getIndex() const; 995ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor 996127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Returns whether this is a parameter pack. 997efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor bool isParameterPack() const { return ParameterPack; } 998fb25052736439d72a557cddd41dfb927bcb3d3e5Anders Carlsson 999127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // Implement isa/cast/dyncast/etc. 100080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1001127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor static bool classof(const TemplateTypeParmDecl *D) { return true; } 100280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == TemplateTypeParm; } 10033e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor}; 10043e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 1005127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// NonTypeTemplateParmDecl - Declares a non-type template parameter, 1006127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// e.g., "Size" in 1007127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// @code 1008127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// template<int Size> class array { }; 1009127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// @endcode 1010127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorclass NonTypeTemplateParmDecl 1011127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor : public VarDecl, protected TemplateParmPosition { 1012d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara /// \brief The default template argument, if any, and whether or not 1013d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara /// it was inherited. 1014d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara llvm::PointerIntPair<Expr*, 1, bool> DefaultArgumentAndInherited; 1015127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor 1016127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor NonTypeTemplateParmDecl(DeclContext *DC, SourceLocation L, unsigned D, 1017127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned P, IdentifierInfo *Id, QualType T, 1018a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *TInfo) 1019d931b086984257de68868a64a235c2b4b34003fbJohn McCall : VarDecl(NonTypeTemplateParm, DC, L, Id, T, TInfo, SC_None, SC_None), 1020d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara TemplateParmPosition(D, P), DefaultArgumentAndInherited(0, false) 1021127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor { } 1022127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor 10231c5976e5e933c0d74f7e04e8f907a93f5edbfec1Anders Carlssonpublic: 1024127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor static NonTypeTemplateParmDecl * 1025127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor Create(ASTContext &C, DeclContext *DC, SourceLocation L, unsigned D, 1026a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall unsigned P, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo); 10279ba41645892da0000fe8a7832b80208f44dafedaAnders Carlsson 1028127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor using TemplateParmPosition::getDepth; 1029b24e199fbd17af780ab000c5862d191e4daffc0fArgyrios Kyrtzidis using TemplateParmPosition::setDepth; 1030127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor using TemplateParmPosition::getPosition; 1031b24e199fbd17af780ab000c5862d191e4daffc0fArgyrios Kyrtzidis using TemplateParmPosition::setPosition; 1032127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor using TemplateParmPosition::getIndex; 10331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1034127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Determine whether this template parameter has a default 1035127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// argument. 1036d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara bool hasDefaultArgument() const { 1037d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara return DefaultArgumentAndInherited.getPointer() != 0; 1038d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara } 1039fb25052736439d72a557cddd41dfb927bcb3d3e5Anders Carlsson 1040127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Retrieve the default argument, if any. 1041d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara Expr *getDefaultArgument() const { 1042d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara return DefaultArgumentAndInherited.getPointer(); 1043d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara } 1044127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor 1045127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Retrieve the location of the default argument, if any. 1046127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor SourceLocation getDefaultArgumentLoc() const; 1047127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor 1048d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara /// \brief Determines whether the default argument was inherited 1049d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara /// from a previous declaration of this template. 1050d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara bool defaultArgumentWasInherited() const { 1051d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara return DefaultArgumentAndInherited.getInt(); 1052d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara } 1053d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara 1054d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara /// \brief Set the default argument for this template parameter, and 1055d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara /// whether that default argument was inherited from another 1056d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara /// declaration. 1057d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara void setDefaultArgument(Expr *DefArg, bool Inherited) { 1058d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara DefaultArgumentAndInherited.setPointer(DefArg); 1059d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara DefaultArgumentAndInherited.setInt(Inherited); 1060d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara } 1061d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara 1062d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara /// \brief Removes the default argument of this template parameter. 1063d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara void removeDefaultArgument() { 1064d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara DefaultArgumentAndInherited.setPointer(0); 1065d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara DefaultArgumentAndInherited.setInt(false); 10663b36b66a00b7d5bab71b486a54694f0ae397bddbAnders Carlsson } 1067127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor 1068127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // Implement isa/cast/dyncast/etc. 106980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1070127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor static bool classof(const NonTypeTemplateParmDecl *D) { return true; } 107180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == NonTypeTemplateParm; } 10721c5976e5e933c0d74f7e04e8f907a93f5edbfec1Anders Carlsson}; 10731c5976e5e933c0d74f7e04e8f907a93f5edbfec1Anders Carlsson 1074127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// TemplateTemplateParmDecl - Declares a template template parameter, 1075127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// e.g., "T" in 1076127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// @code 1077127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// template <template <typename> class T> class container { }; 1078127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// @endcode 1079127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// A template template parameter is a TemplateDecl because it defines the 1080127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor/// name of a template and the template parameters allowable for substitution. 1081127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorclass TemplateTemplateParmDecl 1082127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor : public TemplateDecl, protected TemplateParmPosition { 10837e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor 1084d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara /// DefaultArgument - The default template argument, if any. 1085788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor TemplateArgumentLoc DefaultArgument; 1086d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara /// Whether or not the default argument was inherited. 1087d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara bool DefaultArgumentWasInherited; 10887e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor 1089127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateTemplateParmDecl(DeclContext *DC, SourceLocation L, 1090127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned D, unsigned P, 1091127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor IdentifierInfo *Id, TemplateParameterList *Params) 1092127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor : TemplateDecl(TemplateTemplateParm, DC, L, Id, Params), 1093d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara TemplateParmPosition(D, P), DefaultArgument(), 1094d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara DefaultArgumentWasInherited(false) 1095127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor { } 10967e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor 1097127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregorpublic: 1098127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor static TemplateTemplateParmDecl *Create(ASTContext &C, DeclContext *DC, 1099127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor SourceLocation L, unsigned D, 1100127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor unsigned P, IdentifierInfo *Id, 1101127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor TemplateParameterList *Params); 11027e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor 1103127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor using TemplateParmPosition::getDepth; 1104127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor using TemplateParmPosition::getPosition; 1105127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor using TemplateParmPosition::getIndex; 11061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1107127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Determine whether this template parameter has a default 1108127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// argument. 1109d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara bool hasDefaultArgument() const { 1110d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara return !DefaultArgument.getArgument().isNull(); 1111788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor } 11127e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor 1113127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor /// \brief Retrieve the default argument, if any. 1114d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara const TemplateArgumentLoc &getDefaultArgument() const { 1115d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara return DefaultArgument; 1116d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara } 1117d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara 1118d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara /// \brief Retrieve the location of the default argument, if any. 1119d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara SourceLocation getDefaultArgumentLoc() const; 1120d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara 1121d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara /// \brief Determines whether the default argument was inherited 1122d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara /// from a previous declaration of this template. 1123d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara bool defaultArgumentWasInherited() const { 1124d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara return DefaultArgumentWasInherited; 1125788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor } 11267e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor 1127d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara /// \brief Set the default argument for this template parameter, and 1128d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara /// whether that default argument was inherited from another 1129d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara /// declaration. 1130d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara void setDefaultArgument(const TemplateArgumentLoc &DefArg, bool Inherited) { 1131127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor DefaultArgument = DefArg; 1132d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara DefaultArgumentWasInherited = Inherited; 1133d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara } 1134d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara 1135d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara /// \brief Removes the default argument of this template parameter. 1136d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara void removeDefaultArgument() { 1137d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara DefaultArgument = TemplateArgumentLoc(); 1138d92f7a297c0ed3f7d0ebcbb557e1d4c1925b8c72Abramo Bagnara DefaultArgumentWasInherited = false; 1139127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor } 11407e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor 1141fe72e9ceeae6cc8669cd8bb722425300190638eaDouglas Gregor SourceRange getSourceRange() const { 1142fe72e9ceeae6cc8669cd8bb722425300190638eaDouglas Gregor SourceLocation End = getLocation(); 1143fe72e9ceeae6cc8669cd8bb722425300190638eaDouglas Gregor if (hasDefaultArgument() && !defaultArgumentWasInherited()) 1144fe72e9ceeae6cc8669cd8bb722425300190638eaDouglas Gregor End = getDefaultArgument().getSourceRange().getEnd(); 1145fe72e9ceeae6cc8669cd8bb722425300190638eaDouglas Gregor return SourceRange(getTemplateParameters()->getTemplateLoc(), End); 1146fe72e9ceeae6cc8669cd8bb722425300190638eaDouglas Gregor } 1147fe72e9ceeae6cc8669cd8bb722425300190638eaDouglas Gregor 1148127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // Implement isa/cast/dyncast/etc. 114980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1150127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor static bool classof(const TemplateTemplateParmDecl *D) { return true; } 115180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == TemplateTemplateParm; } 1152bfcc92c3476ada55ceeea49e43e6d2e083252830Argyrios Kyrtzidis 1153d527cc06d78fe5afa5f20105b51697637eb02c56Sebastian Redl friend class ASTDeclReader; 11543397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTDeclWriter; 11557e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor}; 11567e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor 11573e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor/// \brief Represents a class template specialization, which refers to 11583e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor/// a class template with a given set of template arguments. 11593e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor/// 11603e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor/// Class template specializations represent both explicit 11613e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor/// specialization of class templates, as in the example below, and 11623e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor/// implicit instantiations of class templates. 11633e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor/// 11643e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor/// \code 11653e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor/// template<typename T> class array; 11661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 11671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<> 11683e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor/// class array<bool> { }; // class template specialization array<bool> 11693e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor/// \endcode 11701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ClassTemplateSpecializationDecl 11713e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor : public CXXRecordDecl, public llvm::FoldingSetNode { 11721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Structure that stores information about a class template 117437d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// specialization that was instantiated from a class template partial 117537d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// specialization. 117637d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor struct SpecializedPartialSpecialization { 117737d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// \brief The class template partial specialization from which this 117837d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// class template specialization was instantiated. 117937d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor ClassTemplatePartialSpecializationDecl *PartialSpecialization; 11801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 118137d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// \brief The template argument list deduced for the class template 118237d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// partial specialization itself. 118337d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor TemplateArgumentList *TemplateArgs; 118437d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor }; 11851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11863e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor /// \brief The template that this specialization specializes 118737d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor llvm::PointerUnion<ClassTemplateDecl *, SpecializedPartialSpecialization *> 118837d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor SpecializedTemplate; 11893e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 1190c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara /// \brief Further info for explicit template specialization/instantiation. 1191c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara struct ExplicitSpecializationInfo { 1192c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara /// \brief The type-as-written. 1193c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara TypeSourceInfo *TypeAsWritten; 1194c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara /// \brief The location of the extern keyword. 1195c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara SourceLocation ExternLoc; 1196c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara /// \brief The location of the template keyword. 1197c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara SourceLocation TemplateKeywordLoc; 1198c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara 1199c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara ExplicitSpecializationInfo() 1200c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara : TypeAsWritten(0), ExternLoc(), TemplateKeywordLoc() {} 1201c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara }; 1202c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara 1203c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara /// \brief Further info for explicit template specialization/instantiation. 12043cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall /// Does not apply to implicit specializations. 1205c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara ExplicitSpecializationInfo *ExplicitInfo; 12063cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 12077e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor /// \brief The template arguments used to describe this specialization. 12087e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor TemplateArgumentList TemplateArgs; 1209cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 12109cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall /// \brief The point where this template was instantiated (if any) 12119cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall SourceLocation PointOfInstantiation; 12129cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall 1213cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor /// \brief The kind of specialization this declaration refers to. 1214cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor /// Really a value of type TemplateSpecializationKind. 1215d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor unsigned SpecializationKind : 3; 1216cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 1217c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregorprotected: 121813c8577201e4fc0ddac5f09d05fd1778832137d1Douglas Gregor ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK, 12197e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor DeclContext *DC, SourceLocation L, 12203e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor ClassTemplateDecl *SpecializedTemplate, 12218e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor TemplateArgumentListBuilder &Builder, 12228e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor ClassTemplateSpecializationDecl *PrevDecl); 12231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 122494d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis explicit ClassTemplateSpecializationDecl(Kind DK); 122594d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis 12263e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregorpublic: 12273e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor static ClassTemplateSpecializationDecl * 122813c8577201e4fc0ddac5f09d05fd1778832137d1Douglas Gregor Create(ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation L, 12293e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor ClassTemplateDecl *SpecializedTemplate, 123091fdf6f576b91f023c3bebb0d3786aab555cb3c5Anders Carlsson TemplateArgumentListBuilder &Builder, 1231cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor ClassTemplateSpecializationDecl *PrevDecl); 1232b8b03e6df1cc89e701a809c6a47c41f31b7a9e50Argyrios Kyrtzidis static ClassTemplateSpecializationDecl * 1233b8b03e6df1cc89e701a809c6a47c41f31b7a9e50Argyrios Kyrtzidis Create(ASTContext &Context, EmptyShell Empty); 123494d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis 1235136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall virtual void getNameForDiagnostic(std::string &S, 1236136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall const PrintingPolicy &Policy, 1237136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall bool Qualified) const; 1238136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall 1239cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis ClassTemplateSpecializationDecl *getMostRecentDeclaration() { 1240cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis CXXRecordDecl *Recent 1241cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis = cast<CXXRecordDecl>(CXXRecordDecl::getMostRecentDeclaration()); 1242cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis if (!isa<ClassTemplateSpecializationDecl>(Recent)) { 1243cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis // FIXME: Does injected class name need to be in the redeclarations chain? 1244cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis assert(Recent->isInjectedClassName() && Recent->getPreviousDeclaration()); 1245cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis Recent = Recent->getPreviousDeclaration(); 1246cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis } 1247cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis return cast<ClassTemplateSpecializationDecl>(Recent); 1248cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis } 1249cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis 12503e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor /// \brief Retrieve the template that this specialization specializes. 125137d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor ClassTemplateDecl *getSpecializedTemplate() const; 12523e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 12531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the template arguments of the class template 125437d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// specialization. 12551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const TemplateArgumentList &getTemplateArgs() const { 12567e06390f8a60440d6fc5f0e633acdc2edd8ee924Douglas Gregor return TemplateArgs; 12573e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor } 12583e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 125994d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis /// \brief Initialize the template arguments of the class template 126094d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis /// specialization. 126194d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis void initTemplateArgs(TemplateArgument *Args, unsigned NumArgs) { 126294d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis assert(TemplateArgs.flat_size() == 0 && 126394d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis "Template arguments already initialized!"); 126494d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis TemplateArgs.init(getASTContext(), Args, NumArgs); 126594d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis } 126694d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis 1267cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor /// \brief Determine the kind of specialization that this 1268cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor /// declaration represents. 1269cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor TemplateSpecializationKind getSpecializationKind() const { 1270cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor return static_cast<TemplateSpecializationKind>(SpecializationKind); 1271cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor } 1272cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 1273cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor void setSpecializationKind(TemplateSpecializationKind TSK) { 1274cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor SpecializationKind = TSK; 1275cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor } 1276cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 12779cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall /// \brief Get the point of instantiation (if any), or null if none. 12789cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall SourceLocation getPointOfInstantiation() const { 12799cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall return PointOfInstantiation; 12809cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall } 12819cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall 12829cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall void setPointOfInstantiation(SourceLocation Loc) { 12839cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall assert(Loc.isValid() && "point of instantiation must be valid!"); 12849cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall PointOfInstantiation = Loc; 12859cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall } 12869cc7807e1622c2f945b607bdd39dd283df5e7bb5John McCall 128737d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// \brief If this class template specialization is an instantiation of 128837d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// a template (rather than an explicit specialization), return the 128937d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// class template or class template partial specialization from which it 129037d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// was instantiated. 12911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump llvm::PointerUnion<ClassTemplateDecl *, 129237d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor ClassTemplatePartialSpecializationDecl *> 129337d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor getInstantiatedFrom() const { 129437d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor if (getSpecializationKind() != TSK_ImplicitInstantiation && 1295d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor getSpecializationKind() != TSK_ExplicitInstantiationDefinition && 1296d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor getSpecializationKind() != TSK_ExplicitInstantiationDeclaration) 129737d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor return (ClassTemplateDecl*)0; 12981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (SpecializedPartialSpecialization *PartialSpec 130037d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>()) 130137d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor return PartialSpec->PartialSpecialization; 13021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 130337d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor return const_cast<ClassTemplateDecl*>( 130437d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor SpecializedTemplate.get<ClassTemplateDecl*>()); 130537d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor } 13061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 130794d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis /// \brief Retrieve the class template or class template partial 130894d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis /// specialization which was specialized by this. 130994d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis llvm::PointerUnion<ClassTemplateDecl *, 131094d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis ClassTemplatePartialSpecializationDecl *> 131194d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis getSpecializedTemplateOrPartial() const { 131294d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis if (SpecializedPartialSpecialization *PartialSpec 131394d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>()) 131494d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis return PartialSpec->PartialSpecialization; 131594d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis 131694d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis return const_cast<ClassTemplateDecl*>( 131794d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis SpecializedTemplate.get<ClassTemplateDecl*>()); 131894d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis } 131994d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis 132037d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// \brief Retrieve the set of template arguments that should be used 132137d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// to instantiate members of the class template or class template partial 132237d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// specialization from which this class template specialization was 132337d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// instantiated. 132437d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// 132537d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// \returns For a class template specialization instantiated from the primary 132637d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// template, this function will return the same template arguments as 132737d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// getTemplateArgs(). For a class template specialization instantiated from 132837d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// a class template partial specialization, this function will return the 132937d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// deduced template arguments for the class template partial specialization 133037d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// itself. 133137d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor const TemplateArgumentList &getTemplateInstantiationArgs() const { 13321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (SpecializedPartialSpecialization *PartialSpec 133337d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>()) 133437d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor return *PartialSpec->TemplateArgs; 13351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 133637d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor return getTemplateArgs(); 133737d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor } 13381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 133937d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// \brief Note that this class template specialization is actually an 134037d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// instantiation of the given class template partial specialization whose 134137d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor /// template arguments have been deduced. 134237d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, 134337d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor TemplateArgumentList *TemplateArgs) { 134494d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis assert(!SpecializedTemplate.is<SpecializedPartialSpecialization*>() && 134594d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis "Already set to a class template partial specialization!"); 13461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SpecializedPartialSpecialization *PS 134737d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor = new (getASTContext()) SpecializedPartialSpecialization(); 134837d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor PS->PartialSpecialization = PartialSpec; 134937d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor PS->TemplateArgs = TemplateArgs; 135037d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor SpecializedTemplate = PS; 135137d93e9252026d4fb836d9c05d0122a2d46e56beDouglas Gregor } 13521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 135394d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis /// \brief Note that this class template specialization is actually an 135494d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis /// instantiation of the given class template partial specialization whose 135594d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis /// template arguments have been deduced. 135694d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, 135794d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis TemplateArgument *TemplateArgs, 135894d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis unsigned NumTemplateArgs) { 135994d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis ASTContext &Ctx = getASTContext(); 136094d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis setInstantiationOf(PartialSpec, 136194d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis new (Ctx) TemplateArgumentList(Ctx, TemplateArgs, 136294d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis NumTemplateArgs)); 136394d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis } 136494d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis 136594d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis /// \brief Note that this class template specialization is an instantiation 136694d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis /// of the given class template. 136794d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis void setInstantiationOf(ClassTemplateDecl *TemplDecl) { 136894d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis assert(!SpecializedTemplate.is<SpecializedPartialSpecialization*>() && 136994d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis "Previously set to a class template partial specialization!"); 137094d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis SpecializedTemplate = TemplDecl; 137194d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis } 137294d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis 1373fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor /// \brief Sets the type of this specialization as it was written by 1374fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor /// the user. This will be a class template specialization type. 13753cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall void setTypeAsWritten(TypeSourceInfo *T) { 1376db1423008b6185fc570558cff77d92f94e55b386Ted Kremenek if (!ExplicitInfo) 1377db1423008b6185fc570558cff77d92f94e55b386Ted Kremenek ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo; 1378c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara ExplicitInfo->TypeAsWritten = T; 13793cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall } 13803cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall /// \brief Gets the type of this specialization as it was written by 13813cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall /// the user, if it was so written. 13823cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TypeSourceInfo *getTypeAsWritten() const { 1383c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara return ExplicitInfo ? ExplicitInfo->TypeAsWritten : 0; 1384c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara } 1385c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara 1386c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara /// \brief Gets the location of the extern keyword, if present. 1387c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara SourceLocation getExternLoc() const { 1388c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara return ExplicitInfo ? ExplicitInfo->ExternLoc : SourceLocation(); 1389c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara } 1390c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara /// \brief Sets the location of the extern keyword. 1391c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara void setExternLoc(SourceLocation Loc) { 1392db1423008b6185fc570558cff77d92f94e55b386Ted Kremenek if (!ExplicitInfo) 1393db1423008b6185fc570558cff77d92f94e55b386Ted Kremenek ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo; 1394c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara ExplicitInfo->ExternLoc = Loc; 1395c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara } 1396c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara 1397c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara /// \brief Sets the location of the template keyword. 1398c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara void setTemplateKeywordLoc(SourceLocation Loc) { 1399db1423008b6185fc570558cff77d92f94e55b386Ted Kremenek if (!ExplicitInfo) 1400db1423008b6185fc570558cff77d92f94e55b386Ted Kremenek ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo; 1401c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara ExplicitInfo->TemplateKeywordLoc = Loc; 1402c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara } 1403c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara /// \brief Gets the location of the template keyword, if present. 1404c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara SourceLocation getTemplateKeywordLoc() const { 1405c98971d5c994caed9452aeadd0122c855e0f4de1Abramo Bagnara return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation(); 1406fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor } 1407fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor 14081693e154bef16ca060b5e3786d8528ddc11f5637Douglas Gregor SourceLocation getInnerLocStart() const { return getTemplateKeywordLoc(); } 14091693e154bef16ca060b5e3786d8528ddc11f5637Douglas Gregor 1410c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) const { 1411828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor Profile(ID, TemplateArgs.getFlatArgumentList(), TemplateArgs.flat_size(), 1412828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor getASTContext()); 1413c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor } 1414c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor 14151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void 14161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Profile(llvm::FoldingSetNodeID &ID, const TemplateArgument *TemplateArgs, 1417828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor unsigned NumTemplateArgs, ASTContext &Context) { 14180ceffb51b28b09db67404058c642dcb1f877f6e8Anders Carlsson ID.AddInteger(NumTemplateArgs); 14193e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor for (unsigned Arg = 0; Arg != NumTemplateArgs; ++Arg) 1420828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor TemplateArgs[Arg].Profile(ID, Context); 14213e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor } 14223e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 142380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 142480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { 14259a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt return K >= firstClassTemplateSpecialization && 14269a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt K <= lastClassTemplateSpecialization; 14273e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor } 14283e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 14293e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor static bool classof(const ClassTemplateSpecializationDecl *) { 14303e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor return true; 14313e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor } 1432c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor 1433c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor static bool classof(const ClassTemplatePartialSpecializationDecl *) { 1434c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor return true; 1435c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor } 1436c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor}; 1437c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor 14381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ClassTemplatePartialSpecializationDecl 14391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : public ClassTemplateSpecializationDecl { 14401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief The list of template parameters 1441c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor TemplateParameterList* TemplateParams; 1442c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor 1443833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// \brief The source info for the template arguments as written. 14443cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall /// FIXME: redundant with TypeAsWritten? 1445833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc *ArgsAsWritten; 1446833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall unsigned NumArgsAsWritten; 1447833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1448dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor /// \brief Sequence number indicating when this class template partial 1449dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor /// specialization was added to the set of partial specializations for 1450dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor /// its owning class template. 1451dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor unsigned SequenceNumber; 1452dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor 1453ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \brief The class template partial specialization from which this 1454ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// class template partial specialization was instantiated. 1455ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// 1456ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// The boolean value will be true to indicate that this class template 1457ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// partial specialization was specialized at this level. 1458ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor llvm::PointerIntPair<ClassTemplatePartialSpecializationDecl *, 1, bool> 1459ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor InstantiatedFromMember; 1460ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor 146113c8577201e4fc0ddac5f09d05fd1778832137d1Douglas Gregor ClassTemplatePartialSpecializationDecl(ASTContext &Context, TagKind TK, 1462c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor DeclContext *DC, SourceLocation L, 1463c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor TemplateParameterList *Params, 1464c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor ClassTemplateDecl *SpecializedTemplate, 14658e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor TemplateArgumentListBuilder &Builder, 1466833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc *ArgInfos, 1467833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall unsigned NumArgInfos, 1468dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor ClassTemplatePartialSpecializationDecl *PrevDecl, 1469dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor unsigned SequenceNumber) 14701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : ClassTemplateSpecializationDecl(Context, 14718e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor ClassTemplatePartialSpecialization, 147213c8577201e4fc0ddac5f09d05fd1778832137d1Douglas Gregor TK, DC, L, SpecializedTemplate, Builder, 14738e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor PrevDecl), 1474833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateParams(Params), ArgsAsWritten(ArgInfos), 1475dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor NumArgsAsWritten(NumArgInfos), SequenceNumber(SequenceNumber), 1476dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor InstantiatedFromMember(0, false) { } 147794d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis 147894d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis ClassTemplatePartialSpecializationDecl() 147994d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis : ClassTemplateSpecializationDecl(ClassTemplatePartialSpecialization), 148094d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis TemplateParams(0), ArgsAsWritten(0), 148194d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis NumArgsAsWritten(0), SequenceNumber(0), 148294d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis InstantiatedFromMember(0, false) { } 1483c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor 1484c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregorpublic: 1485c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor static ClassTemplatePartialSpecializationDecl * 148613c8577201e4fc0ddac5f09d05fd1778832137d1Douglas Gregor Create(ASTContext &Context, TagKind TK,DeclContext *DC, SourceLocation L, 1487c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor TemplateParameterList *Params, 1488c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor ClassTemplateDecl *SpecializedTemplate, 148991fdf6f576b91f023c3bebb0d3786aab555cb3c5Anders Carlsson TemplateArgumentListBuilder &Builder, 1490d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo &ArgInfos, 14913cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall QualType CanonInjectedType, 1492dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor ClassTemplatePartialSpecializationDecl *PrevDecl, 1493dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor unsigned SequenceNumber); 1494c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor 149594d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis static ClassTemplatePartialSpecializationDecl * 1496b8b03e6df1cc89e701a809c6a47c41f31b7a9e50Argyrios Kyrtzidis Create(ASTContext &Context, EmptyShell Empty); 149794d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis 1498cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis ClassTemplatePartialSpecializationDecl *getMostRecentDeclaration() { 1499cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis return cast<ClassTemplatePartialSpecializationDecl>( 1500cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis ClassTemplateSpecializationDecl::getMostRecentDeclaration()); 1501cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis } 1502cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis 1503c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor /// Get the list of template parameters 1504c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor TemplateParameterList *getTemplateParameters() const { 1505c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor return TemplateParams; 1506c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor } 1507c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor 150894d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis void initTemplateParameters(TemplateParameterList *Params) { 150994d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis assert(TemplateParams == 0 && "TemplateParams already set"); 151094d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis TemplateParams = Params; 151194d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis } 151294d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis 1513833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// Get the template arguments as written. 1514833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc *getTemplateArgsAsWritten() const { 1515833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return ArgsAsWritten; 1516833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 1517833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 151894d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis void initTemplateArgsAsWritten(const TemplateArgumentListInfo &ArgInfos); 151994d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis 1520833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// Get the number of template arguments as written. 1521833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall unsigned getNumTemplateArgsAsWritten() const { 1522833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return NumArgsAsWritten; 1523833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 1524833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1525dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor /// \brief Get the sequence number for this class template partial 1526dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor /// specialization. 1527dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor unsigned getSequenceNumber() const { return SequenceNumber; } 152894d228d3454a3f6436526d15b2ad7fc90246fe54Argyrios Kyrtzidis void setSequenceNumber(unsigned N) { SequenceNumber = N; } 1529dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor 1530ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \brief Retrieve the member class template partial specialization from 1531ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// which this particular class template partial specialization was 1532ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// instantiated. 1533ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// 1534ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \code 1535ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// template<typename T> 1536ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// struct Outer { 1537ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// template<typename U> struct Inner; 1538ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// template<typename U> struct Inner<U*> { }; // #1 1539ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// }; 1540ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// 1541ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// Outer<float>::Inner<int*> ii; 1542ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \endcode 1543ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// 1544ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// In this example, the instantiation of \c Outer<float>::Inner<int*> will 1545ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// end up instantiating the partial specialization 1546ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \c Outer<float>::Inner<U*>, which itself was instantiated from the class 1547ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// template partial specialization \c Outer<T>::Inner<U*>. Given 1548ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \c Outer<float>::Inner<U*>, this function would return 1549ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \c Outer<T>::Inner<U*>. 1550ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor ClassTemplatePartialSpecializationDecl *getInstantiatedFromMember() { 1551ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor ClassTemplatePartialSpecializationDecl *First 1552ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor = cast<ClassTemplatePartialSpecializationDecl>(getFirstDeclaration()); 1553ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor return First->InstantiatedFromMember.getPointer(); 1554ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor } 1555ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor 1556ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor void setInstantiatedFromMember( 1557ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor ClassTemplatePartialSpecializationDecl *PartialSpec) { 1558ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor ClassTemplatePartialSpecializationDecl *First 1559ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor = cast<ClassTemplatePartialSpecializationDecl>(getFirstDeclaration()); 1560ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor First->InstantiatedFromMember.setPointer(PartialSpec); 1561ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor } 1562ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor 1563ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \brief Determines whether this class template partial specialization 1564ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// template was a specialization of a member partial specialization. 1565ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// 1566ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// In the following example, the member template partial specialization 1567ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \c X<int>::Inner<T*> is a member specialization. 1568ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// 1569ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \code 1570ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// template<typename T> 1571ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// struct X { 1572ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// template<typename U> struct Inner; 1573ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// template<typename U> struct Inner<U*>; 1574ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// }; 1575ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// 1576ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// template<> template<typename T> 1577ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// struct X<int>::Inner<T*> { /* ... */ }; 1578ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \endcode 1579ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor bool isMemberSpecialization() { 1580ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor ClassTemplatePartialSpecializationDecl *First 1581ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor = cast<ClassTemplatePartialSpecializationDecl>(getFirstDeclaration()); 1582ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor return First->InstantiatedFromMember.getInt(); 1583ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor } 1584ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor 1585ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor /// \brief Note that this member template is a specialization. 1586ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor void setMemberSpecialization() { 1587ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor ClassTemplatePartialSpecializationDecl *First 1588ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor = cast<ClassTemplatePartialSpecializationDecl>(getFirstDeclaration()); 1589ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor assert(First->InstantiatedFromMember.getPointer() && 1590ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor "Only member templates can be member template specializations"); 1591ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor return First->InstantiatedFromMember.setInt(true); 1592ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor } 159331f17ecbef57b5679c017c375db330546b7b5145John McCall 159431f17ecbef57b5679c017c375db330546b7b5145John McCall /// Retrieves the injected specialization type for this partial 159531f17ecbef57b5679c017c375db330546b7b5145John McCall /// specialization. This is not the same as the type-decl-type for 159631f17ecbef57b5679c017c375db330546b7b5145John McCall /// this partial specialization, which is an InjectedClassNameType. 159731f17ecbef57b5679c017c375db330546b7b5145John McCall QualType getInjectedSpecializationType() const { 159831f17ecbef57b5679c017c375db330546b7b5145John McCall assert(getTypeForDecl() && "partial specialization has no type set!"); 159931f17ecbef57b5679c017c375db330546b7b5145John McCall return cast<InjectedClassNameType>(getTypeForDecl()) 160031f17ecbef57b5679c017c375db330546b7b5145John McCall ->getInjectedSpecializationType(); 160131f17ecbef57b5679c017c375db330546b7b5145John McCall } 1602ed9c0f90b7e0811c209b95e39fe07c211c531285Douglas Gregor 1603c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor // FIXME: Add Profile support! 1604c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor 160580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 160680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { 160780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return K == ClassTemplatePartialSpecialization; 1608c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor } 1609c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor 1610c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor static bool classof(const ClassTemplatePartialSpecializationDecl *) { 1611c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor return true; 1612c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor } 16133e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor}; 16143e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 16153e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor/// Declaration of a class template. 16169eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourneclass ClassTemplateDecl : public RedeclarableTemplateDecl, 16179eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne public RedeclarableTemplate<ClassTemplateDecl> { 16180054531488928a424666ac11fcdc6bcc5112de52Douglas Gregor static void DeallocateCommon(void *Ptr); 16190054531488928a424666ac11fcdc6bcc5112de52Douglas Gregor 16203e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregorprotected: 16219eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne typedef RedeclarableTemplate<ClassTemplateDecl> redeclarable_base; 16229eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 16235953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor /// \brief Data that is common to all of the declarations of a given 16245953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor /// class template. 16259eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne struct Common : CommonBase { 16265953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor /// \brief The class template specializations for this class 16275953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor /// template, including explicit specializations and instantiations. 16285953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor llvm::FoldingSet<ClassTemplateSpecializationDecl> Specializations; 16297da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor 1630c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor /// \brief The class template partial specializations for this class 1631c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor /// template. 16321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump llvm::FoldingSet<ClassTemplatePartialSpecializationDecl> 1633c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor PartialSpecializations; 1634c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor 16357da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// \brief The injected-class-name type for this class template. 16367da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor QualType InjectedClassNameType; 16375953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor }; 16385953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor 1639cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis /// \brief Retrieve the set of specializations of this class template. 1640cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis llvm::FoldingSet<ClassTemplateSpecializationDecl> &getSpecializations() { 1641cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis return getCommonPtr()->Specializations; 1642cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis } 1643cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis 1644cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis /// \brief Retrieve the set of partial specializations of this class 1645cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis /// template. 1646cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis llvm::FoldingSet<ClassTemplatePartialSpecializationDecl> & 1647cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis getPartialSpecializations() { 1648cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis return getCommonPtr()->PartialSpecializations; 1649cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis } 1650cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis 16513e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor ClassTemplateDecl(DeclContext *DC, SourceLocation L, DeclarationName Name, 16528731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis TemplateParameterList *Params, NamedDecl *Decl) 16539eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne : RedeclarableTemplateDecl(ClassTemplate, DC, L, Name, Params, Decl) { } 16549eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 16559eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne CommonBase *newCommon(); 16569eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 16579eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne Common *getCommonPtr() { 16589eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr()); 16599eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne } 16603e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 16613e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregorpublic: 16623e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor /// Get the underlying class declarations of the template. 16633e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor CXXRecordDecl *getTemplatedDecl() const { 16643e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor return static_cast<CXXRecordDecl *>(TemplatedDecl); 16653e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor } 16663e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 16675953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor /// Create a class template node. 16683e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor static ClassTemplateDecl *Create(ASTContext &C, DeclContext *DC, 16693e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor SourceLocation L, 16703e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor DeclarationName Name, 16713e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor TemplateParameterList *Params, 16725953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor NamedDecl *Decl, 16735953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor ClassTemplateDecl *PrevDecl); 16743e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 1675cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis /// \brief Return the specialization with the provided arguments if it exists, 1676cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis /// otherwise return the insertion point. 1677cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis ClassTemplateSpecializationDecl * 1678cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis findSpecialization(const TemplateArgument *Args, unsigned NumArgs, 1679cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis void *&InsertPos); 1680cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis 1681cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis /// \brief Insert the specified specialization knowing that it is not already 1682cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis /// in. InsertPos must be obtained from findSpecialization. 1683cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos) { 1684cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis getSpecializations().InsertNode(D, InsertPos); 16853e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor } 16863e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 16879eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne ClassTemplateDecl *getCanonicalDecl() { 16889eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return redeclarable_base::getCanonicalDecl(); 16899eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne } 16909eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne const ClassTemplateDecl *getCanonicalDecl() const { 16919eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return redeclarable_base::getCanonicalDecl(); 16929eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne } 16939eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 16949eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// \brief Retrieve the previous declaration of this class template, or 16959eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// NULL if no such declaration exists. 16969eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne ClassTemplateDecl *getPreviousDeclaration() { 16979eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return redeclarable_base::getPreviousDeclaration(); 16989eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne } 16999eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 17009eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// \brief Retrieve the previous declaration of this class template, or 17019eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne /// NULL if no such declaration exists. 17029eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne const ClassTemplateDecl *getPreviousDeclaration() const { 17039eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return redeclarable_base::getPreviousDeclaration(); 17049eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne } 17059eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 17069eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne ClassTemplateDecl *getInstantiatedFromMemberTemplate() { 17079eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne return redeclarable_base::getInstantiatedFromMemberTemplate(); 17089eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne } 17099eabebafc165a67812eacc184806e7bf34c5f0a5Peter Collingbourne 1710cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis /// \brief Return the partial specialization with the provided arguments if it 1711cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis /// exists, otherwise return the insertion point. 1712cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis ClassTemplatePartialSpecializationDecl * 1713cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis findPartialSpecialization(const TemplateArgument *Args, unsigned NumArgs, 1714cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis void *&InsertPos); 1715cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis 1716cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis /// \brief Insert the specified partial specialization knowing that it is not 1717cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis /// already in. InsertPos must be obtained from findPartialSpecialization. 1718cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis void AddPartialSpecialization(ClassTemplatePartialSpecializationDecl *D, 1719cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis void *InsertPos) { 1720cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis getPartialSpecializations().InsertNode(D, InsertPos); 1721cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis } 1722cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis 1723cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis /// \brief Return the next partial specialization sequence number. 1724cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis unsigned getNextPartialSpecSequenceNumber() { 1725cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis return getPartialSpecializations().size(); 1726c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor } 1727c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003Douglas Gregor 1728dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor /// \brief Retrieve the partial specializations as an ordered list. 1729dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor void getPartialSpecializations( 1730dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor llvm::SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS); 1731dc60c1eb4acbde6edcec9760de92f9098593d915Douglas Gregor 1732b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor /// \brief Find a class template partial specialization with the given 1733b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor /// type T. 1734b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor /// 1735cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis /// \param T a dependent type that names a specialization of this class 1736b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor /// template. 1737b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor /// 1738b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor /// \returns the class template partial specialization that exactly matches 1739b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor /// the type \p T, or NULL if no such partial specialization exists. 1740b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor ClassTemplatePartialSpecializationDecl *findPartialSpecialization(QualType T); 1741cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis 1742cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis /// \brief Find a class template partial specialization which was instantiated 1743cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis /// from the given member partial specialization. 1744cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis /// 1745cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis /// \param D a member class template partial specialization. 1746cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis /// 1747cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis /// \returns the class template partial specialization which was instantiated 1748cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis /// from the given member partial specialization, or NULL if no such partial 1749cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis /// specialization exists. 1750cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis ClassTemplatePartialSpecializationDecl * 1751cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis findPartialSpecInstantiatedFromMember( 1752cc0b1bc979b650a8a8b34b2032a074fd7724a90dArgyrios Kyrtzidis ClassTemplatePartialSpecializationDecl *D); 17531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17543cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall /// \brief Retrieve the template specialization type of the 17553cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall /// injected-class-name for this class template. 17567da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// 17577da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// The injected-class-name for a class template \c X is \c 17587da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// X<template-args>, where \c template-args is formed from the 17597da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// template arguments that correspond to the template parameters of 17607da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// \c X. For example: 17617da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// 17627da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// \code 17637da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// template<typename T, int N> 17647da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// struct array { 17657da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// typedef array this_type; // "array" is equivalent to "array<T, N>" 17667da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// }; 17677da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor /// \endcode 176824bae92f08ae098cc50a602d8cf1273b423e14daDouglas Gregor QualType getInjectedClassNameSpecialization(); 17697da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor 17709f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne typedef SpecIterator<ClassTemplateSpecializationDecl> spec_iterator; 17719f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne 17729f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne spec_iterator spec_begin() { 17739f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne return makeSpecIterator(getSpecializations(), false); 17749f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne } 17759f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne 17769f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne spec_iterator spec_end() { 17779f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne return makeSpecIterator(getSpecializations(), true); 17789f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne } 17799f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne 17809f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne typedef SpecIterator<ClassTemplatePartialSpecializationDecl> 17819f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne partial_spec_iterator; 17829f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne 17839f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne partial_spec_iterator partial_spec_begin() { 17849f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne return makeSpecIterator(getPartialSpecializations(), false); 17859f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne } 17869f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne 17879f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne partial_spec_iterator partial_spec_end() { 17889f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne return makeSpecIterator(getPartialSpecializations(), true); 17899f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne } 17909f339ba5b00256588d0d78786fff6d48ef073015Peter Collingbourne 17913e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor // Implement isa/cast/dyncast support 179280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 179380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const ClassTemplateDecl *D) { return true; } 179480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == ClassTemplate; } 17955953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor 1796d527cc06d78fe5afa5f20105b51697637eb02c56Sebastian Redl friend class ASTDeclReader; 17973397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTDeclWriter; 17983e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor}; 17993e00bad490f1bae8a2c60f934e7eb5dbb9752c5dDouglas Gregor 1800dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall/// Declaration of a friend template. For example: 1801dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall/// 1802dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall/// template <typename T> class A { 1803dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall/// friend class MyVector<T>; // not a friend template 1804dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall/// template <typename U> friend class B; // friend template 1805dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall/// template <typename U> friend class Foo<T>::Nested; // friend template 1806dd4a3b0065b9a7e7b00073df415a798886c090f3John McCallclass FriendTemplateDecl : public Decl { 1807dd4a3b0065b9a7e7b00073df415a798886c090f3John McCallpublic: 180832f2fb53d9d7c28c94d8569fd0fcf06cccee0c3dJohn McCall typedef llvm::PointerUnion<NamedDecl*,TypeSourceInfo*> FriendUnion; 1809dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1810dd4a3b0065b9a7e7b00073df415a798886c090f3John McCallprivate: 1811dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall // The number of template parameters; always non-zero. 1812dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall unsigned NumParams; 1813dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1814dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall // The parameter list. 1815dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall TemplateParameterList **Params; 1816dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1817dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall // The declaration that's a friend of this class. 1818dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall FriendUnion Friend; 1819dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1820dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall // Location of the 'friend' specifier. 1821dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall SourceLocation FriendLoc; 1822dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1823dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1824dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall FriendTemplateDecl(DeclContext *DC, SourceLocation Loc, 1825dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall unsigned NParams, 1826dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall TemplateParameterList **Params, 1827dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall FriendUnion Friend, 1828dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall SourceLocation FriendLoc) 1829dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall : Decl(Decl::FriendTemplate, DC, Loc), 1830dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall NumParams(NParams), 1831dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall Params(Params), 1832dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall Friend(Friend), 1833dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall FriendLoc(FriendLoc) 1834dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall {} 1835dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1836554e6aa2da082575514607c3639c246c04b3232aArgyrios Kyrtzidis FriendTemplateDecl(EmptyShell Empty) 1837554e6aa2da082575514607c3639c246c04b3232aArgyrios Kyrtzidis : Decl(Decl::FriendTemplate, Empty), 1838554e6aa2da082575514607c3639c246c04b3232aArgyrios Kyrtzidis NumParams(0), 1839554e6aa2da082575514607c3639c246c04b3232aArgyrios Kyrtzidis Params(0) 1840554e6aa2da082575514607c3639c246c04b3232aArgyrios Kyrtzidis {} 1841554e6aa2da082575514607c3639c246c04b3232aArgyrios Kyrtzidis 1842dd4a3b0065b9a7e7b00073df415a798886c090f3John McCallpublic: 1843dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall static FriendTemplateDecl *Create(ASTContext &Context, 1844dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall DeclContext *DC, SourceLocation Loc, 1845dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall unsigned NParams, 1846dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall TemplateParameterList **Params, 1847dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall FriendUnion Friend, 1848dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall SourceLocation FriendLoc); 1849dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1850554e6aa2da082575514607c3639c246c04b3232aArgyrios Kyrtzidis static FriendTemplateDecl *Create(ASTContext &Context, EmptyShell Empty); 1851554e6aa2da082575514607c3639c246c04b3232aArgyrios Kyrtzidis 1852dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall /// If this friend declaration names a templated type (or 1853dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall /// a dependent member type of a templated type), return that 1854dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall /// type; otherwise return null. 185532f2fb53d9d7c28c94d8569fd0fcf06cccee0c3dJohn McCall TypeSourceInfo *getFriendType() const { 185632f2fb53d9d7c28c94d8569fd0fcf06cccee0c3dJohn McCall return Friend.dyn_cast<TypeSourceInfo*>(); 1857dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall } 1858dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1859dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall /// If this friend declaration names a templated function (or 1860dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall /// a member function of a templated type), return that type; 1861dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall /// otherwise return null. 1862dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall NamedDecl *getFriendDecl() const { 1863dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall return Friend.dyn_cast<NamedDecl*>(); 1864dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall } 1865dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1866dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall /// Retrieves the location of the 'friend' keyword. 1867dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall SourceLocation getFriendLoc() const { 1868dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall return FriendLoc; 1869dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall } 1870dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1871dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall TemplateParameterList *getTemplateParameterList(unsigned i) const { 1872dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall assert(i <= NumParams); 1873dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall return Params[i]; 1874dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall } 1875dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1876dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall unsigned getNumTemplateParameters() const { 1877dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall return NumParams; 1878dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall } 1879dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1880dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall // Implement isa/cast/dyncast/etc. 188180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 188280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == Decl::FriendTemplate; } 1883dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall static bool classof(const FriendTemplateDecl *D) { return true; } 1884554e6aa2da082575514607c3639c246c04b3232aArgyrios Kyrtzidis 1885d527cc06d78fe5afa5f20105b51697637eb02c56Sebastian Redl friend class ASTDeclReader; 1886dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall}; 1887dd4a3b0065b9a7e7b00073df415a798886c090f3John McCall 1888e53060fa78ad7e98352049f72787bdb7543e2a48Douglas Gregor/// Implementation of inline functions that require the template declarations 18891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpinline AnyFunctionDecl::AnyFunctionDecl(FunctionTemplateDecl *FTD) 1890e53060fa78ad7e98352049f72787bdb7543e2a48Douglas Gregor : Function(FTD) { } 1891e53060fa78ad7e98352049f72787bdb7543e2a48Douglas Gregor 1892aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor} /* end of namespace clang */ 1893aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor 1894aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#endif 1895